Browse Source

Added all system fields to the internal layouts used in the C# generator.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/685/head
Dimitar Dobrev 9 years ago
parent
commit
d419cb7156
  1. 2
      src/AST/ClassExtensions.cs
  2. 2
      src/AST/TypeExtensions.cs
  3. 80
      src/CppParser/Bindings/CLI/AST.h
  4. 2947
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  5. 10977
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs
  6. 2941
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  7. 7373
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs
  8. 2949
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  9. 13127
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs
  10. 2955
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  11. 3871
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs
  12. 2903
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  13. 3989
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs
  14. 2957
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  15. 7420
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs
  16. 3
      src/CppParser/Bindings/ParserGen.cs
  17. 41
      src/CppParser/Parser.cpp
  18. 3
      src/CppParser/Parser.h
  19. 13
      src/Generator/Generators/CSharp/CSharpSources.cs
  20. 5
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  21. 2
      src/Generator/Passes/CheckIgnoredDecls.cs
  22. 2
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs
  23. 1
      src/Generator/Passes/GenerateTemplatesCodePass.cs
  24. 65
      src/Generator/Passes/IgnoreSystemDeclarationsPass.cs
  25. 1
      src/Generator/Passes/MultipleInheritancePass.cs
  26. 2
      src/Generator/Utils/Utils.cs

2
src/AST/ClassExtensions.cs

@ -201,7 +201,7 @@ namespace CppSharp.AST @@ -201,7 +201,7 @@ namespace CppSharp.AST
public static IEnumerable<TranslationUnit> GetGenerated(this IEnumerable<TranslationUnit> units)
{
return units.Where(u => u.IsGenerated && u.HasDeclarations && u.IsValid);
return units.Where(u => u.IsGenerated && (u.HasDeclarations || u.IsSystemHeader) && u.IsValid);
}
public static bool IsSupportedStdSpecialization(this ClassTemplateSpecialization specialization)

2
src/AST/TypeExtensions.cs

