[cfe-commits] r70687 - in /cfe/trunk: include/clang/Lex/PPCallbacks.h include/clang/Lex/Preprocessor.h test/Preprocessor/depencies-and-pp.c test/Preprocessor/dependencies-and-pp.c tools/clang-cc/DependencyFile.cpp
Daniel Dunbar
daniel at zuster.org
Sun May 3 03:04:35 PDT 2009
Author: ddunbar
Date: Sun May 3 05:04:17 2009
New Revision: 70687
URL: http://llvm.org/viewvc/llvm-project?rev=70687&view=rev
Log:
PR4063, with feeling: Chain PP callbacks by default.
- This is somewhat cleaner and also fixes PR4063 for real, I had the
order wrong so we were just creating an empty dependency file.
Added:
cfe/trunk/test/Preprocessor/dependencies-and-pp.c
- copied, changed from r70686, cfe/trunk/test/Preprocessor/depencies-and-pp.c
Removed:
cfe/trunk/test/Preprocessor/depencies-and-pp.c
Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/tools/clang-cc/DependencyFile.cpp
Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=70687&r1=70686&r2=70687&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Sun May 3 05:04:17 2009
@@ -71,6 +71,51 @@
}
};
+/// PPChainedCallbacks - Simple wrapper class for chaining callbacks.
+class PPChainedCallbacks : public PPCallbacks {
+ PPCallbacks *First, *Second;
+
+public:
+ PPChainedCallbacks(PPCallbacks *_First, PPCallbacks *_Second)
+ : First(_First), Second(_Second) {}
+ ~PPChainedCallbacks() {
+ delete Second;
+ delete First;
+ }
+
+ virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+ SrcMgr::CharacteristicKind FileType) {
+ First->FileChanged(Loc, Reason, FileType);
+ Second->FileChanged(Loc, Reason, FileType);
+ }
+
+ virtual void Ident(SourceLocation Loc, const std::string &str) {
+ First->Ident(Loc, str);
+ Second->Ident(Loc, str);
+ }
+
+ virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
+ const std::string &Str) {
+ First->PragmaComment(Loc, Kind, Str);
+ Second->PragmaComment(Loc, Kind, Str);
+ }
+
+ virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
+ First->MacroExpands(Id, MI);
+ Second->MacroExpands(Id, MI);
+ }
+
+ virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
+ First->MacroDefined(II, MI);
+ Second->MacroDefined(II, MI);
+ }
+
+ virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) {
+ First->MacroUndefined(II, MI);
+ Second->MacroUndefined(II, MI);
+ }
+};
+
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=70687&r1=70686&r2=70687&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sun May 3 05:04:17 2009
@@ -241,7 +241,8 @@
/// it.
PPCallbacks *getPPCallbacks() const { return Callbacks; }
void setPPCallbacks(PPCallbacks *C) {
- delete Callbacks;
+ if (Callbacks)
+ C = new PPChainedCallbacks(C, Callbacks);
Callbacks = C;
}
Removed: cfe/trunk/test/Preprocessor/depencies-and-pp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/depencies-and-pp.c?rev=70686&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/depencies-and-pp.c (original)
+++ cfe/trunk/test/Preprocessor/depencies-and-pp.c (removed)
@@ -1,4 +0,0 @@
-// RUN: clang -E -o %t.1 %s &&
-// RUN: clang -E -MD -MF %t.d -MT foo -o %t.2 %s &&
-// RUN: diff %t.1 %t.2 &&
-// RUN: grep "foo:" %t.d
Copied: cfe/trunk/test/Preprocessor/dependencies-and-pp.c (from r70686, cfe/trunk/test/Preprocessor/depencies-and-pp.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/dependencies-and-pp.c?p2=cfe/trunk/test/Preprocessor/dependencies-and-pp.c&p1=cfe/trunk/test/Preprocessor/depencies-and-pp.c&r1=70686&r2=70687&rev=70687&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/depencies-and-pp.c (original)
+++ cfe/trunk/test/Preprocessor/dependencies-and-pp.c Sun May 3 05:04:17 2009
@@ -1,4 +1,5 @@
// RUN: clang -E -o %t.1 %s &&
// RUN: clang -E -MD -MF %t.d -MT foo -o %t.2 %s &&
// RUN: diff %t.1 %t.2 &&
-// RUN: grep "foo:" %t.d
+// RUN: grep "foo:" %t.d &&
+// RUN: grep "dependencies-and-pp.c" %t.d
Modified: cfe/trunk/tools/clang-cc/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/DependencyFile.cpp?rev=70687&r1=70686&r2=70687&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/DependencyFile.cpp (original)
+++ cfe/trunk/tools/clang-cc/DependencyFile.cpp Sun May 3 05:04:17 2009
@@ -35,10 +35,6 @@
std::vector<std::string> Targets;
llvm::raw_ostream *OS;
- // FIXME: This functionality should be moved into a common class for
- // chaining callbacks.
- PPCallbacks *PrevCallbacks;
-
private:
bool FileMatchesDepCriteria(const char *Filename,
SrcMgr::CharacteristicKind FileType);
@@ -47,14 +43,11 @@
public:
DependencyFileCallback(const Preprocessor *_PP,
llvm::raw_ostream *_OS,
- const std::vector<std::string> &_Targets,
- PPCallbacks *_PrevCallbacks)
- : PP(_PP), Targets(_Targets), OS(_OS), PrevCallbacks(_PrevCallbacks) {
+ const std::vector<std::string> &_Targets)
+ : PP(_PP), Targets(_Targets), OS(_OS) {
}
~DependencyFileCallback() {
- if (PrevCallbacks)
- delete PrevCallbacks;
OutputDependencyFile();
OS->flush();
delete OS;
@@ -62,32 +55,6 @@
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType);
-
- virtual void Ident(SourceLocation Loc, const std::string &str) {
- if (PrevCallbacks)
- PrevCallbacks->Ident(Loc, str);
- }
-
- virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
- const std::string &Str) {
- if (PrevCallbacks)
- PrevCallbacks->PragmaComment(Loc, Kind, Str);
- }
-
- virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
- if (PrevCallbacks)
- PrevCallbacks->MacroExpands(Id, MI);
- }
-
- virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
- if (PrevCallbacks)
- PrevCallbacks->MacroDefined(II, MI);
- }
-
- virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) {
- if (PrevCallbacks)
- PrevCallbacks->MacroUndefined(II, MI);
- }
};
}
@@ -135,13 +102,8 @@
}
}
- // Claim any previous callbacks.
- PPCallbacks *Prev = PP->getPPCallbacks();
- if (Prev)
- PP->setPPCallbacks(0);
-
DependencyFileCallback *PPDep =
- new DependencyFileCallback(PP, OS, DependencyTargets, Prev);
+ new DependencyFileCallback(PP, OS, DependencyTargets);
PP->setPPCallbacks(PPDep);
return true;
}
@@ -162,9 +124,6 @@
void DependencyFileCallback::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType) {
- if (PrevCallbacks)
- PrevCallbacks->FileChanged(Loc, Reason, FileType);
-
if (Reason != PPCallbacks::EnterFile)
return;
More information about the cfe-commits
mailing list