Browse Source

Explicitly construct the parser and keep it in ParserResult.

This fixes some non-deterministic behavior in the new parser but it means we are keeping around all the memory for parsing until the end of the process. This is a bit messy right now but at least we keep the API compatible between parsers. After all the new parser bugs are squashed, this will be reworked.
pull/238/head
triton 11 years ago
parent
commit
55f4b849c7
  1. 9
      src/CppParser/CppParser.cpp
  2. 4
      src/CppParser/CppParser.h
  3. 18
      src/CppParser/Parser.cpp
  4. 4
      src/CppParser/Parser.h

9
src/CppParser/CppParser.cpp

@ -32,6 +32,7 @@ DEF_STRING(ParserTargetInfo, ABI) @@ -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) @@ -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) @@ -57,6 +64,4 @@ DEF_STRING(ParserDiagnostic, Message)
DEF_VECTOR(ParserResult, ParserDiagnostic, Diagnostics)
} }

4
src/CppParser/CppParser.h

@ -70,16 +70,20 @@ enum struct ParserResultKind @@ -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

18
src/CppParser/Parser.cpp

@ -2511,11 +2511,10 @@ void Parser::HandleDiagnostics(ParserResult* res) @@ -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, @@ -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) @@ -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) @@ -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)

4
src/CppParser/Parser.h

@ -48,8 +48,8 @@ struct Parser @@ -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);

Loading…
Cancel
Save