From f77b0f888690e056e7da4efe94f5e97f996f6b05 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 8 Dec 2012 02:21:17 +0000 Subject: [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. llvm-svn: 169666 --- clang/lib/Lex/PreprocessingRecord.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'clang/lib/Lex/PreprocessingRecord.cpp') diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index a78fbe763a2..497af0b3dad 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -357,8 +357,9 @@ MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) { return cast(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()); -- cgit v1.2.3