mirror of https://github.com/microsoft/clang.git
Push location through the MacroUndefined PPCallback and use it to print #undefs in -dD mode. (PR7818)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110523 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
443c21266f
commit
2f05449fa1
|
@ -89,7 +89,8 @@ public:
|
|||
|
||||
/// 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 @@ public:
|
|||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -257,7 +257,8 @@ namespace clang {
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -137,6 +137,9 @@ public:
|
|||
/// 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 @@ void PrintPPOutputPPCallbacks::MacroDefined(const IdentifierInfo *II,
|
|||
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,
|
||||
|
|
|
@ -1508,7 +1508,8 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
|
|||
|
||||
// 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);
|
||||
|
|
|
@ -118,7 +118,8 @@ void PreprocessingRecord::MacroDefined(const IdentifierInfo *II,
|
|||
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);
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue