Branch: Tag:

2001-03-05

2001-03-05 21:32:53 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Support for naming of types in USE_PIKE_TYPE-mode.
Fixed memory-leak in USE_PIKE_TYPE-mode.

Rev: src/language.yacc:1.232
Rev: src/pike_types.c:1.161
Rev: src/pike_types.h:1.62
Rev: src/svalue.h:1.78

5:   \*/   /**/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.160 2001/03/05 18:53:40 grubba Exp $"); + RCSID("$Id: pike_types.c,v 1.161 2001/03/05 21:32:52 grubba Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"
257:    /* Free cdr */    t = cdr;    goto loop; +  +  case PIKE_T_NAME: +  free_string((struct pike_string *)car); +  t = cdr; +  goto loop;    }    }   }
282:    for(t = pike_type_hash[index]; t; t = t->next) {    if ((t->hash == hash) && (t->type == type) &&    (t->car == car) && (t->cdr == cdr)) { +  switch(type) { +  case T_FUNCTION: +  case T_MANY: +  case T_TUPLE: +  case T_MAPPING: +  case T_OR: +  case T_AND: +  /* Free car & cdr */ +  free_type(car); +  free_type(cdr); +  break; +  +  case T_ARRAY: +  case T_MULTISET: +  case T_NOT: +  /* Free car */ +  free_type(car); +  break; +  +  case T_SCOPE: +  case T_ASSIGN: +  /* Free cdr */ +  free_type(cdr); +  break; +  +  case PIKE_T_NAME: +  free_string((struct pike_string *)car); +  free_type(cdr); +  break; +  } +  /* FIXME: Free car & cdr as appropriate. */    add_ref(t);    return t;    }
387:    TYPE_STACK_DEBUG("push_assign_type");   }    + void push_type_name(struct pike_string *name) + { +  /* fprintf(stderr, "push_type_name(\"%s\")\n", name->str); */ +  add_ref(name); +  *Pike_compiler->type_stackp = mk_type(PIKE_T_NAME, +  (void *)name, +  *Pike_compiler->type_stackp, +  PT_COPY_CDR); +  TYPE_STACK_DEBUG("push_type_name"); + } +    void push_finished_type(struct pike_type *t)   {    copy_type(*(++Pike_compiler->type_stackp), t);
426:    case T_ASSIGN:    case T_INT:    case T_OBJECT: +  case PIKE_T_NAME:    default:    /* Should not occurr. */    fatal("");
513:    case '9':    /* Leaf */    break; +  case PIKE_T_NAME: +  /* Pop the name and recurse. */ +  push_finished_type(top->cdr); +  pop_type_stack(); +  break;    default:    Pike_error("pop_type_stack(): Unhandled node type: %d\n", top->type);    }
583:    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 */    if (type->cdr) {    push_finished_type_with_markers(type->cdr, markers);
1032: Inside #if defined(PIKE_DEBUG)
   printf("%d", s->type-'0');    break;    +  case PIKE_T_NAME: +  printf("{ %s = ", ((struct pike_string *)s->car)->str); +  simple_describe_type(s->cdr); +  printf(" }"); +  break; +     case T_SCOPE:    printf("scope(%ld, ", (long)(ptrdiff_t)s->car);    simple_describe_type(s->cdr);
1151:    my_putchar('(');    my_putchar((ptrdiff_t)t->car);    my_putchar('='); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_putchar(')');    break;   
1159:    my_putchar('{');    my_putchar((ptrdiff_t)t->car);    my_putchar(','); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_putchar('}');    break;       case T_TUPLE:    my_putchar('['); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_putchar(','); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_putchar(']');    break;   
1207:    case T_STRING: my_strcat("string"); break;    case T_TYPE: my_strcat("type"); 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 { +  my_describe_type(t->cdr); +  } +  break; +     case T_FUNCTION:    case T_MANY:    {
1231:    while(t->type != T_MANY)    {    if(s++) my_strcat(", "); -  low_describe_type(t->car); +  my_describe_type(t->car);    t = t->cdr;    }    if(t->car->type != T_VOID)    {    if(s++) my_strcat(", "); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(" ...");    }    my_strcat(" : "); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_strcat(")");    }    break;
1251:    my_strcat("array");    if(t->car->type != T_MIXED) {    my_strcat("("); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(")");    }    break;
1260:    my_strcat("multiset");    if(t->car->type != T_MIXED) {    my_strcat("("); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(")");    }    break;
1269:    my_strcat("!");    if (t->car->type > T_NOT) {    my_strcat("("); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(")");    } else { -  low_describe_type(t->car); +  my_describe_type(t->car);    }    break;       case T_OR:    if (t->car->type > T_OR) {    my_strcat("("); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(")");    } else { -  low_describe_type(t->car); +  my_describe_type(t->car);    }    my_strcat(" | ");    if (t->cdr->type > T_OR) {    my_strcat("("); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_strcat(")");    } else { -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    }    break;       case T_AND:    if (t->car->type > T_AND) {    my_strcat("("); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(")");    } else { -  low_describe_type(t->car); +  my_describe_type(t->car);    }    my_strcat(" & ");    if (t->cdr->type > T_AND) {    my_strcat("("); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_strcat(")");    } else { -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    }    break;   
1316:    my_strcat("mapping");    if(t->car->type != T_MIXED || t->cdr->type != T_MIXED) {    my_strcat("("); -  low_describe_type(t->car); +  my_describe_type(t->car);    my_strcat(":"); -  low_describe_type(t->cdr); +  my_describe_type(t->cdr);    my_strcat(")");    }    break;
1378:    return T_INT;       case T_SCOPE: +  case PIKE_T_NAME:    return compile_type_to_runtime_type(t->cdr);       case T_MANY:
1838:    return low_match_types(a->cdr, b, flags);    }    +  case PIKE_T_NAME: +  return low_match_types(a->cdr, b, flags); +     case T_NOT:    if(low_match_types(a->car, b, (flags ^ B_EXACT ) | NO_MAX_ARGS))    return 0;
1919:    return low_match_types(a, b->cdr, flags);    }    +  case PIKE_T_NAME: +  return low_match_types(a, b->cdr, flags); +     case T_NOT:    if(low_match_types(a, b->car, (flags ^ A_EXACT ) | NO_MAX_ARGS))    return 0;
2343:    }    }    +  case PIKE_T_NAME: +  a = a->cdr; +  goto recurse; +     case T_NOT:    if (b->type == T_NOT) {    struct pike_type *tmp = a->car;
2426:    b = b->cdr;    goto recurse;    +  case PIKE_T_NAME: +  b = b->cdr; +  goto recurse; +     case T_NOT:    if (b->car->type == T_NOT) {    b = b->car->car;
2831:    if(!tmp) return 0;    return low_get_return_type(a->cdr, b);    +  case PIKE_T_NAME: +  return low_get_return_type(a->cdr, b); +     case T_ARRAY:    tmp = low_get_return_type(a->car, b);    if(!tmp) return 0;
2912:    return zero_type_string;    }    +  while(t->type == PIKE_T_NAME) { +  t = t->cdr; +  } +  while(index_type->type == PIKE_T_NAME) { +  index_type = index_type->cdr; +  } +     switch(t->type)    {    case T_OBJECT:
3182:    /* FIXME: Shouldn't this look at both branches? */    return low_key_type(t->cdr, n);    +  case PIKE_T_NAME: +  return low_key_type(t->cdr, n); +     case T_ARRAY:    case T_STRING: /* always int */    add_ref(int_type_string);
3224:    case T_NOT:    return low_check_indexing(type->car, index_type, n) != 1;    +  case PIKE_T_NAME: +  return low_check_indexing(type->cdr, index_type, n); +     case T_ARRAY:    if(low_match_types(string_type_string, index_type, 0) &&    low_check_indexing(type->car, index_type, n))
3302:    if(num2<0 && num<0) return ~num<~num2?num:num2;    return num<num2?num:num2;    +  case PIKE_T_NAME: +  return low_count_arguments(q->cdr); +     default: return 0x7fffffff;       case T_FUNCTION:
3343:       default: return 0;    +  case PIKE_T_NAME: +  return low_minimum_arguments(q->cdr); +     case T_FUNCTION:    num = 0;    while(q->type == T_FUNCTION)
3470:    case T_ARRAY:    return zzap_function_return(a->car, id);    +  case PIKE_T_NAME: +  return zzap_function_return(a->cdr, id); +     case T_MIXED:    /* I wonder when this occurrs, but apparently it does... */    /* FIXME: */
3699:    default:    return 0;    +  case PIKE_T_NAME: +  return type_may_overload(type->cdr, lfun); +     case T_OR:    return type_may_overload(type->car, lfun) ||    type_may_overload(type->cdr, lfun);
3874:    case T_MANY:    return 0;    +  case PIKE_T_NAME:    case T_SCOPE:    case T_ASSIGN:    type = type->cdr;
7369: Inside #if defined(USE_PIKE_TYPE)
   /* Free the hashtable here. */    if (pike_type_hash) {    free(pike_type_hash); -  pike_type_hash = NULL; +  /* Don't do this, it messes up stuff... */ +  /* pike_type_hash = NULL; */    } -  pike_type_hash_size = 0; +  /* Don't do this, it messes up stuff... */ +  /* pike_type_hash_size = 0; */   #endif /* USE_PIKE_TYPE */   }