From 6295ff70effa07913ffe73ec2688e71a5bcd642c Mon Sep 17 00:00:00 2001 From: Giuliano Procida Date: Wed, 10 Jun 2020 12:59:39 +0100 Subject: [PATCH] Add declaration-only enums to XML reader/writer. * src/abg-reader.cc (build_enum_type_decl): Detect a declaration-only enum and flag it as such. (build_type_decl): Support reading the "is-declaration" attribute. (build_class_decl): Adjust. * src/abg-writer.cc (write_is_declaration_only): Renamed write_class_or_union_is_declaration_only into this. (write_enum_is_declaration_only): Remove. (write_type_decl, write_enum_type_decl) (write_class_decl_opening_tag, write_union_decl_opening_tag): Use write_is_declaration_only. * tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust. * tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise. * tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise. Signed-off-by: Giuliano Procida Signed-off-by: Dodji Seketeli --- src/abg-reader.cc | 13 +++++-- src/abg-writer.cc | 22 ++++++------ .../test-read-dwarf/PR22122-libftdc.so.abi | 36 +++++++++---------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index ee74d52e..ce90aca1 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -3457,6 +3457,9 @@ build_type_decl(read_context& ctxt, if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "alignment-in-bits")) alignment_in_bits = atoi(CHAR_STR(s)); + bool is_decl_only = false; + read_is_declaration_only(node, is_decl_only); + location loc; read_location(ctxt, node, loc); @@ -3479,6 +3482,7 @@ build_type_decl(read_context& ctxt, type_decl_sptr decl(new type_decl(env, name, size_in_bits, alignment_in_bits, loc)); decl->set_is_anonymous(is_anonymous); + decl->set_is_declaration_only(is_decl_only); if (ctxt.push_and_key_type_decl(decl, id, add_to_current_scope)) { ctxt.map_xml_node_to_decl(node, decl); @@ -4161,6 +4165,9 @@ build_enum_type_decl(read_context& ctxt, location loc; read_location(ctxt, node, loc); + bool is_decl_only = false; + read_is_declaration_only(node, is_decl_only); + bool is_anonymous = false; read_is_anonymous(node, is_anonymous); @@ -4221,6 +4228,7 @@ build_enum_type_decl(read_context& ctxt, enums, linkage_name)); t->set_is_anonymous(is_anonymous); t->set_is_artificial(is_artificial); + t->set_is_declaration_only(is_decl_only); if (ctxt.push_and_key_type_decl(t, id, add_to_current_scope)) { ctxt.map_xml_node_to_decl(node, t); @@ -4487,8 +4495,7 @@ build_class_decl(read_context& ctxt, if (!def_id.empty()) { - class_decl_sptr d = - dynamic_pointer_cast(ctxt.get_type_decl(def_id)); + decl_base_sptr d = is_decl(ctxt.get_type_decl(def_id)); if (d && d->get_is_declaration_only()) { is_def_of_decl = true; @@ -4506,7 +4513,7 @@ build_class_decl(read_context& ctxt, // previous_declaration. // // Let's link them. - decl->set_earlier_declaration(previous_declaration); + decl->set_earlier_declaration(is_decl(previous_declaration)); for (vector::const_iterator i = types_ptr->begin(); i != types_ptr->end(); ++i) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index ce0bae2d..bf44c769 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -876,8 +876,7 @@ static void write_elf_symbol_binding(elf_symbol::binding, ostream&); static bool write_elf_symbol_aliases(const elf_symbol&, ostream&); static bool write_elf_symbol_reference(const elf_symbol&, ostream&); static bool write_elf_symbol_reference(const elf_symbol_sptr, ostream&); -static void write_class_or_union_is_declaration_only(const class_or_union_sptr&, - ostream&); +static void write_is_declaration_only(const decl_base_sptr&, ostream&); static void write_is_struct(const class_decl_sptr&, ostream&); static void write_is_anonymous(const decl_base_sptr&, ostream&); static void write_naming_typedef(const class_decl_sptr&, write_context&); @@ -1777,18 +1776,16 @@ write_cdtor_const_static(bool is_ctor, o << " const='yes'"; } -/// Serialize the attribute "is-declaration-only", if the class or -/// union has its 'is_declaration_only property set. +/// Serialize the attribute "is-declaration-only", if the +/// decl_base_sptr has its 'is_declaration_only property set. /// -/// @param t the pointer to instance of @ref class_or_union to -/// consider. +/// @param t the pointer to instance of @ref decl_base to consider. /// /// @param o the output stream to serialize to. static void -write_class_or_union_is_declaration_only(const class_or_union_sptr& t, - ostream& o) +write_is_declaration_only(const decl_base_sptr& d, ostream& o) { - if (t->get_is_declaration_only()) + if (d->get_is_declaration_only()) o << " is-declaration-only='yes'"; } @@ -2459,6 +2456,8 @@ write_type_decl(const type_decl_sptr& d, write_context& ctxt, unsigned indent) write_size_and_alignment(d, o); + write_is_declaration_only(d, o); + write_location(d, ctxt); o << " id='" << ctxt.get_id_for_type(d) << "'" << "/>"; @@ -2938,6 +2937,7 @@ write_enum_type_decl(const enum_type_decl_sptr& decl, o << " linkage-name='" << decl->get_linkage_name() << "'"; write_location(decl, ctxt); + write_is_declaration_only(decl, o); string i = id; if (i.empty()) @@ -3475,7 +3475,7 @@ write_class_decl_opening_tag(const class_decl_sptr& decl, write_location(decl, ctxt); - write_class_or_union_is_declaration_only(decl, o); + write_is_declaration_only(decl, o); if (decl->get_earlier_declaration()) { @@ -3549,7 +3549,7 @@ write_union_decl_opening_tag(const union_decl_sptr& decl, write_location(decl, ctxt); - write_class_or_union_is_declaration_only(decl, o); + write_is_declaration_only(decl, o); string i = id; if (i.empty()) diff --git a/tests/data/test-read-dwarf/PR22122-libftdc.so.abi b/tests/data/test-read-dwarf/PR22122-libftdc.so.abi index 8df854c0..405e5036 100644 --- a/tests/data/test-read-dwarf/PR22122-libftdc.so.abi +++ b/tests/data/test-read-dwarf/PR22122-libftdc.so.abi @@ -270,7 +270,7 @@ - + @@ -500,7 +500,7 @@ - + @@ -969,7 +969,7 @@ - + @@ -1140,7 +1140,7 @@ - + @@ -3877,7 +3877,7 @@ - + @@ -4400,7 +4400,7 @@ - + @@ -5355,7 +5355,7 @@ - + @@ -5408,7 +5408,7 @@ - + @@ -5426,7 +5426,7 @@ - + @@ -7102,14 +7102,14 @@ - + - + @@ -7271,7 +7271,7 @@ - + @@ -7455,7 +7455,7 @@ - + @@ -7904,7 +7904,7 @@ - + @@ -7985,7 +7985,7 @@ - + @@ -8679,7 +8679,7 @@ - + @@ -8808,7 +8808,7 @@ - + @@ -8863,7 +8863,7 @@ - + -- 2.43.5