Skip to content

Instantly share code, notes, and snippets.

@sandeep-datta
Created May 19, 2012 14:17
Show Gist options
  • Select an option

  • Save sandeep-datta/2730964 to your computer and use it in GitHub Desktop.

Select an option

Save sandeep-datta/2730964 to your computer and use it in GitHub Desktop.
A C++ program to analyse a C/C++ file supplied through the command line using libclang
#include <clang-c/Index.h>
//Purpose: analyse a C/C++ file supplied through the command line using libclang
int main(int argc, char *argv[])
{
CXIndex index = clang_createIndex(0, 0);
CXTranslationUnit tu = clang_parseTranslationUnit(index, NULL,
argv, argc, NULL, 0, CXTranslationUnit_None);
for(unsigned i = 0, n = clang_getNumDiagnostics(tu); i != n; ++i)
{
CXDiagnostic diag = clang_getDiagnostic(tu, i);
unsigned options = clang_defaultDiagnosticDisplayOptions();
CXString str = clang_formatDiagnostic(diag, options);
fprintf(stderr, "%s\n", clang_getCString(str));
}
clang_disposeTranslationUnit(tu);
clang_disposeIndex(index);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment