Logo ROOT   6.08/07
Reference Guide
ClingRAII.h
Go to the documentation of this file.
1 // @(#)root/core/meta:$Id$
2 // Author: Axel Naumann November 2016
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "clang/Sema/Sema.h"
13 #include "cling/Utils/ParserStateRAII.h"
14 #include "clang/Lex/Preprocessor.h"
15 
16 
17 namespace ROOT {
18  namespace Internal {
19 
20  ////////////////////////////////////////////////////////////////////////////////
21  /// RAII used to store Parser, Sema, Preprocessor state for recursive parsing.
24  using PIFAV_t = decltype(clang::Sema::ParsingInitForAutoVars);
27  SemaParsingInitForAutoVarsRAII(PIFAV_t& PIFAV): fSemaPIFAV(PIFAV) {
28  fSavedPIFAV.swap(PIFAV);
29  }
31  fSavedPIFAV.swap(fSemaPIFAV);
32  }
33  };
34 
35  clang::Preprocessor::CleanupAndRestoreCacheRAII fCleanupRAII;
36  clang::Parser::ParserCurTokRestoreRAII fSavedCurToken;
37  cling::ParserStateRAII fParserRAII;
38 
39  // Buffer the delayed infos when doing recursive parsing.
40  clang::Sema::DelayedInfoRAII fSemaInfoRAII;
41 
42  // We can't PushDeclContext, because we go up and the routine that pops
43  // the DeclContext assumes that we drill down always.
44  // We have to be on the global context. At that point we are in a
45  // wrapper function so the parent context must be the global.
46  clang::Sema::ContextAndScopeRAII fPushedDCAndS;
47 
49 
50  ParsingStateRAII(clang::Parser& parser, clang::Sema& sema):
51  fCleanupRAII(sema.getPreprocessor()),
52  fSavedCurToken(parser),
53  fParserRAII(parser, false /*skipToEOF*/),
54  fSemaInfoRAII(sema),
55  fPushedDCAndS(sema, sema.getASTContext().getTranslationUnitDecl(),
56  sema.TUScope),
57  fSemaParsingInitForAutoVarsRAII(sema.ParsingInitForAutoVars)
58  {
59  // After we have saved the token reset the current one to something which
60  // is safe (semi colon usually means empty decl)
61  clang::Token& Tok = const_cast<clang::Token&>(parser.getCurToken());
62  Tok.setKind(clang::tok::semi);
63  }
64  };
65 
66 }
67 }
SemaParsingInitForAutoVarsRAII fSemaParsingInitForAutoVarsRAII
Definition: ClingRAII.h:48
clang::Parser::ParserCurTokRestoreRAII fSavedCurToken
Definition: ClingRAII.h:36
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
clang::Sema::DelayedInfoRAII fSemaInfoRAII
Definition: ClingRAII.h:40
RAII used to store Parser, Sema, Preprocessor state for recursive parsing.
Definition: ClingRAII.h:22
clang::Preprocessor::CleanupAndRestoreCacheRAII fCleanupRAII
Definition: ClingRAII.h:35
clang::Sema::ContextAndScopeRAII fPushedDCAndS
Definition: ClingRAII.h:46
cling::ParserStateRAII fParserRAII
Definition: ClingRAII.h:37
ParsingStateRAII(clang::Parser &parser, clang::Sema &sema)
Definition: ClingRAII.h:50
decltype(clang::Sema::ParsingInitForAutoVars) PIFAV_t
Definition: ClingRAII.h:24