Browse Source

Merge remote-tracking branch 'upstream/master'

Conflicts:
	src/Generator/Generators/CLI/CLITypePrinter.cs
pull/225/head
Elias Holzer 11 years ago
parent
commit
7cde60a97b
  1. 2
      build/Helpers.lua
  2. 35
      build/Parser.lua
  3. BIN
      build/premake4.exe
  4. 43
      build/premake4.lua
  5. 35
      src/CppParser/AST.cpp
  6. 12
      src/CppParser/AST.h
  7. 382
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  8. 31
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppParser.cs
  9. 7
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Target.cs
  10. 15
      src/CppParser/CppParser.cpp
  11. 3
      src/CppParser/CppParser.h
  12. 7
      src/Generator/Driver.cs
  13. 15
      src/Generator/Generators/CLI/CLIMarshal.cs
  14. 757
      src/Generator/Generators/CLI/CLITypePrinter.cs
  15. 9
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  16. 15
      src/Generator/Options.cs
  17. 2
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  18. 16
      tests/Basic/Basic.Tests.cs
  19. 2
      tests/Basic/Basic.cs
  20. 19
      tests/Basic/Basic.h
  21. 3
      tests/CSharpTemp/CSharpTemp.cs
  22. 27
      tests/FieldTests.cs
  23. 166
      tests/InheritanceTests.cs
  24. 31
      tests/ManglingTests.cs
  25. 74
      tests/MarshalingTests.cs
  26. 8
      tests/Native/FieldTests.cpp
  27. 7
      tests/Native/FieldTests.h
  28. 79
      tests/Native/InheritanceTests.cpp
  29. 65
      tests/Native/InheritanceTests.h
  30. 33
      tests/Native/ManglingTests.cpp
  31. 22
      tests/Native/ManglingTests.h
  32. 36
      tests/Native/MarshalingTests.cpp
  33. 77
      tests/Native/MarshalingTests.h
  34. 21
      tests/Native/NUnit.cpp
  35. 114
      tests/Native/NUnit.h

2
build/Helpers.lua

@ -47,7 +47,7 @@ function SetupNativeProject() @@ -47,7 +47,7 @@ function SetupNativeProject()
buildoptions { gcc_buildflags }
configuration { "macosx" }
buildoptions { gcc_buildflags, "-stdlib=libc++", "-fvisibility-inlines-hidden" }
buildoptions { gcc_buildflags, "-stdlib=libc++" }
-- OS-specific options

35
build/Parser.lua

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
newoption {
trigger = "parser",
description = "Controls which version of the parser is enabled.",
value = "version",
allowed = {
{ "cpp", "Cross-platform C++ parser."},
{ "cli", "VS-only C++/CLI parser."},
}
}
function SetupCLIParser()
local parser = _OPTIONS["parser"]
if not parser or parser == "cli" then
defines { "OLD_PARSER" }
links { "CppSharp.Parser" }
else
links { "CppSharp.Parser.CLI" }
end
end
function SetupCSharpParser()
links
{
"CppSharp.Parser.CSharp",
"CppSharp.Runtime"
}
end
function SetupParser()
if string.match(action, "vs*") then
SetupCLIParser()
else
SetupCSharpParser()
end
end

BIN
build/premake4.exe

Binary file not shown.

43
build/premake4.lua

@ -6,45 +6,8 @@ config = {} @@ -6,45 +6,8 @@ config = {}
dofile "Helpers.lua"
dofile "Tests.lua"
-- Setup the LLVM dependency
dofile "LLVM.lua"
newoption {
trigger = "parser",
description = "Controls which version of the parser is enabled.",
value = "version",
allowed = {
{ "cpp", "Cross-platform C++ parser."},
{ "cli", "VS-only C++/CLI parser."},
}
}
function SetupCLIParser()
local parser = _OPTIONS["parser"]
if not parser or parser == "cli" then
defines { "OLD_PARSER" }
links { "CppSharp.Parser" }
else
links { "CppSharp.Parser.CLI" }
end
end
function SetupCSharpParser()
links
{
"CppSharp.Parser.CSharp",
"CppSharp.Runtime"
}
end
function SetupParser()
if string.match(action, "vs*") then
SetupCLIParser()
else
SetupCSharpParser()
end
end
dofile "Parser.lua"
solution "CppSharp"
@ -78,11 +41,11 @@ solution "CppSharp" @@ -78,11 +41,11 @@ solution "CppSharp"
group "Examples"
IncludeExamples()
end
group "Tests"
IncludeTests()
end
group "Libraries"
include (srcdir .. "/Core")
include (srcdir .. "/AST/AST.lua")

35
src/CppParser/AST.cpp

