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.40 1998/04/16 01:23:02 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.41 1998/04/24 00:08:42 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:114:    multiset_type_string=parse_type("multiset");    mapping_type_string=parse_type("mapping");    function_type_string=parse_type("function");    void_type_string=parse_type("void");    any_type_string=parse_type("void|mixed");   }      static int type_length(char *t)   {    char *q=t; -  + one_more_type:    switch(EXTRACT_UCHAR(t++))    {    default:    fatal("error in type string.\n");    /*NOTREACHED*/       break;       case T_ASSIGN:    t++; -  t+=type_length(t); -  break; +  goto one_more_type;       case T_FUNCTION:    while(EXTRACT_UCHAR(t)!=T_MANY) t+=type_length(t); /* skip arguments */    t++;       case T_MAPPING:    case T_OR:    case T_AND:    t+=type_length(t);       case T_ARRAY:    case T_MULTISET:    case T_NOT: -  t+=type_length(t); +  goto one_more_type;       case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':    case '8':
pike.git/src/pike_types.c:170:       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; - static unsigned char *mark_stack[STACK_SIZE/4]; - static unsigned char **mark_stackp=mark_stack; + unsigned char type_stack[PIKE_TYPE_STACK_SIZE]; + unsigned char *type_stackp=type_stack; + unsigned char *pike_type_mark_stack[PIKE_TYPE_STACK_SIZE/4]; + unsigned char **pike_type_mark_stackp=pike_type_mark_stack;    - void push_type(unsigned char tmp) - { -  *type_stackp=tmp; -  type_stackp++; -  if(type_stackp > type_stack + sizeof(type_stack)) -  yyerror("Type stack overflow."); - } +     - void type_stack_mark(void) - { -  *mark_stackp=type_stackp; -  mark_stackp++; -  if(mark_stackp > mark_stack + NELEM(mark_stack)) -  yyerror("Type mark stack overflow."); - } -  +    INT32 pop_stack_mark(void)   { -  mark_stackp--; -  if(mark_stackp<mark_stack) +  pike_type_mark_stackp--; +  if(pike_type_mark_stackp<pike_type_mark_stack)    fatal("Type mark stack underflow\n");    -  return type_stackp - *mark_stackp; +  return type_stackp - *pike_type_mark_stackp;   }      void pop_type_stack(void)   {    type_stackp--;    if(type_stackp<type_stack)    fatal("Type stack underflow\n");   }      void type_stack_pop_to_mark(void)   {    type_stackp-=pop_stack_mark();   #ifdef DEBUG    if(type_stackp<type_stack)    fatal("Type stack underflow\n");   #endif   }    - void reset_type_stack(void) - { -  type_stack_pop_to_mark(); -  type_stack_mark(); - } -  +    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)   {    int e;
pike.git/src/pike_types.c:334:       len=0;    for(len=0;isidchar(EXTRACT_UCHAR(s[0]+len));len++)    {    if(len>=sizeof(buf)) error("Buffer overflow in parse_type\n");    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")) +  switch(buf[0])    { -  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")) +  case 'i': +  if(!strcmp(buf,"int")) { 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;    type_stack_mark();    while(1)    {    if(**s == ':')
pike.git/src/pike_types.c:400:    type_stack_reverse();    if(**s != ')') error("Missing ')' in function type.\n");    ++*s;    type_stack_reverse();    }else{    push_type(T_MIXED);    push_type(T_MIXED);    push_type(T_MANY);    }    push_type(T_FUNCTION); +  break;    } -  else if(!strcmp(buf,"mapping")) +  if(!strcmp(buf,"float")) { push_type(T_FLOAT); break; } +  goto bad_type; +  +  case 'o': +  if(!strcmp(buf,"object"))    { -  +  push_type_int(0); +  push_type(0); +  push_type(T_OBJECT); +  break; +  } +  goto bad_type; +  +  +  case 'p': +  if(!strcmp(buf,"program")) { push_type(T_PROGRAM); break; } +  goto bad_type; +  +  +  case 's': +  if(!strcmp(buf,"string")) { push_type(T_STRING); break; } +  goto bad_type; +  +  case 'v': +  if(!strcmp(buf,"void")) { push_type(T_VOID); break; } +  goto bad_type; +  +  case 'm': +  if(!strcmp(buf,"mixed")) { push_type(T_MIXED); break; } +  if(!strcmp(buf,"mapping")) +  {    while(ISSPACE(**s)) ++*s;    if(**s == '(')    {    type_stack_mark();    ++*s;    type_stack_mark();    internal_parse_type(_s);    type_stack_reverse();    if(**s != ':') error("Expecting ':'.\n");    ++*s;
pike.git/src/pike_types.c:424:    internal_parse_type(_s);    type_stack_reverse();    if(**s != ')') error("Expecting ')'.\n");    ++*s;    type_stack_reverse();    }else{    push_type(T_MIXED);    push_type(T_MIXED);    }    push_type(T_MAPPING); +  break;    } -  else if(!strcmp(buf,"array")) +  if(!strcmp(buf,"multiset"))    {    while(ISSPACE(**s)) ++*s;    if(**s == '(')    {    ++*s;    internal_parse_type(_s);    if(**s != ')') error("Expecting ')'.\n");    ++*s;    }else{    push_type(T_MIXED);    } -  push_type(T_ARRAY); +  push_type(T_MULTISET); +  break;    } -  else if(!strcmp(buf,"multiset")) +  goto bad_type; +  +  case 'u': +  if(!strcmp(buf,"unknown")) { push_type(T_UNKNOWN); break; } +  goto bad_type; +  +  case 'a': +  if(!strcmp(buf,"array"))    {    while(ISSPACE(**s)) ++*s;    if(**s == '(')    {    ++*s;    internal_parse_type(_s);    if(**s != ')') error("Expecting ')'.\n");    ++*s;    }else{    push_type(T_MIXED);    } -  push_type(T_MULTISET); +  push_type(T_ARRAY); +  break;    } -  else if(buf[0]>='0' && buf[0]<='9' && atoi(buf)<10) +  goto bad_type; +  +  case '0': +  case '1': +  case '2': +  case '3': +  case '4': +  case '5': +  case '6': +  case '7': +  case '8': +  case '9': +  if(atoi(buf)<10)    {    while(ISSPACE(**s)) ++*s;    if(**s=='=')    {    ++*s;    internal_parse_type(_s);    push_type(buf[0]);    push_type(T_ASSIGN);    }else{    push_type(buf[0]);    } -  +  break;    } -  else +  +  default: +  bad_type:    error("Couldn't parse type. (%s)\n",buf); -  +  }       while(ISSPACE(**s)) ++*s;   }         static void internal_parse_typeB(char **s)   {    while(ISSPACE(**((unsigned char **)s))) ++*s;    switch(**s)    {
pike.git/src/pike_types.c:585: Inside #if defined(DEBUG)
   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(%s %ld)", -  EXTRACT_UCHAR(a+e+1)?"inherits":"clone of", +  EXTRACT_UCHAR(a+e+1)?"clone of":"inherits",    (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;
pike.git/src/pike_types.c:848:   }      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); -  -  return ID_FROM_INT(p, i)->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));    if(!p) return 0; -  i=FIND_LFUN(p, LFUN_CALL); -  +  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      /*    * match two type strings, return zero if they don't match, and return    * the part of 'a' that _did_ match if it did.