aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PreprocessingRecord.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-08 02:21:17 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-08 02:21:17 +0000
commit5f5250b140544436eb3c2fbd9f43e14019ef01f2 (patch)
treecde8d8ad3e8c8f256f124f8a5986c6850ddb3ecf /lib/Lex/PreprocessingRecord.cpp
parent61c1c8ee3fa1bd1f4866d246c72af854be834634 (diff)
[libclang] Resolve a cursor that points to a macro name inside a #ifdef/#ifndef
directive as a macro expansion. This is more of a "macro reference" than a macro expansion but it's close enough for libclang's purposes. If it causes issues we can revisit and introduce a new kind of cursor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169666 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PreprocessingRecord.cpp')
-rw-r--r--lib/Lex/PreprocessingRecord.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp
index a78fbe763a..497af0b3da 100644
--- a/lib/Lex/PreprocessingRecord.cpp
+++ b/lib/Lex/PreprocessingRecord.cpp
@@ -357,8 +357,9 @@ MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) {
return cast<MacroDefinition>(Entity);
}
-void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI,
- SourceRange Range) {
+void PreprocessingRecord::addMacroExpansion(const Token &Id,
+ const MacroInfo *MI,
+ SourceRange Range) {
// We don't record nested macro expansions.
if (Id.getLocation().isMacroID())
return;
@@ -371,6 +372,32 @@ void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI,
new (*this) MacroExpansion(Def, Range));
}
+void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI) {
+ // This is not actually a macro expansion but record it as a macro reference.
+ if (MI)
+ addMacroExpansion(MacroNameTok, MI, MacroNameTok.getLocation());
+}
+
+void PreprocessingRecord::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
+ const MacroInfo *MI) {
+ // This is not actually a macro expansion but record it as a macro reference.
+ if (MI)
+ addMacroExpansion(MacroNameTok, MI, MacroNameTok.getLocation());
+}
+
+void PreprocessingRecord::Defined(const Token &MacroNameTok,
+ const MacroInfo *MI) {
+ // This is not actually a macro expansion but record it as a macro reference.
+ if (MI)
+ addMacroExpansion(MacroNameTok, MI, MacroNameTok.getLocation());
+}
+
+void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI,
+ SourceRange Range) {
+ addMacroExpansion(Id, MI, Range);
+}
+
void PreprocessingRecord::MacroDefined(const Token &Id,
const MacroInfo *MI) {
SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());