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.291 2007/04/18 11:58:59 grubba Exp $ + || $Id: pike_types.c,v 1.292 2007/04/21 12:42:20 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:38:    */   #define A_EXACT 1   #define B_EXACT 2   #define NO_MAX_ARGS 4   #define NO_SHORTCUTS 8      /*    * 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. +  */      /*    * 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()    */   #define PT_COPY_CAR 1
pike.git/src/pike_types.c:1025:    */   static void debug_push_finished_type_with_markers(struct pike_type *type,    struct pike_type **markers,    INT32 marker_set)   {    recurse:   #if 0    fprintf(stderr, "push_finished_type_with_markers((%d[%x]),...)...\n",    type->type, type->flags);   #endif /* 0 */ -  if (!(type->flags & (marker_set | (marker_set << PT_ASSIGN_SHIFT)))) { +  if (!(type->flags & (marker_set /*| (marker_set << PT_ASSIGN_SHIFT)*/))) {    /* No unassigned markers in this sub-tree */   #if 0    fprintf(stderr, "No unassigned markers in this subtree.\n");   #endif /* 0 */    push_finished_type(type);    return;    }    if ((type->type >= '0') && (type->type <= '9')) {    unsigned int m = type->type - '0';   #if 0
pike.git/src/pike_types.c:3409:   static int low_pike_types_le(struct pike_type *a, struct pike_type *b,    int array_cnt, unsigned int flags)   #ifdef PIKE_TYPE_DEBUG   {    int e;    char *s;    int res;    char buf[50];       if (l_flag>2) { -  dynamic_buffer save_buf; -  init_buf(&save_buf); -  for(e=0;e<indent;e++) my_strcat(" "); -  my_strcat("low_pike_types_le("); -  my_describe_type(a); -  my_strcat(",\n"); -  for(e=0;e<indent;e++) my_strcat(" "); -  my_strcat(" "); -  my_describe_type(b); -  my_strcat(",\n"); -  for(e=0;e<indent;e++) my_strcat(" "); -  my_strcat(" "); -  sprintf(buf, "%d", array_cnt); -  my_strcat(buf); -  my_strcat(", "); -  sprintf(buf, "0x%08x", flags); -  my_strcat(buf); -  my_strcat(");\n"); -  fprintf(stderr,"%s",(s=simple_free_buf(&save_buf))); -  free(s); +  fprintf(stderr, "%*slow_pike_types_le(", indent*2, ""); +  simple_describe_type(a); +  fprintf(stderr, ",\n%*s", indent*2 + 18, ""); +  simple_describe_type(b); +  fprintf(stderr, ",\n%*s%d, 0x%08x);\n", +  indent*2 + 18, "", array_cnt, flags);    indent++;    }       res = low_pike_types_le2(a, b, array_cnt, flags);       if (l_flag>2) {    indent--;    -  for(e=0;e<indent;e++) fprintf(stderr, " "); -  fprintf(stderr, "= %d\n", res); +  fprintf(stderr, "%*s= %d\n", indent*2, "", res);    }    return res;   }      static int low_pike_types_le2(struct pike_type *a, struct pike_type *b,    int array_cnt, unsigned int flags)   #endif /* PIKE_TYPE_DEBUG */   {    int ret;   
pike.git/src/pike_types.c:3501:    case PIKE_T_NAME:    a = a->cdr;    goto recurse;       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;    goto recurse;    } -  if (a->car->type == T_NOT) { +  /* 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); +  return !low_pike_types_le(b, a->car, -array_cnt, flags ^ LE_A_B_SWAPPED);       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(); -  +  if (flags & LE_A_B_SWAPPED) { +  push_finished_type_with_markers(b, a_markers, PT_FLAG_MARKER); +  } else {    push_finished_type_with_markers(b, b_markers, PT_FLAG_MARKER); -  +  }    for(i=array_cnt; i > 0; i--)    push_type(T_ARRAY);    tmp=pop_unfinished_type();       type_stack_mark(); -  +  if (flags & LE_A_B_SWAPPED) { +  low_or_pike_types(b_markers[m], tmp, 0); +  if(b_markers[m]) free_type(b_markers[m]); +  free_type(tmp); +  b_markers[m] = pop_unfinished_type(); +  } else {    low_or_pike_types(a_markers[m], tmp, 0);    if(a_markers[m]) free_type(a_markers[m]);    free_type(tmp);    a_markers[m] = pop_unfinished_type(); -  +  }   #ifdef PIKE_TYPE_DEBUG    if (l_flag>2) { -  dynamic_buffer save_buf; -  char *s; -  int e; -  init_buf(&save_buf); -  for(e=0;e<indent;e++) my_strcat(" "); -  my_strcat("a_markers["); -  my_putchar((char)(m+'0')); -  my_strcat("]="); -  my_describe_type(a_markers[m]); -  my_strcat("\n"); -  fprintf(stderr,"%s",(s=simple_free_buf(&save_buf))); -  free(s); +  if (flags & LE_A_B_SWAPPED) { +  fprintf(stderr, "%*sb_markers[%c]=", +  indent * 2, "", (char)(m+'0')); +  simple_describe_type(b_markers[m]); +  } else { +  fprintf(stderr, "%*sa_markers[%c]=", +  indent * 2, "", (char)(m+'0')); +  simple_describe_type(a_markers[m]);    } -  +  fprintf(stderr, "\n"); +  }   #endif    }    return ret;       case '0': case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8': case '9':    {    int m = a->type - '0'; -  +  if (flags & LE_A_B_SWAPPED) { +  if(b_markers[m]) { +  a = b_markers[m]; +  } else { +  a = mixed_type_string; +  } +  } else {    if(a_markers[m]) {    a = a_markers[m];    } else {    a = mixed_type_string;    } -  +  }    goto recurse;    }    }       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;
pike.git/src/pike_types.c:3589:       case PIKE_T_RING:    b = b->car;    goto recurse;       case PIKE_T_NAME:    b = b->cdr;    goto recurse;       case T_NOT: -  if (b->car->type == T_NOT) { +  /* Some common cases. */ +  switch(b->car->type) { +  case T_NOT:    b = b->car->car;    goto recurse; -  +  case T_MIXED: +  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); +  return !low_pike_types_le(b->car, a, -array_cnt, flags ^ LE_A_B_SWAPPED);       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(); -  +  if (flags & LE_A_B_SWAPPED) { +  push_finished_type_with_markers(a, b_markers, PT_FLAG_MARKER); +  } else {    push_finished_type_with_markers(a, a_markers, PT_FLAG_MARKER); -  +  }    for(i = array_cnt; i < 0; i++)    push_type(T_ARRAY);    tmp=pop_unfinished_type();       type_stack_mark(); -  +  if (flags & LE_A_B_SWAPPED) { +  low_or_pike_types(a_markers[m], tmp, 0); +  if(a_markers[m]) free_type(a_markers[m]); +  free_type(tmp); +  a_markers[m] = pop_unfinished_type(); +  } else {    low_or_pike_types(b_markers[m], tmp, 0);    if(b_markers[m]) free_type(b_markers[m]);    free_type(tmp);    b_markers[m] = pop_unfinished_type(); -  +  }   #ifdef PIKE_TYPE_DEBUG    if (l_flag>2) { -  dynamic_buffer save_buf; -  char *s; -  int e; -  init_buf(&save_buf); -  for(e=0;e<indent;e++) my_strcat(" "); -  my_strcat("b_markers["); -  my_putchar((char)(m+'0')); -  my_strcat("]="); -  my_describe_type(b_markers[m]); -  my_strcat("\n"); -  fprintf(stderr,"%s",(s=simple_free_buf(&save_buf))); -  free(s); +  if (flags & LE_A_B_SWAPPED) { +  fprintf(stderr, "%*sa_markers[%c]=", +  indent * 2, "", (char)(m+'0')); +  simple_describe_type(a_markers[m]); +  } else { +  fprintf(stderr, "%*sb_markers[%c]=", +  indent * 2, "", (char)(m+'0')); +  simple_describe_type(b_markers[m]);    } -  +  fprintf(stderr, "\n"); +  }   #endif    }    return ret;       case '0': case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8': case '9':    { -  int m = b->type - '0'; +  int m = b->type - '0'; +  if (flags & LE_A_B_SWAPPED) { +  if(a_markers[m]) { +  b = a_markers[m]; +  } else { +  b = mixed_type_string; +  } +  } else {    if(b_markers[m]) {    b = b_markers[m];    } else {    b = mixed_type_string;    } -  +  }    goto recurse;    }    }       if ((array_cnt < 0) && (b->type == T_ARRAY)) {    while (b->type == T_ARRAY) {    b = b->car;    if (!++array_cnt) break;    }    goto recurse;
pike.git/src/pike_types.c:3794:    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)) { +  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)) { +  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:7037: Inside #if defined(DEBUG_MALLOC)
  {   #ifdef DEBUG_MALLOC    struct pike_type_location *t = all_pike_type_locations;       while(t) {    free_type(t->t);    t = t->next;    }   #endif /* DEBUG_MALLOC */    +  clear_markers(); +     free_type(string0_type_string);    string0_type_string = NULL;    free_type(string_type_string);    string_type_string = NULL;    free_type(int_type_string);    int_type_string = NULL;    free_type(float_type_string);    float_type_string = NULL;    free_type(function_type_string);    function_type_string = NULL;