changeset 29723:6858992dfadf

enter symbols into current scope in parser instead of lexer * lex.h, lex.ll (base_lexer::is_variable): Eliminate unused SCOPE argument. Change all uses. * oct-parse.yy (identifer): Enter NAME in current scope here instead of in lexer. * token.h, token.cc (token::m_sr): Delete member variable and all uses. (token::symbol_name): Delete method. Use token::text where this method was used prevoiusly. (token::sym_rec, token::is_symbol): Delete methods and all uses. (token::sym_rec_token): Delete enum value and all uses. Use string_token instead. (token::isstring): New method. (token::tok_info): Delete overload for symbol_record objects.
author John W. Eaton <jwe@octave.org>
date Tue, 01 Jun 2021 16:57:40 -0400
parents 9a8a6a99a0a7
children c19f8cbe0fd5
files libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/token.cc libinterp/parse-tree/token.h
diffstat 5 files changed, 20 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h	Wed Jun 02 20:05:45 2021 +0200
+++ b/libinterp/parse-tree/lex.h	Tue Jun 01 16:57:40 2021 -0400
@@ -653,7 +653,7 @@
 
     bool inside_any_object_index (void);
 
-    bool is_variable (const std::string& name, const symbol_scope& scope);
+    bool is_variable (const std::string& name);
 
     int make_keyword_token (const std::string& s);
 
--- a/libinterp/parse-tree/lex.ll	Wed Jun 02 20:05:45 2021 +0200
+++ b/libinterp/parse-tree/lex.ll	Tue Jun 01 16:57:40 2021 -0400
@@ -2354,8 +2354,8 @@
   {
     token *tok = m_tokens.front ();
 
-    if (tok && tok->is_symbol ())
-      m_pending_local_variables.insert (tok->symbol_name ());
+    if (tok && tok->isstring ())
+      m_pending_local_variables.insert (tok->text ());
   }
 
   void
@@ -2654,8 +2654,7 @@
   }
 
   bool
