Split ParserStateRAII into Utils/. We need it in other places.
This commit is contained in:
parent
432c91f534
commit
3847e2560d
49
include/cling/Utils/ParserStateRAII.h
Normal file
49
include/cling/Utils/ParserStateRAII.h
Normal file
@ -0,0 +1,49 @@
|
||||
//--------------------------------------------------------------------*- C++ -*-
|
||||
// CLING - the C++ LLVM-based InterpreterG :)
|
||||
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
|
||||
//
|
||||
// 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
|
@ -12,6 +12,7 @@
|
||||
#include "DeclUnloader.h"
|
||||
#include "cling/Interpreter/Interpreter.h"
|
||||
#include "cling/Utils/AST.h"
|
||||
#include "cling/Utils/ParserStateRAII.h"
|
||||
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
@ -26,82 +27,6 @@
|
||||
|
||||
using namespace clang;
|
||||
|
||||
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:
|
||||
Parser* P;
|
||||
Preprocessor& PP;
|
||||
decltype(Parser::TemplateIds) OldTemplateIds;
|
||||
bool ResetIncrementalProcessing;
|
||||
bool OldSuppressAllDiagnostics;
|
||||
bool OldPPSuppressAllDiagnostics;
|
||||
bool OldSpellChecking;
|
||||
SourceLocation OldPrevTokLocation;
|
||||
unsigned short OldParenCount, OldBracketCount, OldBraceCount;
|
||||
unsigned OldTemplateParameterDepth;
|
||||
bool OldInNonInstantiationSFINAEContext;
|
||||
|
||||
public:
|
||||
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);
|
||||
}
|
||||
|
||||
~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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace cling {
|
||||
///\brief Class to help with the custom allocation of clang::Expr
|
||||
///
|
||||
|
@ -11,6 +11,7 @@ set( LLVM_LINK_COMPONENTS
|
||||
|
||||
add_cling_library(clingUtils OBJECT
|
||||
AST.cpp
|
||||
ParserStateRAII.cpp
|
||||
Paths.cpp
|
||||
PlatformMac.cpp
|
||||
PlatformPosix.cpp
|
||||
|
63
lib/Utils/ParserStateRAII.cpp
Normal file
63
lib/Utils/ParserStateRAII.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// CLING - the C++ LLVM-based InterpreterG :)
|
||||
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
|
||||
//
|
||||
// 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user