cling/patches/clang_root_autoloading.diff
Vassil Vassilev 4761e31353 The patch has to be relative to llvm/src.
git-svn-id: http://root.cern.ch/svn/root/trunk@47368 27541ba8-7e3a-0410-8455-c3a389f83636
2012-11-16 16:24:09 +00:00

163 lines
5.1 KiB
Diff

Index: tools/clang/include/clang/Sema/Sema.h
===================================================================
--- tools/clang/include/clang/Sema/Sema.h (revision 47284)
+++ tools/clang/include/clang/Sema/Sema.h (working copy)
@@ -466,6 +466,41 @@
}
};
+ /// A RAII object to temporarily push a decl context and scope.
+ class ContextAndScopeRAII {
+ private:
+ Sema &S;
+ DeclContext *SavedContext;
+ Scope *SavedScope;
+ ProcessingContextState SavedContextState;
+ QualType SavedCXXThisTypeOverride;
+
+ public:
+ ContextAndScopeRAII(Sema &S, DeclContext *ContextToPush, Scope *ScopeToPush)
+ : S(S), SavedContext(S.CurContext), SavedScope(S.CurScope),
+ SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
+ SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
+ {
+ assert(ContextToPush && "pushing null context");
+ S.CurContext = ContextToPush;
+ S.CurScope = ScopeToPush;
+ }
+
+ void pop() {
+ if (!SavedContext) return;
+ S.CurContext = SavedContext;
+ S.CurScope = SavedScope;
+ S.DelayedDiagnostics.popUndelayed(SavedContextState);
+ S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
+ SavedContext = 0;
+ SavedScope = 0;
+ }
+
+ ~ContextAndScopeRAII() {
+ pop();
+ }
+ };
+
/// WeakUndeclaredIdentifiers - Identifiers contained in
/// \#pragma weak before declared. rare. may alias another
/// identifier, declared or undeclared
Index: tools/clang/include/clang/Lex/Preprocessor.h
===================================================================
--- tools/clang/include/clang/Lex/Preprocessor.h (revision 47284)
+++ tools/clang/include/clang/Lex/Preprocessor.h (working copy)
@@ -623,6 +623,72 @@
void EnterTokenStream(const Token *Toks, unsigned NumToks,
bool DisableMacroExpansion, bool OwnsTokens);
+ /// A RAII object to temporarily reset PP's state and restore it.
+ class CleanupAndRestoreCacheRAII {
+ private:
+ Preprocessor &PP;
+ CachedTokensTy::size_type SavedCachedLexPos;
+ CachedTokensTy SavedCachedTokens;
+ std::vector<IncludeStackInfo> SavedStack;
+ Lexer *SavedCurLexer;
+ PTHLexer *SavedCurPTHLexer;
+ PreprocessorLexer *SavedCurPPLexer;
+ TokenLexer* SavedCurTokenLexer;
+ const DirectoryLookup *SavedCurDirLookup;
+ enum CurLexerKind SavedCurLexerKind;
+
+ public:
+ CleanupAndRestoreCacheRAII(Preprocessor &PP)
+ : PP(PP), SavedCachedLexPos(PP.CachedLexPos),
+ SavedCachedTokens(PP.CachedTokens), SavedStack(PP.IncludeMacroStack),
+ SavedCurLexer(PP.CurLexer.take()),
+ SavedCurPTHLexer(PP.CurPTHLexer.take()),
+ SavedCurPPLexer(PP.CurPPLexer),
+ SavedCurTokenLexer(PP.CurTokenLexer.take()),
+ SavedCurDirLookup(PP.CurDirLookup),
+ SavedCurLexerKind(PP.CurLexerKind)
+ {
+ PP.CachedLexPos = 0;
+ PP.CachedTokens.clear();
+ PP.IncludeMacroStack.clear();
+ PP.CurLexer.reset(0);
+ PP.CurPTHLexer.reset(0);
+ PP.CurPPLexer = 0;
+ PP.CurTokenLexer.reset(0);
+ PP.CurDirLookup = 0;
+ PP.CurLexerKind = CLK_CachingLexer;
+ }
+
+ void pop() {
+ if (SavedCurLexerKind == (enum CurLexerKind)~0U)
+ return;
+
+ PP.CachedLexPos = SavedCachedLexPos;
+ PP.CachedTokens = SavedCachedTokens;
+ PP.IncludeMacroStack = SavedStack;
+ PP.CurLexer.reset(SavedCurLexer);
+ PP.CurPTHLexer.reset(SavedCurPTHLexer);
+ PP.CurPPLexer = SavedCurPPLexer;
+ PP.CurTokenLexer.reset(SavedCurTokenLexer);
+ PP.CurDirLookup = SavedCurDirLookup;
+ PP.CurLexerKind = SavedCurLexerKind;
+
+ SavedCachedLexPos = 0;
+ SavedCachedTokens.clear();
+ SavedStack.clear();
+ SavedCurLexer = 0;
+ SavedCurPTHLexer = 0;
+ SavedCurPPLexer = 0;
+ SavedCurTokenLexer = 0;
+ SavedCurDirLookup = 0;
+ SavedCurLexerKind = (enum CurLexerKind)~0U;
+ }
+
+ ~CleanupAndRestoreCacheRAII() {
+ pop();
+ }
+ };
+
/// RemoveTopOfLexerStack - Pop the current lexer/macro exp off the top of the
/// lexer stack. This should only be used in situations where the current
/// state of the top-of-stack lexer is known.
Index: tools/clang/include/clang/Parse/Parser.h
===================================================================
--- tools/clang/include/clang/Parse/Parser.h (revision 47327)
+++ tools/clang/include/clang/Parse/Parser.h (working copy)
@@ -236,6 +236,34 @@
AttributeFactory &getAttrFactory() { return AttrFactory; }
const Token &getCurToken() const { return Tok; }
+
+ /// A RAII object to temporarily reset PP's state and restore it.
+ class ParserCurTokRestoreRAII {
+ private:
+ Parser &P;
+ Token SavedTok;
+
+ public:
+ ParserCurTokRestoreRAII(Parser &P)
+ : P(P), SavedTok(P.Tok)
+ {
+ }
+
+ void pop() {
+ if (SavedTok.is(tok::unknown))
+ return;
+
+ P.Tok = SavedTok;
+
+ SavedTok.startToken();
+ }
+
+ ~ParserCurTokRestoreRAII() {
+ pop();
+ }
+ };
+
+
Scope *getCurScope() const { return Actions.getCurScope(); }
Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }