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

Daniel Dunbar daniel at zuster.org
Mon Nov 30 18:03:11 PST 2009


Author: ddunbar
Date: Mon Nov 30 20:03:10 2009
New Revision: 90187

URL: http://llvm.org/viewvc/llvm-project?rev=90187&view=rev
Log:
Add c-index-test -test-load-source, which loads the translation unit from a source file (and other command line arguments).

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=90187&r1=90186&r2=90187&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 30 20:03:10 2009
@@ -168,6 +168,38 @@
   return 0;
 }
 
+int perform_test_load_source(int argc, const char **argv, 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_createTranslationUnitFromSourceFile(Idx, 0, argc, argv);
+  if (!TU) {
+    fprintf(stderr, "Unable to load translation unit!\n");
+    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_getCursor().                                       */
 /******************************************************************************/
@@ -394,7 +426,8 @@
     "       c-index-test -test-file-scan <AST file> <source file> "
           "[FileCheck prefix]\n"
     "       c-index-test -test-load-tu <AST file> <symbol filter>\n\n"
-    " <symbol filter> options for -test-load-tu:\n%s",
+    "       c-index-test -test-load-source <symbol filter> {<args>}*\n\n"
+    " <symbol filter> options for -test-load-tu and -test-load-source:\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"
@@ -409,6 +442,8 @@
     return perform_code_completion(argc, argv);
   if (argc == 4 && strcmp(argv[1], "-test-load-tu") == 0)
     return perform_test_load_tu(argv[2], argv[3]);
+  if (argc >= 4 && strcmp(argv[1], "-test-load-source") == 0)
+    return perform_test_load_source(argc - 3, argv + 3, argv[2]);
   if (argc >= 4 && strcmp(argv[1], "-test-file-scan") == 0)
     return perform_file_scan(argv[2], argv[3],
                              argc >= 5 ? argv[4] : 0);





More information about the cfe-commits mailing list