]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add accessors to struct dynamic_prop
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 13 Jul 2020 02:58:51 +0000 (22:58 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 13 Jul 2020 02:58:51 +0000 (22:58 -0400)
Add setters, to ensure that the kind and value of the property are
always kept in sync (a caller can't forget one or the other).  Add
getters, such that we can assert that when a caller accesses a data bit
of the property, the property is indeed of the corresponding kind.

Note that because of the way `struct dynamic_prop` is allocated
currently, we can't make the `m_kind` and `m_data` fields private.  That
would make the type non-default-constructible, and we would have to call
the constructor when allocating them.  However, I still prefixed them
with `m_` to indicate that they should not be accessed from outside the
class (and also to be able to use the name `kind` for the method).

gdb/ChangeLog:

* gdbtypes.h (struct dynamic_prop) <kind, set_undefined,
const_val, set_const_val, baton, set_locexpr, set_loclist,
set_addr_offset, variant_parts, set_variant_parts,
original_type, set_original_type>: New methods.
<kind>: Rename to...
<m_kind>: ... this.  Update all users to use the new methods
instead.
<data>: Rename to...
<m_data>: ... this.  Update all users to use the new methods
instead.

Change-Id: Ib72a8eb440dfeb1a5421d0933334230d7f2478f9

12 files changed:
gdb/ChangeLog
gdb/ada-typeprint.c
gdb/ctfread.c
gdb/dwarf2/loc.c
gdb/dwarf2/read.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/gnu-v3-abi.c
gdb/mdebugread.c
gdb/p-valprint.c
gdb/rust-lang.c
gdb/type-stack.c

index 162929f4140c7d29d336bc01eef090bfa2c2a389..2b6905d276c9b69a1a2c77c311f7953281fc2c89 100644 (file)
@@ -1,3 +1,16 @@
+2020-07-12  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * gdbtypes.h (struct dynamic_prop) <kind, set_undefined,
+       const_val, set_const_val, baton, set_locexpr, set_loclist,
+       set_addr_offset, variant_parts, set_variant_parts,
+       original_type, set_original_type>: New methods.
+       <kind>: Rename to...
+       <m_kind>: ... this.  Update all users to use the new methods
+       instead.
+       <data>: Rename to...
+       <m_data>: ... this.  Update all users to use the new methods
+       instead.
+
 2020-07-12  Simon Marchi  <simon.marchi@efficios.com>
 
        * gdbtypes.c (get_discrete_bounds): Return failure if
index 165ea0ee4aa8b28352e3aef54f5c69e69675205c..062b9d8a21f7b60187c41d63dfb9df88480465b5 100644 (file)
@@ -779,13 +779,13 @@ print_record_field_types (struct type *type, struct type *outer_type,
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
   if (prop != nullptr)
     {
-      if (prop->kind == PROP_TYPE)
+      if (prop->kind () == PROP_TYPE)
        {
-         type = prop->data.original_type;
+         type = prop->original_type ();
          prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
        }
-      gdb_assert (prop->kind == PROP_VARIANT_PARTS);
-      print_record_field_types_dynamic (*prop->data.variant_parts,
+      gdb_assert (prop->kind () == PROP_VARIANT_PARTS);
+      print_record_field_types_dynamic (*prop->variant_parts (),
                                        0, type->num_fields (),
                                        type, stream, show, level, flags);
       return type->num_fields ();
index f44cbecba09a282a53aa5542ba31f171aa41ac65..5b6d731479a1739f91b30525c65b7fd12c65eb4a 100644 (file)
@@ -774,7 +774,7 @@ read_array_type (struct ctf_context *ccp, ctf_id_t tid)
   type = create_array_type (NULL, element_type, range_type);
   if (ar.ctr_nelems <= 1)      /* Check if undefined upper bound.  */
     {
-      TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+      range_type->bounds ()->high.set_undefined ();
       TYPE_LENGTH (type) = 0;
       TYPE_TARGET_STUB (type) = 1;
     }
index 445d71a5ef1665ebbefb0377ec60e65c5dde1e56..866417eb1b103e9a10dfcb0ad4a8f6c57c8f55c6 100644 (file)
@@ -2589,12 +2589,12 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
   if (frame == NULL && has_stack_frames ())
     frame = get_selected_frame (NULL);
 
-  switch (prop->kind)
+  switch (prop->kind ())
     {
     case PROP_LOCEXPR:
       {
        const struct dwarf2_property_baton *baton
-         = (const struct dwarf2_property_baton *) prop->data.baton;
+         = (const struct dwarf2_property_baton *) prop->baton ();
        gdb_assert (baton->property_type != NULL);
 
        if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack,
@@ -2636,7 +2636,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
     case PROP_LOCLIST:
       {
        struct dwarf2_property_baton *baton
-         = (struct dwarf2_property_baton *) prop->data.baton;
+         = (struct dwarf2_property_baton *) prop->baton ();
        CORE_ADDR pc;
        const gdb_byte *data;
        struct value *val;
@@ -2662,13 +2662,13 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
       break;
 
     case PROP_CONST:
-      *value = prop->data.const_val;
+      *value = prop->const_val ();
       return true;
 
     case PROP_ADDR_OFFSET:
       {
        struct dwarf2_property_baton *baton
-         = (struct dwarf2_property_baton *) prop->data.baton;
+         = (struct dwarf2_property_baton *) prop->baton ();
        const struct property_addr_info *pinfo;
        struct value *val;
 
@@ -2708,13 +2708,13 @@ dwarf2_compile_property_to_c (string_file *stream,
                              struct symbol *sym)
 {
   struct dwarf2_property_baton *baton
-    = (struct dwarf2_property_baton *) prop->data.baton;
+    = (struct dwarf2_property_baton *) prop->baton ();
   const gdb_byte *data;
   size_t size;
   dwarf2_per_cu_data *per_cu;
   dwarf2_per_objfile *per_objfile;
 
-  if (prop->kind == PROP_LOCEXPR)
+  if (prop->kind () == PROP_LOCEXPR)
     {
       data = baton->locexpr.data;
       size = baton->locexpr.size;
@@ -2723,7 +2723,7 @@ dwarf2_compile_property_to_c (string_file *stream,
     }
   else
     {
-      gdb_assert (prop->kind == PROP_LOCLIST);
+      gdb_assert (prop->kind () == PROP_LOCLIST);
 
       data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
       per_cu = baton->loclist.per_cu;
index bc8f4a106d1daeaa381f37e64edcd10ec5dd47fd..558fad74f804180a9969a1415ffa23957a8dcac6 100644 (file)
@@ -9464,8 +9464,7 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
     = new (storage) gdb::array_view<variant_part> (part, 1);
 
   struct dynamic_prop prop;
-  prop.kind = PROP_VARIANT_PARTS;
-  prop.data.variant_parts = prop_value;
+  prop.set_variant_parts (prop_value);
 
   type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
@@ -14959,10 +14958,9 @@ add_variant_property (struct field_info *fip, struct type *type,
                            fip->variant_parts);
 
   struct dynamic_prop prop;
-  prop.kind = PROP_VARIANT_PARTS;
-  prop.data.variant_parts
-    = ((gdb::array_view<variant_part> *)
-       obstack_copy (&objfile->objfile_obstack, &parts, sizeof (parts)));
+  prop.set_variant_parts ((gdb::array_view<variant_part> *)
+                         obstack_copy (&objfile->objfile_obstack, &parts,
+                                       sizeof (parts)));
 
   type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
@@ -17138,8 +17136,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct dynamic_prop low_bound;
 
-      low_bound.kind = PROP_CONST;
-      low_bound.data.const_val = 1;
+      low_bound.set_const_val (1);
       range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
     }
   char_type = language_string_char_type (cu->language_defn, gdbarch);
@@ -17646,9 +17643,9 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
          baton->locexpr.is_reference = false;
          break;
        }
-      prop->data.baton = baton;
-      prop->kind = PROP_LOCEXPR;
-      gdb_assert (prop->data.baton != NULL);
+
+      prop->set_locexpr (baton);
+      gdb_assert (prop->baton () != NULL);
     }
   else if (attr->form_is_ref ())
     {
@@ -17672,9 +17669,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
                baton = XOBNEW (obstack, struct dwarf2_property_baton);
                baton->property_type = die_type (target_die, target_cu);
                fill_in_loclist_baton (cu, &baton->loclist, target_attr);
-               prop->data.baton = baton;
-               prop->kind = PROP_LOCLIST;
-               gdb_assert (prop->data.baton != NULL);
+               prop->set_loclist (baton);
+               gdb_assert (prop->baton () != NULL);
              }
            else if (target_attr->form_is_block ())
              {
@@ -17685,9 +17681,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
                baton->locexpr.size = DW_BLOCK (target_attr)->size;
                baton->locexpr.data = DW_BLOCK (target_attr)->data;
                baton->locexpr.is_reference = true;
-               prop->data.baton = baton;
-               prop->kind = PROP_LOCEXPR;
-               gdb_assert (prop->data.baton != NULL);
+               prop->set_locexpr (baton);
+               gdb_assert (prop->baton () != NULL);
              }
            else
              {
@@ -17709,17 +17704,13 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
                                                      target_cu);
              baton->offset_info.offset = offset;
              baton->offset_info.type = die_type (target_die, target_cu);
-             prop->data.baton = baton;
-             prop->kind = PROP_ADDR_OFFSET;
+             prop->set_addr_offset (baton);
              break;
            }
        }
     }
   else if (attr->form_is_constant ())
-    {
-      prop->data.const_val = attr->constant_value (0);
-      prop->kind = PROP_CONST;
-    }
+    prop->set_const_val (attr->constant_value (0));
   else
     {
       dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form),
@@ -17819,9 +17810,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   if (range_type)
     return range_type;
 
-  low.kind = PROP_CONST;
-  high.kind = PROP_CONST;
-  high.data.const_val = 0;
+  high.set_const_val (0);
 
   /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
      omitting DW_AT_lower_bound.  */
@@ -17829,27 +17818,27 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     {
     case language_c:
     case language_cplus:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = 1;
       break;
     case language_fortran:
-      low.data.const_val = 1;
+      low.set_const_val (1);
       low_default_is_valid = 1;
       break;
     case language_d:
     case language_objc:
     case language_rust:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = (cu->header.version >= 4);
       break;
     case language_ada:
     case language_m2:
     case language_pascal:
-      low.data.const_val = 1;
+      low.set_const_val (1);
       low_default_is_valid = (cu->header.version >= 4);
       break;
     default:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = 0;
       break;
     }
@@ -17871,8 +17860,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
        {
          /* If bounds are constant do the final calculation here.  */
-         if (low.kind == PROP_CONST && high.kind == PROP_CONST)
-           high.data.const_val = low.data.const_val + high.data.const_val - 1;
+         if (low.kind () == PROP_CONST && high.kind () == PROP_CONST)
+           high.set_const_val (low.const_val () + high.const_val () - 1);
          else
            high_bound_is_count = 1;
        }
@@ -17905,12 +17894,12 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      the base type is signed.  */
   negative_mask =
     -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
-  if (low.kind == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
-    low.data.const_val |= negative_mask;
-  if (high.kind == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
-    high.data.const_val |= negative_mask;
+  if (low.kind () == PROP_CONST
+      && !TYPE_UNSIGNED (base_type) && (low.const_val () & negative_mask))
+    low.set_const_val (low.const_val () | negative_mask);
+  if (high.kind () == PROP_CONST
+      && !TYPE_UNSIGNED (base_type) && (high.const_val () & negative_mask))
+    high.set_const_val (high.const_val () | negative_mask);
 
   /* Check for bit and byte strides.  */
   struct dynamic_prop byte_stride_prop;
@@ -17962,7 +17951,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   /* Ada expects an empty array on no boundary attributes.  */
   if (attr == NULL && cu->language != language_ada)
-    TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+    range_type->bounds ()->high.set_undefined ();
 
   name = dwarf2_name (die, cu);
   if (name)
index 40165563b91a93137ec63e80e52e6528293d679a..709574545928ef16f904cd908ae6246aa66d13c1 100644 (file)
@@ -874,23 +874,23 @@ allocate_stub_method (struct type *type)
 bool
 operator== (const dynamic_prop &l, const dynamic_prop &r)
 {
-  if (l.kind != r.kind)
+  if (l.kind () != r.kind ())
     return false;
 
-  switch (l.kind)
+  switch (l.kind ())
     {
     case PROP_UNDEFINED:
       return true;
     case PROP_CONST:
-      return l.data.const_val == r.data.const_val;
+      return l.const_val () == r.const_val ();
     case PROP_ADDR_OFFSET:
     case PROP_LOCEXPR:
     case PROP_LOCLIST:
-      return l.data.baton == r.data.baton;
+      return l.baton () == r.baton ();
     case PROP_VARIANT_PARTS:
-      return l.data.variant_parts == r.data.variant_parts;
+      return l.variant_parts () == r.variant_parts ();
     case PROP_TYPE:
-      return l.data.original_type == r.data.original_type;
+      return l.original_type () == r.original_type ();
     }
 
   gdb_assert_not_reached ("unhandled dynamic_prop kind");
@@ -940,21 +940,18 @@ create_range_type (struct type *result_type, struct type *index_type,
   bounds->low = *low_bound;
   bounds->high = *high_bound;
   bounds->bias = bias;
-
-  /* Initialize the stride to be a constant, the value will already be zero
-     thanks to the use of TYPE_ZALLOC above.  */
-  bounds->stride.kind = PROP_CONST;
+  bounds->stride.set_const_val (0);
 
   result_type->set_bounds (bounds);
 
-  if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
+  if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0)
     TYPE_UNSIGNED (result_type) = 1;
 
   /* Ada allows the declaration of range types whose upper bound is
      less than the lower bound, so checking the lower bound is not
      enough.  Make sure we do not mark a range type whose upper bound
      is negative as unsigned.  */
-  if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
+  if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0)
     TYPE_UNSIGNED (result_type) = 0;
 
   TYPE_ENDIANITY_NOT_DEFAULT (result_type)
@@ -1002,11 +999,8 @@ create_static_range_type (struct type *result_type, struct type *index_type,
 {
   struct dynamic_prop low, high;
 
-  low.kind = PROP_CONST;
-  low.data.const_val = low_bound;
-
-  high.kind = PROP_CONST;
-  high.data.const_val = high_bound;
+  low.set_const_val (low_bound);
+  high.set_const_val (high_bound);
 
   result_type = create_range_type (result_type, index_type, &low, &high, 0);
 
@@ -1021,9 +1015,9 @@ has_static_range (const struct range_bounds *bounds)
 {
   /* If the range doesn't have a defined stride then its stride field will
      be initialized to the constant 0.  */
-  return (bounds->low.kind == PROP_CONST
-         && bounds->high.kind == PROP_CONST
-         && bounds->stride.kind == PROP_CONST);
+  return (bounds->low.kind () == PROP_CONST
+         && bounds->high.kind () == PROP_CONST
+         && bounds->stride.kind () == PROP_CONST);
 }
 
 
@@ -1273,13 +1267,13 @@ create_array_type_with_stride (struct type *result_type,
                               unsigned int bit_stride)
 {
   if (byte_stride_prop != NULL
-      && byte_stride_prop->kind == PROP_CONST)
+      && byte_stride_prop->kind () == PROP_CONST)
     {
       /* The byte stride is actually not dynamic.  Pretend we were
         called with bit_stride set instead of byte_stride_prop.
         This will give us the same result type, while avoiding
         the need to handle this as a special case.  */
-      bit_stride = byte_stride_prop->data.const_val * 8;
+      bit_stride = byte_stride_prop->const_val () * 8;
       byte_stride_prop = NULL;
     }
 
@@ -1967,7 +1961,7 @@ array_type_has_dynamic_stride (struct type *type)
 {
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_BYTE_STRIDE);
 
-  return (prop != NULL && prop->kind != PROP_CONST);
+  return (prop != NULL && prop->kind () != PROP_CONST);
 }
 
 /* Worker for is_dynamic_type.  */
@@ -1999,7 +1993,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
     return 1;
 
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
-  if (prop != nullptr && prop->kind != PROP_TYPE)
+  if (prop != nullptr && prop->kind () != PROP_TYPE)
     return 1;
 
   if (TYPE_HAS_DYNAMIC_LENGTH (type))
@@ -2097,38 +2091,27 @@ resolve_dynamic_range (struct type *dyn_range_type,
 
   const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      low_bound.kind = PROP_CONST;
-      low_bound.data.const_val = value;
-    }
+    low_bound.set_const_val (value);
   else
-    {
-      low_bound.kind = PROP_UNDEFINED;
-      low_bound.data.const_val = 0;
-    }
+    low_bound.set_undefined ();
 
   prop = &dyn_range_type->bounds ()->high;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
-      high_bound.kind = PROP_CONST;
-      high_bound.data.const_val = value;
+      high_bound.set_const_val (value);
 
       if (dyn_range_type->bounds ()->flag_upper_bound_is_count)
-       high_bound.data.const_val
-         = low_bound.data.const_val + high_bound.data.const_val - 1;
+       high_bound.set_const_val
+         (low_bound.const_val () + high_bound.const_val () - 1);
     }
   else
-    {
-      high_bound.kind = PROP_UNDEFINED;
-      high_bound.data.const_val = 0;
-    }
+    high_bound.set_undefined ();
 
   bool byte_stride_p = dyn_range_type->bounds ()->flag_is_byte_stride;
   prop = &dyn_range_type->bounds ()->stride;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
-      stride.kind = PROP_CONST;
-      stride.data.const_val = value;
+      stride.set_const_val (value);
 
       /* If we have a bit stride that is not an exact number of bytes then
         I really don't think this is going to work with current GDB, the
@@ -2142,8 +2125,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
     }
   else
     {
-      stride.kind = PROP_UNDEFINED;
-      stride.data.const_val = 0;
+      stride.set_undefined ();
       byte_stride_p = true;
     }
 
@@ -2188,16 +2170,11 @@ resolve_dynamic_array_or_string (struct type *type,
      will update the length of the array accordingly.  */
   prop = TYPE_ALLOCATED_PROP (type);
   if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      TYPE_DYN_PROP_ADDR (prop) = value;
-      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
-    }
+    prop->set_const_val (value);
+
   prop = TYPE_ASSOCIATED_PROP (type);
   if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      TYPE_DYN_PROP_ADDR (prop) = value;
-      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
-    }
+    prop->set_const_val (value);
 
   ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
 
@@ -2447,14 +2424,13 @@ resolve_dynamic_struct (struct type *type,
   resolved_type = copy_type (type);
 
   dynamic_prop *variant_prop = resolved_type->dyn_prop (DYN_PROP_VARIANT_PARTS);
-  if (variant_prop != nullptr && variant_prop->kind == PROP_VARIANT_PARTS)
+  if (variant_prop != nullptr && variant_prop->kind () == PROP_VARIANT_PARTS)
     {
       compute_variant_fields (type, resolved_type, addr_stack,
-                             *variant_prop->data.variant_parts);
+                             *variant_prop->variant_parts ());
       /* We want to leave the property attached, so that the Rust code
         can tell whether the type was originally an enum.  */
-      variant_prop->kind = PROP_TYPE;
-      variant_prop->data.original_type = type;
+      variant_prop->set_original_type (type);
     }
   else
     {
@@ -2483,8 +2459,7 @@ resolve_dynamic_struct (struct type *type,
          baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (resolved_type, i);
 
          struct dynamic_prop prop;
-         prop.kind = PROP_LOCEXPR;
-         prop.data.baton = &baton;
+         prop.set_locexpr (&baton);
 
          CORE_ADDR addr;
          if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr,
@@ -2642,10 +2617,7 @@ resolve_dynamic_type_internal (struct type *type,
   prop = TYPE_DATA_LOCATION (resolved_type);
   if (prop != NULL
       && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      TYPE_DYN_PROP_ADDR (prop) = value;
-      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
-    }
+    prop->set_const_val (value);
 
   return resolved_type;
 }
index 2a1e6931b7fe802e02bf21a71b1c261118449ed4..5d9ed3972ff1c56fc6ec70fc931a430aa12b13fb 100644 (file)
@@ -511,11 +511,87 @@ union dynamic_prop_data
 
 struct dynamic_prop
 {
+  dynamic_prop_kind kind () const
+  {
+    return m_kind;
+  }
+
+  void set_undefined ()
+  {
+    m_kind = PROP_UNDEFINED;
+  }
+
+  LONGEST const_val () const
+  {
+    gdb_assert (m_kind == PROP_CONST);
+
+    return m_data.const_val;
+  }
+
+  void set_const_val (LONGEST const_val)
+  {
+    m_kind = PROP_CONST;
+    m_data.const_val = const_val;
+  }
+
+  void *baton () const
+  {
+    gdb_assert (m_kind == PROP_LOCEXPR
+               || m_kind == PROP_LOCLIST
+               || m_kind == PROP_ADDR_OFFSET);
+
+    return m_data.baton;
+  }
+
+  void set_locexpr (void *baton)
+  {
+    m_kind = PROP_LOCEXPR;
+    m_data.baton = baton;
+  }
+
+  void set_loclist (void *baton)
+  {
+    m_kind = PROP_LOCLIST;
+    m_data.baton = baton;
+  }
+
+  void set_addr_offset (void *baton)
+  {
+    m_kind = PROP_ADDR_OFFSET;
+    m_data.baton = baton;
+  }
+
+  const gdb::array_view<variant_part> *variant_parts () const
+  {
+    gdb_assert (m_kind == PROP_VARIANT_PARTS);
+
+    return m_data.variant_parts;
+  }
+
+  void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
+  {
+    m_kind = PROP_VARIANT_PARTS;
+    m_data.variant_parts = variant_parts;
+  }
+
+  struct type *original_type () const
+  {
+    gdb_assert (m_kind == PROP_TYPE);
+
+    return m_data.original_type;
+  }
+
+  void set_original_type (struct type *original_type)
+  {
+    m_kind = PROP_TYPE;
+    m_data.original_type = original_type;
+  }
+
   /* Determine which field of the union dynamic_prop.data is used.  */
-  enum dynamic_prop_kind kind;
+  enum dynamic_prop_kind m_kind;
 
   /* Storage for dynamic or static value.  */
-  union dynamic_prop_data data;
+  union dynamic_prop_data m_data;
 };
 
 /* Compare two dynamic_prop objects for equality.  dynamic_prop
@@ -1519,19 +1595,19 @@ extern unsigned type_align (struct type *);
 extern bool set_type_align (struct type *, ULONGEST);
 
 #define TYPE_LOW_BOUND(range_type) \
-  ((range_type)->bounds ()->low.data.const_val)
+  ((range_type)->bounds ()->low.const_val ())
 #define TYPE_HIGH_BOUND(range_type) \
-  ((range_type)->bounds ()->high.data.const_val)
+  ((range_type)->bounds ()->high.const_val ())
 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
   (TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
   (TYPE_HIGH_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_KIND(range_type) \
-  ((range_type)->bounds ()->high.kind)
+  ((range_type)->bounds ()->high.kind ())
 #define TYPE_LOW_BOUND_KIND(range_type) \
-  ((range_type)->bounds ()->low.kind)
+  ((range_type)->bounds ()->low.kind ())
 #define TYPE_BIT_STRIDE(range_type) \
-  ((range_type)->bounds ()->stride.data.const_val \
+  ((range_type)->bounds ()->stride.const_val () \
    * ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
 
 /* Property accessors for the type data location.  */
@@ -1540,9 +1616,9 @@ extern bool set_type_align (struct type *, ULONGEST);
 #define TYPE_DATA_LOCATION_BATON(thistype) \
   TYPE_DATA_LOCATION (thistype)->data.baton
 #define TYPE_DATA_LOCATION_ADDR(thistype) \
-  TYPE_DATA_LOCATION (thistype)->data.const_val
+  (TYPE_DATA_LOCATION (thistype)->const_val ())
 #define TYPE_DATA_LOCATION_KIND(thistype) \
-  TYPE_DATA_LOCATION (thistype)->kind
+  (TYPE_DATA_LOCATION (thistype)->kind ())
 #define TYPE_DYNAMIC_LENGTH(thistype) \
   ((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))
 
@@ -1556,9 +1632,9 @@ extern bool set_type_align (struct type *, ULONGEST);
 #define TYPE_DYN_PROP_BATON(dynprop) \
   dynprop->data.baton
 #define TYPE_DYN_PROP_ADDR(dynprop) \
-  dynprop->data.const_val
+  (dynprop->const_val ())
 #define TYPE_DYN_PROP_KIND(dynprop) \
-  dynprop->kind
+  (dynprop->kind ())
 
 
 /* Accessors for struct range_bounds data attached to an array type's
index 23c9c940ca3bde76878096f1e5578e96d6a71ba5..beff8b1ebde6c3a4fdd0f6f019152b5fe67e6d56 100644 (file)
@@ -471,8 +471,7 @@ gnuv3_baseclass_offset (struct type *type, int index,
       baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (type, index);
 
       struct dynamic_prop prop;
-      prop.kind = PROP_LOCEXPR;
-      prop.data.baton = &baton;
+      prop.set_locexpr (&baton);
 
       struct property_addr_info addr_stack;
       addr_stack.type = type;
index aa0c715b054aec22998b968a8f5e365562edf2fe..d38372041d752e4c188c15de168c10ce6b8162f0 100644 (file)
@@ -1736,9 +1736,9 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
       tp->set_num_fields (0);
       tp->set_bounds (((struct range_bounds *)
                        TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
-      TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
+      tp->bounds ()->low.set_const_val (AUX_GET_DNLOW (bigend, ax));
       ax++;
-      TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
+      tp->bounds ()->high.set_const_val (AUX_GET_DNHIGH (bigend, ax));
       ax++;
     }
 
index 3b1303d1248871214b2610bc74ef54b3a8e838a1..c98f3c5bf735bcf2a2567a3f0013bb0902c36368 100644 (file)
@@ -350,7 +350,7 @@ pascal_value_print_inner (struct value *val, struct ui_file *stream,
              maximum value.  */
              bound_info = 0;
              high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
-             TYPE_HIGH_BOUND (range) = high_bound;
+             range->bounds ()->high.set_const_val (high_bound);
            }
        maybe_bad_bstring:
          if (bound_info < 0)
index d1efea19e91823e7760e0ec25d04e99b1bedffab..31126a24b153fa67cae3018a4ecc6332993f0cbe 100644 (file)
@@ -653,8 +653,8 @@ rust_print_struct_def (struct type *type, const char *varstring,
        {
          fputs_filtered ("enum ", stream);
          dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
-         if (prop != nullptr && prop->kind == PROP_TYPE)
-           type = prop->data.original_type;
+         if (prop != nullptr && prop->kind () == PROP_TYPE)
+           type = prop->original_type ();
        }
       else if (type->code () == TYPE_CODE_STRUCT)
        fputs_filtered ("struct ", stream);
index 2d5c88f8d4d65d7e27aa248ff47a20c32e1b5b8b..fae3216ba65c2c78ac4c7689322435b958962685 100644 (file)
@@ -172,8 +172,7 @@ type_stack::follow_types (struct type *follow_type)
          lookup_array_range_type (follow_type,
                                   0, array_size >= 0 ? array_size - 1 : 0);
        if (array_size < 0)
-         TYPE_HIGH_BOUND_KIND (follow_type->index_type ())
-           = PROP_UNDEFINED;
+         follow_type->index_type ()->bounds ()->high.set_undefined ();
        break;
       case tp_function:
        /* FIXME-type-allocation: need a way to free this type when we are