Browse Source

Normalize all the line endings

Normalized all the line endings with:

git rm --cached -r .
git reset --hard
git add .
git commit -m "Normalize all the line endings"

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
pull/249/head
Tomi Valkeinen 11 years ago
parent
commit
4e185973e5
  1. 42
      src/AST/Class.cs
  2. 16
      src/AST/Field.cs
  3. 36
      src/AST/TranslationUnit.cs
  4. 5688
      src/CppParser/Bindings/CLI/AST.cpp
  5. 3750
      src/CppParser/Bindings/CLI/AST.h
  6. 878
      src/CppParser/Bindings/CLI/CppParser.cpp
  7. 566
      src/CppParser/Bindings/CLI/CppParser.h
  8. 54
      src/Generator/AST/Utils.cs
  9. 72
      src/Generator/Driver.cs
  10. 34
      src/Generator/Generator.lua
  11. 88
      src/Generator/Generators/CLI/CLIMarshal.cs
  12. 6
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  13. 796
      src/Generator/Generators/CLI/CLITypePrinter.cs
  14. 60
      src/Generator/Generators/CLI/CLITypeReferences.cs
  15. 404
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  16. 1172
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  17. 54
      src/Generator/Generators/ExtensionMethods.cs
  18. 42
      src/Generator/Generators/Template.cs
  19. 72
      src/Generator/Options.cs
  20. 448
      src/Generator/Passes/CheckOperatorsOverloads.cs
  21. 116
      src/Generator/Passes/ConstructorToConversionOperatorPass.cs
  22. 12
      src/Generator/Passes/GenerateAbstractImplementationsPass.cs
  23. 18
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  24. 10
      src/Generator/Passes/MultipleInheritancePass.cs
  25. 660
      src/Generator/Types/CppTypePrinter.cs
  26. 48
      src/Generator/Types/Types.cs
  27. 30
      src/Generator/Utils/Utils.cs
  28. 104
      tests/Basic/Basic.Tests.cs
  29. 2
      tests/Basic/Basic.cs
  30. 214
      tests/Basic/Basic.h
  31. 6
      tests/CSharpTemp/CSharpTemp.cs

42
src/AST/Class.cs

@ -33,7 +33,7 @@ namespace CppSharp.AST @@ -33,7 +33,7 @@ namespace CppSharp.AST
{
get
{
Class @class;
Class @class;
Type.TryGetClass(out @class);
return @class;
}
@ -115,26 +115,26 @@ namespace CppSharp.AST @@ -115,26 +115,26 @@ namespace CppSharp.AST
Layout = new ClassLayout();
}
public Class(Class @class)
: base(@class)
{
Bases = new List<BaseClassSpecifier>(@class.Bases);
Fields = new List<Field>(@class.Fields);
Properties = new List<Property>(@class.Properties);
Methods = new List<Method>(@class.Methods);
Specifiers = new List<AccessSpecifierDecl>(@class.Specifiers);
IsPOD = @class.IsPOD;
Type = @class.Type;
Layout = new ClassLayout(@class.Layout);
IsAbstract = @class.IsAbstract;
IsUnion = @class.IsUnion;
IsOpaque = @class.IsOpaque;
IsDynamic = @class.IsDynamic;
IsPolymorphic = @class.IsPolymorphic;
HasNonTrivialDefaultConstructor = @class.HasNonTrivialDefaultConstructor;
HasNonTrivialCopyConstructor = @class.HasNonTrivialCopyConstructor;
HasNonTrivialDestructor = @class.HasNonTrivialDestructor;
IsStatic = @class.IsStatic;
public Class(Class @class)
: base(@class)
{
Bases = new List<BaseClassSpecifier>(@class.Bases);
Fields = new List<Field>(@class.Fields);
Properties = new List<Property>(@class.Properties);
Methods = new List<Method>(@class.Methods);
Specifiers = new List<AccessSpecifierDecl>(@class.Specifiers);
IsPOD = @class.IsPOD;
Type = @class.Type;
Layout = new ClassLayout(@class.Layout);
IsAbstract = @class.IsAbstract;
IsUnion = @class.IsUnion;
IsOpaque = @class.IsOpaque;
IsDynamic = @class.IsDynamic;
IsPolymorphic = @class.IsPolymorphic;
HasNonTrivialDefaultConstructor = @class.HasNonTrivialDefaultConstructor;
HasNonTrivialCopyConstructor = @class.HasNonTrivialCopyConstructor;
HasNonTrivialDestructor = @class.HasNonTrivialDestructor;
IsStatic = @class.IsStatic;
}
public bool HasBase

16
src/AST/Field.cs

@ -29,14 +29,14 @@ namespace CppSharp.AST @@ -29,14 +29,14 @@ namespace CppSharp.AST
QualifiedType = type;
Access = access;
Offset = 0;
}
public Field(Field field): base(field)
{
QualifiedType = field.QualifiedType;
Offset = field.Offset;
Class = field.Class;
Expression = field.Expression;
}
public Field(Field field): base(field)
{
QualifiedType = field.QualifiedType;
Offset = field.Offset;
Class = field.Class;
Expression = field.Expression;
}
public override T Visit<T>(IDeclVisitor<T> visitor)

36
src/AST/TranslationUnit.cs

@ -45,23 +45,23 @@ namespace CppSharp.AST @@ -45,23 +45,23 @@ namespace CppSharp.AST
/// Contains the include path.
public string IncludePath;
public string FileRelativeDirectory
{
get
{
var path = IncludePath.Replace('\\', '/');
var index = path.LastIndexOf('/');
return path.Substring(0, index);
}
}
public string FileRelativePath
{
get
{
return Path.Combine(FileRelativeDirectory, FileName);
}
}
public string FileRelativeDirectory
{
get
{
var path = IncludePath.Replace('\\', '/');
var index = path.LastIndexOf('/');
return path.Substring(0, index);
}
}
public string FileRelativePath
{
get
{
return Path.Combine(FileRelativeDirectory, FileName);
}
}
}
}

5688
src/CppParser/Bindings/CLI/AST.cpp

File diff suppressed because it is too large Load Diff

3750
src/CppParser/Bindings/CLI/AST.h

File diff suppressed because it is too large Load Diff

878
src/CppParser/Bindings/CLI/CppParser.cpp

