/* c-index-test.c */
#include "clang-c/Index.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
/******************************************************************************/
/* Utility functions. */
/******************************************************************************/
#ifdef _MSC_VER
char *basename(const char* path)
{
char* base1 = (char*)strrchr(path, '/');
char* base2 = (char*)strrchr(path, '\\');
if (base1 && base2)
return((base1 > base2) ? base1 + 1 : base2 + 1);
else if (base1)
return(base1 + 1);
else if (base2)
return(base2 + 1);
return((char*)path);
}
#else
extern char *basename(const char *);
#endif
/** \brief Return the default parsing options. */
static unsigned getDefaultParsingOptions() {
unsigned options = CXTranslationUnit_DetailedPreprocessingRecord;
if (getenv("CINDEXTEST_EDITING"))
options |= CXTranslationUnit_Editing;
return options;
}
static void PrintExtent(FILE *out, unsigned begin_line, unsigned begin_column,
unsigned end_line, unsigned end_column) {
fprintf(out, "[%d:%d - %d:%d]", begin_line, begin_column,
end_line, end_column);
}
static unsigned CreateTranslationUnit(CXIndex Idx, const char *file,
CXTranslationUnit *TU) {
*TU = clang_createTranslationUnit(Idx, file);
if (!*TU) {
fprintf(stderr, "Unable to load translation unit