Update xml parser to accept castxml output
authorLudwig Jäck <ludwig.jaeck@intra2net.com>
Fri, 31 May 2024 09:57:46 +0000 (11:57 +0200)
committerLudwig Jäck <ludwig.jaeck@intra2net.com>
Fri, 7 Jun 2024 08:02:01 +0000 (10:02 +0200)
Update the function and argument annotations from gccxml to castxml
style since castxml does not support 'gccxml' attributes and only
supports user defined string attributes through using the 'annotation'
attribute.

Update nested namespace parsing since castxml does not provide the
'demangle' attribute which provides the entire expanded declaration
of a type. The solution is concatenating the namespaces recursively.

codegen/main.cpp

index 7271b22..3060ee4 100644 (file)
@@ -107,16 +107,16 @@ std::string get_namespace(const xmlpp::Element* root, const std::string &id)
 {
     std::string error;
     const xmlpp::Element* element(get_element_by_id(root, id));
-    // [RP:20071024]: use "demangled" attribute instead of "name" to cover nested namespaces:
-    if ((!element)||(!element->get_attribute("demangled"))) return error;
-    return element->get_attribute("demangled")->get_value();
+    // castxml does not support "demangled" attribute -> recursivly concat nested namespaces
+    if ((!element)||(element->get_attribute("name")->get_value() == "::")) return error;
+    else return get_namespace(root,element->get_attribute("context")->get_value() ) + element->get_attribute("name")->get_value() + "::";
 }
 
 //! procedure marked for export?
 bool is_marked(const std::string &attrs)
 {
     // todo: improve this
-    std::string to_match("gccxml(libt2n-");
+    std::string to_match("annotate(libt2n-");
     std::string::size_type p(attrs.find(to_match));
     return (p!=std::string::npos);
 }
@@ -206,11 +206,6 @@ type_info get_type(const xmlpp::Element* root, const std::string &id)
     if (element->get_attribute("context"))
     {
         ret.name=get_namespace(root, element->get_attribute("context")->get_value());
-        if (ret.name!="::")
-            ret.name+="::";
-        else
-            // do not explicitely add ::
-            ret.name="";
     }
     ret.name+=element->get_attribute("name")->get_value();
     return ret;
@@ -327,7 +322,6 @@ protected:
         f.ret_type=get_type(root, returns->get_value());
         f.name=name->get_value();
         f.mangled=mangled->get_value();
-
         xmlpp::Node::NodeList list = node->get_children("Argument");
         for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
         {
@@ -355,7 +349,7 @@ protected:
                 if(arg->get_attribute("attributes"))
                 {
                     std::string attr=arg->get_attribute("attributes")->get_value();
-                    const std::string look_for = "gccxml(libt2n-default-arg,";
+                    const std::string look_for = "annotate(libt2n-default-arg,";
 
                     if (attr.compare(0,look_for.size(),look_for) == 0)
                         a.defaultArg=attr.substr(look_for.size(),attr.size()-look_for.size()-1);