]> granicus.if.org Git - clang/commitdiff
[libclang] When pointing at a macro expansion inside a macro argument,
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 20 Sep 2011 23:27:33 +0000 (23:27 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 20 Sep 2011 23:27:33 +0000 (23:27 +0000)
return a cursor for the inner macro.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140207 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PreprocessingRecord.cpp
test/Index/getcursor-pp-pch.c
test/Index/getcursor-pp-pch.c.h
tools/libclang/CIndex.cpp

index 2368b389810ca1bd0290751392cf8a763f292a62..3f288b0fd9f0f8e17be9b1f9f261a901fbec3a8e 100644 (file)
@@ -145,10 +145,10 @@ unsigned PreprocessingRecord::findEndLocalPreprocessedEntity(
 }
 
 void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) {
-  SourceLocation Loc = Entity->getSourceRange().getBegin();
+  assert(Entity);
   assert((PreprocessedEntities.empty() ||
-          !SourceMgr.isBeforeInTranslationUnit(Loc,
-                     PreprocessedEntities.back()->getSourceRange().getEnd())) &&
+       !SourceMgr.isBeforeInTranslationUnit(Entity->getSourceRange().getBegin(),
+                   PreprocessedEntities.back()->getSourceRange().getBegin())) &&
          "Adding a preprocessed entity that is before the previous one in TU");
   PreprocessedEntities.push_back(Entity);
 }
index dc597ffa94e87251e415d2625a51b9eaf05bd52d..d68384c660678c32e9b6f8786984db9b5f3d4706 100644 (file)
@@ -11,6 +11,8 @@ void OBSCURE(func)(int x) {
 // RUN: c-index-test -cursor-at=%s.h:1:11 \
 // RUN:              -cursor-at=%s.h:2:14 \
 // RUN:              -cursor-at=%s.h:4:5 \
+// RUN:              -cursor-at=%s.h:5:5 \
+// RUN:              -cursor-at=%s.h:5:14 \
 // RUN:              -cursor-at=%s:5:7 \
 // RUN:              -cursor-at=%s:6:6 \
 // RUN:              -cursor-at=%s:6:19 \
@@ -21,14 +23,21 @@ void OBSCURE(func)(int x) {
 // RUN: c-index-test -cursor-at=%s.h:1:11 \
 // RUN:              -cursor-at=%s.h:2:14 \
 // RUN:              -cursor-at=%s.h:4:5 \
+// RUN:              -cursor-at=%s.h:5:5 \
+// RUN:              -cursor-at=%s.h:5:14 \
 // RUN:              -cursor-at=%s:5:7 \
 // RUN:              -cursor-at=%s:6:6 \
 // RUN:              -cursor-at=%s:6:19 \
 // RUN:     -include %t.h %s | FileCheck %s
 
+// From header
 // CHECK: macro definition=OBSCURE
 // CHECK: macro definition=DECORATION
 // CHECK: macro expansion=DECORATION:2:9
 // CHECK: macro expansion=OBSCURE:1:9
+// CHECK: macro expansion=DECORATION:2:9
+
+// From main file
+// CHECK: macro expansion=OBSCURE:1:9
 // CHECK: macro expansion=OBSCURE:1:9
 // CHECK: macro expansion=DECORATION:2:9
index 184dd8b4104c6e40b896469b4b53ddad4796dce0..c24a39c0e9db6e87ad1b5b377e3d62000e177fa2 100644 (file)
@@ -2,3 +2,4 @@
 #define DECORATION
 
 DECORATION
+OBSCURE(DECORATION)
index 5916d5c3374f31cd829a9c6bbdb59b088fa52212..d9bc5ca2599c4a4f8ca66829914d3dd99cda8b4a 100644 (file)
@@ -3468,12 +3468,6 @@ static enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
       cursor.kind == CXCursor_TypeRef)
     return CXChildVisit_Recurse;
   
-  // Don't override a preprocessing cursor with another preprocessing
-  // cursor; we want the outermost preprocessing cursor.
-  if (clang_isPreprocessing(cursor.kind) &&
-      clang_isPreprocessing(BestCursor->kind))
-    return CXChildVisit_Recurse;
-  
   *BestCursor = cursor;
   return CXChildVisit_Recurse;
 }