@@ -129,6 +129,10 @@ typedef vector<Dwarf_Off> dwarf_offsets_type;
/// die and which value is the corresponding artefact.
typedef unordered_map<Dwarf_Off, type_or_decl_base_sptr> die_artefact_map_type;
+/// Convenience typedef for a map which key is the offset of a dwarf
+/// die and which value is the corresponding type_base.
+typedef unordered_map<Dwarf_Off, type_base_sptr> die_type_map_type;
+
/// Convenience typedef for a map which key is the offset of a dwarf
/// die, (given by dwarf_dieoffset()) and which value is the
/// corresponding class_decl.
@@ -2270,12 +2274,9 @@ public:
/// function types, inside a translation unit.
mutable istring_fn_type_map_type per_tu_repr_to_fn_type_maps_;
- die_class_or_union_map_type die_wip_classes_map_;
- die_class_or_union_map_type alternate_die_wip_classes_map_;
- die_class_or_union_map_type type_unit_die_wip_classes_map_;
- die_function_type_map_type die_wip_function_types_map_;
- die_function_type_map_type alternate_die_wip_function_types_map_;
- die_function_type_map_type type_unit_die_wip_function_types_map_;
+ die_type_map_type die_wip_types_map_;
+ die_type_map_type alternate_die_wip_types_map_;
+ die_type_map_type type_unit_die_wip_types_map_;
die_function_decl_map_type die_function_with_no_symbol_map_;
vector<Dwarf_Off> types_to_canonicalize_;
vector<Dwarf_Off> alt_types_to_canonicalize_;
@@ -2447,12 +2448,9 @@ public:
type_die_artefact_maps_.clear();
canonical_type_die_offsets_.clear();
canonical_decl_die_offsets_.clear();
- die_wip_classes_map_.clear();
- alternate_die_wip_classes_map_.clear();
- type_unit_die_wip_classes_map_.clear();
- die_wip_function_types_map_.clear();
- alternate_die_wip_function_types_map_.clear();
- type_unit_die_wip_function_types_map_.clear();
+ die_wip_types_map_.clear();
+ alternate_die_wip_types_map_.clear();
+ type_unit_die_wip_types_map_.clear();
die_function_with_no_symbol_map_.clear();
types_to_canonicalize_.clear();
alt_types_to_canonicalize_.clear();
@@ -4280,21 +4278,9 @@ public:
if (!result)
{
- // Maybe we are looking for a class type being constructed?
- const die_class_or_union_map_type& m = die_wip_classes_map(source);
- die_class_or_union_map_type::const_iterator i = m.find(die_offset);
-
- if (i != m.end())
- result = i->second;
- }
-
- if (!result)
- {
- // Maybe we are looking for a function type being constructed?
- const die_function_type_map_type& m =
- die_wip_function_types_map(source);
- die_function_type_map_type::const_iterator i = m.find(die_offset);
-
+ // Maybe we are looking for a type being constructed?
+ const die_type_map_type& m = die_wip_types_map(source);
+ die_type_map_type::const_iterator i = m.find(die_offset);
if (i != m.end())
result = i->second;
}
@@ -4310,70 +4296,34 @@ public:
///
/// @return the map that associates a DIE to the class that is being
/// built.
- const die_class_or_union_map_type&
- die_wip_classes_map(die_source source) const
- {return const_cast<read_context*>(this)->die_wip_classes_map(source);}
+ const die_type_map_type&
+ die_wip_types_map(die_source source) const
+ {return const_cast<read_context*>(this)->die_wip_types_map(source);}
- /// Getter of a map that associates a die that represents a
- /// class/struct with the declaration of the class, while the class
- /// is being constructed.
+ /// Getter of a map that associates a die that represents a type
+ /// with the declaration of the type, while the type is being
+ /// constructed.
///
/// @param source where the DIE comes from.
///
- /// @return the map that associates a DIE to the class that is being
+ /// @return the map that associates a DIE to the type that is being
/// built.
- die_class_or_union_map_type&
- die_wip_classes_map(die_source source)
+ die_type_map_type&
+ die_wip_types_map(die_source source)
{
switch (source)
{
case PRIMARY_DEBUG_INFO_DIE_SOURCE:
break;
case ALT_DEBUG_INFO_DIE_SOURCE:
- return alternate_die_wip_classes_map_;
+ return alternate_die_wip_types_map_;
case TYPE_UNIT_DIE_SOURCE:
- return type_unit_die_wip_classes_map_;
+ return type_unit_die_wip_types_map_;
case NO_DEBUG_INFO_DIE_SOURCE:
case NUMBER_OF_DIE_SOURCES:
ABG_ASSERT_NOT_REACHED;
}
- return die_wip_classes_map_;
- }
-
- /// Getter for a map that associates a die (that represents a
- /// function type) whith a function type, while the function type is
- /// being constructed (WIP == work in progress).
- ///
- /// @param source where the DIE comes from.n
- ///
- /// @return the map of wip function types.
- const die_function_type_map_type&
- die_wip_function_types_map(die_source source) const
- {return const_cast<read_context*>(this)->die_wip_function_types_map(source);}
-
- /// Getter for a map that associates a die (that represents a
- /// function type) whith a function type, while the function type is
- /// being constructed (WIP == work in progress).
- ///
- /// @param source where DIEs of the map come from.
- ///
- /// @return the map of wip function types.
- die_function_type_map_type&
- die_wip_function_types_map(die_source source)
- {
- switch (source)
- {
- case PRIMARY_DEBUG_INFO_DIE_SOURCE:
- break;
- case ALT_DEBUG_INFO_DIE_SOURCE:
- return alternate_die_wip_function_types_map_;
- case TYPE_UNIT_DIE_SOURCE:
- return type_unit_die_wip_function_types_map_;
- case NO_DEBUG_INFO_DIE_SOURCE:
- case NUMBER_OF_DIE_SOURCES:
- ABG_ASSERT_NOT_REACHED;
- }
- return die_wip_function_types_map_;
+ return die_wip_types_map_;
}
/// Getter for a map that associates a die with a function decl
@@ -4387,40 +4337,20 @@ public:
die_function_decl_with_no_symbol_map()
{return die_function_with_no_symbol_map_;}
- /// Return true iff a given offset is for the DIE of a class that is
- /// being built, but that is not fully built yet. WIP == "work in
- /// progress".
- ///
- /// @param offset the DIE offset to consider.
- ///
- /// @param source where the DIE of the map come from.
- ///
- /// @return true iff @p offset is the offset of the DIE of a class
- /// that is being currently built.
- bool
- is_wip_class_die_offset(Dwarf_Off offset, die_source source) const
- {
- die_class_or_union_map_type::const_iterator i =
- die_wip_classes_map(source).find(offset);
- return (i != die_wip_classes_map(source).end());
- }
-
- /// Return true iff a given offset is for the DIE of a function type
- /// that is being built at the moment, but is not fully built yet.
- /// WIP == work in progress.
+ /// Return true iff a given offset is for the DIE of a type that is
+ /// being built at the moment, but is not fully built yet. WIP ==
+ /// work in progress.
///
/// @param offset DIE offset to consider.
///
/// @param source where the DIE comes from.
///
- /// @return true iff @p offset is the offset of the DIE of a
- /// function type that is being currently built.
+ /// @return true iff @p offset is the offset of the DIE of a type
+ /// that is being currently built.
bool
- is_wip_function_type_die_offset(Dwarf_Off offset, die_source source) const
+ is_wip_type_die_offset(Dwarf_Off offset, die_source source) const
{
- die_function_type_map_type::const_iterator i =
- die_wip_function_types_map(source).find(offset);
- return (i != die_wip_function_types_map(source).end());
+ return die_wip_types_map(source).count(offset);
}
/// Getter for the map of declaration-only classes that are to be
@@ -13779,9 +13709,9 @@ add_or_update_class_type(read_context& ctxt,
return result;
{
- die_class_or_union_map_type::const_iterator i =
- ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die));
- if (i != ctxt.die_wip_classes_map(source).end())
+ die_type_map_type::const_iterator i =
+ ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die));
+ if (i != ctxt.die_wip_types_map(source).end())
{
class_decl_sptr class_type = is_class_type(i->second);
ABG_ASSERT(class_type);
@@ -13907,7 +13837,7 @@ add_or_update_class_type(read_context& ctxt,
// here.
return result;
- ctxt.die_wip_classes_map(source)[dwarf_dieoffset(die)] = result;
+ ctxt.die_wip_types_map(source)[dwarf_dieoffset(die)] = result;
scope_decl_sptr scop =
dynamic_pointer_cast<scope_decl>(res);
@@ -14090,14 +14020,15 @@ add_or_update_class_type(read_context& ctxt,
ctxt.scope_stack().pop();
{
- die_class_or_union_map_type::const_iterator i =
- ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die));
- if (i != ctxt.die_wip_classes_map(source).end())
+ die_type_map_type::const_iterator i =
+ ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die));
+ if (i != ctxt.die_wip_types_map(source).end())
{
- if (is_member_type(i->second))
- set_member_access_specifier(res,
- get_member_access_specifier(i->second));
- ctxt.die_wip_classes_map(source).erase(i);
+ const type_base_sptr& type = i->second;
+ const decl_base* decl = is_decl(type.get());
+ if (is_member_type(type) && decl)
+ set_member_access_specifier(res, get_member_access_specifier(*decl));
+ ctxt.die_wip_types_map(source).erase(i);
}
}
@@ -14144,9 +14075,9 @@ add_or_update_union_type(read_context& ctxt,
die_source source;
ABG_ASSERT(ctxt.get_die_source(die, source));
{
- die_class_or_union_map_type::const_iterator i =
- ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die));
- if (i != ctxt.die_wip_classes_map(source).end())
+ die_type_map_type::const_iterator i =
+ ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die));
+ if (i != ctxt.die_wip_types_map(source).end())
{
union_decl_sptr u = is_union_type(i->second);
ABG_ASSERT(u);
@@ -14244,7 +14175,7 @@ add_or_update_union_type(read_context& ctxt,
if (!has_child)
return result;
- ctxt.die_wip_classes_map(source)[dwarf_dieoffset(die)] = result;
+ ctxt.die_wip_types_map(source)[dwarf_dieoffset(die)] = result;
scope_decl_sptr scop =
dynamic_pointer_cast<scope_decl>(result);
@@ -14326,14 +14257,16 @@ add_or_update_union_type(read_context& ctxt,
ctxt.scope_stack().pop();
{
- die_class_or_union_map_type::const_iterator i =
- ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die));
- if (i != ctxt.die_wip_classes_map(source).end())
+ die_type_map_type::const_iterator i =
+ ctxt.die_wip_types_map(source).find(dwarf_dieoffset(die));
+ if (i != ctxt.die_wip_types_map(source).end())
{
- if (is_member_type(i->second))
+ const type_base_sptr& type = i->second;
+ const decl_base* decl = is_decl(type.get());
+ if (is_member_type(type) && decl)
set_member_access_specifier(result,
- get_member_access_specifier(i->second));
- ctxt.die_wip_classes_map(source).erase(i);
+ get_member_access_specifier(*decl));
+ ctxt.die_wip_types_map(source).erase(i);
}
}
@@ -14796,7 +14729,7 @@ build_function_type(read_context& ctxt,
: new function_type(ctxt.env(), tu->get_address_size(),
/*alignment=*/0));
ctxt.associate_die_to_type(die, result, where_offset);
- ctxt.die_wip_function_types_map(source)[dwarf_dieoffset(die)] = result;
+ ctxt.die_wip_types_map(source)[dwarf_dieoffset(die)] = result;
ctxt.associate_die_repr_to_fn_type_per_tu(die, result);
type_base_sptr return_type;
@@ -14872,13 +14805,7 @@ build_function_type(read_context& ctxt,
tu->bind_function_type_life_time(result);
- {
- die_function_type_map_type::const_iterator i =
- ctxt.die_wip_function_types_map(source).
- find(dwarf_dieoffset(die));
- if (i != ctxt.die_wip_function_types_map(source).end())
- ctxt.die_wip_function_types_map(source).erase(i);
- }
+ ctxt.die_wip_types_map(source).erase(dwarf_dieoffset(die));
maybe_canonicalize_type(result, ctxt);
return result;
@@ -16259,7 +16186,7 @@ maybe_canonicalize_type(const Dwarf_Die *die, read_context& ctxt)
// maybe_strip_qualification) after they are initially built.
ctxt.schedule_type_for_late_canonicalization(die);
else if ((is_function_type(t)
- && ctxt.is_wip_function_type_die_offset(die_offset, source))
+ && ctxt.is_wip_type_die_offset(die_offset, source))
|| type_has_non_canonicalized_subtype(t))
ctxt.schedule_type_for_late_canonicalization(die);
else
The DWARF reader tracks incompletely declared class/union and function types using 6 maps. Supporting incompletely declared enum types in the same way would require 3 additional maps and more duplicated code. This commit folds together much of the duplicated WIP type handling. This comes at the price of a tiny bit of extra dynamic casting to copy member access specifiers in a couple of places. There are no behavioural changes. * src/abg-dwarf-reader.cc (die_type_map_type): Add new convenience typedef. (read_context): Replace *wip_classes_map_ and *wip_function_map_ members with *die_wip_types_map_ ones, replace die_wip_classes_map and die_wip_function_types_map getters with die_wip_types_map ones, replace is_wip_class_die_offset and is_wip_function_type_die_offset with is_wip_type_die_offset and simplify lookup. (read_context::initialize): Clear *die_wip_types_map_ instead of *wip_classes_map_ *wip_function_map_. (read_context::lookup_type_from_die_offset): Fold together class/union and function conditionals. (read_context::add_or_update_class_type): Replace uses of die_wip_classes_map with die_wip_types_map. Do an extra dynamic cast to be able to fetch member access specifiers in the case the WIP class is a member. (read_context::add_or_update_union_type): Mutatis mutandis. (read_context::build_function_type): Replace uses of die_wip_function_types_map with die_wip_types_map. Simplify removal from the map. (read_context::maybe_canonicalize_type): Replace use is_wip_function_type_die_offset with is_wip_type_die_offset. Signed-off-by: Giuliano Procida <gprocida@google.com> --- src/abg-dwarf-reader.cc | 191 +++++++++++++--------------------------- 1 file changed, 59 insertions(+), 132 deletions(-)