cling/patches/clang_multi_parsers.diff
2012-11-15 00:08:23 +00:00

220 lines
7.7 KiB
Diff

Index: tools/clang/include/clang/Parse/Parser.h
===================================================================
--- tools/clang/include/clang/Parse/Parser.h (revision 47284)
+++ tools/clang/include/clang/Parse/Parser.h (working copy)
@@ -223,8 +223,10 @@
bool SkipFunctionBodies;
+ bool IsTemporary;
public:
- Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies);
+ Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies,
+ bool isTemp = false);
~Parser();
const LangOptions &getLangOpts() const { return PP.getLangOpts(); }
@@ -720,7 +722,7 @@
return Diag(Tok, DiagID);
}
-private:
+protected:
void SuggestParentheses(SourceLocation Loc, unsigned DK,
SourceRange ParenRange);
void CheckNestedObjCContexts(SourceLocation AtLoc);
Index: tools/clang/lib/Lex/Pragma.cpp
===================================================================
--- tools/clang/lib/Lex/Pragma.cpp (revision 47284)
+++ tools/clang/lib/Lex/Pragma.cpp (working copy)
@@ -890,9 +890,11 @@
}
// Check to make sure we don't already have a pragma for this identifier.
- assert(!InsertNS->FindHandler(Handler->getName()) &&
- "Pragma handler already exists for this identifier!");
- InsertNS->AddPragma(Handler);
+ // assert(!InsertNS->FindHandler(Handler->getName()) &&
+ // "Pragma handler already exists for this identifier!");
+
+ if (!InsertNS->FindHandler(Handler->getName()))
+ InsertNS->AddPragma(Handler);
}
/// RemovePragmaHandler - Remove the specific pragma handler from the
Index: tools/clang/lib/Parse/Parser.cpp
===================================================================
--- tools/clang/lib/Parse/Parser.cpp (revision 47284)
+++ tools/clang/lib/Parse/Parser.cpp (working copy)
@@ -47,13 +47,16 @@
return Ident__except;
}
-Parser::Parser(Preprocessor &pp, Sema &actions, bool SkipFunctionBodies)
+Parser::Parser(Preprocessor &pp, Sema &actions, bool SkipFunctionBodies,
+ bool isTemporary /*=false*/)
: PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
GreaterThanIsOperator(true), ColonIsSacred(false),
InMessageExpression(false), TemplateParameterDepth(0),
- ParsingInObjCContainer(false), SkipFunctionBodies(SkipFunctionBodies) {
+ ParsingInObjCContainer(false), SkipFunctionBodies(SkipFunctionBodies),
+ IsTemporary(isTemporary) {
Tok.setKind(tok::eof);
- Actions.CurScope = 0;
+ if (!IsTemporary)
+ Actions.CurScope = 0;
NumCachedScopes = 0;
ParenCount = BracketCount = BraceCount = 0;
CurParsedObjCImpl = 0;
@@ -61,43 +64,56 @@
// Add #pragma handlers. These are removed and destroyed in the
// destructor.
AlignHandler.reset(new PragmaAlignHandler(actions));
- PP.AddPragmaHandler(AlignHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(AlignHandler.get());
GCCVisibilityHandler.reset(new PragmaGCCVisibilityHandler(actions));
- PP.AddPragmaHandler("GCC", GCCVisibilityHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler("GCC", GCCVisibilityHandler.get());
OptionsHandler.reset(new PragmaOptionsHandler(actions));
- PP.AddPragmaHandler(OptionsHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(OptionsHandler.get());
PackHandler.reset(new PragmaPackHandler(actions));
- PP.AddPragmaHandler(PackHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(PackHandler.get());
MSStructHandler.reset(new PragmaMSStructHandler(actions));
- PP.AddPragmaHandler(MSStructHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(MSStructHandler.get());
UnusedHandler.reset(new PragmaUnusedHandler(actions));
- PP.AddPragmaHandler(UnusedHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(UnusedHandler.get());
WeakHandler.reset(new PragmaWeakHandler(actions));
- PP.AddPragmaHandler(WeakHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(WeakHandler.get());
RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler(actions));
- PP.AddPragmaHandler(RedefineExtnameHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler(RedefineExtnameHandler.get());
FPContractHandler.reset(new PragmaFPContractHandler(actions));
- PP.AddPragmaHandler("STDC", FPContractHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler("STDC", FPContractHandler.get());
if (getLangOpts().OpenCL) {
OpenCLExtensionHandler.reset(new PragmaOpenCLExtensionHandler(actions));
- PP.AddPragmaHandler("OPENCL", OpenCLExtensionHandler.get());
-
- PP.AddPragmaHandler("OPENCL", FPContractHandler.get());
+ if (!IsTemporary)
+ PP.AddPragmaHandler("OPENCL", OpenCLExtensionHandler.get());
+
+ if (!IsTemporary)
+ PP.AddPragmaHandler("OPENCL", FPContractHandler.get());
}
CommentSemaHandler.reset(new ActionCommentHandler(actions));
- PP.addCommentHandler(CommentSemaHandler.get());
+ if (!IsTemporary)
+ PP.addCommentHandler(CommentSemaHandler.get());
- PP.setCodeCompletionHandler(*this);
+ if (!IsTemporary)
+ PP.setCodeCompletionHandler(*this);
}
/// If a crash happens while the parser is active, print out a line indicating
@@ -413,9 +429,11 @@
Parser::~Parser() {
// If we still have scopes active, delete the scope tree.
- delete getCurScope();
- Actions.CurScope = 0;
-
+ if (!IsTemporary) {
+ delete getCurScope();
+ Actions.CurScope = 0;
+ }
+
// Free the scope cache.
for (unsigned i = 0, e = NumCachedScopes; i != e; ++i)
delete ScopeCache[i];
@@ -425,36 +443,38 @@
it != LateParsedTemplateMap.end(); ++it)
delete it->second;
- // Remove the pragma handlers we installed.
- PP.RemovePragmaHandler(AlignHandler.get());
- AlignHandler.reset();
- PP.RemovePragmaHandler("GCC", GCCVisibilityHandler.get());
- GCCVisibilityHandler.reset();
- PP.RemovePragmaHandler(OptionsHandler.get());
- OptionsHandler.reset();
- PP.RemovePragmaHandler(PackHandler.get());
- PackHandler.reset();
- PP.RemovePragmaHandler(MSStructHandler.get());
- MSStructHandler.reset();
- PP.RemovePragmaHandler(UnusedHandler.get());
- UnusedHandler.reset();
- PP.RemovePragmaHandler(WeakHandler.get());
- WeakHandler.reset();
- PP.RemovePragmaHandler(RedefineExtnameHandler.get());
- RedefineExtnameHandler.reset();
+ if (!IsTemporary) {
+ // Remove the pragma handlers we installed.
+ PP.RemovePragmaHandler(AlignHandler.get());
+ AlignHandler.reset();
+ PP.RemovePragmaHandler("GCC", GCCVisibilityHandler.get());
+ GCCVisibilityHandler.reset();
+ PP.RemovePragmaHandler(OptionsHandler.get());
+ OptionsHandler.reset();
+ PP.RemovePragmaHandler(PackHandler.get());
+ PackHandler.reset();
+ PP.RemovePragmaHandler(MSStructHandler.get());
+ MSStructHandler.reset();
+ PP.RemovePragmaHandler(UnusedHandler.get());
+ UnusedHandler.reset();
+ PP.RemovePragmaHandler(WeakHandler.get());
+ WeakHandler.reset();
+ PP.RemovePragmaHandler(RedefineExtnameHandler.get());
+ RedefineExtnameHandler.reset();
- if (getLangOpts().OpenCL) {
- PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get());
- OpenCLExtensionHandler.reset();
- PP.RemovePragmaHandler("OPENCL", FPContractHandler.get());
- }
+ if (getLangOpts().OpenCL) {
+ PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get());
+ OpenCLExtensionHandler.reset();
+ PP.RemovePragmaHandler("OPENCL", FPContractHandler.get());
+ }
- PP.RemovePragmaHandler("STDC", FPContractHandler.get());
- FPContractHandler.reset();
+ PP.RemovePragmaHandler("STDC", FPContractHandler.get());
+ FPContractHandler.reset();
- PP.removeCommentHandler(CommentSemaHandler.get());
+ PP.removeCommentHandler(CommentSemaHandler.get());
- PP.clearCodeCompletionHandler();
+ PP.clearCodeCompletionHandler();
+ }
assert(TemplateIds.empty() && "Still alive TemplateIdAnnotations around?");
}