changeset 30131:a471bf0f78ba

allow for invalid filepos objects * filepos.h (filepos::filepos (int, int)): Don't provide default values. (filepos::filepos (void)): Initialize to invalid line and column positions. (filepos::operator bool): New function. (filepos::set): Delete. * lex.h (lexical_feedback::lexical_feedback): Initialize filepos with line and column == 1. * lex.ll (lexical_feedback::reset): Set m_filepos to (1, 1).
author John W. Eaton <jwe@octave.org>
date Sat, 04 Sep 2021 07:50:08 -0400
parents a9e3e1c96c47
children 72afd5cd4a0c
files libinterp/parse-tree/filepos.h libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll
diffstat 3 files changed, 6 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/filepos.h	Sat Sep 04 05:33:27 2021 -0400
+++ b/libinterp/parse-tree/filepos.h	Sat Sep 04 07:50:08 2021 -0400
@@ -34,7 +34,9 @@
   {
   public:
 
-    filepos (int l = 1, int c = 1) : m_line (l), m_column (c) { }
+    filepos (void) : m_line (0), m_column (0) { }
+
+    filepos (int l, int c) : m_line (l), m_column (c) { }
 
     filepos (const filepos&) = default;
 
@@ -42,11 +44,7 @@
 
     ~filepos (void) = default;
 
-    void set (int l, int c)
-    {
-      m_line = l;
-      m_column = c;
-    }
+    operator bool () { return m_line > 0 && m_column > 0; }
 
     void line (int l) { m_line = l; }
     void column (int c) { m_column = c; }
--- a/libinterp/parse-tree/lex.h	Sat Sep 04 05:33:27 2021 -0400
+++ b/libinterp/parse-tree/lex.h	Sat Sep 04 07:50:08 2021 -0400
@@ -299,7 +299,7 @@
         m_block_comment_nesting_level (0),
         m_command_arg_paren_count (0),
         m_token_count (0),
-        m_filepos (),
+        m_filepos (1, 1),
         m_tok_beg (),
         m_tok_end (),
         m_string_text (),
--- a/libinterp/parse-tree/lex.ll	Sat Sep 04 05:33:27 2021 -0400
+++ b/libinterp/parse-tree/lex.ll	Sat Sep 04 07:50:08 2021 -0400
@@ -2260,7 +2260,7 @@
     m_block_comment_nesting_level = 0;
     m_command_arg_paren_count = 0;
     m_token_count = 0;
-    m_filepos = filepos ();
+    m_filepos = filepos (1, 1);
     m_tok_beg = filepos ();
     m_tok_end = filepos ();
     m_string_text = "";