pike.git / src / pike_types.cmod

version» Context lines:

pike.git/src/pike_types.cmod:186:    case T_MIXED: return "mixed";    default: return "unknown";      #ifdef PIKE_DEBUG    /* Let's make it able to describe any type constant in debug mode. */    case T_UNFINISHED: return "T_UNFINISHED";    case T_MANY: return "T_MANY";    case PIKE_T_INT_UNTYPED: return "PIKE_T_INT_UNTYPED";    case PIKE_T_GET_SET: return "PIKE_T_GET_SET";    case PIKE_T_FREE: return "PIKE_T_FREE"; +  case PIKE_T_FUNCTION_ARG: return "PIKE_T_FUNCTION_ARG";    case PIKE_T_ATTRIBUTE: return "PIKE_T_ATTRIBUTE";    case PIKE_T_NSTRING: return "PIKE_T_NSTRING";    case PIKE_T_LSTRING: return "PIKE_T_LSTRING";    case PIKE_T_LARRAY: return "PIKE_T_LARRAY";    case PIKE_T_RING: return "PIKE_T_RING";    case PIKE_T_NAME: return "PIKE_T_NAME";    case PIKE_T_SCOPE: return "PIKE_T_SCOPE";    case PIKE_T_TUPLE: return "PIKE_T_TUPLE";    case T_ASSIGN: return "T_ASSIGN";    case T_DELETED: return "T_DELETED";
pike.git/src/pike_types.cmod:1993:    case T_STRING: fprintf(stderr, "string"); break;    case T_TYPE: fprintf(stderr, "type"); break;    case T_PROGRAM: fprintf(stderr, "program"); break;    case T_OBJECT:    fprintf(stderr, "object(%s %ld)",    EXTRACT_UCHAR(a+e+1)?"is":"implements",    (long)extract_type_int(a+e+2));    e+=sizeof(INT32)+1;    break;    case T_FUNCTION: fprintf(stderr, "function"); break; +  case PIKE_T_FUNCTION_ARG: fprintf(stderr, "function_arg"); break;    case T_ARRAY: fprintf(stderr, "array"); break;    case T_MAPPING: fprintf(stderr, "mapping"); break;    case T_MULTISET: fprintf(stderr, "multiset"); break;       case PIKE_T_UNKNOWN: fprintf(stderr, "unknown"); break;    case T_MANY: fprintf(stderr, "many"); break;    case T_OR: fprintf(stderr, "or"); break;    case T_AND: fprintf(stderr, "and"); break;    case T_NOT: fprintf(stderr, "not"); break;    case T_VOID: fprintf(stderr, "void"); break;
pike.git/src/pike_types.cmod:2203:    fprintf(stderr, "object(%s %"PRINTPTRDIFFT"d)",    s->car?"is":"implements",    CDR_TO_INT(s));    break;    case T_FUNCTION:    case T_MANY:    fprintf(stderr, "function(");    while(s->type == T_FUNCTION) {    simple_describe_type(s->car);    s = s->cdr; -  while(s->type == T_ASSIGN) { -  fprintf(stderr, "%"PRINTPTRDIFFT"d = ", CAR_TO_INT(s)); -  s = s->cdr; -  } +     if ((s->type == T_FUNCTION) ||    (s->car->type != T_VOID)) {    fprintf(stderr, ", ");    }    } -  +  if (s->type != T_MANY) { +  fprintf(stderr, ", @"); +  simple_describe_type(s); +  fprintf(stderr, ")"); +  } else {    if (s->car->type != T_VOID) {    simple_describe_type(s->car);    fprintf(stderr, "...");    }    fprintf(stderr, ":");    simple_describe_type(s->cdr);    fprintf(stderr, ")"); -  +  }    break;    case T_ARRAY: /* FIXME: cdr */    fprintf(stderr, "array(");    if (s->car != int_pos_type_string) {    simple_describe_type(s->car);    fprintf(stderr, ":");    }    simple_describe_type(s->cdr);    fprintf(stderr, ")");    break;
pike.git/src/pike_types.cmod:2482:    {    /* function == function(zero...:mixed|void) or    * function(zero|void...:mixed|void)    */    string_builder_strcat(s, "function");    /* done */    break;    } else {    int arg = 0;    string_builder_strcat(s, "function("); -  while(t->type != T_MANY) +  while(t->type == T_FUNCTION)    {    if(arg++) string_builder_strcat(s, ", ");    low_describe_type(s, t->car);    t = t->cdr; -  while(t->type == T_ASSIGN) { -  string_builder_sprintf(s, "%c=", '0' + CAR_TO_INT(t)); -  t = t->cdr; +     } -  } +  if (t->type != T_MANY) { +  string_builder_sprintf(s, ", @%T", t); +  } else {    if(t->car->type != T_VOID)    {    if(arg++) string_builder_strcat(s, ", ");    low_describe_type(s, t->car);    string_builder_strcat(s, " ...");    } -  string_builder_sprintf(s, " : %T)", t->cdr); +  t = t->cdr; +  string_builder_sprintf(s, " : %T)", t);    } -  +  }    break;    }       case T_ARRAY:    string_builder_strcat(s, "array");    if((t->cdr->type == T_MIXED) && (t->car == int_pos_type_string)) {    break;    }    string_builder_putchar(s, '(');    if (t->car == zero_type_string) {
pike.git/src/pike_types.cmod:3786:    return 0;    }    return a;    }    case TWOT(T_FUNCTION, T_FUNCTION):    case TWOT(T_FUNCTION, T_MANY):    case TWOT(T_MANY, T_FUNCTION):    case TWOT(T_MANY, T_MANY):    ret = a;    correct_args=0; -  while ((a->type != T_MANY) || (b->type != T_MANY)) +  while ((a->type == T_FUNCTION) || (b->type == T_FUNCTION))    {    struct pike_type *a_tmp, *b_tmp;    -  +  if ((a->type != T_FUNCTION) && (a->type != T_MANY)) break; +  if ((b->type != T_FUNCTION) && (b->type != T_MANY)) break; +     a_tmp = a->car;    if (a->type == T_FUNCTION)    {    a = a->cdr;    }       b_tmp = b->car;    if (b->type == T_FUNCTION)    {    b = b->cdr;    }       if(!low_match_types(a_tmp, b_tmp,    (flags | NO_MAX_ARGS) & ~(A_EXACT|B_EXACT)))    return 0;    if(++correct_args > max_correct_args)    if(!(flags & NO_MAX_ARGS))    max_correct_args=correct_args;    } -  +  +  if ((a->type != T_MANY) || (b->type != T_MANY)) { +  /* Handle the generic case. */ +  return low_match_types(a, b, flags); +  } +     /* check the 'many' type */    if(b->car->type != T_VOID &&    a->car->type != T_VOID)    {    if(!low_match_types(a->car, b->car,    (flags | NO_MAX_ARGS) & ~(A_EXACT|B_EXACT)))    return 0;    }    if(!(flags & NO_MAX_ARGS))    max_correct_args=MAX_INT32;
pike.git/src/pike_types.cmod:4529:    */    /*    * function(:int) <= function(int:int)    * function(int|string:int) <= function(int:int)    * function(:int) <= function(:void)    * function(string:int) != function(int:int)    * function(int:int) != function(:int)    *    * FIXME: Enforcing of all required arguments?    */ -  while((a->type != T_MANY) || (b->type != T_MANY)) +  while((a->type == T_FUNCTION) || (b->type == T_FUNCTION))    {    struct pike_type *a_tmp, *b_tmp;    -  +  if ((a->type != T_FUNCTION) && (a->type != T_MANY)) break; +  if ((b->type != T_FUNCTION) && (b->type != T_MANY)) break; +     a_tmp = a->car;    if (a->type == T_FUNCTION)    {    a = a->cdr;    }       b_tmp = b->car;    if (b->type == T_FUNCTION)    {    b = b->cdr;
pike.git/src/pike_types.cmod:4558:    return 0;    }    } else if (flags & LE_TYPE_SVALUE) {    /* Note: flags never has grouping at this point. */    if (!low_pike_types_le(b_tmp, zero_type_string, 0,    flags ^ LE_A_B_SWAPPED)) {    return 0;    }    }    } +  +  if ((a->type != T_MANY) || (b->type != T_MANY)) { +  /* Handle the generic case. */ +  return low_pike_types_le(a, b, array_cnt, flags); +  } +     /* FALLTHRU */    case TWOT(T_MANY, T_MANY):    /* check the 'many' type */    if ((a->car->type != T_VOID) && (b->car->type != T_VOID)) {    /* Note: flags never has grouping at this point. */    if (!low_pike_types_le(b->car, a->car, 0, flags ^ LE_A_B_SWAPPED)) {    return 0;    }    } else if ((flags & LE_TYPE_SVALUE) && (a->car->type != b->car->type)) {    if (a->car->type == T_VOID) {
pike.git/src/pike_types.cmod:4848:    yyreport_type(REPORT_WARNING, NULL, 0, b, NULL, 0, a, 0, "Type mismatch");    }   #endif /* 0 */    switch(a->type)    {    case T_FUNCTION:    a = a->cdr;    while(a->type == T_FUNCTION) {    a = a->cdr;    } +  if (a->type != T_MANY) { +  return low_get_return_type(a, mixed_type_string); +  }    /* FALLTHRU */    case T_MANY:    a = a->cdr;    push_finished_type_with_markers(a, a_markers, 0);    return 1;       case T_TYPE:    case T_PROGRAM:    push_finished_type(a->car);    return 1;
pike.git/src/pike_types.cmod:5546:    * - There were complaints when people got compilation errors    * for indexing operations that would always fail.    */    return low_match_types(type->car, index_type, 0) ? 1 : -1;       case T_FUNCTION:    while ((type = type->cdr) && (type->type == T_FUNCTION))    ;    if (!type) return 0;    +  if (type->type != T_MANY) return 0; +     /* FALLTHRU */       case T_MANY:    type = type->cdr;    if (!type || (type->type != T_OBJECT) || !type->car)    return 0;    /* function(... : object(is foo)) -- ie probably program(foo). */       /* FALLTHRU */   
pike.git/src/pike_types.cmod:5611:    return low_count_arguments(q->cdr);       default: return MAX_INT32;       case T_FUNCTION:    while(q->type == T_FUNCTION)    {    num++;    q = q->cdr;    } +  +  if (q->type != T_MANY) { +  num2 = low_count_arguments(q); +  if (num2 == MAX_INT32) return num2; +  if (num2 < 0) { +  num += ~num2; +  return ~num; +  } +  return num + num2; +  } +     /* FALLTHRU */    case T_MANY:    q = q->car;    if(q->type != T_VOID) return ~num;    return num;    }   }      /* Count the number of arguments for a funciton type.    * return -1-n if the function can take number of arguments
pike.git/src/pike_types.cmod:6023:    }    /* FIXME: Loop above until function? */    if ((orig_type->type != T_FUNCTION) &&    (orig_type->type != T_MANY)) {    /* Failure. */    break;    }    type_stack_mark();    while((soft_type->type == T_FUNCTION) ||    (orig_type->type == T_FUNCTION)) { +  if ((soft_type->type != T_FUNCTION) && +  (soft_type->type != T_MANY)) break; +  if ((orig_type->type != T_FUNCTION) && +  (orig_type->type != T_MANY)) break;    if (!(tmp2 = soft_cast(soft_type->car, orig_type->car,    flags ^ SOFT_WEAKER))) {    goto function_cast_fail;    }    if (tmp2 != void_type_string) {    push_finished_type(tmp2);    loop_cnt++;    }    free_type(tmp2);    tmp2 = NULL;
pike.git/src/pike_types.cmod:8478:       case T_MANY:    case T_TUPLE:    case T_MAPPING:    case PIKE_T_RING:    /* Order dependant */    low_make_pike_type(type_string+1, cont);    low_make_pike_type(*cont, cont);    push_reverse_type(type);    break; +  case PIKE_T_FUNCTION_ARG: +  low_make_pike_type(type_string+1, cont); +  low_make_pike_type(*cont, cont); +  push_reverse_type(T_FUNCTION); +  break;    case T_FUNCTION:    low_make_function_type(type_string+1, cont);    break;    case T_MULTISET:    case T_TYPE:    case T_NOT:    case T_PROGRAM:    low_make_pike_type(type_string+1, cont);    push_reverse_type(type);    break;