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.161 2001/03/05 21:32:52 grubba Exp $"); + RCSID("$Id: pike_types.c,v 1.162 2001/03/17 16:37:43 grubba 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:409:    *Pike_compiler->type_stackp = mk_type(T_SCOPE,    (void *)(ptrdiff_t)level,    *Pike_compiler->type_stackp,    PT_COPY_CDR);       TYPE_STACK_DEBUG("push_scope_type");   }      void push_assign_type(int marker)   { + #ifdef PIKE_DEBUG +  if ((marker < '0') || (marker > '9')) { +  fatal("Bad assign marker: %d\n", marker); +  } + #endif /* PIKE_DEBUG */    *Pike_compiler->type_stackp = mk_type(T_ASSIGN,    (void *)(ptrdiff_t)marker,    *Pike_compiler->type_stackp,    PT_COPY_CDR);    TYPE_STACK_DEBUG("push_assign_type");   }      void push_type_name(struct pike_string *name)   {    /* fprintf(stderr, "push_type_name(\"%s\")\n", name->str); */
pike.git/src/pike_types.c:456:    --Pike_compiler->type_stackp;    *Pike_compiler->type_stackp = mk_type(type,    *(Pike_compiler->type_stackp+1),    *Pike_compiler->type_stackp,    PT_COPY_BOTH);    break;       case T_ARRAY:    case T_MULTISET:    case T_NOT: +  case T_TYPE:    /* Make a new type of the top type, and put it in car. */    *Pike_compiler->type_stackp = mk_type(type,    *Pike_compiler->type_stackp, NULL,    PT_COPY_CAR);    break;       case T_SCOPE:    case T_ASSIGN:    case T_INT:    case T_OBJECT:    case PIKE_T_NAME:    default:    /* Should not occurr. */    fatal("");    break;       case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_ZERO:    case PIKE_T_UNKNOWN:    /* Leaf type. */    *(++Pike_compiler->type_stackp) = mk_type(type, NULL, NULL, 0);    break;       case '0':
pike.git/src/pike_types.c:524:    case T_MAPPING:    case T_OR:    case T_AND:    /* Both car & cdr. */    push_finished_type(top->cdr);    push_finished_type(top->car);    break;    case T_ARRAY:    case T_MULTISET:    case T_NOT: +  case T_TYPE:    /* car */    push_finished_type(top->car);    break;    case T_SCOPE:    case T_ASSIGN:    /* cdr */    push_finished_type(top->cdr);    break;    case T_INT:    case T_OBJECT:    case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_ZERO:    case PIKE_T_UNKNOWN:    case '0':    case '1':    case '2':    case '3':    case '4':
pike.git/src/pike_types.c:824:    internal_parse_type(_s);    if(**s != ')') Pike_error("Expecting ')'.\n");    ++*s;    }else{    push_type(T_MIXED);    push_type(T_MIXED);    }    push_reverse_type(T_TUPLE);    break;    } -  if(!strcmp(buf,"type")) { push_type(T_TYPE); break; } +  /* FIXME: Handle type(T) */ +  if(!strcmp(buf,"type")) { push_type(T_MIXED); push_type(T_TYPE); 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 == '(')    {    ++*s;
pike.git/src/pike_types.c:1116: Inside #if defined(PIKE_DEBUG)
   {    INT32 min = (ptrdiff_t)s->car;    INT32 max = (ptrdiff_t)s->cdr;    printf("int");    if(min!=MIN_INT32 || max!=MAX_INT32)    printf("(%ld..%ld)",(long)min,(long)max);    break;    }    case T_FLOAT: printf("float"); break;    case T_STRING: printf("string"); break; -  case T_TYPE: printf("type"); break; +  case T_TYPE: +  printf("type("); +  simple_describe_type(s->car); +  printf(")"); +  break;    case T_PROGRAM: printf("program"); break;    case T_OBJECT:    printf("object(%s %ld)",    s->car?"is":"implements",    (long)(ptrdiff_t)s->cdr);    break;    case T_FUNCTION:    case T_MANY:    printf("function(");    while(s->type == T_FUNCTION) {
pike.git/src/pike_types.c:1262:    sprintf(buffer,"object(%s %ld)",    t->car?"is":"implements",    (long)(ptrdiff_t)t->cdr);    my_strcat(buffer);    }else{    my_strcat("object");    }    break;       case T_STRING: my_strcat("string"); break; -  case T_TYPE: my_strcat("type"); break; +  case T_TYPE: +  my_strcat("type("); +  my_describe_type(t->car); +  my_strcat(")"); +  break;       case PIKE_T_NAME:    if (!((struct pike_string *)t->car)->size_shift) {    my_strcat("{ ");    my_binary_strcat(((struct pike_string *)t->car)->str,    ((struct pike_string *)t->car)->len);    my_strcat(" = ");    my_describe_type(t->cdr);    my_strcat(" }");    } else {
pike.git/src/pike_types.c:1636:    {    is_complex |= lower_and_pike_types(t1->car, t2);    t1 = t1->cdr;    }    switch(t1->type) {    case T_ZERO:    case T_VOID:    break;    case T_PROGRAM:    case T_STRING: -  case T_TYPE: +     case T_FLOAT:    case T_INT:    even_lower_and_pike_types(t1, t2);    break;    default:    return 1;    }    return is_complex;   }   
pike.git/src/pike_types.c:1668:    is_complex = 1;    }    }    type = type->cdr;    }    switch(type->type) {    case T_VOID:    case T_ZERO:    case T_PROGRAM:    case T_STRING: -  case T_TYPE: +     case T_FLOAT:    case T_INT:    /* Simple type. Already handled. */    break;    default:    push_finished_type(type);    if (is_complex) {    push_type(T_OR);    }    return 1;
pike.git/src/pike_types.c:1744:    push_scope_type((ptrdiff_t)t1->car);    }    }    else if (t2->type == T_SCOPE)    {    low_and_pike_types(t1, t2->cdr);    push_scope_type((ptrdiff_t)t2->car);    }    else if((t1->type == t2->type) &&    ((t1->type == T_STRING) || -  (t1->type == T_TYPE) || +     (t1->type == T_FLOAT) ||    (t1->type == T_PROGRAM)))    {    push_finished_type(t1);    }    else if(low_pike_types_le(t1, t2, 0, 0))    {    push_finished_type(t1);    }    else if(low_pike_types_le(t2, t1, 0, 0))
pike.git/src/pike_types.c:2294:    INT32 amax = (ptrdiff_t)a->cdr;       INT32 bmin = (ptrdiff_t)b->car;    INT32 bmax = (ptrdiff_t)b->cdr;       if(amin > bmax || bmin > amax) return 0;    break;    }       +  case T_TYPE:    case T_MULTISET:    case T_ARRAY:    if(!low_match_types(a->car, b->car,    flags & ~(A_EXACT|B_EXACT))) return 0;       case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_ZERO:    case T_VOID:    case T_MIXED:    break;       default:    fatal("Error in type string.\n");    }    return ret;
pike.git/src/pike_types.c:2821:    INT32 amax = (ptrdiff_t)a->cdr;       INT32 bmin = (ptrdiff_t)b->car;    INT32 bmax = (ptrdiff_t)b->cdr;       if(amin < bmin || amax > bmax) return 0;    break;    }       +  case T_TYPE:    case T_MULTISET:    case T_ARRAY:    a = a->car;    b = b->car;    array_cnt = 0;    goto recurse;       case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_ZERO:    case T_VOID:    case T_MIXED:    break;       default:    fatal("Error in type string.\n");    }    return 1;
pike.git/src/pike_types.c:3733:    return a;    }       type_stack_mark();    push_object_type(1, s->u.program->id);    push_type(T_VOID);    push_type(T_MANY);    return pop_unfinished_type();    }    +  case T_TYPE: +  type_stack_mark(); +  push_finished_type(s->u.type); +  push_type(T_TYPE); +  return pop_unfinished_type(); +     default:    type_stack_mark();    push_type(s->type);    return pop_unfinished_type();    }   }         static struct pike_type *low_object_type_to_program_type(struct pike_type *obj_t)   {
pike.git/src/pike_types.c:3914:    return mk_type(type, low_make_pike_type(type_string+1, cont),    low_make_pike_type(*cont, cont), PT_COPY_BOTH);    case T_OR:    case T_AND:    /* Order independant */    /* FIXME: */    return mk_type(type, low_make_pike_type(type_string+1, cont),    low_make_pike_type(*cont, cont), PT_COPY_BOTH);    case T_ARRAY:    case T_MULTISET: +  case T_TYPE:    case T_NOT:    /* Single type */    return mk_type(type, low_make_pike_type(type_string+1, cont), NULL,    PT_COPY_CAR);    case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':    case '8':    case '9':    /* Marker type */    *cont = type_string+1;    return mk_type(type, NULL, NULL, PT_SET_MARKER);       case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_ZERO:    case PIKE_T_UNKNOWN:    /* Leaf type */    *cont = type_string+1;    return mk_type(type, NULL, NULL, 0);       case T_INT:
pike.git/src/pike_types.c:4104:    t++;       case T_TUPLE:    case T_MAPPING:    case T_OR:    case T_AND:    t+=type_length(t);       case T_ARRAY:    case T_MULTISET: +  case T_TYPE:    case T_NOT:    goto one_more_type;       case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':    case '8':    case '9':    case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_ZERO:    case PIKE_T_UNKNOWN:    break;       case T_INT:    t+=sizeof(INT32)*2;    break;
pike.git/src/pike_types.c:4475:    if(**s != ')') Pike_error("Expecting ')'.\n");    ++*s;    type_stack_reverse();    }else{    push_type(T_MIXED);    push_type(T_MIXED);    }    push_type(T_TUPLE);    break;    } -  if(!strcmp(buf,"type")) { push_type(T_TYPE); break; } +  /* FIXME: Support for type(T). */ +  if(!strcmp(buf,"type")) { push_type(T_MIXED); push_type(T_TYPE); 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();
pike.git/src/pike_types.c:4815:    (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; -  case T_TYPE: my_strcat("type"); break; +  case T_TYPE: +  my_strcat("type("); +  t = low_describe_type(t); +  my_strcat(")"); +  break;       case T_FUNCTION:    {    int s;    my_strcat("function");    if(EXTRACT_UCHAR(t) == T_MANY &&    ((EXTRACT_UCHAR(t+1) == T_ZERO &&    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)))
pike.git/src/pike_types.c:5210:    t1++;    is_complex |= lower_and_pike_types(t1, t2);    t1 += type_length(t1);    }    switch(EXTRACT_UCHAR(t1)) {    case T_ZERO:    case T_VOID:    break;    case T_PROGRAM:    case T_STRING: -  case T_TYPE: +     case T_FLOAT:    case T_INT:    even_lower_and_pike_types(t1, t2);    break;    default:    return 1;    }    return is_complex;   }   
pike.git/src/pike_types.c:5243:    is_complex = 1;    }    }    type += type_length(type);    }    switch(EXTRACT_UCHAR(type)) {    case T_VOID:    case T_ZERO:    case T_PROGRAM:    case T_STRING: -  case T_TYPE: +     case T_FLOAT:    case T_INT:    /* Simple type. Already handled. */    break;    default:    push_unfinished_type(type);    if (is_complex) {    push_type(T_OR);    }    return 1;
pike.git/src/pike_types.c:5321:    }    push_type(T_SCOPE);    }    else if (EXTRACT_UCHAR(t2) == T_SCOPE)    {    low_and_pike_types(t1, t2+2);    push_type(EXTRACT_UCHAR(t2+1));    push_type(T_SCOPE);    }    else if((EXTRACT_UCHAR(t1)==T_STRING && EXTRACT_UCHAR(t2)==T_STRING) || -  (EXTRACT_UCHAR(t1)==T_TYPE && EXTRACT_UCHAR(t2)==T_TYPE) || +     (EXTRACT_UCHAR(t1)==T_FLOAT && EXTRACT_UCHAR(t2)==T_FLOAT) ||    (EXTRACT_UCHAR(t1)==T_PROGRAM && EXTRACT_UCHAR(t2)==T_PROGRAM))    {    push_unfinished_type(t1);    }    else if(low_pike_types_le(t1, t2, 0, 0))    {    push_unfinished_type(t1);    }    else if(low_pike_types_le(t2, t1, 0, 0))
pike.git/src/pike_types.c:5860:    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_TYPE:    case T_MULTISET:    case T_ARRAY:    if(!low_match_types(++a,++b,flags & ~(A_EXACT|B_EXACT))) return 0;       case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_ZERO:    case T_VOID:    case T_MIXED:    break;       default:    fatal("Error in type string.\n");    }    return ret;
pike.git/src/pike_types.c:6372:    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 < bmin || amax > bmax) return 0;    break;    }       +  case T_TYPE:    case T_MULTISET:    case T_ARRAY:    if(!low_pike_types_le(++a, ++b, 0, flags)) return 0;       case T_FLOAT:    case T_STRING: -  case T_TYPE: +     case T_PROGRAM:    case T_ZERO:    case T_VOID:    case T_MIXED:    break;       default:    fatal("Error in type string.\n");    }    return 1;
pike.git/src/pike_types.c:7249:       type_stack_mark();    push_object_type(1, s->u.program->id);    push_type(T_VOID);    push_type(T_MANY);    push_type(T_FUNCTION);       return pop_unfinished_type();    }    +  case T_TYPE: +  type_stack_mark(); +  push_finished_type(s->u.type); +  push_type(T_TYPE); +  return pop_unfinished_type(); +     default:    type_stack_mark();    push_type(s->type);    return pop_unfinished_type();    }   }      static struct pike_type *low_object_type_to_program_type(char *obj_t)   {    struct pike_type *res = NULL;
pike.git/src/pike_types.c:7454:    string_type_string = CONSTTYPE(tString);    int_type_string = CONSTTYPE(tInt);    object_type_string = CONSTTYPE(tObj);    program_type_string = CONSTTYPE(tPrg);    float_type_string = CONSTTYPE(tFloat);    mixed_type_string = CONSTTYPE(tMix);    array_type_string = CONSTTYPE(tArray);    multiset_type_string = CONSTTYPE(tMultiset);    mapping_type_string = CONSTTYPE(tMapping);    function_type_string = CONSTTYPE(tFunction); -  type_type_string = CONSTTYPE(tType); +  type_type_string = CONSTTYPE(tType(tMix));    void_type_string = CONSTTYPE(tVoid);    zero_type_string = CONSTTYPE(tZero);    any_type_string = CONSTTYPE(tOr(tVoid,tMix));    weak_type_string = CONSTTYPE(tOr4(tArray,tMultiset,tMapping,    tFuncV(tNone,tZero,tOr(tMix,tVoid))));   }      void cleanup_pike_types(void)   {    free_type(string_type_string);