17330f729Sjoerg /*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\ 27330f729Sjoerg |* *| 37330f729Sjoerg |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 47330f729Sjoerg |* Exceptions. *| 57330f729Sjoerg |* See https://llvm.org/LICENSE.txt for license information. *| 67330f729Sjoerg |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 77330f729Sjoerg |* *| 87330f729Sjoerg |*===----------------------------------------------------------------------===*| 97330f729Sjoerg |* *| 107330f729Sjoerg |* This header provides a public interface to use CompilationDatabase without *| 117330f729Sjoerg |* the full Clang C++ API. *| 127330f729Sjoerg |* *| 137330f729Sjoerg \*===----------------------------------------------------------------------===*/ 147330f729Sjoerg 157330f729Sjoerg #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H 167330f729Sjoerg #define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H 177330f729Sjoerg 187330f729Sjoerg #include "clang-c/CXString.h" 19*e038c9c4Sjoerg #include "clang-c/ExternC.h" 20*e038c9c4Sjoerg #include "clang-c/Platform.h" 217330f729Sjoerg 22*e038c9c4Sjoerg LLVM_CLANG_C_EXTERN_C_BEGIN 237330f729Sjoerg 247330f729Sjoerg /** \defgroup COMPILATIONDB CompilationDatabase functions 257330f729Sjoerg * \ingroup CINDEX 267330f729Sjoerg * 277330f729Sjoerg * @{ 287330f729Sjoerg */ 297330f729Sjoerg 307330f729Sjoerg /** 317330f729Sjoerg * A compilation database holds all information used to compile files in a 327330f729Sjoerg * project. For each file in the database, it can be queried for the working 337330f729Sjoerg * directory or the command line used for the compiler invocation. 347330f729Sjoerg * 357330f729Sjoerg * Must be freed by \c clang_CompilationDatabase_dispose 367330f729Sjoerg */ 377330f729Sjoerg typedef void * CXCompilationDatabase; 387330f729Sjoerg 397330f729Sjoerg /** 407330f729Sjoerg * Contains the results of a search in the compilation database 417330f729Sjoerg * 427330f729Sjoerg * When searching for the compile command for a file, the compilation db can 437330f729Sjoerg * return several commands, as the file may have been compiled with 447330f729Sjoerg * different options in different places of the project. This choice of compile 457330f729Sjoerg * commands is wrapped in this opaque data structure. It must be freed by 467330f729Sjoerg * \c clang_CompileCommands_dispose. 477330f729Sjoerg */ 487330f729Sjoerg typedef void * CXCompileCommands; 497330f729Sjoerg 507330f729Sjoerg /** 517330f729Sjoerg * Represents the command line invocation to compile a specific file. 527330f729Sjoerg */ 537330f729Sjoerg typedef void * CXCompileCommand; 547330f729Sjoerg 557330f729Sjoerg /** 567330f729Sjoerg * Error codes for Compilation Database 577330f729Sjoerg */ 587330f729Sjoerg typedef enum { 597330f729Sjoerg /* 607330f729Sjoerg * No error occurred 617330f729Sjoerg */ 627330f729Sjoerg CXCompilationDatabase_NoError = 0, 637330f729Sjoerg 647330f729Sjoerg /* 657330f729Sjoerg * Database can not be loaded 667330f729Sjoerg */ 677330f729Sjoerg CXCompilationDatabase_CanNotLoadDatabase = 1 687330f729Sjoerg 697330f729Sjoerg } CXCompilationDatabase_Error; 707330f729Sjoerg 717330f729Sjoerg /** 727330f729Sjoerg * Creates a compilation database from the database found in directory 737330f729Sjoerg * buildDir. For example, CMake can output a compile_commands.json which can 747330f729Sjoerg * be used to build the database. 757330f729Sjoerg * 767330f729Sjoerg * It must be freed by \c clang_CompilationDatabase_dispose. 777330f729Sjoerg */ 787330f729Sjoerg CINDEX_LINKAGE CXCompilationDatabase 797330f729Sjoerg clang_CompilationDatabase_fromDirectory(const char *BuildDir, 807330f729Sjoerg CXCompilationDatabase_Error *ErrorCode); 817330f729Sjoerg 827330f729Sjoerg /** 837330f729Sjoerg * Free the given compilation database 847330f729Sjoerg */ 857330f729Sjoerg CINDEX_LINKAGE void 867330f729Sjoerg clang_CompilationDatabase_dispose(CXCompilationDatabase); 877330f729Sjoerg 887330f729Sjoerg /** 897330f729Sjoerg * Find the compile commands used for a file. The compile commands 907330f729Sjoerg * must be freed by \c clang_CompileCommands_dispose. 917330f729Sjoerg */ 927330f729Sjoerg CINDEX_LINKAGE CXCompileCommands 937330f729Sjoerg clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, 947330f729Sjoerg const char *CompleteFileName); 957330f729Sjoerg 967330f729Sjoerg /** 977330f729Sjoerg * Get all the compile commands in the given compilation database. 987330f729Sjoerg */ 997330f729Sjoerg CINDEX_LINKAGE CXCompileCommands 1007330f729Sjoerg clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase); 1017330f729Sjoerg 1027330f729Sjoerg /** 1037330f729Sjoerg * Free the given CompileCommands 1047330f729Sjoerg */ 1057330f729Sjoerg CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands); 1067330f729Sjoerg 1077330f729Sjoerg /** 1087330f729Sjoerg * Get the number of CompileCommand we have for a file 1097330f729Sjoerg */ 1107330f729Sjoerg CINDEX_LINKAGE unsigned 1117330f729Sjoerg clang_CompileCommands_getSize(CXCompileCommands); 1127330f729Sjoerg 1137330f729Sjoerg /** 1147330f729Sjoerg * Get the I'th CompileCommand for a file 1157330f729Sjoerg * 1167330f729Sjoerg * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands) 1177330f729Sjoerg */ 1187330f729Sjoerg CINDEX_LINKAGE CXCompileCommand 1197330f729Sjoerg clang_CompileCommands_getCommand(CXCompileCommands, unsigned I); 1207330f729Sjoerg 1217330f729Sjoerg /** 1227330f729Sjoerg * Get the working directory where the CompileCommand was executed from 1237330f729Sjoerg */ 1247330f729Sjoerg CINDEX_LINKAGE CXString 1257330f729Sjoerg clang_CompileCommand_getDirectory(CXCompileCommand); 1267330f729Sjoerg 1277330f729Sjoerg /** 1287330f729Sjoerg * Get the filename associated with the CompileCommand. 1297330f729Sjoerg */ 1307330f729Sjoerg CINDEX_LINKAGE CXString 1317330f729Sjoerg clang_CompileCommand_getFilename(CXCompileCommand); 1327330f729Sjoerg 1337330f729Sjoerg /** 1347330f729Sjoerg * Get the number of arguments in the compiler invocation. 1357330f729Sjoerg * 1367330f729Sjoerg */ 1377330f729Sjoerg CINDEX_LINKAGE unsigned 1387330f729Sjoerg clang_CompileCommand_getNumArgs(CXCompileCommand); 1397330f729Sjoerg 1407330f729Sjoerg /** 1417330f729Sjoerg * Get the I'th argument value in the compiler invocations 1427330f729Sjoerg * 1437330f729Sjoerg * Invariant : 1447330f729Sjoerg * - argument 0 is the compiler executable 1457330f729Sjoerg */ 1467330f729Sjoerg CINDEX_LINKAGE CXString 1477330f729Sjoerg clang_CompileCommand_getArg(CXCompileCommand, unsigned I); 1487330f729Sjoerg 1497330f729Sjoerg /** 1507330f729Sjoerg * Get the number of source mappings for the compiler invocation. 1517330f729Sjoerg */ 1527330f729Sjoerg CINDEX_LINKAGE unsigned 1537330f729Sjoerg clang_CompileCommand_getNumMappedSources(CXCompileCommand); 1547330f729Sjoerg 1557330f729Sjoerg /** 1567330f729Sjoerg * Get the I'th mapped source path for the compiler invocation. 1577330f729Sjoerg */ 1587330f729Sjoerg CINDEX_LINKAGE CXString 1597330f729Sjoerg clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I); 1607330f729Sjoerg 1617330f729Sjoerg /** 1627330f729Sjoerg * Get the I'th mapped source content for the compiler invocation. 1637330f729Sjoerg */ 1647330f729Sjoerg CINDEX_LINKAGE CXString 1657330f729Sjoerg clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I); 1667330f729Sjoerg 1677330f729Sjoerg /** 1687330f729Sjoerg * @} 1697330f729Sjoerg */ 1707330f729Sjoerg 171*e038c9c4Sjoerg LLVM_CLANG_C_EXTERN_C_END 172*e038c9c4Sjoerg 1737330f729Sjoerg #endif 1747330f729Sjoerg 175