Browse Source

Added a parsing option to skip gathering of native layout info.

The way we get AST layout info from Clang sometimes causes us to crash deep inside Clang.

While layout info is needed for binding C++ code, it is not usually necessary for more generalized AST consumption tasks, so add this option to make parsing code less problematic, until we are able to get the bugs tracked down.
pull/1170/head
Joao Matos 7 years ago committed by Dimitar Dobrev
parent
commit
07e3113cef
  1. 10
      src/CppParser/Bindings/CLI/CppParser.cpp
  2. 6
      src/CppParser/Bindings/CLI/CppParser.h
  3. 2012
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  4. 6
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs
  5. 2012
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  6. 6
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs
  7. 2012
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  8. 6
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs
  9. 2012
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  10. 6
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs
  11. 2012
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  12. 6
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs
  13. 2012
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  14. 6
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs
  15. 1
      src/CppParser/CppParser.cpp
  16. 1
      src/CppParser/CppParser.h
  17. 8
      src/CppParser/Parser.cpp
  18. 1
      src/CppParser/Parser.h

10
src/CppParser/Bindings/CLI/CppParser.cpp

@ -500,6 +500,16 @@ void CppSharp::Parser::CppParserOptions::SkipPrivateDeclarations::set(bool value
((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipPrivateDeclarations = value; ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipPrivateDeclarations = value;
} }
bool CppSharp::Parser::CppParserOptions::SkipLayoutInfo::get()
{
return ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipLayoutInfo;
}
void CppSharp::Parser::CppParserOptions::SkipLayoutInfo::set(bool value)
{
((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipLayoutInfo = value;
}
unsigned int CppSharp::Parser::CppParserOptions::ArgumentsCount::get() unsigned int CppSharp::Parser::CppParserOptions::ArgumentsCount::get()
{ {
auto __ret = ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->getArgumentsCount(); auto __ret = ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->getArgumentsCount();

6
src/CppParser/Bindings/CLI/CppParser.h

@ -199,6 +199,12 @@ namespace CppSharp
void set(bool); void set(bool);
} }
property bool SkipLayoutInfo
{
bool get();
void set(bool);
}
property unsigned int ArgumentsCount property unsigned int ArgumentsCount
{ {
unsigned int get(); unsigned int get();

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

File diff suppressed because it is too large Load Diff

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

@ -59,7 +59,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -758,7 +758,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -864,7 +864,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;

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

File diff suppressed because it is too large Load Diff

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

@ -29,7 +29,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -388,7 +388,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -474,7 +474,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;

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

File diff suppressed because it is too large Load Diff

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

@ -59,7 +59,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -758,7 +758,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Allocator>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -864,7 +864,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;

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

File diff suppressed because it is too large Load Diff

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

@ -33,7 +33,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -742,7 +742,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -859,7 +859,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;

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

File diff suppressed because it is too large Load Diff

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

@ -33,7 +33,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Tp>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -742,7 +742,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_CharT>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -839,7 +839,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_CharT, _Traits, _Alloc>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;

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

File diff suppressed because it is too large Load Diff

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

@ -29,7 +29,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.CharTraits<_Elem>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -388,7 +388,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.Allocator<_Ty>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;
@ -474,7 +474,7 @@ namespace Std
protected int __PointerAdjustment; protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>>(); internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::Std.BasicString<_Elem, _Traits, _Alloc>>();
protected void*[] __OriginalVTables; protected internal void*[] __OriginalVTables;
protected bool __ownsNativeInstance; protected bool __ownsNativeInstance;

1
src/CppParser/CppParser.cpp

@ -20,6 +20,7 @@ CppParserOptions::CppParserOptions()
, verbose(false) , verbose(false)
, unityBuild(false) , unityBuild(false)
, skipPrivateDeclarations(true) , skipPrivateDeclarations(true)
, skipLayoutInfo(false)
{ {
} }

1
src/CppParser/CppParser.h

@ -46,6 +46,7 @@ struct CS_API CppParserOptions
bool verbose; bool verbose;
bool unityBuild; bool unityBuild;
bool skipPrivateDeclarations; bool skipPrivateDeclarations;
bool skipLayoutInfo;
}; };
enum class ParserDiagnosticLevel enum class ParserDiagnosticLevel

8
src/CppParser/Parser.cpp

@ -869,8 +869,11 @@ static clang::CXXRecordDecl* GetCXXRecordDeclFromBaseType(const clang::QualType&
return nullptr; return nullptr;
} }
static bool HasLayout(const clang::RecordDecl* Record) bool Parser::HasLayout(const clang::RecordDecl* Record)
{ {
if (opts->skipLayoutInfo)
return false;
if (Record->isDependentType() || !Record->getDefinition() || if (Record->isDependentType() || !Record->getDefinition() ||
!IsRecordValid(Record)) !IsRecordValid(Record))
return false; return false;
@ -2325,7 +2328,8 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
A->qualifiedType = GetQualifiedType(ElemTy, &Next); A->qualifiedType = GetQualifiedType(ElemTy, &Next);
A->sizeType = ArrayType::ArraySize::Constant; A->sizeType = ArrayType::ArraySize::Constant;
A->size = AST.getConstantArrayElementCount(AT); A->size = AST.getConstantArrayElementCount(AT);
if (!ElemTy->isDependentType())
if (!ElemTy->isDependentType() && !opts->skipLayoutInfo)
A->elementSize = (long)AST.getTypeSize(ElemTy); A->elementSize = (long)AST.getTypeSize(ElemTy);
Ty = A; Ty = A;

1
src/CppParser/Parser.h

@ -140,6 +140,7 @@ private:
void HandlePreprocessedEntities(Declaration* Decl, clang::SourceRange sourceRange, void HandlePreprocessedEntities(Declaration* Decl, clang::SourceRange sourceRange,
MacroLocation macroLocation = MacroLocation::Unknown); MacroLocation macroLocation = MacroLocation::Unknown);
bool GetDeclText(clang::SourceRange SR, std::string& Text); bool GetDeclText(clang::SourceRange SR, std::string& Text);
bool HasLayout(const clang::RecordDecl* Record);
TranslationUnit* GetTranslationUnit(clang::SourceLocation Loc, TranslationUnit* GetTranslationUnit(clang::SourceLocation Loc,
SourceLocationKind *Kind = 0); SourceLocationKind *Kind = 0);

Loading…
Cancel
Save