Browse Source

Added support for parsing function bodies (and option `SkipFunctionBodies`).

pull/1179/head
Joao Matos 6 years ago committed by João Matos
parent
commit
378c9b301e
  1. 2
      src/CppParser/AST.cpp
  2. 10
      src/CppParser/Bindings/CLI/CppParser.cpp
  3. 6
      src/CppParser/Bindings/CLI/CppParser.h
  4. 16
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  5. 16
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  6. 16
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  7. 16
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  8. 16
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  9. 16
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  10. 1
      src/CppParser/CppParser.cpp
  11. 1
      src/CppParser/CppParser.h
  12. 3
      src/CppParser/Decl.h
  13. 9
      src/CppParser/Parser.cpp

2
src/CppParser/AST.cpp

@ -565,7 +565,6 @@ Friend::Friend() : CppSharp::CppParser::AST::Declaration(DeclarationKind::Friend
Friend::~Friend() {} Friend::~Friend() {}
StatementObsolete::StatementObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl) : string(str), _class(stmtClass), decl(decl) {} StatementObsolete::StatementObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl) : string(str), _class(stmtClass), decl(decl) {}
ExpressionObsolete::ExpressionObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl) ExpressionObsolete::ExpressionObsolete(const std::string& str, StatementClassObsolete stmtClass, Declaration* decl)
@ -643,6 +642,7 @@ Function::Function()
, callingConvention(CallingConvention::Default) , callingConvention(CallingConvention::Default)
, specializationInfo(0) , specializationInfo(0)
, instantiatedFrom(0) , instantiatedFrom(0)
, bodyStmt(0)
{ {
} }

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

