[cfe-commits] r86550 - in /cfe/trunk: test/Index/code-completion.cpp tools/CIndex/CIndex.exports tools/c-index-test/c-index-test.c
Douglas Gregor
dgregor at apple.com
Mon Nov 9 08:04:45 PST 2009
Author: dgregor
Date: Mon Nov 9 10:04:45 2009
New Revision: 86550
URL: http://llvm.org/viewvc/llvm-project?rev=86550&view=rev
Log:
Minor cleanup for CIndex-based code-completion:
- Provide an actual test for code-completion via CIndex.
- Actually print optional strings in c-index-test
- Export clang_getCompletionChunkCompletionString from CIndex
Added:
cfe/trunk/test/Index/code-completion.cpp
Modified:
cfe/trunk/tools/CIndex/CIndex.exports
cfe/trunk/tools/c-index-test/c-index-test.c
Added: cfe/trunk/test/Index/code-completion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/code-completion.cpp?rev=86550&view=auto
==============================================================================
--- cfe/trunk/test/Index/code-completion.cpp (added)
+++ cfe/trunk/test/Index/code-completion.cpp Mon Nov 9 10:04:45 2009
@@ -0,0 +1,51 @@
+// Code-completion through the C interface
+
+struct X {
+ int member;
+};
+
+struct Y {
+ float member;
+ void memfunc(int i = 17);
+};
+
+struct Z : X, Y {
+ double member;
+ operator int() const;
+};
+
+struct Z get_Z();
+
+void test_Z() {
+ // RUN: c-index-test -code-completion-at=%s:21:11 %s | FileCheck -check-prefix=CHECK-MEMBER %s
+ get_Z().member = 17;
+}
+
+
+float& overloaded(int i, long second);
+double& overloaded(float f, int second);
+int& overloaded(Z z, int second);
+
+void test_overloaded() {
+ // RUN: c-index-test -code-completion-at=%s:31:18 %s | FileCheck -check-prefix=CHECK-OVERLOAD %s
+ overloaded(Z(), 0);
+}
+
+// CHECK-MEMBER: FieldDecl:{TypedText member}
+// CHECK-MEMBER: FunctionDecl:{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )}
+// CHECK-MEMBER: FunctionDecl:{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )}
+// CHECK-MEMBER: FunctionDecl:{Informative Y::}{TypedText ~Y}{LeftParen (}{RightParen )}
+// CHECK-MEMBER: FunctionDecl:{TypedText ~Z}{LeftParen (}{RightParen )}
+// CHECK-MEMBER: FunctionDecl:{TypedText operator int}{LeftParen (}{RightParen )}
+// CHECK-MEMBER: FunctionDecl:{TypedText operator=}{LeftParen (}{Placeholder struct Z const &}{RightParen )}
+// CHECK-MEMBER: StructDecl:{TypedText X}{Text ::}
+// CHECK-MEMBER: StructDecl:{TypedText Y}{Text ::}
+// CHECK-MEMBER: StructDecl:{TypedText Z}{Text ::}
+// CHECK-MEMBER: FieldDecl:{Text X::}{TypedText member}
+// CHECK-MEMBER: FieldDecl:{Text Y::}{TypedText member}
+// CHECK-MEMBER: FunctionDecl:{Text X::}{TypedText operator=}{LeftParen (}{Placeholder struct X const &}{RightParen )}
+// CHECK-MEMBER: FunctionDecl:{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder struct Y const &}{RightParen )}
+
+// CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text struct Z z}{Comma , }{CurrentParameter int second}{RightParen )}
+// CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text int i}{Comma , }{CurrentParameter long second}{RightParen )}
+// CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text float f}{Comma , }{CurrentParameter int second}{RightParen )}
Modified: cfe/trunk/tools/CIndex/CIndex.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.exports?rev=86550&r1=86549&r2=86550&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.exports (original)
+++ cfe/trunk/tools/CIndex/CIndex.exports Mon Nov 9 10:04:45 2009
@@ -4,6 +4,7 @@
_clang_createTranslationUnitFromSourceFile
_clang_disposeIndex
_clang_disposeTranslationUnit
+_clang_getCompletionChunkCompletionString
_clang_getCompletionChunkKind
_clang_getCompletionChunkText
_clang_getCursor
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=86550&r1=86549&r2=86550&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Nov 9 10:04:45 2009
@@ -158,24 +158,37 @@
return "Unknown";
}
-void print_completion_result(CXCompletionResult *completion_result,
- CXClientData client_data) {
- FILE *file = (FILE *)client_data;
+void print_completion_string(CXCompletionString completion_string, FILE *file) {
int I, N;
-
- fprintf(file, "%s:",
- clang_getCursorKindSpelling(completion_result->CursorKind));
- N = clang_getNumCompletionChunks(completion_result->CompletionString);
+
+ N = clang_getNumCompletionChunks(completion_string);
for (I = 0; I != N; ++I) {
- const char *text
- = clang_getCompletionChunkText(completion_result->CompletionString, I);
-
enum CXCompletionChunkKind Kind
- = clang_getCompletionChunkKind(completion_result->CompletionString, I);
+ = clang_getCompletionChunkKind(completion_string, I);
+
+ if (Kind == CXCompletionChunk_Optional) {
+ fprintf(file, "{Optional ");
+ print_completion_string(
+ clang_getCompletionChunkCompletionString(completion_string, I),
+ file);
+ fprintf(file, "}");
+ continue;
+ }
+
+ const char *text
+ = clang_getCompletionChunkText(completion_string, I);
fprintf(file, "{%s %s}",
clang_getCompletionChunkKindSpelling(Kind),
text? text : "");
}
+}
+
+void print_completion_result(CXCompletionResult *completion_result,
+ CXClientData client_data) {
+ FILE *file = (FILE *)client_data;
+ fprintf(file, "%s:",
+ clang_getCursorKindSpelling(completion_result->CursorKind));
+ print_completion_string(completion_result->CompletionString, file);
fprintf(file, "\n");
}
More information about the cfe-commits
mailing list