Created
May 19, 2012 14:17
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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