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.53 1999/02/28 17:07:43 grubba Exp $"); + RCSID("$Id: pike_types.c,v 1.54 1999/03/02 03:13:25 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:151:    case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':    case '8':    case '9': -  case T_INT: +     case T_FLOAT:    case T_STRING:    case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_UNKNOWN:    break;    -  +  case T_INT: +  t+=sizeof(INT32)*2; +  break; +     case T_OBJECT:    t++;    t+=sizeof(INT32);    break;    }    return t-q;   }         unsigned char type_stack[PIKE_TYPE_STACK_SIZE];
pike.git/src/pike_types.c:207:   #endif   }      void type_stack_reverse(void)   {    INT32 a;    a=pop_stack_mark();    reverse((char *)(type_stackp-a),a,1);   }    - void push_type_int(unsigned INT32 i) + void push_type_int(INT32 i)   {    int e; -  for(e=sizeof(i)-1;e>=0;e--) -  push_type(((unsigned char *)&i)[e]); +  for(e=0;e<(int)sizeof(i);e++) +  push_type( (i>>(e*8)) & 0xff );   }    -  + INT32 extract_type_int(char *p) + { +  int e; +  INT32 ret=0; +  for(e=0;e<(int)sizeof(INT32);e++) +  ret=(ret<<8) | EXTRACT_UCHAR(p+e); +  return ret; + } +    void push_unfinished_type(char *s)   {    int e;    e=type_length(s);    for(e--;e>=0;e--) push_type(s[e]);   }      static void push_unfinished_type_with_markers(char *s, struct pike_string **am)   { -  int e,c,len=type_length(s); +  int d,e,c,len=type_length(s);    type_stack_mark();    for(e=0;e<len;e++)    {    switch(c=EXTRACT_UCHAR(s+e))    {   #if 1    case '0': case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8': case '9':    if(am[c-'0'])    {    push_finished_type_backwards(am[c-'0']);    }else{    push_type(T_MIXED);    }    break;   #endif    -  case T_OBJECT: +  case T_INT:    push_type(c); -  +  for(d=0;d<(int)sizeof(INT32)*2;d++)    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;    -  +  case T_OBJECT: +  push_type(c); +  for(d=0;d<(int)sizeof(INT32)+1;d++) push_type(EXTRACT_UCHAR(s+ ++e)); +  break; +     default:    push_type(c);    }    }    type_stack_reverse();   }      void push_finished_type(struct pike_string *type)   {    int e;
pike.git/src/pike_types.c:335:    {    if(len>=sizeof(buf)) error("Buffer overflow in parse_type\n");    buf[len] = s[0][len];    }    buf[len]=0;    *s += len;       switch(buf[0])    {    case 'i': -  if(!strcmp(buf,"int")) { push_type(T_INT); break; } +  if(!strcmp(buf,"int")) +  { +  while(ISSPACE(**s)) ++*s; +  if(**s=='(') +  { +  INT32 min,max; +  ++*s; +  while(ISSPACE(**s)) ++*s; +  min=STRTOL(*s,(char **)s,0); +  while(ISSPACE(**s)) ++*s; +  if(s[0][0]=='.' && s[0][1]=='.') +  s[0]+=2; +  else +  error("Missing .. in integer type.\n"); +  +  while(ISSPACE(**s)) ++*s; +  max=STRTOL(*s,(char **)s,0); +  while(ISSPACE(**s)) ++*s; +  +  if(**s != ')') error("Missing ')' in integer range.\n"); +  ++*s; +  push_type_int(max); +  push_type_int(min); +  }else{ +  push_type_int(MAX_INT32); +  push_type_int(MIN_INT32); +  } +  push_type(T_INT); +  break; +  }    goto bad_type;       case 'f':    if(!strcmp(buf,"function"))    {    while(ISSPACE(**s)) ++*s;    if(**s == '(')    {    ++*s;    while(ISSPACE(**s)) ++*s;
pike.git/src/pike_types.c:639: Inside #if defined(PIKE_DEBUG)
   {    if(e) printf(" ");    switch(EXTRACT_UCHAR(a+e))    {    case '0': case '1': case '2': case '3': case '4':    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_INT: +  { +  INT32 min=extract_type_int(a+e+1); +  INT32 max=extract_type_int(a+e+1+sizeof(INT32)); +  printf("int"); +  if(min!=MIN_INT32 || max!=MAX_INT32) +  printf("(%ld..%ld)",(long)min,(long)max); +  e+=sizeof(INT32)*2; +  break; +  }    case T_FLOAT: printf("float"); break;    case T_STRING: printf("string"); break;    case T_PROGRAM: printf("program"); break;    case T_OBJECT:    printf("object(%s %ld)",    EXTRACT_UCHAR(a+e+1)?"clone of":"inherits", -  (long)EXTRACT_INT(a+e+2)); +  (long)extract_type_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;
pike.git/src/pike_types.c:694:    my_putchar('(');    my_putchar(EXTRACT_UCHAR(t++));    my_putchar('=');    t=low_describe_type(t);    my_putchar(')');    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_INT: +  { +  INT32 min=extract_type_int(t); +  INT32 max=extract_type_int(t+sizeof(INT32)); +  my_strcat("int"); +  +  if(min!=MIN_INT32 || max!=MAX_INT32) +  { +  char buffer[100]; +  sprintf(buffer,"(%ld..%ld)",(long)min,(long)max); +  my_strcat(buffer); +  } +  t+=sizeof(INT32)*2; +  +  break; +  }    case T_FLOAT: my_strcat("float"); break;    case T_PROGRAM: my_strcat("program"); break;    case T_OBJECT: -  if(EXTRACT_INT(t+1)) +  if(extract_type_int(t+1))    {    char buffer[100]; -  sprintf(buffer,"object(%s %ld)",*t?"is":"implements",(long)EXTRACT_INT(t+1)); +  sprintf(buffer,"object(%s %ld)",*t?"is":"implements",(long)extract_type_int(t+1));    my_strcat(buffer);    }else{    my_strcat("object");    }       t+=sizeof(INT32)+1;    /* Prog id */    break;    case T_STRING: my_strcat("string"); break;   
pike.git/src/pike_types.c:797:    t=low_describe_type(t);    my_strcat(")");    }    break;    }    return t;   }      struct pike_string *describe_type(struct pike_string *type)   { +  check_type_string(type);    if(!type) return make_shared_string("mixed");    init_buf();    low_describe_type(type->str);    return free_buf();   }      static int low_is_same_type(char *a, char *b)   {    if(type_length(a) != type_length(b)) return 0;    return !MEMCMP(a,b,type_length(a));
pike.git/src/pike_types.c:888:    push_unfinished_type(t2);    }    else if(!t2)    {    push_unfinished_type(t1);    }    else if(EXTRACT_UCHAR(t1)==T_MIXED || EXTRACT_UCHAR(t2)==T_MIXED)    {    push_type(T_MIXED);    } +  else if(EXTRACT_UCHAR(t1)==T_INT && EXTRACT_UCHAR(t2)==T_INT) +  { +  INT32 i1,i2; +  i1=extract_type_int(t1+1+sizeof(INT32)); +  i2=extract_type_int(t2+1+sizeof(INT32)); +  push_type_int(MAXIMUM(i1,i2)); +  +  i1=extract_type_int(t1+1); +  i2=extract_type_int(t2+1); +  push_type_int(MINIMUM(i1,i2)); +  +  push_type(T_INT); +  }    else    {    push_unfinished_type(t1);    very_low_or_pike_types(t2,t1);    }   }      static void medium_or_pike_types(struct pike_string *a,    struct pike_string *b)   {
pike.git/src/pike_types.c:913:   {    type_stack_mark();    medium_or_pike_types(a,b);    return pop_unfinished_type();   }      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)); +  p=id_to_program(extract_type_int(t+2));    if(!p) return 0;    i=FIND_LFUN(p, lfun);    if(i==-1) return 0;    return ID_FROM_INT(p, i)->type;   }      #define A_EXACT 1   #define B_EXACT 2   #define NO_MAX_ARGS 4   #define NO_SHORTCUTS 8
pike.git/src/pike_types.c:1118:    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:   #if 0 -  if(EXTRACT_INT(a+2) || EXTRACT_INT(b+2)) +  if(extract_type_int(a+2) || extract_type_int(b+2))    {    fprintf(stderr,"Type match1: ");    stupid_describe_type(a,type_length(a));    fprintf(stderr,"Type match2: ");    stupid_describe_type(b,type_length(b));    }   #endif       /* object(* 0) matches any object */ -  if(!EXTRACT_INT(a+2) || !EXTRACT_INT(b+2)) break; +  if(!extract_type_int(a+2) || !extract_type_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; +  if(extract_type_int(a+2) != extract_type_int(b+2)) return 0;    }else{    /* object(0 *) =? object(0 *) */    break;    }    }       {    struct program *ap,*bp; -  ap=id_to_program(EXTRACT_INT(a+2)); -  bp=id_to_program(EXTRACT_INT(b+2)); +  ap=id_to_program(extract_type_int(a+2)); +  bp=id_to_program(extract_type_int(b+2));       if(!ap || !bp) break;       if(EXTRACT_UCHAR(a+1))    {    if(!implements(ap,bp))    return 0;    }else{    if(!implements(bp,ap))    return 0;    }    }       break;    -  +  case T_INT: +  { +  INT32 amin=extract_type_int(a+1); +  INT32 amax=extract_type_int(a+1+sizeof(INT32)); +  +  INT32 bmin=extract_type_int(b+1); +  INT32 bmax=extract_type_int(b+1+sizeof(INT32)); +  +  if(amin > bmax || bmin > amax) 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:    break;       default:    fatal("error in type string.\n");    }
pike.git/src/pike_types.c:1283:   #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+1)); +  struct program *p=id_to_program(extract_type_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:1416:    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+1)); +  struct program *p=id_to_program(extract_type_int(type+1));    if(p)    {    if(n->token == F_ARROW)    {    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)    return 1;    }    return !!low_match_types(string_type_string->str, index_type,0);    }else{    return 1;    }    }       case T_MULTISET:    case T_MAPPING: -  + #if 0    return !!low_match_types(type,index_type,0); -  + #else +  /* FIXME: Compiler warning here!!!! */ +  return 1; + #endif       case T_PROGRAM:    /* FIXME: Should check that the index is a string. */    return 1;       case T_MIXED:    return 1;       default:    return 0;
pike.git/src/pike_types.c:1595:    }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; +  type_stack_mark(); +  /* Fixme, check that the integer is in range of MIN_INT32 .. MAX_INT32!*/ +  push_type_int(s->u.integer); +  push_type_int(s->u.integer); +  push_type(T_INT); +  return pop_unfinished_type();    }else{    ret=mixed_type_string;    }    reference_shared_string(ret);    return ret;       case T_PROGRAM:    {    char *a;    int id=FIND_LFUN(s->u.program,LFUN_CREATE);
pike.git/src/pike_types.c:1713:    type_may_overload(type+type_length(type),lfun);       case T_NOT:    return !type_may_overload(type,lfun);       case T_MIXED:    return 1;       case T_OBJECT:    { -  struct program *p=id_to_program(EXTRACT_INT(type+1)); +  struct program *p=id_to_program(extract_type_int(type+1));    if(!p) return 1;    return FIND_LFUN(p, lfun)!=-1;    }    }   }