Organize c-index-test into logic sections, and add section headers.

llvm-svn: 89117
This commit is contained in:
Ted Kremenek 2009-11-17 18:13:31 +00:00
parent ba4e5da727
commit 1cd27d50b3
1 changed files with 62 additions and 42 deletions

View File

@ -5,6 +5,10 @@
#include <stdio.h>
#include <string.h>
/******************************************************************************/
/* 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=<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) {