@ -511,6 +511,16 @@ void CppSharp::Parser::CppParserOptions::SkipLayoutInfo::set(bool value)
((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipLayoutInfo = value; ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipLayoutInfo = value;
} }
bool CppSharp::Parser::CppParserOptions::SkipFunctionBodies::get()
{
return ((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipFunctionBodies;
}
void CppSharp::Parser::CppParserOptions::SkipFunctionBodies::set(bool value)
{
((::CppSharp::CppParser::CppParserOptions*)NativePtr)->skipFunctionBodies = 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

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

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

@ -44368,6 +44368,9 @@ namespace CppSharp
[FieldOffset(150)] [FieldOffset(150)]
internal byte skipLayoutInfo; internal byte skipLayoutInfo;
[FieldOffset(151)]
internal byte skipFunctionBodies;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@ -44931,6 +44934,19 @@ namespace CppSharp
} }
} }
public bool SkipFunctionBodies
{
get
{
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipFunctionBodies != 0;
}
set
{
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipFunctionBodies = (byte) (value ? 1 : 0);
}
}
public uint ArgumentsCount public uint ArgumentsCount
{ {
get get

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

@ -44368,6 +44368,9 @@ namespace CppSharp
[FieldOffset(186)] [FieldOffset(186)]
internal byte skipLayoutInfo; internal byte skipLayoutInfo;
[FieldOffset(187)]
internal byte skipFunctionBodies;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QAE@XZ")] EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QAE@XZ")]
@ -44931,6 +44934,19 @@ namespace CppSharp
} }
} }
public bool SkipFunctionBodies
{
get
{
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipFunctionBodies != 0;
}
set
{
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipFunctionBodies = (byte) (value ? 1 : 0);
}
}
public uint ArgumentsCount public uint ArgumentsCount
{ {
get get

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

@ -44367,6 +44367,9 @@ namespace CppSharp
[FieldOffset(290)] [FieldOffset(290)]
internal byte skipLayoutInfo; internal byte skipLayoutInfo;
[FieldOffset(291)]
internal byte skipFunctionBodies;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@ -44930,6 +44933,19 @@ namespace CppSharp
} }
} }
public bool SkipFunctionBodies
{
get
{
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipFunctionBodies != 0;
}
set
{
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipFunctionBodies = (byte) (value ? 1 : 0);
}
}
public uint ArgumentsCount public uint ArgumentsCount
{ {
get get

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

@ -44367,6 +44367,9 @@ namespace CppSharp
[FieldOffset(314)] [FieldOffset(314)]
internal byte skipLayoutInfo; internal byte skipLayoutInfo;
[FieldOffset(315)]
internal byte skipFunctionBodies;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@ -44930,6 +44933,19 @@ namespace CppSharp
} }
} }
public bool SkipFunctionBodies
{
get
{
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipFunctionBodies != 0;
}
set
{
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipFunctionBodies = (byte) (value ? 1 : 0);
}
}
public uint ArgumentsCount public uint ArgumentsCount
{ {
get get

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

@ -44367,6 +44367,9 @@ namespace CppSharp
[FieldOffset(242)] [FieldOffset(242)]
internal byte skipLayoutInfo; internal byte skipLayoutInfo;
[FieldOffset(243)]
internal byte skipFunctionBodies;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")] EntryPoint="_ZN8CppSharp9CppParser16CppParserOptionsC2Ev")]
@ -44930,6 +44933,19 @@ namespace CppSharp
} }
} }
public bool SkipFunctionBodies
{
get
{
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipFunctionBodies != 0;
}
set
{
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipFunctionBodies = (byte) (value ? 1 : 0);
}
}
public uint ArgumentsCount public uint ArgumentsCount
{ {
get get

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

@ -44368,6 +44368,9 @@ namespace CppSharp
[FieldOffset(314)] [FieldOffset(314)]
internal byte skipLayoutInfo; internal byte skipLayoutInfo;
[FieldOffset(315)]
internal byte skipFunctionBodies;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QEAA@XZ")] EntryPoint="??0CppParserOptions@CppParser@CppSharp@@QEAA@XZ")]
@ -44931,6 +44934,19 @@ namespace CppSharp
} }
} }
public bool SkipFunctionBodies
{
get
{
return ((global::CppSharp.Parser.CppParserOptions.__Internal*) __Instance)->skipFunctionBodies != 0;
}
set
{
((global::CppSharp.Parser.CppParserOptions.__Internal*)__Instance)->skipFunctionBodies = (byte) (value ? 1 : 0);
}
}
public uint ArgumentsCount public uint ArgumentsCount
{ {
get get

1
src/CppParser/CppParser.cpp

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

1
src/CppParser/CppParser.h

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

3
src/CppParser/Decl.h

@ -320,6 +320,8 @@ enum class FriendKind
Undeclared Undeclared
}; };
class Stmt;
class CS_API Function : public DeclarationContext class CS_API Function : public DeclarationContext
{ {
public: public:
@ -341,6 +343,7 @@ public:
std::string mangled; std::string mangled;
std::string signature; std::string signature;
std::string body; std::string body;
Stmt* bodyStmt;
CallingConvention callingConvention; CallingConvention callingConvention;
VECTOR(Parameter*, Parameters) VECTOR(Parameter*, Parameters)
FunctionTemplateSpecialization* specializationInfo; FunctionTemplateSpecialization* specializationInfo;

9
src/CppParser/Parser.cpp

@ -3198,6 +3198,15 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
ParamStartLoc = VD->getEndLoc(); ParamStartLoc = VD->getEndLoc();
} }
if (!opts->skipFunctionBodies)
{
if (FD->hasBody())
{
if (auto Body = FD->getBody())
F->bodyStmt = WalkStatement(Body);
}
}
auto& CXXABI = codeGenTypes->getCXXABI(); auto& CXXABI = codeGenTypes->getCXXABI();
bool HasThisReturn = false; bool HasThisReturn = false;
if (auto CD = dyn_cast<CXXConstructorDecl>(FD)) if (auto CD = dyn_cast<CXXConstructorDecl>(FD))

Loading…
Cancel
Save