pike.git / src / las.c

version» Context lines:

pike.git/src/las.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: las.c,v 1.385 2007/04/07 19:21:59 grubba Exp $ + || $Id: las.c,v 1.386 2007/04/13 17:42:22 grubba Exp $   */      #include "global.h"   #include "interpret.h"   #include "las.h"   #include "array.h"   #include "object.h"   #include "stralloc.h"   #include "dynamic_buffer.h"   #include "lex.h"
pike.git/src/las.c:1613:    _CDR(res) = mktypenode(type);       n->parent = res;       return freeze_node(res);   }      node *debug_mksoftcastnode(struct pike_type *type, node *n)   {    node *res; +  struct pike_type *result_type = NULL;       if(!n) return 0;      #ifdef PIKE_DEBUG    if (!type) {    Pike_fatal("Soft cast to no type!\n");    }   #endif /* PIKE_DEBUG */       if (Pike_compiler->compiler_pass == 2) {
pike.git/src/las.c:1636:    }       if(type==n->type) {    struct pike_string *t1 = describe_type(type);    yywarning("Soft cast to %S is a noop.", t1);    free_string(t1);    return n;    }       if (n->type) { + #ifdef NEW_ARG_CHECK +  if (!(result_type = soft_cast(type, n->type, 0))) { +  struct pike_string *t1 = describe_type(type); +  struct pike_string *t2 = describe_type(n->type); +  my_yyerror("Soft cast of %S to %S isn't a valid cast.", +  t2, t1); +  free_string(t2); +  free_string(t1); +  } + #else /* !NEW_ARG_CHECK */    if (!check_soft_cast(type, n->type)) {    struct pike_string *t1 = describe_type(type);    struct pike_string *t2 = describe_type(n->type);    yywarning("Soft cast to %S isn't a restriction of %S.",    t1, t2);    free_string(t2);    free_string(t1);    }    /* FIXME: check_soft_cast() is weaker than pike_types_le()    * The resulting type should probably be the and between the old    * and the new type.    */ -  + #endif    }    }       res = mkemptynode();    res->token = F_SOFT_CAST; -  +  if (result_type) { +  res->type = result_type; +  } else {    copy_pike_type(res->type, type); -  +  }       res->tree_info |= n->tree_info;       _CAR(res) = n;    _CDR(res) = mktypenode(type);       n->parent = res;       return freeze_node(res);   }
pike.git/src/las.c:2054:    }   }      node *debug_mktypenode(struct pike_type *t)   {    node *res = mkemptynode();    res->token = F_CONSTANT;    copy_pike_type(res->u.sval.u.type, t);    res->u.sval.type = T_TYPE;    /* FIXME: Should be type(val) */ -  copy_pike_type(res->type, type_type_string); +  type_stack_mark(); +  push_finished_type(t); +  push_type(T_TYPE); +  res->type = pop_unfinished_type();    return freeze_node(res);   }      node *low_mkconstantsvaluenode(struct svalue *s)   {    node *res = mkemptynode();    res->token = F_CONSTANT;   #ifdef SHARED_NODES    /* We need to ensure that all bytes in the svalue struct have well    * defined values, including any padding between the subtype and the
pike.git/src/las.c:2599:    break;    }       case F_SOFT_CAST:    {    dynamic_buffer save_buf;    char *s;    init_buf(&save_buf);    my_describe_type(foo->type);    s=simple_free_buf(&save_buf); -  fprintf(stderr, "[%s]{",s); +  fprintf(stderr, "[%s(", s);    free(s); -  +  low_print_tree(_CDR(foo), 0); +  fprintf(stderr, ")]{");    low_print_tree(_CAR(foo),0);    fputc('}', stderr);    break;    }       case F_COMMA_EXPR:    low_print_tree(_CAR(foo),0);    if(_CAR(foo) && _CDR(foo))    {    if(_CAR(foo)->type == void_type_string &&
pike.git/src/las.c:3617:   #endif    }    }    if (!name) {    MAKE_CONST_STRING(name, "external symbol");    }    }    }    break;    +  case F_CAST: +  case F_SOFT_CAST: +  name = get_name_of_function(CAR(n)); +  break; +     default:    MAKE_CONST_STRING(name, "unknown function");    }   #ifdef PIKE_DEBUG    if (!name) {    Pike_fatal("Failed to get name of function.\n");    }   #endif    return name;   }
pike.git/src/las.c:3648:    return; /* assume it is correct */       old_type = n->type;    n->type = 0;    n->node_info &= ~OPT_TYPE_NOT_FIXED;       switch(n->token)    {    case F_SOFT_CAST:    if (CAR(n) && CAR(n)->type) { + #ifdef NEW_ARG_CHECK +  struct pike_type *soft_type = NULL; +  if (CDR(n) && (CDR(n)->token == F_CONSTANT) && +  (CDR(n)->u.sval.type == T_TYPE)) { +  soft_type = CDR(n)->u.sval.u.type; +  if ((n->type = soft_cast(soft_type, CAR(n)->type, 0))) { +  /* Success. */ +  break; +  } +  struct pike_string *t1 = describe_type(CAR(n)->type); +  struct pike_string *t2 = describe_type(soft_type); +  my_yyerror("Soft cast of %S to %S isn't a valid cast.", +  t2, t1); +  free_string(t2); +  free_string(t1); +  } else { +  yytype_error("Soft cast with non-type.", +  type_type_string, +  CDR(n)->type, 0); +  } +  /* Failure: Fall through to the old code. */ + #else /* !NEW_ARG_CHECK */    if (!check_soft_cast(old_type, CAR(n)->type)) {    struct pike_string *t1 = describe_type(old_type);    struct pike_string *t2 = describe_type(CAR(n)->type);    yywarning("Soft cast to %S isn't a restriction of %S.",    t1, t2);    free_string(t2);    free_string(t1);    }    /* FIXME: check_soft_cast() is weaker than pike_types_le()    * The resulting type should probably be the AND between the old    * and the new type.    */ -  + #endif /* NEW_ARG_CHECK */    }    /* FALL_THROUGH */    case F_CAST:    /* Type-field is correct by definition. */    copy_pike_type(n->type, old_type);    break;       case F_LAND:    case F_LOR:    if (!CAR(n) || CAR(n)->type == void_type_string) {