Browse Source

AS BindingGenerator: Not register factories for nocount objects (#2834)

1vanK 4 years ago
parent
commit
2e39a3d80c

+ 14 - 8
Source/Tools/BindingGenerator/ASClassBinder.cpp

@@ -144,6 +144,16 @@ static void RegisterConstructor(const MethodAnalyzer& methodAnalyzer, ProcessedC
         return;
     }
 
+    if (classAnalyzer.IsNoCount())
+    {
+        MemberRegistrationError regError;
+        regError.name_ = methodAnalyzer.GetName();
+        regError.comment_ = methodAnalyzer.GetLocation();
+        regError.message_ = "Factory not registered since the @nocount object created in a script through the factory will never be deleted";
+        processedClass.unregisteredSpecialMethods_.push_back(regError);
+        return;
+    }
+
     SpecialMethodRegistration result;
     //result.name_ = methodAnalyzer.GetName();
     result.comment_ = methodAnalyzer.GetDeclaration();
@@ -152,14 +162,11 @@ static void RegisterConstructor(const MethodAnalyzer& methodAnalyzer, ProcessedC
     string cppClassName = classAnalyzer.GetClassName();
     vector<ParamAnalyzer> params = methodAnalyzer.GetParams();
 
-    bool isNoCount = classAnalyzer.IsNoCount();
-
     if (params.empty()) // Default constructor
     {
-        if (classAnalyzer.IsRefCounted() || isNoCount)
+        if (classAnalyzer.IsRefCounted())
             result.registration_ = "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_FACTORY, \"" +
-                                   asClassName + "@" + (isNoCount ? "" : "+") +
-                                   " f()\", asFUNCTION(ASCompatibleFactory<" + cppClassName + ">), AS_CALL_CDECL);";
+                                   asClassName + "@+ f()\", asFUNCTION(ASCompatibleFactory<" + cppClassName + ">), AS_CALL_CDECL);";
         else
             result.registration_ = "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_CONSTRUCT, \"void f()\", asFUNCTION(ASCompatibleConstructor<" + cppClassName + ">), AS_CALL_CDECL_OBJFIRST);";
 
@@ -168,7 +175,6 @@ static void RegisterConstructor(const MethodAnalyzer& methodAnalyzer, ProcessedC
         return;
     }
 
-
     vector<ConvertedVariable> convertedParams;
     for (const ParamAnalyzer& param : params)
     {
@@ -198,9 +204,9 @@ static void RegisterConstructor(const MethodAnalyzer& methodAnalyzer, ProcessedC
             needWrapper = true;
     }
 
-    if (classAnalyzer.IsRefCounted() || isNoCount)
+    if (classAnalyzer.IsRefCounted())
     {
-        string asDeclaration = asClassName + "@" + (isNoCount ? "" : "+") + " f(" + JoinASDeclarations(convertedParams) + ")";
+        string asDeclaration = asClassName + "@+ f(" + JoinASDeclarations(convertedParams) + ")";
         result.registration_ = result.registration_ =
             "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_FACTORY, \"" + asDeclaration + "\", AS_FUNCTION("
             + GenerateWrapperName(methodAnalyzer) + ") , AS_CALL_CDECL);";

+ 21 - 16
Source/Urho3D/AngelScript/Generated_Classes.cpp

@@ -45,6 +45,9 @@ static void Register_AllocatorNode(asIScriptEngine* engine)
 // struct AnimationControl | File: ../Graphics/AnimationController.h
 static void Register_AnimationControl(asIScriptEngine* engine)
 {
+    // AnimationControl::AnimationControl() | File: ../Graphics/AnimationController.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+
     RegisterMembers_AnimationControl<AnimationControl>(engine, "AnimationControl");
 
     #ifdef REGISTER_CLASS_MANUAL_PART_AnimationControl
@@ -90,6 +93,9 @@ static void Register_AnimationStateTrack(asIScriptEngine* engine)
 // struct AnimationTrack | File: ../Graphics/Animation.h
 static void Register_AnimationTrack(asIScriptEngine* engine)
 {
+    // AnimationTrack::AnimationTrack() | File: ../Graphics/Animation.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+
     RegisterMembers_AnimationTrack<AnimationTrack>(engine, "AnimationTrack");
 
     #ifdef REGISTER_CLASS_MANUAL_PART_AnimationTrack
@@ -304,6 +310,9 @@ static void Register_Billboard(asIScriptEngine* engine)
 // struct Bone | File: ../Graphics/Skeleton.h
 static void Register_Bone(asIScriptEngine* engine)
 {
+    // Bone::Bone() | File: ../Graphics/Skeleton.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+
     RegisterMembers_Bone<Bone>(engine, "Bone");
 
     #ifdef REGISTER_CLASS_MANUAL_PART_Bone
@@ -486,25 +495,15 @@ static void Register_Color(asIScriptEngine* engine)
     #endif
 }
 
-// explicit ColorFrame::ColorFrame(const Color& color)
-static ColorFrame* ColorFrame__ColorFrame_constspColoramp(const Color& color)
-{
-    return new ColorFrame(color);
-}
-
-// ColorFrame::ColorFrame(const Color& color, float time)
-static ColorFrame* ColorFrame__ColorFrame_constspColoramp_float(const Color& color, float time)
-{
-    return new ColorFrame(color, time);
-}
-
 // struct ColorFrame | File: ../Graphics/ParticleEffect.h
 static void Register_ColorFrame(asIScriptEngine* engine)
 {
-    // explicit ColorFrame::ColorFrame(const Color& color)
-    engine->RegisterObjectBehaviour("ColorFrame", asBEHAVE_FACTORY, "ColorFrame@ f(const Color&in)", AS_FUNCTION(ColorFrame__ColorFrame_constspColoramp) , AS_CALL_CDECL);
-    // ColorFrame::ColorFrame(const Color& color, float time)
-    engine->RegisterObjectBehaviour("ColorFrame", asBEHAVE_FACTORY, "ColorFrame@ f(const Color&in, float)", AS_FUNCTION(ColorFrame__ColorFrame_constspColoramp_float) , AS_CALL_CDECL);
+    // ColorFrame::ColorFrame() | File: ../Graphics/ParticleEffect.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+    // ColorFrame::ColorFrame(const Color& color, float time) | File: ../Graphics/ParticleEffect.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+    // explicit ColorFrame::ColorFrame(const Color& color) | File: ../Graphics/ParticleEffect.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
 
     RegisterMembers_ColorFrame<ColorFrame>(engine, "ColorFrame");
 
@@ -2199,6 +2198,9 @@ static void Register_ShadowBatchQueue(asIScriptEngine* engine)
 // class Skeleton | File: ../Graphics/Skeleton.h
 static void Register_Skeleton(asIScriptEngine* engine)
 {
+    // Skeleton::Skeleton() | File: ../Graphics/Skeleton.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+
     RegisterMembers_Skeleton<Skeleton>(engine, "Skeleton");
 
     #ifdef REGISTER_CLASS_MANUAL_PART_Skeleton
@@ -2581,6 +2583,9 @@ static void Register_TechniqueEntry(asIScriptEngine* engine)
 // struct TextureFrame | File: ../Graphics/ParticleEffect.h
 static void Register_TextureFrame(asIScriptEngine* engine)
 {
+    // TextureFrame::TextureFrame() | File: ../Graphics/ParticleEffect.h
+    // Factory not registered since the @nocount object created in a script through the factory will never be deleted
+
     RegisterMembers_TextureFrame<TextureFrame>(engine, "TextureFrame");
 
     #ifdef REGISTER_CLASS_MANUAL_PART_TextureFrame

+ 0 - 18
Source/Urho3D/AngelScript/Generated_DefaultConstructors.cpp

@@ -18,18 +18,12 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // AllocatorNode::AllocatorNode() | Implicitly-declared
     engine->RegisterObjectBehaviour("AllocatorNode", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AllocatorNode>), AS_CALL_CDECL_OBJFIRST);
 
-    // AnimationControl::AnimationControl() | File: ../Graphics/AnimationController.h
-    engine->RegisterObjectBehaviour("AnimationControl", asBEHAVE_FACTORY, "AnimationControl@ f()", asFUNCTION(ASCompatibleFactory<AnimationControl>), AS_CALL_CDECL);
-
     // AnimationKeyFrame::AnimationKeyFrame() | File: ../Graphics/Animation.h
     engine->RegisterObjectBehaviour("AnimationKeyFrame", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AnimationKeyFrame>), AS_CALL_CDECL_OBJFIRST);
 
     // AnimationStateTrack::AnimationStateTrack() | File: ../Graphics/AnimationState.h
     engine->RegisterObjectBehaviour("AnimationStateTrack", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AnimationStateTrack>), AS_CALL_CDECL_OBJFIRST);
 
-    // AnimationTrack::AnimationTrack() | File: ../Graphics/Animation.h
-    engine->RegisterObjectBehaviour("AnimationTrack", asBEHAVE_FACTORY, "AnimationTrack@ f()", asFUNCTION(ASCompatibleFactory<AnimationTrack>), AS_CALL_CDECL);
-
     // AnimationTriggerPoint::AnimationTriggerPoint() | File: ../Graphics/Animation.h
     engine->RegisterObjectBehaviour("AnimationTriggerPoint", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AnimationTriggerPoint>), AS_CALL_CDECL_OBJFIRST);
 
@@ -57,9 +51,6 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // BiasParameters::BiasParameters() = default | File: ../Graphics/Light.h
     engine->RegisterObjectBehaviour("BiasParameters", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BiasParameters>), AS_CALL_CDECL_OBJFIRST);
 
-    // Bone::Bone() | File: ../Graphics/Skeleton.h
-    engine->RegisterObjectBehaviour("Bone", asBEHAVE_FACTORY, "Bone@ f()", asFUNCTION(ASCompatibleFactory<Bone>), AS_CALL_CDECL);
-
     // BoundingBox::BoundingBox() noexcept | File: ../Math/BoundingBox.h
     engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BoundingBox>), AS_CALL_CDECL_OBJFIRST);
 
@@ -72,9 +63,6 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // Color::Color() noexcept | File: ../Math/Color.h
     engine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Color>), AS_CALL_CDECL_OBJFIRST);
 
-    // ColorFrame::ColorFrame() | File: ../Graphics/ParticleEffect.h
-    engine->RegisterObjectBehaviour("ColorFrame", asBEHAVE_FACTORY, "ColorFrame@ f()", asFUNCTION(ASCompatibleFactory<ColorFrame>), AS_CALL_CDECL);
-
     // CompressedLevel::CompressedLevel() | Implicitly-declared
     engine->RegisterObjectBehaviour("CompressedLevel", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<CompressedLevel>), AS_CALL_CDECL_OBJFIRST);
 
