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.37 1998/04/09 02:47:47 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.38 1998/04/10 22:24:21 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"
pike.git/src/pike_types.c:39:    * mappings are followed by two arguments, the first is the type    * for the indices, and the second is the type of the data, ie:    * T_MAPPING <indice type> <data type>    * multiset works similarly to arrays.    * functions are _very_ special:    * they are coded like this:    * T_FUNCTION <arg type> <arg type> ... <arg type> T_MANY <arg type> <return type>    * note that the type after T_MANY can be T_VOID    * T_MIXED matches anything except T_VOID    * T_UNKNOWN only matches T_MIXED and T_UNKNOWN +  * objects are coded thus: +  * T_OBJECT <0/1> <program_id> +  * ^ +  * 0 means 'inherits' +  * 1 means 'is'    */      struct pike_string *string_type_string;   struct pike_string *int_type_string;   struct pike_string *float_type_string;   struct pike_string *function_type_string;   struct pike_string *object_type_string;   struct pike_string *program_type_string;   struct pike_string *array_type_string;   struct pike_string *multiset_type_string;
pike.git/src/pike_types.c:83: Inside #if defined(DEBUG)
     #ifdef DEBUG   static void CHECK_TYPE(struct pike_string *s)   {    if(debug_findstring(s) != s)    fatal("Type string not shared.\n");       if(type_length(s->str) != s->len)    {    stupid_describe_type(s->str,s->len); -  fatal("Length of type is wrong.\n"); +  fatal("Length of type is wrong. (should be %d, is %d)\n",type_length(s->str),s->len);    }   }   #else   #define CHECK_TYPE(X)   #endif      void init_types(void)   {    string_type_string=parse_type("string");    int_type_string=parse_type("int");
pike.git/src/pike_types.c:157:    case T_INT:    case T_FLOAT:    case T_STRING:    case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_UNKNOWN:    break;       case T_OBJECT: +  t++;    t+=sizeof(INT32);    break;    }    return t-q;   }         #define STACK_SIZE 100000   static unsigned char type_stack[STACK_SIZE];   static unsigned char *type_stackp=type_stack;
pike.git/src/pike_types.c:264: Inside #if 1
   }    break;   #endif       case T_OBJECT:    push_type(c);    push_type(EXTRACT_UCHAR(s+ ++e));    push_type(EXTRACT_UCHAR(s+ ++e));    push_type(EXTRACT_UCHAR(s+ ++e));    push_type(EXTRACT_UCHAR(s+ ++e)); +  push_type(EXTRACT_UCHAR(s+ ++e));    break;       default:    push_type(c);    }    }    type_stack_reverse();   }      void push_finished_type(struct pike_string *type)
