Forráskód Böngészése

Better handling of inherited interface methods

Josh Engebretson 8 éve
szülő
commit
d357a815f0

+ 24 - 12
Source/ToolCore/JSBind/CSharp/CSClassWriter.cpp

@@ -105,6 +105,17 @@ void CSClassWriter::WriteManagedProperties(String& sourceOut)
             if (CSTypeHelper::OmitFunction(prop->getter_) || CSTypeHelper::OmitFunction(prop->setter_))
                 continue;
 
+            if (klass_->IsInterface())
+            {
+                if ((prop->getter_ && prop->getter_->IsInheritedInterface()) ||
+                    (prop->setter_ && prop->setter_->IsInheritedInterface()))
+                {
+                    // note possibility of mismatched inheritance on get/set
+                    // if possible to trip this in C#, will need to be addressed here
+                    continue;
+                }
+            }
+
             if (prop->getter_ && !prop->getter_->Skip())
             {
                 fType = getType = prop->getter_->GetReturnType();
@@ -223,17 +234,21 @@ void CSClassWriter::GenerateManagedSource(String& sourceOut)
 
     JSBClass* baseClass = klass_->GetBaseClass();
     const StringVector& csharpInterfaces = klass_->GetCSharpInterfaces();
+    const PODVector<JSBClass*>& nativeInterfaces = klass_->GetInterfaces();
+
+    String classString = "class";
 
-    if (baseClass || csharpInterfaces.Size())
+    if (klass_->IsInterface())
+        classString = "interface";
+
+    if (baseClass || csharpInterfaces.Size() || nativeInterfaces.Size())
     {
         StringVector baseStrings;
 
         if (baseClass)
         {
             baseStrings.Push(baseClass->GetName());
-        }
-        
-        const PODVector<JSBClass*>& nativeInterfaces = klass_->GetInterfaces();
+        }               
 
         for (unsigned i = 0; i < nativeInterfaces.Size(); i++)
         {
@@ -245,18 +260,12 @@ void CSClassWriter::GenerateManagedSource(String& sourceOut)
             baseStrings.Push(csharpInterfaces[i]);
         }
 
+        String baseString = String::Joined(baseStrings, ", ");
 
-        String baseString = String::Joined(baseStrings, ",");
-
-        line = ToString("public partial class %s%s : %s\n", klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "", baseString.CString());
+        line = ToString("public partial %s %s%s : %s\n", classString.CString(), klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "", baseString.CString());
     }
     else
     {
-        String classString = "class";
-
-        if (klass_->IsInterface())
-            classString = "interface";
-
         line = ToString("public partial %s %s%s\n", classString.CString(), klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "");
     }
 
@@ -303,6 +312,9 @@ void CSClassWriter::GenerateManagedSource(String& sourceOut)
         if (function->IsDestructor())
             continue;
 
+        if (klass_->IsInterface() && function->IsInheritedInterface())
+            continue;
+
         if (CSTypeHelper::OmitFunction(function))
             continue;
 

+ 0 - 1
Source/ToolCore/JSBind/CSharp/CSTypeHelper.cpp

@@ -379,7 +379,6 @@ bool CSTypeHelper::OmitFunction(JSBFunction* function)
     if (!function)
         return false;
 
-
     if (function->GetSkipLanguage(BINDINGLANGUAGE_CSHARP))
         return true;
 

+ 1 - 1
Source/ToolCore/JSBind/JSBClass.cpp

@@ -304,7 +304,7 @@ void JSBClass::MergeInterface(JSBClass* interface)
         if (!MatchFunction(src))
         {
             JSBFunction* function = src->Clone(this);
-            function->SetInterface(true);
+            function->SetInheritedInterface(true);
             AddFunction(function);
         }
     }

+ 2 - 2
Source/ToolCore/JSBind/JSBFunction.cpp

@@ -28,7 +28,7 @@ namespace ToolCore
 unsigned JSBFunction::idCounter_ = 1;
 
 JSBFunction::JSBFunction(JSBClass* klass) : class_(klass), returnType_(0),
-                                  isInterface_(false),
+                                  isInheritedInterface_(false),
                                   isConstructor_(false), isDestructor_(false),
                                   isGetter_(false), isSetter_(false),
                                   isOverload_(false), skip_(false),
@@ -166,7 +166,7 @@ JSBFunction* JSBFunction::Clone(JSBClass* dstClass)
 
     dst->docString_ = docString_;
 
-    dst->isInterface_ = isInterface_;
+    dst->isInheritedInterface_ = isInheritedInterface_;
     dst->isConstructor_ = isConstructor_;
     dst->isDestructor_ = isDestructor_;
     dst->isGetter_ = isGetter_;

+ 5 - 3
Source/ToolCore/JSBind/JSBFunction.h

@@ -153,7 +153,9 @@ public:
     bool IsOverload() { return isOverload_; }
     bool IsVirtual() const { return isVirtual_; }
     bool IsStatic() const { return isStatic_; }
-    bool IsInterface() const { return isInterface_; }
+
+    // get whether this method is inherited from a parent interface
+    bool IsInheritedInterface() const { return isInheritedInterface_; }
 
     // true if return value has been mutated to be passed in at end of parameters (optimization)
     bool HasMutatedReturn() const { return hasMutatedReturn_; }
@@ -190,7 +192,7 @@ public:
     void SetStatic(bool value = true) { isStatic_ = value; }
     void SetSkip(bool value) { skip_ = value; }
     void SetReturnType(JSBFunctionType* retType) { returnType_ = retType; }
-    void SetInterface(bool interface) { isInterface_ = interface; }
+    void SetInheritedInterface(bool interface) { isInheritedInterface_ = interface; }
     void SetDocString(const String& docString) { docString_ = docString; }
 
     void SetSkipLanguage(BindingLanguage language, bool skip = true)
@@ -295,7 +297,7 @@ private:
 
     String docString_;
 
-    bool isInterface_;
+    bool isInheritedInterface_;
 
     bool isConstructor_;
     bool isDestructor_;