summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang/CIndex.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-07 19:16:32 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-07 19:16:32 +0000
commit68d31ce5ff33c987104431efa45c30cfe53df27f (patch)
treed74e6990d35dfd5f081809928276621f64f6ff40 /clang/tools/libclang/CIndex.cpp
parent2d77aeb946c6c11fa70d3446948871579fb81940 (diff)
downloadbcm5719-llvm-68d31ce5ff33c987104431efa45c30cfe53df27f.tar.gz
bcm5719-llvm-68d31ce5ff33c987104431efa45c30cfe53df27f.zip
[libclang] When annotating preprocessor tokens, if we are in a macro definition,
check if the token was ever a macro name and annotate it if that's the case. llvm-svn: 171776
Diffstat (limited to 'clang/tools/libclang/CIndex.cpp')
-rw-r--r--clang/tools/libclang/CIndex.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 797344eada1..97fabab4a51 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5307,6 +5307,7 @@ static void annotatePreprocessorTokens(CXTranslationUnit TU,
unsigned NumTokens) {
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+ Preprocessor &PP = CXXUnit->getPreprocessor();
SourceManager &SourceMgr = CXXUnit->getSourceManager();
std::pair<FileID, unsigned> BeginLocInfo
= SourceMgr.getDecomposedLoc(RegionOfInterest.getBegin());
@@ -5348,12 +5349,41 @@ static void annotatePreprocessorTokens(CXTranslationUnit TU,
// #undefs, to provide specific cursor kinds for those.
SourceLocation BeginLoc = Tok.getLocation();
+ if (lexNext(Lex, Tok, NextIdx, NumTokens))
+ break;
+
+ MacroInfo *MI = 0;
+ if (Tok.is(tok::raw_identifier) &&
+ StringRef(Tok.getRawIdentifierData(), Tok.getLength()) == "define") {
+ if (lexNext(Lex, Tok, NextIdx, NumTokens))
+ break;
+
+ if (Tok.is(tok::raw_identifier)) {
+ StringRef Name(Tok.getRawIdentifierData(), Tok.getLength());
+ IdentifierInfo &II = PP.getIdentifierTable().get(Name);
+ SourceLocation MappedTokLoc =
+ CXXUnit->mapLocationToPreamble(Tok.getLocation());
+ MI = getMacroInfo(II, MappedTokLoc, TU);
+ }
+ }
+
bool finished = false;
do {
if (lexNext(Lex, Tok, NextIdx, NumTokens)) {
finished = true;
break;
}
+ // If we are in a macro definition, check if the token was ever a
+ // macro name and annotate it if that's the case.
+ if (MI) {
+ SourceLocation SaveLoc = Tok.getLocation();
+ Tok.setLocation(CXXUnit->mapLocationToPreamble(SaveLoc));
+ MacroDefinition *MacroDef = checkForMacroInMacroDefinition(MI,Tok,TU);
+ Tok.setLocation(SaveLoc);
+ if (MacroDef)
+ Cursors[NextIdx-1] = MakeMacroExpansionCursor(MacroDef,
+ Tok.getLocation(), TU);
+ }
} while (!Tok.isAtStartOfLine());
unsigned LastIdx = finished ? NextIdx-1 : NextIdx-2;
@@ -5364,7 +5394,7 @@ static void annotatePreprocessorTokens(CXTranslationUnit TU,
MakePreprocessingDirectiveCursor(SourceRange(BeginLoc, EndLoc), TU);
for (; TokIdx <= LastIdx; ++TokIdx)
- Cursors[TokIdx] = Cursor;
+ updateCursorAnnotation(Cursors[TokIdx], Cursor);
if (finished)
break;
OpenPOWER on IntegriCloud