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.162 2001/03/17 16:37:43 grubba Exp $"); + RCSID("$Id: pike_types.c,v 1.163 2001/03/18 00:59:34 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); +  marker -= '0'; + #ifdef PIKE_DEBUG */ +  if ((marker < 0) || (marker > 9)) { +  fatal("Bad assign marker: %ld\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:475:    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(""); +  fatal("Unsupported argument to push_type().\n");    break;       case T_FLOAT:    case T_STRING:    case T_PROGRAM:    case T_MIXED:    case T_VOID:    case T_ZERO:    case PIKE_T_UNKNOWN:    /* Leaf type. */
pike.git/src/pike_types.c:629:    goto recurse;    } else {    push_type(T_ZERO);    }    TYPE_STACK_DEBUG("push_finished_type_with_markers");    return;    }    if (type->type == T_ASSIGN) {    /* Strip assign */   #if 0 -  fprintf(stderr, "Assign to marker %d.\n", ((ptrdiff_t)type->car)-'0'); +  fprintf(stderr, "Assign to marker %d.\n", ((ptrdiff_t)type->car));   #endif /* 0 */    type = type->cdr;    goto recurse;    }    if (type->type == PIKE_T_NAME) {    /* Strip the name, since it won't be correct anymore. */    type = type->cdr;    goto recurse;    }    /* FIXME: T_SCOPE */
pike.git/src/pike_types.c:1216:    /**** FIXME: ****/    switch(t->type)    {    case '0': case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8': case '9':    my_putchar(t->type);    break;       case T_ASSIGN:    my_putchar('('); -  my_putchar((ptrdiff_t)t->car); +  my_putchar('0' + (ptrdiff_t)t->car);    my_putchar('=');    my_describe_type(t->cdr);    my_putchar(')');    break;       case T_SCOPE:    my_putchar('{');    my_putchar((ptrdiff_t)t->car);    my_putchar(',');    my_describe_type(t->cdr);
pike.git/src/pike_types.c:1932:       case T_NOT:    if(low_match_types(a->car, b, (flags ^ B_EXACT ) | NO_MAX_ARGS))    return 0;    return a;       case T_ASSIGN:    ret = low_match_types(a->cdr, b, flags);    if(ret && (b->type != T_VOID))    { -  int m = ((ptrdiff_t)a->car)-'0'; +  int m = (ptrdiff_t)a->car;    struct pike_type *tmp; -  +  + #ifdef PIKE_DEBUG +  if ((m < 0) || (m > 9)) { +  fatal("marker out of range: %d\n", m); +  } + #endif /* PIKE_DEBUG */ +     type_stack_mark();    push_finished_type_with_markers(b, b_markers);    tmp = pop_unfinished_type();       type_stack_mark();    low_or_pike_types(a_markers[m], tmp, 0);    if(a_markers[m]) free_type(a_markers[m]);    free_type(tmp);    a_markers[m] = pop_unfinished_type();   
pike.git/src/pike_types.c:2016:       case T_NOT:    if(low_match_types(a, b->car, (flags ^ A_EXACT ) | NO_MAX_ARGS))    return 0;    return a;       case T_ASSIGN:    ret = low_match_types(a, b->cdr, flags);    if(ret && (a->type != T_VOID))    { -  int m = ((ptrdiff_t)b->car)-'0'; +  int m = (ptrdiff_t)b->car;    struct pike_type *tmp;    type_stack_mark();    push_finished_type_with_markers(a, a_markers);    tmp=pop_unfinished_type();       type_stack_mark();    low_or_pike_types(b_markers[m], tmp, 0);    if(b_markers[m]) free_type(b_markers[m]);    free_type(tmp);    b_markers[m] = pop_unfinished_type();
pike.git/src/pike_types.c:2457:    if (low_pike_types_le(a->car, b, array_cnt, flags)) {    return 0;    }    /* FIXME: This is wrong... */    return !low_pike_types_le(b, a->car, -array_cnt, flags);       case T_ASSIGN:    ret = low_pike_types_le(a->cdr, b, array_cnt, flags);    if(ret && (b->type != T_VOID))    { -  int m = ((ptrdiff_t)a->car)-'0'; +  int m = (ptrdiff_t)a->car;    struct pike_type *tmp;    int i;    type_stack_mark();    push_finished_type_with_markers(b, b_markers);    for(i=array_cnt; i > 0; i--)    push_type(T_ARRAY);    tmp=pop_unfinished_type();       type_stack_mark();    low_or_pike_types(a_markers[m], tmp, 0);
pike.git/src/pike_types.c:2537:    if (low_pike_types_le(a, b->car, array_cnt, flags)) {    return 0;    }    /* FIXME: This is wrong... */    return !low_pike_types_le(b->car, a, -array_cnt, flags);       case T_ASSIGN:    ret = low_pike_types_le(a, b->cdr, array_cnt, flags);    if(ret && (a->type != T_VOID))    { -  int m = ((ptrdiff_t)b->car)-'0'; +  int m = (ptrdiff_t)b->car;    struct pike_type *tmp;    int i;    type_stack_mark();    push_finished_type_with_markers(a, a_markers);    for(i = array_cnt; i < 0; i++)    push_type(T_ARRAY);    tmp=pop_unfinished_type();       type_stack_mark();    low_or_pike_types(b_markers[m], tmp, 0);
pike.git/src/pike_types.c:3912:   }      static struct pike_type *low_make_pike_type(unsigned char *type_string,    unsigned char **cont)   {    unsigned INT32 type;       switch(type = *type_string) {    case T_SCOPE:    case T_ASSIGN: -  return mk_type(type, (void *)(ptrdiff_t)(type_string[1]), +  if ((type_string[1] < '0') || (type_string[1] > '9')) { +  fatal("low_make_pike_type(): Bad marker: %d\n", type_string[1]); +  } +  return mk_type(type, (void *)(ptrdiff_t)(type_string[1] - '0'),    low_make_pike_type(type_string+2, cont), PT_COPY_CDR);    case T_FUNCTION:    /* Multiple ordered values. */    /* FIXME: */    return low_make_function_type(type_string+1, cont);    case T_TUPLE:    case T_MAPPING:    /* Order dependant */    return mk_type(type, low_make_pike_type(type_string+1, cont),    low_make_pike_type(*cont, cont), PT_COPY_BOTH);
pike.git/src/pike_types.c:4040:    case T_VOID:    return 1;    default:    fatal("pike_type_allow_premature_toss: Unknown type code (%d)\n",    ((unsigned char *)type)[-1]);    /* NOT_REACHED */    return 0;    }   }    + static void low_type_to_string(struct pike_type *t) + { +  recurse: +  switch(t->type) { +  case T_ARRAY: +  case T_MULTISET: +  case T_TYPE: +  case T_NOT: +  my_putchar(t->type); +  /* FALL_THROUGH */ +  case PIKE_T_NAME: +  t = t->car; +  goto recurse; +  +  case T_TUPLE: +  case T_MAPPING: +  case T_OR: +  case T_AND: +  my_putchar(t->type); +  low_type_to_string(t->car); +  t = t->cdr; +  goto recurse; +  +  case T_PROGRAM: +  case T_STRING: +  case T_FLOAT: +  case T_ZERO: +  case T_VOID: +  case T_MIXED: +  my_putchar(t->type); +  break; +  +  case T_OBJECT: +  if (t->car || t->cdr) { +  Pike_error("Not supported yet!\n"); +  } else { +  my_strcat(tObj); +  } +  break; +  +  case T_INT: +  { +  INT32 i; +  my_putchar(T_INT); +  i = (INT32)(ptrdiff_t)t->car; +  my_putchar((i >> 24) & 0xff); +  my_putchar((i >> 16) & 0xff); +  my_putchar((i >> 8) & 0xff); +  my_putchar(i & 0xff); +  i = (INT32)(ptrdiff_t)t->cdr; +  my_putchar((i >> 24) & 0xff); +  my_putchar((i >> 16) & 0xff); +  my_putchar((i >> 8) & 0xff); +  my_putchar(i & 0xff); +  } +  break; +  +  case T_FUNCTION: +  case T_MANY: +  my_putchar(T_FUNCTION); +  while(t->type == T_FUNCTION) { +  low_type_to_string(t->car); +  t = t->cdr; +  } +  my_putchar(T_MANY); +  low_type_to_string(t->car); +  t = t->cdr; +  goto recurse; +  +  case T_SCOPE: +  case T_ASSIGN: +  my_putchar(t->type); +  my_putchar('0' + (ptrdiff_t)t->car); +  t = t->cdr; +  goto recurse; +  } + } +    #else /* !USE_PIKE_TYPE */      static void internal_parse_type(char **s);   static ptrdiff_t type_length(const char *t);   static int low_pike_types_le(char *a, char *b,    int array_cnt, unsigned int flags);   static int low_check_indexing(char *type, char *index_type, node *n);      #define EXTRACT_TWOT(X,Y) TWOT(EXTRACT_UCHAR(X), EXTRACT_UCHAR(Y))   
pike.git/src/pike_types.c:7460:    return 0;   }      int pike_type_allow_premature_toss(struct pike_type *type)   {    return low_pike_type_allow_premature_toss(type->str);   }      #endif /* USE_PIKE_TYPE */    + struct pike_string *type_to_string(struct pike_type *t) + { + #ifdef USE_PIKE_TYPE +  init_buf(); +  low_type_to_string(t); +  return free_buf(); + #else /* !USE_PIKE_TYPE */ +  add_ref(t); +  return t; + #endif /* USE_PIKE_TYPE */ + } +    void init_types(void)   {   #ifdef USE_PIKE_TYPE    /* Initialize hashtable here. */    pike_type_hash = (struct pike_type **)xalloc(sizeof(struct pike_type *) *    PIKE_TYPE_HASH_SIZE);    MEMSET(pike_type_hash, 0, sizeof(struct pike_type *) * PIKE_TYPE_HASH_SIZE);    pike_type_hash_size = PIKE_TYPE_HASH_SIZE;   #endif /* USE_PIKE_TYPE */    string_type_string = CONSTTYPE(tString);