pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.12 1997/01/04 05:09:25 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.13 1997/01/22 05:19:45 hubbe Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"   #include "stralloc.h"   #include "stuff.h"   #include "array.h"   #include "program.h"   #include "constants.h"   #include "object.h"   #include "multiset.h"   #include "mapping.h"   #include "macros.h"   #include "error.h" -  + #include "las.h" + #include "language.h"      int max_correct_args;      static void internal_parse_type(char **s);   static int type_length(char *t);      /*    * basic types are represented by just their value in a string    * basic type are string, int, float, object and program    * arrays are coded like by the value T_ARRAY followed by the
pike.git/src/pike_types.c:883:   int match_types(struct pike_string *a,struct pike_string *b)   {    CHECK_TYPE(a);    CHECK_TYPE(b);    return 0!=low_match_types(a->str, b->str,0);   }            /* FIXME, add the index */ - static struct pike_string *low_index_type(char *t) + static struct pike_string *low_index_type(char *t, node *n)   {    switch(EXTRACT_UCHAR(t++))    { -  +  case T_OBJECT: +  { +  struct program *p=id_to_program(EXTRACT_INT(t)); +  if(p) +  { +  if(n->token == F_ARROW) +  { +  if(find_identifier("`->",p) != -1 || find_identifier("`->=",p) != -1) +  { +  reference_shared_string(mixed_type_string); +  return mixed_type_string; +  } +  }else{ +  if(find_identifier("`[]",p) != -1 || find_identifier("`[]=",p) != -1) +  { +  reference_shared_string(mixed_type_string); +  return mixed_type_string; +  } +  } +  if(CDR(n)->token == F_CONSTANT && CDR(n)->u.sval.type==T_STRING) +  { +  INT32 i; +  i=find_shared_string_identifier(CDR(n)->u.sval.u.string, p); +  if(i==-1) +  { +  reference_shared_string(int_type_string); +  return int_type_string; +  }else{ +  reference_shared_string(ID_FROM_INT(p, i)->type); +  return ID_FROM_INT(p, i)->type; +  } +  } +  } +  }    default:    reference_shared_string(mixed_type_string);    return mixed_type_string;       case T_OR:    {    struct pike_string *a,*b; -  a=low_index_type(t); +  a=low_index_type(t,n);    t+=type_length(t); -  b=low_index_type(t); +  b=low_index_type(t,n);    if(!b) return a;    if(!a) return b;    push_finished_type(b);    push_finished_type(a);    push_type(T_OR);    return pop_type();    }       case T_AND: -  return low_index_type(t+type_length(t)); +  return low_index_type(t+type_length(t),n);       case T_STRING: /* always int */    case T_MULTISET: /* always int */    reference_shared_string(int_type_string);    return int_type_string;       case T_MAPPING:    t+=type_length(t);       case T_ARRAY:    return make_shared_binary_string(t, type_length(t));    }   }    - struct pike_string *index_type(struct pike_string *type) + struct pike_string *index_type(struct pike_string *type, node *n)   {    struct pike_string *t; -  t=low_index_type(type->str); +  t=low_index_type(type->str,n);    if(!t) copy_shared_string(t,mixed_type_string);    return t;   }    - static int low_check_indexing(char *type, char *index_type) + static int low_check_indexing(char *type, char *index_type, node *n)   {    switch(EXTRACT_UCHAR(type++))    {    case T_OR: -  return low_check_indexing(type,index_type) || -  low_check_indexing(type+type_length(type),index_type); +  return low_check_indexing(type,index_type,n) || +  low_check_indexing(type+type_length(type),index_type,n);       case T_AND: -  return low_check_indexing(type,index_type) && -  low_check_indexing(type+type_length(type),index_type); +  return low_check_indexing(type,index_type,n) && +  low_check_indexing(type+type_length(type),index_type,n);       case T_NOT: -  return !low_check_indexing(type,index_type); +  return !low_check_indexing(type,index_type,n);       case T_STRING:    case T_ARRAY:    return !!low_match_types(int_type_string->str, index_type,0);       case T_OBJECT: -  +  { +  struct program *p=id_to_program(EXTRACT_INT(type)); +  if(p) +  { +  if(n->token == F_ARROW) +  { +  if(find_identifier("`->",p) != -1 || find_identifier("`->=",p) != -1) +  return 1; +  }else{ +  if(find_identifier("`[]",p) != -1 || find_identifier("`[]=",p) != -1) +  return 1; +  }    return !!low_match_types(string_type_string->str, index_type,0); -  +  }else{ +  return 1; +  } +  }       case T_MULTISET:    case T_MAPPING:    return !!low_match_types(type,index_type,0);       case T_MIXED:    return 1;       default:    return 0;    }   }      int check_indexing(struct pike_string *type, -  struct pike_string *index_type) +  struct pike_string *index_type, +  node *n)   {    CHECK_TYPE(type);    CHECK_TYPE(index_type);    -  return low_check_indexing(type->str, index_type->str); +  return low_check_indexing(type->str, index_type->str, n);   }      /* Count the number of arguments for a funciton type.    * return -1-n if the function can take number of arguments    * >= n (varargs)    */   int count_arguments(struct pike_string *s)   {    int num;    char *q;