Browse Source

Binding Generator: improve working with constexpr | AS Bindings: remove workaround for GCC

1vanK 3 years ago
parent
commit
aa298c4e42

+ 1 - 1
Source/Tools/BindingGenerator/ASClassBinder.cpp

@@ -1121,7 +1121,7 @@ static void RegisterField(const FieldAnalyzer& fieldAnalyzer, ProcessedClass& pr
             return;
         }
 
-        if (fieldAnalyzer.GetType().IsConst())
+        if (fieldAnalyzer.GetType().IsConst() || fieldAnalyzer.GetType().IsConstexpr())
             asType = "const " + asType;
 
         asType = ReplaceAll(asType, "struct ", "");

+ 1 - 1
Source/Tools/BindingGenerator/ASGlobalVariableBinder.cpp

@@ -66,7 +66,7 @@ static void ProcessGlobalVariable(GlobalVariableAnalyzer varAnalyzer)
         asType = typeAnalyzer.GetName();
     }
 
-    if (typeAnalyzer.IsConst())
+    if (typeAnalyzer.IsConst() || typeAnalyzer.IsConstexpr())
         asType = "const " + asType;
 
     string varName = varAnalyzer.GetName();

+ 20 - 3
Source/Tools/BindingGenerator/XmlAnalyzer.cpp

@@ -57,7 +57,6 @@ TypeAnalyzer::TypeAnalyzer(xml_node type, const TemplateSpecialization& speciali
     fullType_ = RemoveFirst(fullType_, "URHO3D_API ");
     fullType_ = RemoveFirst(fullType_, " URHO3D_API");
     fullType_ = CutStart(fullType_, "volatile ");
-    fullType_ = CutStart(fullType_, "constexpr ");
     fullType_ = ReplaceAll(fullType_, " *", "*");
     fullType_ = ReplaceAll(fullType_, " &", "&");
     fullType_ = ReplaceAll(fullType_, "< ", "<");
@@ -69,8 +68,25 @@ TypeAnalyzer::TypeAnalyzer(xml_node type, const TemplateSpecialization& speciali
         fullType_ = regex_replace(fullType_, rgx, it.second);
     }
 
-    isConst_ = StartsWith(fullType_, "const ");
-    name_ = CutStart(fullType_, "const ");
+    if (StartsWith(fullType_, "constexpr "))
+    {
+        isConstexpr_ = true;
+        isConst_ = false;
+        fullType_ = CutStart(fullType_, "constexpr ");
+        name_ = fullType_;
+    }
+    else if (StartsWith(fullType_, "const "))
+    {
+        isConst_ = true;
+        isConstexpr_ = false;
+        name_ = CutStart(fullType_, "const ");
+    }
+    else
+    {
+        isConst_ = false;
+        isConstexpr_ = false;
+        name_ = fullType_;
+    }
 
     isRvalueReference_ = EndsWith(name_, "&&");
     name_ = CutEnd(name_, "&&");
@@ -100,6 +116,7 @@ TypeAnalyzer::TypeAnalyzer(const string& typeName)
     fullType_ = typeName;
     name_ = typeName;
     isConst_ = false;
+    isConstexpr_ = false;
     isPointer_ = false;
     isReference_ = false;
     isRvalueReference_ = false;

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

@@ -43,6 +43,7 @@ private:
     std::string fullType_;
     std::string name_;
     bool isConst_;
+    bool isConstexpr_;
     bool isPointer_; // *
     bool isReference_; // &
     bool isRvalueReference_; // &&
@@ -59,6 +60,7 @@ public:
     std::string ToString() const { return fullType_; }
     std::string GetName() const { return name_; }
     bool IsConst() const { return isConst_; }
+    bool IsConstexpr() const { return isConstexpr_; }
     bool IsPointer() const { return isPointer_; }
     bool IsReference() const { return isReference_; }
     bool IsRvalueReference() const { return isRvalueReference_; }

+ 3 - 3
Source/Urho3D/AngelScript/Generated_Members.h

@@ -1673,10 +1673,10 @@ template <class T> void RegisterMembers_HashBase(asIScriptEngine* engine, const
     // void HashBase::Swap(HashBase& rhs)
     engine->RegisterObjectMethod(className, "void Swap(HashBase&)", AS_METHODPR(T, Swap, (HashBase&), void), AS_CALL_THISCALL);
 
-    // static const unsigned HashBase::MIN_BUCKETS
+    // static constexpr unsigned HashBase::MIN_BUCKETS
     engine->SetDefaultNamespace(className);engine->RegisterGlobalProperty("const uint MIN_BUCKETS", (void*)&T::MIN_BUCKETS);engine->SetDefaultNamespace("");
 
-    // static const unsigned HashBase::MAX_LOAD_FACTOR
+    // static constexpr unsigned HashBase::MAX_LOAD_FACTOR
     engine->SetDefaultNamespace(className);engine->RegisterGlobalProperty("const uint MAX_LOAD_FACTOR", (void*)&T::MAX_LOAD_FACTOR);engine->SetDefaultNamespace("");
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_HashBase
@@ -5074,7 +5074,7 @@ template <class T> void RegisterMembers_String(asIScriptEngine* engine, const ch
     // ShortString String::shortString_
     // Not registered because have @nobind mark
 
-    // static const unsigned String::NPOS
+    // static constexpr unsigned String::NPOS
     engine->SetDefaultNamespace(className);engine->RegisterGlobalProperty("const uint NPOS", (void*)&T::NPOS);engine->SetDefaultNamespace("");
 
     // static const String String::EMPTY

+ 0 - 7
Source/Urho3D/AngelScript/Manual_Container.cpp

@@ -33,13 +33,6 @@ void ASRegisterManualFirst_Container(asIScriptEngine* engine)
 
 // ========================================================================================
 
-// Workaround for GCC to allow get addresses
-const unsigned String::NPOS;
-const unsigned HashBase::MIN_BUCKETS;
-const unsigned HashBase::MAX_LOAD_FACTOR;
-
-// ========================================================================================
-
 static String& StringAssignInt(int value, String& str)
 {
     str = String(value);

+ 3 - 2
Source/Urho3D/Container/HashBase.h

@@ -101,9 +101,10 @@ class URHO3D_API HashBase
 {
 public:
     /// Initial amount of buckets.
-    static const unsigned MIN_BUCKETS = 8;
+    static inline constexpr unsigned MIN_BUCKETS = 8;
+    
     /// Maximum load factor.
-    static const unsigned MAX_LOAD_FACTOR = 4;
+    static inline constexpr unsigned MAX_LOAD_FACTOR = 4;
 
     /// Construct.
     HashBase() :

+ 1 - 1
Source/Urho3D/Container/Str.h

@@ -515,7 +515,7 @@ public:
     static int Compare(const char* lhs, const char* rhs, bool caseSensitive);
 
     /// Position for "not found".
-    static const unsigned NPOS = 0xffffffff;
+    static inline constexpr unsigned NPOS = 0xffffffff;
 
     /// Empty string.
     static const String EMPTY;