comparison libinterp/parse-tree/oct-parse.in.yy @ 16644:856cb7cba231 classdef

maint: periodic merge of default to classdef
author John W. Eaton <jwe@octave.org>
date Sun, 12 May 2013 21:45:57 -0400
parents 8abae9ea4cb5 de91b1621260
children 7368654f302f
comparison
equal deleted inserted replaced
16595:8abae9ea4cb5 16644:856cb7cba231
240 %token <tok_val> CLASSDEF 240 %token <tok_val> CLASSDEF
241 %token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION 241 %token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION
242 %token <tok_val> METAQUERY 242 %token <tok_val> METAQUERY
243 %token <tok_val> SUPERCLASSREF 243 %token <tok_val> SUPERCLASSREF
244 %token <tok_val> GET SET 244 %token <tok_val> GET SET
245 %token <tok_val> FCN
245 246
246 // Other tokens. 247 // Other tokens.
247 %token END_OF_INPUT LEXICAL_ERROR 248 %token END_OF_INPUT LEXICAL_ERROR
248 %token FCN INPUT_FILE 249 %token INPUT_FILE
249 // %token VARARGIN VARARGOUT 250 // %token VARARGIN VARARGOUT
250 251
251 // Nonterminals we construct. 252 // Nonterminals we construct.
252 %type <comment_type> stash_comment function_beg 253 %type <comment_type> stash_comment
253 %type <tok_type> classdef_beg 254 %type <tok_type> function_beg classdef_beg
254 %type <sep_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep 255 %type <sep_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep
255 %type <tree_type> input 256 %type <tree_type> input
256 %type <tree_constant_type> string constant magic_colon 257 %type <tree_constant_type> string constant magic_colon
257 %type <tree_anon_fcn_handle_type> anon_fcn_handle 258 %type <tree_anon_fcn_handle_type> anon_fcn_handle
258 %type <tree_fcn_handle_type> fcn_handle 259 %type <tree_fcn_handle_type> fcn_handle
1155 file : INPUT_FILE opt_nl opt_list END_OF_INPUT 1156 file : INPUT_FILE opt_nl opt_list END_OF_INPUT
1156 { 1157 {
1157 if (! lexer.reading_fcn_file) 1158 if (! lexer.reading_fcn_file)
1158 { 1159 {
1159 tree_statement *end_of_script 1160 tree_statement *end_of_script
1160 = parser.make_end ("endscript", 1161 = parser.make_end ("endscript", true,
1161 lexer.input_line_number, 1162 lexer.input_line_number,
1162 lexer.current_input_column); 1163 lexer.current_input_column);
1163 1164
1164 parser.make_script ($3, end_of_script); 1165 parser.make_script ($3, end_of_script);
1165 } 1166 }
1166 1167
1167 $$ = 0; 1168 $$ = 0;
1177 1178
1178 // =================== 1179 // ===================
1179 // Function definition 1180 // Function definition
1180 // =================== 1181 // ===================
1181 1182
1182 function_beg : push_fcn_symtab FCN stash_comment 1183 function_beg : push_fcn_symtab FCN
1183 { 1184 {
1184 $$ = $3; 1185 $$ = $2;
1185 if (lexer.reading_classdef_file 1186 if (lexer.reading_classdef_file
1186 || lexer.parsing_classdef) 1187 || lexer.parsing_classdef)
1187 lexer.maybe_classdef_get_set_method = true; 1188 lexer.maybe_classdef_get_set_method = true;
1188 } 1189 }
1189 ; 1190 ;
1190 1191
1191 function : function_beg function1 1192 function : function_beg stash_comment function1
1192 { 1193 {
1193 $$ = parser.finish_function (0, $2, $1); 1194 $$ = parser.finish_function (0, $3, $2, $1->line (),
1195 $1->column ());
1194 parser.recover_from_parsing_function (); 1196 parser.recover_from_parsing_function ();
1195 } 1197 }
1196 | function_beg return_list '=' function1 1198 | function_beg stash_comment return_list '=' function1
1197 { 1199 {
1198 $$ = parser.finish_function ($2, $4, $1); 1200 $$ = parser.finish_function ($3, $5, $2, $1->line (),
1201 $1->column ());
1199 parser.recover_from_parsing_function (); 1202 parser.recover_from_parsing_function ();
1200 } 1203 }
1201 ; 1204 ;
1202 1205
1203 fcn_name : identifier 1206 fcn_name : identifier
1244 1247
1245 function_end : END 1248 function_end : END
1246 { 1249 {
1247 parser.endfunction_found = true; 1250 parser.endfunction_found = true;
1248 if (parser.end_token_ok ($1, token::function_end)) 1251 if (parser.end_token_ok ($1, token::function_end))
1249 $$ = parser.make_end ("endfunction", $1->line (), $1->column ()); 1252 $$ = parser.make_end ("endfunction", false,
1253 $1->line (), $1->column ());
1250 else 1254 else
1251 ABORT_PARSE; 1255 ABORT_PARSE;
1252 } 1256 }
1253 | END_OF_INPUT 1257 | END_OF_INPUT
1254 { 1258 {
1278 { 1282 {
1279 parser.bison_error ("classdef body open at end of input"); 1283 parser.bison_error ("classdef body open at end of input");
1280 YYABORT; 1284 YYABORT;
1281 } 1285 }
1282 1286
1283 $$ = parser.make_end ("endfunction", 1287 $$ = parser.make_end ("endfunction", true,
1284 lexer.input_line_number, 1288 lexer.input_line_number,
1285 lexer.current_input_column); 1289 lexer.current_input_column);
1286 } 1290 }
1287 ; 1291 ;
1288 1292
1289 // ======== 1293 // ========
1290 // Classdef 1294 // Classdef
1304 ; 1308 ;
1305 1309
1306 classdef : classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep class_body opt_sep END 1310 classdef : classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep class_body opt_sep END
1307 { 1311 {
1308 lexer.parsing_classdef = false; 1312 lexer.parsing_classdef = false;
1313
1309 if (! ($$ = parser.make_classdef ($1, $3, $4, $5, $7, $9, $2))) 1314 if (! ($$ = parser.make_classdef ($1, $3, $4, $5, $7, $9, $2)))
1310 ABORT_PARSE; 1315 ABORT_PARSE;
1311 } 1316 }
1312 ; 1317 ;
1313 1318
1583 curr_fcn_depth = 0; 1588 curr_fcn_depth = 0;
1584 primary_fcn_scope = -1; 1589 primary_fcn_scope = -1;
1585 curr_class_name = ""; 1590 curr_class_name = "";
1586 function_scopes.clear (); 1591 function_scopes.clear ();
1587 primary_fcn_ptr = 0; 1592 primary_fcn_ptr = 0;
1593 subfunction_names.clear ();
1588 1594
1589 delete stmt_list; 1595 delete stmt_list;
1590 stmt_list = 0; 1596 stmt_list = 0;
1591 1597
1592 lexer.reset (); 1598 lexer.reset ();
2687 if (fcn) 2693 if (fcn)
2688 { 2694 {
2689 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2695 octave_comment_list *tc = octave_comment_buffer::get_comment ();
2690 2696
2691 fcn->stash_trailing_comment (tc); 2697 fcn->stash_trailing_comment (tc);
2698 fcn->stash_fcn_end_location (end_fcn_stmt->line (),
2699 end_fcn_stmt->column ());
2692 } 2700 }
2693 2701
2694 return fcn; 2702 return fcn;
2695 } 2703 }
2696 2704
2697 tree_statement * 2705 tree_statement *
2698 octave_base_parser::make_end (const std::string& type, int l, int c) 2706 octave_base_parser::make_end (const std::string& type, bool eof, int l, int c)
2699 { 2707 {
2700 return make_statement (new tree_no_op_command (type, l, c)); 2708 return make_statement (new tree_no_op_command (type, eof, l, c));
2701 } 2709 }
2702 2710
2703 // Do most of the work for defining a function. 2711 // Do most of the work for defining a function.
2704 2712
2705 octave_user_function * 2713 octave_user_function *
2784 warning ("function '%s' defined within script file '%s'", 2792 warning ("function '%s' defined within script file '%s'",
2785 id_name.c_str (), lexer.fcn_file_full_name.c_str ()); 2793 id_name.c_str (), lexer.fcn_file_full_name.c_str ());
2786 } 2794 }
2787 2795
2788 fcn->stash_function_name (id_name); 2796 fcn->stash_function_name (id_name);
2789 fcn->stash_fcn_location (lexer.input_line_number,
2790 lexer.current_input_column);
2791 2797
2792 if (! lexer.help_text.empty () && curr_fcn_depth == 1 2798 if (! lexer.help_text.empty () && curr_fcn_depth == 1
2793 && ! parsing_subfunctions) 2799 && ! parsing_subfunctions)
2794 { 2800 {
2795 fcn->document (lexer.help_text); 2801 fcn->document (lexer.help_text);
2805 } 2811 }
2806 2812
2807 tree_function_def * 2813 tree_function_def *
2808 octave_base_parser::finish_function (tree_parameter_list *ret_list, 2814 octave_base_parser::finish_function (tree_parameter_list *ret_list,
2809 octave_user_function *fcn, 2815 octave_user_function *fcn,
2810 octave_comment_list *lc) 2816 octave_comment_list *lc,
2817 int l, int c)
2811 { 2818 {
2812 tree_function_def *retval = 0; 2819 tree_function_def *retval = 0;
2813 2820
2814 if (ret_list) 2821 if (ret_list)
2815 ret_list->mark_as_formal_parameters (); 2822 ret_list->mark_as_formal_parameters ();
2831 fcn->define_ret_list (ret_list); 2838 fcn->define_ret_list (ret_list);
2832 2839
2833 if (curr_fcn_depth > 1 || parsing_subfunctions) 2840 if (curr_fcn_depth > 1 || parsing_subfunctions)
2834 { 2841 {
2835 fcn->mark_as_subfunction (); 2842 fcn->mark_as_subfunction ();
2843 fcn->stash_fcn_location (l, c);
2844
2845 subfunction_names.push_back (nm);
2836 2846
2837 if (endfunction_found && function_scopes.size () > 1) 2847 if (endfunction_found && function_scopes.size () > 1)
2838 { 2848 {
2839 symbol_table::scope_id pscope 2849 symbol_table::scope_id pscope
2840 = function_scopes[function_scopes.size ()-2]; 2850 = function_scopes[function_scopes.size ()-2];
3577 3587
3578 if (fcn_ptr) 3588 if (fcn_ptr)
3579 panic_impossible (); 3589 panic_impossible ();
3580 3590
3581 fcn_ptr = parser.classdef_object->make_meta_class (); 3591 fcn_ptr = parser.classdef_object->make_meta_class ();
3592 }
3593 else if (fcn_ptr)
3594 {
3595 fcn_ptr->maybe_relocate_end ();
3596
3597 if (parser.parsing_subfunctions)
3598 {
3599 if (! parser.endfunction_found)
3600 parser.subfunction_names.reverse ();
3601
3602 fcn_ptr->stash_subfunction_names (parser.subfunction_names);
3603 }
3582 } 3604 }
3583 } 3605 }
3584 else 3606 else
3585 error ("parse error while reading file %s", full_file.c_str ()); 3607 error ("parse error while reading file %s", full_file.c_str ());
3586 } 3608 }