Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <clang-c/Index.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. CXIndex index;
  8. CXTranslationUnit tu;
  9. CXFile file;
  10. CXSourceLocation loc;
  11. CXCursor cursor, def;
  12. CXType type;
  13. CXString typesp;
  14. const char *types;
  15.  
  16. char const *args[2] = {"-x", "c++"};
  17. index = clang_createIndex(0, 0);
  18. tu = clang_createTranslationUnitFromSourceFile(index, argv[1],
  19. 2, args, 0, NULL);
  20. file = clang_getFile(tu, argv[1]);
  21. loc = clang_getLocation(tu, file, atoi(argv[2]), atoi(argv[3]));
  22. cursor = clang_getCursor(tu, loc);
  23.  
  24. if (clang_isPreprocessing(cursor.kind))
  25. printf("Preprocessorn");
  26. else {
  27. def = clang_getCursorDefinition(cursor);
  28. if (clang_Cursor_isNull(def))
  29. type = clang_getCursorType(cursor);
  30. else
  31. type = clang_getCursorType(def);
  32. typesp = clang_getTypeSpelling(type);
  33. types = clang_getCString(typesp);
  34. printf("%sn", types);
  35. clang_disposeString(typesp);
  36. }
  37. clang_disposeTranslationUnit(tu);
  38. clang_disposeIndex(index);
  39. }
  40.  
  41. #include <iostream>
  42.  
  43. int main()
  44. {
  45. long t;
  46. t = 0;
  47. std::cout << "Hello World!";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement