12 #include "clang/Sema/Sema.h"
13 #include "cling/Utils/ParserStateRAII.h"
14 #include "clang/Lex/Preprocessor.h"
22 struct ParsingStateRAII {
23 struct SemaExprCleanupsRAII {
24 decltype(clang::Sema::Cleanup) fCleanup;
25 decltype(clang::Sema::ExprCleanupObjects) fExprCleanupObjects;
26 decltype(clang::Sema::MaybeODRUseExprs) fMaybeODRUseExprs;
27 decltype(clang::Sema::FunctionScopes) fFunctionScopes;
28 decltype(clang::Sema::UndefinedButUsed) fUndefinedButUsed;
31 std::swap(fCleanup, fSema.Cleanup);
32 std::swap(fExprCleanupObjects, fSema.ExprCleanupObjects);
33 std::swap(fMaybeODRUseExprs, fSema.MaybeODRUseExprs);
34 std::swap(fFunctionScopes, fSema.FunctionScopes);
35 std::swap(fUndefinedButUsed, fSema.UndefinedButUsed);
37 SemaExprCleanupsRAII(clang::Sema& S): fSema(S) {
38 fFunctionScopes.push_back(
new clang::sema::FunctionScopeInfo(S.Diags));
41 ~SemaExprCleanupsRAII() {
43 assert(fFunctionScopes.size() == 1 &&
"Expected only my FunctionScopeInfo.");
44 delete fFunctionScopes.back();
48 struct SemaParsingInitForAutoVarsRAII {
49 using PIFAV_t = decltype(clang::Sema::ParsingInitForAutoVars);
52 SemaParsingInitForAutoVarsRAII(PIFAV_t& PIFAV): fSemaPIFAV(PIFAV) {
53 fSavedPIFAV.swap(PIFAV);
55 ~SemaParsingInitForAutoVarsRAII() {
56 fSavedPIFAV.swap(fSemaPIFAV);
60 clang::Preprocessor::CleanupAndRestoreCacheRAII fCleanupRAII;
61 clang::Parser::ParserCurTokRestoreRAII fSavedCurToken;
62 cling::ParserStateRAII fParserRAII;
65 clang::Sema::DelayedInfoRAII fSemaInfoRAII;
67 SemaExprCleanupsRAII fSemaExprCleanupsRAII;
73 clang::Sema::ContextAndScopeRAII fPushedDCAndS;
75 SemaParsingInitForAutoVarsRAII fSemaParsingInitForAutoVarsRAII;
77 clang::Sema::SavePendingInstantiationsRAII fPendingInstantiations;
80 ParsingStateRAII(clang::Parser& parser, clang::Sema& sema):
81 fCleanupRAII(sema.getPreprocessor()),
82 fSavedCurToken(parser),
83 fParserRAII(parser, false ),
84 fSemaInfoRAII(sema), fSemaExprCleanupsRAII(sema),
85 fPushedDCAndS(sema, sema.getASTContext().getTranslationUnitDecl(),
87 fSemaParsingInitForAutoVarsRAII(sema.ParsingInitForAutoVars),
88 fPendingInstantiations(sema)
92 clang::Token& Tok =
const_cast<clang::Token&
>(parser.getCurToken());
93 Tok.setKind(clang::tok::semi);