changeset 30091:7d2c9188d3f3

maint: Use enum in symrec.h for clarity. Replace "static const" variables with an enum for clarity. Change enum type to "unsigned short" to use only 1 byte rather than 4 bytes. * symrec.h: Remove "static const unsigned int" class variables "local", "formal", "added_static", and "variable". Declare enum "symrec_t" to describe storage class of a particular symbol. Update all functions to use new enum types.
author Rik <rik@octave.org>
date Tue, 31 Aug 2021 11:48:20 -0700
parents 1575b324613d
children 51040836259d
files libinterp/corefcn/symrec.h
diffstat 1 files changed, 31 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symrec.h	Tue Aug 31 16:49:36 2021 +0900
+++ b/libinterp/corefcn/symrec.h	Tue Aug 31 11:48:20 2021 -0700
@@ -48,18 +48,18 @@
 
     typedef std::size_t context_id;
 
-    // generic variable
-    static const unsigned int local = 1;
-
-    // formal parameter
-    static const unsigned int formal = 2;
-
-    // this symbol may NOT become a variable.
-    // (symbol added to a static workspace)
-    static const unsigned int added_static = 4;
-
-    // this symbol was recognized as a variable from syntax
-    static const unsigned int variable = 8;
+    enum symrec_t : unsigned char
+    {
+      // generic variable
+      LOCAL = 1,
+      // formal parameter
+      FORMAL = 2,
+      // this symbol may NOT become a variable.
+      // (symbol added to a static workspace)
+      ADDED_STATIC = 4,
+      // this symbol was recognized as a variable from syntax
+      VARIABLE = 8
+    };
 
   private:
 
@@ -67,7 +67,7 @@
     {
     public:
 
-      symbol_record_rep (const std::string& nm, unsigned int sc)
+      symbol_record_rep (const std::string& nm, symrec_t sc)
         : m_frame_offset (0), m_data_offset (0), m_storage_class (sc),
           m_name (nm)
       { }
@@ -91,63 +91,66 @@
 
       bool is_local (void) const
       {
-        return m_storage_class & local;
+        return m_storage_class & LOCAL;
       }
 
       bool is_formal (void) const
       {
-        return m_storage_class & formal;
+        return m_storage_class & FORMAL;
       }
 
       bool is_added_static (void) const
       {
-        return m_storage_class & added_static;
+        return m_storage_class & ADDED_STATIC;
       }
 
       bool is_variable (void) const
       {
-        return m_storage_class & variable;
+        return m_storage_class & VARIABLE;
       }
 
       void mark_local (void)
       {
-        m_storage_class |= local;
+        m_storage_class = static_cast<symrec_t> (m_storage_class | LOCAL);
       }
 
       void mark_formal (void)
       {
         // Formal parameters are also variables.
-        m_storage_class |= (formal | variable);
+        m_storage_class = static_cast<symrec_t> (m_storage_class
+                                                 | FORMAL | VARIABLE);
       }
 
       void mark_added_static (void)
       {
-        m_storage_class |= added_static;
+        m_storage_class = static_cast<symrec_t> (m_storage_class
+                                                 | ADDED_STATIC);
       }
 
       void mark_as_variable (void)
       {
-        m_storage_class |= variable;
+        m_storage_class = static_cast<symrec_t> (m_storage_class | VARIABLE);
       }
 
       void unmark_local (void)
       {
-        m_storage_class &= ~local;
+        m_storage_class = static_cast<symrec_t> (m_storage_class & ~LOCAL);
       }
 
       void unmark_formal (void)
       {
-        m_storage_class &= ~formal;
+        m_storage_class = static_cast<symrec_t> (m_storage_class & ~FORMAL);
       }
 
       void unmark_added_static (void)
       {
-        m_storage_class &= ~added_static;
+        m_storage_class = static_cast<symrec_t> (m_storage_class
+                                                 & ~ADDED_STATIC);
       }
 
       void unmark_as_variable (void)
       {
-        m_storage_class &= ~variable;
+        m_storage_class = static_cast<symrec_t> (m_storage_class & ~VARIABLE);
       }
 
       unsigned int storage_class (void) const { return m_storage_class; }
@@ -165,19 +168,19 @@
       std::size_t m_frame_offset;
       std::size_t m_data_offset;
 
-      unsigned int m_storage_class;
+      symrec_t m_storage_class;
 
       std::string m_name;
     };
 
   public:
 
-    symbol_record (const std::string& nm = "", unsigned int sc = local)
+    symbol_record (const std::string& nm = "", symrec_t sc = LOCAL)
       : m_rep (new symbol_record_rep (nm, sc))
     { }
 
     symbol_record (const std::string& nm, const octave_value&,
-                   unsigned int sc = local)
+                   symrec_t sc = LOCAL)
       : m_rep (new symbol_record_rep (nm, sc))
     { }