Naming typedefs of classes are not read properly from abixml
authorDodji Seketeli <dodji@redhat.com>
Thu, 15 Dec 2016 13:29:38 +0000 (14:29 +0100)
committerDodji Seketeli <dodji@redhat.com>
Thu, 15 Dec 2016 15:25:41 +0000 (16:25 +0100)
When loading a class from abixml and when that class has a naming
typedef, build_class_decl fails to build the naming typedef from its
ID because it calls read_context::get_type_decl() instead of
read_context::build_or_get_type_decl().

This patch fixes that issue by using
read_context::build_or_get_type_decl rather than
read_context::get_type_decl.

Also, as read_context::build_or_get_type_decl can trigger the creation
of a class (and recursively call build_class_decl), it needs to be
called after the class type being built is marked as work-in-progress
(aka WIP).  So the handling of the naming typedef is moved to after
the class type being built is marked as WIP.

* src/abg-reader.cc (build_class_decl): Use
read_context::build_or_get_type_decl rather than
read_context::get_type_decl to build the naming typedef referred
to by the class being built.  Move the handling of naming typedefs
after the class is marked as WIP and keyed.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-reader.cc

index 1ba7379c8727dd1118bd4d6777b92498bb699d9d..cea5fa70044fbf705cc5018b2b3d0e750ea3b4d5 100644 (file)
@@ -3900,12 +3900,9 @@ build_class_decl(read_context&           ctxt,
   read_is_anonymous(node, is_anonymous);
 
   string naming_typedef_id;
-  typedef_decl_sptr naming_typedef;
 
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "naming-typedef-id"))
     naming_typedef_id = xml::unescape_xml_string(CHAR_STR(s));
-  if (!naming_typedef_id.empty())
-      naming_typedef = is_typedef(ctxt.get_type_decl(naming_typedef_id));
 
   assert(!id.empty());
   class_decl_sptr previous_definition, previous_declaration;
@@ -3962,9 +3959,6 @@ build_class_decl(read_context&            ctxt,
       decl->set_is_anonymous(is_anonymous);
     }
 
-  if (naming_typedef)
-    decl->set_naming_typedef(naming_typedef);
-
   string def_id;
   bool is_def_of_decl = false;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "def-of-decl-id"))
@@ -4024,6 +4018,15 @@ build_class_decl(read_context&           ctxt,
   ctxt.mark_type_as_wip(decl);
   ctxt.key_type_decl(decl, id);
 
+  // If this class has a naming typedef, get it and refer to it.
+  if (!naming_typedef_id.empty())
+    {
+      typedef_decl_sptr naming_typedef =
+       is_typedef(ctxt.build_or_get_type_decl(naming_typedef_id, true));
+      assert(naming_typedef);
+      decl->set_naming_typedef(naming_typedef);
+    }
+
   for (xmlNodePtr n = node->children; !is_decl_only && n; n = n->next)
     {
       if (n->type != XML_ELEMENT_NODE)