aboutsummaryrefslogtreecommitdiff
path: root/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-07-07 16:03:39 +0000
committerDouglas Gregor <dgregor@apple.com>2011-07-07 16:03:39 +0000
commit3da626b4f38eb0350de960d71271ca77af7a9cc8 (patch)
tree7033914fa939a04b65cef3767a1e4524149f7ad9 /tools/c-index-test/c-index-test.c
parent63ff703393543904046462aee2ac0a53b8937a3e (diff)
Introduce a new libclang aPI function,
clang_codeCompleteGetContexts(), that provides the client with information about the context in which code completion has occurred and what kinds of entities make sense as completions at that point. Patch by Connor Wakamo! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134615 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/c-index-test/c-index-test.c')
-rw-r--r--tools/c-index-test/c-index-test.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index d077653335..e574b872ae 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -1018,6 +1018,79 @@ void print_completion_result(CXCompletionResult *completion_result,
fprintf(file, "\n");
}
+void print_completion_contexts(unsigned long long contexts, FILE *file) {
+ fprintf(file, "Completion contexts:\n");
+ if (contexts == CXCompletionContext_Unknown) {
+ fprintf(file, "Unknown\n");
+ }
+ if (contexts & CXCompletionContext_AnyType) {
+ fprintf(file, "Any type\n");
+ }
+ if (contexts & CXCompletionContext_AnyValue) {
+ fprintf(file, "Any value\n");
+ }
+ if (contexts & CXCompletionContext_ObjCObjectValue) {
+ fprintf(file, "Objective-C object value\n");
+ }
+ if (contexts & CXCompletionContext_ObjCSelectorValue) {
+ fprintf(file, "Objective-C selector value\n");
+ }
+ if (contexts & CXCompletionContext_CXXClassTypeValue) {
+ fprintf(file, "C++ class type value\n");
+ }
+ if (contexts & CXCompletionContext_DotMemberAccess) {
+ fprintf(file, "Dot member access\n");
+ }
+ if (contexts & CXCompletionContext_ArrowMemberAccess) {
+ fprintf(file, "Arrow member access\n");
+ }
+ if (contexts & CXCompletionContext_ObjCPropertyAccess) {
+ fprintf(file, "Objective-C property access\n");
+ }
+ if (contexts & CXCompletionContext_EnumTag) {
+ fprintf(file, "Enum tag\n");
+ }
+ if (contexts & CXCompletionContext_UnionTag) {
+ fprintf(file, "Union tag\n");
+ }
+ if (contexts & CXCompletionContext_StructTag) {
+ fprintf(file, "Struct tag\n");
+ }
+ if (contexts & CXCompletionContext_ClassTag) {
+ fprintf(file, "Class name\n");
+ }
+ if (contexts & CXCompletionContext_Namespace) {
+ fprintf(file, "Namespace or namespace alias\n");
+ }
+ if (contexts & CXCompletionContext_NestedNameSpecifier) {
+ fprintf(file, "Nested name specifier\n");
+ }
+ if (contexts & CXCompletionContext_ObjCInterface) {
+ fprintf(file, "Objective-C interface\n");
+ }
+ if (contexts & CXCompletionContext_ObjCProtocol) {
+ fprintf(file, "Objective-C protocol\n");
+ }
+ if (contexts & CXCompletionContext_ObjCCategory) {
+ fprintf(file, "Objective-C category\n");
+ }
+ if (contexts & CXCompletionContext_ObjCInstanceMessage) {
+ fprintf(file, "Objective-C instance method\n");
+ }
+ if (contexts & CXCompletionContext_ObjCClassMessage) {
+ fprintf(file, "Objective-C class method\n");
+ }
+ if (contexts & CXCompletionContext_ObjCSelectorName) {
+ fprintf(file, "Objective-C selector name\n");
+ }
+ if (contexts & CXCompletionContext_MacroName) {
+ fprintf(file, "Macro name\n");
+ }
+ if (contexts & CXCompletionContext_NaturalLanguage) {
+ fprintf(file, "Natural language\n");
+ }
+}
+
int my_stricmp(const char *s1, const char *s2) {
while (*s1 && *s2) {
int c1 = tolower((unsigned char)*s1), c2 = tolower((unsigned char)*s2);
@@ -1099,6 +1172,7 @@ int perform_code_completion(int argc, const char **argv, int timing_only) {
if (results) {
unsigned i, n = results->NumResults;
+ unsigned long long contexts;
if (!timing_only) {
/* Sort the code-completion results based on the typed text. */
clang_sortCodeCompletionResults(results->Results, results->NumResults);
@@ -1112,6 +1186,10 @@ int perform_code_completion(int argc, const char **argv, int timing_only) {
PrintDiagnostic(diag);
clang_disposeDiagnostic(diag);
}
+
+ contexts = clang_codeCompleteGetContexts(results);
+ print_completion_contexts(contexts, stdout);
+
clang_disposeCodeCompleteResults(results);
}
clang_disposeTranslationUnit(TU);