Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 26th, 2012  |  syntax: D  |  size: 0.98 KB  |  views: 147  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import clang.c.index;
  2. import std.string;
  3.  
  4. extern (C) int printf(in char*, ...);
  5.  
  6. immutable(char*)* strToCArray (string[] arr)
  7. {
  8.     if (!arr)
  9.         return null;
  10.    
  11.     immutable(char*)[] cArr;
  12.     cArr.reserve(arr.length);
  13.    
  14.     foreach (str ; arr)
  15.         cArr ~= str.toStringz;
  16.    
  17.     return cArr.ptr;
  18. }
  19.  
  20. int main (string[] args)
  21. {
  22.     CXIndex Index = clang_createIndex(0, 0);
  23.     CXTranslationUnit TU = clang_parseTranslationUnit(Index, null, strToCArray(args), cast(uint) args.length, null, 0, CXTranslationUnit_Flags.CXTranslationUnit_None);
  24.  
  25.     for (uint I = 0, N = clang_getNumDiagnostics(TU); I != N; ++I)
  26.     {
  27.         CXDiagnostic Diag = clang_getDiagnostic(TU, I);
  28.         CXString String = clang_formatDiagnostic(Diag, clang_defaultDiagnosticDisplayOptions());
  29.         printf("%s\n", clang_getCString(String));
  30.  
  31.         clang_disposeString(String);
  32.     }
  33.  
  34.     clang_disposeTranslationUnit(TU);
  35.      clang_disposeIndex(Index);
  36.  
  37.      return 0;
  38. }
clone this paste RAW Paste Data