blob: 29f89e52a6e3da8bce5880c75a05c9ccb46cde4e [file] [log] [blame]
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +00001/*===-- 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|* *|
Marc-Andre Laperlef9abd402017-06-16 20:58:26 +000010|* This header provides a public interface to use CompilationDatabase without *|
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000011|* the full Clang C++ API. *|
12|* *|
13\*===----------------------------------------------------------------------===*/
14
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000015#ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
16#define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000017
18#include "clang-c/Platform.h"
19#include "clang-c/CXString.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/** \defgroup COMPILATIONDB CompilationDatabase functions
26 * \ingroup CINDEX
27 *
28 * @{
29 */
30
31/**
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +000032 * 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 Grandmaison0fe28a12012-06-30 11:27:57 +000035 *
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +000036 * Must be freed by \c clang_CompilationDatabase_dispose
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000037 */
38typedef 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 Grandmaisonfa6d73c2012-07-03 20:38:12 +000047 * \c clang_CompileCommands_dispose.
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000048 */
49typedef void * CXCompileCommands;
50
51/**
52 * \brief Represents the command line invocation to compile a specific file.
53 */
54typedef void * CXCompileCommand;
55
56/**
57 * \brief Error codes for Compilation Database
58 */
59typedef enum {
60 /*
Benjamin Kramer2501f142013-10-20 11:47:15 +000061 * \brief No error occurred
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000062 */
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 Grandmaisonfa6d73c2012-07-03 20:38:12 +000074 * 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 Grandmaison0fe28a12012-06-30 11:27:57 +000078 */
79CINDEX_LINKAGE CXCompilationDatabase
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +000080clang_CompilationDatabase_fromDirectory(const char *BuildDir,
81 CXCompilationDatabase_Error *ErrorCode);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000082
83/**
84 * \brief Free the given compilation database
85 */
86CINDEX_LINKAGE void
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +000087clang_CompilationDatabase_dispose(CXCompilationDatabase);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000088
89/**
90 * \brief Find the compile commands used for a file. The compile commands
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +000091 * must be freed by \c clang_CompileCommands_dispose.
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000092 */
93CINDEX_LINKAGE CXCompileCommands
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +000094clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
95 const char *CompleteFileName);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +000096
97/**
Argyrios Kyrtzidis251ad5e2012-12-04 07:26:44 +000098 * \brief Get all the compile commands in the given compilation database.
99 */
100CINDEX_LINKAGE CXCompileCommands
101clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase);
102
103/**
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000104 * \brief Free the given CompileCommands
105 */
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000106CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000107
108/**
109 * \brief Get the number of CompileCommand we have for a file
110 */
111CINDEX_LINKAGE unsigned
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000112clang_CompileCommands_getSize(CXCompileCommands);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000113
114/**
115 * \brief Get the I'th CompileCommand for a file
116 *
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000117 * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000118 */
119CINDEX_LINKAGE CXCompileCommand
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000120clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000121
122/**
123 * \brief Get the working directory where the CompileCommand was executed from
124 */
125CINDEX_LINKAGE CXString
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000126clang_CompileCommand_getDirectory(CXCompileCommand);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000127
128/**
Argyrios Kyrtzidis74bcd212015-09-11 20:43:05 +0000129 * \brief Get the filename associated with the CompileCommand.
130 */
131CINDEX_LINKAGE CXString
132clang_CompileCommand_getFilename(CXCompileCommand);
133
134/**
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000135 * \brief Get the number of arguments in the compiler invocation.
136 *
137 */
138CINDEX_LINKAGE unsigned
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000139clang_CompileCommand_getNumArgs(CXCompileCommand);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000140
141/**
142 * \brief Get the I'th argument value in the compiler invocations
143 *
144 * Invariant :
145 * - argument 0 is the compiler executable
146 */
147CINDEX_LINKAGE CXString
Arnaud A. de Grandmaisonfa6d73c2012-07-03 20:38:12 +0000148clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000149
150/**
Manuel Klimek6192c932013-11-13 13:23:27 +0000151 * \brief Get the number of source mappings for the compiler invocation.
152 */
153CINDEX_LINKAGE unsigned
154clang_CompileCommand_getNumMappedSources(CXCompileCommand);
155
156/**
157 * \brief Get the I'th mapped source path for the compiler invocation.
158 */
159CINDEX_LINKAGE CXString
160clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
161
162/**
163 * \brief Get the I'th mapped source content for the compiler invocation.
164 */
165CINDEX_LINKAGE CXString
166clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
167
168/**
Arnaud A. de Grandmaison0fe28a12012-06-30 11:27:57 +0000169 * @}
170 */
171
172#ifdef __cplusplus
173}
174#endif
175#endif
176