[cfe-commits] r89117 - /cfe/trunk/tools/c-index-test/c-index-test.c

Ted Kremenek kremenek at apple.com
Tue Nov 17 10:13:32 PST 2009


Author: kremenek
Date: Tue Nov 17 12:13:31 2009
New Revision: 89117

URL: http://llvm.org/viewvc/llvm-project?rev=89117&view=rev
Log:
Organize c-index-test into logic sections, and add section headers.

Modified:
    cfe/trunk/tools/c-index-test/c-index-test.c

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=89117&r1=89116&r2=89117&view=diff

==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Nov 17 12:13:31 2009
@@ -5,6 +5,10 @@
 #include <stdio.h>
 #include <string.h>
 
+/******************************************************************************/
+/* Utility functions.                                                         */
+/******************************************************************************/
+
 #ifdef _MSC_VER
 char *basename(const char* path)
 {
@@ -23,6 +27,10 @@
 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 @@
   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 @@
   }
 }
 
+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 @@
   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=<site> <compiler arguments>\n"
-  "       c-index-test -test-load-tu <AST file> <symbol filter>\n\n"
-          " <symbol filter> 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=<site> <compiler arguments>\n"
+    "       c-index-test -test-load-tu <AST file> <symbol filter>\n\n"
+    " <symbol filter> 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) {





More information about the cfe-commits mailing list