From 1cd27d50b3ae3d6b90b447bb35f8fe9fd86b53ea Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 17 Nov 2009 18:13:31 +0000 Subject: [PATCH] Organize c-index-test into logic sections, and add section headers. llvm-svn: 89117 --- clang/tools/c-index-test/c-index-test.c | 104 ++++++++++++++---------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index c6fb51a499f4..573222b96c57 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -5,6 +5,10 @@ #include #include +/******************************************************************************/ +/* Utility functions. */ +/******************************************************************************/ + #ifdef _MSC_VER char *basename(const char* path) { @@ -23,6 +27,10 @@ char *basename(const char* path) extern char *basename(const char *); #endif +/******************************************************************************/ +/* Pretty-printing. */ +/******************************************************************************/ + static void PrintCursor(CXCursor Cursor) { if (clang_isInvalid(Cursor.kind)) printf("Invalid Cursor => %s\n", clang_getCursorKindSpelling(Cursor.kind)); @@ -47,6 +55,10 @@ static const char* GetCursorSource(CXCursor Cursor) { return basename(source); } +/******************************************************************************/ +/* Logic for testing clang_loadTranslationUnit(). */ +/******************************************************************************/ + static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) { if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { @@ -115,6 +127,43 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, } } +int perform_test_load_tu(const char *file, const char *filter) { + CXIndex Idx; + CXTranslationUnit TU; + enum CXCursorKind K = CXCursor_NotImplemented; + enum CXCursorKind *ck = &K; + Idx = clang_createIndex(/* excludeDeclsFromPCH */ + !strcmp(filter, "local") ? 1 : 0, + /* displayDiagnostics */ 1); + + TU = clang_createTranslationUnit(Idx, file); + + if (!TU) { + fprintf(stderr, "Unable to load translation unit from '%s'!\n", file); + return 1; + } + + /* Perform some simple filtering. */ + if (!strcmp(filter, "all") || !strcmp(filter, "local")) ck = NULL; + else if (!strcmp(filter, "category")) K = CXCursor_ObjCCategoryDecl; + else if (!strcmp(filter, "interface")) K = CXCursor_ObjCInterfaceDecl; + else if (!strcmp(filter, "protocol")) K = CXCursor_ObjCProtocolDecl; + else if (!strcmp(filter, "function")) K = CXCursor_FunctionDecl; + else if (!strcmp(filter, "typedef")) K = CXCursor_TypedefDecl; + else { + fprintf(stderr, "Unknown filter for -test-load-tu: %s\n", filter); + return 1; + } + + clang_loadTranslationUnit(TU, TranslationUnitVisitor, ck); + clang_disposeTranslationUnit(TU); + return 0; +} + +/******************************************************************************/ +/* Logic for testing clang_codeComplete(). */ +/******************************************************************************/ + /* Parse file:line:column from the input string. Returns 0 on success, non-zero on failure. If successful, the pointer *filename will contain newly-allocated memory (that will be owned by the caller) to store the file name. */ @@ -236,51 +285,22 @@ int perform_code_completion(int argc, const char **argv) { return 0; } -int perform_test_load_tu(const char *file, const char *filter) { - CXIndex Idx; - CXTranslationUnit TU; - enum CXCursorKind K = CXCursor_NotImplemented; - enum CXCursorKind *ck = &K; - Idx = clang_createIndex(/* excludeDeclsFromPCH */ - !strcmp(filter, "local") ? 1 : 0, - /* displayDiagnostics */ 1); - - TU = clang_createTranslationUnit(Idx, file); - - if (!TU) { - fprintf(stderr, "Unable to load translation unit from '%s'!\n", file); - return 1; - } - - /* Perform some simple filtering. */ - if (!strcmp(filter, "all") || !strcmp(filter, "local")) ck = NULL; - else if (!strcmp(filter, "category")) K = CXCursor_ObjCCategoryDecl; - else if (!strcmp(filter, "interface")) K = CXCursor_ObjCInterfaceDecl; - else if (!strcmp(filter, "protocol")) K = CXCursor_ObjCProtocolDecl; - else if (!strcmp(filter, "function")) K = CXCursor_FunctionDecl; - else if (!strcmp(filter, "typedef")) K = CXCursor_TypedefDecl; - else { - fprintf(stderr, "Unknown filter for -test-load-tu: %s\n", filter); - return 1; - } - - clang_loadTranslationUnit(TU, TranslationUnitVisitor, ck); - clang_disposeTranslationUnit(TU); - return 0; -} +/******************************************************************************/ +/* Command line processing. */ +/******************************************************************************/ static void print_usage(void) { fprintf(stderr, - "usage: c-index-test -code-completion-at= \n" - " c-index-test -test-load-tu \n\n" - " options for -test-load-tu:\n%s", - " all - load all symbols, including those from PCH\n" - " local - load all symbols except those in PCH\n" - " category - only load ObjC categories (non-PCH)\n" - " interface - only load ObjC interfaces (non-PCH)\n" - " protocol - only load ObjC protocols (non-PCH)\n" - " function - only load functions (non-PCH)\n" - " typedef - only load typdefs (non-PCH)\n\n"); + "usage: c-index-test -code-completion-at= \n" + " c-index-test -test-load-tu \n\n" + " options for -test-load-tu:\n%s", + " all - load all symbols, including those from PCH\n" + " local - load all symbols except those in PCH\n" + " category - only load ObjC categories (non-PCH)\n" + " interface - only load ObjC interfaces (non-PCH)\n" + " protocol - only load ObjC protocols (non-PCH)\n" + " function - only load functions (non-PCH)\n" + " typedef - only load typdefs (non-PCH)\n\n"); } int main(int argc, const char **argv) {