pike.git / src / las.c

version» Context lines:

pike.git/src/las.c:30:   #include "pikecode.h"   #include "gc.h"   #include "pike_compiler.h"   #include "block_allocator.h"      /* Define this if you want the optimizer to be paranoid about aliasing    * effects to to indexing.    */   /* #define PARANOID_INDEXING */    - /* #define NEW_ARG_CHECK */ -  +    static node *eval(node *);   static void optimize(node *n);      int cumulative_parse_error=0;   extern char *get_type_name(int);      #define MAX_GLOBAL 2048      /* #define yywarning my_yyerror */   
pike.git/src/las.c:1386:    }       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))) {    ref_push_type_value(n->type);    ref_push_type_value(type);    yytype_report(REPORT_ERROR,    NULL, 0, type,    NULL, 0, n->type,    2, "Soft cast of %O to %O isn't a valid cast.");    } else if (result_type == n->type) {    ref_push_type_value(n->type);    ref_push_type_value(type);    yytype_report(REPORT_WARNING,    NULL, 0, NULL,    NULL, 0, NULL,    2, "Soft cast of %O to %O is a noop.");    } - #else /* !NEW_ARG_CHECK */ -  if (!check_soft_cast(type, n->type)) { -  ref_push_type_value(type); -  ref_push_type_value(n->type); -  yytype_report(REPORT_WARNING, -  NULL, 0, NULL, -  NULL, 0, NULL, -  2, "Soft cast to %S isn't a restriction of %S."); +     } -  /* 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;
pike.git/src/las.c:3088:    /* Make a temporary node (lval = 0), so that we can use depend_p(). */    ADD_NODE_REF2(lval,    tmp = mknode(F_ASSIGN, mkintnode(0), lval));    ret = depend_p(n, tmp);    free_node(tmp);    return ret;   }      static int function_type_max=0;    - #ifndef NEW_ARG_CHECK - /* FIXME: Ought to use parent pointer to avoid recursion. */ - static void low_build_function_type(node *n) - { -  if(!n) return; -  if(function_type_max++ > 999) -  { -  reset_type_stack(); -  -  push_type(T_MIXED); -  push_type(T_VOID); -  push_type(T_OR); /* return type is void or mixed */ -  -  push_type(T_MIXED); -  push_type(T_VOID); -  push_type(T_OR); /* varargs */ -  -  push_type(T_MANY); -  return; -  } -  switch(n->token) -  { -  case F_COMMA_EXPR: -  case F_ARG_LIST: -  fatal_check_c_stack(16384); -  -  low_build_function_type(CDR(n)); -  low_build_function_type(CAR(n)); -  break; -  -  case F_PUSH_ARRAY: -  { -  struct pike_type *so_far; -  struct pike_type *arg_type; -  struct pike_type *tmp; -  -  so_far = pop_type(); -  -  copy_pike_type(arg_type, void_type_string); -  -  /* Convert fun(a,b,c...:d) to fun(a|b|c|void...:d) -  */ -  -  while(so_far->type == T_FUNCTION) { -  tmp = or_pike_types(arg_type, so_far->car, 1); -  free_type(arg_type); -  arg_type = tmp; -  copy_pike_type(tmp, so_far->cdr); -  free_type(so_far); -  so_far = tmp; -  } -  -  tmp = or_pike_types(arg_type, so_far->car, 1); -  free_type(arg_type); -  arg_type = tmp; -  -  push_finished_type(so_far->cdr); /* Return type */ -  -  free_type(so_far); -  -  so_far = index_type(CAR(n)->type, int_type_string, n); -  tmp = or_pike_types(arg_type, so_far, 1); -  push_finished_type(tmp); -  if (tmp == mixed_type_string) { -  /* Ensure "or void"... */ -  push_type(T_VOID); -  push_type(T_OR); -  } -  free_type(arg_type); -  free_type(so_far); -  free_type(tmp); -  push_type(T_MANY); -  } -  return; -  -  default: -  if(n->type) -  { -  if(n->type == void_type_string) return; -  push_finished_type(n->type); -  }else{ -  push_type(T_MIXED); -  } -  push_type(T_FUNCTION); -  } - } - #endif -  +    static struct pike_string *get_name_of_function(node *n)   {    struct pike_string *name = NULL;    if (!n) {    MAKE_CONST_STRING(name, "NULL");    return name;    }    switch(n->token)    {   #if 0 /* FIXME */
pike.git/src/las.c:3351:    These two are needed if we want to extract types    from nodes while building the tree.    */    if( CAR(n) ) fix_type_field(CAR(n));    if( CDR(n) ) fix_type_field(CDR(n));       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) &&    (TYPEOF(CDR(n)->u.sval) == T_TYPE)) {    soft_type = CDR(n)->u.sval.u.type;    if ((n->type = soft_cast(soft_type, CAR(n)->type, 0))) {    /* Success. */    break;    }    ref_push_type_value(CAR(n)->type);    ref_push_type_value(soft_type);    yytype_report(REPORT_ERROR, NULL, 0, NULL, NULL, 0, NULL,    2, "Soft cast of %O to %O isn't a valid cast.");    } else {    yytype_report(REPORT_ERROR, NULL, 0, type_type_string,    NULL, 0, CDR(n)->type, 0,    "Soft cast with non-type.");    } -  /* Failure: Fall through to the old code. */ - #else /* !NEW_ARG_CHECK */ -  if (!check_soft_cast(old_type, CAR(n)->type)) { -  ref_push_type_value(old_type); -  ref_push_type_value(CAR(n)->type); -  yytype_report(REPORT_ERROR, NULL, 0, NULL, NULL, 0, NULL, -  2, "Soft cast to %S isn't a restriction of %S.", -  t1, t2); +     } -  /* 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) {    yyerror("Conditional uses void expression.");
pike.git/src/las.c:3618:    break;       case F_AUTO_MAP:    case F_APPLY:    if (!CAR(n) || (CAR(n)->type == void_type_string)) {    yyerror("Calling a void expression.");    } else {    struct pike_type *f; /* Expected type. */    struct pike_type *s; /* Actual type */    struct pike_string *name = NULL; - #ifndef NEW_ARG_CHECK -  char *alternate_name = NULL; - #endif +     INT32 args;    - #ifdef NEW_ARG_CHECK -  +     args = 0; -  +     name = get_name_of_function(CAR(n));      #ifdef PIKE_DEBUG    if (l_flag>2)    safe_pike_fprintf (stderr, "Checking call to %S at %S:%ld.\n", name,    n->current_file, (long)n->line_number);   #endif /* PIKE_DEBUG */       /* NOTE: new_check_call() steals a reference from f! */    copy_pike_type(f, CAR(n)->type);
pike.git/src/las.c:3682: Inside #if defined(NEW_ARG_CHECK)
   NULL, 0, CAR(n)->type,    0, "Function type:");    } else {    yytype_report(REPORT_ERROR, NULL, 0, function_type_string,    NULL, 0, f,    0, "Attempt to call a non function value %S.",    name);    }    free_type(f);    break; - #else /* !NEW_ARG_CHECK */ -  -  if (!match_types(CAR(n)->type, function_type_string) && -  !match_types(CAR(n)->type, array_type_string)) { -  yytype_report(REPORT_ERROR, NULL, 0, function_type_string, -  NULL, 0, CAR(n)->type, -  0, "Calling non function value."); -  copy_pike_type(n->type, mixed_type_string); -  -  /* print_tree(n); */ -  break; +     } -  -  push_type(T_MIXED); /* match any return type */ -  push_type(T_VOID); /* even void */ -  push_type(T_OR); -  -  push_type(T_VOID); /* not varargs */ -  push_type(T_MANY); -  function_type_max=0; -  low_build_function_type(CDR(n)); -  s = pop_type(); -  f = CAR(n)->type?CAR(n)->type:mixed_type_string; -  n->type = check_call(s, f, -  (c->lex.pragmas & ID_STRICT_TYPES) && -  !(n->node_info & OPT_WEAK_TYPE)); -  args = count_arguments(s); -  max_args = count_arguments(f); -  if(max_args<0) max_args = 0x7fffffff; -  -  -  if (n->type) { -  /* Type/argument-check OK. */ -  free_type(s); -  -  if(n->token == F_AUTO_MAP) -  { -  push_finished_type(n->type); -  push_type(T_ARRAY); -  free_type(n->type); -  n->type = pop_type(); -  } -  -  break; -  } -  -  switch(CAR(n)->token) -  { - #if 0 /* FIXME */ -  case F_TRAMPOLINE: - #endif -  case F_IDENTIFIER: -  name=ID_FROM_INT(Pike_compiler->new_program, CAR(n)->u.id.number)->name; -  break; -  -  case F_ARROW: -  case F_INDEX: -  if(CDAR(n)->token == F_CONSTANT && -  TYPEOF(CDAR(n)->u.sval) == T_STRING) -  { -  name=CDAR(n)->u.sval.u.string; -  }else{ -  alternate_name="dynamically resolved function"; -  } -  break; -  -  case F_CONSTANT: -  switch(TYPEOF(CAR(n)->u.sval)) -  { -  case T_FUNCTION: -  if(SUBTYPEOF(CAR(n)->u.sval) == FUNCTION_BUILTIN) -  { -  name=CAR(n)->u.sval.u.efun->name; -  }else{ -  name=ID_FROM_INT(CAR(n)->u.sval.u.object->prog, -  SUBTYPEOF(CAR(n)->u.sval))->name; -  } -  break; -  -  case T_ARRAY: -  alternate_name="array call"; -  break; -  -  case T_PROGRAM: -  alternate_name="clone call"; -  break; -  -  default: -  alternate_name="`() (function call)"; -  break; -  } -  break; -  -  case F_EXTERNAL: -  case F_GET_SET: -  { -  int id_no = CAR(n)->u.integer.b; -  -  if (id_no == IDREF_MAGIC_THIS) -  alternate_name = "this"; /* Should perhaps qualify it. */ -  -  else { -  int program_id = CAR(n)->u.integer.a; -  struct program_state *state = Pike_compiler; -  -  alternate_name="external symbol"; -  -  while (state && (state->new_program->id != program_id)) { -  state = state->previous; -  } -  -  if (state) { -  struct identifier *id = ID_FROM_INT(state->new_program, id_no); -  if (id && id->name) { -  name = id->name; - #if 0 - #ifdef PIKE_DEBUG -  /* FIXME: This test crashes on valid code because the type of the -  * identifier can change in pass 2 -Hubbe -  */ -  if(id->type != f) -  { -  printf("Type of external node is not matching it's identifier.\nid->type: "); -  simple_describe_type(id->type); -  printf("\nf : "); -  simple_describe_type(f); -  printf("\n"); -  -  Pike_fatal("Type of external node is not matching it's identifier.\n"); -  } - #endif - #endif -  } -  } -  } -  } -  break; -  -  default: -  alternate_name="unknown function"; -  } -  -  if(max_args < args) -  { -  if(TEST_COMPAT(0,6)) -  { -  free_type(s); +     copy_pike_type(n->type, mixed_type_string);    break; -  } -  if (name) { -  my_yyerror("Too many arguments to %S.", name); -  } else { -  my_yyerror("Too many arguments to %s.", alternate_name); -  } -  } -  else if(max_correct_args == args) -  { -  if (name) { -  my_yyerror("Too few arguments to %S.", name); -  } else { -  my_yyerror("Too few arguments to %s.", alternate_name); -  } -  } else if (name) { -  my_yyerror("Bad argument %d to %S.", max_correct_args+1, name); -  } else { -  my_yyerror("Bad argument %d to %s.", -  max_correct_args+1, alternate_name); -  } +     -  yytype_error(NULL, f, s, 0); -  -  /* print_tree(n); */ -  -  free_type(s); - #endif /* NEW_ARG_CHECK */ -  } -  copy_pike_type(n->type, mixed_type_string); -  break; -  +     case '?':    if (!CAR(n) || (CAR(n)->type == void_type_string)) {    yyerror("Conditional expression is void.");    } else if(!match_types(CAR(n)->type, mixed_type_string))    yyerror("Bad conditional expression.");       if(!CDR(n) || !CADR(n) || !CDDR(n) ||    CADR(n)->type == void_type_string ||    CDDR(n)->type == void_type_string)    {