-  base_lexer::is_variable (const std::string& name,
-                           const symbol_scope& /*scope*/)
+  base_lexer::is_variable (const std::string& name)
   {
     return ((m_interpreter.at_top_level ()
              && m_interpreter.is_variable (name))
@@ -3555,13 +3554,7 @@
         return count_token_internal (kw_token);
       }
 
-    // Find the token in the symbol table.
-
-    symbol_scope scope = m_symtab_context.curr_scope ();
-
-    symbol_record sr = (scope ? scope.insert (ident) : symbol_record (ident));
-
-    token *tok = new token (NAME, sr, m_tok_beg, m_tok_end);
+    token *tok = new token (NAME, ident, m_tok_beg, m_tok_end);
 
     // The following symbols are handled specially so that things like
     //
@@ -3572,7 +3565,7 @@
 
     if (m_at_beginning_of_statement
         && ! (m_parsing_anon_fcn_body
-              || is_variable (ident, scope)
+              || is_variable (ident)
               || ident == "e" || ident == "pi"
               || ident == "I" || ident == "i"
               || ident == "J" || ident == "j"
@@ -3748,8 +3741,7 @@
       case NAME:
         {
           token *tok_val = current_token ();
-          symbol_record sr = tok_val->sym_rec ();
-          std::cerr << "NAME [" << sr.name () << "]\n";
+          std::cerr << "NAME [" << tok_val->text () << "]\n";
         }
         break;
 
--- a/libinterp/parse-tree/oct-parse.yy	Wed Jun 02 20:05:45 2021 +0200
+++ b/libinterp/parse-tree/oct-parse.yy	Tue Jun 01 16:57:40 2021 -0400
@@ -516,8 +516,18 @@
 
 identifier      : NAME
                   {
-                    $$ = new octave::tree_identifier ($1->sym_rec (),
-                                                      $1->line (),
+                    // Find the token in the symbol table.
+                    octave::symbol_scope scope
+                      = lexer.m_symtab_context.curr_scope ();
+
+                    std::string nm = $1->text ();
+
+                    octave::symbol_record sr
+                      = (scope
+                         ? scope.insert (nm) : octave::symbol_record (nm));
+
+
+                    $$ = new octave::tree_identifier (sr, $1->line (),
                                                       $1->column ());
                   }
                 ;
--- a/libinterp/parse-tree/token.cc	Wed Jun 02 20:05:45 2021 +0200
+++ b/libinterp/parse-tree/token.cc	Tue Jun 01 16:57:40 2021 -0400
@@ -29,7 +29,6 @@
 
 #include <cassert>
 
-#include "symrec.h"
 #include "token.h"
 
 namespace octave
@@ -76,13 +75,6 @@
       m_tok_info (t), m_orig_text ()
   { }
 
-  token::token (int tv, const symbol_record& sr, const filepos& beg_pos,
-                const filepos& end_pos)
-    : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
-      m_end_pos (end_pos), m_tok_val (tv), m_type_tag (sym_rec_token),
-      m_tok_info (sr), m_orig_text ()
-  { }
-
   token::token (int tv, const std::string& meth, const std::string& cls,
                 const filepos& beg_pos, const filepos& end_pos)
     : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos),
@@ -94,8 +86,6 @@
   {
     if (m_type_tag == string_token)
       delete m_tok_info.m_str;
-    else if (m_type_tag == sym_rec_token)
-      delete m_tok_info.m_sr;
     else if (m_type_tag == scls_name_token)
       delete m_tok_info.m_superclass_info;
   }
@@ -107,13 +97,6 @@
     return *m_tok_info.m_str;
   }
 
-  std::string
-  token::symbol_name (void) const
-  {
-    assert (m_type_tag == sym_rec_token);
-    return m_tok_info.m_sr->name ();
-  }
-
   octave_value
   token::number (void) const
   {
@@ -134,13 +117,6 @@
     return m_tok_info.m_et;
   }
 
-  symbol_record
-  token::sym_rec (void) const
-  {
-    assert (m_type_tag == sym_rec_token);
-    return *m_tok_info.m_sr;
-  }
-
   std::string
   token::superclass_method_name (void) const
   {
--- a/libinterp/parse-tree/token.h	Wed Jun 02 20:05:45 2021 +0200
+++ b/libinterp/parse-tree/token.h	Tue Jun 01 16:57:40 2021 -0400
@@ -32,7 +32,6 @@
 
 #include "filepos.h"
 #include "ov.h"
-#include "symrec.h"
 
 namespace octave
 {
@@ -47,7 +46,6 @@
       string_token,
       numeric_token,
       ettype_token,
-      sym_rec_token,
       scls_name_token,
     };
 
@@ -87,9 +85,6 @@
     token (int tv, end_tok_type t, const filepos& beg_pos,
            const filepos& end_pos);
 
-    token (int tv, const symbol_record& s, const filepos& beg_pos,
-           const filepos& end_pos);
-
     token (int tv, const std::string& mth, const std::string& cls,
            const filepos& beg_pos, const filepos& end_pos);
 
@@ -125,17 +120,12 @@
       return m_type_tag == keyword_token || m_type_tag == ettype_token;
     }
 
-    bool is_symbol (void) const
-    {
-      return m_type_tag == sym_rec_token;
-    }
+    bool isstring (void) const { return m_type_tag == string_token; }
 
     std::string text (void) const;
-    std::string symbol_name (void) const;
     octave_value number (void) const;
     token_type ttype (void) const;
     end_tok_type ettype (void) const;
-    symbol_record sym_rec (void) const;
 
     std::string superclass_method_name (void) const;
     std::string superclass_class_name (void) const;
@@ -167,10 +157,6 @@
 
       tok_info (end_tok_type et) : m_et (et) { }
 
-      tok_info (const symbol_record& sr)
-        : m_sr (new symbol_record (sr))
-      { }
-
       tok_info (const std::string& meth, const std::string& cls)
         : m_superclass_info (new superclass_info (meth, cls))
       { }
@@ -187,8 +173,6 @@
 
       end_tok_type m_et;
 
-      symbol_record *m_sr;
-
       struct superclass_info
       {
         superclass_info (void) = delete;