Branch: Tag:

1999-11-23

1999-11-23 22:04:17 by Henrik Grubbström (Grubba) <grubba@grubba.org>

F_SOFT_CAST nodes now seem to work!

Rev: src/las.c:1.129

5:   \*/   /**/   #include "global.h" - RCSID("$Id: las.c,v 1.128 1999/11/23 03:07:35 grubba Exp $"); + RCSID("$Id: las.c,v 1.129 1999/11/23 22:04:17 grubba Exp $");      #include "language.h"   #include "interpret.h"
46:      #define MAX_GLOBAL 2048    + /* #define yywarning my_yyerror */ +    int car_is_node(node *n)   {    switch(n->token)
72:    case F_CONSTANT:    case F_LOCAL:    case F_CAST: +  case F_SOFT_CAST:    return 0;       default:
142:    else    return count_args(CAR(n));    +  case F_SOFT_CAST: +  return count_args(CAR(n)); +     case F_CASE:    case F_FOR:    case F_DO:
478: Inside #if defined(PIKE_DEBUG) && !defined(SHARED_NODES)
  #if defined(PIKE_DEBUG) && !defined(SHARED_NODES)    if(b && a==b)    fatal("mknode: a and be are the same!\n"); -  if (token == F_CAST) +  if ((token == F_CAST) || (token == F_SOFT_CAST))    fatal("Attempt to create a cast-node with mknode()!\n");   #endif   
914:    }   #endif /* PIKE_DEBUG */    +  if (type == void_type_string) return mknode(F_POP_VALUE, n, 0); +     if(type==n->type) return n;       if (n->type) { -  if (!match_types(type, n->type)) { +  if (!pike_types_le(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.",
1223:    return a->u.id.number == b->u.id.number;       case F_CAST: +  case F_SOFT_CAST:    return a->type == b->type && node_is_eq(CAR(a), CAR(b));       case F_CONSTANT:
1351: Inside #if defined(DEAD_CODE)
   b=mkcastnode(n->type,copy_node(CAR(n)));    break;    +  case F_SOFT_CAST: +  b=mksoftcastnode(n->type,copy_node(CAR(n))); +  break; +     case F_CONSTANT:    b=mksvaluenode(&(n->u.sval));    break;