@ -1,439 +1,439 @@ @@ -1,439 +1,439 @@
#include "CppParser.h"
#include "AST.h"
#include "Target.h"
using namespace System;
using namespace System::Runtime::InteropServices;
CppSharp::Parser::ParserOptions::ParserOptions(::CppSharp::CppParser::ParserOptions* native)
{
NativePtr = native;
}
CppSharp::Parser::ParserOptions::ParserOptions(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ParserOptions*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserOptions::ParserOptions()
{
NativePtr = new ::CppSharp::CppParser::ParserOptions();
}
System::String^ CppSharp::Parser::ParserOptions::getArguments(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getArguments(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addArguments(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addArguments(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getIncludeDirs(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getIncludeDirs(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addIncludeDirs(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addIncludeDirs(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getSystemIncludeDirs(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getSystemIncludeDirs(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addSystemIncludeDirs(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addSystemIncludeDirs(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getDefines(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getDefines(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addDefines(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addDefines(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getLibraryDirs(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getLibraryDirs(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addLibraryDirs(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addLibraryDirs(arg0);
}
System::IntPtr CppSharp::Parser::ParserOptions::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ParserOptions::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ParserOptions*)object.ToPointer();
}
unsigned int CppSharp::Parser::ParserOptions::ArgumentsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getArgumentsCount();
return __ret;
}
System::String^ CppSharp::Parser::ParserOptions::FileName::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getFileName();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::FileName::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->setFileName(arg0);
}
unsigned int CppSharp::Parser::ParserOptions::IncludeDirsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getIncludeDirsCount();
return __ret;
}
unsigned int CppSharp::Parser::ParserOptions::SystemIncludeDirsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getSystemIncludeDirsCount();
return __ret;
}
unsigned int CppSharp::Parser::ParserOptions::DefinesCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getDefinesCount();
return __ret;
}
unsigned int CppSharp::Parser::ParserOptions::LibraryDirsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getLibraryDirsCount();
return __ret;
}
System::String^ CppSharp::Parser::ParserOptions::TargetTriple::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getTargetTriple();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::TargetTriple::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->setTargetTriple(arg0);
}
CppSharp::Parser::AST::ASTContext^ CppSharp::Parser::ParserOptions::ASTContext::get()
{
return (((::CppSharp::CppParser::ParserOptions*)NativePtr)->ASTContext == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ASTContext((::CppSharp::CppParser::AST::ASTContext*)((::CppSharp::CppParser::ParserOptions*)NativePtr)->ASTContext);
}
void CppSharp::Parser::ParserOptions::ASTContext::set(CppSharp::Parser::AST::ASTContext^ value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->ASTContext = (::CppSharp::CppParser::AST::ASTContext*)value->NativePtr;
}
int CppSharp::Parser::ParserOptions::ToolSetToUse::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->ToolSetToUse;
}
void CppSharp::Parser::ParserOptions::ToolSetToUse::set(int value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->ToolSetToUse = value;
}
CppSharp::Parser::AST::CppAbi CppSharp::Parser::ParserOptions::Abi::get()
{
return (CppSharp::Parser::AST::CppAbi)((::CppSharp::CppParser::ParserOptions*)NativePtr)->Abi;
}
void CppSharp::Parser::ParserOptions::Abi::set(CppSharp::Parser::AST::CppAbi value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->Abi = (::CppSharp::CppParser::AST::CppAbi)value;
}
bool CppSharp::Parser::ParserOptions::NoStandardIncludes::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoStandardIncludes;
}
void CppSharp::Parser::ParserOptions::NoStandardIncludes::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoStandardIncludes = value;
}
bool CppSharp::Parser::ParserOptions::NoBuiltinIncludes::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoBuiltinIncludes;
}
void CppSharp::Parser::ParserOptions::NoBuiltinIncludes::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoBuiltinIncludes = value;
}
bool CppSharp::Parser::ParserOptions::MicrosoftMode::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->MicrosoftMode;
}
void CppSharp::Parser::ParserOptions::MicrosoftMode::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->MicrosoftMode = value;
}
bool CppSharp::Parser::ParserOptions::Verbose::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->Verbose;
}
void CppSharp::Parser::ParserOptions::Verbose::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->Verbose = value;
}
CppSharp::Parser::ParserDiagnostic::ParserDiagnostic(::CppSharp::CppParser::ParserDiagnostic* native)
{
NativePtr = native;
}
CppSharp::Parser::ParserDiagnostic::ParserDiagnostic(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ParserDiagnostic*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserDiagnostic::ParserDiagnostic()
{
NativePtr = new ::CppSharp::CppParser::ParserDiagnostic();
}
System::IntPtr CppSharp::Parser::ParserDiagnostic::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ParserDiagnostic::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ParserDiagnostic*)object.ToPointer();
}
System::String^ CppSharp::Parser::ParserDiagnostic::FileName::get()
{
auto __ret = ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->getFileName();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserDiagnostic::FileName::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->setFileName(arg0);
}
System::String^ CppSharp::Parser::ParserDiagnostic::Message::get()
{
auto __ret = ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->getMessage();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserDiagnostic::Message::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->setMessage(arg0);
}
CppSharp::Parser::ParserDiagnosticLevel CppSharp::Parser::ParserDiagnostic::Level::get()
{
return (CppSharp::Parser::ParserDiagnosticLevel)((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->Level;
}
void CppSharp::Parser::ParserDiagnostic::Level::set(CppSharp::Parser::ParserDiagnosticLevel value)
{
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->Level = (::CppSharp::CppParser::ParserDiagnosticLevel)value;
}
int CppSharp::Parser::ParserDiagnostic::LineNumber::get()
{
return ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->LineNumber;
}
void CppSharp::Parser::ParserDiagnostic::LineNumber::set(int value)
{
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->LineNumber = value;
}
int CppSharp::Parser::ParserDiagnostic::ColumnNumber::get()
{
return ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->ColumnNumber;
}
void CppSharp::Parser::ParserDiagnostic::ColumnNumber::set(int value)
{
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->ColumnNumber = value;
}
CppSharp::Parser::ParserResult::ParserResult(::CppSharp::CppParser::ParserResult* native)
{
NativePtr = native;
}
CppSharp::Parser::ParserResult::ParserResult(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ParserResult*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserResult::ParserResult()
{
NativePtr = new ::CppSharp::CppParser::ParserResult();
}
CppSharp::Parser::ParserDiagnostic^ CppSharp::Parser::ParserResult::getDiagnostics(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserResult*)NativePtr)->getDiagnostics(i);
auto ____ret = new ::CppSharp::CppParser::ParserDiagnostic(__ret);
return (____ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserDiagnostic((::CppSharp::CppParser::ParserDiagnostic*)____ret);
}
void CppSharp::Parser::ParserResult::addDiagnostics(CppSharp::Parser::ParserDiagnostic^ s)
{
auto &arg0 = *(::CppSharp::CppParser::ParserDiagnostic*)s->NativePtr;
((::CppSharp::CppParser::ParserResult*)NativePtr)->addDiagnostics(arg0);
}
System::IntPtr CppSharp::Parser::ParserResult::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ParserResult::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ParserResult*)object.ToPointer();
}
unsigned int CppSharp::Parser::ParserResult::DiagnosticsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserResult*)NativePtr)->getDiagnosticsCount();
return __ret;
}
CppSharp::Parser::ParserResultKind CppSharp::Parser::ParserResult::Kind::get()
{
return (CppSharp::Parser::ParserResultKind)((::CppSharp::CppParser::ParserResult*)NativePtr)->Kind;
}
void CppSharp::Parser::ParserResult::Kind::set(CppSharp::Parser::ParserResultKind value)
{
((::CppSharp::CppParser::ParserResult*)NativePtr)->Kind = (::CppSharp::CppParser::ParserResultKind)value;
}
CppSharp::Parser::AST::ASTContext^ CppSharp::Parser::ParserResult::ASTContext::get()
{
return (((::CppSharp::CppParser::ParserResult*)NativePtr)->ASTContext == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ASTContext((::CppSharp::CppParser::AST::ASTContext*)((::CppSharp::CppParser::ParserResult*)NativePtr)->ASTContext);
}
void CppSharp::Parser::ParserResult::ASTContext::set(CppSharp::Parser::AST::ASTContext^ value)
{
((::CppSharp::CppParser::ParserResult*)NativePtr)->ASTContext = (::CppSharp::CppParser::AST::ASTContext*)value->NativePtr;
}
CppSharp::Parser::AST::NativeLibrary^ CppSharp::Parser::ParserResult::Library::get()
{
return (((::CppSharp::CppParser::ParserResult*)NativePtr)->Library == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::NativeLibrary((::CppSharp::CppParser::AST::NativeLibrary*)((::CppSharp::CppParser::ParserResult*)NativePtr)->Library);
}
void CppSharp::Parser::ParserResult::Library::set(CppSharp::Parser::AST::NativeLibrary^ value)
{
((::CppSharp::CppParser::ParserResult*)NativePtr)->Library = (::CppSharp::CppParser::AST::NativeLibrary*)value->NativePtr;
}
CppSharp::Parser::ClangParser::ClangParser(::CppSharp::CppParser::ClangParser* native)
{
NativePtr = native;
}
CppSharp::Parser::ClangParser::ClangParser(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ClangParser*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserResult^ CppSharp::Parser::ClangParser::ParseHeader(CppSharp::Parser::ParserOptions^ Opts)
{
auto arg0 = (::CppSharp::CppParser::ParserOptions*)Opts->NativePtr;
auto __ret = ::CppSharp::CppParser::ClangParser::ParseHeader(arg0);
if (__ret == nullptr) return nullptr;
return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserResult((::CppSharp::CppParser::ParserResult*)__ret);
}
CppSharp::Parser::ParserResult^ CppSharp::Parser::ClangParser::ParseLibrary(CppSharp::Parser::ParserOptions^ Opts)
{
auto arg0 = (::CppSharp::CppParser::ParserOptions*)Opts->NativePtr;
auto __ret = ::CppSharp::CppParser::ClangParser::ParseLibrary(arg0);
if (__ret == nullptr) return nullptr;
return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserResult((::CppSharp::CppParser::ParserResult*)__ret);
}
CppSharp::Parser::ParserTargetInfo^ CppSharp::Parser::ClangParser::GetTargetInfo(CppSharp::Parser::ParserOptions^ Opts)
{
auto arg0 = (::CppSharp::CppParser::ParserOptions*)Opts->NativePtr;
auto __ret = ::CppSharp::CppParser::ClangParser::GetTargetInfo(arg0);
if (__ret == nullptr) return nullptr;
return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserTargetInfo((::CppSharp::CppParser::ParserTargetInfo*)__ret);
}
CppSharp::Parser::ClangParser::ClangParser()
{
NativePtr = new ::CppSharp::CppParser::ClangParser();
}
System::IntPtr CppSharp::Parser::ClangParser::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ClangParser::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ClangParser*)object.ToPointer();
}
#include "CppParser.h"
#include "AST.h"
#include "Target.h"
using namespace System;
using namespace System::Runtime::InteropServices;
CppSharp::Parser::ParserOptions::ParserOptions(::CppSharp::CppParser::ParserOptions* native)
{
NativePtr = native;
}
CppSharp::Parser::ParserOptions::ParserOptions(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ParserOptions*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserOptions::ParserOptions()
{
NativePtr = new ::CppSharp::CppParser::ParserOptions();
}
System::String^ CppSharp::Parser::ParserOptions::getArguments(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getArguments(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addArguments(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addArguments(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getIncludeDirs(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getIncludeDirs(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addIncludeDirs(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addIncludeDirs(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getSystemIncludeDirs(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getSystemIncludeDirs(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addSystemIncludeDirs(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addSystemIncludeDirs(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getDefines(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getDefines(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addDefines(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addDefines(arg0);
}
System::String^ CppSharp::Parser::ParserOptions::getLibraryDirs(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getLibraryDirs(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::addLibraryDirs(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->addLibraryDirs(arg0);
}
System::IntPtr CppSharp::Parser::ParserOptions::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ParserOptions::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ParserOptions*)object.ToPointer();
}
unsigned int CppSharp::Parser::ParserOptions::ArgumentsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getArgumentsCount();
return __ret;
}
System::String^ CppSharp::Parser::ParserOptions::FileName::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getFileName();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::FileName::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->setFileName(arg0);
}
unsigned int CppSharp::Parser::ParserOptions::IncludeDirsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getIncludeDirsCount();
return __ret;
}
unsigned int CppSharp::Parser::ParserOptions::SystemIncludeDirsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getSystemIncludeDirsCount();
return __ret;
}
unsigned int CppSharp::Parser::ParserOptions::DefinesCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getDefinesCount();
return __ret;
}
unsigned int CppSharp::Parser::ParserOptions::LibraryDirsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getLibraryDirsCount();
return __ret;
}
System::String^ CppSharp::Parser::ParserOptions::TargetTriple::get()
{
auto __ret = ((::CppSharp::CppParser::ParserOptions*)NativePtr)->getTargetTriple();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserOptions::TargetTriple::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserOptions*)NativePtr)->setTargetTriple(arg0);
}
CppSharp::Parser::AST::ASTContext^ CppSharp::Parser::ParserOptions::ASTContext::get()
{
return (((::CppSharp::CppParser::ParserOptions*)NativePtr)->ASTContext == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ASTContext((::CppSharp::CppParser::AST::ASTContext*)((::CppSharp::CppParser::ParserOptions*)NativePtr)->ASTContext);
}
void CppSharp::Parser::ParserOptions::ASTContext::set(CppSharp::Parser::AST::ASTContext^ value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->ASTContext = (::CppSharp::CppParser::AST::ASTContext*)value->NativePtr;
}
int CppSharp::Parser::ParserOptions::ToolSetToUse::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->ToolSetToUse;
}
void CppSharp::Parser::ParserOptions::ToolSetToUse::set(int value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->ToolSetToUse = value;
}
CppSharp::Parser::AST::CppAbi CppSharp::Parser::ParserOptions::Abi::get()
{
return (CppSharp::Parser::AST::CppAbi)((::CppSharp::CppParser::ParserOptions*)NativePtr)->Abi;
}
void CppSharp::Parser::ParserOptions::Abi::set(CppSharp::Parser::AST::CppAbi value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->Abi = (::CppSharp::CppParser::AST::CppAbi)value;
}
bool CppSharp::Parser::ParserOptions::NoStandardIncludes::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoStandardIncludes;
}
void CppSharp::Parser::ParserOptions::NoStandardIncludes::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoStandardIncludes = value;
}
bool CppSharp::Parser::ParserOptions::NoBuiltinIncludes::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoBuiltinIncludes;
}
void CppSharp::Parser::ParserOptions::NoBuiltinIncludes::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->NoBuiltinIncludes = value;
}
bool CppSharp::Parser::ParserOptions::MicrosoftMode::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->MicrosoftMode;
}
void CppSharp::Parser::ParserOptions::MicrosoftMode::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->MicrosoftMode = value;
}
bool CppSharp::Parser::ParserOptions::Verbose::get()
{
return ((::CppSharp::CppParser::ParserOptions*)NativePtr)->Verbose;
}
void CppSharp::Parser::ParserOptions::Verbose::set(bool value)
{
((::CppSharp::CppParser::ParserOptions*)NativePtr)->Verbose = value;
}
CppSharp::Parser::ParserDiagnostic::ParserDiagnostic(::CppSharp::CppParser::ParserDiagnostic* native)
{
NativePtr = native;
}
CppSharp::Parser::ParserDiagnostic::ParserDiagnostic(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ParserDiagnostic*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserDiagnostic::ParserDiagnostic()
{
NativePtr = new ::CppSharp::CppParser::ParserDiagnostic();
}
System::IntPtr CppSharp::Parser::ParserDiagnostic::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ParserDiagnostic::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ParserDiagnostic*)object.ToPointer();
}
System::String^ CppSharp::Parser::ParserDiagnostic::FileName::get()
{
auto __ret = ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->getFileName();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserDiagnostic::FileName::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->setFileName(arg0);
}
System::String^ CppSharp::Parser::ParserDiagnostic::Message::get()
{
auto __ret = ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->getMessage();
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::ParserDiagnostic::Message::set(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->setMessage(arg0);
}
CppSharp::Parser::ParserDiagnosticLevel CppSharp::Parser::ParserDiagnostic::Level::get()
{
return (CppSharp::Parser::ParserDiagnosticLevel)((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->Level;
}
void CppSharp::Parser::ParserDiagnostic::Level::set(CppSharp::Parser::ParserDiagnosticLevel value)
{
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->Level = (::CppSharp::CppParser::ParserDiagnosticLevel)value;
}
int CppSharp::Parser::ParserDiagnostic::LineNumber::get()
{
return ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->LineNumber;
}
void CppSharp::Parser::ParserDiagnostic::LineNumber::set(int value)
{
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->LineNumber = value;
}
int CppSharp::Parser::ParserDiagnostic::ColumnNumber::get()
{
return ((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->ColumnNumber;
}
void CppSharp::Parser::ParserDiagnostic::ColumnNumber::set(int value)
{
((::CppSharp::CppParser::ParserDiagnostic*)NativePtr)->ColumnNumber = value;
}
CppSharp::Parser::ParserResult::ParserResult(::CppSharp::CppParser::ParserResult* native)
{
NativePtr = native;
}
CppSharp::Parser::ParserResult::ParserResult(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ParserResult*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserResult::ParserResult()
{
NativePtr = new ::CppSharp::CppParser::ParserResult();
}
CppSharp::Parser::ParserDiagnostic^ CppSharp::Parser::ParserResult::getDiagnostics(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::ParserResult*)NativePtr)->getDiagnostics(i);
auto ____ret = new ::CppSharp::CppParser::ParserDiagnostic(__ret);
return (____ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserDiagnostic((::CppSharp::CppParser::ParserDiagnostic*)____ret);
}
void CppSharp::Parser::ParserResult::addDiagnostics(CppSharp::Parser::ParserDiagnostic^ s)
{
auto &arg0 = *(::CppSharp::CppParser::ParserDiagnostic*)s->NativePtr;
((::CppSharp::CppParser::ParserResult*)NativePtr)->addDiagnostics(arg0);
}
System::IntPtr CppSharp::Parser::ParserResult::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ParserResult::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ParserResult*)object.ToPointer();
}
unsigned int CppSharp::Parser::ParserResult::DiagnosticsCount::get()
{
auto __ret = ((::CppSharp::CppParser::ParserResult*)NativePtr)->getDiagnosticsCount();
return __ret;
}
CppSharp::Parser::ParserResultKind CppSharp::Parser::ParserResult::Kind::get()
{
return (CppSharp::Parser::ParserResultKind)((::CppSharp::CppParser::ParserResult*)NativePtr)->Kind;
}
void CppSharp::Parser::ParserResult::Kind::set(CppSharp::Parser::ParserResultKind value)
{
((::CppSharp::CppParser::ParserResult*)NativePtr)->Kind = (::CppSharp::CppParser::ParserResultKind)value;
}
CppSharp::Parser::AST::ASTContext^ CppSharp::Parser::ParserResult::ASTContext::get()
{
return (((::CppSharp::CppParser::ParserResult*)NativePtr)->ASTContext == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ASTContext((::CppSharp::CppParser::AST::ASTContext*)((::CppSharp::CppParser::ParserResult*)NativePtr)->ASTContext);
}
void CppSharp::Parser::ParserResult::ASTContext::set(CppSharp::Parser::AST::ASTContext^ value)
{
((::CppSharp::CppParser::ParserResult*)NativePtr)->ASTContext = (::CppSharp::CppParser::AST::ASTContext*)value->NativePtr;
}
CppSharp::Parser::AST::NativeLibrary^ CppSharp::Parser::ParserResult::Library::get()
{
return (((::CppSharp::CppParser::ParserResult*)NativePtr)->Library == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::NativeLibrary((::CppSharp::CppParser::AST::NativeLibrary*)((::CppSharp::CppParser::ParserResult*)NativePtr)->Library);
}
void CppSharp::Parser::ParserResult::Library::set(CppSharp::Parser::AST::NativeLibrary^ value)
{
((::CppSharp::CppParser::ParserResult*)NativePtr)->Library = (::CppSharp::CppParser::AST::NativeLibrary*)value->NativePtr;
}
CppSharp::Parser::ClangParser::ClangParser(::CppSharp::CppParser::ClangParser* native)
{
NativePtr = native;
}
CppSharp::Parser::ClangParser::ClangParser(System::IntPtr native)
{
auto __native = (::CppSharp::CppParser::ClangParser*)native.ToPointer();
NativePtr = __native;
}
CppSharp::Parser::ParserResult^ CppSharp::Parser::ClangParser::ParseHeader(CppSharp::Parser::ParserOptions^ Opts)
{
auto arg0 = (::CppSharp::CppParser::ParserOptions*)Opts->NativePtr;
auto __ret = ::CppSharp::CppParser::ClangParser::ParseHeader(arg0);
if (__ret == nullptr) return nullptr;
return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserResult((::CppSharp::CppParser::ParserResult*)__ret);
}
CppSharp::Parser::ParserResult^ CppSharp::Parser::ClangParser::ParseLibrary(CppSharp::Parser::ParserOptions^ Opts)
{
auto arg0 = (::CppSharp::CppParser::ParserOptions*)Opts->NativePtr;
auto __ret = ::CppSharp::CppParser::ClangParser::ParseLibrary(arg0);
if (__ret == nullptr) return nullptr;
return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserResult((::CppSharp::CppParser::ParserResult*)__ret);
}
CppSharp::Parser::ParserTargetInfo^ CppSharp::Parser::ClangParser::GetTargetInfo(CppSharp::Parser::ParserOptions^ Opts)
{
auto arg0 = (::CppSharp::CppParser::ParserOptions*)Opts->NativePtr;
auto __ret = ::CppSharp::CppParser::ClangParser::GetTargetInfo(arg0);
if (__ret == nullptr) return nullptr;
return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::ParserTargetInfo((::CppSharp::CppParser::ParserTargetInfo*)__ret);
}
CppSharp::Parser::ClangParser::ClangParser()
{
NativePtr = new ::CppSharp::CppParser::ClangParser();
}
System::IntPtr CppSharp::Parser::ClangParser::__Instance::get()
{
return System::IntPtr(NativePtr);
}
void CppSharp::Parser::ClangParser::__Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::ClangParser*)object.ToPointer();
}

566
src/CppParser/Bindings/CLI/CppParser.h

@ -1,283 +1,283 @@ @@ -1,283 +1,283 @@
#pragma once
#include "CppSharp.h"
#include <CppParser.h>
namespace CppSharp
{
namespace Parser
{
enum struct ParserDiagnosticLevel;
enum struct ParserResultKind;
enum struct SourceLocationKind;
ref class ClangParser;
ref class Parser;
ref class ParserDiagnostic;
ref class ParserOptions;
ref class ParserResult;
ref class ParserTargetInfo;
namespace AST
{
enum struct CppAbi;
ref class ASTContext;
ref class NativeLibrary;
}
}
}
namespace CppSharp
{
namespace Parser
{
public enum struct ParserDiagnosticLevel
{
Ignored = 0,
Note = 1,
Warning = 2,
Error = 3,
Fatal = 4
};
public enum struct ParserResultKind
{
Success = 0,
Error = 1,
FileNotFound = 2
};
public enum struct SourceLocationKind
{
Invalid = 0,
Builtin = 1,
CommandLine = 2,
System = 3,
User = 4
};
public ref class ParserOptions : ICppInstance
{
public:
property ::CppSharp::CppParser::ParserOptions* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ParserOptions(::CppSharp::CppParser::ParserOptions* native);
ParserOptions(System::IntPtr native);
ParserOptions();
property unsigned int ArgumentsCount
{
unsigned int get();
}
property System::String^ FileName
{
System::String^ get();
void set(System::String^);
}
property unsigned int IncludeDirsCount
{
unsigned int get();
}
property unsigned int SystemIncludeDirsCount
{
unsigned int get();
}
property unsigned int DefinesCount
{
unsigned int get();
}
property unsigned int LibraryDirsCount
{
unsigned int get();
}
property System::String^ TargetTriple
{
System::String^ get();
void set(System::String^);
}
property CppSharp::Parser::AST::ASTContext^ ASTContext
{
CppSharp::Parser::AST::ASTContext^ get();
void set(CppSharp::Parser::AST::ASTContext^);
}
property int ToolSetToUse
{
int get();
void set(int);
}
property CppSharp::Parser::AST::CppAbi Abi
{
CppSharp::Parser::AST::CppAbi get();
void set(CppSharp::Parser::AST::CppAbi);
}
property bool NoStandardIncludes
{
bool get();
void set(bool);
}
property bool NoBuiltinIncludes
{
bool get();
void set(bool);
}
property bool MicrosoftMode
{
bool get();
void set(bool);
}
property bool Verbose
{
bool get();
void set(bool);
}
System::String^ getArguments(unsigned int i);
void addArguments(System::String^ s);
System::String^ getIncludeDirs(unsigned int i);
void addIncludeDirs(System::String^ s);
System::String^ getSystemIncludeDirs(unsigned int i);
void addSystemIncludeDirs(System::String^ s);
System::String^ getDefines(unsigned int i);
void addDefines(System::String^ s);
System::String^ getLibraryDirs(unsigned int i);
void addLibraryDirs(System::String^ s);
};
public ref class ParserDiagnostic : ICppInstance
{
public:
property ::CppSharp::CppParser::ParserDiagnostic* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ParserDiagnostic(::CppSharp::CppParser::ParserDiagnostic* native);
ParserDiagnostic(System::IntPtr native);
ParserDiagnostic();
property System::String^ FileName
{
System::String^ get();
void set(System::String^);
}
property System::String^ Message
{
System::String^ get();
void set(System::String^);
}
property CppSharp::Parser::ParserDiagnosticLevel Level
{
CppSharp::Parser::ParserDiagnosticLevel get();
void set(CppSharp::Parser::ParserDiagnosticLevel);
}
property int LineNumber
{
int get();
void set(int);
}
property int ColumnNumber
{
int get();
void set(int);
}
};
public ref class ParserResult : ICppInstance
{
public:
property ::CppSharp::CppParser::ParserResult* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ParserResult(::CppSharp::CppParser::ParserResult* native);
ParserResult(System::IntPtr native);
ParserResult();
property unsigned int DiagnosticsCount
{
unsigned int get();
}
property CppSharp::Parser::ParserResultKind Kind
{
CppSharp::Parser::ParserResultKind get();
void set(CppSharp::Parser::ParserResultKind);
}
property CppSharp::Parser::AST::ASTContext^ ASTContext
{
CppSharp::Parser::AST::ASTContext^ get();
void set(CppSharp::Parser::AST::ASTContext^);
}
property CppSharp::Parser::AST::NativeLibrary^ Library
{
CppSharp::Parser::AST::NativeLibrary^ get();
void set(CppSharp::Parser::AST::NativeLibrary^);
}
CppSharp::Parser::ParserDiagnostic^ getDiagnostics(unsigned int i);
void addDiagnostics(CppSharp::Parser::ParserDiagnostic^ s);
};
public ref class ClangParser : ICppInstance
{
public:
property ::CppSharp::CppParser::ClangParser* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ClangParser(::CppSharp::CppParser::ClangParser* native);
ClangParser(System::IntPtr native);
ClangParser();
static CppSharp::Parser::ParserResult^ ParseHeader(CppSharp::Parser::ParserOptions^ Opts);
static CppSharp::Parser::ParserResult^ ParseLibrary(CppSharp::Parser::ParserOptions^ Opts);
static CppSharp::Parser::ParserTargetInfo^ GetTargetInfo(CppSharp::Parser::ParserOptions^ Opts);
};
}
}
#pragma once
#include "CppSharp.h"
#include <CppParser.h>
namespace CppSharp
{
namespace Parser
{
enum struct ParserDiagnosticLevel;
enum struct ParserResultKind;
enum struct SourceLocationKind;
ref class ClangParser;
ref class Parser;
ref class ParserDiagnostic;
ref class ParserOptions;
ref class ParserResult;
ref class ParserTargetInfo;
namespace AST
{
enum struct CppAbi;
ref class ASTContext;
ref class NativeLibrary;
}
}
}
namespace CppSharp
{
namespace Parser
{
public enum struct ParserDiagnosticLevel
{
Ignored = 0,
Note = 1,
Warning = 2,
Error = 3,
Fatal = 4
};
public enum struct ParserResultKind
{
Success = 0,
Error = 1,
FileNotFound = 2
};
public enum struct SourceLocationKind
{
Invalid = 0,
Builtin = 1,
CommandLine = 2,
System = 3,
User = 4
};
public ref class ParserOptions : ICppInstance
{
public:
property ::CppSharp::CppParser::ParserOptions* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ParserOptions(::CppSharp::CppParser::ParserOptions* native);
ParserOptions(System::IntPtr native);
ParserOptions();
property unsigned int ArgumentsCount
{
unsigned int get();
}
property System::String^ FileName
{
System::String^ get();
void set(System::String^);
}
property unsigned int IncludeDirsCount
{
unsigned int get();
}
property unsigned int SystemIncludeDirsCount
{
unsigned int get();
}
property unsigned int DefinesCount
{
unsigned int get();
}
property unsigned int LibraryDirsCount
{
unsigned int get();
}
property System::String^ TargetTriple
{
System::String^ get();
void set(System::String^);
}
property CppSharp::Parser::AST::ASTContext^ ASTContext
{
CppSharp::Parser::AST::ASTContext^ get();
void set(CppSharp::Parser::AST::ASTContext^);
}
property int ToolSetToUse
{
int get();
void set(int);
}
property CppSharp::Parser::AST::CppAbi Abi
{
CppSharp::Parser::AST::CppAbi get();
void set(CppSharp::Parser::AST::CppAbi);
}
property bool NoStandardIncludes
{
bool get();
void set(bool);
}
property bool NoBuiltinIncludes
{
bool get();
void set(bool);
}
property bool MicrosoftMode
{
bool get();
void set(bool);
}
property bool Verbose
{
bool get();
void set(bool);
}
System::String^ getArguments(unsigned int i);
void addArguments(System::String^ s);
System::String^ getIncludeDirs(unsigned int i);
void addIncludeDirs(System::String^ s);
System::String^ getSystemIncludeDirs(unsigned int i);
void addSystemIncludeDirs(System::String^ s);
System::String^ getDefines(unsigned int i);
void addDefines(System::String^ s);
System::String^ getLibraryDirs(unsigned int i);
void addLibraryDirs(System::String^ s);
};
public ref class ParserDiagnostic : ICppInstance
{
public:
property ::CppSharp::CppParser::ParserDiagnostic* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ParserDiagnostic(::CppSharp::CppParser::ParserDiagnostic* native);
ParserDiagnostic(System::IntPtr native);
ParserDiagnostic();
property System::String^ FileName
{
System::String^ get();
void set(System::String^);
}
property System::String^ Message
{
System::String^ get();
void set(System::String^);
}
property CppSharp::Parser::ParserDiagnosticLevel Level
{
CppSharp::Parser::ParserDiagnosticLevel get();
void set(CppSharp::Parser::ParserDiagnosticLevel);
}
property int LineNumber
{
int get();
void set(int);
}
property int ColumnNumber
{
int get();
void set(int);
}
};
public ref class ParserResult : ICppInstance
{
public:
property ::CppSharp::CppParser::ParserResult* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ParserResult(::CppSharp::CppParser::ParserResult* native);
ParserResult(System::IntPtr native);
ParserResult();
property unsigned int DiagnosticsCount
{
unsigned int get();
}
property CppSharp::Parser::ParserResultKind Kind
{
CppSharp::Parser::ParserResultKind get();
void set(CppSharp::Parser::ParserResultKind);
}
property CppSharp::Parser::AST::ASTContext^ ASTContext
{
CppSharp::Parser::AST::ASTContext^ get();
void set(CppSharp::Parser::AST::ASTContext^);
}
property CppSharp::Parser::AST::NativeLibrary^ Library
{
CppSharp::Parser::AST::NativeLibrary^ get();
void set(CppSharp::Parser::AST::NativeLibrary^);
}
CppSharp::Parser::ParserDiagnostic^ getDiagnostics(unsigned int i);
void addDiagnostics(CppSharp::Parser::ParserDiagnostic^ s);
};
public ref class ClangParser : ICppInstance
{
public:
property ::CppSharp::CppParser::ClangParser* NativePtr;
property System::IntPtr __Instance
{
virtual System::IntPtr get();
virtual void set(System::IntPtr instance);
}
ClangParser(::CppSharp::CppParser::ClangParser* native);
ClangParser(System::IntPtr native);
ClangParser();
static CppSharp::Parser::ParserResult^ ParseHeader(CppSharp::Parser::ParserOptions^ Opts);
static CppSharp::Parser::ParserResult^ ParseLibrary(CppSharp::Parser::ParserOptions^ Opts);
static CppSharp::Parser::ParserTargetInfo^ GetTargetInfo(CppSharp::Parser::ParserOptions^ Opts);
};
}
}

54
src/Generator/AST/Utils.cs

@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@

using System;
using System.Linq;
using Mono.Options;
using System.Linq;
using Mono.Options;
namespace CppSharp.AST
{
public static class ASTUtils
{
{
public static bool CheckIgnoreFunction(Function function, DriverOptions options)
{
if (!function.IsGenerated) return true;
if (!function.IsGenerated) return true;
if (function is Method)
return CheckIgnoreMethod(function as Method, options);
@ -19,7 +19,7 @@ namespace CppSharp.AST @@ -19,7 +19,7 @@ namespace CppSharp.AST
public static bool CheckIgnoreMethod(Method method, DriverOptions options)
{
if (!method.IsGenerated) return true;
if (!method.IsGenerated) return true;
var isEmptyCtor = method.IsConstructor && method.Parameters.Count == 0;
@ -39,24 +39,24 @@ namespace CppSharp.AST @@ -39,24 +39,24 @@ namespace CppSharp.AST
if (method.Access == AccessSpecifier.Private && !method.IsOverride)
return true;
//Ignore copy constructor if a base class don't has or has a private copy constructor
if (method.IsCopyConstructor)
{
if (!options.GenerateCopyConstructors)
return true;
var baseClass = @class;
while (baseClass != null && baseClass.HasBaseClass)
{
baseClass = baseClass.BaseClass;
var copyConstructor = baseClass.Methods.FirstOrDefault(m => m.IsCopyConstructor);
if (copyConstructor == null
|| copyConstructor.Access == AccessSpecifier.Private
|| !copyConstructor.IsDeclared)
return true;
}
}
//Ignore copy constructor if a base class don't has or has a private copy constructor
if (method.IsCopyConstructor)
{
if (!options.GenerateCopyConstructors)
return true;
var baseClass = @class;
while (baseClass != null && baseClass.HasBaseClass)
{
baseClass = baseClass.BaseClass;
var copyConstructor = baseClass.Methods.FirstOrDefault(m => m.IsCopyConstructor);
if (copyConstructor == null
|| copyConstructor.Access == AccessSpecifier.Private
|| !copyConstructor.IsDeclared)
return true;
}
}
return false;
}
@ -66,8 +66,8 @@ namespace CppSharp.AST @@ -66,8 +66,8 @@ namespace CppSharp.AST
return true;
if (field.Class.IsValueType && field.IsDeclared)
return false;
return false;
return !field.IsGenerated && (!useInternals || !field.IsInternal);
}
@ -200,7 +200,7 @@ namespace CppSharp.AST @@ -200,7 +200,7 @@ namespace CppSharp.AST
case CXXOperatorKind.Conversion:
return "implicit operator";
case CXXOperatorKind.ExplicitConversion:
case CXXOperatorKind.ExplicitConversion:
return "explicit operator";
}

72
src/Generator/Driver.cs

@ -71,27 +71,27 @@ namespace CppSharp @@ -71,27 +71,27 @@ namespace CppSharp
for (var i = 0; i < options.LibraryDirs.Count; i++)
options.LibraryDirs[i] = Path.GetFullPath(options.LibraryDirs[i]);
if (options.NoGenIncludeDirs != null)
for (var i = 0; i < options.NoGenIncludeDirs.Count; i++)
options.NoGenIncludeDirs[i] = Path.GetFullPath(options.NoGenIncludeDirs[i]);
#endif
if (options.NoGenIncludeDirs != null)
foreach (var incDir in options.NoGenIncludeDirs)
#if OLD_PARSER
options.IncludeDirs.Add(incDir);
#else
options.addIncludeDirs(incDir);
#endif
if (options.NoGenIncludeDirs != null)
for (var i = 0; i < options.NoGenIncludeDirs.Count; i++)
options.NoGenIncludeDirs[i] = Path.GetFullPath(options.NoGenIncludeDirs[i]);
#endif
if (options.NoGenIncludeDirs != null)
foreach (var incDir in options.NoGenIncludeDirs)
#if OLD_PARSER
options.IncludeDirs.Add(incDir);
#else
options.addIncludeDirs(incDir);
#endif
if (string.IsNullOrWhiteSpace(options.OutputNamespace))
options.OutputNamespace = options.LibraryName;
}
public void Setup()
{
ValidateOptions(Options);
ValidateOptions(Options);
TypeDatabase.SetupTypeMaps();
Generator = CreateGeneratorFromKind(Options.GeneratorKind);
}
@ -276,9 +276,9 @@ namespace CppSharp @@ -276,9 +276,9 @@ namespace CppSharp
TranslationUnitPasses.AddPass(new FindSymbolsPass());
TranslationUnitPasses.AddPass(new CheckStaticClass());
TranslationUnitPasses.AddPass(new MoveOperatorToClassPass());
TranslationUnitPasses.AddPass(new MoveFunctionToClassPass());
if (Options.GenerateConversionOperators)
TranslationUnitPasses.AddPass(new MoveFunctionToClassPass());
if (Options.GenerateConversionOperators)
TranslationUnitPasses.AddPass(new ConstructorToConversionOperatorPass());
TranslationUnitPasses.AddPass(new CheckAmbiguousFunctions());
@ -303,12 +303,12 @@ namespace CppSharp @@ -303,12 +303,12 @@ namespace CppSharp
}
if (Options.GenerateVirtualTables)
TranslationUnitPasses.AddPass(new CheckVTableComponentsPass());
if (Options.GenerateProperties)
TranslationUnitPasses.AddPass(new CheckVTableComponentsPass());
if (Options.GenerateProperties)
TranslationUnitPasses.AddPass(new GetterSetterToPropertyPass());
if (Options.GeneratePropertiesAdvanced)
if (Options.GeneratePropertiesAdvanced)
TranslationUnitPasses.AddPass(new GetterSetterToPropertyAdvancedPass());
}
@ -332,7 +332,7 @@ namespace CppSharp @@ -332,7 +332,7 @@ namespace CppSharp
public void WriteCode(List<GeneratorOutput> outputs)
{
var outputPath = Path.GetFullPath(Options.OutputDir);
var outputPath = Path.GetFullPath(Options.OutputDir);
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
@ -341,31 +341,31 @@ namespace CppSharp @@ -341,31 +341,31 @@ namespace CppSharp
{
var fileBase = output.TranslationUnit.FileNameWithoutExtension;
if (Options.UseHeaderDirectories)
{
var dir = Path.Combine(outputPath, output.TranslationUnit.FileRelativeDirectory);
Directory.CreateDirectory(dir);
fileBase = Path.Combine(output.TranslationUnit.FileRelativeDirectory, fileBase);
}
if (Options.UseHeaderDirectories)
{
var dir = Path.Combine(outputPath, output.TranslationUnit.FileRelativeDirectory);
Directory.CreateDirectory(dir);
fileBase = Path.Combine(output.TranslationUnit.FileRelativeDirectory, fileBase);
}
if (Options.GenerateName != null)
fileBase = Options.GenerateName(output.TranslationUnit);
foreach (var template in output.Templates)
{
var fileRelativePath = string.Format("{0}.{1}", fileBase, template.FileExtension);
Diagnostics.EmitMessage("Generated '{0}'", fileRelativePath);
var fileRelativePath = string.Format("{0}.{1}", fileBase, template.FileExtension);
Diagnostics.EmitMessage("Generated '{0}'", fileRelativePath);
var file = Path.Combine(outputPath, fileRelativePath);
var file = Path.Combine(outputPath, fileRelativePath);
File.WriteAllText(file, template.Generate());
Options.CodeFiles.Add(file);
}
}
}
public void CompileCode()
{
if (!Options.CompileCode)
public void CompileCode()
{
if (!Options.CompileCode)
return;
var assemblyFile = string.IsNullOrEmpty(Options.LibraryName) ?

34
src/Generator/Generator.lua

@ -1,17 +1,17 @@ @@ -1,17 +1,17 @@
project "CppSharp.Generator"
kind "SharedLib"
language "C#"
location "."
SetupManagedProject()
files { "**.cs", "**verbs.txt" }
excludes { "Filter.cs" }
links { "System", "System.Core", "CppSharp", "CppSharp.AST" }
SetupParser()
configuration '**verbs.txt'
buildaction "Embed"
project "CppSharp.Generator"
kind "SharedLib"
language "C#"
location "."
SetupManagedProject()
files { "**.cs", "**verbs.txt" }
excludes { "Filter.cs" }
links { "System", "System.Core", "CppSharp", "CppSharp.AST" }
SetupParser()
configuration '**verbs.txt'
buildaction "Embed"

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
using System;
using System.Linq;
using System.Linq;
using System.Text;
using CppSharp.AST;
using CppSharp.AST.Extensions;
@ -90,35 +90,35 @@ namespace CppSharp.Generators.CLI @@ -90,35 +90,35 @@ namespace CppSharp.Generators.CLI
}
if (pointee.IsPrimitiveType(out primitive))
{
var returnVarName = Context.ReturnVarName;
if (quals.IsConst != Context.ReturnType.Qualifiers.IsConst)
{
var nativeTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase, false);
var constlessPointer = new PointerType()
{
IsDependent = pointer.IsDependent,
Modifier = pointer.Modifier,
QualifiedPointee = new QualifiedType(Context.ReturnType.Type.GetPointee())
};
var nativeConstlessTypeName = constlessPointer.Visit(nativeTypePrinter, new TypeQualifiers());
returnVarName = string.Format("const_cast<{0}>({1})",
nativeConstlessTypeName, Context.ReturnVarName);
}
if (pointer.Pointee is TypedefType)
{
var desugaredPointer = new PointerType()
{
IsDependent = pointer.IsDependent,
Modifier = pointer.Modifier,
QualifiedPointee = new QualifiedType(pointee)
};
var nativeTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
var nativeTypeName = desugaredPointer.Visit(nativeTypePrinter, quals);
Context.Return.Write("reinterpret_cast<{0}>({1})", nativeTypeName,
returnVarName);
}
else
{
var returnVarName = Context.ReturnVarName;
if (quals.IsConst != Context.ReturnType.Qualifiers.IsConst)
{
var nativeTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase, false);
var constlessPointer = new PointerType()
{
IsDependent = pointer.IsDependent,
Modifier = pointer.Modifier,
QualifiedPointee = new QualifiedType(Context.ReturnType.Type.GetPointee())
};
var nativeConstlessTypeName = constlessPointer.Visit(nativeTypePrinter, new TypeQualifiers());
returnVarName = string.Format("const_cast<{0}>({1})",
nativeConstlessTypeName, Context.ReturnVarName);
}
if (pointer.Pointee is TypedefType)
{
var desugaredPointer = new PointerType()
{
IsDependent = pointer.IsDependent,
Modifier = pointer.Modifier,
QualifiedPointee = new QualifiedType(pointee)
};
var nativeTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
var nativeTypeName = desugaredPointer.Visit(nativeTypePrinter, quals);
Context.Return.Write("reinterpret_cast<{0}>({1})", nativeTypeName,
returnVarName);
}
else
Context.Return.Write(returnVarName);
return true;
}
@ -165,7 +165,7 @@ namespace CppSharp.Generators.CLI @@ -165,7 +165,7 @@ namespace CppSharp.Generators.CLI
case PrimitiveType.Int64:
case PrimitiveType.UInt64:
case PrimitiveType.Float:
case PrimitiveType.Double:
case PrimitiveType.Double:
case PrimitiveType.Null:
Context.Return.Write(Context.ReturnVarName);
return true;
@ -444,15 +444,15 @@ namespace CppSharp.Generators.CLI @@ -444,15 +444,15 @@ namespace CppSharp.Generators.CLI
var cppTypeName = pointer.Visit(cppTypePrinter, quals);
return VisitDelegateType(function, cppTypeName);
}
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
ArgumentPrefix.Write("&");
Context.Return.Write("(::{0})*{1}", @enum.QualifiedOriginalName,
Context.Parameter.Name);
return true;
}
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
ArgumentPrefix.Write("&");
Context.Return.Write("(::{0})*{1}", @enum.QualifiedOriginalName,
Context.Parameter.Name);
return true;
}
Class @class;
@ -461,9 +461,9 @@ namespace CppSharp.Generators.CLI @@ -461,9 +461,9 @@ namespace CppSharp.Generators.CLI
if (Context.Function == null)
Context.Return.Write("&");
return pointee.Visit(this, quals);
}
var finalPointee = pointer.GetFinalPointee();
}
var finalPointee = pointer.GetFinalPointee();
if (finalPointee.IsPrimitiveType())
{
var cppTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
@ -641,7 +641,7 @@ namespace CppSharp.Generators.CLI @@ -641,7 +641,7 @@ namespace CppSharp.Generators.CLI
{
foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared))
{
MarshalValueClassProperties(@base.Class, marshalVar);
MarshalValueClassProperties(@base.Class, marshalVar);
}
foreach (var property in @class.Properties.Where( p => !ASTUtils.CheckIgnoreProperty(p)))

