Browse Source

Greatly reduce warnings on generated C# code

Josh Engebretson 10 years ago
parent
commit
5ad128c8f6

+ 1 - 34
Script/AtomicNET/AtomicNET/AtomicNETEngine/AtomicNET.cs

@@ -91,39 +91,6 @@ public static class Atomic
   private static extern IntPtr csb_AtomicEngine_GetSubsystem(string name);
 
 }
-
-public static partial class Constants
-{
-    public const string LIBNAME = "__Internal";
-}
-
-public partial class RefCounted
-{
-
-  public RefCounted()
-  {
-  }
-
-  protected RefCounted (IntPtr native)
-  {
-    nativeInstance = native;
-  }
-
-  public IntPtr nativeInstance = IntPtr.Zero;
-
-  [DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
-  public static extern IntPtr csb_Atomic_RefCounted_GetClassID (IntPtr self);
-
-}
-
-public class InspectorAttribute : Attribute
-{
-  public InspectorAttribute(string DefaultValue = "")
-  {
-  }
-
-  public string DefaultValue;
-}
-
+				
 
 }

+ 27 - 0
Script/AtomicNET/AtomicNET/AtomicNETEngine/CSComponent.cs

@@ -0,0 +1,27 @@
+
+
+namespace AtomicEngine
+{
+
+	public partial class CSComponent : ScriptComponent
+	{
+		public virtual void Start()
+		{
+
+		}
+
+
+		public virtual void Update(float timeStep)
+		{
+
+		}
+
+		internal void StartInternal()
+		{
+			ApplyFieldValues();
+			Start();
+		}
+			
+	}
+
+}

+ 0 - 25
Script/AtomicNET/AtomicNET/AtomicNETEngine/ComponentCore.cs

@@ -8,31 +8,6 @@ using System.Linq;
 namespace AtomicEngine
 {
 
-
-  public partial class CSComponent : ScriptComponent
-  {
-
-    public void StartInternal()
-    {
-      ApplyFieldValues();
-      Start();
-    }
-
-    public virtual void Start()
-    {
-
-    }
-
-
-    public virtual void Update(float timeStep)
-    {
-
-    }
-
-
-
-  }
-
   public static class ComponentCore
   {
 

+ 14 - 0
Script/AtomicNET/AtomicNET/AtomicNETEngine/Constants.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+
+namespace AtomicEngine
+{
+
+	public static partial class Constants
+	{
+		public const string LIBNAME = "__Internal";
+	}
+
+}

+ 20 - 0
Script/AtomicNET/AtomicNET/AtomicNETEngine/InspectorAttribute.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+
+namespace AtomicEngine
+{
+
+
+	public class InspectorAttribute : Attribute
+	{
+		public InspectorAttribute(string DefaultValue = "")
+		{
+		}
+
+		public string DefaultValue;
+	}
+
+
+}

+ 30 - 0
Script/AtomicNET/AtomicNET/AtomicNETEngine/RefCounted.cs

@@ -0,0 +1,30 @@
+
+using System;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+
+namespace AtomicEngine
+{
+
+	public partial class RefCounted
+	{
+
+		public RefCounted ()
+		{
+		}
+
+		protected RefCounted (IntPtr native)
+		{
+			nativeInstance = native;
+		}
+
+		public IntPtr nativeInstance = IntPtr.Zero;
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		public static extern IntPtr csb_Atomic_RefCounted_GetClassID (IntPtr self);
+
+	}
+
+
+}

+ 2 - 2
Source/Atomic/UI/UISelectList.cpp

@@ -68,12 +68,12 @@ void UISelectList::SetValue(int value)
 
 }
 
-int UISelectList::GetValue()
+double UISelectList::GetValue()
 {
     if (!widget_)
         return 0;
 
-    return ((TBSelectList*)widget_)->GetValue();
+    return (double) ((TBSelectList*)widget_)->GetValue();
 
 }
 

+ 1 - 1
Source/Atomic/UI/UISelectList.h

@@ -48,7 +48,7 @@ public:
     void InvalidateList();
 
     void SetValue(int value);
-    int GetValue();
+    double GetValue();
 
     String GetHoverItemID();
     String GetSelectedItemID();

+ 1 - 1
Source/Atomic/UI/UIWidget.h

@@ -191,7 +191,7 @@ class UIWidget : public Object, public tb::TBWidgetDelegate
     void SetGravity(UI_GRAVITY gravity);
 
     void SetValue(double value);
-    double GetValue();
+    virtual double GetValue();
 
     void SetFocus();
     bool GetFocus();

+ 13 - 1
Source/ToolCore/JSBind/CSharp/CSClassWriter.cpp

@@ -101,8 +101,20 @@ void CSClassWriter::WriteManagedProperties(String& sourceOut)
             if (!fType)
                 continue;
 
+            String line = "public ";
+
+            JSBClass* baseClass = klass_->GetBaseClass();
+            if (baseClass)
+            {
+                if (baseClass->MatchProperty(prop, true))
+                {
+                    // always new so we don't have to deal with virtual/override on properties
+                    line += "new ";
+                }
+            }
+
             String type = CSTypeHelper::GetManagedTypeString(fType, false);
-            String line = ToString("public %s %s\n", type.CString(), prop->name_.CString());
+            line += ToString("%s %s\n", type.CString(), prop->name_.CString());
             source += IndentLine(line);
             source += IndentLine("{\n");
 

+ 21 - 1
Source/ToolCore/JSBind/CSharp/CSFunctionWriter.cpp

@@ -552,7 +552,27 @@ void CSFunctionWriter::WriteManagedFunction(String& source)
 
     GenManagedFunctionParameters(sig);
 
-    String line = ToString("public %s %s (%s)\n", returnType.CString(), function_->GetName().CString(), sig.CString());
+    String line = "public ";
+
+    bool marked = false;
+    JSBClass* baseClass = klass->GetBaseClass();
+    if (baseClass)
+    {
+        JSBFunction* override = baseClass->MatchFunction(function_, true);
+        if (override)
+        {
+            marked = true;
+            if (override->IsVirtual())
+                line += "override ";
+            else
+                line += "new ";
+        }
+    }
+
+    if (!marked && function_->IsVirtual())
+        line += "virtual ";
+
+    line += ToString("%s %s (%s)\n", returnType.CString(), function_->GetName().CString(), sig.CString());
 
     source += IndentLine(line);
 

+ 37 - 0
Source/ToolCore/JSBind/JSBClass.cpp

@@ -10,6 +10,7 @@
 #include <Atomic/IO/File.h>
 #include <Atomic/Resource/JSONFile.h>
 
+#include "JSBType.h"
 #include "JSBModule.h"
 #include "JSBClass.h"
 #include "JSBFunction.h"
@@ -189,6 +190,42 @@ void JSBClass::SetSkipFunction(const String& name, bool skip)
     }
 
 }
+
+bool JSBClass::MatchProperty(JSBProperty* property, bool includeBases)
+{
+
+    HashMap<String, JSBProperty*>::Iterator itr;
+    for (itr = properties_.Begin(); itr != properties_.End(); itr++)
+    {
+        if (itr->first_ != property->name_)
+            continue;
+
+        return true;
+    }
+
+    if (!includeBases || !baseClasses_.Size())
+        return 0;
+
+    return baseClasses_[0]->MatchProperty(property, true);
+}
+
+JSBFunction* JSBClass::MatchFunction(JSBFunction *function, bool includeBases)
+{
+    for (unsigned i = 0; i < functions_.Size(); i++)
+    {
+        JSBFunction* func = functions_[i];
+
+        if (func->Match(function))
+            return func;
+    }
+
+    if (!includeBases || !baseClasses_.Size())
+        return 0;
+
+    return baseClasses_[0]->MatchFunction(function, true);
+
+}
+
 void JSBClass::SetBaseClass(JSBClass *baseClass)
 {
     // we can't hook up chain here, as base class may not have been visited yet

+ 3 - 0
Source/ToolCore/JSBind/JSBClass.h

@@ -19,6 +19,7 @@ namespace ToolCore
 
 class JSBPackage;
 class JSBFunction;
+class JSBFunctionType;
 class JSBType;
 
 // chosen function overrides
@@ -121,6 +122,8 @@ public:
         return properties_[name];
     }
 
+    JSBFunction* MatchFunction(JSBFunction* function, bool includeBases = false);
+    bool MatchProperty(JSBProperty* property, bool includeBases = false);
 
     JSBHeader* GetHeader() { return header_; }
     JSBModule* GetModule() { return module_; }

+ 30 - 0
Source/ToolCore/JSBind/JSBFunction.cpp

@@ -55,6 +55,36 @@ void JSBFunction::Process()
 
 }
 
+bool JSBFunction::Match(JSBFunction* func)
+{
+    if (func->Skip() || func->GetName() != name_)
+        return false;
+
+    if (!returnType_)
+    {
+        if (func->GetReturnType())
+            return false;
+    }
+    else
+    {
+        if (!returnType_->Match(func->GetReturnType()))
+            return false;
+    }
+
+    Vector<JSBFunctionType*>& fparams = func->GetParameters();
+
+    if (parameters_.Size() != fparams.Size())
+        return false;
+
+    for ( unsigned j = 0; j < fparams.Size(); j++)
+    {
+        if (!parameters_[j]->Match(fparams[j]))
+            return false;
+    }
+
+    return true;
+}
+
 JSBClass* JSBFunction::GetReturnClass()
 {
     if (!returnType_)

+ 32 - 0
Source/ToolCore/JSBind/JSBFunction.h

@@ -30,6 +30,36 @@ public:
         isConst_ = false;
     }
 
+    // returns true if the types match
+    bool Match(const JSBFunctionType* other)
+    {
+        if (!other)
+            return false;
+
+        if (isSharedPtr_ != other->isSharedPtr_)
+            return false;
+        if (isPointer_ != other->isPointer_)
+            return false;
+        if (isReference_ != other->isReference_)
+            return false;
+        if (isTemplate_ != other->isTemplate_)
+            return false;
+        if (isConst_ != other->isConst_)
+            return false;
+
+        if (name_ != other->name_)
+            return false;
+
+        if (!type_ && !other->type_)
+            return true;
+
+        if (!type_ || !other->type_)
+            return false;
+
+        return type_->Match(other->type_);
+
+    }
+
     bool isSharedPtr_;
     bool isPointer_;
     bool isReference_;
@@ -95,6 +125,8 @@ public:
 
     const String& GetName() { return name_; }
 
+    bool Match(JSBFunction* func);
+
     bool IsConstructor() { return isConstructor_; }
     bool IsDestructor() { return isDestructor_; }
     bool IsSetter() { return isSetter_; }

+ 1 - 1
Source/ToolCore/JSBind/JSBHeaderVisitor.h

@@ -278,7 +278,7 @@ public:
         if (name.StartsWith("~"))
             jfunction->SetDestructor();
 
-        if (function->isOverride())
+        if (function->isVirtual())
             jfunction->SetVirtual(true);
 
         // see if we support return type

+ 84 - 0
Source/ToolCore/JSBind/JSBType.h

@@ -30,6 +30,9 @@ class JSBType
 
 public:
 
+    // returns true if the types match
+    virtual bool Match (JSBType* other) = 0;
+
     virtual JSBPrimitiveType* asPrimitiveType() { return 0; }
     virtual JSBClassType* asClassType() { return 0; }
     virtual JSBStringType* asStringType() { return 0; }
@@ -69,6 +72,21 @@ public:
 
     }
 
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        const JSBPrimitiveType* pother = other->asPrimitiveType();
+
+        if (!pother)
+            return false;
+
+        return (kind_ == pother->kind_ && isUnsigned_ == pother->isUnsigned_);
+
+        return true;
+    }
+
     String ToString()
     {
         switch (kind_)
@@ -112,6 +130,15 @@ public:
 
     String ToString() { return "String"; }
 
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        return other->asStringType() == 0 ? false : true;
+    }
+
+
 };
 
 class JSBStringHashType : public JSBType
@@ -122,6 +149,14 @@ public:
 
     String ToString() { return "StringHash"; }
 
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        return other->asStringHashType() == 0 ? false : true;
+    }
+
 };
 
 class JSBHeapPtrType : public JSBType
@@ -132,6 +167,14 @@ public:
 
     String ToString() { return "JS_HEAP_PTR"; }
 
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        return other->asHeapPtrType() == 0 ? false : true;
+    }
+
 };
 
 
@@ -147,6 +190,19 @@ public:
 
     String ToString() { return enum_->GetName(); }
 
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        JSBEnumType* pother = other->asEnumType();
+
+        if (!pother || pother->enum_ != enum_)
+            return false;
+
+        return true;
+    }
+
 };
 
 class JSBVectorType : public JSBType
@@ -161,6 +217,20 @@ public:
     virtual JSBVectorType* asVectorType() { return this; }
 
     String ToString() { return "Vector<" + vectorType_->ToString() + ">"; }
+
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        JSBVectorType* pother = other->asVectorType();
+
+        if (!pother || !vectorType_->Match(pother->vectorType_))
+            return false;
+
+        return true;
+    }
+
 };
 
 
@@ -183,6 +253,20 @@ public:
         return class_->GetNativeName();
     }
 
+    virtual bool Match (JSBType* other)
+    {
+        if (!other)
+            return false;
+
+        JSBClassType* pother = other->asClassType();
+
+        if (!pother || class_ != pother->class_)
+            return false;
+
+        return true;
+    }
+
+
 };
 
 }