Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expand StartParsingRAII
In particular the CachedTokens need to be pushed/pop or otherwise
give misleading information.

This fixes ROOT-10224.
  • Loading branch information
pcanal committed Sep 6, 2019
commit efa1c7799358656f61909bbc39af6da60316fa36
3 changes: 3 additions & 0 deletions interpreter/cling/include/cling/Utils/ParserStateRAII.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace cling {
ParserStateRAII(clang::Parser& p, bool skipToEOF);
~ParserStateRAII();

void SetSkipToEOF(bool newvalue) {
SkipToEOF = newvalue;
}
};

} // end namespace cling
Expand Down
23 changes: 17 additions & 6 deletions interpreter/cling/lib/Interpreter/LookupHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,25 @@ namespace cling {
class StartParsingRAII {
LookupHelper& m_LH;
llvm::SaveAndRestore<bool> SaveIsRecursivelyRunning;
// Save and restore the state of the Parser and lexer.
// Note: ROOT::Internal::ParsingStateRAII also save and restore the state of Sema,
// including pending instantiation for example. It is not clear whether we need
// to do so here too or whether we need to also see the "on-going" semantic information ...
// For now, we leave Sema untouched.
clang::Preprocessor::CleanupAndRestoreCacheRAII fCleanupRAII;
clang::Parser::ParserCurTokRestoreRAII fSavedCurToken;
ParserStateRAII ResetParserState;
void prepareForParsing(llvm::StringRef code, llvm::StringRef bufferName,
LookupHelper::DiagSetting diagOnOff);
public:
StartParsingRAII(LookupHelper& LH, llvm::StringRef code,
llvm::StringRef bufferName,
LookupHelper::DiagSetting diagOnOff)
: m_LH(LH), SaveIsRecursivelyRunning(LH.IsRecursivelyRunning),
ResetParserState(*LH.m_Parser.get(),
!LH.IsRecursivelyRunning /*skipToEOF*/) {
: m_LH(LH), SaveIsRecursivelyRunning(LH.IsRecursivelyRunning)
, fCleanupRAII(LH.m_Parser.get()->getPreprocessor())
, fSavedCurToken(*LH.m_Parser.get())
, ResetParserState(*LH.m_Parser.get(), !LH.IsRecursivelyRunning /*skipToEOF*/)
{
LH.IsRecursivelyRunning = true;
prepareForParsing(code, bufferName, diagOnOff);
}
Expand Down Expand Up @@ -1237,7 +1246,8 @@ namespace cling {
llvm::StringRef funcName,
Interpreter* Interp,
UnqualifiedId &FuncId,
LookupHelper::DiagSetting diagOnOff) {
LookupHelper::DiagSetting diagOnOff,
ParserStateRAII &ResetParserState) {

// Use a very simple parse step that dectect whether the name search (which
// is already supposed to be an unqualified name) is a simple identifier,
Expand Down Expand Up @@ -1336,6 +1346,7 @@ namespace cling {
// Create a fake file to parse the function name.
//
// FIXME:, TODO: Cleanup that complete mess.
ResetParserState.SetSkipToEOF(true);
{
PP.getDiagnostics().setSuppressAllDiagnostics(diagOnOff ==
LookupHelper::NoDiagnostics);
Expand Down Expand Up @@ -1410,9 +1421,9 @@ namespace cling {
S.EnterDeclaratorContext(P.getCurScope(), foundDC);

UnqualifiedId FuncId;
ParserStateRAII ResetParserState(P, true /*skipToEOF*/);
ParserStateRAII ResetParserState(P, false /*skipToEOF*/);
if (!ParseWithShortcuts(foundDC, Context, funcName, Interp,
FuncId, diagOnOff)) {
FuncId, diagOnOff, ResetParserState)) {
// Failed parse, cleanup.
// Destroy the scope we created first, and
// restore the original.
Expand Down