changeset 33317:e79a3b7ebd6b

use filepos instead of line and column separately for bison errors * parse.h, oct-parse.yy (bison_error (const std::string&, int, int)): Delete. Change all uses to call bison_error (const std::string&, const filepos&) instead. (parse_exception::m_pos): New data member. (parse-exception::pos): New function. (parse_exception::parse_exception): Accept filepos, not line and column. (parse_exception::m_line, parse_exception::m_column): Delete. (parse_exception::line, parse_exception::column): Delete. Change all uses to call pos instead. * anon-fcn-validator.h (anon_fcn_validator::line, anon_fcn_validator::column): Delete unused functions.
author John W. Eaton <jwe@octave.org>
date Thu, 04 Apr 2024 13:35:04 -0400
parents 2f24c41a14cd
children b794f004bff7
files libinterp/parse-tree/anon-fcn-validator.h libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/parse.h
diffstat 3 files changed, 21 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/anon-fcn-validator.h	Thu Apr 04 13:24:21 2024 -0400
+++ b/libinterp/parse-tree/anon-fcn-validator.h	Thu Apr 04 13:35:04 2024 -0400
@@ -63,9 +63,6 @@
   filepos beg_pos () const { return m_beg_pos; }
   filepos end_pos () const { return m_end_pos; }
 
-  int line () const { return m_beg_pos.line (); }
-  int column () const { return m_beg_pos.column (); }
-
   std::string message () const { return m_message; }
 
 private:
--- a/libinterp/parse-tree/oct-parse.yy	Thu Apr 04 13:24:21 2024 -0400
+++ b/libinterp/parse-tree/oct-parse.yy	Thu Apr 04 13:35:04 2024 -0400
@@ -197,7 +197,7 @@
   octave::tree_classdef_enum_block* tree_classdef_enum_block_type;
 }
 
-// Tokens with line and column information.
+// Tokens with position information.
 %token <tok> '=' ':' '-' '+' '*' '/' '~' '!'
 %token <tok> '(' ')' '[' ']' '{' '}' '.' '@'
 %token <tok> ',' ';' '\n'
@@ -2225,10 +2225,10 @@
     parse_exception (const std::string& message,
                      const std::string& fcn_name = "",
                      const std::string& file_name = "",
-                     int line = -1, int column = -1)
+                     const filepos& pos = filepos ())
       : runtime_error (message), m_message (message),
         m_fcn_name (fcn_name), m_file_name (file_name),
-        m_line (line), m_column (column)
+        m_pos (pos)
     { }
 
     OCTAVE_DEFAULT_COPY_MOVE_DELETE (parse_exception)
@@ -2241,8 +2241,7 @@
     std::string fcn_name () const { return m_fcn_name; }
     std::string file_name () const { return m_file_name; }
 
-    int line () const { return m_line; }
-    int column () const { return m_column; }
+    filepos pos () const { return m_pos; }
 
     // virtual void display (std::ostream& os) const;
 
@@ -2252,8 +2251,7 @@
 
     std::string m_fcn_name;
     std::string m_file_name;
-    int m_line;
-    int m_column;
+    filepos m_pos;
   };
 
   class parse_tree_validator : public tree_walker
@@ -2319,11 +2317,8 @@
 
           if (m_scope.is_variable (sym_nm))
             {
-              std::string message
-                = sym_nm + ": invalid use of symbol as both variable and command";
-              parse_exception pe (message, m_scope.fcn_name (),
-                                  m_scope.fcn_file_name (),
-                                  idx_expr.line (), idx_expr.column ());
+              std::string message = sym_nm + ": invalid use of symbol as both variable and command";
+              parse_exception pe (message, m_scope.fcn_name (), m_scope.fcn_file_name (), idx_expr.beg_pos ());
 
               m_error_list.push_back (pe);
             }
@@ -2728,7 +2723,7 @@
         delete param_list;
         delete expr;
 
-        bison_error (validator.message (), validator.line (), validator.column ());
+        bison_error (validator.message (), validator.beg_pos ());
 
         return nullptr;
       }
@@ -3585,8 +3580,13 @@
 
     if (! m_function_scopes.name_current_scope (id_name))
       {
-        bison_error ("duplicate subfunction or nested function name",
-                     id->line (), id->column () + 1);
+        // FIXME: is this correct?  Before using position, the column
+        // was incremented.  Hmm.
+
+        filepos id_pos = id->beg_pos ();
+        id_pos.increment_column ();
+
+        bison_error ("duplicate subfunction or nested function name", id_pos);
 
         delete id;
         return nullptr;
@@ -4024,15 +4024,12 @@
 
     if (short_name != cls_name)
       {
-        int l = id->line ();
-        int c = id->column ();
-
         delete a;
         delete id;
         delete sc;
         delete body;
 
-        bison_error ("invalid classdef definition, the class name must match the filename", l, c);
+        bison_error ("invalid classdef definition, the class name must match the filename", id->beg_pos ());
 
       }
     else
@@ -5077,14 +5074,11 @@
   void
   base_parser::bison_error (const std::string& str, const filepos& pos)
   {
-    bison_error (str, pos.line (), pos.column ());
-  }
-
-  void
-  base_parser::bison_error (const std::string& str, int err_line, int err_col)
-  {
     std::ostringstream output_buf;
 
+    int err_line = pos.line ();
+    int err_col = pos.column ();
+
     bool in_file = (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file
                     || m_lexer.m_reading_classdef_file);
 
@@ -5134,7 +5128,7 @@
   void
   base_parser::bison_error (const parse_exception& pe)
   {
-    bison_error (pe.message (), pe.line (), pe.column ());
+    bison_error (pe.message (), pe.pos ());
   }
 
   void
@@ -5145,7 +5139,7 @@
 
     parse_exception pe = pe_list.front ();
 
-    bison_error (pe.message (), pe.line (), pe.column ());
+    bison_error (pe.message (), pe.pos ());
   }
 
   int
--- a/libinterp/parse-tree/parse.h	Thu Apr 04 13:24:21 2024 -0400
+++ b/libinterp/parse-tree/parse.h	Thu Apr 04 13:35:04 2024 -0400
@@ -647,7 +647,6 @@
   // Generic error messages.
   OCTINTERP_API void bison_error (const std::string& s);
   OCTINTERP_API void bison_error (const std::string& s, const filepos& pos);
-  OCTINTERP_API void bison_error (const std::string& s, int line, int column);
   OCTINTERP_API void bison_error (const std::list<parse_exception>& pe);
   OCTINTERP_API void bison_error (const parse_exception& pe);