Skip to content
Snippets Groups Projects
Commit f664d369 authored by Vassil Vassilev's avatar Vassil Vassilev
Browse files

[cling] Support recursive lookup helper calls.

The implementation of class->library mapping makes a call to the
LookupHelper::findScope. This makes the recursive invocations to
LookupHelper::findScope -> ... -> LookupHelper::findScope happen more often.
parent 67a59af9
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,8 @@ namespace cling { ...@@ -71,6 +71,8 @@ namespace cling {
unsigned m_CacheHits = 0; unsigned m_CacheHits = 0;
/// Number of times we missed the cache. /// Number of times we missed the cache.
unsigned m_TotalParseRequests = 0; unsigned m_TotalParseRequests = 0;
/// If we are called recursively.
bool IsRecursivelyRunning = false;
public: public:
LookupHelper(clang::Parser* P, Interpreter* interp); LookupHelper(clang::Parser* P, Interpreter* interp);
......
...@@ -36,6 +36,7 @@ namespace cling { ...@@ -36,6 +36,7 @@ namespace cling {
bool OldSuppressAllDiagnostics; bool OldSuppressAllDiagnostics;
bool OldPPSuppressAllDiagnostics; bool OldPPSuppressAllDiagnostics;
bool OldSpellChecking; bool OldSpellChecking;
clang::Token OldTok;
clang::SourceLocation OldPrevTokLocation; clang::SourceLocation OldPrevTokLocation;
unsigned short OldParenCount, OldBracketCount, OldBraceCount; unsigned short OldParenCount, OldBracketCount, OldBraceCount;
unsigned OldTemplateParameterDepth; unsigned OldTemplateParameterDepth;
......
...@@ -37,17 +37,20 @@ namespace cling { ...@@ -37,17 +37,20 @@ namespace cling {
class StartParsingRAII { class StartParsingRAII {
LookupHelper& m_LH; LookupHelper& m_LH;
llvm::SaveAndRestore<bool> SaveIsRecursivelyRunning;
ParserStateRAII ResetParserState; ParserStateRAII ResetParserState;
void prepareForParsing(llvm::StringRef code, llvm::StringRef bufferName, void prepareForParsing(llvm::StringRef code, llvm::StringRef bufferName,
LookupHelper::DiagSetting diagOnOff); LookupHelper::DiagSetting diagOnOff);
public: public:
StartParsingRAII(LookupHelper& LH, llvm::StringRef code, StartParsingRAII(LookupHelper& LH, llvm::StringRef code,
llvm::StringRef bufferName, llvm::StringRef bufferName,
LookupHelper::DiagSetting diagOnOff) LookupHelper::DiagSetting diagOnOff)
: m_LH(LH), ResetParserState(*LH.m_Parser.get(), true /*skipToEOF*/) { : m_LH(LH), SaveIsRecursivelyRunning(LH.IsRecursivelyRunning),
prepareForParsing(code, bufferName, diagOnOff); ResetParserState(*LH.m_Parser.get(),
} !LH.IsRecursivelyRunning /*skipToEOF*/) {
LH.IsRecursivelyRunning = true;
prepareForParsing(code, bufferName, diagOnOff);
}
~StartParsingRAII() { pop(); } ~StartParsingRAII() { pop(); }
void pop() const {} void pop() const {}
...@@ -84,7 +87,8 @@ namespace cling { ...@@ -84,7 +87,8 @@ namespace cling {
if (!PP.isIncrementalProcessingEnabled()) { if (!PP.isIncrementalProcessingEnabled()) {
PP.enableIncrementalProcessing(); PP.enableIncrementalProcessing();
} }
assert(!code.empty()&&"prepareForParsing should only be called when needd"); assert(!code.empty() &&
"prepareForParsing should only be called when need");
// Create a fake file to parse the type name. // Create a fake file to parse the type name.
FileID FID; FileID FID;
......
...@@ -24,7 +24,7 @@ cling::ParserStateRAII::ParserStateRAII(Parser& p, bool skipToEOF) ...@@ -24,7 +24,7 @@ cling::ParserStateRAII::ParserStateRAII(Parser& p, bool skipToEOF)
OldPPSuppressAllDiagnostics(p.getPreprocessor().getDiagnostics() OldPPSuppressAllDiagnostics(p.getPreprocessor().getDiagnostics()
.getSuppressAllDiagnostics()), .getSuppressAllDiagnostics()),
OldSpellChecking(p.getPreprocessor().getLangOpts().SpellChecking), OldSpellChecking(p.getPreprocessor().getLangOpts().SpellChecking),
OldPrevTokLocation(p.PrevTokLocation), OldTok(p.Tok), OldPrevTokLocation(p.PrevTokLocation),
OldParenCount(p.ParenCount), OldBracketCount(p.BracketCount), OldParenCount(p.ParenCount), OldBracketCount(p.BracketCount),
OldBraceCount(p.BraceCount), OldBraceCount(p.BraceCount),
OldTemplateParameterDepth(p.TemplateParameterDepth), OldTemplateParameterDepth(p.TemplateParameterDepth),
...@@ -54,6 +54,8 @@ cling::ParserStateRAII::~ParserStateRAII() { ...@@ -54,6 +54,8 @@ cling::ParserStateRAII::~ParserStateRAII() {
P->TemplateIds.swap(OldTemplateIds); P->TemplateIds.swap(OldTemplateIds);
if (SkipToEOF) if (SkipToEOF)
P->SkipUntil(tok::eof); P->SkipUntil(tok::eof);
else
P->Tok = OldTok;
PP.enableIncrementalProcessing(ResetIncrementalProcessing); PP.enableIncrementalProcessing(ResetIncrementalProcessing);
if (!SemaDiagHadErrors) { if (!SemaDiagHadErrors) {
// Doesn't reset the diagnostic mappings // Doesn't reset the diagnostic mappings
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment