Browse Source

Reworked type parsing with dependent information.

pull/124/head
triton 12 years ago
parent
commit
4d91312e87
  1. 2
      src/AST/Type.cs
  2. 3
      src/CppParser/AST.h
  3. 11
      src/CppParser/Bindings/CLI/AST.cpp
  4. 5
      src/CppParser/Bindings/CLI/AST.h
  5. 140
      src/CppParser/Bindings/CSharp/AST.cs
  6. 126
      src/CppParser/Parser.cpp
  7. 125
      src/Parser/Parser.cpp

2
src/AST/Type.cs

@ -11,6 +11,8 @@ namespace CppSharp.AST @@ -11,6 +11,8 @@ namespace CppSharp.AST
{
public static Func<Type, string> TypePrinterDelegate;
public bool IsDependent { get; set; }
protected Type()
{
}

3
src/CppParser/AST.h

@ -31,7 +31,7 @@ namespace CppSharp { namespace CppParser { namespace AST { @@ -31,7 +31,7 @@ namespace CppSharp { namespace CppParser { namespace AST {
struct CS_API Type
{
bool IsDependent;
};
struct CS_API TypeQualifiers
@ -85,6 +85,7 @@ struct CS_API FunctionType : public Type @@ -85,6 +85,7 @@ struct CS_API FunctionType : public Type
{
QualifiedType ReturnType;
CppSharp::CppParser::AST::CallingConvention CallingConvention;
VECTOR(QualifiedType, Arguments)
VECTOR(Parameter*, Parameters)
};

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

@ -28,6 +28,17 @@ void CppSharp::Parser::AST::Type::Instance::set(System::IntPtr object) @@ -28,6 +28,17 @@ void CppSharp::Parser::AST::Type::Instance::set(System::IntPtr object)
{
NativePtr = (::CppSharp::CppParser::AST::Type*)object.ToPointer();
}
bool CppSharp::Parser::AST::Type::IsDependent::get()
{
return ((::CppSharp::CppParser::AST::Type*)NativePtr)->IsDependent;
}
void CppSharp::Parser::AST::Type::IsDependent::set(bool value)
{
((::CppSharp::CppParser::AST::Type*)NativePtr)->IsDependent = value;
}
CppSharp::Parser::AST::TypeQualifiers::TypeQualifiers(::CppSharp::CppParser::AST::TypeQualifiers* native)
{
NativePtr = native;

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

@ -227,6 +227,11 @@ namespace CppSharp @@ -227,6 +227,11 @@ namespace CppSharp
Type(System::IntPtr native);
Type();
property bool IsDependent
{
bool get();
void set(bool);
}
};
public ref class TypeQualifiers : ICppInstance

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

@ -154,6 +154,9 @@ namespace CppSharp @@ -154,6 +154,9 @@ namespace CppSharp
[StructLayout(LayoutKind.Explicit, Size = 1)]
public struct Internal
{
[FieldOffset(0)]
public bool IsDependent;
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0Type@AST@CppParser@CppSharp@@QAE@ABU0123@@Z")]
@ -164,7 +167,7 @@ namespace CppSharp @@ -164,7 +167,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 0; }
get { return 1; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -205,6 +208,21 @@ namespace CppSharp @@ -205,6 +208,21 @@ namespace CppSharp
{
Marshal.FreeHGlobal(__Instance);
}
public bool IsDependent
{
get
{
var __ptr = (Internal*)__Instance.ToPointer();
return __ptr->IsDependent;
}
set
{
var __ptr = (Internal*)__Instance.ToPointer();
__ptr->IsDependent = value;
}
}
}
public unsafe partial class TypeQualifiers : IDisposable, CppSharp.Runtime.ICppMarshal
@ -419,10 +437,10 @@ namespace CppSharp @@ -419,10 +437,10 @@ namespace CppSharp
public unsafe partial class TagType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 4)]
[StructLayout(LayoutKind.Explicit, Size = 8)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public global::System.IntPtr Declaration;
[SuppressUnmanagedCodeSecurity]
@ -433,7 +451,7 @@ namespace CppSharp @@ -433,7 +451,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 4; }
get { return 8; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -462,7 +480,7 @@ namespace CppSharp @@ -462,7 +480,7 @@ namespace CppSharp
public TagType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(4);
__Instance = Marshal.AllocHGlobal(8);
}
protected override void Dispose(bool disposing)
@ -489,16 +507,16 @@ namespace CppSharp @@ -489,16 +507,16 @@ namespace CppSharp
public unsafe partial class ArrayType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
[StructLayout(LayoutKind.Explicit, Size = 20)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType;
[FieldOffset(8)]
[FieldOffset(12)]
public CppSharp.Parser.AST.ArrayType.ArraySize SizeType;
[FieldOffset(12)]
[FieldOffset(16)]
public int Size;
[SuppressUnmanagedCodeSecurity]
@ -517,7 +535,7 @@ namespace CppSharp @@ -517,7 +535,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 16; }
get { return 20; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -546,7 +564,7 @@ namespace CppSharp @@ -546,7 +564,7 @@ namespace CppSharp
public ArrayType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(16);
__Instance = Marshal.AllocHGlobal(20);
}
protected override void Dispose(bool disposing)
@ -605,16 +623,16 @@ namespace CppSharp @@ -605,16 +623,16 @@ namespace CppSharp
public unsafe partial class FunctionType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
[StructLayout(LayoutKind.Explicit, Size = 40)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.QualifiedType.Internal ReturnType;
[FieldOffset(8)]
[FieldOffset(12)]
public CppSharp.Parser.AST.CallingConvention CallingConvention;
[FieldOffset(12)]
[FieldOffset(28)]
public Std.Vector Parameters;
[SuppressUnmanagedCodeSecurity]
@ -640,7 +658,7 @@ namespace CppSharp @@ -640,7 +658,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 24; }
get { return 40; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -669,7 +687,7 @@ namespace CppSharp @@ -669,7 +687,7 @@ namespace CppSharp
public FunctionType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(24);
__Instance = Marshal.AllocHGlobal(40);
Internal.FunctionType_1(__Instance);
}
@ -742,13 +760,13 @@ namespace CppSharp @@ -742,13 +760,13 @@ namespace CppSharp
public unsafe partial class PointerType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 12)]
[StructLayout(LayoutKind.Explicit, Size = 16)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.QualifiedType.Internal QualifiedPointee;
[FieldOffset(8)]
[FieldOffset(12)]
public CppSharp.Parser.AST.PointerType.TypeModifier Modifier;
[SuppressUnmanagedCodeSecurity]
@ -767,7 +785,7 @@ namespace CppSharp @@ -767,7 +785,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 12; }
get { return 16; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -796,7 +814,7 @@ namespace CppSharp @@ -796,7 +814,7 @@ namespace CppSharp
public PointerType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(12);
__Instance = Marshal.AllocHGlobal(16);
}
protected override void Dispose(bool disposing)
@ -840,10 +858,10 @@ namespace CppSharp @@ -840,10 +858,10 @@ namespace CppSharp
public unsafe partial class MemberPointerType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
[StructLayout(LayoutKind.Explicit, Size = 12)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.QualifiedType.Internal Pointee;
[SuppressUnmanagedCodeSecurity]
@ -854,7 +872,7 @@ namespace CppSharp @@ -854,7 +872,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 8; }
get { return 12; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -883,7 +901,7 @@ namespace CppSharp @@ -883,7 +901,7 @@ namespace CppSharp
public MemberPointerType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(8);
__Instance = Marshal.AllocHGlobal(12);
}
protected override void Dispose(bool disposing)
@ -912,10 +930,10 @@ namespace CppSharp @@ -912,10 +930,10 @@ namespace CppSharp
public unsafe partial class TypedefType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 4)]
[StructLayout(LayoutKind.Explicit, Size = 8)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public global::System.IntPtr Declaration;
[SuppressUnmanagedCodeSecurity]
@ -926,7 +944,7 @@ namespace CppSharp @@ -926,7 +944,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 4; }
get { return 8; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -955,7 +973,7 @@ namespace CppSharp @@ -955,7 +973,7 @@ namespace CppSharp
public TypedefType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(4);
__Instance = Marshal.AllocHGlobal(8);
}
protected override void Dispose(bool disposing)
@ -982,16 +1000,16 @@ namespace CppSharp @@ -982,16 +1000,16 @@ namespace CppSharp
public unsafe partial class DecayedType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
[StructLayout(LayoutKind.Explicit, Size = 28)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.QualifiedType.Internal Decayed;
[FieldOffset(8)]
[FieldOffset(12)]
public CppSharp.Parser.AST.QualifiedType.Internal Original;
[FieldOffset(16)]
[FieldOffset(20)]
public CppSharp.Parser.AST.QualifiedType.Internal Pointee;
[SuppressUnmanagedCodeSecurity]
@ -1002,7 +1020,7 @@ namespace CppSharp @@ -1002,7 +1020,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 24; }
get { return 28; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1031,7 +1049,7 @@ namespace CppSharp @@ -1031,7 +1049,7 @@ namespace CppSharp
public DecayedType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(24);
__Instance = Marshal.AllocHGlobal(28);
}
protected override void Dispose(bool disposing)
@ -1242,16 +1260,16 @@ namespace CppSharp @@ -1242,16 +1260,16 @@ namespace CppSharp
public unsafe partial class TemplateSpecializationType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 20)]
[StructLayout(LayoutKind.Explicit, Size = 24)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public Std.Vector Arguments;
[FieldOffset(12)]
[FieldOffset(16)]
public global::System.IntPtr Template;
[FieldOffset(16)]
[FieldOffset(20)]
public global::System.IntPtr Desugared;
[SuppressUnmanagedCodeSecurity]
@ -1277,7 +1295,7 @@ namespace CppSharp @@ -1277,7 +1295,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 20; }
get { return 24; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1306,7 +1324,7 @@ namespace CppSharp @@ -1306,7 +1324,7 @@ namespace CppSharp
public TemplateSpecializationType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(20);
__Instance = Marshal.AllocHGlobal(24);
Internal.TemplateSpecializationType_1(__Instance);
}
@ -1462,10 +1480,10 @@ namespace CppSharp @@ -1462,10 +1480,10 @@ namespace CppSharp
public unsafe partial class TemplateParameterType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
[StructLayout(LayoutKind.Explicit, Size = 28)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.TemplateParameter.Internal Parameter;
[SuppressUnmanagedCodeSecurity]
@ -1481,7 +1499,7 @@ namespace CppSharp @@ -1481,7 +1499,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 24; }
get { return 28; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1510,7 +1528,7 @@ namespace CppSharp @@ -1510,7 +1528,7 @@ namespace CppSharp
public TemplateParameterType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(24);
__Instance = Marshal.AllocHGlobal(28);
Internal.TemplateParameterType_0(__Instance);
}
@ -1540,10 +1558,10 @@ namespace CppSharp @@ -1540,10 +1558,10 @@ namespace CppSharp
public unsafe partial class TemplateParameterSubstitutionType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
[StructLayout(LayoutKind.Explicit, Size = 12)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.QualifiedType.Internal Replacement;
[SuppressUnmanagedCodeSecurity]
@ -1554,7 +1572,7 @@ namespace CppSharp @@ -1554,7 +1572,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 8; }
get { return 12; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1583,7 +1601,7 @@ namespace CppSharp @@ -1583,7 +1601,7 @@ namespace CppSharp
public TemplateParameterSubstitutionType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(8);
__Instance = Marshal.AllocHGlobal(12);
}
protected override void Dispose(bool disposing)
@ -1612,13 +1630,13 @@ namespace CppSharp @@ -1612,13 +1630,13 @@ namespace CppSharp
public unsafe partial class InjectedClassNameType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
[StructLayout(LayoutKind.Explicit, Size = 32)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.TemplateSpecializationType.Internal TemplateSpecialization;
[FieldOffset(20)]
[FieldOffset(28)]
public global::System.IntPtr Class;
[SuppressUnmanagedCodeSecurity]
@ -1634,7 +1652,7 @@ namespace CppSharp @@ -1634,7 +1652,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 24; }
get { return 32; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1663,7 +1681,7 @@ namespace CppSharp @@ -1663,7 +1681,7 @@ namespace CppSharp
public InjectedClassNameType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(24);
__Instance = Marshal.AllocHGlobal(32);
Internal.InjectedClassNameType_0(__Instance);
}
@ -1678,7 +1696,7 @@ namespace CppSharp @@ -1678,7 +1696,7 @@ namespace CppSharp
{
var __ptr = (Internal*)__Instance.ToPointer();
var __copy = new global::System.IntPtr(&__ptr->TemplateSpecialization);
var __instance = Marshal.AllocHGlobal(20);
var __instance = Marshal.AllocHGlobal(24);
CppSharp.Parser.AST.TemplateSpecializationType.Internal.TemplateSpecializationType_2(__instance, new global::System.IntPtr(&__copy));
return new CppSharp.Parser.AST.TemplateSpecializationType(__instance);
}
@ -1720,7 +1738,7 @@ namespace CppSharp @@ -1720,7 +1738,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 0; }
get { return 1; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1760,10 +1778,10 @@ namespace CppSharp @@ -1760,10 +1778,10 @@ namespace CppSharp
public unsafe partial class BuiltinType : CppSharp.Parser.AST.Type, IDisposable, CppSharp.Runtime.ICppMarshal
{
[StructLayout(LayoutKind.Explicit, Size = 4)]
[StructLayout(LayoutKind.Explicit, Size = 8)]
public new struct Internal
{
[FieldOffset(0)]
[FieldOffset(4)]
public CppSharp.Parser.AST.PrimitiveType Type;
[SuppressUnmanagedCodeSecurity]
@ -1774,7 +1792,7 @@ namespace CppSharp @@ -1774,7 +1792,7 @@ namespace CppSharp
int CppSharp.Runtime.ICppMarshal.NativeDataSize
{
get { return 4; }
get { return 8; }
}
void CppSharp.Runtime.ICppMarshal.MarshalManagedToNative(global::System.IntPtr instance)
@ -1803,7 +1821,7 @@ namespace CppSharp @@ -1803,7 +1821,7 @@ namespace CppSharp
public BuiltinType()
: this(IntPtr.Zero)
{
__Instance = Marshal.AllocHGlobal(4);
__Instance = Marshal.AllocHGlobal(8);
}
protected override void Dispose(bool disposing)

126
src/CppParser/Parser.cpp

@ -1099,6 +1099,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1099,6 +1099,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
Type = Desugared.getTypePtr();
}
CppSharp::CppParser::AST::Type* Ty = nullptr;
assert(Type && "Expected a valid type");
switch(Type->getTypeClass())
{
@ -1110,7 +1112,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1110,7 +1112,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
auto BT = new BuiltinType();
BT->Type = WalkBuiltinType(Builtin);
return BT;
Ty = BT;
break;
}
case clang::Type::Enum:
{
@ -1120,7 +1123,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1120,7 +1123,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
auto TT = new TagType();
TT->Declaration = TT->Declaration = WalkDeclaration(ED, /*IgnoreSystemDecls=*/false);
return TT;
Ty = TT;
break;
}
case clang::Type::Pointer:
{
@ -1130,12 +1134,13 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1130,12 +1134,13 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
P->Modifier = PointerType::TypeModifier::Pointer;
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Pointee = Pointer->getPointeeType();
P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
Ty = P;
break;
}
case clang::Type::Typedef:
{
@ -1149,13 +1154,15 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1149,13 +1154,15 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
auto Type = new TypedefType();
Type->Declaration = TDD;
return Type;
Ty = Type;
break;
}
case clang::Type::Decayed:
{
auto DT = Type->getAs<clang::DecayedType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Type = new DecayedType();
Type->Decayed = GetQualifiedType(DT->getDecayedType(),
@ -1165,14 +1172,18 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1165,14 +1172,18 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
Type->Pointee = GetQualifiedType(DT->getPointeeType(),
WalkType(DT->getPointeeType(), &Next));
return Type;
Ty = Type;
break;
}
case clang::Type::Elaborated:
{
auto ET = Type->getAs<clang::ElaboratedType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
return WalkType(ET->getNamedType(), &Next);
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
Ty = WalkType(ET->getNamedType(), &Next);
break;
}
case clang::Type::Record:
{
@ -1182,62 +1193,77 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1182,62 +1193,77 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
auto TT = new TagType();
TT->Declaration = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false);
return TT;
Ty = TT;
break;
}
case clang::Type::Paren:
{
auto PT = Type->getAs<clang::ParenType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
return WalkType(PT->getInnerType(), &Next);
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
Ty = WalkType(PT->getInnerType(), &Next);
break;
}
case clang::Type::ConstantArray:
{
auto AT = AST->getAsConstantArrayType(QualType);
auto A = new ArrayType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = new ArrayType();
A->QualifiedType = GetQualifiedType(AT->getElementType(),
WalkType(AT->getElementType(), &Next));
A->SizeType = ArrayType::ArraySize::Constant;
A->Size = AST->getConstantArrayElementCount(AT);
return A;
Ty = A;
break;
}
case clang::Type::IncompleteArray:
{
auto AT = AST->getAsIncompleteArrayType(QualType);
auto A = new ArrayType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = new ArrayType();
A->QualifiedType = GetQualifiedType(AT->getElementType(),
WalkType(AT->getElementType(), &Next));
A->SizeType = ArrayType::ArraySize::Incomplete;
return A;
Ty = A;
break;
}
case clang::Type::DependentSizedArray:
{
auto AT = AST->getAsDependentSizedArrayType(QualType);
auto A = new ArrayType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = new ArrayType();
A->QualifiedType = GetQualifiedType(AT->getElementType(),
WalkType(AT->getElementType(), &Next));
A->SizeType = ArrayType::ArraySize::Dependent;
//A->Size = AT->getSizeExpr();
return A;
Ty = A;
break;
}
case clang::Type::FunctionProto:
{
auto FP = Type->getAs<clang::FunctionProtoType>();
auto FTL = TL->getAs<FunctionProtoTypeLoc>();
auto RL = FTL.getResultLoc();
FunctionProtoTypeLoc FTL;
TypeLoc RL;
if (TL && !TL->isNull())
{
FTL = TL->getAs<FunctionProtoTypeLoc>();
RL = FTL.getResultLoc();
}
auto F = new FunctionType();
F->ReturnType = GetQualifiedType(FP->getResultType(),
@ -1261,28 +1287,37 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1261,28 +1287,37 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
}
return F;
Ty = F;
break;
}
case clang::Type::TypeOf:
{
auto TO = Type->getAs<clang::TypeOfType>();
return WalkType(TO->getUnderlyingType());
Ty = WalkType(TO->getUnderlyingType());
break;
}
case clang::Type::TypeOfExpr:
{
auto TO = Type->getAs<clang::TypeOfExprType>();
return WalkType(TO->getUnderlyingExpr()->getType());
Ty = WalkType(TO->getUnderlyingExpr()->getType());
break;
}
case clang::Type::MemberPointer:
{
auto MP = Type->getAs<clang::MemberPointerType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto MPT = new MemberPointerType();
MPT->Pointee = GetQualifiedType(MP->getPointeeType(),
WalkType(MP->getPointeeType(), &Next));
return MPT;
Ty = MPT;
break;
}
case clang::Type::TemplateSpecialization:
{
@ -1360,7 +1395,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1360,7 +1395,8 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
TST->Arguments.push_back(Arg);
}
return TST;
Ty = TST;
break;
}
case clang::Type::TemplateTypeParm:
{
@ -1371,19 +1407,22 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1371,19 +1407,22 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
if (auto Ident = TP->getIdentifier())
TPT->Parameter.Name = Ident->getName();
return TPT;
Ty = TPT;
break;
}
case clang::Type::SubstTemplateTypeParm:
{
auto TP = Type->getAs<SubstTemplateTypeParmType>();
auto Ty = TP->getReplacementType();
auto TPT = new TemplateParameterSubstitutionType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
TPT->Replacement = GetQualifiedType(Ty, WalkType(Ty, &Next));
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto RepTy = TP->getReplacementType();
TPT->Replacement = GetQualifiedType(RepTy, WalkType(RepTy, &Next));
return TPT;
Ty = TPT;
break;
}
case clang::Type::InjectedClassName:
{
@ -1391,13 +1430,17 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1391,13 +1430,17 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
auto ICNT = new InjectedClassNameType();
ICNT->Class = static_cast<Class*>(WalkDeclaration(
ICN->getDecl(), 0, /*IgnoreSystemDecls=*/false));
return ICNT;
Ty = ICNT;
break;
}
case clang::Type::DependentName:
{
auto DN = Type->getAs<clang::DependentNameType>();
auto DNT = new DependentNameType();
return DNT;
Ty = DNT;
break;
}
case clang::Type::LValueReference:
{
@ -1407,12 +1450,13 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1407,12 +1450,13 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
P->Modifier = PointerType::TypeModifier::LVReference;
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Pointee = LR->getPointeeType();
P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
Ty = P;
break;
}
case clang::Type::RValueReference:
{
@ -1422,12 +1466,13 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1422,12 +1466,13 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
P->Modifier = PointerType::TypeModifier::RVReference;
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Pointee = LR->getPointeeType();
P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
Ty = P;
break;
}
case clang::Type::Vector:
{
@ -1444,6 +1489,9 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, @@ -1444,6 +1489,9 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
Debug("Unhandled type class '%s'\n", Type->getTypeClassName());
return nullptr;
} }
Ty->IsDependent = Type->isDependentType();
return Ty;
}
//-----------------------------------//

