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