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.348 2008/07/09 20:43:45 mast Exp $ + || $Id: pike_types.c,v 1.349 2008/08/11 13:36:58 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:35:   #endif /* PIKE_DEBUG */      /*    * Flags used by low_match_types().    */   #define A_EXACT 1   #define B_EXACT 2   #define NO_MAX_ARGS 4   #define NO_SHORTCUTS 8    + #define TYPE_GROUPING +    /*    * Flags used by pike_types_le()    */   #define LE_WEAK_OBJECTS 1 /* Perform weaker checking of objects. */   #define LE_A_B_SWAPPED 2 /* Argument A and B have been swapped.    * Relevant for markers.    */   #ifdef TYPE_GROUPING - #define LE_A_GROUPED 0/*4*/ /* Argument A has been grouped. + #define LE_A_GROUPED 4 /* Argument A has been grouped.    * Perform weaker checking for OR-nodes. */ - #define LE_B_GROUPED 0/*8*/ /* Argument B has been grouped. + #define LE_B_GROUPED 8 /* Argument B has been grouped.    * Perform weaker checking for OR-nodes. */ - #define LE_A_B_GROUPED 0/*12*/ /* Both the above two flags. */ + #define LE_A_B_GROUPED 12 /* Both the above two flags. */   #endif   #define LE_USE_HANDLERS 16 /* Call handlers if appropriate. */      /*    * Flags used by low_get_first_arg_type()    */   #define FILTER_KEEP_VOID 1 /* Keep void during the filtering. */      /*    * Flags used as flag_method to mk_type()
pike.git/src/pike_types.c:3749:    int ret;       recurse:   #if 0    fprintf(stderr, "low_pike_types_le(%d, %d, %d, 0x%08x)\n",    a->type, b->type, array_cnt, flags);   #endif /* 0 */       if(a == b) return 1;    + #ifdef TYPE_GROUPING +  if (a->type != T_OR) { +  flags &= ~LE_A_GROUPED; +  } + #endif +     switch(a->type)    {    case T_AND:    /* OK if either of the parts is a subset. */    /* FIXME: What if b also contains an AND? */    ret = low_pike_types_le(a->car, b, array_cnt, flags); -  if(ret) return ret; +  if(!ret) {    a = a->cdr;    goto recurse; -  +  } +  /* Note that we need to recurse, since there may be T_ASSIGN nodes +  * in the cdr that need to be executed. +  */ +  low_pike_types_le(a->cdr, b, array_cnt, flags); +  return 1;       case T_OR:    /* OK, if both of the parts are a subset,    * unless we are grouped, in which case    * only one part needs to be a subset.    */    if (a->car->type == T_VOID) {    /* Special case for T_VOID */    /* FIXME: Should probably be handled as T_ZERO. */   #ifdef TYPE_GROUPING
pike.git/src/pike_types.c:3832:    }    pop_stack();    return 1;       case T_NOT:    if (b->type == T_NOT) {    struct pike_type *tmp = a->car;    a = b->car;    b = tmp;    array_cnt = -array_cnt; -  flags ^= LE_A_B_SWAPPED +  flags ^= LE_A_B_SWAPPED; + #if 0   #ifdef TYPE_GROUPING -  |LE_A_B_GROUPED +  if (flags & LE_A_B_GROUPED) { +  if ((flags & LE_A_B_GROUPED) == LE_A_B_GROUPED) { +  flags ^= LE_A_B_GROUPED; +  } +  } else { +  flags |= LE_A_B_GROUPED; +  }   #endif -  ; + #endif    goto recurse;    }    /* Some common cases. */    switch(a->car->type) {    case T_NOT:    a = a->car->car;    goto recurse;    case T_MIXED:    a = zero_type_string;    goto recurse;    case T_ZERO:    case T_VOID:    a = mixed_type_string;    goto recurse;    }    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 ^ (LE_A_B_SWAPPED +  flags ^= LE_A_B_SWAPPED; + #if 0   #ifdef TYPE_GROUPING -  |LE_A_B_GROUPED +  if (flags & LE_A_B_GROUPED) { +  if ((flags & LE_A_B_GROUPED) == LE_A_B_GROUPED) { +  flags ^= LE_A_B_GROUPED; +  } +  } else { +  flags |= LE_A_B_GROUPED; +  }   #endif -  )); + #endif +  /* 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 = CAR_TO_INT(a);    struct pike_type *tmp;    int i;       type_stack_mark();
pike.git/src/pike_types.c:3931:    if(a_markers[m]) {    a = a_markers[m];    } else {    a = mixed_type_string;    }    }    goto recurse;    }    }    + #ifdef TYPE_GROUPING +  if (b->type != T_OR) { +  flags &= ~LE_B_GROUPED; +  } + #endif +     switch(b->type)    {    case T_AND:    /* OK, if a is a subset of both parts. */    ret = low_pike_types_le(a, b->car, array_cnt, flags);    if(!ret) return 0;    b = b->cdr;    goto recurse;       case T_OR:
pike.git/src/pike_types.c:4003:    b = zero_type_string;    goto recurse;    case T_ZERO:    case T_VOID:    b = mixed_type_string;    goto recurse;    }    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 ^ (LE_A_B_SWAPPED +  flags ^= LE_A_B_SWAPPED;   #ifdef TYPE_GROUPING -  |LE_A_B_GROUPED +  if (flags & LE_A_B_GROUPED) { +  if ((flags & LE_A_B_GROUPED) == LE_A_B_GROUPED) { +  flags ^= LE_A_B_GROUPED; +  } +  } else { +  flags |= LE_A_B_GROUPED; +  }   #endif -  )); +  /* 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 = CAR_TO_INT(b);    struct pike_type *tmp;    int i;       type_stack_mark();
pike.git/src/pike_types.c:4261:    a = a->cdr;    }       b_tmp = b->car;    if (b->type == T_FUNCTION)    {    b = b->cdr;    }       if (a_tmp->type != T_VOID) { -  if (!low_pike_types_le(b_tmp, a_tmp, 0, -  flags ^ (LE_A_B_SWAPPED - #ifdef TYPE_GROUPING -  |LE_A_B_GROUPED - #endif -  ))) { +  /* Note: flags never has grouping at this point. */ +  if (!low_pike_types_le(b_tmp, a_tmp, 0, flags ^ LE_A_B_SWAPPED)) {    return 0;    }    }    }    /* FALL_THROUGH */    case TWOT(T_MANY, T_MANY):    /* check the 'many' type */    if ((a->car->type != T_VOID) && (b->car->type != T_VOID)) { -  if (!low_pike_types_le(b->car, a->car, 0, -  flags ^ (LE_A_B_SWAPPED - #ifdef TYPE_GROUPING -  |LE_A_B_GROUPED - #endif -  ))) { +  /* 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;    }    }       a = a->cdr;    b = b->cdr;       /* check the returntype */    /* FIXME: Check array_cnt */    if ((b->type != T_VOID) && (a->type != T_VOID)) {
pike.git/src/pike_types.c:7112:    {    push_object_type(1, s->u.object->prog->id);    }    }else{    /* Destructed object */    push_type(T_ZERO);    }    return pop_unfinished_type();       case T_INT: -  if(s->u.integer) -  { +  if(s->u.integer) {    type_stack_mark();    /* Fixme, check that the integer is in range of MIN_INT32 .. MAX_INT32!    */    push_int_type(s->u.integer, s->u.integer);    return pop_unfinished_type();    }else{    copy_pike_type(ret, zero_type_string);    return ret;    }   
pike.git/src/pike_types.c:7570:      /* Make a pike-type from a serialized (old-style) type. */   struct pike_type *debug_make_pike_type(const char *serialized_type)   {    unsigned char *dummy;    type_stack_mark();    low_make_pike_type((unsigned char *)serialized_type, &dummy);   #if 1    if ((Pike_compiler->type_stackp[0]->flags &    (PT_FLAG_MARKER|PT_FLAG_ASSIGN)) || -  (Pike_compiler->type_stackp[0]->type == T_OR) || -  (Pike_compiler->type_stackp[0]->type == T_AND)) { +  (((Pike_compiler->type_stackp[0]->type == T_OR) || +  (Pike_compiler->type_stackp[0]->type == T_AND)) && +  (Pike_compiler->type_stackp[0]->car->type == PIKE_T_FUNCTION))) {    push_scope_type(0);    }   #endif /* 1 */    return pop_unfinished_type();   }      int pike_type_allow_premature_toss(struct pike_type *type)   {    again:   #if 0