CXCompilationDatabase.h 5.3 KB

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