pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: pike_types.c,v 1.261 2007/01/10 19:09:14 grubba Exp $ + || $Id: pike_types.c,v 1.262 2007/03/03 16:46:13 grubba Exp $   */      #include "global.h"   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"   #include "stralloc.h"   #include "stuff.h"   #include "array.h"   #include "program.h"
pike.git/src/pike_types.c:151:    case T_FLOAT: return "float";    case T_MANY: case T_FUNCTION: return "function";    case T_INT: return "int";    case T_SVALUE_PTR: return "svalue_ptr";    case T_OBJ_INDEX: return "obj_index";    case T_MAPPING: return "mapping";    case T_MULTISET: return "multiset";    case T_OBJECT: return "object";    case T_PROGRAM: return "program";    case T_STRING: return "string"; +  case PIKE_T_NSTRING: return "narrow_string";    case T_TYPE: return "type";    case T_ZERO: return "zero";    case T_VOID: return "void";    case T_MIXED: return "mixed";    case T_STORAGE: return "object storage";    case T_MAPPING_DATA: return "mapping_data";    case T_PIKE_FRAME: return "pike_frame";    case T_MULTISET_DATA: return "multiset_data";    case T_STRUCT_CALLABLE: return "callable";    case PIKE_T_GET_SET: return "getter/setter";
pike.git/src/pike_types.c:197:    * RING type type    * TUPLE type type    * MAPPING index type value type    * OR type type    * AND type type    * ARRAY type -    * MULTISET type -    * NOT type -    * '0'-'9' - -    * FLOAT - - -  * STRING - - +  * STRING bitwidth (int) - Width added in 7.7    * TYPE type -    * PROGRAM type -    * MIXED - -    * VOID - -    * ZERO - -    * UNKNOWN - -    * INT min (int) max (int)    * OBJECT implements/is object id(int)    *    * Note that the cdr of a FUNCTION is a valid FUNCTION for the rest of
pike.git/src/pike_types.c:644:    min, max);   #endif /* PIKE_DEBUG */       *(++Pike_compiler->type_stackp) = mk_type(T_INT,    (void *)(ptrdiff_t)min,    (void *)(ptrdiff_t)max, 0);       TYPE_STACK_DEBUG("push_int_type");   }    + void debug_push_string_type(INT32 bitwidth) + { +  if ((bitwidth < 0) || (bitwidth > 32)) { +  my_yyerror("Invalid string width: %ld (expected 0..32).", +  (long)bitwidth); +  bitwidth = 32; +  } +  +  *(++Pike_compiler->type_stackp) = mk_type(T_STRING, +  (void *)(ptrdiff_t)bitwidth, +  NULL, 0); +  +  TYPE_STACK_DEBUG("push_string_type"); + } +    void debug_push_object_type(int flag, INT32 id)   {    *(++Pike_compiler->type_stackp) = mk_type(T_OBJECT,    (void *)(ptrdiff_t)flag,    (void *)(ptrdiff_t)id, 0);       TYPE_STACK_DEBUG("push_object_type");   }      void debug_push_object_type_backwards(int flag, INT32 id)
pike.git/src/pike_types.c:746:    PT_COPY_CAR);    break;       case T_SCOPE:    case T_ASSIGN:    case T_INT:    case T_OBJECT:    case PIKE_T_NAME:    default:    /* Should not occur. */ -  Pike_fatal("Unsupported argument to push_type().\n"); +  Pike_fatal("Unsupported argument to push_type(): %d\n", type);    break;    -  case T_FLOAT: +     case T_STRING: -  +  Pike_fatal("String types should not be created with push_type().\n"); +  break; +  +  case T_FLOAT:    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':    case '1':
pike.git/src/pike_types.c:985:    push_type(T_OR);    }    if (field & BIT_PROGRAM) {    push_object_type(0, 0);    push_type(T_PROGRAM);    push_type(T_OR);    }    }    if (field & BIT_BASIC) {    if (field & BIT_STRING) { -  push_type(T_STRING); +  push_string_type(32);    push_type(T_OR);    }    if (field & BIT_TYPE) {    push_type(T_MIXED);    push_type(T_TYPE);    push_type(T_OR);    }    if (field & BIT_INT) {    push_int_type(MIN_INT32, MAX_INT32);    push_type(T_OR);
pike.git/src/pike_types.c:1220:    case 'p':    if(!strcmp(buf,"program")) {    push_object_type(0, 0);    push_type(T_PROGRAM);    break;    }    goto bad_type;          case 's': -  if(!strcmp(buf,"string")) { push_type(T_STRING); break; } +  if(!strcmp(buf,"string")) { +  while(ISSPACE(**s)) ++*s; +  if(**s == '(') +  { +  INT32 bitwidth; +  ++*s; +  while(ISSPACE(**s)) ++*s; +  bitwidth=STRTOL((const char *)*s,(char **)s,0); +  while(ISSPACE(**s)) ++*s; +  if(**s != ')') yyerror("Missing ')' in string width."); +  else +  ++*s; +  push_string_type(bitwidth); +  } else { +  push_string_type(32); +  } +  break; +  }    goto bad_type;       case 'v':    if(!strcmp(buf,"void")) { push_type(T_VOID); break; }    goto bad_type;       case 't':    if (!strcmp(buf,"tuple"))    {    while(ISSPACE(**s)) ++*s;
pike.git/src/pike_types.c:1549: Inside #if defined(PIKE_DEBUG)
   case T_INT:    {    INT32 min = CAR_TO_INT(s);    INT32 max = CDR_TO_INT(s);    fprintf(stderr, "int");    if(min!=MIN_INT32 || max!=MAX_INT32)    fprintf(stderr, "(%ld..%ld)",(long)min,(long)max);    break;    }    case T_FLOAT: fprintf(stderr, "float"); break; -  case T_STRING: fprintf(stderr, "string"); break; +  case T_STRING: +  { +  INT32 bitwidth = CAR_TO_INT(s); +  if (bitwidth != 32) { +  fprintf(stderr, "string(%d)", bitwidth); +  } else { +  fprintf(stderr, "string"); +  } +  break; +  }    case T_TYPE:    fprintf(stderr, "type(");    simple_describe_type(s->car);    fprintf(stderr, ")");    break;    case T_PROGRAM:    fprintf(stderr, "program(");    simple_describe_type(s->car);    fprintf(stderr, ")");    break;
pike.git/src/pike_types.c:1664: Inside #if defined(PIKE_DEBUG) and #if defined(DEBUG_MALLOC)
   fprintf(stderr, " (refs:%ld)\n", (long)t->refs);    }    }    }   }   #endif /* DEBUG_MALLOC */   #endif      static void low_describe_type(struct pike_type *t)   { +  char buffer[100]; +     check_c_stack(1024);    /**** 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:
pike.git/src/pike_types.c:1709:    case T_MIXED: my_strcat("mixed"); break;    case PIKE_T_UNKNOWN: my_strcat("unknown"); break;    case T_INT:    {    INT32 min=CAR_TO_INT(t);    INT32 max=CDR_TO_INT(t);    my_strcat("int");       if(min!=MIN_INT32 || max!=MAX_INT32)    { -  char buffer[100]; +     sprintf(buffer,"(%ld..%ld)",(long)min,(long)max);    my_strcat(buffer);    }    break;    }    case T_FLOAT: my_strcat("float"); break;    case T_PROGRAM:    if ((t->car->type == T_OBJECT) &&    (!t->car->cdr)) {    my_strcat("program");
pike.git/src/pike_types.c:1739:    char buffer[100];    sprintf(buffer,"object(%s %"PRINTPTRDIFFT"d)",    t->car?"is":"implements",    CDR_TO_INT(t));    my_strcat(buffer);    }else{    my_strcat("object");    }    break;    -  case T_STRING: my_strcat("string"); break; +  case T_STRING: +  { +  INT32 bitwidth=CAR_TO_INT(t); +  my_strcat("string"); +  if (bitwidth != 32) { +  sprintf(buffer,"(%ld)",(long)bitwidth); +  my_strcat(buffer); +  } +  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,
pike.git/src/pike_types.c:2044:    push_finished_type(t2);    push_type(T_OR);    } else {    /* Overlap */    min1 = MINIMUM(min1, min2);    max1 = MAXIMUM(max1, max2);       push_int_type(min1, max1);    }    } +  else if (t1->type == T_STRING && t2->type == T_STRING) { +  INT32 w1 = CAR_TO_INT(t1); +  INT32 w2 = CAR_TO_INT(t2); +  if (w1 >= w2) { +  push_finished_type(t1); +  } else { +  push_finished_type(t2); +  } +  }    else if (t1->type == T_SCOPE)    {    if (t2->type == T_SCOPE) {    low_or_pike_types(t1->cdr, t2->cdr, zero_implied);    if (t1->car > t2->car)    push_scope_type(CAR_TO_INT(t1));    else    push_scope_type(CAR_TO_INT(t2));    } else {    low_or_pike_types(t1->cdr, t2, zero_implied);
pike.git/src/pike_types.c:2241:    } else {    low_and_pike_types(t1->cdr, t2);    push_scope_type(CAR_TO_INT(t1));    }    }    else if (t2->type == T_SCOPE)    {    low_and_pike_types(t1, t2->cdr);    push_scope_type(CAR_TO_INT(t2));    } -  else if((t1->type == t2->type) && -  ((t1->type == T_STRING) || -  (t1->type == T_FLOAT))) +  else if ((t1->type == T_STRING) && (t2->type == T_STRING)) { +  INT32 w1, w2; +  w1 = CAR_TO_INT(t1); +  w2 = CAR_TO_INT(t2); +  if (w1 < w2) { +  push_finished_type(t1); +  } else { +  push_finished_type(t2); +  } +  } +  else if((t1->type == T_FLOAT) && (t2->type == T_FLOAT))    {    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))    {    push_finished_type(t2);
pike.git/src/pike_types.c:3381:       case T_TYPE:    case T_PROGRAM:    case T_MULTISET:    case T_ARRAY:    a = a->car;    b = b->car;    array_cnt = 0;    goto recurse;    -  case T_FLOAT: +     case T_STRING: -  +  { +  INT32 awidth = CAR_TO_INT(a); +  INT32 bwidth = CAR_TO_INT(b); +  return awidth <= bwidth; +  } +  +  case T_FLOAT:    case T_ZERO:    case T_VOID:    case T_MIXED:    break;       default:    Pike_fatal("Error in type string.\n");    }    return 1;   }
pike.git/src/pike_types.c:3662:    free_type(a);    free_type(b);    return pop_unfinished_type();    }       case T_AND:    /* FIXME: Shouldn't both branches be looked at? */    return low_index_type(t->cdr, index_type, n);       case T_STRING: /* always int */ +  { +  int width = CAR_TO_INT(t); +  if (width != 32) { +  /* Narrow string */ +  type_stack_mark(); +  push_int_type(0, (1<<width)-1); +  return pop_unfinished_type(); +  } +  } +  /* FALL_THROUGH */    case T_MULTISET: /* always int */    add_ref(int_type_string);    return int_type_string;       case T_MAPPING:    add_ref(t = t->cdr);    return t;       case T_ARRAY:    {
pike.git/src/pike_types.c:4580:    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();    +  case T_STRING: +  type_stack_mark(); +  if (s->u.string->len) { +  /* FIXME: Could be extended to detect 7-bit strings, etc. */ +  push_string_type(8<<s->u.string->size_shift); +  } else { +  push_string_type(0); +  } +  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:4820:    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_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_STRING: +  *cont = type_string + 1; +  return mk_type(T_STRING, (void *)(ptrdiff_t)32, NULL, 0); +  +  case PIKE_T_NSTRING: +  *cont = type_string + 2; /* 1 + 1 */ +  /* FIXME: Add check for valid bitwidth (0..32). */ +  return mk_type(T_STRING, (void *)(ptrdiff_t)type_string[1], NULL, 0); +     case T_INT:    *cont = type_string + 9; /* 2*sizeof(INT32) + 1 */    return mk_type(T_INT,    (void *)(ptrdiff_t)extract_type_int((char *)type_string+1), -  (void *)(ptrdiff_t)extract_type_int((char *)type_string+5), 0); +  (void *)(ptrdiff_t)extract_type_int((char *)type_string+5), +  0);       case PIKE_T_INT_UNTYPED:    *cont = type_string + 1;    return mk_type(T_INT,    (void *)(ptrdiff_t)0x80000000,    (void *)(ptrdiff_t)0x7fffffff, 0);       case T_OBJECT:    *cont = type_string + 6; /* 1 + sizeof(INT32) + 1 */    return mk_type(T_OBJECT, (void *)(ptrdiff_t)(type_string[1]),
pike.git/src/pike_types.c:5033:    case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':    case '8':    case '9': -  case T_STRING: +     case T_FLOAT:    case T_ZERO:    case T_VOID:    case T_MIXED:    my_putchar(t->type);    break;       case T_OBJECT:    {    INT32 i;
pike.git/src/pike_types.c:5058:       if( i > 65535 ) i = 0; /* Not constant between recompilations */       my_putchar((i >> 24) & 0xff);    my_putchar((i >> 16) & 0xff);    my_putchar((i >> 8) & 0xff);    my_putchar(i & 0xff);    }    break;    +  case T_STRING: +  { +  INT32 width = (INT32)CAR_TO_INT(t); +  my_putchar(T_STRING); +  my_putchar((width >> 24) & 0xff); +  my_putchar((width >> 16) & 0xff); +  my_putchar((width >> 8) & 0xff); +  my_putchar(width & 0xff); +  } +  break; +     case T_INT:    {    INT32 i;    my_putchar(T_INT);    i = (INT32)CAR_TO_INT(t);    my_putchar((i >> 24) & 0xff);    my_putchar((i >> 16) & 0xff);    my_putchar((i >> 8) & 0xff);    my_putchar(i & 0xff);    i = (INT32)CDR_TO_INT(t);