Branch: Tag:

2018-11-05

2018-11-05 13:08:34 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Added syntax for annotations.

Note that the annotations are currently thrown away.

317:   %type <n> TOK_IDENTIFIER   %type <n> TOK_RESERVED   %type <n> TOK_VERSION + %type <n> annotation   %type <n> attribute   %type <n> assoc_pair   %type <n> line_number_info
343:   %type <n> continue   %type <n> default   %type <n> do + %type <n> constant_expr   %type <n> safe_expr0   %type <n> splice_expr   %type <n> expr01
1064:    | constant {}    | modifiers named_class { free_node($2); }    | modifiers enum { free_node($2); } +  | annotation ';' { free_node($1); }    | typedef {}    | static_assertion expected_semicolon {}    | error TOK_LEX_EOF
1263:    }    ;    + annotation: '@' constant_expr +  { +  $$ = $2; +  } +  ; +    modifiers: modifier_list    {    $$=Pike_compiler->current_modifiers=$1 |    (THIS_COMPILATION->lex.pragmas & ID_MODIFIER_MASK);    } -  +  | annotation ':' modifiers +  { +  if ($1) free_node($1); +  $$ = $3; +  }    ;      modifier_list: /* empty */ { $$ = 0; }
1922:    ;       + constant_expr: safe_expr0 +  { +  /* Ugly hack to make sure that $1 is optimized */ +  { +  int tmp = Pike_compiler->compiler_pass; +  $$ = mknode(F_COMMA_EXPR, $1, 0); +  optimize_node($$); +  Pike_compiler->compiler_pass = tmp; +  } +  +  if(!is_const($$)) { +  if(Pike_compiler->compiler_pass == COMPILER_PASS_LAST) +  yyerror("Expected constant expression."); +  push_int(0); +  } else { +  ptrdiff_t tmp = eval_low($$, 1); +  if(tmp < 1) +  { +  if(Pike_compiler->compiler_pass == COMPILER_PASS_LAST) +  yyerror("Error evaluating constant expression."); +  push_int(0); +  } else { +  pop_n_elems((INT32)(tmp - 1)); +  } +  } +  free_node($$); +  $$ = mksvaluenode(Pike_sp - 1); +  pop_stack(); +  } +  ; +    local_constant_name: TOK_IDENTIFIER '=' safe_expr0    {    struct pike_type *type;