@ -148,7 +148,7 @@ @@ -148,7 +148,7 @@
if (templateTemplateParameter != null)
return (decl = templateTemplateParameter.TemplatedDecl as T) != null;
}
tagType = (TagType) type.Desugared.Type;
tagType = (TagType) (type.Desugared.Type.GetFinalPointee() ?? type.Desugared.Type);
}
else
{

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

@ -182,6 +182,16 @@ namespace CppSharp @@ -182,6 +182,16 @@ namespace CppSharp
Public = 2
};
public enum struct MacroLocation
{
Unknown = 0,
ClassHead = 1,
ClassBody = 2,
FunctionHead = 3,
FunctionParameters = 4,
FunctionBody = 5
};
public enum struct RawCommentKind
{
Invalid = 0,
@ -213,27 +223,6 @@ namespace CppSharp @@ -213,27 +223,6 @@ namespace CppSharp
VerbatimBlockLineComment = 14
};
public enum struct CppAbi
{
Itanium = 0,
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
};
public enum struct VTableComponentKind
{
VCallOffset = 0,
VBaseOffset = 1,
OffsetToTop = 2,
RTTI = 3,
FunctionPointer = 4,
CompleteDtorPointer = 5,
DeletingDtorPointer = 6,
UnusedFunctionPointer = 7
};
public enum struct CXXOperatorKind
{
None = 0,
@ -293,15 +282,6 @@ namespace CppSharp @@ -293,15 +282,6 @@ namespace CppSharp
Unknown = 5
};
public enum struct TemplateSpecializationKind
{
Undeclared = 0,
ImplicitInstantiation = 1,
ExplicitSpecialization = 2,
ExplicitInstantiationDeclaration = 3,
ExplicitInstantiationDefinition = 4
};
public enum struct StatementClass
{
Any = 0,
@ -314,6 +294,15 @@ namespace CppSharp @@ -314,6 +294,15 @@ namespace CppSharp
ExplicitCastExpr = 7
};
public enum struct TemplateSpecializationKind
{
Undeclared = 0,
ImplicitInstantiation = 1,
ExplicitSpecialization = 2,
ExplicitInstantiationDeclaration = 3,
ExplicitInstantiationDefinition = 4
};
public enum struct CXXMethodKind
{
Normal = 0,
@ -324,6 +313,27 @@ namespace CppSharp @@ -324,6 +313,27 @@ namespace CppSharp
UsingDirective = 5
};
public enum struct CppAbi
{
Itanium = 0,
Microsoft = 1,
ARM = 2,
iOS = 3,
iOS64 = 4
};
public enum struct VTableComponentKind
{
VCallOffset = 0,
VBaseOffset = 1,
OffsetToTop = 2,
RTTI = 3,
FunctionPointer = 4,
CompleteDtorPointer = 5,
DeletingDtorPointer = 6,
UnusedFunctionPointer = 7
};
public enum struct PrimitiveType
{
Null = 0,
@ -352,16 +362,6 @@ namespace CppSharp @@ -352,16 +362,6 @@ namespace CppSharp
IntPtr = 23
};
public enum struct MacroLocation
{
Unknown = 0,
ClassHead = 1,
ClassBody = 2,
FunctionHead = 3,
FunctionParameters = 4,
FunctionBody = 5
};
public enum struct ArchType
{
UnknownArch = 0,

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

File diff suppressed because it is too large Load Diff

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

File diff suppressed because it is too large Load Diff

2941
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

7373
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs

File diff suppressed because it is too large Load Diff

2949
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

13127
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs

File diff suppressed because it is too large Load Diff

2955
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

3871
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs

File diff suppressed because it is too large Load Diff

2903
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

3989
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs

File diff suppressed because it is too large Load Diff

2957
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

7420
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs

File diff suppressed because it is too large Load Diff

3
src/CppParser/Bindings/ParserGen.cs

@ -87,6 +87,7 @@ namespace CppSharp @@ -87,6 +87,7 @@ namespace CppSharp
options.OutputNamespace = string.Empty;
options.CheckSymbols = false;
options.Verbose = true;
options.UnityBuild = true;
}
private void SetupLinuxOptions(DriverOptions options)
@ -108,7 +109,7 @@ namespace CppSharp @@ -108,7 +109,7 @@ namespace CppSharp
string gccVersion = gccVersionPath.Substring(
gccVersionPath.LastIndexOf(Path.DirectorySeparatorChar) + 1);
string[] systemIncludeDirs = new[] {
string[] systemIncludeDirs = {
Path.Combine("usr", "include", "c++", gccVersion),
Path.Combine("usr", "include", "x86_64-linux-gnu", "c++", gccVersion),
Path.Combine("usr", "include", "c++", gccVersion, "backward"),

41
src/CppParser/Parser.cpp

@ -64,25 +64,6 @@ using namespace CppSharp::CppParser; @@ -64,25 +64,6 @@ using namespace CppSharp::CppParser;
// We use this as a placeholder for pointer values that should be ignored.
void* IgnorePtr = (void*) 0x1;
bool IsNamespaceStd(const clang::DeclContext* Namespace)
{
if (!Namespace)
return false;
if (Namespace->isInlineNamespace())
return IsNamespaceStd(llvm::cast<clang::Decl>(Namespace)->getDeclContext());
if (auto NamedDecl = llvm::dyn_cast<clang::NamedDecl>(Namespace))
return NamedDecl->getName() == "std";
return false;
}
bool Parser::IsStdTypeSupported(const clang::RecordDecl* Record)
{
auto TU = GetTranslationUnit(Record);
return TU->IsSystemHeader &&
IsNamespaceStd(Record->getDeclContext()) &&
(Record->getName() == "basic_string" || Record->getName() == "allocator");
}
//-----------------------------------//
Parser::Parser(ParserOptions* Opts) : Lib(Opts->ASTContext), Opts(Opts), Index(0)
@ -113,7 +94,7 @@ LayoutField Parser::WalkVTablePointer(Class* Class, @@ -113,7 +94,7 @@ LayoutField Parser::WalkVTablePointer(Class* Class,
}
void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
clang::CharUnits Offset, bool IncludeVirtualBases, bool IsSupportedStdType)
clang::CharUnits Offset, bool IncludeVirtualBases)
{
using namespace clang;
@ -164,7 +145,7 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD, @@ -164,7 +145,7 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
for (const CXXRecordDecl *Base : Bases) {
CharUnits BaseOffset = Offset + Layout.getBaseClassOffset(Base);
ReadClassLayout(Class, Base, BaseOffset,
/*IncludeVirtualBases=*/false, IsSupportedStdType);
/*IncludeVirtualBases=*/false);
}
// vbptr (for Microsoft C++ ABI)
@ -184,20 +165,6 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD, @@ -184,20 +165,6 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
CharUnits FieldOffset =
Offset + C->getASTContext().toCharUnitsFromBits(LocalFieldOffsetInBits);
// Recursively dump fields of record type.
if (auto RT = Field->getType()->getAs<RecordType>())
{
if (IsSupportedStdType)
{
ReadClassLayout(Class, RT->getDecl(), FieldOffset, IncludeVirtualBases, IsSupportedStdType);
continue;
}
auto TU = GetTranslationUnit(RT->getDecl());
if (TU->IsSystemHeader && !IsStdTypeSupported(RT->getDecl()))
continue;
}
auto F = WalkFieldCXX(Field, Parent);
LayoutField LayoutField;
LayoutField.Offset = FieldOffset.getQuantity();
@ -225,7 +192,7 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD, @@ -225,7 +192,7 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
}
ReadClassLayout(Class, VBase, VBaseOffset,
/*IncludeVirtualBases=*/false, IsSupportedStdType);
/*IncludeVirtualBases=*/false);
}
}
}
@ -921,7 +888,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC) @@ -921,7 +888,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
RC->Layout->Alignment = (int)Layout.getAlignment().getQuantity();
RC->Layout->Size = (int)Layout.getSize().getQuantity();
RC->Layout->DataSize = (int)Layout.getDataSize().getQuantity();
ReadClassLayout(RC, Record, CharUnits(), true, IsStdTypeSupported(Record));
ReadClassLayout(RC, Record, CharUnits(), true);
}
for(auto it = Record->decls_begin(); it != Record->decls_end(); ++it)

3
src/CppParser/Parser.h

@ -59,7 +59,6 @@ public: @@ -59,7 +59,6 @@ public:
ParserTargetInfo* GetTargetInfo();
private:
bool IsStdTypeSupported(const clang::RecordDecl* Decl);
// AST traversers
void WalkAST();
Declaration* WalkDeclaration(const clang::Decl* D, bool CanBeDefinition = false);
@ -105,7 +104,7 @@ private: @@ -105,7 +104,7 @@ private:
std::vector<TemplateArgument> WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, const clang::ASTTemplateArgumentListInfo* TSTL);
void WalkVTable(const clang::CXXRecordDecl* RD, Class* C);
QualifiedType GetQualifiedType(clang::QualType qual, clang::TypeLoc* TL = 0);
void ReadClassLayout(Class* Class, const clang::RecordDecl* RD, clang::CharUnits Offset, bool IncludeVirtualBases, bool IsStdString = false);
void ReadClassLayout(Class* Class, const clang::RecordDecl* RD, clang::CharUnits Offset, bool IncludeVirtualBases);
LayoutField WalkVTablePointer(Class* Class, const clang::CharUnits& Offset, const std::string& prefix);
VTableLayout WalkVTableLayout(const clang::VTableLayout& VTLayout);
VTableComponent WalkVTableComponent(const clang::VTableComponent& Component);

13
src/Generator/Generators/CSharp/CSharpSources.cs

@ -249,7 +249,7 @@ namespace CppSharp.Generators.CSharp @@ -249,7 +249,7 @@ namespace CppSharp.Generators.CSharp
// Generate all the enum declarations.
foreach (var @enum in context.Enums)
{
if (!@enum.IsGenerated || @enum.IsIncomplete)
if (@enum.IsIncomplete)
continue;
GenerateEnum(@enum);
@ -281,8 +281,7 @@ namespace CppSharp.Generators.CSharp @@ -281,8 +281,7 @@ namespace CppSharp.Generators.CSharp
if (specialization != null)
GenerateClass(specialization);
}
else if ((!@class.Ignore || !@class.TranslationUnit.IsSystemHeader) &&
!(@class.Namespace is Class))
else if (!(@class.Namespace is Class))
GenerateClassTemplateSpecializationInternal(@class);
}
@ -609,7 +608,7 @@ namespace CppSharp.Generators.CSharp @@ -609,7 +608,7 @@ namespace CppSharp.Generators.CSharp
foreach (var field in @class.Layout.Fields)
GenerateClassInternalsField(field);
if (@class.IsGenerated && (!(@class is ClassTemplateSpecialization) || @class.IsSupportedStdType()))
if (@class.IsGenerated)
{
var functions = GatherClassInternalFunctions(@class);
@ -799,8 +798,6 @@ namespace CppSharp.Generators.CSharp @@ -799,8 +798,6 @@ namespace CppSharp.Generators.CSharp
{
Declaration decl;
field.QualifiedType.Type.TryGetDeclaration(out decl);
if (decl != null && decl.TranslationUnit.IsSystemHeader && !decl.IsSupportedStdType())
return;
var arrayType = field.QualifiedType.Type.Desugar() as ArrayType;
var coreType = field.QualifiedType.Type.Desugar();
@ -3013,8 +3010,6 @@ namespace CppSharp.Generators.CSharp @@ -3013,8 +3010,6 @@ namespace CppSharp.Generators.CSharp
public void GenerateEnum(Enumeration @enum)
{
if (!@enum.IsGenerated) return;
PushBlock(CSharpBlockKind.Enum);
GenerateDeclarationCommon(@enum);
@ -3025,7 +3020,7 @@ namespace CppSharp.Generators.CSharp @@ -3025,7 +3020,7 @@ namespace CppSharp.Generators.CSharp
// internal P/Invoke declarations must see protected enums
if (@enum.Access == AccessSpecifier.Protected)
Write("internal ");
Write("enum {0}", @enum.Name);
Write("enum {0}", Helpers.SafeIdentifier(@enum.Name));
var typeName = TypePrinter.VisitPrimitiveType(@enum.BuiltinType.Type,
new TypeQualifiers());

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

@ -397,6 +397,8 @@ namespace CppSharp.Generators.CSharp @@ -397,6 +397,8 @@ namespace CppSharp.Generators.CSharp
{
if (ContextKind != CSharpTypePrinterContextKind.Native)
return GetNestedQualifiedName(decl);
if (template.Desugared.Type.IsAddress())
return template.Desugared.Type.ToString();
var specialization = template.GetClassTemplateSpecialization();
return specialization.Visit(this);
}
@ -661,7 +663,8 @@ namespace CppSharp.Generators.CSharp @@ -661,7 +663,8 @@ namespace CppSharp.Generators.CSharp
if (specialization != null)
{
ctx = specialization.TemplatedDecl.TemplatedClass.Namespace;
if (specialization.OriginalNamespace is Class)
if (specialization.OriginalNamespace is Class &&
!(specialization.OriginalNamespace is ClassTemplateSpecialization))
{
names.Add(string.Format("{0}_{1}", decl.OriginalNamespace.Name, decl.Name));
ctx = ctx.Namespace ?? ctx;

2
src/Generator/Passes/CheckIgnoredDecls.cs

@ -38,7 +38,7 @@ namespace CppSharp.Passes @@ -38,7 +38,7 @@ namespace CppSharp.Passes
if (!base.VisitClassTemplateDecl(template))
return false;
if (!Driver.Options.IsCLIGenerator && template.IsSupportedStdType())
if (!Driver.Options.IsCLIGenerator && template.TranslationUnit.IsSystemHeader)
return false;
// templates are not supported yet

2
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -138,7 +138,7 @@ namespace CppSharp.Passes @@ -138,7 +138,7 @@ namespace CppSharp.Passes
}
var prefixBuilder = new StringBuilder(prefix);
prefixBuilder.Trim();
prefixBuilder.TrimUnderscores();
while (@enum.Namespace.Enums.Any(e => e != @enum &&
e.Name == prefixBuilder.ToString()))
prefixBuilder.Append('_');

1
src/Generator/Passes/GenerateTemplatesCodePass.cs

@ -3,7 +3,6 @@ using System.IO; @@ -3,7 +3,6 @@ using System.IO;
using System.Linq;
using System.Text;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
namespace CppSharp.Passes

65
src/Generator/Passes/IgnoreSystemDeclarationsPass.cs

@ -17,8 +17,6 @@ namespace CppSharp.Passes @@ -17,8 +17,6 @@ namespace CppSharp.Passes
Options.VisitNamespaceEnums = false;
Options.VisitNamespaceEvents = false;
Options.VisitNamespaceTemplates = false;
Options.VisitNamespaceTypedefs = false;
Options.VisitNamespaceVariables = false;
Options.VisitTemplateArguments = false;
}
@ -27,9 +25,6 @@ namespace CppSharp.Passes @@ -27,9 +25,6 @@ namespace CppSharp.Passes
if (!unit.IsValid)
return false;
if (!Driver.Options.IsCLIGenerator && unit.IsSystemHeader)
unit.ExplicitlyIgnore();
if (ClearVisitedDeclarations)
Visited.Clear();
@ -38,18 +33,25 @@ namespace CppSharp.Passes @@ -38,18 +33,25 @@ namespace CppSharp.Passes
return true;
}
public override bool VisitDeclaration(Declaration decl)
{
if (!Driver.Options.IsCLIGenerator &&
decl.Namespace != null && decl.TranslationUnit.IsSystemHeader)
decl.ExplicitlyIgnore();
return base.VisitDeclaration(decl);
}
public override bool VisitClassDecl(Class @class)
{
if (!base.VisitClassDecl(@class) || !@class.IsDependent ||
Driver.Options.IsCLIGenerator || !@class.IsSupportedStdType())
if (!base.VisitClassDecl(@class) || Driver.Options.IsCLIGenerator)
return false;
if (!@class.TranslationUnit.IsSystemHeader)
return false;
if (!@class.IsSupportedStdType())
{
@class.ExplicitlyIgnore();
if (@class.IsDependent)
foreach (var specialization in @class.Specializations)
specialization.ExplicitlyIgnore();
return false;
}
if (!@class.IsDependent)
return false;
// we only need a few members for marshalling so strip the rest
@ -84,6 +86,39 @@ namespace CppSharp.Passes @@ -84,6 +86,39 @@ namespace CppSharp.Passes
return true;
}
public override bool VisitFunctionDecl(Function function)
{
if (!base.VisitFunctionDecl(function))
return false;
if (function.TranslationUnit.IsSystemHeader)
function.ExplicitlyIgnore();
return true;
}
public override bool VisitTypedefDecl(TypedefDecl typedef)
{
if (!base.VisitTypedefDecl(typedef))
return false;
if (typedef.TranslationUnit.IsSystemHeader)
typedef.ExplicitlyIgnore();
return true;
}
public override bool VisitVariableDecl(Variable variable)
{
if (!base.VisitDeclaration(variable))
return false;
if (variable.TranslationUnit.IsSystemHeader)
variable.ExplicitlyIgnore();
return true;
}
private static void MarkForGeneration(ClassTemplateSpecialization specialization)
{
specialization.GenerationKind = GenerationKind.Generate;

1
src/Generator/Passes/MultipleInheritancePass.cs

@ -81,6 +81,7 @@ namespace CppSharp.Passes @@ -81,6 +81,7 @@ namespace CppSharp.Passes
@interface.Bases.AddRange(
from b in @base.Bases
where b.Class != null
let i = GetInterface(b.Class)
select new BaseClassSpecifier(b) { Type = new TagType(i) });

2
src/Generator/Utils/Utils.cs

@ -100,7 +100,7 @@ namespace CppSharp @@ -100,7 +100,7 @@ namespace CppSharp
return source.Substring(start, end - start);
}
public static void Trim(this StringBuilder stringBuilder)
public static void TrimUnderscores(this StringBuilder stringBuilder)
{
while (stringBuilder.Length > 0 && stringBuilder[0] == '_')
stringBuilder.Remove(0, 1);

Loading…
Cancel
Save