forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ParserStateRAII into Utils/. We need it in other places.
- Loading branch information
1 parent
6f16264
commit 2e4cf96
Showing
4 changed files
with
114 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//--------------------------------------------------------------------*- C++ -*- | ||
// CLING - the C++ LLVM-based InterpreterG :) | ||
// author: Vassil Vassilev <[email protected]> | ||
// | ||
// This file is dual-licensed: you can choose to license it under the University | ||
// of Illinois Open Source License or the GNU Lesser General Public License. See | ||
// LICENSE.TXT for details. | ||
//------------------------------------------------------------------------------ | ||
|
||
#ifndef CLING_UTILS_ParserStateRAII_H | ||
#define CLING_UTILS_ParserStateRAII_H | ||
|
||
#include "clang/Basic/SourceLocation.h" | ||
#include "clang/Parse/Parser.h" | ||
|
||
namespace clang { | ||
class Preprocessor; | ||
} | ||
|
||
namespace cling { | ||
///\brief Cleanup Parser state after a failed lookup. | ||
/// | ||
/// After a failed lookup we need to discard the remaining unparsed input, | ||
/// restore the original state of the incremental parsing flag, clear any | ||
/// pending diagnostics, restore the suppress diagnostics flag, and restore | ||
/// the spell checking language options. | ||
/// | ||
class ParserStateRAII { | ||
private: | ||
clang::Parser* P; | ||
clang::Preprocessor& PP; | ||
decltype(clang::Parser::TemplateIds) OldTemplateIds; | ||
bool ResetIncrementalProcessing; | ||
bool OldSuppressAllDiagnostics; | ||
bool OldPPSuppressAllDiagnostics; | ||
bool OldSpellChecking; | ||
clang::SourceLocation OldPrevTokLocation; | ||
unsigned short OldParenCount, OldBracketCount, OldBraceCount; | ||
unsigned OldTemplateParameterDepth; | ||
bool OldInNonInstantiationSFINAEContext; | ||
|
||
public: | ||
ParserStateRAII(clang::Parser& p); | ||
~ParserStateRAII(); | ||
|
||
}; | ||
|
||
} // end namespace cling | ||
#endif // CLING_UTILS_ParserStateRAII_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//------------------------------------------------------------------------------ | ||
// CLING - the C++ LLVM-based InterpreterG :) | ||
// author: Vassil Vassilev <[email protected]> | ||
// | ||
// This file is dual-licensed: you can choose to license it under the University | ||
// of Illinois Open Source License or the GNU Lesser General Public License. See | ||
// LICENSE.TXT for details. | ||
//------------------------------------------------------------------------------ | ||
|
||
#include "cling/Utils/ParserStateRAII.h" | ||
|
||
#include "clang/Parse/RAIIObjectsForParser.h" | ||
|
||
using namespace clang; | ||
|
||
cling::ParserStateRAII::ParserStateRAII(Parser& p) | ||
: P(&p), PP(p.getPreprocessor()), | ||
ResetIncrementalProcessing(p.getPreprocessor() | ||
.isIncrementalProcessingEnabled()), | ||
OldSuppressAllDiagnostics(P->getActions().getDiagnostics() | ||
.getSuppressAllDiagnostics()), | ||
OldPPSuppressAllDiagnostics(p.getPreprocessor().getDiagnostics() | ||
.getSuppressAllDiagnostics()), | ||
OldSpellChecking(p.getPreprocessor().getLangOpts().SpellChecking), | ||
OldPrevTokLocation(p.PrevTokLocation), | ||
OldParenCount(p.ParenCount), OldBracketCount(p.BracketCount), | ||
OldBraceCount(p.BraceCount), | ||
OldTemplateParameterDepth(p.TemplateParameterDepth), | ||
OldInNonInstantiationSFINAEContext(P->getActions() | ||
.InNonInstantiationSFINAEContext) | ||
{ | ||
OldTemplateIds.swap(P->TemplateIds); | ||
} | ||
|
||
cling::ParserStateRAII::~ParserStateRAII() { | ||
// | ||
// Advance the parser to the end of the file, and pop the include stack. | ||
// | ||
// Note: Consuming the EOF token will pop the include stack. | ||
// | ||
{ | ||
// Cleanup the TemplateIds before swapping the previous set back. | ||
DestroyTemplateIdAnnotationsRAIIObj CleanupTemplateIds(*P); | ||
} | ||
P->TemplateIds.swap(OldTemplateIds); | ||
P->SkipUntil(tok::eof); | ||
PP.enableIncrementalProcessing(ResetIncrementalProcessing); | ||
// Doesn't reset the diagnostic mappings | ||
P->getActions().getDiagnostics().Reset(/*soft=*/true); | ||
P->getActions().getDiagnostics().setSuppressAllDiagnostics(OldSuppressAllDiagnostics); | ||
PP.getDiagnostics().Reset(/*soft=*/true); | ||
PP.getDiagnostics().setSuppressAllDiagnostics(OldPPSuppressAllDiagnostics); | ||
const_cast<LangOptions&>(PP.getLangOpts()).SpellChecking = | ||
OldSpellChecking; | ||
|
||
P->PrevTokLocation = OldPrevTokLocation; | ||
P->ParenCount = OldParenCount; | ||
P->BracketCount = OldBracketCount; | ||
P->BraceCount = OldBraceCount; | ||
P->TemplateParameterDepth = OldTemplateParameterDepth; | ||
P->getActions().InNonInstantiationSFINAEContext = | ||
OldInNonInstantiationSFINAEContext; | ||
} |