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