[cfe-commits] r70686 - in /cfe/trunk: test/Preprocessor/depencies-and-pp.c tools/clang-cc/DependencyFile.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Sun May 3 02:36:07 PDT 2009
Author: ddunbar
Date: Sun May 3 04:35:25 2009
New Revision: 70686
URL: http://llvm.org/viewvc/llvm-project?rev=70686&view=rev
Log:
PR4063: Fix dependency generation with -E.
Added:
cfe/trunk/test/Preprocessor/depencies-and-pp.c
Modified:
cfe/trunk/tools/clang-cc/DependencyFile.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Added: 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 (added)
+++ cfe/trunk/test/Preprocessor/depencies-and-pp.c Sun May 3 04:35:25 2009
@@ -0,0 +1,4 @@
+// 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
Modified: cfe/trunk/tools/clang-cc/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/DependencyFile.cpp?rev=70686&r1=70685&r2=70686&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/DependencyFile.cpp (original)
+++ cfe/trunk/tools/clang-cc/DependencyFile.cpp Sun May 3 04:35:25 2009
@@ -35,6 +35,10 @@
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);
@@ -43,11 +47,14 @@
public:
DependencyFileCallback(const Preprocessor *_PP,
llvm::raw_ostream *_OS,
- const std::vector<std::string> &_Targets)
- : PP(_PP), Targets(_Targets), OS(_OS) {
+ const std::vector<std::string> &_Targets,
+ PPCallbacks *_PrevCallbacks)
+ : PP(_PP), Targets(_Targets), OS(_OS), PrevCallbacks(_PrevCallbacks) {
}
~DependencyFileCallback() {
+ if (PrevCallbacks)
+ delete PrevCallbacks;
OutputDependencyFile();
OS->flush();
delete OS;
@@ -55,6 +62,32 @@
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);
+ }
};
}
@@ -102,8 +135,13 @@
}
}
+ // Claim any previous callbacks.
+ PPCallbacks *Prev = PP->getPPCallbacks();
+ if (Prev)
+ PP->setPPCallbacks(0);
+
DependencyFileCallback *PPDep =
- new DependencyFileCallback(PP, OS, DependencyTargets);
+ new DependencyFileCallback(PP, OS, DependencyTargets, Prev);
PP->setPPCallbacks(PPDep);
return true;
}
@@ -124,6 +162,9 @@
void DependencyFileCallback::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType) {
+ if (PrevCallbacks)
+ PrevCallbacks->FileChanged(Loc, Reason, FileType);
+
if (Reason != PPCallbacks::EnterFile)
return;
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=70686&r1=70685&r2=70686&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Sun May 3 04:35:25 2009
@@ -1385,14 +1385,11 @@
if (InitializePreprocessor(*PP, InFile, InitOpts))
return 0;
- /// FIXME: PP can only handle one callback
- if (ProgAction != PrintPreprocessedInput) {
- std::string ErrStr;
- bool DFG = CreateDependencyFileGen(PP.get(), ErrStr);
- if (!DFG && !ErrStr.empty()) {
- fprintf(stderr, "%s", ErrStr.c_str());
- return 0;
- }
+ std::string ErrStr;
+ bool DFG = CreateDependencyFileGen(PP.get(), ErrStr);
+ if (!DFG && !ErrStr.empty()) {
+ fprintf(stderr, "%s", ErrStr.c_str());
+ return 0;
}
return PP.take();
More information about the cfe-commits
mailing list