6
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -843,7 +843,7 @@ namespace CppSharp.Generators.CLI @@ -843,7 +843,7 @@ namespace CppSharp.Generators.CLI
CheckArgumentRange(function);
var retType = function.ReturnType;
if (publicRetType == null)
if (publicRetType == null)
publicRetType = retType.Type;
var needsReturn = !retType.Type.IsPrimitiveType(PrimitiveType.Void);
@ -977,8 +977,8 @@ namespace CppSharp.Generators.CLI @@ -977,8 +977,8 @@ namespace CppSharp.Generators.CLI
if (retType.Type.IsPointer() &&
retType.Type.GetPointee().Equals(publicRetType) &&
publicRetType.IsPrimitiveType())
WriteLine("return *({0});", marshal.Context.Return);
else if (retType.Type.IsReference() && publicRetType.IsReference())
WriteLine("return *({0});", marshal.Context.Return);
else if (retType.Type.IsReference() && publicRetType.IsReference())
WriteLine("return ({0})({1});", publicRetType, marshal.Context.Return);
else
WriteLine("return {0};", marshal.Context.Return);

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

@ -1,398 +1,398 @@ @@ -1,398 +1,398 @@
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
// Any of the following types may be a pointer type:
// * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
// * 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())
{
// 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) + "*";
}
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
var typeName = @enum.Visit(this);
return string.Format("{0}*", typeName);
}
return pointer.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";
case PrimitiveType.Null: return "void*";
}
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)
{
var result = type.Type.FullName.Replace(".", "::");
if (!type.Type.IsValueType)
result += "^";
return result;
}
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);
}
}
}
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
// Any of the following types may be a pointer type:
// * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
// * 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())
{
// 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) + "*";
}
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
var typeName = @enum.Visit(this);
return string.Format("{0}*", typeName);
}
return pointer.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";
case PrimitiveType.Null: return "void*";
}
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)
{
var result = type.Type.FullName.Replace(".", "::");
if (!type.Type.IsValueType)
result += "^";
return result;
}
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);
}
}
}

60
src/Generator/Generators/CLI/CLITypeReferences.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System;
using System.Collections.Generic;
using System.IO;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators.AST;
@ -27,7 +27,7 @@ namespace CppSharp.Generators.CLI @@ -27,7 +27,7 @@ namespace CppSharp.Generators.CLI
public class CLITypeReferenceCollector : AstVisitor
{
private readonly ITypeMapDatabase TypeMapDatabase;
private readonly DriverOptions DriverOptions;
private readonly DriverOptions DriverOptions;
private TranslationUnit TranslationUnit;
private Dictionary<Declaration, CLITypeReference> typeReferences;
@ -36,10 +36,10 @@ namespace CppSharp.Generators.CLI @@ -36,10 +36,10 @@ namespace CppSharp.Generators.CLI
get { return typeReferences.Values; }
}
public CLITypeReferenceCollector(ITypeMapDatabase typeMapDatabase, DriverOptions driverOptions)
public CLITypeReferenceCollector(ITypeMapDatabase typeMapDatabase, DriverOptions driverOptions)
{
TypeMapDatabase = typeMapDatabase;
DriverOptions = driverOptions;
DriverOptions = driverOptions;
typeReferences = new Dictionary<Declaration,CLITypeReference>();
}
@ -110,11 +110,11 @@ namespace CppSharp.Generators.CLI @@ -110,11 +110,11 @@ namespace CppSharp.Generators.CLI
return;
}
var translationUnit = decl.Namespace.TranslationUnit;
var translationUnit = decl.Namespace.TranslationUnit;
if (translationUnit.IsSystemHeader)
return;
if (translationUnit.IsSystemHeader)
return;
if (!decl.IsGenerated)
return;
@ -126,32 +126,32 @@ namespace CppSharp.Generators.CLI @@ -126,32 +126,32 @@ namespace CppSharp.Generators.CLI
{
typeRef.Include = new Include
{
File = GetIncludePath(translationUnit),
TranslationUnit = translationUnit,
Kind = translationUnit.IsGenerated
? Include.IncludeKind.Quoted
: Include.IncludeKind.Angled,
File = GetIncludePath(translationUnit),
TranslationUnit = translationUnit,
Kind = translationUnit.IsGenerated
? Include.IncludeKind.Quoted
: Include.IncludeKind.Angled,
};
}
typeRef.Include.InHeader |= IsIncludeInHeader(record);
}
private string GetIncludePath(TranslationUnit translationUnit)
{
if (!DriverOptions.UseHeaderDirectories)
return translationUnit.FileName;
var rel = PathHelpers.GetRelativePath(
TranslationUnit.FileRelativeDirectory,
translationUnit.FileRelativeDirectory);
if (string.IsNullOrEmpty(rel))
return translationUnit.FileName;
return Path.Combine(rel, translationUnit.FileName);
}
private string GetIncludePath(TranslationUnit translationUnit)
{
if (!DriverOptions.UseHeaderDirectories)
return translationUnit.FileName;
var rel = PathHelpers.GetRelativePath(
TranslationUnit.FileRelativeDirectory,
translationUnit.FileRelativeDirectory);
if (string.IsNullOrEmpty(rel))
return translationUnit.FileName;
return Path.Combine(rel, translationUnit.FileName);
}
private bool IsBuiltinTypedef(Declaration decl)
{
var typedefDecl = decl as TypedefDecl;

404
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -6,8 +6,8 @@ using System.Linq; @@ -6,8 +6,8 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Util;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute;
@ -184,7 +184,7 @@ namespace CppSharp.Generators.CSharp @@ -184,7 +184,7 @@ namespace CppSharp.Generators.CSharp
// Generate all the enum declarations.
foreach (var @enum in context.Enums)
{
{
if (!@enum.IsGenerated || @enum.IsIncomplete)
continue;
@ -200,7 +200,7 @@ namespace CppSharp.Generators.CSharp @@ -200,7 +200,7 @@ namespace CppSharp.Generators.CSharp
// Generate all the struct/class declarations.
foreach (var @class in context.Classes)
{
if (@class.IsIncomplete)
if (@class.IsIncomplete)
continue;
if (@class.IsInterface)
@ -222,7 +222,7 @@ namespace CppSharp.Generators.CSharp @@ -222,7 +222,7 @@ namespace CppSharp.Generators.CSharp
// Generate all the internal function declarations.
foreach (var function in context.Functions)
{
{
if (!function.IsGenerated && !function.IsInternal ) continue;
GenerateInternalFunction(function);
@ -232,7 +232,7 @@ namespace CppSharp.Generators.CSharp @@ -232,7 +232,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
foreach (var function in context.Functions)
{
{
if (!function.IsGenerated) continue;
GenerateFunction(function);
@ -243,7 +243,7 @@ namespace CppSharp.Generators.CSharp @@ -243,7 +243,7 @@ namespace CppSharp.Generators.CSharp
}
foreach (var @event in context.Events)
{
{
if (!@event.IsGenerated) continue;
GenerateEvent(@event);
@ -359,7 +359,7 @@ namespace CppSharp.Generators.CSharp @@ -359,7 +359,7 @@ namespace CppSharp.Generators.CSharp
if (Options.GenerateVirtualTables && @class.IsDynamic)
GenerateVTable(@class);
}
exit:
exit:
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -384,7 +384,7 @@ namespace CppSharp.Generators.CSharp @@ -384,7 +384,7 @@ namespace CppSharp.Generators.CSharp
}
private void GenerateInterface(Class @class)
{
{
if (!@class.IsGenerated || @class.IsIncomplete)
return;
@ -413,7 +413,7 @@ namespace CppSharp.Generators.CSharp @@ -413,7 +413,7 @@ namespace CppSharp.Generators.CSharp
WriteLine(");");
PopBlock(NewLineKind.BeforeNextBlock);
}
}
foreach (var prop in @class.Properties.Where(p => p.IsGenerated))
{
PushBlock(CSharpBlockKind.Property);
@ -454,9 +454,9 @@ namespace CppSharp.Generators.CSharp @@ -454,9 +454,9 @@ namespace CppSharp.Generators.CSharp
var typePrinter = TypePrinter;
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
GenerateClassFields(@class, GenerateClassInternalsField, true);
if (Options.GenerateVirtualTables && @class.IsDynamic)
GenerateVTablePointers(@class);
GenerateClassFields(@class, GenerateClassInternalsField, true);
if (Options.GenerateVirtualTables && @class.IsDynamic)
GenerateVTablePointers(@class);
var functions = GatherClassInternalFunctions(@class);
@ -486,9 +486,9 @@ namespace CppSharp.Generators.CSharp @@ -486,9 +486,9 @@ namespace CppSharp.Generators.CSharp
functions.Add(method);
};
foreach (var ctor in @class.Constructors)
{
if (@class.IsStatic)
foreach (var ctor in @class.Constructors)
{
if (@class.IsStatic)
continue;
if (ctor.IsMoveConstructor)
@ -579,7 +579,7 @@ namespace CppSharp.Generators.CSharp @@ -579,7 +579,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateStructMarshalingProperties(Class @class)
{
foreach (var @base in @class.Bases)
{
{
if (!@base.IsClass || !@base.Class.IsDeclared)
continue;
@ -588,7 +588,7 @@ namespace CppSharp.Generators.CSharp @@ -588,7 +588,7 @@ namespace CppSharp.Generators.CSharp
for (int i = 0; i < @class.Properties.Count; i++)
{
var property = @class.Properties[i];
var property = @class.Properties[i];
if (!property.IsGenerated || property.Field == null) continue;
var nativeField = string.Format("{0}->{1}",
@ -630,7 +630,7 @@ namespace CppSharp.Generators.CSharp @@ -630,7 +630,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateStructInternalMarshalingProperties(Class @class, string marshalVar)
{
foreach (var @base in @class.Bases)
{
{
if (!@base.IsClass || !@base.Class.IsDeclared)
continue;
@ -639,7 +639,7 @@ namespace CppSharp.Generators.CSharp @@ -639,7 +639,7 @@ namespace CppSharp.Generators.CSharp
}
foreach (var property in @class.Properties)
{
{
if (!property.IsGenerated || property.Field == null)
continue;
@ -701,8 +701,8 @@ namespace CppSharp.Generators.CSharp @@ -701,8 +701,8 @@ namespace CppSharp.Generators.CSharp
public static bool ShouldGenerateClassNativeField(Class @class)
{
if (@class.IsStatic)
return false;
if (@class.IsStatic)
return false;
return @class.IsRefType && (!@class.HasBase || !HasRefBase(@class));
}
@ -711,26 +711,26 @@ namespace CppSharp.Generators.CSharp @@ -711,26 +711,26 @@ namespace CppSharp.Generators.CSharp
if (@class.IsUnion)
WriteLine("[StructLayout(LayoutKind.Explicit)]");
Write(@class.IsInternal ? "internal " : Helpers.GetAccess(@class.Access));
Write(@class.IsInternal ? "internal " : Helpers.GetAccess(@class.Access));
Write("unsafe ");
if (Driver.Options.GenerateAbstractImpls && @class.IsAbstract)
Write("abstract ");
if (@class.IsStatic)
Write("static ");
// This token needs to directly precede the "class" token.
if (@class.IsStatic)
Write("static ");
// This token needs to directly precede the "class" token.
if (Options.GeneratePartialClasses)
Write("partial ");
Write(@class.IsInterface ? "interface " : (@class.IsValueType ? "struct " : "class "));
Write("{0}", @class.Name);
var bases = new List<string>();
var needsBase = @class.HasBaseClass && !@class.IsValueType && @class.IsGenerated
&& !@class.Bases[0].Class.IsValueType
var bases = new List<string>();
var needsBase = @class.HasBaseClass && !@class.IsValueType && @class.IsGenerated
&& !@class.Bases[0].Class.IsValueType
&& @class.Bases[0].Class.IsGenerated;
if (needsBase)
@ -739,12 +739,12 @@ namespace CppSharp.Generators.CSharp @@ -739,12 +739,12 @@ namespace CppSharp.Generators.CSharp
from @base in @class.Bases
where @base.IsClass
select QualifiedIdentifier(@base.Class));
}
if (@class.IsGenerated)
}
if (@class.IsGenerated)
{
if (@class.IsRefType)
bases.Add("IDisposable");
if (@class.IsRefType)
bases.Add("IDisposable");
if (Options.GenerateClassMarshals)
{
@ -752,37 +752,37 @@ namespace CppSharp.Generators.CSharp @@ -752,37 +752,37 @@ namespace CppSharp.Generators.CSharp
}
}
if (bases.Count > 0 && !@class.IsStatic)
if (bases.Count > 0 && !@class.IsStatic)
Write(" : {0}", string.Join(", ", bases));
}
public void GenerateClassFields(Class @class, Action<Field> action, bool nativeFields = false)
public void GenerateClassFields(Class @class, Action<Field> action, bool nativeFields = false)
{
foreach (var @base in @class.Bases.Where(b => !(b.Type is DependentNameType)))
foreach (var @base in @class.Bases.Where(b => !(b.Type is DependentNameType)))
{
TypeMap typeMap;
if ((!Driver.TypeDatabase.FindTypeMap(@base.Type, out typeMap) && !@base.Class.IsDeclared) ||
@base.Class.OriginalClass == @class)
TypeMap typeMap;
if ((!Driver.TypeDatabase.FindTypeMap(@base.Type, out typeMap) && !@base.Class.IsDeclared) ||
@base.Class.OriginalClass == @class)
continue;
GenerateClassFields(@base.Class, action, nativeFields);
GenerateClassFields(@base.Class, action, nativeFields);
}
foreach (var field in @class.Fields)
{
if (ASTUtils.CheckIgnoreField(field, nativeFields)) continue;
{
if (ASTUtils.CheckIgnoreField(field, nativeFields)) continue;
action(field);
}
}
private void GenerateClassInternalsField(Field field)
{
// we do not support dependent fields yet, see https://github.com/mono/CppSharp/issues/197
Class @class;
if (field.Type.IsDependent && !field.Type.IsPointer() &&
!(field.Type.TryGetClass(out @class) && @class.IsUnion))
return;
private void GenerateClassInternalsField(Field field)
{
// we do not support dependent fields yet, see https://github.com/mono/CppSharp/issues/197
Class @class;
if (field.Type.IsDependent && !field.Type.IsPointer() &&
!(field.Type.TryGetClass(out @class) && @class.IsUnion))
return;
var safeIdentifier = Helpers.SafeIdentifier(field.OriginalName);
PushBlock(CSharpBlockKind.Field);
@ -797,11 +797,11 @@ namespace CppSharp.Generators.CSharp @@ -797,11 +797,11 @@ namespace CppSharp.Generators.CSharp
if (field.Expression != null)
{
var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter);
Write("public {0} {1} = {2};", fieldTypePrinted.Type, safeIdentifier, fieldValuePrinted);
Write("public {0} {1} = {2};", fieldTypePrinted.Type, safeIdentifier, fieldValuePrinted);
}
else
{
Write("public {0} {1};", fieldTypePrinted.Type, safeIdentifier);
Write("public {0} {1};", fieldTypePrinted.Type, safeIdentifier);
}
PopBlock(NewLineKind.BeforeNextBlock);
@ -974,7 +974,7 @@ namespace CppSharp.Generators.CSharp @@ -974,7 +974,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateIndexerSetter(QualifiedType returnType, Function function)
{
Type type;
Type type;
function.Type.IsPointerTo(out type);
PrimitiveType primitiveType;
string internalFunction = GetFunctionNativeIdentifier(function);
@ -1120,7 +1120,7 @@ namespace CppSharp.Generators.CSharp @@ -1120,7 +1120,7 @@ namespace CppSharp.Generators.CSharp
{
var staticMethods = new List<Method>();
foreach (var method in @class.Methods)
{
{
if (ASTUtils.CheckIgnoreMethod(method, Options))
continue;
@ -1145,7 +1145,7 @@ namespace CppSharp.Generators.CSharp @@ -1145,7 +1145,7 @@ namespace CppSharp.Generators.CSharp
public void GenerateClassVariables(Class @class)
{
foreach (var variable in @class.Variables)
{
{
if (!variable.IsGenerated) continue;
if (variable.Access != AccessSpecifier.Public)
@ -1160,7 +1160,7 @@ namespace CppSharp.Generators.CSharp @@ -1160,7 +1160,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateClassProperties(Class @class)
{
if (@class.IsValueType)
{
{
foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared))
{
GenerateClassProperties(@base.Class);
@ -1171,7 +1171,7 @@ namespace CppSharp.Generators.CSharp @@ -1171,7 +1171,7 @@ namespace CppSharp.Generators.CSharp
}
private void GenerateProperties(Class @class)
{
{
foreach (var prop in @class.Properties.Where(p => p.IsGenerated))
{
if (prop.IsInRefTypeAndBackedByValueClassField())
@ -1225,7 +1225,7 @@ namespace CppSharp.Generators.CSharp @@ -1225,7 +1225,7 @@ namespace CppSharp.Generators.CSharp
}
else
{
if (prop.HasGetter)
if (prop.HasGetter)
GeneratePropertyGetter(prop.QualifiedType, prop.GetMethod, @class);
if (prop.HasSetter)
@ -1289,8 +1289,8 @@ namespace CppSharp.Generators.CSharp @@ -1289,8 +1289,8 @@ namespace CppSharp.Generators.CSharp
const string dictionary = "System.Collections.Generic.Dictionary";
WriteLine("private static void*[] _OldVTables;");
WriteLine("private static void*[] _NewVTables;");
WriteLine("private static void*[] _OldVTables;");
WriteLine("private static void*[] _NewVTables;");
WriteLine("private static void*[] _Thunks;");
WriteLine("private static {0}<IntPtr, WeakReference> _References;", dictionary);
NewLine();
@ -1340,7 +1340,7 @@ namespace CppSharp.Generators.CSharp @@ -1340,7 +1340,7 @@ namespace CppSharp.Generators.CSharp
// Get the _Thunks
WriteLine("if (_Thunks == null)");
WriteStartBraceIndent();
WriteStartBraceIndent();
WriteLine("_Thunks = new void*[{0}];", wrappedEntries.Count);
var uniqueEntries = new HashSet<VTableComponent>();
@ -1379,24 +1379,24 @@ namespace CppSharp.Generators.CSharp @@ -1379,24 +1379,24 @@ namespace CppSharp.Generators.CSharp
}
private void SaveOriginalVTablePointersMS(Class @class)
{
{
WriteLine("_OldVTables = new void*[{0}];", @class.Layout.VFTables.Count);
for (int i = 0; i < @class.Layout.VFTables.Count; i++)
{
{
WriteLine("_OldVTables[{0}] = native->vfptr{0}.ToPointer();", i);
}
}
private void SaveOriginalVTablePointersItanium()
{
{
WriteLine("_OldVTables = new void*[1];");
WriteLine("_OldVTables[0] = native->vfptr0.ToPointer();");
}
private void AllocateNewVTablesMS(Class @class)
{
{
WriteLine("_NewVTables = new void*[{0}];", @class.Layout.VFTables.Count);
for (int tableIndex = 0; tableIndex < @class.Layout.VFTables.Count; tableIndex++)
@ -1412,10 +1412,10 @@ namespace CppSharp.Generators.CSharp @@ -1412,10 +1412,10 @@ namespace CppSharp.Generators.CSharp
var entry = vfptr.Layout.Components[entryIndex];
var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry)
* (Driver.Options.Is32Bit ? 4 : 8);
if (entry.Ignore)
if (entry.Ignore)
WriteLine("*(void**)(vfptr{0} + {1}) = *(void**)(native->vfptr{0} + {1});",
tableIndex, offsetInBytes);
else
else
WriteLine("*(void**)(vfptr{0} + {1}) = _Thunks[{2}];", tableIndex,
offsetInBytes, entryIndex);
}
@ -1424,7 +1424,7 @@ namespace CppSharp.Generators.CSharp @@ -1424,7 +1424,7 @@ namespace CppSharp.Generators.CSharp
WriteCloseBraceIndent();
NewLine();
for (var i = 0; i < @class.Layout.VFTables.Count; i++)
for (var i = 0; i < @class.Layout.VFTables.Count; i++)
WriteLine("native->vfptr{0} = new IntPtr(_NewVTables[{0}]);", i);
}
@ -1434,7 +1434,7 @@ namespace CppSharp.Generators.CSharp @@ -1434,7 +1434,7 @@ namespace CppSharp.Generators.CSharp
// reserve space for the offset-to-top and RTTI pointers as well
var size = entries.Count;
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.Options.Is32Bit ? 4 : 8);
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.Options.Is32Bit ? 4 : 8);
WriteLine("_NewVTables[0] = vfptr0.ToPointer();");
for (int i = 0; i < entries.Count; i++)
@ -1442,15 +1442,15 @@ namespace CppSharp.Generators.CSharp @@ -1442,15 +1442,15 @@ namespace CppSharp.Generators.CSharp
var entry = entries[i];
var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry)
* (Driver.Options.Is32Bit ? 4 : 8);
if (entry.Ignore)
if (entry.Ignore)
WriteLine("*(void**)(vfptr0 + {0}) = *(void**)(native->vfptr0 + {0});", offsetInBytes);
else
else
WriteLine("*(void**)(vfptr0 + {0}) = _Thunks[{1}];", offsetInBytes, i);
}
WriteCloseBraceIndent();
NewLine();
NewLine();
WriteLine("native->vfptr0 = new IntPtr(_NewVTables[0]);");
}
@ -1483,7 +1483,7 @@ namespace CppSharp.Generators.CSharp @@ -1483,7 +1483,7 @@ namespace CppSharp.Generators.CSharp
var marshals = new List<string>();
for (int i = 0; i < method.Parameters.Count; i++)
{
var param = method.Parameters[i];
var param = method.Parameters[i];
if (!param.IsGenerated)
continue;
@ -1566,16 +1566,16 @@ namespace CppSharp.Generators.CSharp @@ -1566,16 +1566,16 @@ namespace CppSharp.Generators.CSharp
private void GenerateVTableMethodDelegates(Class @class, Method method)
{
PushBlock(CSharpBlockKind.VTableDelegate);
// This works around a parser bug, see https://github.com/mono/CppSharp/issues/202
if (method.Signature != null)
{
PushBlock(CSharpBlockKind.VTableDelegate);
// This works around a parser bug, see https://github.com/mono/CppSharp/issues/202
if (method.Signature != null)
{
var cleanSig = method.Signature.ReplaceLineBreaks("");
cleanSig = Regex.Replace(cleanSig, @"\s+", " ");
WriteLine("// {0}", cleanSig);
}
WriteLine("// {0}", cleanSig);
}
WriteLine("[SuppressUnmanagedCodeSecurity]");
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
method.CallingConvention.ToInteropCallConv());
@ -1759,14 +1759,14 @@ namespace CppSharp.Generators.CSharp @@ -1759,14 +1759,14 @@ namespace CppSharp.Generators.CSharp
public void GenerateClassConstructors(Class @class)
{
if (@class.IsStatic)
return;
if (@class.IsStatic)
return;
// Output a default constructor that takes the native pointer.
GenerateNativeConstructor(@class);
foreach (var ctor in @class.Constructors)
{
{
if (ASTUtils.CheckIgnoreMethod(ctor, Options))
continue;
@ -1929,8 +1929,8 @@ namespace CppSharp.Generators.CSharp @@ -1929,8 +1929,8 @@ namespace CppSharp.Generators.CSharp
}
private bool GenerateClassConstructorBase(Class @class, Method method)
{
var hasBase = @class.HasBaseClass;
{
var hasBase = @class.HasBaseClass;
if (hasBase && !@class.IsValueType)
{
@ -2072,23 +2072,23 @@ namespace CppSharp.Generators.CSharp @@ -2072,23 +2072,23 @@ namespace CppSharp.Generators.CSharp
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
private void CheckArgumentRange(Function method)
{
if (Driver.Options.MarshalCharAsManagedChar)
{
foreach (var param in method.Parameters.Where(
p => p.Type.IsPrimitiveType(PrimitiveType.Int8)))
{
WriteLine("if ({0} < char.MinValue || {0} > sbyte.MaxValue)", param.Name);
WriteLineIndent(
"throw new global::System.ArgumentException(\"{0} must be in the range {1} - {2}.\");",
param.Name, (int) char.MinValue, sbyte.MaxValue);
}
}
}
}
private void CheckArgumentRange(Function method)
{
if (Driver.Options.MarshalCharAsManagedChar)
{
foreach (var param in method.Parameters.Where(
p => p.Type.IsPrimitiveType(PrimitiveType.Int8)))
{
WriteLine("if ({0} < char.MinValue || {0} > sbyte.MaxValue)", param.Name);
WriteLineIndent(
"throw new global::System.ArgumentException(\"{0} must be in the range {1} - {2}.\");",
param.Name, (int) char.MinValue, sbyte.MaxValue);
}
}
}
private static AccessSpecifier GetValidMethodAccess(Method method)
{
switch (method.Access)
@ -2130,24 +2130,24 @@ namespace CppSharp.Generators.CSharp @@ -2130,24 +2130,24 @@ namespace CppSharp.Generators.CSharp
private void GenerateOperator(Method method, Class @class)
{
if (method.IsSynthetized)
{
if (method.Kind == CXXMethodKind.Conversion)
{
// To avoid ambiguity when having the multiple inheritance pass enabled
{
if (method.Kind == CXXMethodKind.Conversion)
{
// To avoid ambiguity when having the multiple inheritance pass enabled
var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class);
if (@interface != null)
WriteLine("return new {0}(({2}){1});", method.ConversionType,
method.Parameters[0].Name, @interface.Name);
else
WriteLine("return new {0}({1});", method.ConversionType,
method.Parameters[0].Name);
}
else
{
var @operator = Operators.GetOperatorOverloadPair(method.OperatorKind);
WriteLine("return !({0} {1} {2});", method.Parameters[0].Name,
@operator, method.Parameters[1].Name);
if (@interface != null)
WriteLine("return new {0}(({2}){1});", method.ConversionType,
method.Parameters[0].Name, @interface.Name);
else
WriteLine("return new {0}({1});", method.ConversionType,
method.Parameters[0].Name);
}
else
{
var @operator = Operators.GetOperatorOverloadPair(method.OperatorKind);
WriteLine("return !({0} {1} {2});", method.Parameters[0].Name,
@operator, method.Parameters[1].Name);
}
return;
}
@ -2177,7 +2177,7 @@ namespace CppSharp.Generators.CSharp @@ -2177,7 +2177,7 @@ namespace CppSharp.Generators.CSharp
GenerateVTableClassSetupCall(@class);
}
public void GenerateInternalFunctionCall(Function function,
public void GenerateInternalFunctionCall(Function function,
List<Parameter> parameters = null, Type returnType = null)
{
if (parameters == null)
@ -2189,7 +2189,7 @@ namespace CppSharp.Generators.CSharp @@ -2189,7 +2189,7 @@ namespace CppSharp.Generators.CSharp
GenerateFunctionCall(functionName, parameters, function, returnType);
}
public void GenerateFunctionCall(string functionName, List<Parameter> parameters,
public void GenerateFunctionCall(string functionName, List<Parameter> parameters,
Function function, Type returnType = null)
{
if (function.IsPure)
@ -2198,8 +2198,8 @@ namespace CppSharp.Generators.CSharp @@ -2198,8 +2198,8 @@ namespace CppSharp.Generators.CSharp
return;
}
var retType = function.OriginalReturnType;
if (returnType == null)
var retType = function.OriginalReturnType;
if (returnType == null)
returnType = retType.Type;
var needsReturn = !retType.Type.IsPrimitiveType(PrimitiveType.Void);
@ -2220,12 +2220,12 @@ namespace CppSharp.Generators.CSharp @@ -2220,12 +2220,12 @@ namespace CppSharp.Generators.CSharp
var @params = GenerateFunctionParamsMarshal(parameters, function);
var originalFunction = function.OriginalFunction ?? function;
if (originalFunction.HasIndirectReturnTypeParameter)
{
var indirectRetType = originalFunction.Parameters.First(
parameter => parameter.Kind == ParameterKind.IndirectReturnType);
var originalFunction = function.OriginalFunction ?? function;
if (originalFunction.HasIndirectReturnTypeParameter)
{
var indirectRetType = originalFunction.Parameters.First(
parameter => parameter.Kind == ParameterKind.IndirectReturnType);
Class retClass;
indirectRetType.Type.Desugar().TryGetClass(out retClass);
@ -2247,37 +2247,37 @@ namespace CppSharp.Generators.CSharp @@ -2247,37 +2247,37 @@ namespace CppSharp.Generators.CSharp
name += param.Name;
names.Add(name);
}
var needsFixedThis = needsInstance && isValueType;
if (originalFunction.HasIndirectReturnTypeParameter)
{
var name = string.Format("new IntPtr(&{0})", GeneratedIdentifier("ret"));
names.Insert(0, name);
}
if (needsInstance)
{
}
var needsFixedThis = needsInstance && isValueType;
if (originalFunction.HasIndirectReturnTypeParameter)
{
var name = string.Format("new IntPtr(&{0})", GeneratedIdentifier("ret"));
names.Insert(0, name);
}
if (needsInstance)
{
var instanceIndex = GetInstanceParamIndex(function);
if (needsFixedThis)
{
{
names.Insert(instanceIndex, string.Format("new global::System.IntPtr(&{0})",
GeneratedIdentifier("fixedInstance")));
}
else
{
if (operatorParam != null)
{
{
names.Insert(instanceIndex, operatorParam.Name + "." + Helpers.InstanceIdentifier);
}
else
{
{
names.Insert(instanceIndex, Helpers.InstanceIdentifier);
}
}
}
}
if (needsFixedThis)
{
@ -2359,31 +2359,31 @@ namespace CppSharp.Generators.CSharp @@ -2359,31 +2359,31 @@ namespace CppSharp.Generators.CSharp
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
// Special case for indexer - needs to dereference if the internal
// function is a pointer type and the property is not.
if (retType.Type.IsAddress() &&
retType.Type.GetPointee().Equals(returnType) &&
returnType.IsPrimitiveType())
// Special case for indexer - needs to dereference if the internal
// function is a pointer type and the property is not.
if (retType.Type.IsAddress() &&
retType.Type.GetPointee().Equals(returnType) &&
returnType.IsPrimitiveType())
WriteLine("return *{0};", marshal.Context.Return);
else
WriteLine("return {0};", marshal.Context.Return);
}
}
private int GetInstanceParamIndex(Function function)
{
var method = function as Method;
if (Options.IsMicrosoftAbi)
return 0;
var indirectReturnType = method.Parameters.FirstOrDefault(
parameter => parameter.Kind == ParameterKind.IndirectReturnType);
var indirectReturnTypeIndex = method.Parameters.IndexOf(indirectReturnType);
return indirectReturnTypeIndex >= 0 ? ++indirectReturnTypeIndex : 0;
}
}
private int GetInstanceParamIndex(Function function)
{
var method = function as Method;
if (Options.IsMicrosoftAbi)
return 0;
var indirectReturnType = method.Parameters.FirstOrDefault(
parameter => parameter.Kind == ParameterKind.IndirectReturnType);
var indirectReturnTypeIndex = method.Parameters.IndexOf(indirectReturnType);
return indirectReturnTypeIndex >= 0 ? ++indirectReturnTypeIndex : 0;
}
private void GenerateFunctionCallOutParams(IEnumerable<ParamMarshal> @params,
ICollection<TextGenerator> cleanups)
{
@ -2522,7 +2522,7 @@ namespace CppSharp.Generators.CSharp @@ -2522,7 +2522,7 @@ namespace CppSharp.Generators.CSharp
#endregion
public bool GenerateTypedef(TypedefDecl typedef)
{
{
if (!typedef.IsGenerated)
return false;
@ -2540,17 +2540,17 @@ namespace CppSharp.Generators.CSharp @@ -2540,17 +2540,17 @@ namespace CppSharp.Generators.CSharp
}
else if (typedef.Type.IsPointerTo(out functionType))
{
PushBlock(CSharpBlockKind.Typedef);
var attributedType = typedef.Type.GetPointee() as AttributedType;
if (attributedType != null)
{
var equivalentFunctionType = attributedType.Equivalent.Type as FunctionType;
var callingConvention = equivalentFunctionType.CallingConvention.ToInteropCallConv();
if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi)
{
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
callingConvention);
}
PushBlock(CSharpBlockKind.Typedef);
var attributedType = typedef.Type.GetPointee() as AttributedType;
if (attributedType != null)
{
var equivalentFunctionType = attributedType.Equivalent.Type as FunctionType;
var callingConvention = equivalentFunctionType.CallingConvention.ToInteropCallConv();
if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi)
{
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
callingConvention);
}
}
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
WriteLine("{0}unsafe {1};",
@ -2565,7 +2565,7 @@ namespace CppSharp.Generators.CSharp @@ -2565,7 +2565,7 @@ namespace CppSharp.Generators.CSharp
}
public void GenerateEnum(Enumeration @enum)
{
{
if (!@enum.IsGenerated) return;
PushBlock(CSharpBlockKind.Enum);
@ -2631,7 +2631,7 @@ namespace CppSharp.Generators.CSharp @@ -2631,7 +2631,7 @@ namespace CppSharp.Generators.CSharp
if (method.IsConstructor && !method.IsCopyConstructor)
functionName = "ctor";
else if (method.IsCopyConstructor)
functionName = "cctor";
functionName = "cctor";
else if (method.IsDestructor)
functionName = "dtor";
else
@ -2649,7 +2649,7 @@ namespace CppSharp.Generators.CSharp @@ -2649,7 +2649,7 @@ namespace CppSharp.Generators.CSharp
if (index >= 0)
identifier += "_" + index.ToString(CultureInfo.InvariantCulture);
else if (function.Index.HasValue)
else if (function.Index.HasValue)
identifier += "_" + function.Index.Value;
return identifier;
@ -2685,8 +2685,8 @@ namespace CppSharp.Generators.CSharp @@ -2685,8 +2685,8 @@ namespace CppSharp.Generators.CSharp
if (Options.GenerateInternalImports)
libName = "__Internal";
Write("[DllImport(\"{0}\", ", libName);
Write("[DllImport(\"{0}\", ", libName);
var callConv = function.CallingConvention.ToInteropCallConv();
WriteLine("CallingConvention = global::System.Runtime.InteropServices.CallingConvention.{0},",
callConv);
@ -2705,20 +2705,20 @@ namespace CppSharp.Generators.CSharp @@ -2705,20 +2705,20 @@ namespace CppSharp.Generators.CSharp
var retType = retParam.CSharpType(typePrinter);
var method = function as Method;
var isInstanceMethod = method != null && !method.IsStatic;
if (isInstanceMethod && Options.IsMicrosoftAbi)
var isInstanceMethod = method != null && !method.IsStatic;
if (isInstanceMethod && Options.IsMicrosoftAbi)
{
@params.Add("global::System.IntPtr instance");
if (method.IsConstructor)
if (method.IsConstructor)
retType = "global::System.IntPtr";
}
if (!function.HasIndirectReturnTypeParameter &&
isInstanceMethod && Options.IsItaniumAbi)
@params.Add("global::System.IntPtr instance");
if (!function.HasIndirectReturnTypeParameter &&
isInstanceMethod && Options.IsItaniumAbi)
@params.Add("global::System.IntPtr instance");
foreach (var param in function.Parameters)
{
if (param.Kind == ParameterKind.OperatorParameter)
@ -2727,12 +2727,12 @@ namespace CppSharp.Generators.CSharp @@ -2727,12 +2727,12 @@ namespace CppSharp.Generators.CSharp
var typeName = param.CSharpType(typePrinter);
@params.Add(string.Format("{0} {1}", typeName, param.Name));
if (param.Kind == ParameterKind.IndirectReturnType &&
isInstanceMethod && Options.IsItaniumAbi)
@params.Add("global::System.IntPtr instance");
}
if (param.Kind == ParameterKind.IndirectReturnType &&
isInstanceMethod && Options.IsItaniumAbi)
@params.Add("global::System.IntPtr instance");
}
if (method != null && method.IsConstructor)
{
var @class = method.Namespace as Class;

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

File diff suppressed because it is too large Load Diff

54
src/Generator/Generators/ExtensionMethods.cs

@ -1,27 +1,27 @@ @@ -1,27 +1,27 @@
using CppSharp.AST;
using Interop = System.Runtime.InteropServices;
namespace CppSharp.Generators
{
public static class ExtensionMethods
{
public static Interop.CallingConvention ToInteropCallConv(this CallingConvention convention)
{
switch (convention)
{
case CallingConvention.Default:
return Interop.CallingConvention.Winapi;
case CallingConvention.C:
return Interop.CallingConvention.Cdecl;
case CallingConvention.StdCall:
return Interop.CallingConvention.StdCall;
case CallingConvention.ThisCall:
return Interop.CallingConvention.ThisCall;
case CallingConvention.FastCall:
return Interop.CallingConvention.FastCall;
}
return Interop.CallingConvention.Winapi;
}
}
}
using CppSharp.AST;
using Interop = System.Runtime.InteropServices;
namespace CppSharp.Generators
{
public static class ExtensionMethods
{
public static Interop.CallingConvention ToInteropCallConv(this CallingConvention convention)
{
switch (convention)
{
case CallingConvention.Default:
return Interop.CallingConvention.Winapi;
case CallingConvention.C:
return Interop.CallingConvention.Cdecl;
case CallingConvention.StdCall:
return Interop.CallingConvention.StdCall;
case CallingConvention.ThisCall:
return Interop.CallingConvention.ThisCall;
case CallingConvention.FastCall:
return Interop.CallingConvention.FastCall;
}
return Interop.CallingConvention.Winapi;
}
}
}

42
src/Generator/Generators/Template.cs

@ -38,8 +38,8 @@ namespace CppSharp.Generators @@ -38,8 +38,8 @@ namespace CppSharp.Generators
private bool hasIndentChanged;
private bool isSubBlock;
public Func<bool> CheckGenerate;
public Func<bool> CheckGenerate;
public Block() : this(BlockKind.Unknown)
{
@ -83,9 +83,9 @@ namespace CppSharp.Generators @@ -83,9 +83,9 @@ namespace CppSharp.Generators
public virtual string Generate(DriverOptions options)
{
if (CheckGenerate != null && !CheckGenerate())
return "";
if (CheckGenerate != null && !CheckGenerate())
return "";
if (Blocks.Count == 0)
return Text.ToString();
@ -170,17 +170,17 @@ namespace CppSharp.Generators @@ -170,17 +170,17 @@ namespace CppSharp.Generators
return builder.ToString();
}
public bool IsEmpty
{
get
{
if (Blocks.Any(block => !block.IsEmpty))
return false;
return string.IsNullOrEmpty(Text.ToString());
}
}
public bool IsEmpty
{
get
{
if (Blocks.Any(block => !block.IsEmpty))
return false;
return string.IsNullOrEmpty(Text.ToString());
}
}
#region ITextGenerator implementation
public uint Indent { get { return Text.Indent; } }
@ -296,14 +296,14 @@ namespace CppSharp.Generators @@ -296,14 +296,14 @@ namespace CppSharp.Generators
ActiveBlock = block;
}
public Block PopBlock(NewLineKind newLineKind = NewLineKind.Never)
public Block PopBlock(NewLineKind newLineKind = NewLineKind.Never)
{
var block = ActiveBlock;
var block = ActiveBlock;
ActiveBlock.NewLineKind = newLineKind;
ActiveBlock = ActiveBlock.Parent;
return block;
return block;
}
public IEnumerable<Block> FindBlocks(int kind)

72
src/Generator/Options.cs

@ -54,14 +54,14 @@ namespace CppSharp @@ -54,14 +54,14 @@ namespace CppSharp
// General options
public bool Quiet;
public bool ShowHelpText;
public bool OutputDebug;
/// <summary>
/// Set to true to simulate generating without actually writing
/// any output to disk. This can be useful to activate while
/// debugging the parser generator so generator bugs do not get
/// in the way while iterating.
/// </summary>
public bool OutputDebug;
/// <summary>
/// Set to true to simulate generating without actually writing
/// any output to disk. This can be useful to activate while
/// debugging the parser generator so generator bugs do not get
/// in the way while iterating.
/// </summary>
public bool DryRun;
// Parser options
@ -101,39 +101,39 @@ namespace CppSharp @@ -101,39 +101,39 @@ namespace CppSharp
public bool GenerateAbstractImpls;
public bool GenerateInterfacesForMultipleInheritance;
public bool GenerateInternalImports;
public bool GenerateClassMarshals;
public bool GenerateInlines;
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;
/// <summary>
/// If set to true the generator will use ConstructorToConversionOperatorPass to
/// create implicit and explicit conversion operators out of single argument
/// constructors.
/// </summary>
public bool GenerateConversionOperators;
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;
/// <summary>
/// If set to true the generator will use ConstructorToConversionOperatorPass to
/// create implicit and explicit conversion operators out of single argument
/// constructors.
/// </summary>
public bool GenerateConversionOperators;
//List of include directories that are used but not generated
public List<string> NoGenIncludeDirs;
/// <summary>
/// Wether the generated C# code should be automatically compiled.
/// </summary>
public bool CompileCode;
/// <summary>
/// Wether the generated C# code should be automatically compiled.
/// </summary>
public bool CompileCode;
/// <summary>
/// Enable this option to enable generation of finalizers.

448
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -1,109 +1,109 @@ @@ -1,109 +1,109 @@
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
namespace CppSharp.Passes
{
/// <summary>
/// Checks for missing operator overloads required by C#.
/// </summary>
class CheckOperatorsOverloadsPass : TranslationUnitPass
{
public CheckOperatorsOverloadsPass()
{
ClearVisitedDeclarations = false;
}
public override bool VisitClassDecl(Class @class)
{
if (@class.CompleteDeclaration != null)
return VisitClassDecl(@class.CompleteDeclaration as Class);
if (!VisitDeclarationContext(@class))
return false;
// Check for C++ operators that cannot be represented in C#.
CheckInvalidOperators(@class);
if (Driver.Options.IsCSharpGenerator)
{
// The comparison operators, if overloaded, must be overloaded in pairs;
// that is, if == is overloaded, != must also be overloaded. The reverse
// is also true, and similar for < and >, and for <= and >=.
HandleMissingOperatorOverloadPair(@class, CXXOperatorKind.EqualEqual,
CXXOperatorKind.ExclaimEqual);
HandleMissingOperatorOverloadPair(@class, CXXOperatorKind.Less,
CXXOperatorKind.Greater);
HandleMissingOperatorOverloadPair(@class, CXXOperatorKind.LessEqual,
CXXOperatorKind.GreaterEqual);
}
return false;
}
private void CheckInvalidOperators(Class @class)
{
foreach (var @operator in @class.Operators.Where(o => o.IsGenerated))
{
if (!IsValidOperatorOverload(@operator))
{
Driver.Diagnostics.Debug(DiagnosticId.InvalidOperatorOverload,
"Invalid operator overload {0}::{1}",
@class.OriginalName, @operator.OperatorKind);
@operator.ExplicitlyIgnore();
continue;
}
if (@operator.SynthKind == FunctionSynthKind.NonMemberOperator)
continue;
if (@operator.OperatorKind == CXXOperatorKind.Subscript)
{
CreateIndexer(@class, @operator);
}
else
{
// Handle missing operator parameters
if (@operator.IsStatic)
@operator.Parameters = @operator.Parameters.Skip(1).ToList();
var type = new PointerType()
{
QualifiedPointee = new QualifiedType(new TagType(@class)),
Modifier = PointerType.TypeModifier.LVReference
};
@operator.Parameters.Insert(0, new Parameter
{
Name = Generator.GeneratedIdentifier("op"),
QualifiedType = new QualifiedType(type),
Kind = ParameterKind.OperatorParameter
});
}
}
}
void CreateIndexer(Class @class, Method @operator)
{
var property = new Property
{
Name = "Item",
QualifiedType = @operator.ReturnType,
Access = @operator.Access,
Namespace = @class,
GetMethod = @operator
};
var returnType = @operator.Type;
if (returnType.IsAddress())
{
var pointer = returnType as PointerType;
var qualifiedPointee = pointer.QualifiedPointee;
if (!qualifiedPointee.Qualifiers.IsConst)
property.SetMethod = @operator;
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
namespace CppSharp.Passes
{
/// <summary>
/// Checks for missing operator overloads required by C#.
/// </summary>
class CheckOperatorsOverloadsPass : TranslationUnitPass
{
public CheckOperatorsOverloadsPass()
{
ClearVisitedDeclarations = false;
}
public override bool VisitClassDecl(Class @class)
{
if (@class.CompleteDeclaration != null)
return VisitClassDecl(@class.CompleteDeclaration as Class);
if (!VisitDeclarationContext(@class))
return false;
// Check for C++ operators that cannot be represented in C#.
CheckInvalidOperators(@class);
if (Driver.Options.IsCSharpGenerator)
{
// The comparison operators, if overloaded, must be overloaded in pairs;
// that is, if == is overloaded, != must also be overloaded. The reverse
// is also true, and similar for < and >, and for <= and >=.
HandleMissingOperatorOverloadPair(@class, CXXOperatorKind.EqualEqual,
CXXOperatorKind.ExclaimEqual);
HandleMissingOperatorOverloadPair(@class, CXXOperatorKind.Less,
CXXOperatorKind.Greater);
HandleMissingOperatorOverloadPair(@class, CXXOperatorKind.LessEqual,
CXXOperatorKind.GreaterEqual);
}
return false;
}
private void CheckInvalidOperators(Class @class)
{
foreach (var @operator in @class.Operators.Where(o => o.IsGenerated))
{
if (!IsValidOperatorOverload(@operator))
{
Driver.Diagnostics.Debug(DiagnosticId.InvalidOperatorOverload,
"Invalid operator overload {0}::{1}",
@class.OriginalName, @operator.OperatorKind);
@operator.ExplicitlyIgnore();
continue;
}
if (@operator.SynthKind == FunctionSynthKind.NonMemberOperator)
continue;
if (@operator.OperatorKind == CXXOperatorKind.Subscript)
{
CreateIndexer(@class, @operator);
}
else
{
// Handle missing operator parameters
if (@operator.IsStatic)
@operator.Parameters = @operator.Parameters.Skip(1).ToList();
var type = new PointerType()
{
QualifiedPointee = new QualifiedType(new TagType(@class)),
Modifier = PointerType.TypeModifier.LVReference
};
@operator.Parameters.Insert(0, new Parameter
{
Name = Generator.GeneratedIdentifier("op"),
QualifiedType = new QualifiedType(type),
Kind = ParameterKind.OperatorParameter
});
}
}
}
void CreateIndexer(Class @class, Method @operator)
{
var property = new Property
{
Name = "Item",
QualifiedType = @operator.ReturnType,
Access = @operator.Access,
Namespace = @class,
GetMethod = @operator
};
var returnType = @operator.Type;
if (returnType.IsAddress())
{
var pointer = returnType as PointerType;
var qualifiedPointee = pointer.QualifiedPointee;
if (!qualifiedPointee.Qualifiers.IsConst)
property.SetMethod = @operator;
}
// If we've a setter use the pointee as the type of the property.
@ -111,68 +111,68 @@ namespace CppSharp.Passes @@ -111,68 +111,68 @@ namespace CppSharp.Passes
if (pointerType != null && property.HasSetter)
property.QualifiedType = new QualifiedType(
pointerType.Pointee, property.QualifiedType.Qualifiers);
if (Driver.Options.IsCLIGenerator)
// C++/CLI uses "default" as the indexer property name.
property.Name = "default";
property.Parameters.AddRange(@operator.Parameters);
@class.Properties.Add(property);
@operator.GenerationKind = GenerationKind.Internal;
}
static void HandleMissingOperatorOverloadPair(Class @class, CXXOperatorKind op1,
CXXOperatorKind op2)
{
foreach (var op in @class.Operators.Where(
o => o.OperatorKind == op1 || o.OperatorKind == op2).ToList())
{
int index;
var missingKind = CheckMissingOperatorOverloadPair(@class, out index, op1, op2,
op.Parameters.Last().Type);
if (missingKind == CXXOperatorKind.None || !op.IsGenerated)
continue;
var method = new Method()
{
Name = Operators.GetOperatorIdentifier(missingKind),
Namespace = @class,
IsSynthetized = true,
Kind = CXXMethodKind.Operator,
OperatorKind = missingKind,
ReturnType = op.ReturnType,
Parameters = op.Parameters
};
@class.Methods.Insert(index, method);
}
}
static CXXOperatorKind CheckMissingOperatorOverloadPair(Class @class,
out int index, CXXOperatorKind op1, CXXOperatorKind op2, Type type)
{
var first = @class.Operators.FirstOrDefault(o => o.OperatorKind == op1 &&
o.Parameters.Last().Type.Equals(type));
var second = @class.Operators.FirstOrDefault(o => o.OperatorKind == op2 &&
o.Parameters.Last().Type.Equals(type));
var hasFirst = first != null;
var hasSecond = second != null;
if (hasFirst && (!hasSecond || !second.IsGenerated))
{
index = @class.Methods.IndexOf(first);
return op2;
}
if (hasSecond && (!hasFirst || !first.IsGenerated))
{
index = @class.Methods.IndexOf(second);
return op1;
}
@class.Properties.Add(property);
@operator.GenerationKind = GenerationKind.Internal;
}
static void HandleMissingOperatorOverloadPair(Class @class, CXXOperatorKind op1,
CXXOperatorKind op2)
{
foreach (var op in @class.Operators.Where(
o => o.OperatorKind == op1 || o.OperatorKind == op2).ToList())
{
int index;
var missingKind = CheckMissingOperatorOverloadPair(@class, out index, op1, op2,
op.Parameters.Last().Type);
if (missingKind == CXXOperatorKind.None || !op.IsGenerated)
continue;
var method = new Method()
{
Name = Operators.GetOperatorIdentifier(missingKind),
Namespace = @class,
IsSynthetized = true,
Kind = CXXMethodKind.Operator,
OperatorKind = missingKind,
ReturnType = op.ReturnType,
Parameters = op.Parameters
};
@class.Methods.Insert(index, method);
}
}
static CXXOperatorKind CheckMissingOperatorOverloadPair(Class @class,
out int index, CXXOperatorKind op1, CXXOperatorKind op2, Type type)
{
var first = @class.Operators.FirstOrDefault(o => o.OperatorKind == op1 &&
o.Parameters.Last().Type.Equals(type));
var second = @class.Operators.FirstOrDefault(o => o.OperatorKind == op2 &&
o.Parameters.Last().Type.Equals(type));
var hasFirst = first != null;
var hasSecond = second != null;
if (hasFirst && (!hasSecond || !second.IsGenerated))
{
index = @class.Methods.IndexOf(first);
return op2;
}
if (hasSecond && (!hasFirst || !first.IsGenerated))
{
index = @class.Methods.IndexOf(second);
return op1;
}
index = 0;
return CXXOperatorKind.None;
@ -200,66 +200,66 @@ namespace CppSharp.Passes @@ -200,66 +200,66 @@ namespace CppSharp.Passes
// The array indexing operator can be overloaded
case CXXOperatorKind.Subscript:
// The conversion operators can be overloaded
// The conversion operators can be overloaded
case CXXOperatorKind.Conversion:
case CXXOperatorKind.ExplicitConversion:
return true;
// The comparison operators can be overloaded if their return type is bool
case CXXOperatorKind.EqualEqual:
case CXXOperatorKind.ExclaimEqual:
case CXXOperatorKind.Less:
case CXXOperatorKind.Greater:
case CXXOperatorKind.LessEqual:
case CXXOperatorKind.GreaterEqual:
return @operator.ReturnType.Type.IsPrimitiveType(PrimitiveType.Bool);
// Only prefix operators can be overloaded
case CXXOperatorKind.PlusPlus:
case CXXOperatorKind.MinusMinus:
return @operator.Parameters.Count == 0;
// Bitwise shift operators can only be overloaded if the second parameter is int
case CXXOperatorKind.LessLess:
case CXXOperatorKind.GreaterGreater:
PrimitiveType primitiveType;
return @operator.Parameters.Last().Type.IsPrimitiveType(out primitiveType) &&
primitiveType == PrimitiveType.Int32;
// No parameters means the dereference operator - cannot be overloaded
case CXXOperatorKind.Star:
return @operator.Parameters.Count > 0;
// Assignment operators cannot be overloaded
case CXXOperatorKind.PlusEqual:
case CXXOperatorKind.MinusEqual:
case CXXOperatorKind.StarEqual:
case CXXOperatorKind.SlashEqual:
case CXXOperatorKind.PercentEqual:
case CXXOperatorKind.AmpEqual:
case CXXOperatorKind.PipeEqual:
case CXXOperatorKind.CaretEqual:
case CXXOperatorKind.LessLessEqual:
case CXXOperatorKind.GreaterGreaterEqual:
// The conditional logical operators cannot be overloaded
case CXXOperatorKind.AmpAmp:
case CXXOperatorKind.PipePipe:
// These operators cannot be overloaded.
case CXXOperatorKind.Equal:
case CXXOperatorKind.Comma:
case CXXOperatorKind.ArrowStar:
case CXXOperatorKind.Arrow:
case CXXOperatorKind.Call:
case CXXOperatorKind.Conditional:
case CXXOperatorKind.New:
case CXXOperatorKind.Delete:
case CXXOperatorKind.Array_New:
case CXXOperatorKind.Array_Delete:
default:
return false;
}
}
}
}
return true;
// The comparison operators can be overloaded if their return type is bool
case CXXOperatorKind.EqualEqual:
case CXXOperatorKind.ExclaimEqual:
case CXXOperatorKind.Less:
case CXXOperatorKind.Greater:
case CXXOperatorKind.LessEqual:
case CXXOperatorKind.GreaterEqual:
return @operator.ReturnType.Type.IsPrimitiveType(PrimitiveType.Bool);
// Only prefix operators can be overloaded
case CXXOperatorKind.PlusPlus:
case CXXOperatorKind.MinusMinus:
return @operator.Parameters.Count == 0;
// Bitwise shift operators can only be overloaded if the second parameter is int
case CXXOperatorKind.LessLess:
case CXXOperatorKind.GreaterGreater:
PrimitiveType primitiveType;
return @operator.Parameters.Last().Type.IsPrimitiveType(out primitiveType) &&
primitiveType == PrimitiveType.Int32;
// No parameters means the dereference operator - cannot be overloaded
case CXXOperatorKind.Star:
return @operator.Parameters.Count > 0;
// Assignment operators cannot be overloaded
case CXXOperatorKind.PlusEqual:
case CXXOperatorKind.MinusEqual:
case CXXOperatorKind.StarEqual:
case CXXOperatorKind.SlashEqual:
case CXXOperatorKind.PercentEqual:
case CXXOperatorKind.AmpEqual:
case CXXOperatorKind.PipeEqual:
case CXXOperatorKind.CaretEqual:
case CXXOperatorKind.LessLessEqual:
case CXXOperatorKind.GreaterGreaterEqual:
// The conditional logical operators cannot be overloaded
case CXXOperatorKind.AmpAmp:
case CXXOperatorKind.PipePipe:
// These operators cannot be overloaded.
case CXXOperatorKind.Equal:
case CXXOperatorKind.Comma:
case CXXOperatorKind.ArrowStar:
case CXXOperatorKind.Arrow:
case CXXOperatorKind.Call:
case CXXOperatorKind.Conditional:
case CXXOperatorKind.New:
case CXXOperatorKind.Delete:
case CXXOperatorKind.Array_New:
case CXXOperatorKind.Array_Delete:
default:
return false;
}
}
}
}

116
src/Generator/Passes/ConstructorToConversionOperatorPass.cs

@ -1,58 +1,58 @@ @@ -1,58 +1,58 @@
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
namespace CppSharp.Passes
{
/// <summary>
/// This pass will create conversion operators out of single argument
/// constructors.
/// </summary>
public class ConstructorToConversionOperatorPass : TranslationUnitPass
{
public override bool VisitMethodDecl(Method method)
{
if (!method.IsConstructor)
return false;
if (method.IsCopyConstructor)
return false;
if (method.Parameters.Count != 1)
return false;
var parameter = method.Parameters[0];
var parameterType = parameter.Type as PointerType;
if (parameterType == null)
return false;
if (!parameterType.IsReference)
return false;
var qualifiedPointee = parameterType.QualifiedPointee;
Class castFromClass;
if (!qualifiedPointee.Type.TryGetClass(out castFromClass))
return false;
var castToClass = method.OriginalNamespace as Class;
if (castToClass == null)
return false;
if (castFromClass == castToClass)
return false;
var operatorKind = method.IsExplicit
? CXXOperatorKind.ExplicitConversion
: CXXOperatorKind.Conversion;
var castToType = new TagType(castToClass);
var qualifiedCastToType = new QualifiedType(castToType);
var conversionOperator = new Method()
{
Name = Operators.GetOperatorIdentifier(operatorKind),
Namespace = castFromClass,
Kind = CXXMethodKind.Conversion,
IsSynthetized = true,
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType
};
conversionOperator.OperatorKind = operatorKind;
castFromClass.Methods.Add(conversionOperator);
return true;
}
}
}
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
namespace CppSharp.Passes
{
/// <summary>
/// This pass will create conversion operators out of single argument
/// constructors.
/// </summary>
public class ConstructorToConversionOperatorPass : TranslationUnitPass
{
public override bool VisitMethodDecl(Method method)
{
if (!method.IsConstructor)
return false;
if (method.IsCopyConstructor)
return false;
if (method.Parameters.Count != 1)
return false;
var parameter = method.Parameters[0];
var parameterType = parameter.Type as PointerType;
if (parameterType == null)
return false;
if (!parameterType.IsReference)
return false;
var qualifiedPointee = parameterType.QualifiedPointee;
Class castFromClass;
if (!qualifiedPointee.Type.TryGetClass(out castFromClass))
return false;
var castToClass = method.OriginalNamespace as Class;
if (castToClass == null)
return false;
if (castFromClass == castToClass)
return false;
var operatorKind = method.IsExplicit
? CXXOperatorKind.ExplicitConversion
: CXXOperatorKind.Conversion;
var castToType = new TagType(castToClass);
var qualifiedCastToType = new QualifiedType(castToType);
var conversionOperator = new Method()
{
Name = Operators.GetOperatorIdentifier(operatorKind),
Namespace = castFromClass,
Kind = CXXMethodKind.Conversion,
IsSynthetized = true,
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType
};
conversionOperator.OperatorKind = operatorKind;
castFromClass.Methods.Add(conversionOperator);
return true;
}
}
}

12
src/Generator/Passes/GenerateAbstractImplementationsPass.cs

@ -25,12 +25,12 @@ namespace CppSharp.Passes @@ -25,12 +25,12 @@ namespace CppSharp.Passes
public override bool VisitTranslationUnit(TranslationUnit unit)
{
var result = base.VisitTranslationUnit(unit);
foreach (var internalImpl in internalImpls)
if (internalImpl.Namespace != null)
internalImpl.Namespace.Classes.Add(internalImpl);
else
unit.Classes.AddRange(internalImpls);
var result = base.VisitTranslationUnit(unit);
foreach (var internalImpl in internalImpls)
if (internalImpl.Namespace != null)
internalImpl.Namespace.Classes.Add(internalImpl);
else
unit.Classes.AddRange(internalImpls);
internalImpls.Clear();
return result;

18
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -74,8 +74,8 @@ namespace CppSharp.Passes @@ -74,8 +74,8 @@ namespace CppSharp.Passes
public override bool VisitMethodDecl(Method method)
{
if (!VisitDeclaration(method))
return false;
return false;
if (ASTUtils.CheckIgnoreMethod(method, Driver.Options))
return false;
@ -84,12 +84,12 @@ namespace CppSharp.Passes @@ -84,12 +84,12 @@ namespace CppSharp.Passes
if (@class == null || @class.IsIncomplete)
return false;
if (method.IsConstructor)
return false;
if (method.IsSynthetized)
return false;
if (method.IsConstructor)
return false;
if (method.IsSynthetized)
return false;
if (IsGetter(method))
{
var name = method.Name.Substring("get".Length);
@ -114,7 +114,7 @@ namespace CppSharp.Passes @@ -114,7 +114,7 @@ namespace CppSharp.Passes
prop.SetMethod = method;
prop.Access = method.Access;
// Ignore the original method now that we know it is a setter.
// Ignore the original method now that we know it is a setter.
method.GenerationKind = GenerationKind.Internal;
Driver.Diagnostics.Debug("Setter created: {0}::{1}", @class.Name, name);

10
src/Generator/Passes/MultipleInheritancePass.cs

@ -67,7 +67,7 @@ namespace CppSharp.Passes @@ -67,7 +67,7 @@ namespace CppSharp.Passes
select new BaseClassSpecifier { Type = new TagType(i) });
@interface.Methods.AddRange(
from m in @base.Methods
from m in @base.Methods
where !m.IsConstructor && !m.IsDestructor && !m.IsStatic && m.IsDeclared && !m.IsOperator
select new Method(m) { Namespace = @interface });
@ -76,8 +76,8 @@ namespace CppSharp.Passes @@ -76,8 +76,8 @@ namespace CppSharp.Passes
where property.IsDeclared
select new Property(property) { Namespace = @interface });
@interface.Fields.AddRange(@base.Fields);
@interface.Fields.AddRange(@base.Fields);
if (@interface.Bases.Count == 0)
{
Property instance = new Property();
@ -112,7 +112,7 @@ namespace CppSharp.Passes @@ -112,7 +112,7 @@ namespace CppSharp.Passes
IsVirtual = false,
IsOverride = false
};
var rootBaseMethod = @class.GetRootBaseMethod(method, true);
var rootBaseMethod = @class.GetRootBaseMethod(method, true);
if (rootBaseMethod != null && rootBaseMethod.IsDeclared)
impl.ExplicitInterfaceImpl = @interface;
@class.Methods.Add(impl);
@ -126,7 +126,7 @@ namespace CppSharp.Passes @@ -126,7 +126,7 @@ namespace CppSharp.Passes
foreach (var property in @interface.Properties.Where(p => p.Name != Helpers.InstanceIdentifier))
{
var impl = new Property(property) { Namespace = @class };
var rootBaseProperty = @class.GetRootBaseProperty(property, true);
var rootBaseProperty = @class.GetRootBaseProperty(property, true);
if (rootBaseProperty != null && rootBaseProperty.IsDeclared)
impl.ExplicitInterfaceImpl = @interface;
@class.Properties.Add(impl);

660
src/Generator/Types/CppTypePrinter.cs

@ -1,330 +1,330 @@ @@ -1,330 +1,330 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CppSharp.AST;
using Type = CppSharp.AST.Type;
namespace CppSharp.Types
{
public enum CppTypePrintScopeKind
{
Local,
Qualified,
GlobalQualified
}
public class CppTypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{
public CppTypePrintScopeKind PrintScopeKind;
public bool PrintLogicalNames;
public bool PrintTypeQualifiers;
public CppTypePrinter(ITypeMapDatabase database, bool printTypeQualifiers = true)
{
PrintScopeKind = CppTypePrintScopeKind.GlobalQualified;
PrintTypeQualifiers = printTypeQualifiers;
}
public string VisitTagType(TagType tag, TypeQualifiers quals)
{
return tag.Declaration.Visit(this);
}
public string VisitArrayType(ArrayType array, TypeQualifiers quals)
{
var typeName = array.Type.Visit(this);
switch (array.SizeType)
{
case ArrayType.ArraySize.Constant:
return string.Format("{0}[{1}]", typeName, array.Size);
case ArrayType.ArraySize.Variable:
case ArrayType.ArraySize.Dependent:
case ArrayType.ArraySize.Incomplete:
return string.Format("{0}[]", typeName);
}
throw new NotSupportedException();
}
static string ConvertModifierToString(PointerType.TypeModifier modifier)
{
switch (modifier)
{
case PointerType.TypeModifier.Value: return string.Empty;
case PointerType.TypeModifier.Pointer: return "*";
case PointerType.TypeModifier.LVReference: return "&";
case PointerType.TypeModifier.RVReference: return "&&";
}
return string.Empty;
}
public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
var pointee = pointer.Pointee;
var function = pointee as FunctionType;
if (function != null)
{
var arguments = function.Parameters;
var returnType = function.ReturnType;
var args = string.Empty;
if (arguments.Count > 0)
args = VisitParameters(function.Parameters, hasNames: false);
return string.Format("{0} (*)({1})", returnType.Visit(this), args);
}
var pointeeType = pointer.Pointee.Visit(this, quals);
var mod = ConvertModifierToString(pointer.Modifier);
var s = PrintTypeQualifiers && quals.IsConst ? "const " : string.Empty;
s += string.Format("{0}{1}", pointeeType, mod);
return s;
}
public string VisitMemberPointerType(MemberPointerType member, TypeQualifiers quals)
{
return string.Empty;
}
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 "char";
case PrimitiveType.Int8: return "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 "void*";
case PrimitiveType.UIntPtr: return "uintptr_t";
case PrimitiveType.Null: return "std::nullptr_t";
}
throw new NotSupportedException();
}
public string VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
{
return GetDeclName(typedef.Declaration);
}
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)
{
return string.Format("{0}<{1}>", template.Template.TemplatedDecl.Visit(this),
string.Join(", ",
template.Arguments.Where(
a => a.Type.Type != null &&
!(a.Type.Type is DependentNameType)).Select(a => a.Type.Visit(this))));
}
public string VisitTemplateParameterType(TemplateParameterType param, TypeQualifiers quals)
{
if (param.Parameter.Name == null)
return string.Empty;
return param.Parameter.Name;
}
public string VisitTemplateParameterSubstitutionType(
TemplateParameterSubstitutionType param, TypeQualifiers quals)
{
return param.Replacement.Visit(this);
}
public string VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals)
{
return injected.Class.Visit(this);
}
public string VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals)
{
throw new System.NotImplementedException();
}
public string VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals)
{
return string.Empty;
}
public string VisitCILType(CILType type, TypeQualifiers quals)
{
return string.Empty;
}
public string VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals)
{
throw new System.NotImplementedException();
}
public string VisitDeclaration(Declaration decl, TypeQualifiers quals)
{
throw new System.NotImplementedException();
}
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);
return string.Format("{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 arg, bool hasName = true)
{
var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers);
var name = arg.Name;
if (hasName && !string.IsNullOrEmpty(name))
return string.Format("{0} {1}", type, name);
return type;
}
public string VisitDelegate(FunctionType function)
{
throw new System.NotImplementedException();
}
public string GetDeclName(Declaration declaration)
{
switch (PrintScopeKind)
{
case CppTypePrintScopeKind.Local:
return PrintLogicalNames ? declaration.LogicalOriginalName
: declaration.OriginalName;
case CppTypePrintScopeKind.Qualified:
return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName;
case CppTypePrintScopeKind.GlobalQualified:
return "::" + (PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName);
}
throw new NotSupportedException();
}
public string VisitDeclaration(Declaration decl)
{
return GetDeclName(decl);
}
public string VisitClassDecl(Class @class)
{
return VisitDeclaration(@class);
}
public string VisitFieldDecl(Field field)
{
return VisitDeclaration(field);
}
public string VisitFunctionDecl(Function function)
{
return VisitDeclaration(function);
}
public string VisitMethodDecl(Method method)
{
return VisitDeclaration(method);
}
public string VisitParameterDecl(Parameter parameter)
{
return VisitParameter(parameter, hasName: false);
}
public string VisitTypedefDecl(TypedefDecl typedef)
{
return VisitDeclaration(typedef);
}
public string VisitEnumDecl(Enumeration @enum)
{
return VisitDeclaration(@enum);
}
public string VisitVariableDecl(Variable variable)
{
return VisitDeclaration(variable);
}
public string VisitClassTemplateDecl(ClassTemplate template)
{
return VisitDeclaration(template);
}
public string VisitFunctionTemplateDecl(FunctionTemplate template)
{
return VisitDeclaration(template);
}
public string VisitMacroDefinition(MacroDefinition macro)
{
throw new NotImplementedException();
}
public string VisitNamespace(Namespace @namespace)
{
return VisitDeclaration(@namespace);
}
public string VisitEvent(Event @event)
{
return string.Empty;
}
public string VisitProperty(Property property)
{
return VisitDeclaration(property);
}
public string ToString(Type type)
{
return type.Visit(this);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using CppSharp.AST;
using Type = CppSharp.AST.Type;
namespace CppSharp.Types
{
public enum CppTypePrintScopeKind
{
Local,
Qualified,
GlobalQualified
}
public class CppTypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{
public CppTypePrintScopeKind PrintScopeKind;
public bool PrintLogicalNames;
public bool PrintTypeQualifiers;
public CppTypePrinter(ITypeMapDatabase database, bool printTypeQualifiers = true)
{
PrintScopeKind = CppTypePrintScopeKind.GlobalQualified;
PrintTypeQualifiers = printTypeQualifiers;
}
public string VisitTagType(TagType tag, TypeQualifiers quals)
{
return tag.Declaration.Visit(this);
}
public string VisitArrayType(ArrayType array, TypeQualifiers quals)
{
var typeName = array.Type.Visit(this);
switch (array.SizeType)
{
case ArrayType.ArraySize.Constant:
return string.Format("{0}[{1}]", typeName, array.Size);
case ArrayType.ArraySize.Variable:
case ArrayType.ArraySize.Dependent:
case ArrayType.ArraySize.Incomplete:
return string.Format("{0}[]", typeName);
}
throw new NotSupportedException();
}
static string ConvertModifierToString(PointerType.TypeModifier modifier)
{
switch (modifier)
{
case PointerType.TypeModifier.Value: return string.Empty;
case PointerType.TypeModifier.Pointer: return "*";
case PointerType.TypeModifier.LVReference: return "&";
case PointerType.TypeModifier.RVReference: return "&&";
}
return string.Empty;
}
public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
var pointee = pointer.Pointee;
var function = pointee as FunctionType;
if (function != null)
{
var arguments = function.Parameters;
var returnType = function.ReturnType;
var args = string.Empty;
if (arguments.Count > 0)
args = VisitParameters(function.Parameters, hasNames: false);
return string.Format("{0} (*)({1})", returnType.Visit(this), args);
}
var pointeeType = pointer.Pointee.Visit(this, quals);
var mod = ConvertModifierToString(pointer.Modifier);
var s = PrintTypeQualifiers && quals.IsConst ? "const " : string.Empty;
s += string.Format("{0}{1}", pointeeType, mod);
return s;
}
public string VisitMemberPointerType(MemberPointerType member, TypeQualifiers quals)
{
return string.Empty;
}
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 "char";
case PrimitiveType.Int8: return "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 "void*";
case PrimitiveType.UIntPtr: return "uintptr_t";
case PrimitiveType.Null: return "std::nullptr_t";
}
throw new NotSupportedException();
}
public string VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
{
return GetDeclName(typedef.Declaration);
}
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)
{
return string.Format("{0}<{1}>", template.Template.TemplatedDecl.Visit(this),
string.Join(", ",
template.Arguments.Where(
a => a.Type.Type != null &&
!(a.Type.Type is DependentNameType)).Select(a => a.Type.Visit(this))));
}
public string VisitTemplateParameterType(TemplateParameterType param, TypeQualifiers quals)
{
if (param.Parameter.Name == null)
return string.Empty;
return param.Parameter.Name;
}
public string VisitTemplateParameterSubstitutionType(
TemplateParameterSubstitutionType param, TypeQualifiers quals)
{
return param.Replacement.Visit(this);
}
public string VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals)
{
return injected.Class.Visit(this);
}
public string VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals)
{
throw new System.NotImplementedException();
}
public string VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals)
{
return string.Empty;
}
public string VisitCILType(CILType type, TypeQualifiers quals)
{
return string.Empty;
}
public string VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals)
{
throw new System.NotImplementedException();
}
public string VisitDeclaration(Declaration decl, TypeQualifiers quals)
{
throw new System.NotImplementedException();
}
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);
return string.Format("{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 arg, bool hasName = true)
{
var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers);
var name = arg.Name;
if (hasName && !string.IsNullOrEmpty(name))
return string.Format("{0} {1}", type, name);
return type;
}
public string VisitDelegate(FunctionType function)
{
throw new System.NotImplementedException();
}
public string GetDeclName(Declaration declaration)
{
switch (PrintScopeKind)
{
case CppTypePrintScopeKind.Local:
return PrintLogicalNames ? declaration.LogicalOriginalName
: declaration.OriginalName;
case CppTypePrintScopeKind.Qualified:
return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName;
case CppTypePrintScopeKind.GlobalQualified:
return "::" + (PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName);
}
throw new NotSupportedException();
}
public string VisitDeclaration(Declaration decl)
{
return GetDeclName(decl);
}
public string VisitClassDecl(Class @class)
{
return VisitDeclaration(@class);
}
public string VisitFieldDecl(Field field)
{
return VisitDeclaration(field);
}
public string VisitFunctionDecl(Function function)
{
return VisitDeclaration(function);
}
public string VisitMethodDecl(Method method)
{
return VisitDeclaration(method);
}
public string VisitParameterDecl(Parameter parameter)
{
return VisitParameter(parameter, hasName: false);
}
public string VisitTypedefDecl(TypedefDecl typedef)
{
return VisitDeclaration(typedef);
}
public string VisitEnumDecl(Enumeration @enum)
{
return VisitDeclaration(@enum);
}
public string VisitVariableDecl(Variable variable)
{
return VisitDeclaration(variable);
}
public string VisitClassTemplateDecl(ClassTemplate template)
{
return VisitDeclaration(template);
}
public string VisitFunctionTemplateDecl(FunctionTemplate template)
{
return VisitDeclaration(template);
}
public string VisitMacroDefinition(MacroDefinition macro)
{
throw new NotImplementedException();
}
public string VisitNamespace(Namespace @namespace)
{
return VisitDeclaration(@namespace);
}
public string VisitEvent(Event @event)
{
return string.Empty;
}
public string VisitProperty(Property property)
{
return VisitDeclaration(property);
}
public string ToString(Type type)
{
return type.Visit(this);
}
}
}

48
src/Generator/Types/Types.cs

@ -112,19 +112,19 @@ namespace CppSharp @@ -112,19 +112,19 @@ namespace CppSharp
}
return base.VisitMemberPointerType(member, quals);
}
public override bool VisitParameterDecl(Parameter parameter)
{
if (parameter.Type.IsPrimitiveType(PrimitiveType.Null))
{
Ignore();
return false;
}
return base.VisitParameterDecl(parameter);
}
}
public override bool VisitParameterDecl(Parameter parameter)
{
if (parameter.Type.IsPrimitiveType(PrimitiveType.Null))
{
Ignore();
return false;
}
return base.VisitParameterDecl(parameter);
}
public override bool VisitTemplateSpecializationType(
TemplateSpecializationType template, TypeQualifiers quals)
{
@ -138,17 +138,17 @@ namespace CppSharp @@ -138,17 +138,17 @@ namespace CppSharp
Ignore();
return base.VisitTemplateSpecializationType(template, quals);
}
public override bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
{
// We don't know how to marshal non-static member functions
if (function.CallingConvention == CallingConvention.ThisCall)
{
Ignore();
return false;
}
return base.VisitFunctionType(function, quals);
}
public override bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
{
// We don't know how to marshal non-static member functions
if (function.CallingConvention == CallingConvention.ThisCall)
{
Ignore();
return false;
}
return base.VisitFunctionType(function, quals);
}
}

30
src/Generator/Utils/Utils.cs

@ -235,19 +235,19 @@ namespace CppSharp @@ -235,19 +235,19 @@ namespace CppSharp
return assembly.GetTypes().Where(baseType.IsAssignableFrom);
}
}
public static class PathHelpers
{
public static string GetRelativePath(string fromPath, string toPath)
{
var path1 = fromPath.Trim('\\', '/');
var path2 = toPath.Trim('\\', '/');
var uri1 = new System.Uri("c:\\" + path1 + "\\");
var uri2 = new System.Uri("c:\\" + path2 + "\\");
return uri1.MakeRelativeUri(uri2).ToString();
}
}
public static class PathHelpers
{
public static string GetRelativePath(string fromPath, string toPath)
{
var path1 = fromPath.Trim('\\', '/');
var path2 = toPath.Trim('\\', '/');
var uri1 = new System.Uri("c:\\" + path1 + "\\");
var uri2 = new System.Uri("c:\\" + path2 + "\\");
return uri1.MakeRelativeUri(uri2).ToString();
}
}
}

104
tests/Basic/Basic.Tests.cs

@ -22,16 +22,16 @@ public class BasicTests : GeneratorTestFixture @@ -22,16 +22,16 @@ public class BasicTests : GeneratorTestFixture
Assert.That(hello.AddFoo(foo), Is.EqualTo(11));
Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11));
Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11));
Assert.That(hello.AddFooRef(foo), Is.EqualTo(11));
unsafe
{
var pointer = foo.SomePointer;
var pointerPointer = foo.SomePointerPointer;
for (int i = 0; i < 4; i++)
{
Assert.AreEqual(i, pointer[i]);
Assert.AreEqual(i, (*pointerPointer)[i]);
}
Assert.That(hello.AddFooRef(foo), Is.EqualTo(11));
unsafe
{
var pointer = foo.SomePointer;
var pointerPointer = foo.SomePointerPointer;
for (int i = 0; i < 4; i++)
{
Assert.AreEqual(i, pointer[i]);
Assert.AreEqual(i, (*pointerPointer)[i]);
}
}
var bar = new Bar { A = 4, B = 7 };
@ -178,9 +178,9 @@ public class BasicTests : GeneratorTestFixture @@ -178,9 +178,9 @@ public class BasicTests : GeneratorTestFixture
Assert.AreEqual(8, doubleSum);
var stdcall = delegates.StdCall(i => i);
Assert.AreEqual(1, stdcall);
var cdecl = delegates.CDecl(i => i);
Assert.AreEqual(1, stdcall);
var cdecl = delegates.CDecl(i => i);
Assert.AreEqual(1, cdecl);
}
@ -204,7 +204,7 @@ public class BasicTests : GeneratorTestFixture @@ -204,7 +204,7 @@ public class BasicTests : GeneratorTestFixture
[Test]
public void TestStaticClasses()
{
Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
Assert.That(TestStaticClassDerived.Foo(), Is.EqualTo(0));
}
@ -239,22 +239,22 @@ public class BasicTests : GeneratorTestFixture @@ -239,22 +239,22 @@ public class BasicTests : GeneratorTestFixture
[Test]
public unsafe void TestIndexers()
{
var indexedProperties = new TestIndexedProperties();
Assert.AreEqual(1, indexedProperties[0]);
Assert.AreEqual(1, indexedProperties["foo"]);
indexedProperties[0] = 2;
var indexedProperties = new TestIndexedProperties();
Assert.AreEqual(1, indexedProperties[0]);
Assert.AreEqual(1, indexedProperties["foo"]);
indexedProperties[0] = 2;
Assert.AreEqual(2, indexedProperties[0]);
indexedProperties[0f] = 3;
Assert.AreEqual(3, indexedProperties[0f]);
var properties = indexedProperties[(byte)0];
Assert.AreEqual(0, properties.Field);
var newProperties = new TestProperties();
indexedProperties[0f] = 3;
Assert.AreEqual(3, indexedProperties[0f]);
var properties = indexedProperties[(byte)0];
Assert.AreEqual(0, properties.Field);
var newProperties = new TestProperties();
newProperties.Field = 4;
indexedProperties[(byte)0] = newProperties;
Assert.AreEqual(4, indexedProperties[(byte)0].Field);
newProperties = indexedProperties[(short)0];
Assert.AreEqual(4, newProperties.Field);
newProperties.Field = 5;
indexedProperties[(byte)0] = newProperties;
Assert.AreEqual(4, indexedProperties[(byte)0].Field);
newProperties = indexedProperties[(short)0];
Assert.AreEqual(4, newProperties.Field);
newProperties.Field = 5;
Assert.AreEqual(5, indexedProperties[(byte)0].Field);
}
@ -304,30 +304,30 @@ public class BasicTests : GeneratorTestFixture @@ -304,30 +304,30 @@ public class BasicTests : GeneratorTestFixture
var @class = new TestGetterSetterToProperties();
Assert.That(@class.Width, Is.EqualTo(640));
Assert.That(@class.Height, Is.EqualTo(480));
}
[Test]
public unsafe void TestSingleArgumentCtorToCastOperator()
{
var classA = new ClassA(10);
ClassB classB = classA;
Assert.AreEqual(classA.Value, classB.Value);
ClassC classC = (ClassC)classB;
Assert.AreEqual(classB.Value, classC.Value);
}
[Test]
public unsafe void TestDecltype()
{
var ret = basic.TestDecltype();
Assert.AreEqual(0, ret);
}
[Test]
public unsafe void TestNullPtrType()
{
var ret = basic.TestNullPtrTypeRet();
Assert.AreEqual(IntPtr.Zero, new IntPtr(ret));
}
[Test]
public unsafe void TestSingleArgumentCtorToCastOperator()
{
var classA = new ClassA(10);
ClassB classB = classA;
Assert.AreEqual(classA.Value, classB.Value);
ClassC classC = (ClassC)classB;
Assert.AreEqual(classB.Value, classC.Value);
}
[Test]
public unsafe void TestDecltype()
{
var ret = basic.TestDecltype();
Assert.AreEqual(0, ret);
}
[Test]
public unsafe void TestNullPtrType()
{
var ret = basic.TestNullPtrTypeRet();
Assert.AreEqual(IntPtr.Zero, new IntPtr(ret));
}
}

2
tests/Basic/Basic.cs

@ -20,7 +20,7 @@ namespace CppSharp.Tests @@ -20,7 +20,7 @@ namespace CppSharp.Tests
driver.Options.GenerateVirtualTables = true;
driver.Options.GenerateCopyConstructors = true;
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateProperties = true;
driver.Options.GenerateProperties = true;
driver.Options.GenerateConversionOperators = true;
}

214
tests/Basic/Basic.h

@ -11,12 +11,12 @@ public: @@ -11,12 +11,12 @@ public:
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;
// Not properly handled yet - ignore
float nested_array[2][2];
// Primitive pointer types
const int* SomePointer;
const int** SomePointerPointer;
};
struct DLL_API Bar
@ -234,12 +234,12 @@ DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1, @@ -234,12 +234,12 @@ DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1,
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;
}
// 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);
@ -325,14 +325,14 @@ public: @@ -325,14 +325,14 @@ public:
float B;
};
TestCopyConstructorRef::TestCopyConstructorRef()
{
}
TestCopyConstructorRef::TestCopyConstructorRef(const TestCopyConstructorRef& other)
{
A = other.A;
B = other.B;
TestCopyConstructorRef::TestCopyConstructorRef()
{
}
TestCopyConstructorRef::TestCopyConstructorRef(const TestCopyConstructorRef& other)
{
A = other.A;
B = other.B;
}
template <class T>
@ -340,28 +340,28 @@ struct EmptyNamedNestedEnum @@ -340,28 +340,28 @@ 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;
};
}
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
@ -380,72 +380,72 @@ ClassWithOverloadedOperators::operator int() { return 2; } @@ -380,72 +380,72 @@ ClassWithOverloadedOperators::operator int() { return 2; }
ClassWithOverloadedOperators::operator short() { return 3; }
// Tests global static function generation
DLL_API int Function()
{
return 5;
}
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);
};
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; }
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();
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);
};
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; }
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; }

6
tests/CSharpTemp/CSharpTemp.cs

@ -62,9 +62,9 @@ namespace CppSharp.Tests @@ -62,9 +62,9 @@ namespace CppSharp.Tests
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = true;
driver.Options.GenerateCopyConstructors = true;
// To ensure that calls to constructors in conversion operators
// are not ambiguous with multiple inheritance pass enabled.
driver.Options.GenerateCopyConstructors = true;
// To ensure that calls to constructors in conversion operators
// are not ambiguous with multiple inheritance pass enabled.
driver.Options.GenerateConversionOperators = true;
driver.TranslationUnitPasses.AddPass(new TestAttributesPass());
}

Loading…
Cancel
Save