pike.git / src / pike_types.cmod

version» Context lines:

pike.git/src/pike_types.cmod:9906:    /* Possible to index the array with an int. */    add_ref(t->cdr);    return t->cdr;    }    /* Bad index type. */    return 0;    }    }   }    + /** +  * Returns the type resulting from indexing type with index_type. +  * +  * The node n is used to determine whether the indexing method +  * is `[]() (the default) or `->(). +  * +  * See also key_type(). +  */   struct pike_type *index_type(struct pike_type *type,    struct pike_type *index_type,    node *n)   {    struct pike_type *t;    clear_markers();    t = low_index_type(type, index_type, n); -  if(!t) { -  copy_pike_type(t, mixed_type_string); -  } +     return t;   }      #ifdef DEBUG_MALLOC   #define low_range_type(X,Y,Z) ((struct pike_type *)debug_malloc_pass(debug_low_range_type((X),(Y),(Z))))   #else   #define low_range_type debug_low_range_type   #endif      /* FIXME, add the index
pike.git/src/pike_types.cmod:10185:      #ifdef DEBUG_MALLOC   #define low_key_type(X,Y) ((struct pike_type *)debug_malloc_pass(debug_low_key_type((X),(Y))))   #else   #define low_key_type debug_low_key_type   #endif      /* FIXME, add the index */   static struct pike_type *debug_low_key_type(struct pike_type *t, node *n)   { -  switch(t->type) +  switch(t?t->type:PIKE_T_UNKNOWN)    {    case T_OBJECT:    {    struct program *p = id_to_program(CDR_TO_INT(t));    if(p && n)    {    if(n->token == F_ARROW)    {    int i;    if((i = FIND_LFUN(p,LFUN_ARROW))!=-1 ||
pike.git/src/pike_types.cmod:10224:    if (res) return res;    /* FIXME: Warn? */    add_ref(mixed_type_string);    return mixed_type_string;    }    }    }    add_ref(string_type_string);    return string_type_string;    } -  default: +  +  case PIKE_T_MIXED:    add_ref(mixed_type_string);    return mixed_type_string;    -  +  default: +  case PIKE_T_UNKNOWN:    case T_VOID:    case T_ZERO:    case T_TYPE:    case PIKE_T_RING:    case T_FLOAT:    case T_INT: -  return 0; +  return NULL;       case T_OR:    {    struct pike_type *a,*b;    a = low_key_type(t->car, n);    b = low_key_type(t->cdr, n);    if(!b) return a;    if(!a) return b;    type_stack_mark();    low_or_pike_types(a,b,1);    free_type(a);    free_type(b);    return pop_unfinished_type();    }       case T_AND: -  /* FIXME: Shouldn't this look at both branches? */ -  return low_key_type(t->cdr, n); +  { +  struct pike_type *a,*b; +  a = low_key_type(t->car, n); +  b = low_key_type(t->cdr, n); +  t = and_pike_types(a, b); +  free_type(a); +  free_type(b); +  return t; +  }    -  +  case T_NOT: +  t = low_key_type(t->car, n); +  type_stack_mark(); +  push_finished_type(t); +  push_type(T_NOT); +  free_type(t); +  return pop_unfinished_type(); +  +  case PIKE_T_SCOPE: +  case PIKE_T_ASSIGN:    case PIKE_T_NAME:    case PIKE_T_ATTRIBUTE:    return low_key_type(t->cdr, n);    -  case T_ARRAY: /* FIXME: cdr */ -  case T_STRING: /* always int */ -  add_ref(int_type_string); -  return int_type_string; -  +  case T_ARRAY: +  case T_STRING:    case T_MAPPING:    case T_MULTISET: -  +  /* FIXME: Arrays may also be indexed with strings when +  * strings are valid indices for their values. +  */    copy_pike_type(t, t->car);    return t;    }   }    -  + /** +  * Returns the type of valid indices of type. +  * +  * The node n is used to determine whether the indexing method +  * is `[]() (the default) or `->(). +  * +  * See also index_type(). +  */   struct pike_type *key_type(struct pike_type *type, node *n)   {    struct pike_type *t;    clear_markers();    t = low_key_type(type,n); -  if(!t) { -  copy_pike_type(t, mixed_type_string); -  } +     return t;   }         /* Returns whether a value of type 'type' may be indexed with a value    * of type 'index_type'. Returns -1 if the indexing operation is valid,    * but will always fail.    * The node 'n' is the node with the indexing operator.    */   static int low_check_indexing(struct pike_type *type,