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.84 1999/11/30 07:49:28 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.85 1999/12/07 09:40:59 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:365:    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;       switch(buf[0])    { +  case 'z': +  if(!strcmp(buf,"zero")) { push_type(T_MIXED); break; } +  goto bad_type; +     case 'i':    if(!strcmp(buf,"int"))    {    while(ISSPACE(**s)) ++*s;    if(**s=='(')    {    INT32 min,max;    ++*s;    while(ISSPACE(**s)) ++*s;    min=STRTOL(*s,(char **)s,0);
pike.git/src/pike_types.c:601:    ++*s;    internal_parse_typeB(s);    push_type(T_NOT);    break;       case '(':    ++*s;    internal_parse_type(s);    while(ISSPACE(**((unsigned char **)s))) ++*s;    if(**s != ')') error("Expecting ')'.\n"); +  ++*s;    break;       default:       internal_parse_typeA(s);    }   }      static void internal_parse_typeCC(char **s)   {
pike.git/src/pike_types.c:805:    }       t+=sizeof(INT32)+1;    /* Prog id */    break;    case T_STRING: my_strcat("string"); break;       case T_FUNCTION:    {    int s; -  my_strcat("function("); +  my_strcat("function"); +  if(EXTRACT_UCHAR(t) == T_MANY && +  (EXTRACT_UCHAR(t+1) == T_MIXED && +  EXTRACT_UCHAR(t+2) == T_OR && +  ((EXTRACT_UCHAR(t+3) == T_MIXED && EXTRACT_UCHAR(t+4) == T_VOID) || +  (EXTRACT_UCHAR(t+4) == T_MIXED && EXTRACT_UCHAR(t+3) == T_VOID))) +  || +  (EXTRACT_UCHAR(t+1) == T_OR +  && +  ((EXTRACT_UCHAR(t+2) == T_MIXED && EXTRACT_UCHAR(t+3) == T_VOID) || +  (EXTRACT_UCHAR(t+3) == T_MIXED && EXTRACT_UCHAR(t+2) == T_VOID)) +  && +  EXTRACT_UCHAR(t+4) == T_OR +  && +  ((EXTRACT_UCHAR(t+5) == T_MIXED && EXTRACT_UCHAR(t+6) == T_VOID) || +  (EXTRACT_UCHAR(t+6) == T_MIXED && EXTRACT_UCHAR(t+5) == T_VOID)))) +  { +  /* done */ +  ; +  } else { +  my_strcat("(");    s=0;    while(EXTRACT_UCHAR(t) != T_MANY)    {    if(s++) my_strcat(", ");    t=low_describe_type(t);    }    t++;    if(EXTRACT_UCHAR(t) == T_VOID)    {    t++;    }else{    if(s++) my_strcat(", ");    t=low_describe_type(t);    my_strcat(" ...");    }    my_strcat(" : ");    t=low_describe_type(t);    my_strcat(")"); -  +  }    break;    }       case T_ARRAY:    my_strcat("array");    if(EXTRACT_UCHAR(t)==T_MIXED)    {    t++;    }else{    my_strcat("(");
pike.git/src/pike_types.c:970:    * this might use the 'le' operator    */       if(!low_find_exact_type_match(to_push, not_push, T_OR))    {    push_unfinished_type(to_push);    push_type(T_OR);    }   }    - static void low_or_pike_types(char *t1, char *t2) + static void low_or_pike_types(char *t1, char *t2, int zero_implied)   {    if(!t1)    {    if(!t2)    push_type(T_VOID);    else    push_unfinished_type(t2);    }    else if((!t2) - #if 0 -  || (EXTRACT_UCHAR(t2) == T_ZERO) - #endif +  || (EXTRACT_UCHAR(t2) == T_ZERO && zero_implied) +     )    {    push_unfinished_type(t1);    } - #if 0 -  else if (EXTRACT_UCHAR(t1) == T_ZERO) +  else if (EXTRACT_UCHAR(t1) == T_ZERO && zero_implied)    {    push_unfinished_type(t2);    } - #endif +     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)    {    /* FIXME:    * This should only be done if the ranges are    * overlapping or adjecant to each other. /Hubbe    */
pike.git/src/pike_types.c:1022:    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) +  struct pike_string *b, +  int zero_implied)   { -  low_or_pike_types( a ? a->str : 0 , b ? b->str : 0 ); +  low_or_pike_types( a ? a->str : 0 , b ? b->str : 0 , zero_implied);   }      struct pike_string *or_pike_types(struct pike_string *a, -  struct pike_string *b) +  struct pike_string *b, +  int zero_implied)   {    type_stack_mark(); -  medium_or_pike_types(a,b); +  medium_or_pike_types(a,b,zero_implied);    return pop_unfinished_type();   }      static void very_low_and_pike_types(char *to_push, char *not_push)   {    while(EXTRACT_UCHAR(to_push)==T_AND)    {    to_push++;    very_low_and_pike_types(to_push, not_push);    to_push+=type_length(to_push);
pike.git/src/pike_types.c:1346:    ret=low_match_types(a+2,b,flags);    if(ret && EXTRACT_UCHAR(b)!=T_VOID)    {    int m=EXTRACT_UCHAR(a+1)-'0';    struct pike_string *tmp;    type_stack_mark();    push_unfinished_type_with_markers(b, b_markers);    tmp=pop_unfinished_type();       type_stack_mark(); -  medium_or_pike_types(a_markers[m], tmp); +  medium_or_pike_types(a_markers[m], tmp, 0);    if(a_markers[m]) free_string(a_markers[m]);    free_string(tmp);    a_markers[m]=pop_unfinished_type();      #ifdef PIKE_TYPE_DEBUG    {    char *s;    int e;    init_buf();    for(e=0;e<indent;e++) my_strcat(" ");
pike.git/src/pike_types.c:1431:    ret=low_match_types(a,b+2,flags);    if(ret && EXTRACT_UCHAR(a)!=T_VOID)    {    int m=EXTRACT_UCHAR(b+1)-'0';    struct pike_string *tmp;    type_stack_mark();    push_unfinished_type_with_markers(a, a_markers);    tmp=pop_unfinished_type();       type_stack_mark(); -  medium_or_pike_types(b_markers[m], tmp); +  medium_or_pike_types(b_markers[m], tmp, 0);    if(b_markers[m]) free_string(b_markers[m]);    free_string(tmp);    b_markers[m]=pop_unfinished_type();   #ifdef PIKE_TYPE_DEBUG    {    char *s;    int e;    init_buf();    for(e=0;e<indent;e++) my_strcat(" ");    my_strcat("b_markers[");
pike.git/src/pike_types.c:1781:    ret=low_pike_types_le(a+2,b);    if(ret && EXTRACT_UCHAR(b)!=T_VOID)    {    int m=EXTRACT_UCHAR(a+1)-'0';    struct pike_string *tmp;    type_stack_mark();    push_unfinished_type_with_markers(b, b_markers);    tmp=pop_unfinished_type();       type_stack_mark(); -  medium_or_pike_types(a_markers[m], tmp); +  medium_or_pike_types(a_markers[m], tmp, 0);    if(a_markers[m]) free_string(a_markers[m]);    free_string(tmp);    a_markers[m]=pop_unfinished_type();   #ifdef PIKE_TYPE_DEBUG    {    char *s;    int e;    init_buf();    for(e=0;e<indent;e++) my_strcat(" ");    my_strcat("a_markers[");
pike.git/src/pike_types.c:1846:    ret=low_pike_types_le(a,b+2);    if(ret && EXTRACT_UCHAR(a)!=T_VOID)    {    int m=EXTRACT_UCHAR(b+1)-'0';    struct pike_string *tmp;    type_stack_mark();    push_unfinished_type_with_markers(a, a_markers);    tmp=pop_unfinished_type();       type_stack_mark(); -  medium_or_pike_types(b_markers[m], tmp); +  medium_or_pike_types(b_markers[m], tmp, 0);    if(b_markers[m]) free_string(b_markers[m]);    free_string(tmp);    b_markers[m]=pop_unfinished_type();   #ifdef PIKE_TYPE_DEBUG    {    char *s;    int e;    init_buf();    for(e=0;e<indent;e++) my_strcat(" ");    my_strcat("b_markers[");
pike.git/src/pike_types.c:2116:    type_stack_mark();    }       if(low_get_return_type(a+type_length(a),b))    o2=pop_unfinished_type();    else    pop_stack_mark();       if(!o1 && !o2) return 0;    -  medium_or_pike_types(o1,o2); +  medium_or_pike_types(o1,o2, 0);       if(o1) free_string(o1);    if(o2) free_string(o2);       return 1;    }       case T_AND:    a++;    type_stack_mark();
pike.git/src/pike_types.c:2186:   int pike_types_le(struct pike_string *a,struct pike_string *b)   {    check_type_string(a);    check_type_string(b);    clear_markers();    return low_pike_types_le(a->str, b->str);   }         #ifdef DEBUG_MALLOC - #define low_index_type(X,Y) ((struct pike_string *)debug_malloc_touch(debug_low_index_type((X),(Y)))) + #define low_index_type(X,Y,Z) ((struct pike_string *)debug_malloc_touch(debug_low_index_type((X),(Y),(Z))))   #else   #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) + static struct pike_string *debug_low_index_type(char *t, +  char *index_type, +  node *n)   { -  +  struct pike_string *tmp;    struct program *p; -  +  switch(low_check_indexing(t, index_type, n)) +  { +  case 0: return 0; +  case -1: +  reference_shared_string(zero_type_string); +  return zero_type_string; +  } +     switch(EXTRACT_UCHAR(t++))    {    case T_OBJECT:    {    p=id_to_program(extract_type_int(t+1));       comefrom_int_index:    if(p && n)    { -  +  INT32 i;    if(n->token == F_ARROW)    { -  if(FIND_LFUN(p,LFUN_ARROW)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW)!=-1) +  /* FIXME: make this stricter */ +  if((i=FIND_LFUN(p,LFUN_ARROW))!=-1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW)!=-1)    { -  +  /* FIXME: function_type_string should be replaced with something +  * derived from type_string +  */ +  if(i!=-1 && (tmp=check_call(function_type_string, ID_FROM_INT(p, i)->type))) +  return tmp; +     reference_shared_string(mixed_type_string);    return mixed_type_string;    }    }else{ -  if(FIND_LFUN(p,LFUN_INDEX) != -1 || FIND_LFUN(p,LFUN_ASSIGN_INDEX) != -1) +  if((i=FIND_LFUN(p,LFUN_INDEX)) != -1 || FIND_LFUN(p,LFUN_ASSIGN_INDEX) != -1)    { -  +  /* FIXME: function_type_string should be replaced with something +  * derived from type_string +  */ +  if(i!=-1 && (tmp=check_call(function_type_string, ID_FROM_INT(p, i)->type))) +  return tmp; +     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(mixed_type_string);    return mixed_type_string;    }else{   #if 0    if(EXTRACT_UCHAR(t) ||    (p->identifier_references[i].id_flags & ID_NOMASK) ||    (ID_FROM_INT(p, i)->identifier_flags & IDENTIFIER_PROTOTYPED))
pike.git/src/pike_types.c:2266:    goto comefrom_int_index;   #endif    case T_ZERO:    case T_VOID:    case T_FLOAT:    return 0;       case T_OR:    {    struct pike_string *a,*b; -  a=low_index_type(t,n); +  a=low_index_type(t,index_type,n);    t+=type_length(t); -  b=low_index_type(t,n); +  b=low_index_type(t,index_type,n);    if(!b) return a;    if(!a) return b;    type_stack_mark(); -  medium_or_pike_types(a,b); +  medium_or_pike_types(a,b,1);    free_string(a);    free_string(b);    return pop_unfinished_type();    }       case T_AND: -  return low_index_type(t+type_length(t),n); +  return low_index_type(t+type_length(t),index_type,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);    return make_shared_binary_string(t, type_length(t));       case T_ARRAY:    if(n &&    (CDR(n)->token == F_CONSTANT ?    (CDR(n)->u.sval.type == T_STRING) :    !!low_match_types(string_type_string->str,CDR(n)->type->str,0)))    { -  struct pike_string *a=low_index_type(t,n); +  struct pike_string *a=low_index_type(t,index_type,n);    if(!a)    return make_shared_binary_string(t, type_length(t));       type_stack_mark();    push_finished_type(a);    free_string(a);    push_type(T_ARRAY);    if(low_match_types(int_type_string->str,CDR(n)->type->str,0))    {    push_unfinished_type(t);    push_type(T_OR);    }    return pop_unfinished_type();    }else{    return make_shared_binary_string(t, type_length(t));    }    }   }    - struct pike_string *index_type(struct pike_string *type, node *n) + struct pike_string *index_type(struct pike_string *type, +  struct pike_string *index_type, +  node *n)   {    struct pike_string *t;    clear_markers(); -  t=low_index_type(type->str,n); +  t=low_index_type(type->str,index_type->str,n);    if(!t) copy_shared_string(t,mixed_type_string);    return t;   }         #ifdef DEBUG_MALLOC   #define low_key_type(X,Y) ((struct pike_string *)debug_malloc_touch(debug_low_key_type((X),(Y))))   #else   #define low_key_type debug_low_key_type   #endif
pike.git/src/pike_types.c:2379:       case T_OR:    {    struct pike_string *a,*b;    a=low_key_type(t,n);    t+=type_length(t);    b=low_key_type(t,n);    if(!b) return a;    if(!a) return b;    type_stack_mark(); -  medium_or_pike_types(a,b); +  medium_or_pike_types(a,b,1);    free_string(a);    free_string(b);    return pop_unfinished_type();    }       case T_AND:    return low_key_type(t+type_length(t),n);       case T_ARRAY:    case T_STRING: /* always int */
pike.git/src/pike_types.c:2423:    {    case T_OR:    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,n) &&    low_check_indexing(type+type_length(type),index_type,n);       case T_NOT: -  return !low_check_indexing(type,index_type,n); +  return low_check_indexing(type,index_type,n)!=1;       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:
pike.git/src/pike_types.c:2454:    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 +  return low_match_types(type,index_type,0) ? 1 : -1;      #ifdef AUTO_BIGNUM    case T_INT:   #endif    case T_PROGRAM:    return !!low_match_types(string_type_string->str, index_type,0);       case T_MIXED:    return 1;   
pike.git/src/pike_types.c:2620:   struct pike_string *zzap_function_return(char *a, INT32 id)   {    switch(EXTRACT_UCHAR(a))    {    case T_OR:    {    struct pike_string *ar, *br, *ret=0;    a++;    ar=zzap_function_return(a,id);    br=zzap_function_return(a+type_length(a),id); -  if(ar && br) ret=or_pike_types(ar,br); +  if(ar && br) ret=or_pike_types(ar,br,0);    if(ar) free_string(ar);    if(br) free_string(br);    return ret;    }       case T_FUNCTION:    type_stack_mark();    push_type_int(id);    push_type(1);    push_type(T_OBJECT);