pike.git/src/pike_types.c:332:    buf[len] = s[0][len];    }    buf[len]=0;    *s += len;       if(!strcmp(buf,"int")) push_type(T_INT);    else if(!strcmp(buf,"float")) push_type(T_FLOAT);    else if(!strcmp(buf,"object"))    {    push_type_int(0); +  push_type(0);    push_type(T_OBJECT);    }    else if(!strcmp(buf,"program")) push_type(T_PROGRAM);    else if(!strcmp(buf,"string")) push_type(T_STRING);    else if(!strcmp(buf,"void")) push_type(T_VOID);    else if(!strcmp(buf,"mixed")) push_type(T_MIXED);    else if(!strcmp(buf,"unknown")) push_type(T_UNKNOWN);    else if(!strcmp(buf,"function"))    {    while(ISSPACE(**s)) ++*s;
pike.git/src/pike_types.c:576: Inside #if defined(DEBUG)
   case '5': case '6': case '7': case '8': case '9':    printf("%c",EXTRACT_UCHAR(a+e));    break;       case T_ASSIGN: printf("="); break;    case T_INT: printf("int"); break;    case T_FLOAT: printf("float"); break;    case T_STRING: printf("string"); break;    case T_PROGRAM: printf("program"); break;    case T_OBJECT: -  printf("object(%ld)",(long)EXTRACT_INT(a+e+1)); -  e+=sizeof(INT32); +  printf("object(%s %ld)", +  EXTRACT_UCHAR(a+e+1)?"inherits":"clone of", +  (long)EXTRACT_INT(a+e+2)); +  e+=sizeof(INT32)+1;    break;    case T_FUNCTION: printf("function"); break;    case T_ARRAY: printf("array"); break;    case T_MAPPING: printf("mapping"); break;    case T_MULTISET: printf("multiset"); break;       case T_UNKNOWN: printf("unknown"); break;    case T_MANY: printf("many"); break;    case T_OR: printf("or"); break;    case T_AND: printf("and"); break;
pike.git/src/pike_types.c:629:    break;       case T_VOID: my_strcat("void"); break;    case T_MIXED: my_strcat("mixed"); break;    case T_UNKNOWN: my_strcat("unknown"); break;    case T_INT: my_strcat("int"); break;    case T_FLOAT: my_strcat("float"); break;    case T_PROGRAM: my_strcat("program"); break;    case T_OBJECT:    my_strcat("object"); -  t+=4; +  t+=sizeof(INT32)+1;    /* Prog id */    break;    case T_STRING: my_strcat("string"); break;       case T_FUNCTION:    {    int s;    my_strcat("function(");    s=0;    while(EXTRACT_UCHAR(t) != T_MANY)
pike.git/src/pike_types.c:830:   }      static struct pike_string *or_pike_types(struct pike_string *a,    struct pike_string *b)   {    type_stack_mark();    medium_or_pike_types(a,b);    return pop_unfinished_type();   }    + static struct pike_string *low_object_fun_type(char *t, +  struct pike_string *tmp) + { +  struct program *p; +  int i; +  p=id_to_program(EXTRACT_INT(t+2)); +  if(!p) return 0; +  i=FIND_LFUN(p, LFUN_CALL);    -  +  if(EXTRACT_UCHAR(t+1) || +  (p->identifier_references[i].id_flags & ID_NOMASK) || +  (ID_FROM_INT(p, i)->identifier_flags & IDENTIFIER_PROTOTYPED)) +  return ID_FROM_INT(p, i)->type; +  +  return 0; + } +  + static struct pike_string *low_object_lfun_type(char *t, short lfun) + { +  struct program *p; +  int i; +  p=id_to_program(EXTRACT_INT(t+2)); +  if(!p) return 0; +  i=FIND_LFUN(p, LFUN_CALL); +  +  if(EXTRACT_UCHAR(t+1) || +  (p->identifier_references[i].id_flags & ID_NOMASK) || +  (ID_FROM_INT(p, i)->identifier_flags & IDENTIFIER_PROTOTYPED)) +  return ID_FROM_INT(p, i)->type; +  +  return 0; + } +    #define A_EXACT 1   #define B_EXACT 2   #define NO_MAX_ARGS 4      /*    * match two type strings, return zero if they don't match, and return    * the part of 'a' that _did_ match if it did.    */   static char *low_match_types(char *a,char *b, int flags)   {
pike.git/src/pike_types.c:945:    if(EXTRACT_UCHAR(b) == T_MIXED && !(flags & B_EXACT)) return a;       /* Special cases (tm) */    switch(EXTRACT_TWOT(a,b))    {    case TWOT(T_PROGRAM, T_FUNCTION):    case TWOT(T_FUNCTION, T_PROGRAM):    return a;    case TWOT(T_OBJECT, T_FUNCTION):    { -  struct program *p; -  if((p=id_to_program(EXTRACT_INT(a+1)))) -  { -  int i=FIND_LFUN(p,LFUN_CALL); -  if(i == -1) return 0; -  return low_match_types(ID_FROM_INT(p, i)->type->str, b, flags); -  } +  struct pike_string *s; +  if((s=low_object_lfun_type(a, LFUN_CALL))) +  return low_match_types(s->str,b,flags);    return a;    }       case TWOT(T_FUNCTION, T_OBJECT):    { -  struct program *p; -  if((p=id_to_program(EXTRACT_INT(b+1)))) -  { -  int i=FIND_LFUN(p,LFUN_CALL); -  if(i == -1) return 0; -  return low_match_types(a, ID_FROM_INT(p, i)->type->str, flags); -  } +  struct pike_string *s; +  if((s=low_object_lfun_type(b, LFUN_CALL))) +  return low_match_types(a,s->str,flags);    return a;    }    }       if(EXTRACT_UCHAR(a) != EXTRACT_UCHAR(b)) return 0;       ret=a;    switch(EXTRACT_UCHAR(a))    {    case T_FUNCTION:
pike.git/src/pike_types.c:1023:    /* check the returntype */    if(!low_match_types(a,b,flags)) return 0;    break;       case T_MAPPING:    if(!low_match_types(++a,++b,flags)) return 0;    if(!low_match_types(a+type_length(a),b+type_length(b),flags)) return 0;    break;       case T_OBJECT: -  a++; -  b++; -  if(!EXTRACT_INT(a) || !EXTRACT_INT(b)) break; -  if(EXTRACT_INT(a) != EXTRACT_INT(b)) return 0; +  /* object(* 0) matches any object */ +  if(!EXTRACT_INT(a+2) || !EXTRACT_INT(b+2)) break; +  +  /* object(x *) =? object(x *) */ +  if(EXTRACT_UCHAR(a+1) == EXTRACT_UCHAR(b+1)) +  { +  /* x? */ +  if(EXTRACT_UCHAR(a+1)) +  { +  /* object(1 x) =? object(1 x) */ +  if(EXTRACT_INT(a+2) != EXTRACT_INT(b+2)) return 0; +  }else{ +  /* object(0 *) =? object(0 *) */    break; -  +  } +  }    -  +  { +  struct program *ap,*bp; +  ap=id_to_program(EXTRACT_UCHAR(a+2)); +  bp=id_to_program(EXTRACT_UCHAR(b+2)); +  +  if(!ap || !bp) break; +  +  if(EXTRACT_UCHAR(a+1)) +  { +  if(low_get_storage(bp,ap)==-1) +  return 0; +  }else{ +  if(low_get_storage(ap,bp)==-1) +  return 0; +  } +  } +  +  break; +     case T_MULTISET:    case T_ARRAY:    if(!low_match_types(++a,++b,flags)) return 0;       case T_INT:    case T_FLOAT:    case T_STRING:    case T_PROGRAM:    case T_VOID:    case T_MIXED:
pike.git/src/pike_types.c:1114:    case T_FUNCTION:    a++;    while(EXTRACT_UCHAR(a)!=T_MANY) a+=type_length(a);    a++;    a+=type_length(a);    push_unfinished_type_with_markers(a, a_markers );    return 1;       case T_PROGRAM:    push_type_int(0); +  push_type(0);    push_type(T_OBJECT);    return 1;       default:    push_type(T_MIXED);    return 1;    }    }    return 0;   }
pike.git/src/pike_types.c:1148:   #define low_index_type debug_low_index_type   #endif      /* FIXME, add the index */   static struct pike_string *debug_low_index_type(char *t, node *n)   {    switch(EXTRACT_UCHAR(t++))    {    case T_OBJECT:    { -  struct program *p=id_to_program(EXTRACT_INT(t)); +  struct program *p=id_to_program(EXTRACT_INT(t+1));    if(p && n)    {    if(n->token == F_ARROW)    {    if(FIND_LFUN(p,LFUN_ARROW)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW)!=-1)    {    reference_shared_string(mixed_type_string);    return mixed_type_string;    }    }else{
pike.git/src/pike_types.c:1174:    }    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{ +  if(EXTRACT_UCHAR(t) || +  (p->identifier_references[i].id_flags & ID_NOMASK) || +  (ID_FROM_INT(p, i)->identifier_flags & IDENTIFIER_PROTOTYPED)) +  {    reference_shared_string(ID_FROM_INT(p, i)->type);    return ID_FROM_INT(p, i)->type; -  +  }else{ +  reference_shared_string(mixed_type_string); +  return mixed_type_string;    }    }    }    } -  +  }    default:    reference_shared_string(mixed_type_string);    return mixed_type_string;       case T_OR:    {    struct pike_string *a,*b;    type_stack_mark();    a=low_index_type(t,n);    t+=type_length(t);
pike.git/src/pike_types.c:1269:    case T_ARRAY:    if(low_match_types(string_type_string->str, index_type,0) &&    low_check_indexing(type, index_type,n))    return 1;       case T_STRING:    return !!low_match_types(int_type_string->str, index_type,0);       case T_OBJECT:    { -  struct program *p=id_to_program(EXTRACT_INT(type)); +  struct program *p=id_to_program(EXTRACT_INT(type+1));    if(p)    {    if(n->token == F_ARROW)    { -  if(FIND_LFUN(p,LFUN_ARROW) != -1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW) != -1) +  if(FIND_LFUN(p,LFUN_ARROW)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW)!=-1)    return 1;    }else{ -  if(FIND_LFUN(p,LFUN_INDEX) != -1 || FIND_LFUN(p,LFUN_ASSIGN_INDEX) != -1) +  if(FIND_LFUN(p,LFUN_INDEX)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_INDEX)!=-1)    return 1;    }    return !!low_match_types(string_type_string->str, index_type,0);    }else{    return 1;    }    }       case T_MULTISET:    case T_MAPPING:
pike.git/src/pike_types.c:1433:    push_type(T_MIXED);    push_type(T_MIXED);    push_type(T_MAPPING);    return pop_unfinished_type();       case T_OBJECT:    type_stack_mark();    if(s->u.object->prog)    {    push_type_int(s->u.object->prog->id); +  push_type(1);    }else{    push_type_int(0); -  +  push_type(0);    }    push_type(T_OBJECT);    return pop_unfinished_type();       case T_INT:    if(s->u.integer)    {    ret=int_type_string;    }else{    ret=mixed_type_string;
pike.git/src/pike_types.c:1463:    if(id>=0)    {    a=ID_FROM_INT(s->u.program, id)->type->str;    }else{    a=function_type_string->str;    }    if(EXTRACT_UCHAR(a)==T_FUNCTION)    {    type_stack_mark();    push_type_int(s->u.program->id); +  push_type(1);    push_type(T_OBJECT);       type_stack_mark();    a++;    while(EXTRACT_UCHAR(a)!=T_MANY)    {    type_stack_mark();    push_unfinished_type(a);    type_stack_reverse();    a+=type_length(a);