diff --git a/src/CppParser/CppParser.cpp b/src/CppParser/CppParser.cpp index 22bcc664..91008bfe 100644 --- a/src/CppParser/CppParser.cpp +++ b/src/CppParser/CppParser.cpp @@ -32,6 +32,7 @@ DEF_STRING(ParserTargetInfo, ABI) ParserResult::ParserResult() : ASTContext(0) , Library(0) + , Parser(0) { } @@ -40,8 +41,14 @@ ParserResult::ParserResult(const ParserResult& rhs) , Diagnostics(rhs.Diagnostics) , ASTContext(rhs.ASTContext) , Library(rhs.Library) + , Parser(rhs.Parser) {} +ParserResult::~ParserResult() +{ + delete Parser; +} + ParserDiagnostic::ParserDiagnostic() {} ParserDiagnostic::ParserDiagnostic(const ParserDiagnostic& rhs) @@ -57,6 +64,4 @@ DEF_STRING(ParserDiagnostic, Message) DEF_VECTOR(ParserResult, ParserDiagnostic, Diagnostics) - - } } \ No newline at end of file diff --git a/src/CppParser/CppParser.h b/src/CppParser/CppParser.h index 39ee504c..993b6e15 100644 --- a/src/CppParser/CppParser.h +++ b/src/CppParser/CppParser.h @@ -70,16 +70,20 @@ enum struct ParserResultKind FileNotFound }; +struct Parser; + struct CS_API ParserResult { ParserResult(); ParserResult(const ParserResult&); + ~ParserResult(); ParserResultKind Kind; VECTOR(ParserDiagnostic, Diagnostics) CppSharp::CppParser::AST::ASTContext* ASTContext; CppSharp::CppParser::AST::NativeLibrary* Library; + Parser* Parser; }; enum class SourceLocationKind diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index fc9b38bc..07f9ad9e 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -2511,11 +2511,10 @@ void Parser::HandleDiagnostics(ParserResult* res) } } -ParserResult* Parser::ParseHeader(const std::string& File) +ParserResult* Parser::ParseHeader(const std::string& File, ParserResult* res) { assert(Opts->ASTContext && "Expected a valid ASTContext"); - auto res = new ParserResult(); res->ASTContext = Lib; if (File.empty()) @@ -2677,11 +2676,8 @@ ParserResultKind Parser::ParseSharedLib(llvm::StringRef File, return ParserResultKind::Success; } - ParserResult* Parser::ParseLibrary(const std::string& File) + ParserResult* Parser::ParseLibrary(const std::string& File, ParserResult* res) { - auto res = new ParserResult(); - res->ASTContext = Lib; - if (File.empty()) { res->Kind = ParserResultKind::FileNotFound; @@ -2730,8 +2726,9 @@ ParserResult* ClangParser::ParseHeader(ParserOptions* Opts) if (!Opts) return nullptr; - Parser parser(Opts); - return parser.ParseHeader(Opts->FileName); + auto res = new ParserResult(); + res->Parser = new Parser(Opts); + return res->Parser->ParseHeader(Opts->FileName, res); } ParserResult* ClangParser::ParseLibrary(ParserOptions* Opts) @@ -2739,8 +2736,9 @@ ParserResult* ClangParser::ParseLibrary(ParserOptions* Opts) if (!Opts) return nullptr; - Parser parser(Opts); - return parser.ParseLibrary(Opts->FileName); + auto res = new ParserResult(); + res->Parser = new Parser(Opts); + return res->Parser->ParseLibrary(Opts->FileName, res); } ParserTargetInfo* ClangParser::GetTargetInfo(ParserOptions* Opts) diff --git a/src/CppParser/Parser.h b/src/CppParser/Parser.h index f13e46f4..b47690a5 100644 --- a/src/CppParser/Parser.h +++ b/src/CppParser/Parser.h @@ -48,8 +48,8 @@ struct Parser Parser(ParserOptions* Opts); void SetupHeader(); - ParserResult* ParseHeader(const std::string& File); - ParserResult* ParseLibrary(const std::string& File); + ParserResult* ParseHeader(const std::string& File, ParserResult* res); + ParserResult* ParseLibrary(const std::string& File, ParserResult* res); ParserResultKind ParseArchive(llvm::StringRef File, llvm::MemoryBuffer *Buffer, CppSharp::CppParser::NativeLibrary*& NativeLib);