瀏覽代碼

AS Autobindings: reorganize doxygen 7732 issue workaround (#2746)

1vanK 5 年之前
父節點
當前提交
0ba217b9a1

+ 0 - 5
Source/Tools/BindingGenerator/ASUtils.cpp

@@ -92,7 +92,6 @@ static bool IsUsing(const string& identifier)
 bool IsKnownType(const string& name)
 {
     static vector<string> _knownTypes = {
-        "", // TODO: fix opConv()
         "void",
         "bool",
         "size_t",
@@ -773,10 +772,6 @@ string Generate_asMETHODPR(const ClassFunctionAnalyzer& functionAnalyzer, bool t
 
     string returnType = functionAnalyzer.GetReturnType(templateSpecialization).ToString();
     
-    // Extracting type from function name (workaround for https://github.com/doxygen/doxygen/issues/7732)
-    if (functionAnalyzer.IsConsversionOperator())
-        returnType = CutStart(functionName, "operator ");
-
     if (templateVersion)
         return "asMETHODPR(T, " + functionName + ", " + cppParams + ", " + returnType + ")";
     else

+ 41 - 23
Source/Tools/BindingGenerator/XmlAnalyzer.cpp

@@ -27,18 +27,28 @@
 #include <cassert>
 #include <regex>
 
-TypeAnalyzer::TypeAnalyzer(xml_node type, const map<string, string>& templateSpecialization)
+string RemoveRefs(xml_node node)
 {
-    assert(type.name() == string("type"));
+    assert(node.name() == string("type") || node.name() == string("defval") || node.name() == string("para"));
+
+    string result;
 
-    for (xml_node part : type.children())
+    for (xml_node part : node.children())
     {
         if (part.name() == string("ref"))
-            fullType_ += part.child_value();
+            result += part.child_value();
         else
-            fullType_ += part.value();
+            result += part.value();
     }
 
+    return result;
+}
+
+TypeAnalyzer::TypeAnalyzer(xml_node type, const map<string, string>& templateSpecialization)
+{
+    assert(type.name() == string("type"));
+
+    fullType_ = RemoveRefs(type);
     fullType_ = RemoveFirst(fullType_, "URHO3D_API ");
     fullType_ = CutStart(fullType_, "constexpr ");
     fullType_ = ReplaceAll(fullType_, " *", "*");
@@ -78,6 +88,18 @@ TypeAnalyzer::TypeAnalyzer(xml_node type, const map<string, string>& templateSpe
     }
 }
 
+TypeAnalyzer::TypeAnalyzer(const string& typeName)
+{
+    fullType_ = typeName;
+    name_ = typeName;
+    isConst_ = false;
+    isPointer_ = false;
+    isReference_ = false;
+    isRvalueReference_ = false;
+    isDoublePointer_ = false;
+    isRefToPoiner_ = false;
+}
+
 // ============================================================================
 
 ParamAnalyzer::ParamAnalyzer(xml_node param, const map<string, string>& templateSpecialization)
@@ -116,18 +138,12 @@ string ParamAnalyzer::GetDeclname() const
 
 string ParamAnalyzer::GetDefval() const
 {
-    string result;
-
     xml_node defval = node_.child("defval");
-    for (xml_node part : defval.children())
-    {
-        if (part.name() == string("ref"))
-            result += part.child_value();
-        else
-            result += part.value();
-    }
 
-    return result;
+    if (defval)
+        return RemoveRefs(defval);
+
+    return "";
 }
 
 // ============================================================================
@@ -233,6 +249,15 @@ TypeAnalyzer ExtractType(xml_node memberdef, const map<string, string>& template
     xml_node type = memberdef.child("type");
     assert(type);
 
+    // Doxygen bug workaround https://github.com/doxygen/doxygen/issues/7732
+    // For user-defined conversion operator exract return type from function name
+    if (RemoveRefs(type).empty() && ExtractKind(memberdef) == "function")
+    {
+        string functionName = ExtractName(memberdef);
+        if (StartsWith(functionName, "operator "))
+            return TypeAnalyzer(CutStart(functionName, "operator "));
+    }
+
     return TypeAnalyzer(type, templateSpecialization);
 }
 
@@ -351,14 +376,7 @@ static string DescriptionToString(xml_node description)
 
     for (xml_node para : description.children("para"))
     {
-        for (xml_node part : para.children())
-        {
-            if (part.name() == string("ref"))
-                result += part.child_value();
-            else
-                result += part.value();
-        }
-
+        result += RemoveRefs(para);
         result += " "; // To avoid gluing words from different paragraphs
     }
 

+ 6 - 0
Source/Tools/BindingGenerator/XmlAnalyzer.h

@@ -34,6 +34,9 @@
 using namespace pugi;
 using namespace std;
 
+// <type>...</type> | <defval>...</defval> | <para>...</para>
+string RemoveRefs(xml_node node);
+
 // <type>...</type>
 class TypeAnalyzer
 {
@@ -51,6 +54,9 @@ private:
 public:
     TypeAnalyzer(xml_node type, const map<string, string>& templateSpecialization = map<string, string>());
 
+    // Used for doxygen bug workaround https://github.com/doxygen/doxygen/issues/7732
+    TypeAnalyzer(const string& typeName);
+
     string ToString() const { return fullType_; }
     string GetName() const { return name_; }
     bool IsConst() const { return isConst_; }