pike.git / src / las.c

version» Context lines:

pike.git/src/las.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   /**/   #include "global.h" - RCSID("$Id: las.c,v 1.148 1999/12/22 19:05:17 grubba Exp $"); + RCSID("$Id: las.c,v 1.149 1999/12/22 23:04:50 grubba Exp $");      #include "language.h"   #include "interpret.h"   #include "las.h"   #include "array.h"   #include "object.h"   #include "stralloc.h"   #include "dynamic_buffer.h"   #include "lex.h"   #include "pike_types.h"
pike.git/src/las.c:2128:    if(n->type)    {    if(n->type == void_type_string) return;    push_finished_type(n->type);    }else{    push_type(T_MIXED);    }    }   }    + #define YYTE_IS_WARNING 1    -  + static void yytype_error(char *msg, struct pike_string *expected_t, +  struct pike_string *got_t, unsigned int flags) + { +  struct pike_string *expected = describe_type(expected_t); +  struct pike_string *got = describe_type(got_t); +  +  if (flags & YYTE_IS_WARNING) { +  if (msg) { +  yywarning("%s", msg); +  } +  yywarning("Expected: %s", expected->str); +  yywarning("Got : %s", got->str); +  } else { +  if (msg) { +  my_yyerror("%s", msg); +  } +  my_yyerror("Expected: %s", expected->str); +  my_yyerror("Got : %s", got->str); +  } +  free_string(got); +  free_string(expected); + } +    void fix_type_field(node *n)   {    struct pike_string *type_a,*type_b;    struct pike_string *old_type;       if (n->type && !(n->node_info & OPT_TYPE_NOT_FIXED))    return; /* assume it is correct */       old_type = n->type;    n->type = 0;
pike.git/src/las.c:2197:    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)) { -  -  struct pike_string *s1,*s2; -  s1=describe_type(CDR(n)->type); -  s2=describe_type(CAR(n)->type); -  my_yyerror("Bad type in assignment."); -  my_yyerror("Expected: %s",s1->str); -  my_yyerror("Got : %s",s2->str); -  free_string(s1); -  free_string(s2); -  +  yytype_error("Bad type in assignment.", +  CDR(n)->type, CAR(n)->type, 0);    } 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);   #ifdef PIKE_DEBUG    if (l_flag > 0) {    fprintf(stderr, "Warning: Invalid assignment: ");    print_tree(n);    }   #endif /* PIKE_DEBUG */    yywarning("An expression type %s cannot be assigned to "
pike.git/src/las.c:2338:    my_yyerror("Too many arguments to %s.",name);    }    else if(max_correct_args == args)    {    my_yyerror("Too few arguments to %s.",name);    }else{    my_yyerror("Bad argument %d to %s.",    max_correct_args+1, name);    }    -  { -  struct pike_string *s1,*s2; -  s1=describe_type(f); -  s2=describe_type(s); -  my_yyerror("Expected: %s",s1->str); -  my_yyerror("Got : %s",s2->str); -  free_string(s1); -  free_string(s2); -  } +  yytype_error(NULL, f, s, 0); +     free_string(s);    }    copy_shared_string(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.");
pike.git/src/las.c:2434:    )    ) {    if (!match_types(compiler_frame->current_return_type,CAR(n)->type))    {    yyerror("Wrong return type.");    yyexplain_nonmatching_types(compiler_frame->current_return_type,    CAR(n)->type);    }    else if (lex.pragmas & ID_STRICT_TYPES)    { -  struct pike_string *t1 = -  describe_type(compiler_frame->current_return_type); -  struct pike_string *t2 = describe_type(CAR(n)->type); -  yywarning("Return type mismatch."); -  yywarning("Expected: %s", t1->str); -  yywarning("Got : %s", t2->str); -  free_string(t2); -  free_string(t1); +  yytype_error("Return type mismatch.", +  compiler_frame->current_return_type, +  CAR(n)->type, +  YYTE_IS_WARNING);    }    }    }       /* Fall through */       case F_INC_LOOP:    case F_DEC_LOOP:    case F_DEC_NEQ_LOOP:    case F_INC_NEQ_LOOP:
pike.git/src/las.c:2516:    free_string(t);    }       if (!CDAR(n) || pike_types_le(CDAR(n)->type, void_type_string)) {    yyerror("Bad argument 2 to foreach().");    } else {    struct pike_string *value_type = array_value_type(CAAR(n)->type);       if (!pike_types_le(value_type, CDAR(n)->type)) {    if (!match_types(value_type, CDAR(n)->type)) { -  struct pike_string *t1 = describe_type(value_type); -  struct pike_string *t2 = describe_type(CDAR(n)->type); -  my_yyerror("Variable type mismatch in foreach()."); -  my_yyerror("Expected: %s", t1->str); -  my_yyerror("Got : %s", t2->str); -  free_string(t2); -  free_string(t1); +  yytype_error("Variable type mismatch in foreach().", +  value_type, CDAR(n)->type, 0);    } else if (lex.pragmas & ID_STRICT_TYPES) { -  struct pike_string *t1 = describe_type(value_type); -  struct pike_string *t2 = describe_type(CDAR(n)->type); -  yywarning("Variable type mismatch in foreach()."); -  yywarning("Expected: %s", t1->str); -  yywarning("Got : %s", t2->str); -  free_string(t2); -  free_string(t1); +  yytype_error("Variable type mismatch in foreach().", +  value_type, CDAR(n)->type, 0);    }    }    free_string(value_type);    }    }    free_string(array_zero);    }    }    copy_shared_string(n->type, void_type_string);    break;       case F_SSCANF:    if (!CAR(n) || (CAR(n)->token != F_ARG_LIST) ||    !CAAR(n) || !CDAR(n)) {    yyerror("Too few arguments to sscanf().");    } else {    if (!pike_types_le(CAAR(n)->type, string_type_string)) {    if (!match_types(CAAR(n)->type, string_type_string)) { -  yyerror("Bad argument 1 to sscanf()."); +  yytype_error("Bad argument 1 to sscanf().", +  string_type_string, CAAR(n)->type, 0);    } else if (lex.pragmas & ID_STRICT_TYPES) { -  struct pike_string *t = describe_type(CAAR(n)->type); -  yywarning("Argument 1 to sscanf() has bad type " -  "(%s expected string).", t->str); -  free_string(t); +  yytype_error("Argument 1 to sscanf() has bad type.", +  string_type_string, CAAR(n)->type, YYTE_IS_WARNING);    }    }    if (!pike_types_le(CDAR(n)->type, string_type_string)) {    if (!match_types(CDAR(n)->type, string_type_string)) { -  yyerror("Bad argument 2 to sscanf()."); +  yytype_error("Bad argument 2 to sscanf().", +  string_type_string, CDAR(n)->type, 0);    } else if (lex.pragmas & ID_STRICT_TYPES) { -  struct pike_string *t = describe_type(CAAR(n)->type); -  yywarning("Argument 2 to sscanf() has bad type " -  "(%s expected string).", t->str); -  free_string(t); +  yytype_error("Argument 2 to sscanf() has bad type.", +  string_type_string, CDAR(n)->type, YYTE_IS_WARNING);    }    }    }    MAKE_CONSTANT_SHARED_STRING(n->type, tIntPos);    break;       case F_UNDEFINED:    MAKE_CONSTANT_SHARED_STRING(n->type, tZero);    break;