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