diff 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
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy	Fri Oct 18 16:27:44 2013 -0700
+++ b/libinterp/parse-tree/oct-parse.in.yy	Fri Oct 18 21:00:33 2013 -0400
@@ -105,16 +105,6 @@
 
 static void yyerror (octave_base_parser& parser, const char *s);
 
-// Finish building a statement.
-template <class T>
-static tree_statement *
-make_statement (T *arg)
-{
-  octave_comment_list *comment = octave_comment_buffer::get_comment ();
-
-  return new tree_statement (arg, comment);
-}
-
 #define ABORT_PARSE \
   do \
     { \
@@ -396,11 +386,11 @@
                 ;
 
 statement       : expression
-                  { $$ = make_statement ($1); }
+                  { $$ = parser.make_statement ($1); }
                 | command
-                  { $$ = make_statement ($1); }
+                  { $$ = parser.make_statement ($1); }
                 | word_list_cmd
-                  { $$ = make_statement ($1); }
+                  { $$ = parser.make_statement ($1); }
                 ;
 
 // =================
@@ -1579,7 +1569,7 @@
                 ;
 
 stash_comment   : // empty
-                  { $$ = octave_comment_buffer::get_comment (); }
+                  { $$ = lexer.get_comment (); }
                 ;
 
 parse_error     : LEXICAL_ERROR
@@ -2338,7 +2328,7 @@
 
   if (end_token_ok (end_tok, token::unwind_protect_end))
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       int l = unwind_tok->line ();
       int c = unwind_tok->column ();
@@ -2370,7 +2360,7 @@
 
   if (end_token_ok (end_tok, token::try_catch_end))
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       int l = try_tok->line ();
       int c = try_tok->column ();
@@ -2424,7 +2414,7 @@
 
   if (end_token_ok (end_tok, token::while_end))
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       lexer.looping--;
 
@@ -2452,7 +2442,7 @@
 {
   maybe_warn_assign_as_truth_value (expr);
 
-  octave_comment_list *tc = octave_comment_buffer::get_comment ();
+  octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
   lexer.looping--;
 
@@ -2479,7 +2469,7 @@
 
   if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end))
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       lexer.looping--;
 
@@ -2573,7 +2563,7 @@
 
   if (end_token_ok (end_tok, token::if_end))
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       int l = if_tok->line ();
       int c = if_tok->column ();
@@ -2626,7 +2616,7 @@
 
   if (end_token_ok (end_tok, token::switch_end))
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       int l = switch_tok->line ();
       int c = switch_tok->column ();
@@ -2810,7 +2800,7 @@
 
   if (fcn)
     {
-      octave_comment_list *tc = octave_comment_buffer::get_comment ();
+      octave_comment_list *tc = lexer.comment_buf.get_comment ();
 
       fcn->stash_trailing_comment (tc);
       fcn->stash_fcn_end_location (end_fcn_stmt->line (),
@@ -3344,6 +3334,16 @@
   return list;
 }
 
+// Finish building a statement.
+template <class T>
+tree_statement *
+octave_base_parser::make_statement (T *arg)
+{
+  octave_comment_list *comment = lexer.get_comment ();
+
+  return new tree_statement (arg, comment);
+}
+
 tree_statement_list *
 octave_base_parser::make_statement_list (tree_statement *stmt)
 {
@@ -3465,15 +3465,6 @@
 static void
 safe_fclose (FILE *f)
 {
-  // FIXME -- comments at the end of an input file are
-  // discarded (otherwise, they would be appended to the next
-  // statement, possibly from the command line or another file, which
-  // can be quite confusing).
-
-  octave_comment_list *tc = octave_comment_buffer::get_comment ();
-
-  delete tc;
-
   if (f)
     fclose (static_cast<FILE *> (f));
 }