10b57cec5SDimitry Andric /*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\ 20b57cec5SDimitry Andric |* *| 30b57cec5SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 40b57cec5SDimitry Andric |* Exceptions. *| 50b57cec5SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information. *| 60b57cec5SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 70b57cec5SDimitry Andric |* *| 80b57cec5SDimitry Andric |*===----------------------------------------------------------------------===*| 90b57cec5SDimitry Andric |* *| 100b57cec5SDimitry Andric |* This header provides a public interface to use CompilationDatabase without *| 110b57cec5SDimitry Andric |* the full Clang C++ API. *| 120b57cec5SDimitry Andric |* *| 130b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/ 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H 160b57cec5SDimitry Andric #define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric #include "clang-c/CXString.h" 19*480093f4SDimitry Andric #include "clang-c/ExternC.h" 20*480093f4SDimitry Andric #include "clang-c/Platform.h" 210b57cec5SDimitry Andric 22*480093f4SDimitry Andric LLVM_CLANG_C_EXTERN_C_BEGIN 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric /** \defgroup COMPILATIONDB CompilationDatabase functions 250b57cec5SDimitry Andric * \ingroup CINDEX 260b57cec5SDimitry Andric * 270b57cec5SDimitry Andric * @{ 280b57cec5SDimitry Andric */ 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric /** 310b57cec5SDimitry Andric * A compilation database holds all information used to compile files in a 320b57cec5SDimitry Andric * project. For each file in the database, it can be queried for the working 330b57cec5SDimitry Andric * directory or the command line used for the compiler invocation. 340b57cec5SDimitry Andric * 350b57cec5SDimitry Andric * Must be freed by \c clang_CompilationDatabase_dispose 360b57cec5SDimitry Andric */ 370b57cec5SDimitry Andric typedef void * CXCompilationDatabase; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric /** 400b57cec5SDimitry Andric * Contains the results of a search in the compilation database 410b57cec5SDimitry Andric * 420b57cec5SDimitry Andric * When searching for the compile command for a file, the compilation db can 430b57cec5SDimitry Andric * return several commands, as the file may have been compiled with 440b57cec5SDimitry Andric * different options in different places of the project. This choice of compile 450b57cec5SDimitry Andric * commands is wrapped in this opaque data structure. It must be freed by 460b57cec5SDimitry Andric * \c clang_CompileCommands_dispose. 470b57cec5SDimitry Andric */ 480b57cec5SDimitry Andric typedef void * CXCompileCommands; 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric /** 510b57cec5SDimitry Andric * Represents the command line invocation to compile a specific file. 520b57cec5SDimitry Andric */ 530b57cec5SDimitry Andric typedef void * CXCompileCommand; 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric /** 560b57cec5SDimitry Andric * Error codes for Compilation Database 570b57cec5SDimitry Andric */ 580b57cec5SDimitry Andric typedef enum { 590b57cec5SDimitry Andric /* 600b57cec5SDimitry Andric * No error occurred 610b57cec5SDimitry Andric */ 620b57cec5SDimitry Andric CXCompilationDatabase_NoError = 0, 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric /* 650b57cec5SDimitry Andric * Database can not be loaded 660b57cec5SDimitry Andric */ 670b57cec5SDimitry Andric CXCompilationDatabase_CanNotLoadDatabase = 1 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric } CXCompilationDatabase_Error; 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric /** 720b57cec5SDimitry Andric * Creates a compilation database from the database found in directory 730b57cec5SDimitry Andric * buildDir. For example, CMake can output a compile_commands.json which can 740b57cec5SDimitry Andric * be used to build the database. 750b57cec5SDimitry Andric * 760b57cec5SDimitry Andric * It must be freed by \c clang_CompilationDatabase_dispose. 770b57cec5SDimitry Andric */ 780b57cec5SDimitry Andric CINDEX_LINKAGE CXCompilationDatabase 790b57cec5SDimitry Andric clang_CompilationDatabase_fromDirectory(const char *BuildDir, 800b57cec5SDimitry Andric CXCompilationDatabase_Error *ErrorCode); 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric /** 830b57cec5SDimitry Andric * Free the given compilation database 840b57cec5SDimitry Andric */ 850b57cec5SDimitry Andric CINDEX_LINKAGE void 860b57cec5SDimitry Andric clang_CompilationDatabase_dispose(CXCompilationDatabase); 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric /** 890b57cec5SDimitry Andric * Find the compile commands used for a file. The compile commands 900b57cec5SDimitry Andric * must be freed by \c clang_CompileCommands_dispose. 910b57cec5SDimitry Andric */ 920b57cec5SDimitry Andric CINDEX_LINKAGE CXCompileCommands 930b57cec5SDimitry Andric clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, 940b57cec5SDimitry Andric const char *CompleteFileName); 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric /** 970b57cec5SDimitry Andric * Get all the compile commands in the given compilation database. 980b57cec5SDimitry Andric */ 990b57cec5SDimitry Andric CINDEX_LINKAGE CXCompileCommands 1000b57cec5SDimitry Andric clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase); 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric /** 1030b57cec5SDimitry Andric * Free the given CompileCommands 1040b57cec5SDimitry Andric */ 1050b57cec5SDimitry Andric CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands); 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric /** 1080b57cec5SDimitry Andric * Get the number of CompileCommand we have for a file 1090b57cec5SDimitry Andric */ 1100b57cec5SDimitry Andric CINDEX_LINKAGE unsigned 1110b57cec5SDimitry Andric clang_CompileCommands_getSize(CXCompileCommands); 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric /** 1140b57cec5SDimitry Andric * Get the I'th CompileCommand for a file 1150b57cec5SDimitry Andric * 1160b57cec5SDimitry Andric * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands) 1170b57cec5SDimitry Andric */ 1180b57cec5SDimitry Andric CINDEX_LINKAGE CXCompileCommand 1190b57cec5SDimitry Andric clang_CompileCommands_getCommand(CXCompileCommands, unsigned I); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric /** 1220b57cec5SDimitry Andric * Get the working directory where the CompileCommand was executed from 1230b57cec5SDimitry Andric */ 1240b57cec5SDimitry Andric CINDEX_LINKAGE CXString 1250b57cec5SDimitry Andric clang_CompileCommand_getDirectory(CXCompileCommand); 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andric /** 1280b57cec5SDimitry Andric * Get the filename associated with the CompileCommand. 1290b57cec5SDimitry Andric */ 1300b57cec5SDimitry Andric CINDEX_LINKAGE CXString 1310b57cec5SDimitry Andric clang_CompileCommand_getFilename(CXCompileCommand); 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric /** 1340b57cec5SDimitry Andric * Get the number of arguments in the compiler invocation. 1350b57cec5SDimitry Andric * 1360b57cec5SDimitry Andric */ 1370b57cec5SDimitry Andric CINDEX_LINKAGE unsigned 1380b57cec5SDimitry Andric clang_CompileCommand_getNumArgs(CXCompileCommand); 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric /** 1410b57cec5SDimitry Andric * Get the I'th argument value in the compiler invocations 1420b57cec5SDimitry Andric * 1430b57cec5SDimitry Andric * Invariant : 1440b57cec5SDimitry Andric * - argument 0 is the compiler executable 1450b57cec5SDimitry Andric */ 1460b57cec5SDimitry Andric CINDEX_LINKAGE CXString 1470b57cec5SDimitry Andric clang_CompileCommand_getArg(CXCompileCommand, unsigned I); 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andric /** 1500b57cec5SDimitry Andric * Get the number of source mappings for the compiler invocation. 1510b57cec5SDimitry Andric */ 1520b57cec5SDimitry Andric CINDEX_LINKAGE unsigned 1530b57cec5SDimitry Andric clang_CompileCommand_getNumMappedSources(CXCompileCommand); 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric /** 1560b57cec5SDimitry Andric * Get the I'th mapped source path for the compiler invocation. 1570b57cec5SDimitry Andric */ 1580b57cec5SDimitry Andric CINDEX_LINKAGE CXString 1590b57cec5SDimitry Andric clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I); 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric /** 1620b57cec5SDimitry Andric * Get the I'th mapped source content for the compiler invocation. 1630b57cec5SDimitry Andric */ 1640b57cec5SDimitry Andric CINDEX_LINKAGE CXString 1650b57cec5SDimitry Andric clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I); 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric /** 1680b57cec5SDimitry Andric * @} 1690b57cec5SDimitry Andric */ 1700b57cec5SDimitry Andric 171*480093f4SDimitry Andric LLVM_CLANG_C_EXTERN_C_END 172*480093f4SDimitry Andric 1730b57cec5SDimitry Andric #endif 1740b57cec5SDimitry Andric 175