[cfe-commits] r169949 - in /cfe/trunk: test/Index/annotate-tokens-pp.c tools/libclang/CIndex.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Dec 11 17:05:26 PST 2012
Author: akirtzidis
Date: Tue Dec 11 19:05:25 2012
New Revision: 169949
URL: http://llvm.org/viewvc/llvm-project?rev=169949&view=rev
Log:
[libclang] Make sure tokens from preprocessor directives are annotated as such,
even if the directive is inside a declaration.
Fixes rdar://11548788 & http://llvm.org/PR12970
Modified:
cfe/trunk/test/Index/annotate-tokens-pp.c
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/test/Index/annotate-tokens-pp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens-pp.c?rev=169949&r1=169948&r2=169949&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens-pp.c (original)
+++ cfe/trunk/test/Index/annotate-tokens-pp.c Tue Dec 11 19:05:25 2012
@@ -30,8 +30,20 @@
const char *fname = __FILE__;
-// RUN: c-index-test -test-annotate-tokens=%s:2:1:32:1 -I%S/Inputs %s | FileCheck %s
-// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-annotate-tokens=%s:2:1:32:1 -I%S/Inputs %s | FileCheck %s
+#define SOME_MACRO 3
+
+#ifdef SOME_MACRO
+#endif
+
+struct A
+{
+#ifdef SOME_MACRO
+ int x;
+#endif
+};
+
+// RUN: c-index-test -test-annotate-tokens=%s:2:1:44:1 -I%S/Inputs %s | FileCheck %s
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-annotate-tokens=%s:2:1:44:1 -I%S/Inputs %s | FileCheck %s
// CHECK: Punctuation: "#" [2:1 - 2:2] preprocessing directive=
// CHECK: Identifier: "define" [2:2 - 2:8] preprocessing directive=
// CHECK: Identifier: "STILL_NOTHING" [2:9 - 2:22] macro definition=STILL_NOTHING
@@ -196,3 +208,20 @@
// CHECK: {{28:1.*inclusion directive=pragma-once.h.*multi-include guarded}}
// CHECK: {{29:1.*inclusion directive=guarded.h.*multi-include guarded}}
// CHECK: Identifier: "__FILE__" [31:21 - 31:29] macro expansion=__FILE__
+// CHECK: Punctuation: "#" [35:1 - 35:2] preprocessing directive=
+// CHECK: Identifier: "ifdef" [35:2 - 35:7] preprocessing directive=
+// CHECK: Identifier: "SOME_MACRO" [35:8 - 35:18] macro expansion=SOME_MACRO:33:9
+// CHECK: Punctuation: "#" [36:1 - 36:2] preprocessing directive=
+// CHECK: Identifier: "endif" [36:2 - 36:7] preprocessing directive=
+// CHECK: Keyword: "struct" [38:1 - 38:7] StructDecl=A:38:8 (Definition)
+// CHECK: Identifier: "A" [38:8 - 38:9] StructDecl=A:38:8 (Definition)
+// CHECK: Punctuation: "{" [39:1 - 39:2] StructDecl=A:38:8 (Definition)
+// CHECK: Punctuation: "#" [40:1 - 40:2] preprocessing directive=
+// CHECK: Identifier: "ifdef" [40:2 - 40:7] preprocessing directive=
+// CHECK: Identifier: "SOME_MACRO" [40:8 - 40:18] macro expansion=SOME_MACRO:33:9
+// CHECK: Keyword: "int" [41:3 - 41:6] FieldDecl=x:41:7 (Definition)
+// CHECK: Identifier: "x" [41:7 - 41:8] FieldDecl=x:41:7 (Definition)
+// CHECK: Punctuation: ";" [41:8 - 41:9] StructDecl=A:38:8 (Definition)
+// CHECK: Punctuation: "#" [42:1 - 42:2] preprocessing directive=
+// CHECK: Identifier: "endif" [42:2 - 42:7] preprocessing directive=
+// CHECK: Punctuation: "}" [43:1 - 43:2] StructDecl=A:38:8 (Definition)
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=169949&r1=169948&r2=169949&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Dec 11 19:05:25 2012
@@ -4935,9 +4935,7 @@
for (unsigned I = 0 ; I < TokIdx ; ++I) {
AnnotateTokensData::iterator Pos = Annotated.find(Tokens[I].int_data[1]);
- if (Pos != Annotated.end() &&
- (clang_isInvalid(Cursors[I].kind) ||
- Pos->second.kind != CXCursor_PreprocessingDirective))
+ if (Pos != Annotated.end() && !clang_isPreprocessing(Cursors[I].kind))
Cursors[I] = Pos->second;
}
@@ -5067,13 +5065,6 @@
}
if (clang_isPreprocessing(cursor.kind)) {
- // For macro expansions, just note where the beginning of the macro
- // expansion occurs.
- if (cursor.kind == CXCursor_MacroExpansion) {
- Annotated[Loc.int_data] = cursor;
- return CXChildVisit_Recurse;
- }
-
// Items in the preprocessing record are kept separate from items in
// declarations, so we keep a separate token index.
unsigned SavedTokIdx = TokIdx;
@@ -5107,6 +5098,10 @@
case RangeOverlap:
Cursors[I] = cursor;
AdvanceToken();
+ // For macro expansions, just note where the beginning of the macro
+ // expansion occurs.
+ if (cursor.kind == CXCursor_MacroExpansion)
+ break;
continue;
}
break;
More information about the cfe-commits
mailing list