pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:1:   /* -*- c -*-   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: language.yacc,v 1.447 2008/07/14 11:38:30 grubba Exp $ + || $Id: language.yacc,v 1.448 2008/07/18 18:06:22 grubba Exp $   */      %pure_parser      %token TOK_ARROW      /*    * Basic value pushing    */   %token TOK_CONSTANT TOK_FLOAT TOK_STRING
pike.git/src/language.yacc:156:      /* #define LAMBDA_DEBUG 1 */      static void yyerror_reserved(const char *keyword);   static struct pike_string *get_new_name(struct pike_string *prefix);   int add_local_name(struct pike_string *, struct pike_type *, node *);   int low_add_local_name(struct compiler_frame *,    struct pike_string *, struct pike_type *, node *);   static void mark_lvalues_as_used(node *n);   static node *lexical_islocal(struct pike_string *); - static void safe_inc_enum(void); + static node *safe_inc_enum(node *n);   static int call_handle_import(struct pike_string *s);      static int inherit_depth;   static struct program_state *inherit_state = NULL;      /*    * Kludge for Bison not using prototypes.    */   #ifndef __GNUC__   #ifndef __cplusplus
pike.git/src/language.yacc:303:   %type <n> open_paren_with_line_info   %type <n> close_paren_or_missing   %type <n> open_bracket_with_line_info   %type <n> block_or_semi   %type <n> break   %type <n> case   %type <n> catch   %type <n> catch_arg   %type <n> class   %type <n> enum + %type <n> enum_def + %type <n> enum_value   %type <n> safe_comma_expr   %type <n> comma_expr   %type <n> comma_expr2   %type <n> range_bound   %type <n> cond   %type <n> continue   %type <n> default   %type <n> do   %type <n> safe_expr0   %type <n> expr00
pike.git/src/language.yacc:343:   %type <n> lvalue   %type <n> lvalue_list   %type <n> low_lvalue_list   %type <n> m_expr_list   %type <n> m_expr_list2   %type <n> new_local_name   %type <n> new_local_name2   %type <n> normal_label_statement   %type <n> optional_else_part   %type <n> optional_label + %type <n> propagated_enum_value   %type <n> propagated_type   %type <n> return   %type <n> sscanf   %type <n> statement   %type <n> statements   %type <n> statement_with_semicolon   %type <n> switch   %type <n> typeof   %type <n> unused   %type <n> unused2
pike.git/src/language.yacc:2353:    (long)Pike_compiler->new_program->id,    Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */       if(Pike_compiler->compiler_pass > 1)    {    id=isidentifier(name);    }else{    id=define_function(name,    type, -  ID_INLINE|ID_USED, +  ID_PROTECTED | ID_PRIVATE | ID_INLINE | ID_USED,    IDENTIFIER_PIKE_FUNCTION |    (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),    0,    OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);    }    Pike_compiler->varargs=0;    Pike_compiler->compiler_frame->current_function_number=id;       n=0;    if(Pike_compiler->compiler_pass > 1 &&
pike.git/src/language.yacc:2486:    (long)Pike_compiler->new_program->id,    Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */       if(Pike_compiler->compiler_pass > 1)    {    id=isidentifier(name);    }else{    id=define_function(name,    type, -  ID_INLINE|ID_USED, +  ID_PROTECTED | ID_PRIVATE | ID_INLINE | ID_USED,    IDENTIFIER_PIKE_FUNCTION|    (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),    0,    OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);    }    Pike_compiler->varargs=0;    Pike_compiler->compiler_frame->current_function_number=id;       n=0;    if(Pike_compiler->compiler_pass > 1 &&
pike.git/src/language.yacc:2894:    free_node($3);    check_tree($$,0);    THIS_COMPILATION->lex.pragmas = $<number>5;    }    ;      simple_identifier: TOK_IDENTIFIER    | bad_identifier { $$ = 0; }    ;    - enum_value: /* EMPTY */ + enum_value: /* EMPTY */ { $$ = 0; } +  | '=' safe_expr0 { $$ = $2; } +  ; +  + /* Previous enum value at $0. */ + enum_def: /* EMPTY */ +  | simple_identifier enum_value    { -  safe_inc_enum(); -  } -  | '=' safe_expr0 -  { -  pop_stack(); +  if ($1) { +  if ($2) { +  /* Explicit enum value. */       /* This can be made more lenient in the future */       /* Ugly hack to make sure that $2 is optimized */    {    int tmp=Pike_compiler->compiler_pass;    $2=mknode(F_COMMA_EXPR,$2,0);    Pike_compiler->compiler_pass=tmp;    }   
pike.git/src/language.yacc:2931:    {    yyerror("Error in enum definition.");    push_int(0);    }else{    pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1)));    }    } else {    push_int(0);    }    } -  if($2) free_node($2); +  free_node($2); +  free_node($<n>0); +  $<n>0 = mkconstantsvaluenode(Pike_sp-1); +  } else { +  /* Implicit enum value. */ +  $<n>0 = safe_inc_enum($<n>0); +  push_svalue(&$<n>0->u.sval);    } -  ; -  - enum_def: /* EMPTY */ -  | simple_identifier enum_value -  { -  if ($1) { +     add_constant($1->u.sval.u.string, Pike_sp-1,    (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE); -  } -  free_node($1); +     /* Update the type. */    {    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(new, current, 1);    free_type(current);    free_type(new);    type_stack_mark();    push_finished_type(res);    free_type(res);    } -  +  pop_stack(); +  free_node($1);    } -  +  }    ;    -  + /* Previous enum value at $-2 */ + propagated_enum_value: +  { +  $$ = $<n>-2; +  } +  ; +  + /* Previous enum value at $0. */   enum_list: enum_def -  | enum_list ',' enum_def +  | enum_list ',' propagated_enum_value enum_def { $<n>0 = $3; }    | error    ;      /* Modifiers at $0. */   enum: TOK_ENUM    {    if ((Pike_compiler->current_modifiers & ID_EXTERN) &&    (Pike_compiler->compiler_pass == 1)) {    yywarning("Extern declared enum.");    }    -  push_int(-1); /* Last enum-value. */ +     type_stack_mark();    push_type(T_ZERO); /* Joined type so far. */    } -  optional_identifier '{' enum_list end_block +  optional_identifier '{'    { -  struct pike_type *t = pop_unfinished_type(); +  push_int(-1); /* Previous value. */ +  $<n>$ = mkconstantsvaluenode(Pike_sp-1);    pop_stack(); -  +  } +  enum_list end_block +  { +  struct pike_type *t = pop_unfinished_type(); +  free_node($<n>5);    if ($3) {    ref_push_type_value(t);    add_constant($3->u.sval.u.string, Pike_sp-1,    (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);    pop_stack();    free_node($3);    }    $$ = mktypenode(t);    free_type(t);    }
pike.git/src/language.yacc:4741:       return mklocalnode(e,depth);    }    }    if(!(f->lexical_scope & SCOPE_LOCAL)) return 0;    depth++;    f=f->previous;    }   }    - static void safe_inc_enum(void) + static node *safe_inc_enum(node *n)   {    JMP_BUF recovery; -  STACK_LEVEL_START(1); +  STACK_LEVEL_START(0);    -  if (SETJMP_SP(recovery, 1)) { +  if (SETJMP(recovery)) {    handle_compile_exception ("Bad implicit enum value (failed to add 1).");    push_int(0);    } else { -  +  if (n->token != F_CONSTANT) Pike_fatal("Bad node to safe_inc_enum().\n"); +  push_svalue(&n->u.sval);    push_int(1);    f_add(2);    }    UNSETJMP(recovery);    STACK_LEVEL_DONE(1); -  +  free_node(n); +  n = mkconstantsvaluenode(Pike_sp-1); +  pop_stack(); +  return n;   }         static int call_handle_import(struct pike_string *s)   {    struct compilation *c = THIS_COMPILATION;    int args;       ref_push_string(s);    ref_push_string(c->lex.current_file);