]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use an enum to represent subclasses of symbol
authorTom Tromey <tom@tromey.com>
Fri, 17 Nov 2017 19:05:58 +0000 (12:05 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 17 Nov 2017 21:34:14 +0000 (14:34 -0700)
This changes struct symbol to use an enum to encode the concrete
subclass of a particular symbol.  Note that "enum class" doesn't work
properly with bitfields, so a plain enum is used.

2017-11-17  Tom Tromey  <tom@tromey.com>

* symtab.h (enum symbol_subclass_kind): New.
(struct symbol) <is_cplus_template_function, is_rust_vtable>:
Remove.
<subclass>: New member.
(SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION): Update.
* rust-lang.c (rust_get_trait_object_pointer): Update.
* dwarf2read.c (read_func_scope): Update.
(read_variable): Update.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/rust-lang.c
gdb/symtab.h

index 5aecd43182a7254842d583f97635651dbd319f74..31e447aa7dea93aeb8031f732d33d823e790799f 100644 (file)
@@ -1,3 +1,14 @@
+2017-11-17  Tom Tromey  <tom@tromey.com>
+
+       * symtab.h (enum symbol_subclass_kind): New.
+       (struct symbol) <is_cplus_template_function, is_rust_vtable>:
+       Remove.
+       <subclass>: New member.
+       (SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION): Update.
+       * rust-lang.c (rust_get_trait_object_pointer): Update.
+       * dwarf2read.c (read_func_scope): Update.
+       (read_variable): Update.
+
 2017-11-17  Tom Tromey  <tom@tromey.com>
 
        * dwarf2read.c (read_func_scope): Update.
index 86b699671ac90a38a7b8f3044f0c5b422019828a..5437d21b8941a8922e4250619558af60467d5554 100644 (file)
@@ -12263,7 +12263,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
          || child_die->tag == DW_TAG_template_value_param)
        {
          templ_func = allocate_template_symbol (objfile);
-         templ_func->is_cplus_template_function = 1;
+         templ_func->subclass = SYMBOL_TEMPLATE;
          break;
        }
     }
@@ -12821,7 +12821,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
                                    struct rust_vtable_symbol);
          initialize_objfile_symbol (storage);
          storage->concrete_type = containing_type;
-         storage->is_rust_vtable = 1;
+         storage->subclass = SYMBOL_RUST_VTABLE;
        }
     }
 
index 832f77fd3fa42fec0d72866f0ead2c70afaa6950..f3562e0f32b2c8940f8554b0cf40c2ec17ef0fea 100644 (file)
@@ -421,7 +421,7 @@ rust_get_trait_object_pointer (struct value *value)
 
   CORE_ADDR vtable = value_as_address (value_field (value, vtable_field));
   struct symbol *symbol = find_symbol_at_address (vtable);
-  if (symbol == NULL || !symbol->is_rust_vtable)
+  if (symbol == NULL || symbol->subclass != SYMBOL_RUST_VTABLE)
     return NULL;
 
   struct rust_vtable_symbol *vtable_sym
index 83d0ff256967a3c51a79c87a292a1318dbc076db..2d826aabb50cd5848b04a68730f6e75e954e21e9 100644 (file)
@@ -1009,6 +1009,21 @@ struct symbol_impl
   const struct symbol_register_ops *ops_register;
 };
 
+/* struct symbol has some subclasses.  This enum is used to
+   differentiate between them.  */
+
+enum symbol_subclass_kind
+{
+  /* Plain struct symbol.  */
+  SYMBOL_NONE,
+
+  /* struct template_symbol.  */
+  SYMBOL_TEMPLATE,
+
+  /* struct rust_vtable_symbol.  */
+  SYMBOL_RUST_VTABLE
+};
+
 /* This structure is space critical.  See space comments at the top.  */
 
 struct symbol
@@ -1058,14 +1073,9 @@ struct symbol
   /* Whether this is an inlined function (class LOC_BLOCK only).  */
   unsigned is_inlined : 1;
 
-  /* True if this is a C++ function symbol with template arguments.
-     In this case the symbol is really a "struct template_symbol".  */
-  unsigned is_cplus_template_function : 1;
-
-  /* True if this is a Rust virtual table.  In this case, the symbol
-     can be downcast to "struct rust_vtable_symbol".  */
+  /* The concrete type of this symbol.  */
 
-  unsigned is_rust_vtable : 1;
+  ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
 
   /* Line number of this symbol's definition, except for inlined
      functions.  For an inlined function (class LOC_BLOCK and
@@ -1127,7 +1137,7 @@ extern const struct block_symbol null_block_symbol;
 #define SYMBOL_IS_ARGUMENT(symbol)     (symbol)->is_argument
 #define SYMBOL_INLINED(symbol)         (symbol)->is_inlined
 #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
-  (symbol)->is_cplus_template_function
+  (((symbol)->subclass) == SYMBOL_TEMPLATE)
 #define SYMBOL_TYPE(symbol)            (symbol)->type
 #define SYMBOL_LINE(symbol)            (symbol)->line
 #define SYMBOL_COMPUTED_OPS(symbol)    (SYMBOL_IMPL (symbol).ops_computed)