Branch: Tag:

2022-06-10

2022-06-10 18:29:54 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler [Typechecker]: Add struct call_state.

This struct is intended to contain state that is to be propagated
between arguments during typechecking of function calls.

3820:    node *efun_node = NULL;    struct pike_type *f;    enum Pike_opcodes opcode = n->token; -  INT32 args = 0; +  struct call_state cs;    -  +  INIT_CALL_STATE(cs); +     switch(opcode) {    case F_AND_EQ:    efun_name = "`&";
3893:    * for new_check_call(),    */    n->token = F_ARG_LIST; -  f = debug_malloc_pass(new_check_call(efun_string, f, n, &args, 0)); +  f = debug_malloc_pass(new_check_call(efun_string, f, n, &cs, 0));    n->token = opcode;    if (f) {    struct pike_type *ret = new_get_return_type(f, 0);
3901:    f = ret;    }    +  FREE_CALL_STATE(cs); +     if (f && CAR(n)) {    /* Check that the returned type is compatible with the    * variable type.
4100:    struct pike_type *f; /* Expected type. */    struct pike_type *s; /* Actual type */    struct pike_string *name = NULL; -  INT32 args; +  struct call_state cs;   #ifdef PIKE_DEBUG    int save_l_flag = l_flag;   
4109:    }   #endif    -  args = 0; +  INIT_CALL_STATE(cs);    name = get_name_of_function(CAR(n));      #ifdef PIKE_DEBUG
4120:       /* NOTE: new_check_call() steals a reference from f! */    copy_pike_type(f, CAR(n)->type); -  f = debug_malloc_pass(new_check_call(name, f, CDR(n), &args, 0)); +  f = debug_malloc_pass(new_check_call(name, f, CDR(n), &cs, 0));       if (!f) {    /* Errors have been generated. */
4128:    l_flag = save_l_flag;   #endif    copy_pike_type(n->type, mixed_type_string); +  +  FREE_CALL_STATE(cs);    break;    }   
4151:   #ifdef PIKE_DEBUG    l_flag = save_l_flag;   #endif +  +  FREE_CALL_STATE(cs);    break;    }   
4162:    yytype_report(REPORT_ERROR, NULL, 0, s,    NULL, 0, NULL,    0, "Too few arguments to %S (got %d).", -  name, args); +  name, cs.argno);    free_type(s);    yytype_report(REPORT_ERROR, NULL, 0, NULL,    NULL, 0, CAR(n)->type,
4177:   #ifdef PIKE_DEBUG    l_flag = save_l_flag;   #endif +  +  FREE_CALL_STATE(cs);    break;    }    copy_pike_type(n->type, mixed_type_string);
4403:    struct pike_string *sscanf_name;    struct pike_type *sscanf_type;    node *args; -  INT32 argno = 0; +  struct call_state cs;    MAKE_CONST_STRING(sscanf_name, "sscanf");    add_ref(sscanf_type = sscanf_type_string);    args = mknode(F_ARG_LIST, CAR(n), CDR(n));    add_ref(CAR(n));    if (CDR(n)) add_ref(CDR(n)); -  sscanf_type = new_check_call(sscanf_name, sscanf_type, args, &argno, 0); +  INIT_CALL_STATE(cs); +  sscanf_type = new_check_call(sscanf_name, sscanf_type, args, &cs, 0);    free_node(args);    if (sscanf_type) {    if (!(n->type = new_get_return_type(sscanf_type, 0))) {
4419:    NULL, 0, expected,    NULL, 0, NULL,    0, "Too few arguments to sscanf (got %d).", -  argno); +  cs.argno);    free_type(expected);    } else {    /* Most likely not reached. */
4431:    }    free_type(sscanf_type);    } +  FREE_CALL_STATE(cs);    if (!n->type) {    MAKE_CONSTANT_TYPE(n->type, tIntPos);    }