CXCompilationDatabase.h 5.1 KB

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