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