comparison libinterp/parse-tree/oct-parse.in.yy @ 17693:efbe746f8fa8

eliminate octave_comment_buffer singleton * lex.h (octave_base_lexer::comment_buffer): New class adapted from octave_comment_buffer class. No longer a singleton class. (octave_base_lexer::comment_buffer::reset): New function. (octave_base_lexer::reset): Call comment_buf.reset. (octave_base_lexer::comment_buf): New data member. (octave_base_lexer::get_comment): New function. * comment-list.h, comment-list.cc (octave_comment_buffer): Delete. Change all uses of octave_comment_buffer to use local comment_buf object instead. * parse.h (octave_base_parser::make_statement): New member function. * oct-parse.in.yy (make_statement): Delete. Change all uses of make_statement to use the member function instead. (safe_fclose): Don't extract and delete comment list here.
author John W. Eaton <jwe@octave.org>
date Fri, 18 Oct 2013 21:00:33 -0400
parents 9f6e4e5c2bac
children f79bf671a493
comparison
equal deleted inserted replaced
17692:38cf56b77274 17693:efbe746f8fa8
102 102
103 // Forward declarations for some functions defined at the bottom of 103 // Forward declarations for some functions defined at the bottom of
104 // the file. 104 // the file.
105 105
106 static void yyerror (octave_base_parser& parser, const char *s); 106 static void yyerror (octave_base_parser& parser, const char *s);
107
108 // Finish building a statement.
109 template <class T>
110 static tree_statement *
111 make_statement (T *arg)
112 {
113 octave_comment_list *comment = octave_comment_buffer::get_comment ();
114
115 return new tree_statement (arg, comment);
116 }
117 107
118 #define ABORT_PARSE \ 108 #define ABORT_PARSE \
119 do \ 109 do \
120 { \ 110 { \
121 yyerrok; \ 111 yyerrok; \
394 | list1 sep statement 384 | list1 sep statement
395 { $$ = parser.append_statement_list ($1, $2, $3, true); } 385 { $$ = parser.append_statement_list ($1, $2, $3, true); }
396 ; 386 ;
397 387
398 statement : expression 388 statement : expression
399 { $$ = make_statement ($1); } 389 { $$ = parser.make_statement ($1); }
400 | command 390 | command
401 { $$ = make_statement ($1); } 391 { $$ = parser.make_statement ($1); }
402 | word_list_cmd 392 | word_list_cmd
403 { $$ = make_statement ($1); } 393 { $$ = parser.make_statement ($1); }
404 ; 394 ;
405 395
406 // ================= 396 // =================
407 // Word-list command 397 // Word-list command
408 // ================= 398 // =================
1577 stmt_begin : // empty 1567 stmt_begin : // empty
1578 { lexer.at_beginning_of_statement = true; } 1568 { lexer.at_beginning_of_statement = true; }
1579 ; 1569 ;
1580 1570
1581 stash_comment : // empty 1571 stash_comment : // empty
1582 { $$ = octave_comment_buffer::get_comment (); } 1572 { $$ = lexer.get_comment (); }
1583 ; 1573 ;
1584 1574
1585 parse_error : LEXICAL_ERROR 1575 parse_error : LEXICAL_ERROR
1586 { parser.bison_error ("parse error"); } 1576 { parser.bison_error ("parse error"); }
1587 | error 1577 | error
2336 { 2326 {
2337 tree_command *retval = 0; 2327 tree_command *retval = 0;
2338 2328
2339 if (end_token_ok (end_tok, token::unwind_protect_end)) 2329 if (end_token_ok (end_tok, token::unwind_protect_end))
2340 { 2330 {
2341 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2331 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2342 2332
2343 int l = unwind_tok->line (); 2333 int l = unwind_tok->line ();
2344 int c = unwind_tok->column (); 2334 int c = unwind_tok->column ();
2345 2335
2346 retval = new tree_unwind_protect_command (body, cleanup_stmts, 2336 retval = new tree_unwind_protect_command (body, cleanup_stmts,
2368 { 2358 {
2369 tree_command *retval = 0; 2359 tree_command *retval = 0;
2370 2360
2371 if (end_token_ok (end_tok, token::try_catch_end)) 2361 if (end_token_ok (end_tok, token::try_catch_end))
2372 { 2362 {
2373 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2363 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2374 2364
2375 int l = try_tok->line (); 2365 int l = try_tok->line ();
2376 int c = try_tok->column (); 2366 int c = try_tok->column ();
2377 2367
2378 tree_identifier *id = 0; 2368 tree_identifier *id = 0;
2422 2412
2423 maybe_warn_assign_as_truth_value (expr); 2413 maybe_warn_assign_as_truth_value (expr);
2424 2414
2425 if (end_token_ok (end_tok, token::while_end)) 2415 if (end_token_ok (end_tok, token::while_end))
2426 { 2416 {
2427 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2417 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2428 2418
2429 lexer.looping--; 2419 lexer.looping--;
2430 2420
2431 int l = while_tok->line (); 2421 int l = while_tok->line ();
2432 int c = while_tok->column (); 2422 int c = while_tok->column ();
2450 tree_expression *expr, 2440 tree_expression *expr,
2451 octave_comment_list *lc) 2441 octave_comment_list *lc)
2452 { 2442 {
2453 maybe_warn_assign_as_truth_value (expr); 2443 maybe_warn_assign_as_truth_value (expr);
2454 2444
2455 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2445 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2456 2446
2457 lexer.looping--; 2447 lexer.looping--;
2458 2448
2459 int l = until_tok->line (); 2449 int l = until_tok->line ();
2460 int c = until_tok->column (); 2450 int c = until_tok->column ();
2477 2467
2478 bool parfor = tok_id == PARFOR; 2468 bool parfor = tok_id == PARFOR;
2479 2469
2480 if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end)) 2470 if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end))
2481 { 2471 {
2482 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2472 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2483 2473
2484 lexer.looping--; 2474 lexer.looping--;
2485 2475
2486 int l = for_tok->line (); 2476 int l = for_tok->line ();
2487 int c = for_tok->column (); 2477 int c = for_tok->column ();
2571 { 2561 {
2572 tree_if_command *retval = 0; 2562 tree_if_command *retval = 0;
2573 2563
2574 if (end_token_ok (end_tok, token::if_end)) 2564 if (end_token_ok (end_tok, token::if_end))
2575 { 2565 {
2576 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2566 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2577 2567
2578 int l = if_tok->line (); 2568 int l = if_tok->line ();
2579 int c = if_tok->column (); 2569 int c = if_tok->column ();
2580 2570
2581 if (list && ! list->empty ()) 2571 if (list && ! list->empty ())
2624 { 2614 {
2625 tree_switch_command *retval = 0; 2615 tree_switch_command *retval = 0;
2626 2616
2627 if (end_token_ok (end_tok, token::switch_end)) 2617 if (end_token_ok (end_tok, token::switch_end))
2628 { 2618 {
2629 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2619 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2630 2620
2631 int l = switch_tok->line (); 2621 int l = switch_tok->line ();
2632 int c = switch_tok->column (); 2622 int c = switch_tok->column ();
2633 2623
2634 if (list && ! list->empty ()) 2624 if (list && ! list->empty ())
2808 = new octave_user_function (lexer.symtab_context.curr_scope (), 2798 = new octave_user_function (lexer.symtab_context.curr_scope (),
2809 param_list, 0, body); 2799 param_list, 0, body);
2810 2800
2811 if (fcn) 2801 if (fcn)
2812 { 2802 {
2813 octave_comment_list *tc = octave_comment_buffer::get_comment (); 2803 octave_comment_list *tc = lexer.comment_buf.get_comment ();
2814 2804
2815 fcn->stash_trailing_comment (tc); 2805 fcn->stash_trailing_comment (tc);
2816 fcn->stash_fcn_end_location (end_fcn_stmt->line (), 2806 fcn->stash_fcn_end_location (end_fcn_stmt->line (),
2817 end_fcn_stmt->column ()); 2807 end_fcn_stmt->column ());
2818 } 2808 }
3342 } 3332 }
3343 3333
3344 return list; 3334 return list;
3345 } 3335 }
3346 3336
3337 // Finish building a statement.
3338 template <class T>
3339 tree_statement *
3340 octave_base_parser::make_statement (T *arg)
3341 {
3342 octave_comment_list *comment = lexer.get_comment ();
3343
3344 return new tree_statement (arg, comment);
3345 }
3346
3347 tree_statement_list * 3347 tree_statement_list *
3348 octave_base_parser::make_statement_list (tree_statement *stmt) 3348 octave_base_parser::make_statement_list (tree_statement *stmt)
3349 { 3349 {
3350 return new tree_statement_list (stmt); 3350 return new tree_statement_list (stmt);
3351 } 3351 }
3463 } 3463 }
3464 3464
3465 static void 3465 static void
3466 safe_fclose (FILE *f) 3466 safe_fclose (FILE *f)
3467 { 3467 {
3468 // FIXME -- comments at the end of an input file are
3469 // discarded (otherwise, they would be appended to the next
3470 // statement, possibly from the command line or another file, which
3471 // can be quite confusing).
3472
3473 octave_comment_list *tc = octave_comment_buffer::get_comment ();
3474
3475 delete tc;
3476
3477 if (f) 3468 if (f)
3478 fclose (static_cast<FILE *> (f)); 3469 fclose (static_cast<FILE *> (f));
3479 } 3470 }
3480 3471
3481 static octave_function * 3472 static octave_function *