Branch: Tag:

2019-03-26

2019-03-26 10:06:16 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Allow full constant expressions in import.

185:   static node *safe_inc_enum(node *n);   static node *find_versioned_identifier(struct pike_string *identifier,    int major, int minor); - static int call_handle_import(struct pike_string *s); - static void update_current_type(); + static int call_handle_import(void); + static void update_current_type(void);      static int inherit_depth;   static struct program_state *inherit_state = NULL;
522:    | modifiers TOK_INHERIT error '}' { yyerror("Missing ';'."); }    ;    - import: TOK_IMPORT idents ';' + import: TOK_IMPORT constant_expr ';'    {    resolv_constant($2);    free_node($2); -  use_module(Pike_sp-1); -  pop_stack(); +  if (TYPEOF(Pike_sp[-1]) == PIKE_T_STRING) { +  call_handle_import();    } -  | TOK_IMPORT string ';' -  { -  if (call_handle_import($2->u.sval.u.string)) { +     use_module(Pike_sp-1);    pop_stack();    } -  free_node($2); -  } -  | TOK_IMPORT error ';' { yyerrok; } -  | TOK_IMPORT error TOK_LEX_EOF -  { -  yyerror("Missing ';'."); -  yyerror("Unexpected end of file."); -  } -  | TOK_IMPORT error '}' { yyerror("Missing ';'."); } +     ;      constant_name: TOK_IDENTIFIER '=' safe_expr0
4128:    | '.' TOK_IDENTIFIER    {    struct pike_string *dot; -  MAKE_CONST_STRING(dot, "."); -  if (call_handle_import(dot)) { +  push_constant_text("."); +  if (call_handle_import()) {    node *tmp=mkconstantsvaluenode(Pike_sp-1);    pop_stack();    $$=index_node(tmp, ".", $2->u.sval.u.string);
4555:    { yyerror_reserved("gauge"); }    | TOK_IF    { yyerror_reserved("if"); } +  | TOK_IMPORT +  { yyerror_reserved("import"); }    | TOK_INT_ID    { yyerror_reserved("int"); }    | TOK_LAMBDA
4617:    { yyerror_reserved("final");}    | TOK_ELSE    { yyerror("else without if."); } -  | TOK_IMPORT -  { yyerror_reserved("import"); } +     | TOK_INHERIT    { yyerror_reserved("inherit"); }    ;
4986:    return res;   }    - static int call_handle_import(struct pike_string *s) + static int call_handle_import(void)   { -  ref_push_string(s); +     if (safe_apply_low2(Pike_fp->current_object,    PC_HANDLE_IMPORT_FUN_NUM    + Pike_fp->context->identifier_level, 1, NULL)) {
5001:    if (TYPEOF(Pike_sp[-1]) != T_INT) return 1;       pop_stack(); -  my_yyerror("Couldn't find module to import: %S", s); +  my_yyerror("Couldn't find module to import.");    return 0;    }    my_yyerror("Invalid return value from handle_import: %O", Pike_sp-1);
5015:   }      /* Set compiler_frame->current_type from the type stack. */ - static void update_current_type() + static void update_current_type(void)   {    if(Pike_compiler->compiler_frame->current_type)    free_type(Pike_compiler->compiler_frame->current_type);    Pike_compiler->compiler_frame->current_type = compiler_pop_type();   }