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