Browse Source

Synced new and old parser.

* Implemented missing parts in regards to class templates.
* Fixed couple of class member initialization issues in C++ AST classes.
* Make code more look alike so it's easier to compare them.
* All tests pass now with old and new parser. Especially the nasty STL one with the ostream typedef.
pull/245/head
Elias Holzer 11 years ago
parent
commit
d3fb9289cf
  1. 4
      src/AST/ASTVisitor.cs
  2. 2
      src/AST/Template.cs
  3. 18
      src/AST/Type.cs
  4. 2
      src/AST/TypeExtensions.cs
  5. 89
      src/Core/Parser/ASTConverter.cs
  6. 59
      src/CppParser/AST.cpp
  7. 6
      src/CppParser/AST.h
  8. 12
      src/CppParser/Bindings/CLI/AST.cpp
  9. 22
      src/CppParser/Bindings/CLI/AST.h
  10. 1
      src/CppParser/Bindings/CLI/CppParser.h
  11. 1265
      src/CppParser/Bindings/CSharp/AST.cs
  12. 60
      src/CppParser/Bindings/CSharp/CppParser.cs
  13. 79
      src/CppParser/Bindings/CSharp/Target.cs
  14. 43
      src/CppParser/Parser.cpp
  15. 37
      src/Parser/Parser.cpp

4
src/AST/ASTVisitor.cs

@ -84,7 +84,7 @@ namespace CppSharp.AST @@ -84,7 +84,7 @@ namespace CppSharp.AST
if (array.SizeType == ArrayType.ArraySize.Dependent)
return false;
return array.Type.Visit(this, quals);
return array.QualifiedType.Visit(this);
}
public virtual bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
@ -119,7 +119,7 @@ namespace CppSharp.AST @@ -119,7 +119,7 @@ namespace CppSharp.AST
if (!VisitType(member, quals))
return false;
return member.Pointee.Visit(this, quals);
return member.QualifiedPointee.Visit(this);
}
public virtual bool VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)

2
src/AST/Template.cs

@ -168,7 +168,7 @@ namespace CppSharp.AST @@ -168,7 +168,7 @@ namespace CppSharp.AST
/// </summary>
public class ClassTemplateSpecialization : Class
{
public ClassTemplate TemplatedDecl;
public ClassTemplate TemplatedDecl;
public List<TemplateArgument> Arguments;

18
src/AST/Type.cs

@ -136,7 +136,7 @@ namespace CppSharp.AST @@ -136,7 +136,7 @@ namespace CppSharp.AST
}
// Type of the array elements.
public Type Type;
public QualifiedType QualifiedType;
// Size type of array.
public ArraySize SizeType;
@ -144,6 +144,11 @@ namespace CppSharp.AST @@ -144,6 +144,11 @@ namespace CppSharp.AST
// In case of a constant size array.
public long Size;
public Type Type
{
get { return QualifiedType.Type; }
}
public override T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals)
{
return visitor.VisitArrayType(this, quals);
@ -153,7 +158,7 @@ namespace CppSharp.AST @@ -153,7 +158,7 @@ namespace CppSharp.AST
{
var type = obj as ArrayType;
if (type == null) return false;
var equals = Type.Equals(type.Type) && SizeType.Equals(type.SizeType);
var equals = QualifiedType.Equals(type.QualifiedType) && SizeType.Equals(type.SizeType);
if (SizeType == ArraySize.Constant)
equals &= Size.Equals(type.Size);
@ -266,7 +271,12 @@ namespace CppSharp.AST @@ -266,7 +271,12 @@ namespace CppSharp.AST
/// </summary>
public class MemberPointerType : Type
{
public Type Pointee;
public QualifiedType QualifiedPointee;
public Type Pointee
{
get { return QualifiedPointee.Type; }
}
public override T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals)
{
@ -278,7 +288,7 @@ namespace CppSharp.AST @@ -278,7 +288,7 @@ namespace CppSharp.AST
var pointer = obj as MemberPointerType;
if (pointer == null) return false;
return Pointee.Equals(pointer.Pointee);
return QualifiedPointee.Equals(pointer.QualifiedPointee);
}
public override int GetHashCode()

2
src/AST/TypeExtensions.cs

@ -197,7 +197,7 @@ @@ -197,7 +197,7 @@
return ptr.Pointee;
var memberPtr = t as MemberPointerType;
if (memberPtr != null)
return memberPtr.Pointee;
return memberPtr.QualifiedPointee.Type;
return null;
}

89
src/Core/Parser/ASTConverter.cs

@ -354,7 +354,7 @@ namespace CppSharp @@ -354,7 +354,7 @@ namespace CppSharp
{
Size = type.Size,
SizeType = VisitArraySizeType(type.SizeType),
Type = VisitQualified(type.QualifiedType).Type
QualifiedType = VisitQualified(type.QualifiedType)
};
VisitType(type, _type);
return _type;
@ -408,7 +408,7 @@ namespace CppSharp @@ -408,7 +408,7 @@ namespace CppSharp
{
var _type = new CppSharp.AST.MemberPointerType();
VisitType(type, _type);
_type.Pointee = VisitQualified(type.Pointee).Type;
_type.QualifiedPointee = VisitQualified(type.Pointee);
return _type;
}
@ -502,8 +502,8 @@ namespace CppSharp @@ -502,8 +502,8 @@ namespace CppSharp
public override AST.Type VisitTemplateParameterSubstitution(TemplateParameterSubstitutionType type)
{
throw new NotImplementedException();
var _type = new CppSharp.AST.TemplateParameterSubstitutionType();
_type.Replacement = VisitQualified(type.Replacement);
VisitType(type, _type);
return _type;
}
@ -1262,7 +1262,12 @@ namespace CppSharp @@ -1262,7 +1262,12 @@ namespace CppSharp
{
var _decl = new AST.ClassTemplate();
VisitTemplate(decl, _decl);
for (uint i = 0; i < decl.SpecializationsCount; ++i)
{
var spec = decl.getSpecializations(i);
var _spec = (AST.ClassTemplateSpecialization)Visit(spec);
_decl.Specializations.Add(_spec);
}
return _decl;
}
@ -1270,21 +1275,83 @@ namespace CppSharp @@ -1270,21 +1275,83 @@ namespace CppSharp
ClassTemplateSpecialization decl)
{
var _decl = new AST.ClassTemplateSpecialization();
VisitClassTemplateSpecialization(decl, _decl);
return _decl;
}
private void VisitClassTemplateSpecialization(ClassTemplateSpecialization decl, AST.ClassTemplateSpecialization _decl)
{
VisitClass(decl, _decl);
_decl.SpecializationKind = VisitSpecializationKind(decl.SpecializationKind);
_decl.TemplatedDecl = (AST.ClassTemplate)Visit(decl.TemplatedDecl);
for (uint i = 0; i < decl.ArgumentsCount; ++i)
{
var arg = decl.getArguments(i);
var _arg = VisitTemplateArgument(arg);
_decl.Arguments.Add(_arg);
}
}
//for (uint i = 0; i < decl.ArgumentsCount; ++i)
//{
// var _arg = decl.getArguments(i);
// _decl.Arguments.Add(_arg);
//}
private AST.TemplateArgument VisitTemplateArgument(TemplateArgument arg)
{
var _arg = new AST.TemplateArgument();
_arg.Kind = VisitTemplateArgumentKind(arg.Kind);
_arg.Type = typeConverter.VisitQualified(arg.Type);
_arg.Declaration = Visit(arg.Declaration);
_arg.Integral = arg.Integral;
return _arg;
}
return _decl;
private AST.TemplateArgument.ArgumentKind VisitTemplateArgumentKind(TemplateArgument.ArgumentKind argumentKind)
{
switch (argumentKind)
{
case TemplateArgument.ArgumentKind.Declaration:
return AST.TemplateArgument.ArgumentKind.Declaration;
case TemplateArgument.ArgumentKind.Expression:
return AST.TemplateArgument.ArgumentKind.Expression;
case TemplateArgument.ArgumentKind.Integral:
return AST.TemplateArgument.ArgumentKind.Integral;
case TemplateArgument.ArgumentKind.NullPtr:
return AST.TemplateArgument.ArgumentKind.NullPtr;
case TemplateArgument.ArgumentKind.Pack:
return AST.TemplateArgument.ArgumentKind.Pack;
case TemplateArgument.ArgumentKind.Template:
return AST.TemplateArgument.ArgumentKind.Template;
case TemplateArgument.ArgumentKind.TemplateExpansion:
return AST.TemplateArgument.ArgumentKind.TemplateExpansion;
case TemplateArgument.ArgumentKind.Type:
return AST.TemplateArgument.ArgumentKind.Type;
default:
throw new NotImplementedException();
}
}
private AST.TemplateSpecializationKind VisitSpecializationKind(TemplateSpecializationKind templateSpecializationKind)
{
switch (templateSpecializationKind)
{
case TemplateSpecializationKind.ExplicitInstantiationDeclaration:
return AST.TemplateSpecializationKind.ExplicitInstantiationDeclaration;
case TemplateSpecializationKind.ExplicitInstantiationDefinition:
return AST.TemplateSpecializationKind.ExplicitInstantiationDefinition;
case TemplateSpecializationKind.ExplicitSpecialization:
return AST.TemplateSpecializationKind.ExplicitSpecialization;
case TemplateSpecializationKind.ImplicitInstantiation:
return AST.TemplateSpecializationKind.ImplicitInstantiation;
case TemplateSpecializationKind.Undeclared:
return AST.TemplateSpecializationKind.Undeclared;
default:
throw new NotImplementedException();
}
}
public override AST.Declaration VisitClassTemplatePartialSpecialization(
ClassTemplatePartialSpecialization decl)
{
throw new NotImplementedException();
var _decl = new AST.ClassTemplatePartialSpecialization();
VisitClassTemplateSpecialization(decl, _decl);
return _decl;
}
public override AST.Declaration VisitFunctionTemplate(FunctionTemplate decl)

