Expand StartParsingRAII

In particular the CachedTokens need to be pushed/pop or otherwise
give misleading information.

This fixes ROOT-10224.
This commit is contained in:
Philippe Canal 2019-09-06 11:02:07 -05:00 committed by SFT
parent 1a53d8241d
commit 8b906da196
2 changed files with 20 additions and 6 deletions

View File

@ -47,6 +47,9 @@ namespace cling {
ParserStateRAII(clang::Parser& p, bool skipToEOF);
~ParserStateRAII();
void SetSkipToEOF(bool newvalue) {
SkipToEOF = newvalue;
}
};
} // end namespace cling

View File

@ -38,6 +38,13 @@ 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);
@ -45,9 +52,11 @@ namespace cling {
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);
}
@ -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,
@ -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);
@ -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.