Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | /*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\ |
| 2 | |* *| |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 *| |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 7 | |* *| |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* *| |
| 10 | |* This header provides a public interface to use CompilationDatabase without *| |
| 11 | |* the full Clang C++ API. *| |
| 12 | |* *| |
| 13 | \*===----------------------------------------------------------------------===*/ |
| 14 | |
| 15 | #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H |
| 16 | #define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H |
| 17 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 18 | #include "clang-c/CXString.h" |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 19 | #include "clang-c/ExternC.h" |
| 20 | #include "clang-c/Platform.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 21 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 22 | LLVM_CLANG_C_EXTERN_C_BEGIN |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 23 | |
| 24 | /** \defgroup COMPILATIONDB CompilationDatabase functions |
| 25 | * \ingroup CINDEX |
| 26 | * |
| 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 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 40 | * Contains the results of a search in the compilation database |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 41 | * |
| 42 | * When searching for the compile command for a file, the compilation db can |
| 43 | * return several commands, as the file may have been compiled with |
| 44 | * different options in different places of the project. This choice of compile |
| 45 | * commands is wrapped in this opaque data structure. It must be freed by |
| 46 | * \c clang_CompileCommands_dispose. |
| 47 | */ |
| 48 | typedef void * CXCompileCommands; |
| 49 | |
| 50 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 51 | * Represents the command line invocation to compile a specific file. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 52 | */ |
| 53 | typedef void * CXCompileCommand; |
| 54 | |
| 55 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 56 | * Error codes for Compilation Database |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 57 | */ |
| 58 | typedef enum { |
| 59 | /* |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 60 | * No error occurred |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 61 | */ |
| 62 | CXCompilationDatabase_NoError = 0, |
| 63 | |
| 64 | /* |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 65 | * Database can not be loaded |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 66 | */ |
| 67 | CXCompilationDatabase_CanNotLoadDatabase = 1 |
| 68 | |
| 69 | } CXCompilationDatabase_Error; |
| 70 | |
| 71 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 72 | * Creates a compilation database from the database found in directory |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 73 | * buildDir. For example, CMake can output a compile_commands.json which can |
| 74 | * be used to build the database. |
| 75 | * |
| 76 | * It must be freed by \c clang_CompilationDatabase_dispose. |
| 77 | */ |
| 78 | CINDEX_LINKAGE CXCompilationDatabase |
| 79 | clang_CompilationDatabase_fromDirectory(const char *BuildDir, |
| 80 | CXCompilationDatabase_Error *ErrorCode); |
| 81 | |
| 82 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 83 | * Free the given compilation database |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 84 | */ |
| 85 | CINDEX_LINKAGE void |
| 86 | clang_CompilationDatabase_dispose(CXCompilationDatabase); |
| 87 | |
| 88 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 89 | * Find the compile commands used for a file. The compile commands |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 90 | * must be freed by \c clang_CompileCommands_dispose. |
| 91 | */ |
| 92 | CINDEX_LINKAGE CXCompileCommands |
| 93 | clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, |
| 94 | const char *CompleteFileName); |
| 95 | |
| 96 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 97 | * Get all the compile commands in the given compilation database. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 98 | */ |
| 99 | CINDEX_LINKAGE CXCompileCommands |
| 100 | clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase); |
| 101 | |
| 102 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 103 | * Free the given CompileCommands |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 104 | */ |
| 105 | CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands); |
| 106 | |
| 107 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 108 | * Get the number of CompileCommand we have for a file |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 109 | */ |
| 110 | CINDEX_LINKAGE unsigned |
| 111 | clang_CompileCommands_getSize(CXCompileCommands); |
| 112 | |
| 113 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 114 | * Get the I'th CompileCommand for a file |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 115 | * |
| 116 | * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands) |
| 117 | */ |
| 118 | CINDEX_LINKAGE CXCompileCommand |
| 119 | clang_CompileCommands_getCommand(CXCompileCommands, unsigned I); |
| 120 | |
| 121 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 122 | * Get the working directory where the CompileCommand was executed from |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 123 | */ |
| 124 | CINDEX_LINKAGE CXString |
| 125 | clang_CompileCommand_getDirectory(CXCompileCommand); |
| 126 | |
| 127 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 128 | * Get the filename associated with the CompileCommand. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 129 | */ |
| 130 | CINDEX_LINKAGE CXString |
| 131 | clang_CompileCommand_getFilename(CXCompileCommand); |
| 132 | |
| 133 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 134 | * Get the number of arguments in the compiler invocation. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 135 | * |
| 136 | */ |
| 137 | CINDEX_LINKAGE unsigned |
| 138 | clang_CompileCommand_getNumArgs(CXCompileCommand); |
| 139 | |
| 140 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 141 | * Get the I'th argument value in the compiler invocations |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 142 | * |
| 143 | * Invariant : |
| 144 | * - argument 0 is the compiler executable |
| 145 | */ |
| 146 | CINDEX_LINKAGE CXString |
| 147 | clang_CompileCommand_getArg(CXCompileCommand, unsigned I); |
| 148 | |
| 149 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 150 | * Get the number of source mappings for the compiler invocation. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 151 | */ |
| 152 | CINDEX_LINKAGE unsigned |
| 153 | clang_CompileCommand_getNumMappedSources(CXCompileCommand); |
| 154 | |
| 155 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 156 | * Get the I'th mapped source path for the compiler invocation. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 157 | */ |
| 158 | CINDEX_LINKAGE CXString |
| 159 | clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I); |
| 160 | |
| 161 | /** |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 162 | * Get the I'th mapped source content for the compiler invocation. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 163 | */ |
| 164 | CINDEX_LINKAGE CXString |
| 165 | clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I); |
| 166 | |
| 167 | /** |
| 168 | * @} |
| 169 | */ |
| 170 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 171 | LLVM_CLANG_C_EXTERN_C_END |
| 172 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 173 | #endif |
| 174 | |