59
src/CppParser/AST.cpp

@ -55,6 +55,9 @@ AttributedType::AttributedType() : Type(TypeKind::Attributed) {} @@ -55,6 +55,9 @@ AttributedType::AttributedType() : Type(TypeKind::Attributed) {}
DecayedType::DecayedType() : Type(TypeKind::Decayed) {}
// Template
Template::Template(DeclarationKind kind) : Declaration(kind) {}
TemplateArgument::TemplateArgument() : Declaration(0) {}
TemplateSpecializationType::TemplateSpecializationType()
@ -136,8 +139,10 @@ DEF_STRING(Declaration, Name) @@ -136,8 +139,10 @@ DEF_STRING(Declaration, Name)
DEF_STRING(Declaration, DebugText)
DEF_VECTOR(Declaration, PreprocessedEntity*, PreprocessedEntities)
DeclarationContext::DeclarationContext() : IsAnonymous(false),
Declaration(DeclarationKind::DeclarationContext) {}
DeclarationContext::DeclarationContext(DeclarationKind kind)
: Declaration(kind)
, IsAnonymous(false)
{}
DEF_VECTOR(DeclarationContext, Namespace*, Namespaces)
DEF_VECTOR(DeclarationContext, Enumeration*, Enums)
@ -355,6 +360,18 @@ Function* DeclarationContext::FindFunction(const std::string& Name, bool Create) @@ -355,6 +360,18 @@ Function* DeclarationContext::FindFunction(const std::string& Name, bool Create)
return function;
}
ClassTemplate*
DeclarationContext::FindClassTemplate(void* OriginalPtr)
{
auto foundTemplate = std::find_if(Templates.begin(), Templates.end(),
[&](Template* t) { return t->OriginalPtr == OriginalPtr; });
if (foundTemplate != Templates.end())
return static_cast<ClassTemplate*>(*foundTemplate);
return nullptr;
}
FunctionTemplate*
DeclarationContext::FindFunctionTemplate(void* OriginalPtr)
{
@ -450,7 +467,20 @@ Field::Field() : Declaration(DeclarationKind::Field), Class(0) {} @@ -450,7 +467,20 @@ Field::Field() : Declaration(DeclarationKind::Field), Class(0) {}
AccessSpecifierDecl::AccessSpecifierDecl()
: Declaration(DeclarationKind::AccessSpecifier) {}
Class::Class() : Layout(0) { Kind = DeclarationKind::Class; }
Class::Class()
: DeclarationContext(DeclarationKind::Class)
, IsPOD(false)
, IsAbstract(false)
, IsUnion(false)
, IsDynamic(false)
, IsPolymorphic(false)
, HasNonTrivialDefaultConstructor(false)
, HasNonTrivialCopyConstructor(false)
, HasNonTrivialDestructor(false)
, IsExternCContext(false)
, Layout(0)
{
}
DEF_VECTOR(Class, BaseClassSpecifier*, Bases)
DEF_VECTOR(Class, Field*, Fields)
@ -462,7 +492,7 @@ Template::Template() : Declaration(DeclarationKind::Template), @@ -462,7 +492,7 @@ Template::Template() : Declaration(DeclarationKind::Template),
DEF_VECTOR(Template, TemplateParameter, Parameters)
ClassTemplate::ClassTemplate() { Kind = DeclarationKind::ClassTemplate; }
ClassTemplate::ClassTemplate() : Template(DeclarationKind::ClassTemplate) {}
DEF_VECTOR(ClassTemplate, ClassTemplateSpecialization*, Specializations)
@ -474,9 +504,13 @@ DEF_VECTOR(ClassTemplateSpecialization, TemplateArgument, Arguments) @@ -474,9 +504,13 @@ DEF_VECTOR(ClassTemplateSpecialization, TemplateArgument, Arguments)
ClassTemplatePartialSpecialization::ClassTemplatePartialSpecialization()
{ Kind = DeclarationKind::ClassTemplatePartialSpecialization; }
FunctionTemplate::FunctionTemplate() { Kind = DeclarationKind::FunctionTemplate; }
FunctionTemplate::FunctionTemplate() : Template(DeclarationKind::FunctionTemplate) {}
Namespace::Namespace() : IsInline(false) { Kind = DeclarationKind::Namespace; }
Namespace::Namespace()
: DeclarationContext(DeclarationKind::Namespace)
, IsInline(false)
{
}
PreprocessedEntity::PreprocessedEntity()
: Declaration(DeclarationKind::PreprocessedEntity),
@ -504,7 +538,13 @@ DEF_VECTOR(ASTContext, TranslationUnit*, TranslationUnits) @@ -504,7 +538,13 @@ DEF_VECTOR(ASTContext, TranslationUnit*, TranslationUnits)
ClassTemplateSpecialization* ClassTemplate::FindSpecialization(void* ptr)
{
return 0;
auto foundSpec = std::find_if(Specializations.begin(), Specializations.end(),
[&](ClassTemplateSpecialization* cts) { return cts->OriginalPtr == ptr; });
if (foundSpec != Specializations.end())
return static_cast<ClassTemplateSpecialization*>(*foundSpec);
return nullptr;
}
ClassTemplateSpecialization*
@ -515,7 +555,10 @@ ClassTemplate::FindSpecialization(TemplateSpecializationType type) @@ -515,7 +555,10 @@ ClassTemplate::FindSpecialization(TemplateSpecializationType type)
ClassTemplatePartialSpecialization* ClassTemplate::FindPartialSpecialization(void* ptr)
{
return 0;
auto foundSpec = FindSpecialization(ptr);
if (foundSpec != nullptr)
return static_cast<ClassTemplatePartialSpecialization*>(foundSpec);
return nullptr;
}
ClassTemplatePartialSpecialization*

6
src/CppParser/AST.h

@ -380,12 +380,13 @@ struct Function; @@ -380,12 +380,13 @@ struct Function;
struct TypedefDecl;
struct Namespace;
struct Template;
struct ClassTemplate;
struct FunctionTemplate;
struct Variable;
struct CS_API DeclarationContext : public Declaration
{
DECLARE_DECL_KIND(DeclarationContext, DeclarationContext)
DeclarationContext(DeclarationKind kind);
CS_IGNORE Declaration* FindAnonymous(uint64_t key);
@ -398,6 +399,7 @@ struct CS_API DeclarationContext : public Declaration @@ -398,6 +399,7 @@ struct CS_API DeclarationContext : public Declaration
CS_IGNORE Class* FindClass(const std::string& Name, bool IsComplete,
bool Create = false);
CS_IGNORE ClassTemplate* FindClassTemplate(void* OriginalPtr);
CS_IGNORE FunctionTemplate* FindFunctionTemplate(void* OriginalPtr);
CS_IGNORE FunctionTemplate* FindFunctionTemplate(const std::string& Name,
const std::vector<TemplateParameter>& Params);
@ -574,7 +576,6 @@ struct CS_API Variable : public Declaration @@ -574,7 +576,6 @@ struct CS_API Variable : public Declaration
CppSharp::CppParser::AST::QualifiedType QualifiedType;
};
struct DeclarationContext;
struct PreprocessedEntity;
struct CS_API BaseClassSpecifier
@ -624,6 +625,7 @@ struct CS_API Class : public DeclarationContext @@ -624,6 +625,7 @@ struct CS_API Class : public DeclarationContext
struct CS_API Template : public Declaration
{
Template(DeclarationKind kind);
DECLARE_DECL_KIND(Template, Template)
Declaration* TemplatedDecl;
VECTOR(TemplateParameter, Parameters)

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

@ -1236,10 +1236,11 @@ CppSharp::Parser::AST::DeclarationContext::DeclarationContext(System::IntPtr nat @@ -1236,10 +1236,11 @@ CppSharp::Parser::AST::DeclarationContext::DeclarationContext(System::IntPtr nat
auto __native = (::CppSharp::CppParser::AST::DeclarationContext*)native.ToPointer();
}
CppSharp::Parser::AST::DeclarationContext::DeclarationContext()
CppSharp::Parser::AST::DeclarationContext::DeclarationContext(CppSharp::Parser::AST::DeclarationKind kind)
: CppSharp::Parser::AST::Declaration((::CppSharp::CppParser::AST::Declaration*)nullptr)
{
NativePtr = new ::CppSharp::CppParser::AST::DeclarationContext();
auto arg0 = (::CppSharp::CppParser::AST::DeclarationKind)kind;
NativePtr = new ::CppSharp::CppParser::AST::DeclarationContext(arg0);
}
CppSharp::Parser::AST::Namespace^ CppSharp::Parser::AST::DeclarationContext::getNamespaces(unsigned int i)
@ -2222,6 +2223,13 @@ CppSharp::Parser::AST::Template::Template(System::IntPtr native) @@ -2222,6 +2223,13 @@ CppSharp::Parser::AST::Template::Template(System::IntPtr native)
auto __native = (::CppSharp::CppParser::AST::Template*)native.ToPointer();
}
CppSharp::Parser::AST::Template::Template(CppSharp::Parser::AST::DeclarationKind kind)
: CppSharp::Parser::AST::Declaration((::CppSharp::CppParser::AST::Declaration*)nullptr)
{
auto arg0 = (::CppSharp::CppParser::AST::DeclarationKind)kind;
NativePtr = new ::CppSharp::CppParser::AST::Template(arg0);
}
CppSharp::Parser::AST::Template::Template()
: CppSharp::Parser::AST::Declaration((::CppSharp::CppParser::AST::Declaration*)nullptr)
{

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

@ -221,6 +221,15 @@ namespace CppSharp @@ -221,6 +221,15 @@ namespace CppSharp
UnusedFunctionPointer = 7
};
public enum struct TemplateSpecializationKind
{
Undeclared = 0,
ImplicitInstantiation = 1,
ExplicitSpecialization = 2,
ExplicitInstantiationDeclaration = 3,
ExplicitInstantiationDefinition = 4
};
public enum struct PrimitiveType
{
Null = 0,
@ -269,15 +278,6 @@ namespace CppSharp @@ -269,15 +278,6 @@ namespace CppSharp
FunctionBody = 5
};
public enum struct TemplateSpecializationKind
{
Undeclared = 0,
ImplicitInstantiation = 1,
ExplicitSpecialization = 2,
ExplicitInstantiationDeclaration = 3,
ExplicitInstantiationDefinition = 4
};
public ref class Type : ICppInstance
{
public:
@ -1008,7 +1008,7 @@ namespace CppSharp @@ -1008,7 +1008,7 @@ namespace CppSharp
DeclarationContext(::CppSharp::CppParser::AST::DeclarationContext* native);
DeclarationContext(System::IntPtr native);
DeclarationContext();
DeclarationContext(CppSharp::Parser::AST::DeclarationKind kind);
property unsigned int NamespacesCount
{
@ -1554,6 +1554,8 @@ namespace CppSharp @@ -1554,6 +1554,8 @@ namespace CppSharp
Template(::CppSharp::CppParser::AST::Template* native);
Template(System::IntPtr native);
Template(CppSharp::Parser::AST::DeclarationKind kind);
Template();
property unsigned int ParametersCount

1
src/CppParser/Bindings/CLI/CppParser.h

@ -11,6 +11,7 @@ namespace CppSharp @@ -11,6 +11,7 @@ namespace CppSharp
enum struct ParserResultKind;
enum struct SourceLocationKind;
ref class ClangParser;
ref class Parser;
ref class ParserDiagnostic;
ref class ParserOptions;
ref class ParserResult;

1265
src/CppParser/Bindings/CSharp/AST.cs

File diff suppressed because it is too large Load Diff

60
src/CppParser/Bindings/CSharp/CppParser.cs

@ -40,47 +40,26 @@ namespace CppSharp @@ -40,47 +40,26 @@ namespace CppSharp
[StructLayout(LayoutKind.Explicit, Size = 124)]
public struct Internal
{
[FieldOffset(0)]
internal Std.Vector Arguments;
[FieldOffset(12)]
internal Std.String FileName;
[FieldOffset(36)]
internal Std.Vector IncludeDirs;
[FieldOffset(48)]
internal Std.Vector SystemIncludeDirs;
[FieldOffset(60)]
internal Std.Vector Defines;
[FieldOffset(72)]
internal Std.Vector LibraryDirs;
[FieldOffset(84)]
internal global::System.IntPtr ASTContext;
public global::System.IntPtr ASTContext;
[FieldOffset(88)]
internal int ToolSetToUse;
[FieldOffset(92)]
internal Std.String TargetTriple;
public int ToolSetToUse;
[FieldOffset(116)]
internal CppSharp.Parser.AST.CppAbi Abi;
public CppSharp.Parser.AST.CppAbi Abi;
[FieldOffset(120)]
internal bool NoStandardIncludes;
public bool NoStandardIncludes;
[FieldOffset(121)]
internal bool NoBuiltinIncludes;
public bool NoBuiltinIncludes;
[FieldOffset(122)]
internal bool MicrosoftMode;
public bool MicrosoftMode;
[FieldOffset(123)]
internal bool Verbose;
public bool Verbose;
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
@ -488,20 +467,14 @@ namespace CppSharp @@ -488,20 +467,14 @@ namespace CppSharp
[StructLayout(LayoutKind.Explicit, Size = 60)]
public struct Internal
{
[FieldOffset(0)]
internal Std.String FileName;
[FieldOffset(24)]
internal Std.String Message;
[FieldOffset(48)]
internal CppSharp.Parser.ParserDiagnosticLevel Level;
public CppSharp.Parser.ParserDiagnosticLevel Level;
[FieldOffset(52)]
internal int LineNumber;
public int LineNumber;
[FieldOffset(56)]
internal int ColumnNumber;
public int ColumnNumber;
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
@ -656,20 +629,17 @@ namespace CppSharp @@ -656,20 +629,17 @@ namespace CppSharp
public unsafe partial class ParserResult : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
[StructLayout(LayoutKind.Explicit, Size = 28)]
public struct Internal
{
[FieldOffset(0)]
internal CppSharp.Parser.ParserResultKind Kind;
[FieldOffset(4)]
internal Std.Vector Diagnostics;
public CppSharp.Parser.ParserResultKind Kind;
[FieldOffset(16)]
internal global::System.IntPtr ASTContext;
public global::System.IntPtr ASTContext;
[FieldOffset(20)]
internal global::System.IntPtr Library;
public global::System.IntPtr Library;
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
@ -721,7 +691,7 @@ namespace CppSharp @@ -721,7 +691,7 @@ namespace CppSharp
public ParserResult()
{
__Instance = Marshal.AllocHGlobal(24);
__Instance = Marshal.AllocHGlobal(28);
Internal.ctor_0(__Instance);
}

79
src/CppParser/Bindings/CSharp/Target.cs

@ -30,122 +30,119 @@ namespace CppSharp @@ -30,122 +30,119 @@ namespace CppSharp
[StructLayout(LayoutKind.Explicit, Size = 176)]
public struct Internal
{
[FieldOffset(0)]
internal Std.String ABI;
[FieldOffset(24)]
internal CppSharp.Parser.ParserIntType Char16Type;
public CppSharp.Parser.ParserIntType Char16Type;
[FieldOffset(28)]
internal CppSharp.Parser.ParserIntType Char32Type;
public CppSharp.Parser.ParserIntType Char32Type;
[FieldOffset(32)]
internal CppSharp.Parser.ParserIntType Int64Type;
public CppSharp.Parser.ParserIntType Int64Type;
[FieldOffset(36)]
internal CppSharp.Parser.ParserIntType IntMaxType;
public CppSharp.Parser.ParserIntType IntMaxType;
[FieldOffset(40)]
internal CppSharp.Parser.ParserIntType IntPtrType;
public CppSharp.Parser.ParserIntType IntPtrType;
[FieldOffset(44)]
internal CppSharp.Parser.ParserIntType SizeType;
public CppSharp.Parser.ParserIntType SizeType;
[FieldOffset(48)]
internal CppSharp.Parser.ParserIntType UIntMaxType;
public CppSharp.Parser.ParserIntType UIntMaxType;
[FieldOffset(52)]
internal CppSharp.Parser.ParserIntType WCharType;
public CppSharp.Parser.ParserIntType WCharType;
[FieldOffset(56)]
internal CppSharp.Parser.ParserIntType WIntType;
public CppSharp.Parser.ParserIntType WIntType;
[FieldOffset(60)]
internal uint BoolAlign;
public uint BoolAlign;
[FieldOffset(64)]
internal uint BoolWidth;
public uint BoolWidth;
[FieldOffset(68)]
internal uint CharAlign;
public uint CharAlign;
[FieldOffset(72)]
internal uint CharWidth;
public uint CharWidth;
[FieldOffset(76)]
internal uint Char16Align;
public uint Char16Align;
[FieldOffset(80)]
internal uint Char16Width;
public uint Char16Width;
[FieldOffset(84)]
internal uint Char32Align;
public uint Char32Align;
[FieldOffset(88)]
internal uint Char32Width;
public uint Char32Width;
[FieldOffset(92)]
internal uint HalfAlign;
public uint HalfAlign;
[FieldOffset(96)]
internal uint HalfWidth;
public uint HalfWidth;
[FieldOffset(100)]
internal uint FloatAlign;
public uint FloatAlign;
[FieldOffset(104)]
internal uint FloatWidth;
public uint FloatWidth;
[FieldOffset(108)]
internal uint DoubleAlign;
public uint DoubleAlign;
[FieldOffset(112)]
internal uint DoubleWidth;
public uint DoubleWidth;
[FieldOffset(116)]
internal uint ShortAlign;
public uint ShortAlign;
[FieldOffset(120)]
internal uint ShortWidth;
public uint ShortWidth;
[FieldOffset(124)]
internal uint IntAlign;
public uint IntAlign;
[FieldOffset(128)]
internal uint IntWidth;
public uint IntWidth;
[FieldOffset(132)]
internal uint IntMaxTWidth;
public uint IntMaxTWidth;
[FieldOffset(136)]
internal uint LongAlign;
public uint LongAlign;
[FieldOffset(140)]
internal uint LongWidth;
public uint LongWidth;
[FieldOffset(144)]
internal uint LongDoubleAlign;
public uint LongDoubleAlign;
[FieldOffset(148)]
internal uint LongDoubleWidth;
public uint LongDoubleWidth;
[FieldOffset(152)]
internal uint LongLongAlign;
public uint LongLongAlign;
[FieldOffset(156)]
internal uint LongLongWidth;
public uint LongLongWidth;
[FieldOffset(160)]
internal uint PointerAlign;
public uint PointerAlign;
[FieldOffset(164)]
internal uint PointerWidth;
public uint PointerWidth;
[FieldOffset(168)]
internal uint WCharAlign;
public uint WCharAlign;
[FieldOffset(172)]
internal uint WCharWidth;
public uint WCharWidth;
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,

43
src/CppParser/Parser.cpp

@ -791,13 +791,18 @@ ClassTemplate* Parser::WalkClassTemplate(clang::ClassTemplateDecl* TD) @@ -791,13 +791,18 @@ ClassTemplate* Parser::WalkClassTemplate(clang::ClassTemplateDecl* TD)
auto NS = GetNamespace(TD);
assert(NS && "Expected a valid namespace");
ClassTemplate* CT = new ClassTemplate();
HandleDeclaration(TD, CT);
auto CT = NS->FindClassTemplate((void*) TD);
if (CT != nullptr)
return CT;
CT->TemplatedDecl = WalkRecordCXX(TD->getTemplatedDecl());
CT = new ClassTemplate();
HandleDeclaration(TD, CT);
CT->_Namespace = NS;
NS->Templates.push_back(CT);
CT->TemplatedDecl = WalkRecordCXX(TD->getTemplatedDecl());
auto TPL = TD->getTemplateParameters();
for(auto it = TPL->begin(); it != TPL->end(); ++it)
{
@ -1107,10 +1112,15 @@ DeclarationContext* Parser::GetNamespace(clang::Decl* D, @@ -1107,10 +1112,15 @@ DeclarationContext* Parser::GetNamespace(clang::Decl* D,
continue;
}
case Decl::ClassTemplateSpecialization:
{
auto CTSpec = cast<ClassTemplateSpecializationDecl>(Ctx);
DC = WalkClassTemplateSpecialization(CTSpec);
continue;
}
case Decl::ClassTemplatePartialSpecialization:
{
// FIXME: Ignore ClassTemplateSpecialization namespaces...
// We might be able to translate these to C# nested types.
auto CTPSpec = cast<ClassTemplatePartialSpecializationDecl>(Ctx);
DC = WalkClassTemplatePartialSpecialization(CTPSpec);
continue;
}
default:
@ -1487,8 +1497,6 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1487,8 +1497,6 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
F->Parameters.push_back(FA);
}
return F;
Ty = F;
break;
}
@ -1684,6 +1692,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1684,6 +1692,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
{
// TODO: stubbed
Ty = new PackExpansionType();
break;
}
case clang::Type::Decltype:
{
@ -1838,7 +1847,6 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, @@ -1838,7 +1847,6 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
auto NS = GetNamespace(FD);
assert(NS && "Expected a valid namespace");
F->OriginalPtr = (void*) FD;
F->Name = FD->getNameAsString();
F->_Namespace = NS;
F->IsVariadic = FD->isVariadic();
@ -2320,10 +2328,6 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2320,10 +2328,6 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
{
ClassTemplateDecl* TD = cast<ClassTemplateDecl>(D);
auto Template = WalkClassTemplate(TD);
auto NS = GetNamespace(TD);
Template->_Namespace = NS;
NS->Templates.push_back(Template);
Decl = Template;
break;
@ -2331,8 +2335,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2331,8 +2335,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
case Decl::ClassTemplateSpecialization:
{
auto TS = cast<ClassTemplateSpecializationDecl>(D);
auto CT = new ClassTemplateSpecialization();
HandleDeclaration(TS, CT);
auto CT = WalkClassTemplateSpecialization(TS);
Decl = CT;
break;
@ -2340,8 +2343,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2340,8 +2343,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
case Decl::ClassTemplatePartialSpecialization:
{
auto TS = cast<ClassTemplatePartialSpecializationDecl>(D);
auto CT = new ClassTemplatePartialSpecialization();
HandleDeclaration(TS, CT);
auto CT = WalkClassTemplatePartialSpecialization(TS);
Decl = CT;
break;
@ -2349,13 +2351,9 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2349,13 +2351,9 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
case Decl::FunctionTemplate:
{
FunctionTemplateDecl* TD = cast<FunctionTemplateDecl>(D);
auto Template = WalkFunctionTemplate(TD);
auto NS = GetNamespace(TD);
Template->_Namespace = NS;
NS->Templates.push_back(Template);
auto FT = WalkFunctionTemplate(TD);
Decl = Template;
Decl = FT;
break;
}
case Decl::Enum:
@ -2447,6 +2445,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2447,6 +2445,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
case Decl::UnresolvedUsingValue:
case Decl::IndirectField:
case Decl::StaticAssert:
case Decl::TypeAliasTemplate:
break;
default:
{

37
src/Parser/Parser.cpp

@ -541,6 +541,10 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -541,6 +541,10 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
if (Record->isInjectedClassName())
return nullptr;
// skip va_list_tag as in clang: lib/Sema/SemaLookup.cpp
if (Record->getDeclName() == C->getSema().VAListTagName)
return nullptr;
auto NS = GetNamespace(Record);
assert(NS && "Expected a valid namespace");
@ -616,6 +620,8 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record, @@ -616,6 +620,8 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record,
if (hasLayout)
{
Layout = &C->getASTContext().getASTRecordLayout(Record);
if (!RC->Layout)
RC->Layout = gcnew CppSharp::AST::ClassLayout();
RC->Layout->Alignment = (int)Layout-> getAlignment().getQuantity();
RC->Layout->Size = (int)Layout->getSize().getQuantity();
RC->Layout->DataSize = (int)Layout->getDataSize().getQuantity();
@ -681,7 +687,9 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record, @@ -681,7 +687,9 @@ void Parser::WalkRecordCXX(clang::CXXRecordDecl* Record,
CppSharp::AST::BaseClassSpecifier^ Base = gcnew CppSharp::AST::BaseClassSpecifier();
Base->Access = ConvertToAccess(BS.getAccessSpecifier());
Base->IsVirtual = BS.isVirtual();
Base->Type = WalkType(BS.getType(), &BS.getTypeSourceInfo()->getTypeLoc());
auto BSTL = BS.getTypeSourceInfo()->getTypeLoc();
Base->Type = WalkType(BS.getType(), &BSTL);
RC->Bases->Add(Base);
}
@ -1377,9 +1385,12 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1377,9 +1385,12 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Type = gcnew CppSharp::AST::DecayedType();
Type->Decayed = GetQualifiedType(DT->getDecayedType(), WalkType(DT->getDecayedType(), &Next));
Type->Original = GetQualifiedType(DT->getOriginalType(), WalkType(DT->getOriginalType(), &Next));
Type->Pointee = GetQualifiedType(DT->getPointeeType(), WalkType(DT->getPointeeType(), &Next));
Type->Decayed = GetQualifiedType(DT->getDecayedType(),
WalkType(DT->getDecayedType(), &Next));
Type->Original = GetQualifiedType(DT->getOriginalType(),
WalkType(DT->getOriginalType(), &Next));
Type->Pointee = GetQualifiedType(DT->getPointeeType(),
WalkType(DT->getPointeeType(), &Next));
Ty = Type;
break;
@ -1423,7 +1434,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1423,7 +1434,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = gcnew CppSharp::AST::ArrayType();
A->Type = WalkType(AT->getElementType(), &Next);
A->QualifiedType = GetQualifiedType(AT->getElementType(),
WalkType(AT->getElementType(), &Next));
A->SizeType = CppSharp::AST::ArrayType::ArraySize::Constant;
A->Size = AST->getConstantArrayElementCount(AT);
@ -1438,7 +1450,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1438,7 +1450,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = gcnew CppSharp::AST::ArrayType();
A->Type = WalkType(AT->getElementType(), &Next);
A->QualifiedType = GetQualifiedType(AT->getElementType(),
WalkType(AT->getElementType(), &Next));
A->SizeType = CppSharp::AST::ArrayType::ArraySize::Incomplete;
Ty = A;
@ -1452,7 +1465,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1452,7 +1465,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = gcnew CppSharp::AST::ArrayType();
A->Type = WalkType(AT->getElementType(), &Next);
A->QualifiedType = GetQualifiedType(AT->getElementType(),
WalkType(AT->getElementType(), &Next));
A->SizeType = CppSharp::AST::ArrayType::ArraySize::Dependent;
//A->Size = AT->getSizeExpr();
@ -1519,11 +1533,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1519,11 +1533,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
case Type::MemberPointer:
{
auto MP = Type->getAs<clang::MemberPointerType>();
TypeLoc Next;
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto MPT = gcnew CppSharp::AST::MemberPointerType();
MPT->Pointee = WalkType(MP->getPointeeType(), &Next);
MPT->QualifiedPointee = GetQualifiedType(MP->getPointeeType(),
WalkType(MP->getPointeeType(), &Next));
Ty = MPT;
break;
@ -1571,7 +1587,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1571,7 +1587,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Type;
TypeLoc ArgTL;
ArgTL = ArgLoc.getTypeSourceInfo()->getTypeLoc();
Arg.Type = GetQualifiedType(TA.getAsType(), WalkType(TA.getAsType(), &ArgTL));
Arg.Type = GetQualifiedType(TA.getAsType(),
WalkType(TA.getAsType(), &ArgTL));
break;
}
case TemplateArgument::Declaration:
@ -2159,7 +2176,7 @@ CppSharp::AST::PreprocessedEntity^ Parser::WalkPreprocessedEntity( @@ -2159,7 +2176,7 @@ CppSharp::AST::PreprocessedEntity^ Parser::WalkPreprocessedEntity(
return nullptr;
Entity->OriginalPtr = System::IntPtr(PPEntity);
Entity->Namespace = GetTranslationUnit(PPEntity->getSourceRange().getBegin(), NULL);
Entity->Namespace = GetTranslationUnit(PPEntity->getSourceRange().getBegin());
if (Decl->GetType() == CppSharp::AST::TranslationUnit::typeid)
{

Loading…
Cancel
Save