1455:    node **n;    if(!a || !*a) return (node **)NULL;    if(((*a)->token == F_CAST) || +  ((*a)->token == F_SOFT_CAST) ||    ((*a)->token == F_POP_VALUE)) return last_cmd(&_CAR(*a));    if(((*a)->token != F_ARG_LIST) &&    ((*a)->token != F_COMMA_EXPR)) return a;    if(CDR(*a))    {    if(CDR(*a)->token != F_CAST && -  +  CDR(*a)->token != F_SOFT_CAST &&    CDR(*a)->token != F_POP_VALUE &&    CAR(*a)->token != F_ARG_LIST && /* FIXME: typo? */    CAR(*a)->token != F_COMMA_EXPR) /* FIXME: typo? */
1471:    if(CAR(*a))    {    if(CAR(*a)->token != F_CAST && +  CAR(*a)->token != F_SOFT_CAST &&    CAR(*a)->token != F_POP_VALUE &&    CAR(*a)->token != F_ARG_LIST &&    CAR(*a)->token != F_COMMA_EXPR)
1599:    break;    }    +  case F_SOFT_CAST: +  { +  char *s; +  init_buf(); +  low_describe_type(foo->type->str); +  s=simple_free_buf(); +  fprintf(stderr, "[%s]{",s); +  free(s); +  low_print_tree(_CAR(foo),0); +  fprintf(stderr, "}"); +  break; +  } +     case F_COMMA_EXPR:    low_print_tree(_CAR(foo),0);    if(_CAR(foo) && _CDR(foo))
1962:    switch(n->token)    {    case F_CAST: +  case F_SOFT_CAST:    case F_APPLY:    return n->type != void_type_string;   
2039:    {    case F_SOFT_CAST:    if (CAR(n) && CAR(n)->type) { -  if (!match_types(old_type, CAR(n)->type)) { +  if (!pike_types_le(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.",
2082:    copy_shared_string(n->type, void_type_string);    break;    } else if(CAR(n) && CDR(n)) { +  /* Ensure that the type-fields are up to date. */    fix_type_field(CAR(n));    fix_type_field(CDR(n)); -  +  if (!pike_types_le(CAR(n)->type, CDR(n)->type)) {    /* a["b"]=c and a->b=c can be valid when a is an array */    if (CDR(n)->token != F_INDEX && CDR(n)->token != F_ARROW &&    !match_types(CDR(n)->type,CAR(n)->type)) {    my_yyerror("Bad type in assignment."); -  +  } else if (lex.pragmas & ID_STRICT_TYPES) { +  struct pike_string *t1 = describe_type(CAR(n)->type); +  struct pike_string *t2 = describe_type(CDR(n)->type); +  print_tree(n); +  yywarning("An expression type %s cannot be assigned to " +  "a variable of type %s.", +  t1->str, t2->str); +  free_string(t2); +  free_string(t1); +  yywarning("Incompatible types in assignment.");    }    } -  +  }    n->type = and_pike_types(CAR(n)->type, CDR(n)->type);    break;   
2098:    if (!CAR(n) || (CAR(n)->type == void_type_string)) {    my_yyerror("Indexing a void expression.");    /* The optimizer converts this to an expression returning 0. */ -  copy_shared_string(n->type, mixed_type_string); +  copy_shared_string(n->type, zero_type_string);    } else {    type_a=CAR(n)->type;    type_b=CDR(n)->type;
2257:   #endif /* SHARED_NODES */    break;    } -  } else if(compiler_frame && -  compiler_frame->current_return_type && -  !match_types(compiler_frame->current_return_type,CAR(n)->type) && +  } else if(compiler_frame && compiler_frame->current_return_type) { +  if (!pike_types_le(CAR(n)->type, compiler_frame->current_return_type) &&    !(    compiler_frame->current_return_type==void_type_string &&    CAR(n)->token == F_CONSTANT &&    IS_ZERO(& CAR(n)->u.sval)    ) -  ) +  ) { +  if (!match_types(compiler_frame->current_return_type,CAR(n)->type))    {    yyerror("Wrong return type.");    } -  +  else if (lex.pragmas & ID_STRICT_TYPES) +  { +  yywarning("Return type mismatch."); +  } +  } +  }       /* Fall through */   
2317:    break;       case F_UNDEFINED: -  MAKE_CONSTANT_SHARED_STRING(n->type, tInt0); +  MAKE_CONSTANT_SHARED_STRING(n->type, tZero);    break;       case F_ARG_LIST:
2755: Inside #if defined(SHARED_NODES) && !defined(IN_TPIKE)
   return mkcastnode(n->type, low_localopt(CAR(n), usage, switch_u, cont_u,    break_u, catch_u));    +  case F_SOFT_CAST: +  return mksoftcastnode(n->type, low_localopt(CAR(n), usage, switch_u, +  cont_u, break_u, catch_u)); +     case F_CONTINUE:    MEMCPY(usage, cont_u, MAX_LOCAL);    ADD_NODE_REF(n);
3394:    extern struct svalue *sp;    if(!is_const(n) || n->token==':')    return n; +     args=eval_low(n);       switch(args)
3414:    pop_stack();    return n;    } +  if (n->token != F_SOFT_CAST) {    free_node(n);    n=mksvaluenode(sp-1); -  +  } else { +  node *nn = n; +  n = mksoftcastnode(n->type, mksvaluenode(sp-1)); +  free_node(nn); +  }    pop_stack();    break;       default: -  +  if (n->token != F_SOFT_CAST) {    free_node(n);    n=NULL;    while(args--)
3427:    n=mknode(F_ARG_LIST,mksvaluenode(sp-1),n);    pop_stack();    } +  } else { +  node *nn = n; +  n = NULL; +  while(args--) +  { +  n=mknode(F_ARG_LIST,mksvaluenode(sp-1),n); +  pop_stack();    } -  +  n = mksoftcastnode(nn->type, n); +  free_node(nn); +  } +  }    return dmalloc_touch(node *, n);   }