Created
May 19, 2012 14:22
-
-
Save sandeep-datta/2730990 to your computer and use it in GitHub Desktop.
A D program to analyse a C/C++ file supplied through the command line using the D bindings for 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
| import std.stdio; | |
| import std.string; | |
| import deimos.clang.index; | |
| //Purpose: analyse a C/C++ file supplied through the command line using libclang | |
| //How to compile:- | |
| //dmd -c -gc testclang.d | |
| //g++ -g -I../llvm/tools/clang/include -L../llvm/build/Debug+Asserts/lib -o testclang testclang.o -lclang -lphobos2 -lrt | |
| //Note: libclang.so must be in the search path for this to work. | |
| void main(string[] args) | |
| { | |
| CXIndex index = clang_createIndex(0, 0); | |
| CXTranslationUnit tu = clang_parseTranslationUnit(index | |
| , cast(char*)std.string.toStringz(args[1]) | |
| , null | |
| , 0 | |
| , null | |
| , 0 | |
| , CXTranslationUnit_Flags.CXTranslationUnit_None); | |
| writefln("tu=%s", tu); | |
| for(uint i = 0, n = clang_getNumDiagnostics(tu); i != n; ++i) | |
| { | |
| CXDiagnostic diag = clang_getDiagnostic(tu, i); | |
| writefln("diag=%s", diag); | |
| uint options = clang_defaultDiagnosticDisplayOptions(); | |
| //BUG: Wrong calling convention used by the D compiler? | |
| CXString str = clang_formatDiagnostic(diag, options); | |
| stderr.writeln(clang_getCString(str)); | |
| } | |
| clang_disposeTranslationUnit(tu); | |
| clang_disposeIndex(index); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment