CXCompilationDatabase.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\
  2. |* *|
  3. |* The LLVM Compiler Infrastructure *|
  4. |* *|
  5. |* This file is distributed under the University of Illinois Open Source *|
  6. |* License. See LICENSE.TXT for details. *|
  7. |* *|
  8. |*===----------------------------------------------------------------------===*|
  9. |* *|
  10. |* This header provides a public inferface to use CompilationDatabase without *|
  11. |* the full Clang C++ API. *|
  12. |* *|
  13. \*===----------------------------------------------------------------------===*/
  14. #ifndef CLANG_CXCOMPILATIONDATABASE_H
  15. #define CLANG_CXCOMPILATIONDATABASE_H
  16. #include "clang-c/Platform.h"
  17. #include "clang-c/CXString.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /** \defgroup COMPILATIONDB CompilationDatabase functions
  22. * \ingroup CINDEX
  23. *
  24. * @{
  25. */
  26. /**
  27. * A compilation database holds all information used to compile files in a
  28. * project. For each file in the database, it can be queried for the working
  29. * directory or the command line used for the compiler invocation.
  30. *
  31. * Must be freed by \c clang_CompilationDatabase_dispose
  32. */
  33. typedef void * CXCompilationDatabase;
  34. /**
  35. * \brief Contains the results of a search in the compilation database
  36. *
  37. * When searching for the compile command for a file, the compilation db can
  38. * return several commands, as the file may have been compiled with
  39. * different options in different places of the project. This choice of compile
  40. * commands is wrapped in this opaque data structure. It must be freed by
  41. * \c clang_CompileCommands_dispose.
  42. */
  43. typedef void * CXCompileCommands;
  44. /**
  45. * \brief Represents the command line invocation to compile a specific file.
  46. */
  47. typedef void * CXCompileCommand;
  48. /**
  49. * \brief Error codes for Compilation Database
  50. */
  51. typedef enum {
  52. /*
  53. * \brief No error occured
  54. */
  55. CXCompilationDatabase_NoError = 0,
  56. /*
  57. * \brief Database can not be loaded
  58. */
  59. CXCompilationDatabase_CanNotLoadDatabase = 1
  60. } CXCompilationDatabase_Error;
  61. /**
  62. * \brief Creates a compilation database from the database found in directory
  63. * buildDir. For example, CMake can output a compile_commands.json which can
  64. * be used to build the database.
  65. *
  66. * It must be freed by \c clang_CompilationDatabase_dispose.
  67. */
  68. CINDEX_LINKAGE CXCompilationDatabase
  69. clang_CompilationDatabase_fromDirectory(const char *BuildDir,
  70. CXCompilationDatabase_Error *ErrorCode);
  71. /**
  72. * \brief Free the given compilation database
  73. */
  74. CINDEX_LINKAGE void
  75. clang_CompilationDatabase_dispose(CXCompilationDatabase);
  76. /**
  77. * \brief Find the compile commands used for a file. The compile commands
  78. * must be freed by \c clang_CompileCommands_dispose.
  79. */
  80. CINDEX_LINKAGE CXCompileCommands
  81. clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
  82. const char *CompleteFileName);
  83. /**
  84. * \brief Free the given CompileCommands
  85. */
  86. CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
  87. /**
  88. * \brief Get the number of CompileCommand we have for a file
  89. */
  90. CINDEX_LINKAGE unsigned
  91. clang_CompileCommands_getSize(CXCompileCommands);
  92. /**
  93. * \brief Get the I'th CompileCommand for a file
  94. *
  95. * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
  96. */
  97. CINDEX_LINKAGE CXCompileCommand
  98. clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
  99. /**
  100. * \brief Get the working directory where the CompileCommand was executed from
  101. */
  102. CINDEX_LINKAGE CXString
  103. clang_CompileCommand_getDirectory(CXCompileCommand);
  104. /**
  105. * \brief Get the number of arguments in the compiler invocation.
  106. *
  107. */
  108. CINDEX_LINKAGE unsigned
  109. clang_CompileCommand_getNumArgs(CXCompileCommand);
  110. /**
  111. * \brief Get the I'th argument value in the compiler invocations
  112. *
  113. * Invariant :
  114. * - argument 0 is the compiler executable
  115. */
  116. CINDEX_LINKAGE CXString
  117. clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
  118. /**
  119. * @}
  120. */
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif