[cfe-commits] r110523 - in /cfe/trunk: include/clang/Lex/PPCallbacks.h include/clang/Lex/PreprocessingRecord.h lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/PPDirectives.cpp lib/Lex/PreprocessingRecord.cpp test/Preprocessor/dump-macros-undef.c
Benjamin Kramer
benny.kra at googlemail.com
Sat Aug 7 15:27:00 PDT 2010
Author: d0k
Date: Sat Aug 7 17:27:00 2010
New Revision: 110523
URL: http://llvm.org/viewvc/llvm-project?rev=110523&view=rev
Log:
Push location through the MacroUndefined PPCallback and use it to print #undefs in -dD mode. (PR7818)
Added:
cfe/trunk/test/Preprocessor/dump-macros-undef.c
Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PreprocessingRecord.cpp
Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=110523&r1=110522&r2=110523&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Sat Aug 7 17:27:00 2010
@@ -89,7 +89,8 @@
/// MacroUndefined - This hook is called whenever a macro #undef is seen.
/// MI is released immediately following this callback.
- virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) {
+ virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
+ const MacroInfo *MI) {
}
};
@@ -149,9 +150,10 @@
Second->MacroDefined(II, MI);
}
- virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI) {
- First->MacroUndefined(II, MI);
- Second->MacroUndefined(II, MI);
+ virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
+ const MacroInfo *MI) {
+ First->MacroUndefined(Loc, II, MI);
+ Second->MacroUndefined(Loc, II, MI);
}
};
Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=110523&r1=110522&r2=110523&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Sat Aug 7 17:27:00 2010
@@ -257,7 +257,8 @@
virtual void MacroExpands(const Token &Id, const MacroInfo* MI);
virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI);
- virtual void MacroUndefined(const IdentifierInfo *II, const MacroInfo *MI);
+ virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
+ const MacroInfo *MI);
};
} // end namespace clang
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=110523&r1=110522&r2=110523&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sat Aug 7 17:27:00 2010
@@ -137,6 +137,9 @@
/// MacroDefined - This hook is called whenever a macro definition is seen.
void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI);
+ /// MacroUndefined - This hook is called whenever a macro #undef is seen.
+ void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
+ const MacroInfo *MI);
};
} // end anonymous namespace
@@ -280,6 +283,16 @@
EmittedMacroOnThisLine = true;
}
+void PrintPPOutputPPCallbacks::MacroUndefined(SourceLocation Loc,
+ const IdentifierInfo *II,
+ const MacroInfo *MI) {
+ // Only print out macro definitions in -dD mode.
+ if (!DumpDefines) return;
+
+ MoveToLine(Loc);
+ OS << "#undef " << II->getName();
+ EmittedMacroOnThisLine = true;
+}
void PrintPPOutputPPCallbacks::PragmaComment(SourceLocation Loc,
const IdentifierInfo *Kind,
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=110523&r1=110522&r2=110523&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sat Aug 7 17:27:00 2010
@@ -1508,7 +1508,8 @@
// If the callbacks want to know, tell them about the macro #undef.
if (Callbacks)
- Callbacks->MacroUndefined(MacroNameTok.getIdentifierInfo(), MI);
+ Callbacks->MacroUndefined(MacroNameTok.getLocation(),
+ MacroNameTok.getIdentifierInfo(), MI);
// Free macro definition.
ReleaseMacroInfo(MI);
Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=110523&r1=110522&r2=110523&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Sat Aug 7 17:27:00 2010
@@ -118,7 +118,8 @@
PreprocessedEntities.push_back(Def);
}
-void PreprocessingRecord::MacroUndefined(const IdentifierInfo *II,
+void PreprocessingRecord::MacroUndefined(SourceLocation Loc,
+ const IdentifierInfo *II,
const MacroInfo *MI) {
llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos
= MacroDefinitions.find(MI);
Added: cfe/trunk/test/Preprocessor/dump-macros-undef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/dump-macros-undef.c?rev=110523&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/dump-macros-undef.c (added)
+++ cfe/trunk/test/Preprocessor/dump-macros-undef.c Sat Aug 7 17:27:00 2010
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -E -dD %s | FileCheck %s
+// PR7818
+
+// CHECK: # 1 "{{.+}}.c"
+#define X 3
+// CHECK: #define X 3
+#undef X
+// CHECK: #undef X
More information about the cfe-commits
mailing list