[cfe-commits] r140207 - in /cfe/trunk: lib/Lex/PreprocessingRecord.cpp test/Index/getcursor-pp-pch.c test/Index/getcursor-pp-pch.c.h tools/libclang/CIndex.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Sep 20 16:27:33 PDT 2011


Author: akirtzidis
Date: Tue Sep 20 18:27:33 2011
New Revision: 140207

URL: http://llvm.org/viewvc/llvm-project?rev=140207&view=rev
Log:
[libclang] When pointing at a macro expansion inside a macro argument,
return a cursor for the inner macro.

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

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=140207&r1=140206&r2=140207&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Tue Sep 20 18:27:33 2011
@@ -145,10 +145,10 @@
 }
 
 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);
 }

Modified: cfe/trunk/test/Index/getcursor-pp-pch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/getcursor-pp-pch.c?rev=140207&r1=140206&r2=140207&view=diff
==============================================================================
--- cfe/trunk/test/Index/getcursor-pp-pch.c (original)
+++ cfe/trunk/test/Index/getcursor-pp-pch.c Tue Sep 20 18:27:33 2011
@@ -11,6 +11,8 @@
 // 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 @@
 // 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

Modified: cfe/trunk/test/Index/getcursor-pp-pch.c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/getcursor-pp-pch.c.h?rev=140207&r1=140206&r2=140207&view=diff
==============================================================================
--- cfe/trunk/test/Index/getcursor-pp-pch.c.h (original)
+++ cfe/trunk/test/Index/getcursor-pp-pch.c.h Tue Sep 20 18:27:33 2011
@@ -2,3 +2,4 @@
 #define DECORATION
 
 DECORATION
+OBSCURE(DECORATION)

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=140207&r1=140206&r2=140207&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Sep 20 18:27:33 2011
@@ -3468,12 +3468,6 @@
       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;
 }





More information about the cfe-commits mailing list