@ -34,6 +34,8 @@ static std::vector<T> split(const T & str, const T & delimiters) { @@ -34,6 +34,8 @@ static std::vector<T> split(const T & str, const T & delimiters) {
namespace CppSharp { namespace CppParser { namespace AST {
Type::Type(TypeKind kind) : Kind(kind) {}
Type::Type(const Type& rhs) : Kind(rhs.Kind), IsDependent(rhs.IsDependent) {}
QualifiedType::QualifiedType() : Type(0) {}
TagType::TagType() : Type(TypeKind::Tag) {}
@ -57,9 +59,16 @@ TemplateArgument::TemplateArgument() : Declaration(0) {} @@ -57,9 +59,16 @@ TemplateArgument::TemplateArgument() : Declaration(0) {}
TemplateSpecializationType::TemplateSpecializationType()
: Type(TypeKind::TemplateSpecialization), Template(0), Desugared(0) {}
TemplateSpecializationType::TemplateSpecializationType(
const TemplateSpecializationType& rhs) : Type(rhs),
Arguments(rhs.Arguments), Template(rhs.Template), Desugared(rhs.Desugared) {}
DEF_VECTOR(TemplateSpecializationType, TemplateArgument, Arguments)
// TemplateParameter
TemplateParameter::TemplateParameter() {}
TemplateParameter::TemplateParameter(const TemplateParameter& rhs) : Name(rhs.Name) {}
DEF_STRING(TemplateParameter, Name)
TemplateParameterType::TemplateParameterType() : Type(TypeKind::TemplateParameter) {}
@ -80,9 +89,14 @@ VTableComponent::VTableComponent() : Offset(0), Declaration(0) {} @@ -80,9 +89,14 @@ VTableComponent::VTableComponent() : Offset(0), Declaration(0) {}
// VTableLayout
VTableLayout::VTableLayout() {}
VTableLayout::VTableLayout(const VTableLayout& rhs) : Components(rhs.Components) {}
DEF_VECTOR(VTableLayout, VTableComponent, Components)
VFTableInfo::VFTableInfo() : VBTableIndex(0), VFPtrOffset(0), VFPtrFullOffset(0) {}
VFTableInfo::VFTableInfo(const VFTableInfo& rhs) : VBTableIndex(rhs.VBTableIndex),
VFPtrOffset(rhs.VFPtrOffset), VFPtrFullOffset(rhs.VFPtrFullOffset),
Layout(rhs.Layout) {}
ClassLayout::ClassLayout() : ABI(CppAbi::Itanium), HasOwnVFPtr(false),
VBPtrOffset(0), Alignment(0), Size(0), DataSize(0) {}
@ -102,6 +116,22 @@ Declaration::Declaration(DeclarationKind kind) @@ -102,6 +116,22 @@ Declaration::Declaration(DeclarationKind kind)
{
}
Declaration::Declaration(const Declaration& rhs)
: Kind(rhs.Kind)
, Access(rhs.Access)
, _Namespace(rhs._Namespace)
, Name(rhs.Name)
, Comment(rhs.Comment)
, DebugText(rhs.DebugText)
, IsIncomplete(rhs.IsIncomplete)
, IsDependent(rhs.IsDependent)
, CompleteDeclaration(rhs.CompleteDeclaration)
, DefinitionOrder(rhs.DefinitionOrder)
, PreprocessedEntities(rhs.PreprocessedEntities)
, OriginalPtr(rhs.OriginalPtr)
{
}
DEF_STRING(Declaration, Name)
DEF_STRING(Declaration, DebugText)
DEF_VECTOR(Declaration, PreprocessedEntity*, PreprocessedEntities)
@ -360,6 +390,9 @@ DEF_VECTOR(Enumeration, Enumeration::Item, Items) @@ -360,6 +390,9 @@ DEF_VECTOR(Enumeration, Enumeration::Item, Items)
Enumeration::Item::Item() : Declaration(DeclarationKind::EnumerationItem) {}
Enumeration::Item::Item(const Item& rhs) : Declaration(rhs),
Expression(rhs.Expression), Value(rhs.Value) {}
DEF_STRING(Enumeration::Item, Expression)
Variable::Variable() : Declaration(DeclarationKind::Variable) {}
@ -451,8 +484,10 @@ ASTContext::ASTContext() {} @@ -451,8 +484,10 @@ ASTContext::ASTContext() {}
TranslationUnit* ASTContext::FindOrCreateModule(std::string File)
{
#ifdef _WIN32
// Clean up the file path.
std::replace(File.begin(), File.end(), '/', '\\');
#endif
auto existingUnit = std::find_if(TranslationUnits.begin(),
TranslationUnits.end(), [&](TranslationUnit* unit) {

12
src/CppParser/AST.h

@ -38,6 +38,8 @@ enum struct TypeKind @@ -38,6 +38,8 @@ enum struct TypeKind
struct CS_API Type
{
Type(TypeKind kind);
Type(const Type&);
TypeKind Kind;
bool IsDependent;
};
@ -171,6 +173,8 @@ struct Template; @@ -171,6 +173,8 @@ struct Template;
struct CS_API TemplateSpecializationType : public Type
{
TemplateSpecializationType();
TemplateSpecializationType(const TemplateSpecializationType&);
VECTOR(TemplateArgument, Arguments)
CppSharp::CppParser::AST::Template* Template;
Type* Desugared;
@ -178,6 +182,9 @@ struct CS_API TemplateSpecializationType : public Type @@ -178,6 +182,9 @@ struct CS_API TemplateSpecializationType : public Type
struct CS_API TemplateParameter
{
TemplateParameter();
TemplateParameter(const TemplateParameter&);
bool operator==(const TemplateParameter& param) const
{
return Name == param.Name;
@ -278,12 +285,14 @@ struct CS_API VTableComponent @@ -278,12 +285,14 @@ struct CS_API VTableComponent
struct CS_API VTableLayout
{
VTableLayout();
VTableLayout(const VTableLayout&);
VECTOR(VTableComponent, Components)
};
struct CS_API VFTableInfo
{
VFTableInfo();
VFTableInfo(const VFTableInfo&);
uint64_t VBTableIndex;
uint32_t VFPtrOffset;
uint32_t VFPtrFullOffset;
@ -349,6 +358,7 @@ struct PreprocessedEntity; @@ -349,6 +358,7 @@ struct PreprocessedEntity;
struct CS_API Declaration
{
Declaration(DeclarationKind kind);
Declaration(const Declaration&);
DeclarationKind Kind;
AccessSpecifier Access;
@ -531,6 +541,8 @@ struct CS_API Enumeration : public Declaration @@ -531,6 +541,8 @@ struct CS_API Enumeration : public Declaration
struct CS_API Item : public Declaration
{
DECLARE_DECL_KIND(Item, EnumerationItem)
Item(const Item&);
STRING(Expression)
uint64_t Value;
};

382
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

@ -253,12 +253,6 @@ namespace CppSharp @@ -253,12 +253,6 @@ namespace CppSharp
Internal.ctor_0(__Instance, arg0);
}
public Type(CppSharp.Parser.AST.Type _0)
{
__Instance = Marshal.AllocHGlobal(8);
*((Type.Internal*) __Instance) = *((Type.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
@ -338,12 +332,6 @@ namespace CppSharp @@ -338,12 +332,6 @@ namespace CppSharp
__Instance = native;
}
public TypeQualifiers(CppSharp.Parser.AST.TypeQualifiers _0)
{
__Instance = Marshal.AllocHGlobal(3);
*((TypeQualifiers.Internal*) __Instance) = *((TypeQualifiers.Internal*) _0.__Instance);
}
public TypeQualifiers()
{
__Instance = Marshal.AllocHGlobal(3);
@ -451,12 +439,6 @@ namespace CppSharp @@ -451,12 +439,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public QualifiedType(CppSharp.Parser.AST.QualifiedType _0)
{
__Instance = Marshal.AllocHGlobal(8);
*((QualifiedType.Internal*) __Instance) = *((QualifiedType.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
@ -548,13 +530,6 @@ namespace CppSharp @@ -548,13 +530,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TagType(CppSharp.Parser.AST.TagType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(12);
*((TagType.Internal*) __Instance) = *((TagType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -637,13 +612,6 @@ namespace CppSharp @@ -637,13 +612,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ArrayType(CppSharp.Parser.AST.ArrayType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(24);
*((ArrayType.Internal*) __Instance) = *((ArrayType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -770,14 +738,6 @@ namespace CppSharp @@ -770,14 +738,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public FunctionType(CppSharp.Parser.AST.FunctionType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(32);
var arg0 = _0 == (CppSharp.Parser.AST.FunctionType) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -896,13 +856,6 @@ namespace CppSharp @@ -896,13 +856,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public PointerType(CppSharp.Parser.AST.PointerType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(20);
*((PointerType.Internal*) __Instance) = *((PointerType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -988,13 +941,6 @@ namespace CppSharp @@ -988,13 +941,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public MemberPointerType(CppSharp.Parser.AST.MemberPointerType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(16);
*((MemberPointerType.Internal*) __Instance) = *((MemberPointerType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1065,13 +1011,6 @@ namespace CppSharp @@ -1065,13 +1011,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TypedefType(CppSharp.Parser.AST.TypedefType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(12);
*((TypedefType.Internal*) __Instance) = *((TypedefType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1143,13 +1082,6 @@ namespace CppSharp @@ -1143,13 +1082,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public AttributedType(CppSharp.Parser.AST.AttributedType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(24);
*((AttributedType.Internal*) __Instance) = *((AttributedType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1243,13 +1175,6 @@ namespace CppSharp @@ -1243,13 +1175,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public DecayedType(CppSharp.Parser.AST.DecayedType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(32);
*((DecayedType.Internal*) __Instance) = *((DecayedType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1370,12 +1295,6 @@ namespace CppSharp @@ -1370,12 +1295,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TemplateArgument(CppSharp.Parser.AST.TemplateArgument _0)
{
__Instance = Marshal.AllocHGlobal(20);
*((TemplateArgument.Internal*) __Instance) = *((TemplateArgument.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
@ -1523,14 +1442,6 @@ namespace CppSharp @@ -1523,14 +1442,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TemplateSpecializationType(CppSharp.Parser.AST.TemplateSpecializationType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(28);
var arg0 = _0 == (CppSharp.Parser.AST.TemplateSpecializationType) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1654,13 +1565,6 @@ namespace CppSharp @@ -1654,13 +1565,6 @@ namespace CppSharp
Internal.ctor_1(__Instance);
}
public TemplateParameter(CppSharp.Parser.AST.TemplateParameter _0)
{
__Instance = Marshal.AllocHGlobal(12);
var arg0 = _0 == (CppSharp.Parser.AST.TemplateParameter) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -1756,14 +1660,6 @@ namespace CppSharp @@ -1756,14 +1660,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TemplateParameterType(CppSharp.Parser.AST.TemplateParameterType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(20);
var arg0 = _0 == (CppSharp.Parser.AST.TemplateParameterType) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1834,13 +1730,6 @@ namespace CppSharp @@ -1834,13 +1730,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TemplateParameterSubstitutionType(CppSharp.Parser.AST.TemplateParameterSubstitutionType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(16);
*((TemplateParameterSubstitutionType.Internal*) __Instance) = *((TemplateParameterSubstitutionType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -1919,14 +1808,6 @@ namespace CppSharp @@ -1919,14 +1808,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public InjectedClassNameType(CppSharp.Parser.AST.InjectedClassNameType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(40);
var arg0 = _0 == (CppSharp.Parser.AST.InjectedClassNameType) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -2009,13 +1890,6 @@ namespace CppSharp @@ -2009,13 +1890,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public DependentNameType(CppSharp.Parser.AST.DependentNameType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(8);
*((DependentNameType.Internal*) __Instance) = *((DependentNameType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -2066,13 +1940,6 @@ namespace CppSharp @@ -2066,13 +1940,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public PackExpansionType(CppSharp.Parser.AST.PackExpansionType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(8);
*((PackExpansionType.Internal*) __Instance) = *((PackExpansionType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -2126,13 +1993,6 @@ namespace CppSharp @@ -2126,13 +1993,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public BuiltinType(CppSharp.Parser.AST.BuiltinType _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(12);
*((BuiltinType.Internal*) __Instance) = *((BuiltinType.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -2202,12 +2062,6 @@ namespace CppSharp @@ -2202,12 +2062,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public VTableComponent(CppSharp.Parser.AST.VTableComponent _0)
{
__Instance = Marshal.AllocHGlobal(12);
*((VTableComponent.Internal*) __Instance) = *((VTableComponent.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
@ -2327,13 +2181,6 @@ namespace CppSharp @@ -2327,13 +2181,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public VTableLayout(CppSharp.Parser.AST.VTableLayout _0)
{
__Instance = Marshal.AllocHGlobal(12);
var arg0 = _0 == (CppSharp.Parser.AST.VTableLayout) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -2427,13 +2274,6 @@ namespace CppSharp @@ -2427,13 +2274,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public VFTableInfo(CppSharp.Parser.AST.VFTableInfo _0)
{
__Instance = Marshal.AllocHGlobal(28);
var arg0 = _0 == (CppSharp.Parser.AST.VFTableInfo) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -2592,13 +2432,6 @@ namespace CppSharp @@ -2592,13 +2432,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ClassLayout(CppSharp.Parser.AST.ClassLayout _0)
{
__Instance = Marshal.AllocHGlobal(48);
var arg0 = _0 == (CppSharp.Parser.AST.ClassLayout) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -2859,13 +2692,6 @@ namespace CppSharp @@ -2859,13 +2692,6 @@ namespace CppSharp
Internal.ctor_0(__Instance, arg0);
}
public Declaration(CppSharp.Parser.AST.Declaration _0)
{
__Instance = Marshal.AllocHGlobal(68);
var arg0 = _0 == (CppSharp.Parser.AST.Declaration) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -3281,14 +3107,6 @@ namespace CppSharp @@ -3281,14 +3107,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public DeclarationContext(CppSharp.Parser.AST.DeclarationContext _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(168);
var arg0 = _0 == (CppSharp.Parser.AST.DeclarationContext) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -3546,14 +3364,6 @@ namespace CppSharp @@ -3546,14 +3364,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TypedefDecl(CppSharp.Parser.AST.TypedefDecl _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(76);
var arg0 = _0 == (CppSharp.Parser.AST.TypedefDecl) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -3665,14 +3475,6 @@ namespace CppSharp @@ -3665,14 +3475,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Parameter(CppSharp.Parser.AST.Parameter _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(80);
var arg0 = _0 == (CppSharp.Parser.AST.Parameter) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -3873,14 +3675,6 @@ namespace CppSharp @@ -3873,14 +3675,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Function(CppSharp.Parser.AST.Function _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(128);
var arg0 = _0 == (CppSharp.Parser.AST.Function) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -4210,14 +4004,6 @@ namespace CppSharp @@ -4210,14 +4004,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Method(CppSharp.Parser.AST.Method _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(156);
var arg0 = _0 == (CppSharp.Parser.AST.Method) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -4578,14 +4364,6 @@ namespace CppSharp @@ -4578,14 +4364,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Item(CppSharp.Parser.AST.Enumeration.Item _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(88);
var arg0 = _0 == (CppSharp.Parser.AST.Enumeration.Item) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -4646,14 +4424,6 @@ namespace CppSharp @@ -4646,14 +4424,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Enumeration(CppSharp.Parser.AST.Enumeration _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(92);
var arg0 = _0 == (CppSharp.Parser.AST.Enumeration) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -4824,14 +4594,6 @@ namespace CppSharp @@ -4824,14 +4594,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Variable(CppSharp.Parser.AST.Variable _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(88);
var arg0 = _0 == (CppSharp.Parser.AST.Variable) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -4920,12 +4682,6 @@ namespace CppSharp @@ -4920,12 +4682,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public BaseClassSpecifier(CppSharp.Parser.AST.BaseClassSpecifier _0)
{
__Instance = Marshal.AllocHGlobal(12);
*((BaseClassSpecifier.Internal*) __Instance) = *((BaseClassSpecifier.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
@ -5071,14 +4827,6 @@ namespace CppSharp @@ -5071,14 +4827,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Field(CppSharp.Parser.AST.Field _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(84);
var arg0 = _0 == (CppSharp.Parser.AST.Field) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -5211,14 +4959,6 @@ namespace CppSharp @@ -5211,14 +4959,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public AccessSpecifierDecl(CppSharp.Parser.AST.AccessSpecifierDecl _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(68);
var arg0 = _0 == (CppSharp.Parser.AST.AccessSpecifierDecl) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -5433,14 +5173,6 @@ namespace CppSharp @@ -5433,14 +5173,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Class(CppSharp.Parser.AST.Class _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(232);
var arg0 = _0 == (CppSharp.Parser.AST.Class) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -5785,14 +5517,6 @@ namespace CppSharp @@ -5785,14 +5517,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Template(CppSharp.Parser.AST.Template _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(84);
var arg0 = _0 == (CppSharp.Parser.AST.Template) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -5961,14 +5685,6 @@ namespace CppSharp @@ -5961,14 +5685,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ClassTemplate(CppSharp.Parser.AST.ClassTemplate _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(96);
var arg0 = _0 == (CppSharp.Parser.AST.ClassTemplate) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -6201,14 +5917,6 @@ namespace CppSharp @@ -6201,14 +5917,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ClassTemplateSpecialization(CppSharp.Parser.AST.ClassTemplateSpecialization _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(252);
var arg0 = _0 == (CppSharp.Parser.AST.ClassTemplateSpecialization) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -6426,14 +6134,6 @@ namespace CppSharp @@ -6426,14 +6134,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ClassTemplatePartialSpecialization(CppSharp.Parser.AST.ClassTemplatePartialSpecialization _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(252);
var arg0 = _0 == (CppSharp.Parser.AST.ClassTemplatePartialSpecialization) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -6525,14 +6225,6 @@ namespace CppSharp @@ -6525,14 +6225,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public FunctionTemplate(CppSharp.Parser.AST.FunctionTemplate _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(84);
var arg0 = _0 == (CppSharp.Parser.AST.FunctionTemplate) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -6648,14 +6340,6 @@ namespace CppSharp @@ -6648,14 +6340,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public Namespace(CppSharp.Parser.AST.Namespace _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(168);
var arg0 = _0 == (CppSharp.Parser.AST.Namespace) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -6759,14 +6443,6 @@ namespace CppSharp @@ -6759,14 +6443,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public PreprocessedEntity(CppSharp.Parser.AST.PreprocessedEntity _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(72);
var arg0 = _0 == (CppSharp.Parser.AST.PreprocessedEntity) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_1(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -6883,14 +6559,6 @@ namespace CppSharp @@ -6883,14 +6559,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public MacroDefinition(CppSharp.Parser.AST.MacroDefinition _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(84);
var arg0 = _0 == (CppSharp.Parser.AST.MacroDefinition) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -7012,14 +6680,6 @@ namespace CppSharp @@ -7012,14 +6680,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public MacroExpansion(CppSharp.Parser.AST.MacroExpansion _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(88);
var arg0 = _0 == (CppSharp.Parser.AST.MacroExpansion) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -7201,14 +6861,6 @@ namespace CppSharp @@ -7201,14 +6861,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public TranslationUnit(CppSharp.Parser.AST.TranslationUnit _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(196);
var arg0 = _0 == (CppSharp.Parser.AST.TranslationUnit) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -7344,13 +6996,6 @@ namespace CppSharp @@ -7344,13 +6996,6 @@ namespace CppSharp
Internal.ctor_1(__Instance);
}
public NativeLibrary(CppSharp.Parser.AST.NativeLibrary _0)
{
__Instance = Marshal.AllocHGlobal(24);
var arg0 = _0 == (CppSharp.Parser.AST.NativeLibrary) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -7466,13 +7111,6 @@ namespace CppSharp @@ -7466,13 +7111,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ASTContext(CppSharp.Parser.AST.ASTContext _0)
{
__Instance = Marshal.AllocHGlobal(12);
var arg0 = _0 == (CppSharp.Parser.AST.ASTContext) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -7551,12 +7189,6 @@ namespace CppSharp @@ -7551,12 +7189,6 @@ namespace CppSharp
Internal.ctor_0(__Instance, arg0);
}
public Comment(CppSharp.Parser.AST.Comment _0)
{
__Instance = Marshal.AllocHGlobal(4);
*((Comment.Internal*) __Instance) = *((Comment.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
@ -7625,13 +7257,6 @@ namespace CppSharp @@ -7625,13 +7257,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public FullComment(CppSharp.Parser.AST.FullComment _0)
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(4);
*((FullComment.Internal*) __Instance) = *((FullComment.Internal*) _0.__Instance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
@ -7714,13 +7339,6 @@ namespace CppSharp @@ -7714,13 +7339,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public RawComment(CppSharp.Parser.AST.RawComment _0)
{
__Instance = Marshal.AllocHGlobal(32);
var arg0 = _0 == (CppSharp.Parser.AST.RawComment) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);

31
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppParser.cs

@ -216,13 +216,6 @@ namespace CppSharp @@ -216,13 +216,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ParserOptions(CppSharp.Parser.ParserOptions _0)
{
__Instance = Marshal.AllocHGlobal(100);
var arg0 = _0 == (CppSharp.Parser.ParserOptions) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -513,7 +506,7 @@ namespace CppSharp @@ -513,7 +506,7 @@ namespace CppSharp
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser16ParserDiagnosticC2Ev")]
internal static extern void ctor_1(global::System.IntPtr instance);
internal static extern void ctor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -566,14 +559,7 @@ namespace CppSharp @@ -566,14 +559,7 @@ namespace CppSharp
public ParserDiagnostic()
{
__Instance = Marshal.AllocHGlobal(36);
Internal.ctor_1(__Instance);
}
public ParserDiagnostic(CppSharp.Parser.ParserDiagnostic _0)
{
__Instance = Marshal.AllocHGlobal(36);
var arg0 = _0 == (CppSharp.Parser.ParserDiagnostic) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
Internal.ctor_0(__Instance);
}
public void Dispose()
@ -739,13 +725,6 @@ namespace CppSharp @@ -739,13 +725,6 @@ namespace CppSharp
Internal.ctor_0(__Instance);
}
public ParserResult(CppSharp.Parser.ParserResult _0)
{
__Instance = Marshal.AllocHGlobal(24);
var arg0 = _0 == (CppSharp.Parser.ParserResult) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);
@ -876,12 +855,6 @@ namespace CppSharp @@ -876,12 +855,6 @@ namespace CppSharp
__Instance = Marshal.AllocHGlobal(1);
}
public ClangParser(CppSharp.Parser.ClangParser _0)
{
__Instance = Marshal.AllocHGlobal(1);
*((ClangParser.Internal*) __Instance) = *((ClangParser.Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);

7
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Target.cs

@ -196,13 +196,6 @@ namespace CppSharp @@ -196,13 +196,6 @@ namespace CppSharp
Internal.ctor_1(__Instance);
}
public ParserTargetInfo(CppSharp.Parser.ParserTargetInfo _0)
{
__Instance = Marshal.AllocHGlobal(164);
var arg0 = _0 == (CppSharp.Parser.ParserTargetInfo) null ? global::System.IntPtr.Zero : _0.__Instance;
Internal.cctor_2(__Instance, arg0);
}
public void Dispose()
{
Dispose(disposing: true);

15
src/CppParser/CppParser.cpp

@ -35,8 +35,23 @@ ParserResult::ParserResult() @@ -35,8 +35,23 @@ ParserResult::ParserResult()
{
}
ParserResult::ParserResult(const ParserResult& rhs)
: Kind(rhs.Kind)
, Diagnostics(rhs.Diagnostics)
, ASTContext(rhs.ASTContext)
, Library(rhs.Library)
{}
ParserDiagnostic::ParserDiagnostic() {}
ParserDiagnostic::ParserDiagnostic(const ParserDiagnostic& rhs)
: FileName(rhs.FileName)
, Message(rhs.Message)
, Level(rhs.Level)
, LineNumber(rhs.LineNumber)
, ColumnNumber(rhs.ColumnNumber)
{}
DEF_STRING(ParserDiagnostic, FileName)
DEF_STRING(ParserDiagnostic, Message)

3
src/CppParser/CppParser.h

@ -54,6 +54,8 @@ enum struct ParserDiagnosticLevel @@ -54,6 +54,8 @@ enum struct ParserDiagnosticLevel
struct CS_API ParserDiagnostic
{
ParserDiagnostic();
ParserDiagnostic(const ParserDiagnostic&);
STRING(FileName)
STRING(Message)
ParserDiagnosticLevel Level;
@ -71,6 +73,7 @@ enum struct ParserResultKind @@ -71,6 +73,7 @@ enum struct ParserResultKind
struct CS_API ParserResult
{
ParserResult();
ParserResult(const ParserResult&);
ParserResultKind Kind;
VECTOR(ParserDiagnostic, Diagnostics)

7
src/Generator/Driver.cs

@ -298,9 +298,12 @@ namespace CppSharp @@ -298,9 +298,12 @@ namespace CppSharp
}
if (Options.GenerateVirtualTables)
TranslationUnitPasses.AddPass(new CheckVTableComponentsPass());
TranslationUnitPasses.AddPass(new CheckVTableComponentsPass());
if (Options.GenerateProperties)
TranslationUnitPasses.AddPass(new GetterSetterToPropertyPass());
if (Options.GenerateProperties)
if (Options.GeneratePropertiesAdvanced)
TranslationUnitPasses.AddPass(new GetterSetterToPropertyAdvancedPass());
}

15
src/Generator/Generators/CLI/CLIMarshal.cs

@ -423,11 +423,20 @@ namespace CppSharp.Generators.CLI @@ -423,11 +423,20 @@ namespace CppSharp.Generators.CLI
var cppTypeName = pointer.Visit(cppTypePrinter, quals);
return VisitDelegateType(function, cppTypeName);
}
Enumeration @enum;
if (pointee.IsTagDecl(out @enum))
{
ArgumentPrefix.Write("&");
Context.Return.Write("(::{0})*{1}", @enum.QualifiedOriginalName,
Context.Parameter.Name);
return true;
}
Class @class;
if (pointee.IsTagDecl(out @class) && @class.IsValueType)
{
Class @class;
if (pointee.IsTagDecl(out @class) && @class.IsValueType)
{
if (Context.Function == null)
Context.Return.Write("&");
return pointee.Visit(this, quals);

757
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -1,145 +1,145 @@ @@ -1,145 +1,145 @@
using System;
using System.Collections.Generic;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
using Type = CppSharp.AST.Type;
namespace CppSharp.Generators.CLI
{
public class CLITypePrinterContext : TypePrinterContext
{
public CLITypePrinterContext()
{
}
public CLITypePrinterContext(TypePrinterContextKind kind)
: base(kind)
{
}
}
public class CLITypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{
public Driver Driver { get; set; }
public CLITypePrinterContext Context { get; set; }
readonly ITypeMapDatabase TypeMapDatabase;
readonly DriverOptions Options;
public CLITypePrinter(Driver driver)
{
Driver = driver;
TypeMapDatabase = driver.TypeDatabase;
Options = driver.Options;
Context = new CLITypePrinterContext();
}
public CLITypePrinter(Driver driver, CLITypePrinterContext context)
: this(driver)
{
Context = context;
}
public string VisitTagType(TagType tag, TypeQualifiers quals)
{
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
{
typeMap.Type = tag;
Context.Type = tag;
return typeMap.CLISignature(Context);
}
Declaration decl = tag.Declaration;
if (decl == null)
return string.Empty;
return VisitDeclaration(decl, quals);
}
public string VisitArrayType(ArrayType array, TypeQualifiers quals)
{
return string.Format("cli::array<{0}>^", array.Type.Visit(this));
}
public string VisitFunctionType(FunctionType function, TypeQualifiers quals)
{
var arguments = function.Parameters;
var returnType = function.ReturnType;
var args = string.Empty;
if (arguments.Count > 0)
args = VisitParameters(function.Parameters, hasNames: false);
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{
if (!string.IsNullOrEmpty(args))
args = string.Format("<{0}>", args);
return string.Format("System::Action{0}", args);
}
if (!string.IsNullOrEmpty(args))
args = string.Format(", {0}", args);
return string.Format("System::Func<{0}{1}>", returnType.Visit(this), args);
}
public string VisitParameters(IEnumerable<Parameter> @params,
bool hasNames)
{
var args = new List<string>();
foreach (var param in @params)
args.Add(VisitParameter(param, hasNames));
return string.Join(", ", args);
}
public string VisitParameter(Parameter param, bool hasName = true)
{
Context.Parameter = param;
var type = param.Type.Visit(this, param.QualifiedType.Qualifiers);
Context.Parameter = null;
var str = string.Empty;
if(param.Usage == ParameterUsage.Out)
str += "[System::Runtime::InteropServices::Out] ";
str += type;
if(param.Usage == ParameterUsage.Out ||
param.Usage == ParameterUsage.InOut)
str += "%";
if (hasName && !string.IsNullOrEmpty(param.Name))
str += " " + param.Name;
return str;
}
public string VisitDelegate(FunctionType function)
{
return string.Format("delegate {0} {{0}}({1})",
function.ReturnType.Visit(this),
VisitParameters(function.Parameters, hasNames: true));
}
public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
var pointee = pointer.Pointee;
if (pointee is FunctionType)
{
var function = pointee as FunctionType;
return string.Format("{0}^", function.Visit(this, quals));
}
if (pointee.IsPrimitiveType(PrimitiveType.Char) && quals.IsConst)
{
return "System::String^";
using System;
using System.Collections.Generic;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
using Type = CppSharp.AST.Type;
namespace CppSharp.Generators.CLI
{
public class CLITypePrinterContext : TypePrinterContext
{
public CLITypePrinterContext()
{
}
public CLITypePrinterContext(TypePrinterContextKind kind)
: base(kind)
{
}
}
public class CLITypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{
public Driver Driver { get; set; }
public CLITypePrinterContext Context { get; set; }
readonly ITypeMapDatabase TypeMapDatabase;
readonly DriverOptions Options;
public CLITypePrinter(Driver driver)
{
Driver = driver;
TypeMapDatabase = driver.TypeDatabase;
Options = driver.Options;
Context = new CLITypePrinterContext();
}
public CLITypePrinter(Driver driver, CLITypePrinterContext context)
: this(driver)
{
Context = context;
}
public string VisitTagType(TagType tag, TypeQualifiers quals)
{
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
{
typeMap.Type = tag;
Context.Type = tag;
return typeMap.CLISignature(Context);
}
Declaration decl = tag.Declaration;
if (decl == null)
return string.Empty;
return VisitDeclaration(decl, quals);
}
public string VisitArrayType(ArrayType array, TypeQualifiers quals)
{
return string.Format("cli::array<{0}>^", array.Type.Visit(this));
}
public string VisitFunctionType(FunctionType function, TypeQualifiers quals)
{
var arguments = function.Parameters;
var returnType = function.ReturnType;
var args = string.Empty;
if (arguments.Count > 0)
args = VisitParameters(function.Parameters, hasNames: false);
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{
if (!string.IsNullOrEmpty(args))
args = string.Format("<{0}>", args);
return string.Format("System::Action{0}", args);
}
if (!string.IsNullOrEmpty(args))
args = string.Format(", {0}", args);
return string.Format("System::Func<{0}{1}>", returnType.Visit(this), args);
}
public string VisitParameters(IEnumerable<Parameter> @params,
bool hasNames)
{
var args = new List<string>();
foreach (var param in @params)
args.Add(VisitParameter(param, hasNames));
return string.Join(", ", args);
}
public string VisitParameter(Parameter param, bool hasName = true)
{
Context.Parameter = param;
var type = param.Type.Visit(this, param.QualifiedType.Qualifiers);
Context.Parameter = null;
var str = string.Empty;
if(param.Usage == ParameterUsage.Out)
str += "[System::Runtime::InteropServices::Out] ";
str += type;
if(param.Usage == ParameterUsage.Out ||
param.Usage == ParameterUsage.InOut)
str += "%";
if (hasName && !string.IsNullOrEmpty(param.Name))
str += " " + param.Name;
return str;
}
public string VisitDelegate(FunctionType function)
{
return string.Format("delegate {0} {{0}}({1})",
function.ReturnType.Visit(this),
VisitParameters(function.Parameters, hasNames: true));
}
public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
var pointee = pointer.Pointee.Desugar();
if (pointee is FunctionType)
{
var function = pointee as FunctionType;
return string.Format("{0}^", function.Visit(this, quals));
}
if (pointee.IsPrimitiveType(PrimitiveType.Char) && quals.IsConst)
{
return "System::String^";
}
// From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
@ -148,240 +148,247 @@ namespace CppSharp.Generators.CLI @@ -148,240 +148,247 @@ namespace CppSharp.Generators.CLI
// * Any enum type.
// * Any pointer type.
// * Any user-defined struct type that contains fields of unmanaged types only.
var finalPointee = pointer.GetFinalPointee();
if (finalPointee.IsPrimitiveType())
{
var finalPointee = pointer.GetFinalPointee();
if (finalPointee.IsPrimitiveType())
{
// Skip one indirection if passed by reference
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee)
return pointee.Visit(this, quals);
return pointee.Visit(this, quals) + "*";
}
return pointee.Visit(this, quals);
}
public string VisitMemberPointerType(MemberPointerType member,
TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
{
return VisitPrimitiveType(builtin.Type);
}
public string VisitPrimitiveType(PrimitiveType primitive)
{
switch (primitive)
{
case PrimitiveType.Bool: return "bool";
case PrimitiveType.Void: return "void";
case PrimitiveType.Char16:
case PrimitiveType.WideChar: return "System::Char";
case PrimitiveType.Int8: return Options.MarshalCharAsManagedChar ? "System::Char" : "char";
case PrimitiveType.UInt8: return "unsigned char";
case PrimitiveType.Int16: return "short";
case PrimitiveType.UInt16: return "unsigned short";
case PrimitiveType.Int32: return "int";
case PrimitiveType.UInt32: return "unsigned int";
case PrimitiveType.Int64: return "long long";
case PrimitiveType.UInt64: return "unsigned long long";
case PrimitiveType.Float: return "float";
case PrimitiveType.Double: return "double";
case PrimitiveType.IntPtr: return "IntPtr";
case PrimitiveType.UIntPtr: return "UIntPtr";
}
throw new NotSupportedException();
}
public string VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
{
var decl = typedef.Declaration;
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{
typeMap.Type = typedef;
Context.Type = typedef;
return typeMap.CLISignature(Context);
}
FunctionType func;
if (decl.Type.IsPointerTo<FunctionType>(out func))
{
// TODO: Use SafeIdentifier()
return string.Format("{0}^", VisitDeclaration(decl));
}
return decl.Type.Visit(this);
}
public string VisitAttributedType(AttributedType attributed, TypeQualifiers quals)
{
return attributed.Modified.Visit(this);
}
public string VisitDecayedType(DecayedType decayed, TypeQualifiers quals)
{
return decayed.Decayed.Visit(this);
}
public string VisitTemplateSpecializationType(TemplateSpecializationType template,
TypeQualifiers quals)
{
var decl = template.Template.TemplatedDecl;
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(template, out typeMap))
{
typeMap.Declaration = decl;
typeMap.Type = template;
Context.Type = template;
return typeMap.CLISignature(Context);
}
return decl.Name;
}
public string VisitTemplateParameterType(TemplateParameterType param,
TypeQualifiers quals)
{
return param.Parameter.Name;
}
public string VisitTemplateParameterSubstitutionType(
TemplateParameterSubstitutionType param, TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals)
{
return string.Empty;
}
public string VisitCILType(CILType type, TypeQualifiers quals)
{
return type.Type.FullName.Replace(".", "::") + "^";
}
public string VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals)
{
return VisitPrimitiveType(type);
}
public string VisitDeclaration(Declaration decl, TypeQualifiers quals)
{
return VisitDeclaration(decl);
}
public string VisitDeclaration(Declaration decl)
{
var names = new List<string>();
if (Options.GenerateLibraryNamespace)
names.Add(Driver.Options.OutputNamespace);
if (!string.IsNullOrEmpty(decl.Namespace.QualifiedName))
names.Add(decl.Namespace.QualifiedName);
names.Add(decl.Visit(this));
return string.Join("::", names);
}
public string VisitClassDecl(Class @class)
{
if (@class.CompleteDeclaration != null)
return VisitClassDecl(@class.CompleteDeclaration as Class);
return string.Format("{0}{1}", @class.Name, @class.IsRefType ? "^"
: string.Empty);
}
public string VisitFieldDecl(Field field)
{
throw new NotImplementedException();
}
public string VisitFunctionDecl(Function function)
{
throw new NotImplementedException();
}
public string VisitMethodDecl(Method method)
{
throw new NotImplementedException();
}
public string VisitParameterDecl(Parameter parameter)
{
throw new NotImplementedException();
}
public string VisitTypedefDecl(TypedefDecl typedef)
{
return typedef.Name;
}
public string VisitEnumDecl(Enumeration @enum)
{
return @enum.Name;
}
public string VisitVariableDecl(Variable variable)
{
throw new NotImplementedException();
}
public string VisitClassTemplateDecl(ClassTemplate template)
{
throw new NotImplementedException();
}
public string VisitFunctionTemplateDecl(FunctionTemplate template)
{
throw new NotImplementedException();
}
public string VisitMacroDefinition(MacroDefinition macro)
{
throw new NotImplementedException();
}
public string VisitNamespace(Namespace @namespace)
{
throw new NotImplementedException();
}
public string VisitEvent(Event @event)
{
throw new NotImplementedException();
}
public string VisitProperty(Property property)
{
throw new NotImplementedException();
}
public string ToString(Type type)
{
return type.Visit(this);
}
}
}
return pointee.Visit(this, quals);
return pointee.Visit(this, quals) + "*";
}
Enumeration @enum;
if (pointee.IsTagDecl(out @enum))
{
var typeName = @enum.Visit(this);
return string.Format("{0}*", typeName);
}
return pointee.Visit(this, quals);
}
public string VisitMemberPointerType(MemberPointerType member,
TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
{
return VisitPrimitiveType(builtin.Type);
}
public string VisitPrimitiveType(PrimitiveType primitive)
{
switch (primitive)
{
case PrimitiveType.Bool: return "bool";
case PrimitiveType.Void: return "void";
case PrimitiveType.Char16:
case PrimitiveType.WideChar: return "System::Char";
case PrimitiveType.Int8: return Options.MarshalCharAsManagedChar ? "System::Char" : "char";
case PrimitiveType.UInt8: return "unsigned char";
case PrimitiveType.Int16: return "short";
case PrimitiveType.UInt16: return "unsigned short";
case PrimitiveType.Int32: return "int";
case PrimitiveType.UInt32: return "unsigned int";
case PrimitiveType.Int64: return "long long";
case PrimitiveType.UInt64: return "unsigned long long";
case PrimitiveType.Float: return "float";
case PrimitiveType.Double: return "double";
case PrimitiveType.IntPtr: return "IntPtr";
case PrimitiveType.UIntPtr: return "UIntPtr";
}
throw new NotSupportedException();
}
public string VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
{
var decl = typedef.Declaration;
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{
typeMap.Type = typedef;
Context.Type = typedef;
return typeMap.CLISignature(Context);
}
FunctionType func;
if (decl.Type.IsPointerTo<FunctionType>(out func))
{
// TODO: Use SafeIdentifier()
return string.Format("{0}^", VisitDeclaration(decl));
}
return decl.Type.Visit(this);
}
public string VisitAttributedType(AttributedType attributed, TypeQualifiers quals)
{
return attributed.Modified.Visit(this);
}
public string VisitDecayedType(DecayedType decayed, TypeQualifiers quals)
{
return decayed.Decayed.Visit(this);
}
public string VisitTemplateSpecializationType(TemplateSpecializationType template,
TypeQualifiers quals)
{
var decl = template.Template.TemplatedDecl;
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(template, out typeMap))
{
typeMap.Declaration = decl;
typeMap.Type = template;
Context.Type = template;
return typeMap.CLISignature(Context);
}
return decl.Name;
}
public string VisitTemplateParameterType(TemplateParameterType param,
TypeQualifiers quals)
{
return param.Parameter.Name;
}
public string VisitTemplateParameterSubstitutionType(
TemplateParameterSubstitutionType param, TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals)
{
throw new NotImplementedException();
}
public string VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals)
{
return string.Empty;
}
public string VisitCILType(CILType type, TypeQualifiers quals)
{
return type.Type.FullName.Replace(".", "::") + "^";
}
public string VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals)
{
return VisitPrimitiveType(type);
}
public string VisitDeclaration(Declaration decl, TypeQualifiers quals)
{
return VisitDeclaration(decl);
}
public string VisitDeclaration(Declaration decl)
{
var names = new List<string>();
if (Options.GenerateLibraryNamespace)
names.Add(Driver.Options.OutputNamespace);
if (!string.IsNullOrEmpty(decl.Namespace.QualifiedName))
names.Add(decl.Namespace.QualifiedName);
names.Add(decl.Visit(this));
return string.Join("::", names);
}
public string VisitClassDecl(Class @class)
{
if (@class.CompleteDeclaration != null)
return VisitClassDecl(@class.CompleteDeclaration as Class);
return string.Format("{0}{1}", @class.Name, @class.IsRefType ? "^"
: string.Empty);
}
public string VisitFieldDecl(Field field)
{
throw new NotImplementedException();
}
public string VisitFunctionDecl(Function function)
{
throw new NotImplementedException();
}
public string VisitMethodDecl(Method method)
{
throw new NotImplementedException();
}
public string VisitParameterDecl(Parameter parameter)
{
throw new NotImplementedException();
}
public string VisitTypedefDecl(TypedefDecl typedef)
{
return typedef.Name;
}
public string VisitEnumDecl(Enumeration @enum)
{
return @enum.Name;
}
public string VisitVariableDecl(Variable variable)
{
throw new NotImplementedException();
}
public string VisitClassTemplateDecl(ClassTemplate template)
{
throw new NotImplementedException();
}
public string VisitFunctionTemplateDecl(FunctionTemplate template)
{
throw new NotImplementedException();
}
public string VisitMacroDefinition(MacroDefinition macro)
{
throw new NotImplementedException();
}
public string VisitNamespace(Namespace @namespace)
{
throw new NotImplementedException();
}
public string VisitEvent(Event @event)
{
throw new NotImplementedException();
}
public string VisitProperty(Property property)
{
throw new NotImplementedException();
}
public string ToString(Type type)
{
return type.Visit(this);
}
}
}

9
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -208,6 +208,8 @@ namespace CppSharp.Generators.CSharp @@ -208,6 +208,8 @@ namespace CppSharp.Generators.CSharp
if (IsConstCharString(pointer))
return isManagedContext ? "string" : "global::System.IntPtr";
var desugared = pointee.Desugar();
// From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
// Any of the following types may be a pointer type:
// * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
@ -229,8 +231,13 @@ namespace CppSharp.Generators.CSharp @@ -229,8 +231,13 @@ namespace CppSharp.Generators.CSharp
return pointee.Visit(this, quals) + "*";
}
Enumeration @enum;
if (desugared.IsTagDecl(out @enum))
{
return @enum.Name + "*";
}
Class @class;
var desugared = pointee.Desugar();
if ((desugared.IsDependent || desugared.IsTagDecl(out @class))
&& ContextKind == CSharpTypePrinterContextKind.Native)
{

15
src/Generator/Options.cs

@ -92,12 +92,25 @@ namespace CppSharp @@ -92,12 +92,25 @@ namespace CppSharp
public bool GenerateVirtualTables;
public bool GenerateAbstractImpls;
public bool GenerateInterfacesForMultipleInheritance;
public bool GenerateProperties;
public bool GenerateInternalImports;
public bool GenerateClassMarshals;
public bool GenerateInlines;
public bool GenerateCopyConstructors;
public bool UseHeaderDirectories;
/// <summary>
/// If set to true the generator will use GetterSetterToPropertyPass to
/// convert matching getter/setter pairs to properties.
/// </summary>
public bool GenerateProperties;
/// <summary>
/// If set to true the generator will use GetterSetterToPropertyAdvancedPass to
/// convert matching getter/setter pairs to properties. This pass has slightly
/// different semantics from GetterSetterToPropertyPass, it will more agressively
/// try to match for matching properties.
/// </summary>
public bool GeneratePropertiesAdvanced;
//List of include directories that are used but not generated
public List<string> NoGenIncludeDirs;

2
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -11,7 +11,7 @@ using Type = CppSharp.AST.Type; @@ -11,7 +11,7 @@ using Type = CppSharp.AST.Type;
namespace CppSharp.Passes
{
class GetterSetterToPropertyAdvancedPass : TranslationUnitPass
public class GetterSetterToPropertyAdvancedPass : TranslationUnitPass
{
// collect all types of methods first to be able to match pairs and detect virtuals and overrides;
// (a property needs to) be virtual or an override if either of its constituent methods are such)

16
tests/Basic/Basic.Tests.cs

@ -278,5 +278,21 @@ public class BasicTests : GeneratorTestFixture @@ -278,5 +278,21 @@ public class BasicTests : GeneratorTestFixture
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));
}
[Test]
public unsafe void TestArraysPointers()
{
var values = MyEnum.A;
var arrays = new TestArraysPointers(&values, 1);
Assert.That(arrays.Value, Is.EqualTo(MyEnum.A));
}
[Test]
public unsafe void TestGetterSetterToProperties()
{
var @class = new TestGetterSetterToProperties();
Assert.That(@class.Width, Is.EqualTo(640));
Assert.That(@class.Height, Is.EqualTo(480));
}
}

2
tests/Basic/Basic.cs

@ -18,7 +18,9 @@ namespace CppSharp.Tests @@ -18,7 +18,9 @@ namespace CppSharp.Tests
if (driver.Options.IsCSharpGenerator)
driver.Options.GenerateAbstractImpls = true;
driver.Options.GenerateVirtualTables = true;
driver.Options.GenerateCopyConstructors = true;
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateProperties = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)

19
tests/Basic/Basic.h

@ -367,3 +367,22 @@ struct DLL_API TestProperties @@ -367,3 +367,22 @@ struct DLL_API TestProperties
int getFieldValue() { return Field; }
void setFieldValue(int Value) { Field = Value; }
};
enum struct MyEnum { A, B, C };
class DLL_API TestArraysPointers
{
public:
TestArraysPointers(MyEnum *values, int count)
{
if (values && count) Value = values[0];
}
MyEnum Value;
};
struct DLL_API TestGetterSetterToProperties
{
int getWidth() { return 640; }
int getHeight() { return 480; }
};

3
tests/CSharpTemp/CSharpTemp.cs

@ -60,8 +60,9 @@ namespace CppSharp.Tests @@ -60,8 +60,9 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GenerateProperties = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = true;
driver.Options.GenerateCopyConstructors = true;
driver.TranslationUnitPasses.AddPass(new TestAttributesPass());
}

27
tests/FieldTests.cs

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
using System;
using NUnit.Framework;
namespace Tests {
[TestFixture]
public class FieldTests {
[Test]
public void TestReadCppObject ()
{
var hf1 = new HasField (1, null);
var hf2 = new HasField (2, hf1);
var hf3 = new HasField (3, hf2);
Assert.IsNull (hf1.other, "#1");
Assert.AreEqual (1, hf1.number);
Assert.AreSame (hf2.other, hf1, "#2");
Assert.AreEqual (1, hf2.other.number);
Assert.AreSame (hf3.other.other, hf1, "#3");
Assert.AreEqual (1, hf3.other.other.number, "#4");
}
}
}

166
tests/InheritanceTests.cs

@ -1,166 +0,0 @@ @@ -1,166 +0,0 @@
using System;
using NUnit.Framework;
namespace Tests {
[TestFixture]
public class InheritanceTests {
[Test]
public void TestVirtualCall ()
{
var cls = new NumberClass (5);
Assert.AreEqual (5, cls.Number, "#1");
Assert.AreEqual (-5, cls.NegativeNumber, "#2");
}
[Test]
public void TestVirtualCallOnBaseClass ()
{
var cls = new AdderClass (8);
Assert.AreEqual (8, cls.Number, "#1");
cls.Add (2);
Assert.AreEqual (10, ((NumberClass)cls).Number, "#2");
}
[Test]
public void TestVirtualCallOnVirtualBaseClass ()
{
var cls = new AdderClassWithVirtualBase (8);
Assert.AreEqual (8, cls.Number, "#1");
cls.Add (2);
Assert.AreEqual (10, ((NumberClass)cls).Number, "#2");
}
[Test]
public void TestMultipleBases ()
{
var cls = new ClassWithNonVirtualBases (5, 3);
Assert.AreEqual (5, cls.Number, "#1");
Assert.AreEqual (3, ((MultiplierClass)cls).Number, "#2");
cls.Add (4);
Assert.AreEqual (9, cls.Number, "#3");
Assert.AreEqual (3, ((MultiplierClass)cls).Number, "#4");
cls.MultiplierClass.Multiply (10);
Assert.AreEqual (9, cls.Number, "#5");
Assert.AreEqual (30, ((MultiplierClass)cls).Number, "#6");
}
[Test]
public void TestMultipleVirtualBases ()
{
var cls = new ClassWithVirtualBases (4);
Assert.AreEqual (4, cls.Number, "#1");
Assert.AreEqual (4, ((MultiplierClassWithVirtualBase)cls).Number, "#2");
cls.Add (5);
Assert.AreEqual (9, cls.Number, "#3");
Assert.AreEqual (9, ((MultiplierClassWithVirtualBase)cls).Number, "#4");
cls.MultiplierClassWithVirtualBase.Multiply (6);
Assert.AreEqual (30, cls.Number, "#5");
Assert.AreEqual (30, ((MultiplierClassWithVirtualBase)cls).Number, "#6");
}
[Test]
public void TestNativeOverride1 ()
{
var cls = new ClassThatOverridesStuff (5, 3);
Assert.AreEqual (3, cls.Number, "#1");
Assert.AreEqual (3, ((NumberClass)cls).Number, "#2");
Assert.AreEqual (-3, cls.NegativeNumber, "#3");
Assert.AreEqual (5, cls.BaseNumber, "#4");
}
[Test]
public void TestNativeOverride2 ()
{
var cls = ClassThatOverridesStuff.GetInstance (5, 3);
Assert.AreEqual (3, cls.Number, "#1");
Assert.AreEqual (3, ((NumberClass)cls).Number, "#2");
Assert.AreEqual (-3, cls.NegativeNumber, "#3");
// Assert.AreEqual (5, ((ClassThatOverridesStuff)cls).BaseNumber, "#4");
}
class ManagedOverride1 : NumberClass {
public ManagedOverride1 () : base (3)
{
}
public override int Number {
get {
return 25;
}
}
}
[Test]
public void TestManagedOverride1 ()
{
var cls = new ManagedOverride1 ();
Assert.AreEqual (-25, cls.NegativeNumber, "#1");
}
class ManagedOverride2 : ClassWithNonVirtualBases {
public ManagedOverride2 () : base (5, 3)
{
}
public override int Number {
get {
return 25;
}
}
// override virtual member inherited from non-primary base
protected override void MultiplierClass__Multiply (int n)
{
base.MultiplierClass__Multiply (10);
}
}
[Test]
public void TestManagedOverride2 ()
{
var cls = new ManagedOverride2 ();
Assert.AreEqual (-25, cls.NegativeNumber, "#1");
cls.MultiplierClass.Multiply (7);
Assert.AreEqual (30, ((MultiplierClass)cls).Number, "#3");
cls.CallMultiply (2);
Assert.AreEqual (25, cls.Number, "#2");
Assert.AreEqual (300, ((MultiplierClass)cls).Number, "#5");
}
[Test]
public void TestRoundtripManagedOverride ()
{
var managed = new ManagedOverride2 ();
var roundtripper = new ClassThatRoundtrips (7, managed);
// test primary base ptr from native
var cls = roundtripper.GetThis ();
Assert.AreSame (roundtripper, cls, "#1");
Assert.AreEqual (7, cls.Number, "#2");
// test non-primary base ptr from native
cls = roundtripper.GetThat ();
Assert.AreSame ((MultiplierClass)managed, cls, "#3");
Assert.AreEqual (3, cls.Number, "#4");
Assert.AreEqual (3, cls.Number, "#5");
cls.Multiply (0);
Assert.AreEqual (-30, cls.NegativeNumber, "#6");
// cast to non-primary subclass
Assert.IsNotNull (((ClassWithNonVirtualBases)cls) as ManagedOverride2, "#7");
}
}
}

31
tests/ManglingTests.cs

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
using System;
using NUnit.Framework;
namespace Tests {
[TestFixture]
public class ManglingTests {
[Test]
public void TestCompression ()
{
Compression.Test1 (null, "foo", null, "bar");
}
[Test]
public void TestNamespaced ()
{
Ns1.Namespaced.Test1 ();
Ns1.Namespaced.Test2 (null);
}
[Test]
public void TestNamespaced2 ()
{
var cls = new Ns1.Ns2.Namespaced2 ();
cls.Test1 ();
cls.Test2 (null);
}
}
}

74
tests/MarshalingTests.cs

@ -1,74 +0,0 @@ @@ -1,74 +0,0 @@
using System;
using NUnit.Framework;
namespace Tests {
[TestFixture]
public class MarshalingTests {
[Test]
public void TestClassReturn ()
{
// Section 3.1.4:
// Classes with non-default copy ctors/destructors are returned using a hidden
// argument
var c = ClassWithCopyCtor.Return (42);
Assert.AreEqual (42, c.GetX (), "#1");
var c2 = ClassWithDtor.Return (43);
Assert.AreEqual (43, c2.GetX (), "#2");
// This class is returned normally
var c3 = ClassWithoutCopyCtor.Return (44);
Assert.AreEqual (44, c3.GetX (), "#3");
}
// An object as ref argument
[Test]
public void TestClassArg ()
{
var c1 = new Class (4);
var c2 = new Class (5);
c1.CopyTo (c2);
Assert.AreEqual (4, c2.GetX (), "#1");
}
// A null object as ref argument
[Test]
public void TestClassArgNull ()
{
var c1 = new Class (4);
Assert.That (c1.IsNull (null), "#1");
}
// An object as byval argument
[Test]
public void TestClassArgByval ()
{
var c1 = new Class (4);
var c2 = new Class (5);
c1.CopyFromValue (c2);
Assert.AreEqual (5, c1.GetX (), "#1");
}
// A null object as byval argument
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TestClassArgByvalNull ()
{
var c1 = new Class (4);
c1.CopyFromValue (null);
}
[Test]
public void TestByRefReturn ()
{
var c1 = new Class (7);
Assert.AreEqual (7, c1.GetXRef ());
}
}
}

8
tests/Native/FieldTests.cpp

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
#include "FieldTests.h"
HasField::HasField (int number, HasField* other)
{
this->number = number;
this->other = other;
}

7
tests/Native/FieldTests.h

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
class HasField {
public:
int number;
HasField* other;
HasField (int number, HasField* other);
};

79
tests/Native/InheritanceTests.cpp

@ -1,79 +0,0 @@ @@ -1,79 +0,0 @@
#include "InheritanceTests.h"
NumberClass::NumberClass (int n)
: num (n)
{
}
int NumberClass::Number () const
{
return this->num;
}
int NumberClass::NegativeNumber () const
{
return -(this->Number ());
}
NumberClass::~NumberClass ()
{
this->num = 0;
}
AdderClass::AdderClass (int n)
: NumberClass (n)
{
}
void AdderClass::Add (int n)
{
this->num += n;
}
AdderClassWithVirtualBase::AdderClassWithVirtualBase (int n)
: NumberClass (n)
{
}
void AdderClassWithVirtualBase::Add (int n)
{
this->num += n;
}
MultiplierClass::MultiplierClass (int n)
: NumberClass (n)
{
}
void MultiplierClass::Multiply (int n)
{
this->num *= n;
}
MultiplierClassWithVirtualBase::MultiplierClassWithVirtualBase (int n)
: NumberClass (n)
{
}
void MultiplierClassWithVirtualBase::Multiply (int n)
{
this->num *= n;
}
ClassThatOverridesStuff::ClassThatOverridesStuff (int num, int my)
: NumberClass (num), myNum (my)
{
}
int ClassThatOverridesStuff::Number () const
{
return this->myNum;
}
int ClassThatOverridesStuff::BaseNumber () const
{
return this->NumberClass::Number ();
}
ClassThatOverridesStuff::~ClassThatOverridesStuff ()
{
this->myNum = 0;
}
NumberClass* ClassThatOverridesStuff::GetInstance (int num, int my)
{
return new ClassThatOverridesStuff (num, my);
}

65
tests/Native/InheritanceTests.h

@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
class NumberClass {
protected:
int num;
public:
NumberClass (int n);
virtual int NegativeNumber () const;
virtual int Number () const;
virtual ~NumberClass ();
};
class AdderClass : public NumberClass {
public:
AdderClass (int n);
virtual void Add (int n);
};
class AdderClassWithVirtualBase : public virtual NumberClass {
public:
AdderClassWithVirtualBase (int n);
virtual void Add (int n);
};
class MultiplierClass : public NumberClass {
public:
MultiplierClass (int n);
virtual void Multiply (int n);
};
class MultiplierClassWithVirtualBase : public virtual NumberClass {
public:
MultiplierClassWithVirtualBase (int n);
virtual void Multiply (int n);
};
class ClassWithNonVirtualBases : public AdderClass, public MultiplierClass {
public:
// num is not shared between AdderClass and MultiplierClass; Add and Multiply should operate on different numbers
ClassWithNonVirtualBases (int addN, int multN) : AdderClass (addN), MultiplierClass (multN) {}
virtual void CallMultiply (int n) { this->Multiply (n); }
};
class ClassWithVirtualBases : public AdderClassWithVirtualBase, public MultiplierClassWithVirtualBase {
public:
// num is shared between AdderClass and MultiplierClass; Add and Multiply should both operate on n
ClassWithVirtualBases (int n) : NumberClass (n-2), AdderClassWithVirtualBase (n-1), MultiplierClassWithVirtualBase (n) {}
};
class ClassThatOverridesStuff : public NumberClass {
protected:
int myNum;
public:
ClassThatOverridesStuff (int num, int my);
virtual int Number () const;
virtual ~ClassThatOverridesStuff ();
virtual int BaseNumber () const;
static NumberClass* GetInstance (int num, int my);
};
class ClassThatRoundtrips : public MultiplierClass {
protected:
MultiplierClass* that;
public:
ClassThatRoundtrips (int n, MultiplierClass* managed) : MultiplierClass (n) { this->that = managed; }
virtual MultiplierClass* GetThat () { return this->that; }
virtual MultiplierClass* GetThis () { return this; }
};

33
tests/Native/ManglingTests.cpp

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
#include "ManglingTests.h"
#include <stdio.h>
void Compression::Test1 (const Compression* a1, const char* a2, const Compression* a3, const char* a4)
{
printf ("Compression::Test1");
}
void Ns1::Namespaced::Test1 ()
{
printf ("Ns1::Namespaced::Test1");
}
void Ns1::Namespaced::Test2 (const Compression* a1)
{
printf ("Ns1::Namespaced::Test2");
}
Ns1::Ns2::Namespaced2::Namespaced2 ()
{
printf ("Ns1::Ns2::Namespaced2::Namespaced2");
}
void Ns1::Ns2::Namespaced2::Test1 ()
{
printf ("Ns1::Ns2::Namespaced2::Test1");
}
Ns1::Ns2::Namespaced2* Ns1::Ns2::Namespaced2::Test2 (Compression* a1)
{
printf ("Ns1::Ns2::Namespaced2::Test2");
}

22
tests/Native/ManglingTests.h

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
class Compression {
public:
static void Test1 (const Compression* a1, const char* a2, const Compression* a3, const char* a4);
};
namespace Ns1 {
class Namespaced {
public:
static void Test1 ();
static void Test2 (const Compression* a1);
};
}
namespace Ns1 { namespace Ns2 {
class Namespaced2 {
public:
Namespaced2 ();
void Test1 ();
Namespaced2* Test2 (Compression* a1);
};
}}

36
tests/Native/MarshalingTests.cpp

@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
#include "MarshalingTests.h"
ClassWithCopyCtor::ClassWithCopyCtor(const ClassWithCopyCtor& f) {
x = f.x;
}
ClassWithCopyCtor
ClassWithCopyCtor::Return (int x) {
return ClassWithCopyCtor (x);
}
int
ClassWithCopyCtor::GetX () {
return x;
}
ClassWithDtor
ClassWithDtor::Return (int x) {
return ClassWithDtor (x);
}
int
ClassWithDtor::GetX () {
return x;
}
ClassWithoutCopyCtor
ClassWithoutCopyCtor::Return (int x) {
return ClassWithoutCopyCtor (x);
}
int
ClassWithoutCopyCtor::GetX () {
return x;
}

77
tests/Native/MarshalingTests.h

@ -1,77 +0,0 @@ @@ -1,77 +0,0 @@
class ClassWithCopyCtor {
int x;
public:
ClassWithCopyCtor(int xarg) {
x = xarg;
}
ClassWithCopyCtor(const ClassWithCopyCtor& f);
static ClassWithCopyCtor Return (int x);
int GetX ();
};
class ClassWithDtor {
int x;
public:
ClassWithDtor(int xarg) {
x = xarg;
}
~ClassWithDtor () {
}
static ClassWithDtor Return (int x);
int GetX ();
};
class ClassWithoutCopyCtor {
int x;
public:
ClassWithoutCopyCtor(int xarg) {
x = xarg;
}
static ClassWithoutCopyCtor Return (int x);
int GetX ();
};
class Class {
int x;
public:
Class (int xarg) {
x = xarg;
}
void CopyFromValue (Class c) {
x = c.x;
}
void CopyTo (Class *c) {
c->x = x;
}
bool IsNull (Class *c) {
return !c ? true : false;
}
int GetX () {
return x;
}
int& GetXRef () {
return x;
}
};

21
tests/Native/NUnit.cpp

@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
//
// NUnit.cpp: Bridges the NUnit Assert methods to C++
//
// Author:
// Alexander Corrado (alexander.corrado@gmail.com)
//
// Copyright (C) 2010 Alexander Corrado
//
#include "NUnit.h"
NUnit* NUnit::Assert;
extern "C" {
void SetNUnitInterface (NUnit* nunit)
{
NUnit::Assert = nunit;
}
}

114
tests/Native/NUnit.h

@ -1,114 +0,0 @@ @@ -1,114 +0,0 @@
//
// NUnit.h: The NUnit C++ interface
//
// Author:
// Alexander Corrado (alexander.corrado@gmail.com)
//
// Copyright (C) 2010 Alexander Corrado
//
#ifndef _CPPINTEROP_NUNIT_H_
#define _CPPINTEROP_NUNIT_H_
#ifdef __GNUC__
#define EXPORT
#elif defined(_MSC_VER)
#define EXPORT __declspec(dllexport)
#else
#error Unknown compiler!
#endif
typedef const char* string;
typedef unsigned int uint;
typedef unsigned long ulong;
class NUnit {
public:
static NUnit* Assert;
virtual void Fail (string message);
virtual void Fail ();
virtual void IsTrue (bool condition, string message);
virtual void IsTrue (bool condition);
virtual void IsFalse (bool condition, string message);
virtual void IsFalse (bool condition);
virtual void IsEmpty (string aString, string message);
virtual void IsEmpty (string aString);
virtual void IsNotEmpty (string aString, string message);
virtual void IsNotEmpty (string aString);
virtual void AreEqual (int expected, int actual, string message);
virtual void AreEqual (int expected, int actual);
virtual void AreEqual (long expected, long actual, string message);
virtual void AreEqual (long expected, long actual);
virtual void AreEqual (uint expected, uint actual, string message);
virtual void AreEqual (uint expected, uint actual);
virtual void AreEqual (ulong expected, ulong actual, string message);
virtual void AreEqual (ulong expected, ulong actual);
virtual void AreEqual (double expected, double actual, double delta, string message);
virtual void AreEqual (double expected, double actual, double delta);
virtual void AreEqual (float expected, float actual, float delta, string message);
virtual void AreEqual (float expected, float actual, float delta);
virtual void AreNotEqual (int expected, int actual, string message);
virtual void AreNotEqual (int expected, int actual);
virtual void AreNotEqual (long expected, long actual, string message);
virtual void AreNotEqual (long expected, long actual);
virtual void AreNotEqual (uint expected, uint actual, string message);
virtual void AreNotEqual (uint expected, uint actual);
virtual void AreNotEqual (ulong expected, ulong actual, string message);
virtual void AreNotEqual (ulong expected, ulong actual);
virtual void AreNotEqual (double expected, double actual, string message);
virtual void AreNotEqual (double expected, double actual);
virtual void AreNotEqual (float expected, float actual, string message);
virtual void AreNotEqual (float expected, float actual);
virtual void Greater (int expected, int actual, string message);
virtual void Greater (int expected, int actual);
virtual void Greater (long expected, long actual, string message);
virtual void Greater (long expected, long actual);
virtual void Greater (uint expected, uint actual, string message);
virtual void Greater (uint expected, uint actual);
virtual void Greater (ulong expected, ulong actual, string message);
virtual void Greater (ulong expected, ulong actual);
virtual void Greater (double expected, double actual, string message);
virtual void Greater (double expected, double actual);
virtual void Greater (float expected, float actual, string message);
virtual void Greater (float expected, float actual);
virtual void Less (int expected, int actual, string message);
virtual void Less (int expected, int actual);
virtual void Less (long expected, long actual, string message);
virtual void Less (long expected, long actual);
virtual void Less (uint expected, uint actual, string message);
virtual void Less (uint expected, uint actual);
virtual void Less (ulong expected, ulong actual, string message);
virtual void Less (ulong expected, ulong actual);
virtual void Less (double expected, double actual, string message);
virtual void Less (double expected, double actual);
virtual void Less (float expected, float actual, string message);
virtual void Less (float expected, float actual);
virtual void GreaterOrEqual (int expected, int actual, string message);
virtual void GreaterOrEqual (int expected, int actual);
virtual void GreaterOrEqual (long expected, long actual, string message);
virtual void GreaterOrEqual (long expected, long actual);
virtual void GreaterOrEqual (uint expected, uint actual, string message);
virtual void GreaterOrEqual (uint expected, uint actual);
virtual void GreaterOrEqual (ulong expected, ulong actual, string message);
virtual void GreaterOrEqual (ulong expected, ulong actual);
virtual void GreaterOrEqual (double expected, double actual, string message);
virtual void GreaterOrEqual (double expected, double actual);
virtual void GreaterOrEqual (float expected, float actual, string message);
virtual void GreaterOrEqual (float expected, float actual);
virtual void LessOrEqual (int expected, int actual, string message);
virtual void LessOrEqual (int expected, int actual);
virtual void LessOrEqual (long expected, long actual, string message);
virtual void LessOrEqual (long expected, long actual);
virtual void LessOrEqual (uint expected, uint actual, string message);
virtual void LessOrEqual (uint expected, uint actual);
virtual void LessOrEqual (ulong expected, ulong actual, string message);
virtual void LessOrEqual (ulong expected, ulong actual);
virtual void LessOrEqual (double expected, double actual, string message);
virtual void LessOrEqual (double expected, double actual);
virtual void LessOrEqual (float expected, float actual, string message);
virtual void LessOrEqual (float expected, float actual);
};
#endif /* _CPPINTEROP_NUNIT_H_ */
Loading…
Cancel
Save