# HG changeset patch # User John W. Eaton # Date 1206469920 14400 # Node ID ae90e05ad2990b5b7f2c933931ec0a1d2a3325e6 # Parent ba15376ddfe133d637cc4296e3bb36be69a0193a fix parameter list initializer bug diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2008-03-25 John W. Eaton + + * lex.h (lexical_feedback::looking_at_initializer_expression): + New data member. + * lex.l (lexical_feedback::init): Initialize it. + (handle_identifier): Don't unconditionally force identifiers to be + variables in the current scope. Don't call force_local_variable + for symbols that appear in parameter initializer expressions. + * parse.y (decl_param_init): New parser "subroutine". + (decl2): Use it. Set lexer_flags.looking_at_initializer_expression + to false after parsing initializer. + 2008-03-24 David Bateman * data.cc (map_s_s): Fix for sparse/sparse mappers that resulted diff --git a/src/lex.h b/src/lex.h --- a/src/lex.h +++ b/src/lex.h @@ -92,6 +92,10 @@ // TRUE means we're parsing the parameter list for a function. bool looking_at_parameter_list; + // TRUE means we are looking at the initializer expression for a + // parameter list element. + bool looking_at_initializer_expression; + // TRUE means we're parsing a matrix or the left hand side of // multi-value assignment statement. bool looking_at_matrix_or_assign_lhs; diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -2286,7 +2286,8 @@ { if (next_tok_is_eq || lexer_flags.looking_at_return_list - || lexer_flags.looking_at_parameter_list + || (lexer_flags.looking_at_parameter_list + && ! lexer_flags.looking_at_initializer_expression) || lexer_flags.looking_at_matrix_or_assign_lhs) { force_local_variable (tok); @@ -2312,11 +2313,6 @@ yylval.tok_val = new token (&(symbol_table::insert (tok)), input_line_number, current_input_column); - // FIXME -- this forces a link for tok in the chain of variables for - // the current scope. Probably this step should be done - // differently, maybe in symbol_table::insert? - symbol_table::varref (tok); - token_stack.push (yylval.tok_val); // After seeing an identifer, it is ok to convert spaces to a comma @@ -2364,6 +2360,9 @@ looking_at_return_list = false; looking_at_parameter_list = false; + // Not looking at an argument list initializer expression. + looking_at_initializer_expression = false; + // Not parsing a matrix or the left hand side of multi-value // assignment statement. looking_at_matrix_or_assign_lhs = false; diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -929,10 +929,16 @@ } ; +decl_param_init : // empty + { lexer_flags.looking_at_initializer_expression = true; } + decl2 : identifier { $$ = new tree_decl_elt ($1); } - | identifier '=' expression - { $$ = new tree_decl_elt ($1, $3); } + | identifier '=' decl_param_init expression + { + lexer_flags.looking_at_initializer_expression = false; + $$ = new tree_decl_elt ($1, $4); + } ; // ====================