125
src/Parser/Parser.cpp

@ -1221,6 +1221,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1221,6 +1221,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
Type = Desugared.getTypePtr();
}
CppSharp::AST::Type^ Ty = nullptr;
assert(Type && "Expected a valid type");
switch(Type->getTypeClass())
{
@ -1232,7 +1234,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1232,7 +1234,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
auto BT = gcnew CppSharp::AST::BuiltinType();
BT->Type = WalkBuiltinType(Builtin);
return BT;
Ty = BT;
break;
}
case Type::Enum:
{
@ -1242,7 +1245,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1242,7 +1245,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
auto TT = gcnew CppSharp::AST::TagType();
TT->Declaration = TT->Declaration = WalkDeclaration(ED, /*IgnoreSystemDecls=*/false);
return TT;
Ty = TT;
break;
}
case Type::Pointer:
{
@ -1252,12 +1256,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1252,12 +1256,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
P->Modifier = CppSharp::AST::PointerType::TypeModifier::Pointer;
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Pointee = Pointer->getPointeeType();
P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
Ty = P;
break;
}
case Type::Typedef:
{
@ -1271,27 +1276,33 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1271,27 +1276,33 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
auto Type = gcnew CppSharp::AST::TypedefType();
Type->Declaration = TDD;
return Type;
Ty = Type;
break;
}
case Type::Decayed:
{
auto DT = Type->getAs<clang::DecayedType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
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));
return Type;
Ty = Type;
break;
}
case Type::Elaborated:
{
auto ET = Type->getAs<clang::ElaboratedType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
return WalkType(ET->getNamedType(), &Next);
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
Ty = WalkType(ET->getNamedType(), &Next);
break;
}
case Type::Record:
{
@ -1301,59 +1312,74 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1301,59 +1312,74 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
auto TT = gcnew CppSharp::AST::TagType();
TT->Declaration = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false);
return TT;
Ty = TT;
break;
}
case Type::Paren:
{
auto PT = Type->getAs<clang::ParenType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
return WalkType(PT->getInnerType(), &Next);
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
Ty = WalkType(PT->getInnerType(), &Next);
break;
}
case Type::ConstantArray:
{
auto AT = AST->getAsConstantArrayType(QualType);
auto A = gcnew CppSharp::AST::ArrayType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = gcnew CppSharp::AST::ArrayType();
A->Type = WalkType(AT->getElementType(), &Next);
A->SizeType = CppSharp::AST::ArrayType::ArraySize::Constant;
A->Size = AST->getConstantArrayElementCount(AT);
return A;
Ty = A;
break;
}
case Type::IncompleteArray:
{
auto AT = AST->getAsIncompleteArrayType(QualType);
auto A = gcnew CppSharp::AST::ArrayType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = gcnew CppSharp::AST::ArrayType();
A->Type = WalkType(AT->getElementType(), &Next);
A->SizeType = CppSharp::AST::ArrayType::ArraySize::Incomplete;
return A;
Ty = A;
break;
}
case Type::DependentSizedArray:
{
auto AT = AST->getAsDependentSizedArrayType(QualType);
auto A = gcnew CppSharp::AST::ArrayType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto A = gcnew CppSharp::AST::ArrayType();
A->Type = WalkType(AT->getElementType(), &Next);
A->SizeType = CppSharp::AST::ArrayType::ArraySize::Dependent;
//A->Size = AT->getSizeExpr();
return A;
Ty = A;
break;
}
case Type::FunctionProto:
{
auto FP = Type->getAs<clang::FunctionProtoType>();
auto FTL = TL->getAs<FunctionProtoTypeLoc>();
auto RL = FTL.getResultLoc();
FunctionProtoTypeLoc FTL;
TypeLoc RL;
if (TL && !TL->isNull())
{
FTL = TL->getAs<FunctionProtoTypeLoc>();
RL = FTL.getResultLoc();
}
auto F = gcnew CppSharp::AST::FunctionType();
F->ReturnType = GetQualifiedType(FP->getResultType(),
@ -1375,28 +1401,34 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1375,28 +1401,34 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
F->Parameters->Add(FA);
}
return F;
Ty = F;
break;
}
case Type::TypeOf:
{
auto TO = Type->getAs<clang::TypeOfType>();
return WalkType(TO->getUnderlyingType());
Ty = WalkType(TO->getUnderlyingType());
break;
}
case Type::TypeOfExpr:
{
auto TO = Type->getAs<clang::TypeOfExprType>();
return WalkType(TO->getUnderlyingExpr()->getType());
Ty = WalkType(TO->getUnderlyingExpr()->getType());
break;
}
case Type::MemberPointer:
{
auto MP = Type->getAs<clang::MemberPointerType>();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto MPT = gcnew CppSharp::AST::MemberPointerType();
MPT->Pointee = WalkType(MP->getPointeeType(), &Next);
return MPT;
Ty = MPT;
break;
}
case Type::TemplateSpecialization:
{
@ -1473,7 +1505,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1473,7 +1505,8 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
TST->Arguments->Add(Arg);
}
return TST;
Ty = TST;
break;
}
case Type::TemplateTypeParm:
{
@ -1484,19 +1517,22 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1484,19 +1517,22 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
if (auto Ident = TP->getIdentifier())
TPT->Parameter.Name = marshalString<E_UTF8>(Ident->getName());
return TPT;
Ty = TPT;
break;
}
case Type::SubstTemplateTypeParm:
{
auto TP = Type->getAs<SubstTemplateTypeParmType>();
auto Ty = TP->getReplacementType();
auto TPT = gcnew CppSharp::AST::TemplateParameterSubstitutionType();
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
TPT->Replacement = GetQualifiedType(Ty, WalkType(Ty, &Next));
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto RepTy = TP->getReplacementType();
TPT->Replacement = GetQualifiedType(RepTy, WalkType(RepTy, &Next));
return TPT;
Ty = TPT;
break;
}
case Type::InjectedClassName:
{
@ -1504,13 +1540,17 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1504,13 +1540,17 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
auto ICNT = gcnew CppSharp::AST::InjectedClassNameType();
ICNT->Class = safe_cast<CppSharp::AST::Class^>(WalkDeclaration(
ICN->getDecl(), 0, /*IgnoreSystemDecls=*/false));
return ICNT;
Ty = ICNT;
break;
}
case Type::DependentName:
{
auto DN = Type->getAs<DependentNameType>();
auto DNT = gcnew CppSharp::AST::DependentNameType();
return DNT;
Ty = DNT;
break;
}
case Type::LValueReference:
{
@ -1520,12 +1560,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1520,12 +1560,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
P->Modifier = CppSharp::AST::PointerType::TypeModifier::LVReference;
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Pointee = LR->getPointeeType();
P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
Ty = P;
break;
}
case Type::RValueReference:
{
@ -1535,12 +1576,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1535,12 +1576,13 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
P->Modifier = CppSharp::AST::PointerType::TypeModifier::RVReference;
TypeLoc Next;
if (!TL->isNull()) Next = TL->getNextTypeLoc();
if (TL && !TL->isNull()) Next = TL->getNextTypeLoc();
auto Pointee = LR->getPointeeType();
P->QualifiedPointee = GetQualifiedType(Pointee, WalkType(Pointee, &Next));
return P;
Ty = P;
break;
}
case Type::Vector:
{
@ -1557,6 +1599,9 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* @@ -1557,6 +1599,9 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
Debug("Unhandled type class '%s'\n", Type->getTypeClassName());
return nullptr;
} }
Ty->IsDependent = Type->isDependentType();
return Ty;
}
//-----------------------------------//

Loading…
Cancel
Save