Branch: Tag:

2001-04-01

2001-04-01 13:58:53 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Implemented typedef. Fixes [bug 1461].

Rev: src/language.yacc:1.239
Rev: src/lexer.h:1.31

84:   %token TOK_STATIC   %token TOK_STRING_ID   %token TOK_SUB_EQ + %token TOK_TYPEDEF   %token TOK_TYPEOF   %token TOK_VARIANT   %token TOK_VOID_ID
111:   /* This is the grammar definition of Pike. */      #include "global.h" - RCSID("$Id: language.yacc,v 1.238 2001/03/31 15:20:43 grubba Exp $"); + RCSID("$Id: language.yacc,v 1.239 2001/04/01 13:58:53 grubba Exp $");   #ifdef HAVE_MEMORY_H   #include <memory.h>   #endif
276:   %type <n> catch_arg   %type <n> class   %type <n> enum - %type <n> enum_identifier +    %type <n> safe_comma_expr   %type <n> comma_expr   %type <n> comma_expr2
332:   %type <n> local_function   %type <n> local_function2   %type <n> magic_identifier + %type <n> simple_identifier   %type <n> foreach_lvalues   %type <n> foreach_optional_lvalue   %%
878:    | constant {}    | class { free_node($1); }    | enum { free_node($1); } +  | typedef {}    | error TOK_LEX_EOF    {    reset_type_stack();
1012:    | TOK_FLOAT_ID { $$ = "float"; }    | TOK_INT_ID { $$ = "int"; }    | TOK_ENUM { $$ = "enum"; } +  | TOK_TYPEDEF { $$ = "typedef"; }    ;      magic_identifiers3:
1080:    }    ;    + full_type: type8 +  | type8 '*' +  { +  if (Pike_compiler->compiler_pass == 2) { +  yywarning("The *-syntax in types is obsolete. Use array instead."); +  } +  push_type(T_ARRAY); +  } +  ; +    type6: type | identifier_type ;      type: type '*'
2374:    }    ;    - enum_identifier: TOK_IDENTIFIER + simple_identifier: TOK_IDENTIFIER    | bad_identifier { $$ = 0; }    ;   
2420:    ;      enum_def: /* EMPTY */ -  | enum_identifier enum_value +  | simple_identifier enum_value    {    if ($1) {    add_constant($1->u.sval.u.string, Pike_sp-1,
2431:    {    struct pike_type *current = pop_unfinished_type();    struct pike_type *new = get_type_of_svalue(Pike_sp-1); -  struct pike_type *res = or_pike_types(current, new, 1); +  struct pike_type *res = or_pike_types(new, current, 1);    free_type(current);    free_type(new);    type_stack_mark();
2471:    }    ;    + typedef: modifiers TOK_TYPEDEF full_type simple_identifier ';' +  { +  struct pike_type *t = compiler_pop_type(); +  +  if ((Pike_compiler->current_modifiers & ID_EXTERN) && +  (Pike_compiler->compiler_pass == 1)) { +  yywarning("Extern declared typedef."); +  } +  +  if ($4) { +  ref_push_type_value(t); +  add_constant($4->u.sval.u.string, Pike_sp-1, +  Pike_compiler->current_modifiers & ~ID_EXTERN); +  pop_stack(); +  free_node($4); +  } +  free_type(t); +  } +  ; +    cond: TOK_IF    {    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
3482:      /* FIXME: Should probably set Pike_compiler->last_identifier. */   bad_identifier: bad_expr_ident -  | TOK_CLASS -  { yyerror("class is a reserved word."); } +     | TOK_ARRAY_ID    { yyerror("array is a reserved word."); } -  +  | TOK_CLASS +  { yyerror("class is a reserved word."); } +  | TOK_ENUM +  { yyerror("enum is a reserved word."); }    | TOK_FLOAT_ID    { yyerror("float is a reserved word.");}    | TOK_FUNCTION_ID
3504:    { yyerror("program is a reserved word."); }    | TOK_STRING_ID    { yyerror("string is a reserved word."); } +  | TOK_TYPEDEF +  { yyerror("typedef is a reserved word."); }    | TOK_VOID_ID    { yyerror("void is a reserved word."); } -  | TOK_ENUM -  { yyerror("enum is a reserved word."); } +     ;      bad_expr_ident: