From 077e505cd7a68db3c459e4b3134b6b2f68dd9559 Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Sun, 26 Jul 2015 19:12:03 +0530 Subject: [PATCH 1/6] Added marshalling to struct... --- .../Passes/CheckValueTypeClassesPass.cs | 42 +++++++++++++++++++ tests/Basic/Basic.cs | 1 + tests/Basic/Basic.h | 5 +++ 3 files changed, 48 insertions(+) create mode 100644 src/Generator/Passes/CheckValueTypeClassesPass.cs diff --git a/src/Generator/Passes/CheckValueTypeClassesPass.cs b/src/Generator/Passes/CheckValueTypeClassesPass.cs new file mode 100644 index 0000000000..6b2067e864 --- /dev/null +++ b/src/Generator/Passes/CheckValueTypeClassesPass.cs @@ -0,0 +1,42 @@ +using System.Linq; +using CppSharp.AST; + +namespace CppSharp.Passes +{ + public class CheckValueTypeClassesPass : TranslationUnitPass + { + public CheckValueTypeClassesPass() + { + } + + public override bool VisitClassDecl(Class @class) + { + @class.Type = CheckClassIsStructible(@class, Driver) ? ClassType.ValueType : @class.Type; + return base.VisitClassDecl(@class); + } + + private bool CheckClassIsStructible(Class @class, Driver Driver) + { + if (@class.IsUnion || @class.Namespace.Templates.Any(tmp => tmp.Name.Equals(@class.Name))) + return false; + if (@class.IsInterface || @class.IsStatic || @class.IsAbstract) + return false; + if (@class.Declarations.Any(decl => decl.Access == AccessSpecifier.Protected)) + return false; + if (@class.Methods.Any(m => m.IsVirtual)) + return false; + if (@class.HasBaseClass && @class.BaseClass.IsRefType) + return false; + + var allTrUnits = Driver.ASTContext.TranslationUnits; + if (allTrUnits.Any(trUnit => trUnit.Classes.Any( + cls => cls.Bases.Any(clss => clss.IsClass && clss.Class == @class)))) + return false; + + if (@class.IsPOD || @class.IsValueType) + return true; + + return false; + } + } +} \ No newline at end of file diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs index 269386a702..27213e98f8 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -32,6 +32,7 @@ public override void Preprocess(Driver driver, ASTContext ctx) { driver.AddTranslationUnitPass(new GetterSetterToPropertyPass()); driver.AddTranslationUnitPass(new CheckMacroPass()); + driver.AddTranslationUnitPass(new CheckValueTypeClassesPass()); ctx.SetClassAsValueType("Bar"); ctx.SetClassAsValueType("Bar2"); ctx.IgnoreClassWithName("IgnoredType"); diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index c9e8b9b8bf..a0582bd2d0 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -799,3 +799,8 @@ class DLL_API ReturnsEmpty public: Empty getEmpty(); }; + +DLL_API class TestIsStructFreeClass { }; +DLL_API struct TestIsStructFreeStruct { }; +DLL_API struct TestIsStructInheritedStruct { }; +DLL_API struct TestIsStructInheritingStruct : public TestIsStructInheritedStruct { }; \ No newline at end of file From 766c52659b92fdbf6664d92c2a57937e28295c9b Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Tue, 28 Jul 2015 20:13:23 +0530 Subject: [PATCH 2/6] Done few changes. Brings more errors with it. --- src/Generator/Driver.cs | 1 + src/Generator/Passes/CheckValueTypeClassesPass.cs | 7 ++----- tests/Basic/Basic.cs | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index b820159812..252ad514e0 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -285,6 +285,7 @@ public void SetupPasses(ILibrary library) } TranslationUnitPasses.AddPass(new CheckVTableComponentsPass()); + TranslationUnitPasses.AddPass(new CheckValueTypeClassesPass()); if (Options.GenerateProperties) TranslationUnitPasses.AddPass(new GetterSetterToPropertyPass()); diff --git a/src/Generator/Passes/CheckValueTypeClassesPass.cs b/src/Generator/Passes/CheckValueTypeClassesPass.cs index 6b2067e864..fec91854dd 100644 --- a/src/Generator/Passes/CheckValueTypeClassesPass.cs +++ b/src/Generator/Passes/CheckValueTypeClassesPass.cs @@ -23,7 +23,7 @@ private bool CheckClassIsStructible(Class @class, Driver Driver) return false; if (@class.Declarations.Any(decl => decl.Access == AccessSpecifier.Protected)) return false; - if (@class.Methods.Any(m => m.IsVirtual)) + if (@class.IsDynamic) return false; if (@class.HasBaseClass && @class.BaseClass.IsRefType) return false; @@ -33,10 +33,7 @@ private bool CheckClassIsStructible(Class @class, Driver Driver) cls => cls.Bases.Any(clss => clss.IsClass && clss.Class == @class)))) return false; - if (@class.IsPOD || @class.IsValueType) - return true; - - return false; + return @class.IsPOD; } } } \ No newline at end of file diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs index 27213e98f8..269386a702 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -32,7 +32,6 @@ public override void Preprocess(Driver driver, ASTContext ctx) { driver.AddTranslationUnitPass(new GetterSetterToPropertyPass()); driver.AddTranslationUnitPass(new CheckMacroPass()); - driver.AddTranslationUnitPass(new CheckValueTypeClassesPass()); ctx.SetClassAsValueType("Bar"); ctx.SetClassAsValueType("Bar2"); ctx.IgnoreClassWithName("IgnoredType"); From 48e40fe59a140161cf0bc3fec49a09db4737f076 Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Sun, 9 Aug 2015 01:28:47 +0530 Subject: [PATCH 3/6] Fixed struct marshalling for all cases and added a macro CS_REF_TYPE. --- src/AST/Class.cs | 8 + src/Generator/Driver.cs | 1 - .../Generators/CSharp/CSharpTextTemplate.cs | 8 +- src/Generator/Passes/CheckMacrosPass.cs | 6 + .../Passes/CheckValueTypeClassesPass.cs | 2 +- tests/Basic/Basic.cs | 1 + tests/Basic/Basic.h~RF137be55.TMP | 792 ++++++++++++++++++ tests/CLITemp/CLITemp.cs | 2 + tests/STL/STL.cs | 3 + tests/STL/STL.h | 3 +- 10 files changed, 820 insertions(+), 6 deletions(-) create mode 100644 tests/Basic/Basic.h~RF137be55.TMP diff --git a/src/AST/Class.cs b/src/AST/Class.cs index e61296195f..34f013a854 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -113,6 +113,7 @@ public Class() IsUnion = false; IsOpaque = false; IsPOD = false; + IsForcedRefType = false; Type = ClassType.RefType; Layout = new ClassLayout(); } @@ -137,6 +138,13 @@ public Class(Class @class) HasNonTrivialCopyConstructor = @class.HasNonTrivialCopyConstructor; HasNonTrivialDestructor = @class.HasNonTrivialDestructor; IsStatic = @class.IsStatic; + IsForcedRefType = @class.IsForcedRefType; + } + + public bool IsForcedRefType + { + get; + set; } public bool HasBase diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 252ad514e0..b820159812 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -285,7 +285,6 @@ public void SetupPasses(ILibrary library) } TranslationUnitPasses.AddPass(new CheckVTableComponentsPass()); - TranslationUnitPasses.AddPass(new CheckValueTypeClassesPass()); if (Options.GenerateProperties) TranslationUnitPasses.AddPass(new GetterSetterToPropertyPass()); diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 0b52e3b95b..93327b3875 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2573,10 +2573,12 @@ private ParamMarshal GenerateFunctionParamMarshal(Parameter param, int paramInde var paramType = param.Type; Class @class; - if ( (paramType.GetFinalPointee() ?? paramType).Desugar().TryGetClass(out @class) - && @class.IsRefType) + if ( (paramType.GetFinalPointee() ?? paramType).Desugar().TryGetClass(out @class)) { - WriteLine("{0} = new {1}();", param.Name, paramType); + if(@class.IsRefType || @class.IsValueType) + WriteLine("{0} = new {1}();", param.Name, paramType);/* + else if(@class.IsRefType) + WriteLine("{0} = new {1}();", param.Name, paramType);*/ } } diff --git a/src/Generator/Passes/CheckMacrosPass.cs b/src/Generator/Passes/CheckMacrosPass.cs index 1946c30fd1..568f62db05 100644 --- a/src/Generator/Passes/CheckMacrosPass.cs +++ b/src/Generator/Passes/CheckMacrosPass.cs @@ -46,6 +46,10 @@ namespace CppSharp.Passes /// Used to flag a method as internal to an assembly. So, it is /// not accessible outside that assembly. /// + /// CS_REF_TYPE (classes and structs) + /// Used to flag a type as ref type. So, it is generated as a C# class + /// even when the CheckValueTypeClassesPass is enabled. + /// /// There isn't a standardized header provided by CppSharp so you will /// have to define these on your own. /// @@ -109,6 +113,8 @@ public override bool VisitClassDecl(Class @class) if (expansions.Any(e => e.Text == Prefix + "_VALUE_TYPE")) @class.Type = ClassType.ValueType; + else if (expansions.Any(e => e.Text == Prefix + "_REF_TYPE")) + @class.IsForcedRefType = true; // If the class is a forward declaration, then we process the macro expansions // of the complete class as if they were specified on the forward declaration. diff --git a/src/Generator/Passes/CheckValueTypeClassesPass.cs b/src/Generator/Passes/CheckValueTypeClassesPass.cs index fec91854dd..3c696d23a4 100644 --- a/src/Generator/Passes/CheckValueTypeClassesPass.cs +++ b/src/Generator/Passes/CheckValueTypeClassesPass.cs @@ -33,7 +33,7 @@ private bool CheckClassIsStructible(Class @class, Driver Driver) cls => cls.Bases.Any(clss => clss.IsClass && clss.Class == @class)))) return false; - return @class.IsPOD; + return @class.IsPOD && !@class.IsForcedRefType; } } } \ No newline at end of file diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs index 269386a702..27213e98f8 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -32,6 +32,7 @@ public override void Preprocess(Driver driver, ASTContext ctx) { driver.AddTranslationUnitPass(new GetterSetterToPropertyPass()); driver.AddTranslationUnitPass(new CheckMacroPass()); + driver.AddTranslationUnitPass(new CheckValueTypeClassesPass()); ctx.SetClassAsValueType("Bar"); ctx.SetClassAsValueType("Bar2"); ctx.IgnoreClassWithName("IgnoredType"); diff --git a/tests/Basic/Basic.h~RF137be55.TMP b/tests/Basic/Basic.h~RF137be55.TMP new file mode 100644 index 0000000000..3261794403 --- /dev/null +++ b/tests/Basic/Basic.h~RF137be55.TMP @@ -0,0 +1,792 @@ +#include "../Tests.h" +#include "AnotherUnit.h" + +#ifdef _WIN32 +#include +#endif +#include + +class DLL_API IgnoredType +{ + class IgnoredNested + { + private: + int i; + }; +private: + int i; +}; + +class DLL_API Foo +{ +private: + enum Private + { + Value1, + Value2 + }; +public: + + Foo(); + Foo(Private p); + int A; + float B; + IgnoredType ignoredType; + int fixedArray[3]; + void* ptr; + static const int unsafe = 10; + + const char* GetANSI(); + // TODO: VC++ does not support char16 + // char16 chr16; + + // Not properly handled yet - ignore + float nested_array[2][2]; + // Primitive pointer types + const int* SomePointer; + const int** SomePointerPointer; + + typedef Foo* FooPtr; + + void TakesTypedefedPtr(FooPtr date); + + bool operator ==(const Foo& other) const; +}; + +struct DLL_API Bar +{ + enum Item + { + Item1, + Item2 + }; + + Bar(); + Item RetItem1(); + int A; + float B; + + Bar* returnPointerToValueType(); + + bool operator ==(const Bar& other) const; +}; + +class DLL_API Foo2 : public Foo +{ + struct Copy { + Foo A; + }* copy; + +public: + + Foo2(); + + int C; + + Foo2 operator<<(signed int i); + Foo2 operator<<(signed long l); + Bar valueTypeField; + char testCharMarshalling(char c); + void testKeywordParam(void* where); +}; + +DLL_API Bar::Item operator |(Bar::Item left, Bar::Item right); + +struct DLL_API Bar2 : public Bar +{ + // Conversion operators + + struct DLL_API Nested + { + operator int() const; + }; + + operator int() const; + operator Foo2(); + Foo2 needFixedInstance() const; + + typedef void *Bar2::*FunctionPointerResolvedAsVoidStar; + operator FunctionPointerResolvedAsVoidStar() const { return 0; } + + int C; + Bar* pointerToStruct; + int* pointerToPrimitive; + Foo2* pointerToClass; + Bar valueStruct; +}; + +enum Enum +{ + A = 0, B = 2, C = 5, + //D = 0x80000000, + E = 0x1, + F = -9 +}; + +class DLL_API Hello +{ + union NestedPrivate { + int i; + float f; + }; + +public: + union NestedPublic { + int j; + float g; + long l; + }; + + Hello (); + Hello(const Hello& hello); + + void PrintHello(const char* s); + bool test1(int i, float f); + int add(int a, int b); + + int AddFoo(Foo); + int AddFooRef(Foo&); + int AddFooPtr(Foo*); + int AddFooPtrRef(Foo*&); + Foo RetFoo(int a, float b); + + int AddFoo2(Foo2); + + int AddBar(Bar); + int AddBar2(Bar2); + + int RetEnum(Enum); + Hello* RetNull(); + + bool TestPrimitiveOut(CS_OUT float* f); + bool TestPrimitiveOutRef(CS_OUT float& f); + + bool TestPrimitiveInOut(CS_IN_OUT int* i); + bool TestPrimitiveInOutRef(CS_IN_OUT int& i); + + void EnumOut(int value, CS_OUT Enum* e); + void EnumOutRef(int value, CS_OUT Enum& e); + + void EnumInOut(CS_IN_OUT Enum* e); + void EnumInOutRef(CS_IN_OUT Enum& e); + + void StringOut(CS_OUT const char** str); + void StringOutRef(CS_OUT const char*& str); + void StringInOut(CS_IN_OUT const char** str); + void StringInOutRef(CS_IN_OUT const char*& str); +}; + +class DLL_API AbstractFoo +{ +public: + virtual int pureFunction(int i) = 0; + virtual int pureFunction1() = 0; + virtual int pureFunction2() = 0; +}; + +class DLL_API ImplementsAbstractFoo : public AbstractFoo +{ +public: + virtual int pureFunction(int i); + virtual int pureFunction1(); + virtual int pureFunction2(); +}; + +class DLL_API ReturnsAbstractFoo +{ +public: + ReturnsAbstractFoo(); + const AbstractFoo& getFoo(); + +private: + ImplementsAbstractFoo i; +}; + +int DLL_API unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int)); + +DLL_API Bar indirectReturn(); + +// Tests CheckVirtualOverrideReturnCovariance +struct Exception; +typedef Exception Ex1; + +struct DerivedException; +typedef DerivedException Ex2; + +struct DLL_API Exception +{ + virtual Ex1* clone() = 0; +}; + +struct DLL_API DerivedException : public Exception +{ + virtual Ex2* clone() override { return 0; } +}; + +// Tests for ambiguous call to native functions with default parameters +struct DLL_API DefaultParameters +{ + void Foo(int a, int b = 0); + void Foo(int a); + + void Bar() const; + void Bar(); +}; + +// The Curiously Recurring Template Pattern (CRTP) +template +class Base +{ + // methods within Base can use template to access members of Derived + Derived* create() { return new Derived(); } +}; + +class Derived : public Base +{ +}; + +// Tests the MoveFunctionToClassPass +class DLL_API basic +{ + +}; + +DLL_API int test(basic& s); + +// Tests the MoveOperatorToClassPass +struct DLL_API TestMoveOperatorToClass +{ + TestMoveOperatorToClass(); + int A; + int B; +}; + +TestMoveOperatorToClass::TestMoveOperatorToClass() {} + +DLL_API int operator *(TestMoveOperatorToClass klass, int b) +{ + return klass.A * b; +} + +DLL_API TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b) +{ + TestMoveOperatorToClass nb; + nb.A = -b.A; + nb.B = -b.B; + return nb; +} + +DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1, + const TestMoveOperatorToClass& b2) +{ + TestMoveOperatorToClass b; + b.A = b1.A + b2.A; + b.B = b1.B + b2.B; + return b; +} + +// Not a valid operator overload for Foo2 in managed code - comparison operators need to return bool. +DLL_API int operator==(const Foo2& a, const Foo2& b) +{ + return 0; +} + +// Tests delegates +typedef int (*DelegateInGlobalNamespace)(int); +typedef int (STDCALL *DelegateStdCall)(int); +typedef int (CDECL *DelegateCDecl)(int n); + +struct DLL_API TestDelegates +{ + typedef int (*DelegateInClass)(int); + typedef int(TestDelegates::*MemberDelegate)(int); + + TestDelegates(); + static int Double(int N) { return N * 2; } + int Triple(int N) { return N * 3; } + + int StdCall(DelegateStdCall del) { return del(1); } + int CDecl(DelegateCDecl del) { return del(1); } + void MarshalUnattributedDelegate(DelegateInGlobalNamespace del); + + int MarshalAnonymousDelegate(int (*del)(int n)); + void MarshalAnonymousDelegate2(int (*del)(int n)); + void MarshalAnonymousDelegate3(float (*del)(float n)); + int (*MarshalAnonymousDelegate4())(int n); + + void MarshalDelegateInAnotherUnit(DelegateInAnotherUnit del); + + DelegateInClass A; + DelegateInGlobalNamespace B; + // As long as we can't marshal them make sure they're ignored + MemberDelegate C; +}; + +TestDelegates::TestDelegates() : A(Double), B(Double), C(&TestDelegates::Triple) +{ +} + +namespace DelegateNamespace +{ + namespace Nested + { + void DLL_API f1(void (*)()); + } + + void DLL_API f2(void (*)()); +} + +// Tests memory leaks in constructors +// C#: Marshal.FreeHGlobal(arg0); +struct DLL_API TestMemoryLeaks +{ + TestMemoryLeaks(const char* name) {} +}; + +// Tests that finalizers are generated +/* CLI: ~TestFinalizers() */ +struct DLL_API TestFinalizers +{ +}; + +// Tests static classes +struct DLL_API TestStaticClass +{ + static int Add(int a, int b); + + static int GetOneTwoThree() { return 123; } + +protected: + + static int _Mult(int a, int b) { return a * b; } + + static int GetFourFiveSix() { return 456; } + +private: + TestStaticClass(); +}; + +int TestStaticClass::Add(int a, int b) { return a + b; } + +struct DLL_API TestStaticClassDerived : TestStaticClass +{ + static int Foo(); + +private: + TestStaticClassDerived(); +}; + +int TestStaticClassDerived::Foo() { return 0; } + +class DLL_API TestNotStaticClass +{ +public: + static TestNotStaticClass StaticFunction(); +private: + TestNotStaticClass(); +}; + +TestNotStaticClass::TestNotStaticClass() +{ +} + +TestNotStaticClass TestNotStaticClass::StaticFunction() +{ + return TestNotStaticClass(); +} + +class HasIgnoredField +{ + Base fieldOfIgnoredType; +}; + +template +class DependentTypeWithNestedIndependent +{ + union + { + int i; + long l; + }; +}; + +class DLL_API TestCopyConstructorRef +{ +public: + TestCopyConstructorRef(); + TestCopyConstructorRef(const TestCopyConstructorRef& other); + int A; + float B; +}; + +TestCopyConstructorRef::TestCopyConstructorRef() +{ +} + +TestCopyConstructorRef::TestCopyConstructorRef(const TestCopyConstructorRef& other) +{ + A = other.A; + B = other.B; +} + +template +struct EmptyNamedNestedEnum +{ + enum { Value = 10 }; +}; + +typedef unsigned long foo_t; +typedef struct DLL_API SomeStruct +{ + SomeStruct(); + foo_t p; +} SomeStruct; + +SomeStruct::SomeStruct() : p(1) {} + +class DLL_API SomeClassExtendingTheStruct : public SomeStruct +{ +}; + +namespace SomeNamespace +{ + class DLL_API AbstractClass + { + public: + virtual void AbstractMethod() = 0; + }; +} + +// Test operator overloads +class DLL_API ClassWithOverloadedOperators +{ +public: + ClassWithOverloadedOperators(); + + operator char(); + operator int(); + operator short(); + + virtual bool operator<(const ClassWithOverloadedOperators &other) const; +}; + +ClassWithOverloadedOperators::ClassWithOverloadedOperators() {} +ClassWithOverloadedOperators::operator char() { return 1; } +ClassWithOverloadedOperators::operator int() { return 2; } +ClassWithOverloadedOperators::operator short() { return 3; } +bool ClassWithOverloadedOperators:: + operator<(const ClassWithOverloadedOperators &other) const { + return true; +} + +// Tests global static function generation +DLL_API int Function() +{ + return 5; +} + +// Tests properties +struct DLL_API TestProperties +{ + TestProperties(); + int Field; + + int getFieldValue(); + void setFieldValue(int Value); +}; + +TestProperties::TestProperties() : Field(0) {} +int TestProperties::getFieldValue() { return Field; } +void TestProperties::setFieldValue(int Value) { Field = Value; } + +class DLL_API TestIndexedProperties +{ + foo_t p; + TestProperties f; +public: + TestIndexedProperties(); + // Should lead to a read/write indexer with return type uint + foo_t& operator[](int i); + // Should lead to a read/write indexer with return type uint + foo_t* operator[](float f); + // Should lead to a read-only indexer with return type uint + foo_t operator[](const char* name); + // Should lead to a read-only indexer with return type uint* + const foo_t& operator[](double d); + // Should lead to a read/write indexer with return type TestProperties + TestProperties* operator[](unsigned char b); + // Should lead to a read-only indexer with return type TestProperties + const TestProperties& operator[](short b); + // Should lead to a read-only indexer with argument type TestProperties + foo_t operator[](TestProperties b); +}; + +TestIndexedProperties::TestIndexedProperties() : p(1), f() {} +foo_t& TestIndexedProperties::operator[](int i) { return p; } +foo_t TestIndexedProperties::operator[](const char* name) { return p; } +foo_t* TestIndexedProperties::operator[](float f) { return &p; } +const foo_t& TestIndexedProperties::operator[](double f) { return p; } +TestProperties* TestIndexedProperties::operator[](unsigned char b) { return &f; } +const TestProperties& TestIndexedProperties::operator[](short b) { return f; } +foo_t TestIndexedProperties::operator[](TestProperties b) { return p; } + +struct DLL_API TestIndexedPropertiesInValueType +{ +public: + int operator[](int i); +}; + +int TestIndexedPropertiesInValueType::operator[](int i) { return i; } + +// Tests variables +struct DLL_API TestVariables +{ + static int VALUE; + void SetValue(int value = VALUE); +}; + +int TestVariables::VALUE; +void TestVariables::SetValue(int value) { VALUE = value; } + +typedef const wchar_t * LPCWSTR; +struct DLL_API TestWideStrings +{ + LPCWSTR GetWidePointer(); +}; + +LPCWSTR TestWideStrings::GetWidePointer() { return L"Hello"; } + +enum struct MyEnum { A, B, C }; + +class DLL_API TestArraysPointers +{ +public: + TestArraysPointers(MyEnum *values, int count); + + MyEnum Value; +}; + +TestArraysPointers::TestArraysPointers(MyEnum *values, int count) +{ + if (values && count) Value = values[0]; +} + +struct DLL_API TestGetterSetterToProperties +{ + int getWidth(); + int getHeight(); +}; + +int TestGetterSetterToProperties::getWidth() { return 640; } +int TestGetterSetterToProperties::getHeight() { return 480; } + +// Tests conversion operators of classes +class DLL_API ClassA +{ +public: + ClassA(int value) { Value = value; } + int Value; +}; +class DLL_API ClassB +{ +public: + // conversion from ClassA (constructor): + ClassB(const ClassA& x) { Value = x.Value; } + int Value; + // conversion from ClassA (assignment): + //ClassB& operator= (const ClassA& x) { return *this; } + // conversion to ClassA (type-cast operator) + //operator ClassA() { return ClassA(); } +}; +class DLL_API ClassC +{ +public: + // This should NOT lead to a conversion + ClassC(const ClassA* x) { Value = x->Value; } + // This should lead to an explicit conversion + explicit ClassC(const ClassB& x) { Value = x.Value; } + int Value; +}; + +// Test decltype +int Expr = 0; +DLL_API decltype(Expr) TestDecltype() +{ + return Expr; +} + +DLL_API void TestNullPtrType(decltype(nullptr)) +{ +} + +DLL_API decltype(nullptr) TestNullPtrTypeRet() +{ + return nullptr; +} + +// Tests dependent name types +template struct DependentType +{ + DependentType(typename T::Dependent* t) { } +}; + +class PureDtor +{ +public: + virtual ~PureDtor() = 0; +}; + +DLL_API void va_listFunction(va_list v); + +struct DLL_API TestNestedTypes +{ +public: + struct + { + struct + { + }; + }; + struct + { + struct + { + }; + }; + struct + { + struct + { + }; + }; + struct + { + struct + { + }; + }; + + union as_types + { + int as_int; + struct uchars + { + unsigned char blue, green, red, alpha; + } as_uchar; + }; +}; + +class DLL_API HasStdString +{ + // test if these are ignored with the C# back-end +public: + std::string testStdString(std::string s); + std::string s; +}; + +class DLL_API InternalCtorAmbiguity +{ +public: + InternalCtorAmbiguity(void* param); +}; + +class DLL_API InvokesInternalCtorAmbiguity +{ +public: + InvokesInternalCtorAmbiguity(); + InternalCtorAmbiguity* InvokeInternalCtor(); +private: + InternalCtorAmbiguity* ptr; +}; + +class DLL_API HasFriend +{ +public: + HasFriend(int m); + DLL_API friend inline const HasFriend operator+(const HasFriend& f1, const HasFriend& f2); + DLL_API friend inline const HasFriend operator-(const HasFriend& f1, const HasFriend& f2); + int getM(); +private: + int m; +}; + +template class FriendTemplate +{ + template + friend FriendTemplate func(const FriendTemplate&); + + friend FriendTemplate; + friend class FriendTemplate; + + template + friend class FriendTemplate; +}; + +class DLL_API DifferentConstOverloads +{ +public: + bool operator ==(const DifferentConstOverloads& other); + bool operator ==(int number) const; +}; + +class TestNamingAnonymousTypesInUnion +{ +public: + union { + struct { + } argb; + struct { + } ahsv; + struct { + } acmyk; + } ct; +}; + +#define CS_API +class CS_API ClassPassTry +{ +public: + int n; + char c; +}; + +void funcTry(CS_OUT ClassPassTry* classTry) { } +void funcTry2(CS_OUT ClassPassTry classTry) { } + +struct DLL_API BaseClassWithOperator +{ + int n; +public: + BaseClassWithOperator(int m) + { + n = m; + } + BaseClassWithOperator operator+(int m) + { + BaseClassWithOperator temp(n); + temp.n += m; + return temp; + } + int getN() + { + return n; + } +}; + +BaseClassWithOperator funcCheckOperatorForBaseClass() +{ + BaseClassWithOperator a(5); + return (a + 6); +} + +class DLL_API DerivedClassForOperator : public BaseClassWithOperator +{ +public: + DerivedClassForOperator(int n) : BaseClassWithOperator(n) { } +}; + +BaseClassWithOperator funcCheckOperatorForDerivedClass() +{ + DerivedClassForOperator a(5); + return (a + 6); +} \ No newline at end of file diff --git a/tests/CLITemp/CLITemp.cs b/tests/CLITemp/CLITemp.cs index 71a42f1758..f92266a95e 100644 --- a/tests/CLITemp/CLITemp.cs +++ b/tests/CLITemp/CLITemp.cs @@ -1,5 +1,6 @@ using CppSharp.AST; using CppSharp.Generators; +using CppSharp.Passes; using CppSharp.Utils; namespace CppSharp.Tests @@ -20,6 +21,7 @@ public override void Setup(Driver driver) public override void Preprocess(Driver driver, ASTContext ctx) { + driver.TranslationUnitPasses.AddPass(new CheckValueTypeClassesPass()); } public static void Main(string[] args) diff --git a/tests/STL/STL.cs b/tests/STL/STL.cs index d87e2d70b8..07858f59ad 100644 --- a/tests/STL/STL.cs +++ b/tests/STL/STL.cs @@ -1,5 +1,6 @@ using CppSharp.AST; using CppSharp.Generators; +using CppSharp.Passes; using CppSharp.Utils; namespace CppSharp.Tests @@ -14,6 +15,8 @@ public STL(GeneratorKind kind) public override void Preprocess(Driver driver, ASTContext ctx) { ctx.SetClassAsValueType("IntWrapperValueType"); + driver.TranslationUnitPasses.AddPass(new CheckMacroPass()); + driver.TranslationUnitPasses.AddPass(new CheckValueTypeClassesPass()); } public static void Main(string[] args) diff --git a/tests/STL/STL.h b/tests/STL/STL.h index 3220da3a75..8a63e515ee 100644 --- a/tests/STL/STL.h +++ b/tests/STL/STL.h @@ -2,7 +2,8 @@ #include #include -struct DLL_API IntWrapper +#define CS_REF_TYPE +struct DLL_API CS_REF_TYPE IntWrapper { int Value; }; From 4855cfd70e8d573ea6de8003c7e0ec5423229af7 Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Sun, 9 Aug 2015 01:30:21 +0530 Subject: [PATCH 4/6] Made gitignore to ignore temp files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 046bc62068..42b36eacdc 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ src/generator/generator *.csproj *.ilk *.manifest +*.tmp /build/vs2012 /build/vs2013 /build/gmake From 21938df56cffacc459185282660c79470916e29c Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Sun, 9 Aug 2015 01:31:34 +0530 Subject: [PATCH 5/6] Removed temp file. And checked the new gitignore. --- tests/Basic/Basic.h~RF137be55.TMP | 792 ------------------------------ 1 file changed, 792 deletions(-) delete mode 100644 tests/Basic/Basic.h~RF137be55.TMP diff --git a/tests/Basic/Basic.h~RF137be55.TMP b/tests/Basic/Basic.h~RF137be55.TMP deleted file mode 100644 index 3261794403..0000000000 --- a/tests/Basic/Basic.h~RF137be55.TMP +++ /dev/null @@ -1,792 +0,0 @@ -#include "../Tests.h" -#include "AnotherUnit.h" - -#ifdef _WIN32 -#include -#endif -#include - -class DLL_API IgnoredType -{ - class IgnoredNested - { - private: - int i; - }; -private: - int i; -}; - -class DLL_API Foo -{ -private: - enum Private - { - Value1, - Value2 - }; -public: - - Foo(); - Foo(Private p); - int A; - float B; - IgnoredType ignoredType; - int fixedArray[3]; - void* ptr; - static const int unsafe = 10; - - const char* GetANSI(); - // TODO: VC++ does not support char16 - // char16 chr16; - - // Not properly handled yet - ignore - float nested_array[2][2]; - // Primitive pointer types - const int* SomePointer; - const int** SomePointerPointer; - - typedef Foo* FooPtr; - - void TakesTypedefedPtr(FooPtr date); - - bool operator ==(const Foo& other) const; -}; - -struct DLL_API Bar -{ - enum Item - { - Item1, - Item2 - }; - - Bar(); - Item RetItem1(); - int A; - float B; - - Bar* returnPointerToValueType(); - - bool operator ==(const Bar& other) const; -}; - -class DLL_API Foo2 : public Foo -{ - struct Copy { - Foo A; - }* copy; - -public: - - Foo2(); - - int C; - - Foo2 operator<<(signed int i); - Foo2 operator<<(signed long l); - Bar valueTypeField; - char testCharMarshalling(char c); - void testKeywordParam(void* where); -}; - -DLL_API Bar::Item operator |(Bar::Item left, Bar::Item right); - -struct DLL_API Bar2 : public Bar -{ - // Conversion operators - - struct DLL_API Nested - { - operator int() const; - }; - - operator int() const; - operator Foo2(); - Foo2 needFixedInstance() const; - - typedef void *Bar2::*FunctionPointerResolvedAsVoidStar; - operator FunctionPointerResolvedAsVoidStar() const { return 0; } - - int C; - Bar* pointerToStruct; - int* pointerToPrimitive; - Foo2* pointerToClass; - Bar valueStruct; -}; - -enum Enum -{ - A = 0, B = 2, C = 5, - //D = 0x80000000, - E = 0x1, - F = -9 -}; - -class DLL_API Hello -{ - union NestedPrivate { - int i; - float f; - }; - -public: - union NestedPublic { - int j; - float g; - long l; - }; - - Hello (); - Hello(const Hello& hello); - - void PrintHello(const char* s); - bool test1(int i, float f); - int add(int a, int b); - - int AddFoo(Foo); - int AddFooRef(Foo&); - int AddFooPtr(Foo*); - int AddFooPtrRef(Foo*&); - Foo RetFoo(int a, float b); - - int AddFoo2(Foo2); - - int AddBar(Bar); - int AddBar2(Bar2); - - int RetEnum(Enum); - Hello* RetNull(); - - bool TestPrimitiveOut(CS_OUT float* f); - bool TestPrimitiveOutRef(CS_OUT float& f); - - bool TestPrimitiveInOut(CS_IN_OUT int* i); - bool TestPrimitiveInOutRef(CS_IN_OUT int& i); - - void EnumOut(int value, CS_OUT Enum* e); - void EnumOutRef(int value, CS_OUT Enum& e); - - void EnumInOut(CS_IN_OUT Enum* e); - void EnumInOutRef(CS_IN_OUT Enum& e); - - void StringOut(CS_OUT const char** str); - void StringOutRef(CS_OUT const char*& str); - void StringInOut(CS_IN_OUT const char** str); - void StringInOutRef(CS_IN_OUT const char*& str); -}; - -class DLL_API AbstractFoo -{ -public: - virtual int pureFunction(int i) = 0; - virtual int pureFunction1() = 0; - virtual int pureFunction2() = 0; -}; - -class DLL_API ImplementsAbstractFoo : public AbstractFoo -{ -public: - virtual int pureFunction(int i); - virtual int pureFunction1(); - virtual int pureFunction2(); -}; - -class DLL_API ReturnsAbstractFoo -{ -public: - ReturnsAbstractFoo(); - const AbstractFoo& getFoo(); - -private: - ImplementsAbstractFoo i; -}; - -int DLL_API unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int)); - -DLL_API Bar indirectReturn(); - -// Tests CheckVirtualOverrideReturnCovariance -struct Exception; -typedef Exception Ex1; - -struct DerivedException; -typedef DerivedException Ex2; - -struct DLL_API Exception -{ - virtual Ex1* clone() = 0; -}; - -struct DLL_API DerivedException : public Exception -{ - virtual Ex2* clone() override { return 0; } -}; - -// Tests for ambiguous call to native functions with default parameters -struct DLL_API DefaultParameters -{ - void Foo(int a, int b = 0); - void Foo(int a); - - void Bar() const; - void Bar(); -}; - -// The Curiously Recurring Template Pattern (CRTP) -template -class Base -{ - // methods within Base can use template to access members of Derived - Derived* create() { return new Derived(); } -}; - -class Derived : public Base -{ -}; - -// Tests the MoveFunctionToClassPass -class DLL_API basic -{ - -}; - -DLL_API int test(basic& s); - -// Tests the MoveOperatorToClassPass -struct DLL_API TestMoveOperatorToClass -{ - TestMoveOperatorToClass(); - int A; - int B; -}; - -TestMoveOperatorToClass::TestMoveOperatorToClass() {} - -DLL_API int operator *(TestMoveOperatorToClass klass, int b) -{ - return klass.A * b; -} - -DLL_API TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b) -{ - TestMoveOperatorToClass nb; - nb.A = -b.A; - nb.B = -b.B; - return nb; -} - -DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1, - const TestMoveOperatorToClass& b2) -{ - TestMoveOperatorToClass b; - b.A = b1.A + b2.A; - b.B = b1.B + b2.B; - return b; -} - -// Not a valid operator overload for Foo2 in managed code - comparison operators need to return bool. -DLL_API int operator==(const Foo2& a, const Foo2& b) -{ - return 0; -} - -// Tests delegates -typedef int (*DelegateInGlobalNamespace)(int); -typedef int (STDCALL *DelegateStdCall)(int); -typedef int (CDECL *DelegateCDecl)(int n); - -struct DLL_API TestDelegates -{ - typedef int (*DelegateInClass)(int); - typedef int(TestDelegates::*MemberDelegate)(int); - - TestDelegates(); - static int Double(int N) { return N * 2; } - int Triple(int N) { return N * 3; } - - int StdCall(DelegateStdCall del) { return del(1); } - int CDecl(DelegateCDecl del) { return del(1); } - void MarshalUnattributedDelegate(DelegateInGlobalNamespace del); - - int MarshalAnonymousDelegate(int (*del)(int n)); - void MarshalAnonymousDelegate2(int (*del)(int n)); - void MarshalAnonymousDelegate3(float (*del)(float n)); - int (*MarshalAnonymousDelegate4())(int n); - - void MarshalDelegateInAnotherUnit(DelegateInAnotherUnit del); - - DelegateInClass A; - DelegateInGlobalNamespace B; - // As long as we can't marshal them make sure they're ignored - MemberDelegate C; -}; - -TestDelegates::TestDelegates() : A(Double), B(Double), C(&TestDelegates::Triple) -{ -} - -namespace DelegateNamespace -{ - namespace Nested - { - void DLL_API f1(void (*)()); - } - - void DLL_API f2(void (*)()); -} - -// Tests memory leaks in constructors -// C#: Marshal.FreeHGlobal(arg0); -struct DLL_API TestMemoryLeaks -{ - TestMemoryLeaks(const char* name) {} -}; - -// Tests that finalizers are generated -/* CLI: ~TestFinalizers() */ -struct DLL_API TestFinalizers -{ -}; - -// Tests static classes -struct DLL_API TestStaticClass -{ - static int Add(int a, int b); - - static int GetOneTwoThree() { return 123; } - -protected: - - static int _Mult(int a, int b) { return a * b; } - - static int GetFourFiveSix() { return 456; } - -private: - TestStaticClass(); -}; - -int TestStaticClass::Add(int a, int b) { return a + b; } - -struct DLL_API TestStaticClassDerived : TestStaticClass -{ - static int Foo(); - -private: - TestStaticClassDerived(); -}; - -int TestStaticClassDerived::Foo() { return 0; } - -class DLL_API TestNotStaticClass -{ -public: - static TestNotStaticClass StaticFunction(); -private: - TestNotStaticClass(); -}; - -TestNotStaticClass::TestNotStaticClass() -{ -} - -TestNotStaticClass TestNotStaticClass::StaticFunction() -{ - return TestNotStaticClass(); -} - -class HasIgnoredField -{ - Base fieldOfIgnoredType; -}; - -template -class DependentTypeWithNestedIndependent -{ - union - { - int i; - long l; - }; -}; - -class DLL_API TestCopyConstructorRef -{ -public: - TestCopyConstructorRef(); - TestCopyConstructorRef(const TestCopyConstructorRef& other); - int A; - float B; -}; - -TestCopyConstructorRef::TestCopyConstructorRef() -{ -} - -TestCopyConstructorRef::TestCopyConstructorRef(const TestCopyConstructorRef& other) -{ - A = other.A; - B = other.B; -} - -template -struct EmptyNamedNestedEnum -{ - enum { Value = 10 }; -}; - -typedef unsigned long foo_t; -typedef struct DLL_API SomeStruct -{ - SomeStruct(); - foo_t p; -} SomeStruct; - -SomeStruct::SomeStruct() : p(1) {} - -class DLL_API SomeClassExtendingTheStruct : public SomeStruct -{ -}; - -namespace SomeNamespace -{ - class DLL_API AbstractClass - { - public: - virtual void AbstractMethod() = 0; - }; -} - -// Test operator overloads -class DLL_API ClassWithOverloadedOperators -{ -public: - ClassWithOverloadedOperators(); - - operator char(); - operator int(); - operator short(); - - virtual bool operator<(const ClassWithOverloadedOperators &other) const; -}; - -ClassWithOverloadedOperators::ClassWithOverloadedOperators() {} -ClassWithOverloadedOperators::operator char() { return 1; } -ClassWithOverloadedOperators::operator int() { return 2; } -ClassWithOverloadedOperators::operator short() { return 3; } -bool ClassWithOverloadedOperators:: - operator<(const ClassWithOverloadedOperators &other) const { - return true; -} - -// Tests global static function generation -DLL_API int Function() -{ - return 5; -} - -// Tests properties -struct DLL_API TestProperties -{ - TestProperties(); - int Field; - - int getFieldValue(); - void setFieldValue(int Value); -}; - -TestProperties::TestProperties() : Field(0) {} -int TestProperties::getFieldValue() { return Field; } -void TestProperties::setFieldValue(int Value) { Field = Value; } - -class DLL_API TestIndexedProperties -{ - foo_t p; - TestProperties f; -public: - TestIndexedProperties(); - // Should lead to a read/write indexer with return type uint - foo_t& operator[](int i); - // Should lead to a read/write indexer with return type uint - foo_t* operator[](float f); - // Should lead to a read-only indexer with return type uint - foo_t operator[](const char* name); - // Should lead to a read-only indexer with return type uint* - const foo_t& operator[](double d); - // Should lead to a read/write indexer with return type TestProperties - TestProperties* operator[](unsigned char b); - // Should lead to a read-only indexer with return type TestProperties - const TestProperties& operator[](short b); - // Should lead to a read-only indexer with argument type TestProperties - foo_t operator[](TestProperties b); -}; - -TestIndexedProperties::TestIndexedProperties() : p(1), f() {} -foo_t& TestIndexedProperties::operator[](int i) { return p; } -foo_t TestIndexedProperties::operator[](const char* name) { return p; } -foo_t* TestIndexedProperties::operator[](float f) { return &p; } -const foo_t& TestIndexedProperties::operator[](double f) { return p; } -TestProperties* TestIndexedProperties::operator[](unsigned char b) { return &f; } -const TestProperties& TestIndexedProperties::operator[](short b) { return f; } -foo_t TestIndexedProperties::operator[](TestProperties b) { return p; } - -struct DLL_API TestIndexedPropertiesInValueType -{ -public: - int operator[](int i); -}; - -int TestIndexedPropertiesInValueType::operator[](int i) { return i; } - -// Tests variables -struct DLL_API TestVariables -{ - static int VALUE; - void SetValue(int value = VALUE); -}; - -int TestVariables::VALUE; -void TestVariables::SetValue(int value) { VALUE = value; } - -typedef const wchar_t * LPCWSTR; -struct DLL_API TestWideStrings -{ - LPCWSTR GetWidePointer(); -}; - -LPCWSTR TestWideStrings::GetWidePointer() { return L"Hello"; } - -enum struct MyEnum { A, B, C }; - -class DLL_API TestArraysPointers -{ -public: - TestArraysPointers(MyEnum *values, int count); - - MyEnum Value; -}; - -TestArraysPointers::TestArraysPointers(MyEnum *values, int count) -{ - if (values && count) Value = values[0]; -} - -struct DLL_API TestGetterSetterToProperties -{ - int getWidth(); - int getHeight(); -}; - -int TestGetterSetterToProperties::getWidth() { return 640; } -int TestGetterSetterToProperties::getHeight() { return 480; } - -// Tests conversion operators of classes -class DLL_API ClassA -{ -public: - ClassA(int value) { Value = value; } - int Value; -}; -class DLL_API ClassB -{ -public: - // conversion from ClassA (constructor): - ClassB(const ClassA& x) { Value = x.Value; } - int Value; - // conversion from ClassA (assignment): - //ClassB& operator= (const ClassA& x) { return *this; } - // conversion to ClassA (type-cast operator) - //operator ClassA() { return ClassA(); } -}; -class DLL_API ClassC -{ -public: - // This should NOT lead to a conversion - ClassC(const ClassA* x) { Value = x->Value; } - // This should lead to an explicit conversion - explicit ClassC(const ClassB& x) { Value = x.Value; } - int Value; -}; - -// Test decltype -int Expr = 0; -DLL_API decltype(Expr) TestDecltype() -{ - return Expr; -} - -DLL_API void TestNullPtrType(decltype(nullptr)) -{ -} - -DLL_API decltype(nullptr) TestNullPtrTypeRet() -{ - return nullptr; -} - -// Tests dependent name types -template struct DependentType -{ - DependentType(typename T::Dependent* t) { } -}; - -class PureDtor -{ -public: - virtual ~PureDtor() = 0; -}; - -DLL_API void va_listFunction(va_list v); - -struct DLL_API TestNestedTypes -{ -public: - struct - { - struct - { - }; - }; - struct - { - struct - { - }; - }; - struct - { - struct - { - }; - }; - struct - { - struct - { - }; - }; - - union as_types - { - int as_int; - struct uchars - { - unsigned char blue, green, red, alpha; - } as_uchar; - }; -}; - -class DLL_API HasStdString -{ - // test if these are ignored with the C# back-end -public: - std::string testStdString(std::string s); - std::string s; -}; - -class DLL_API InternalCtorAmbiguity -{ -public: - InternalCtorAmbiguity(void* param); -}; - -class DLL_API InvokesInternalCtorAmbiguity -{ -public: - InvokesInternalCtorAmbiguity(); - InternalCtorAmbiguity* InvokeInternalCtor(); -private: - InternalCtorAmbiguity* ptr; -}; - -class DLL_API HasFriend -{ -public: - HasFriend(int m); - DLL_API friend inline const HasFriend operator+(const HasFriend& f1, const HasFriend& f2); - DLL_API friend inline const HasFriend operator-(const HasFriend& f1, const HasFriend& f2); - int getM(); -private: - int m; -}; - -template class FriendTemplate -{ - template - friend FriendTemplate func(const FriendTemplate&); - - friend FriendTemplate; - friend class FriendTemplate; - - template - friend class FriendTemplate; -}; - -class DLL_API DifferentConstOverloads -{ -public: - bool operator ==(const DifferentConstOverloads& other); - bool operator ==(int number) const; -}; - -class TestNamingAnonymousTypesInUnion -{ -public: - union { - struct { - } argb; - struct { - } ahsv; - struct { - } acmyk; - } ct; -}; - -#define CS_API -class CS_API ClassPassTry -{ -public: - int n; - char c; -}; - -void funcTry(CS_OUT ClassPassTry* classTry) { } -void funcTry2(CS_OUT ClassPassTry classTry) { } - -struct DLL_API BaseClassWithOperator -{ - int n; -public: - BaseClassWithOperator(int m) - { - n = m; - } - BaseClassWithOperator operator+(int m) - { - BaseClassWithOperator temp(n); - temp.n += m; - return temp; - } - int getN() - { - return n; - } -}; - -BaseClassWithOperator funcCheckOperatorForBaseClass() -{ - BaseClassWithOperator a(5); - return (a + 6); -} - -class DLL_API DerivedClassForOperator : public BaseClassWithOperator -{ -public: - DerivedClassForOperator(int n) : BaseClassWithOperator(n) { } -}; - -BaseClassWithOperator funcCheckOperatorForDerivedClass() -{ - DerivedClassForOperator a(5); - return (a + 6); -} \ No newline at end of file From ed0b28a60023b1977b6ff18d789c2d6e6e0cb946 Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Sun, 9 Aug 2015 01:37:39 +0530 Subject: [PATCH 6/6] Removed comment. --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 93327b3875..536a88dfa3 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2576,9 +2576,7 @@ private ParamMarshal GenerateFunctionParamMarshal(Parameter param, int paramInde if ( (paramType.GetFinalPointee() ?? paramType).Desugar().TryGetClass(out @class)) { if(@class.IsRefType || @class.IsValueType) - WriteLine("{0} = new {1}();", param.Name, paramType);/* - else if(@class.IsRefType) - WriteLine("{0} = new {1}();", param.Name, paramType);*/ + WriteLine("{0} = new {1}();", param.Name, paramType); } }