@@ -270,9 +258,6 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // ShadowBatchQueue::ShadowBatchQueue() | Implicitly-declared
     engine->RegisterObjectBehaviour("ShadowBatchQueue", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<ShadowBatchQueue>), AS_CALL_CDECL_OBJFIRST);
 
-    // Skeleton::Skeleton() | File: ../Graphics/Skeleton.h
-    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_FACTORY, "Skeleton@ f()", asFUNCTION(ASCompatibleFactory<Skeleton>), AS_CALL_CDECL);
-
     // SourceBatch::SourceBatch() | File: ../Graphics/Drawable.h
     engine->RegisterObjectBehaviour("SourceBatch", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<SourceBatch>), AS_CALL_CDECL_OBJFIRST);
 
@@ -297,9 +282,6 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // TechniqueEntry::TechniqueEntry() noexcept | File: ../Graphics/Material.h
     engine->RegisterObjectBehaviour("TechniqueEntry", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<TechniqueEntry>), AS_CALL_CDECL_OBJFIRST);
 
-    // TextureFrame::TextureFrame() | File: ../Graphics/ParticleEffect.h
-    engine->RegisterObjectBehaviour("TextureFrame", asBEHAVE_FACTORY, "TextureFrame@ f()", asFUNCTION(ASCompatibleFactory<TextureFrame>), AS_CALL_CDECL);
-
     // Timer::Timer() | File: ../Core/Timer.h
     engine->RegisterObjectBehaviour("Timer", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Timer>), AS_CALL_CDECL_OBJFIRST);