clang 8.0.0

CXCompilationDatabase.h
Go to the documentation of this file.
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 interface to use CompilationDatabase without *|
11 |* the full Clang C++ API. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
14
15 #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
16 #define LLVM_CLANG_C_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 /**
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.
35 *
36 * Must be freed by \c clang_CompilationDatabase_dispose
37 */
38 typedef void * CXCompilationDatabase;
39
40 /**
41 * 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
47 * \c clang_CompileCommands_dispose.
48 */
49 typedef void * CXCompileCommands;
50
51 /**
52 * Represents the command line invocation to compile a specific file.
53 */
54 typedef void * CXCompileCommand;
55
56 /**
57 * Error codes for Compilation Database
58 */
59 typedef enum {
60 /*
61 * No error occurred
62 */
63 CXCompilationDatabase_NoError = 0,
64
65 /*
66 * Database can not be loaded
67 */
68 CXCompilationDatabase_CanNotLoadDatabase = 1
69
70 } CXCompilationDatabase_Error;
71
72 /**
73 * Creates a compilation database from the database found in directory
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.
78 */
79 CINDEX_LINKAGE CXCompilationDatabase
80 clang_CompilationDatabase_fromDirectory(const char *BuildDir,
81 CXCompilationDatabase_Error *ErrorCode);
82
83 /**
84 * Free the given compilation database
85 */
86 CINDEX_LINKAGE void
87 clang_CompilationDatabase_dispose(CXCompilationDatabase);
88
89 /**
90 * Find the compile commands used for a file. The compile commands
91 * must be freed by \c clang_CompileCommands_dispose.
92 */
93 CINDEX_LINKAGE CXCompileCommands
94 clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
95 const char *CompleteFileName);
96
97 /**
98 * Get all the compile commands in the given compilation database.
99 */
100 CINDEX_LINKAGE CXCompileCommands
101 clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase);
102
103 /**
104 * Free the given CompileCommands
105 */
106 CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
107
108 /**
109 * Get the number of CompileCommand we have for a file
110 */
111 CINDEX_LINKAGE unsigned
112 clang_CompileCommands_getSize(CXCompileCommands);
113
114 /**
115 * Get the I'th CompileCommand for a file
116 *
117 * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
118 */
119 CINDEX_LINKAGE CXCompileCommand
120 clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
121
122 /**
123 * Get the working directory where the CompileCommand was executed from
124 */
125 CINDEX_LINKAGE CXString
126 clang_CompileCommand_getDirectory(CXCompileCommand);
127
128 /**
129 * Get the filename associated with the CompileCommand.
130 */
131 CINDEX_LINKAGE CXString
132 clang_CompileCommand_getFilename(CXCompileCommand);
133
134 /**
135 * Get the number of arguments in the compiler invocation.
136 *
137 */
138 CINDEX_LINKAGE unsigned
139 clang_CompileCommand_getNumArgs(CXCompileCommand);
140
141 /**
142 * Get the I'th argument value in the compiler invocations
143 *
144 * Invariant :
145 * - argument 0 is the compiler executable
146 */
147 CINDEX_LINKAGE CXString
148 clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
149
150 /**
151 * Get the number of source mappings for the compiler invocation.
152 */
153 CINDEX_LINKAGE unsigned
154 clang_CompileCommand_getNumMappedSources(CXCompileCommand);
155
156 /**
157 * Get the I'th mapped source path for the compiler invocation.
158 */
159 CINDEX_LINKAGE CXString
160 clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
161
162 /**
163 * Get the I'th mapped source content for the compiler invocation.
164 */
165 CINDEX_LINKAGE CXString
166 clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
167
168 /**
169 * @}
170 */
171
172 #ifdef __cplusplus
173 }
174 #endif
175 #endif
176
clang_CompileCommand_getNumMappedSources
CINDEX_LINKAGE unsigned clang_CompileCommand_getNumMappedSources(CXCompileCommand)
Get the number of source mappings for the compiler invocation.
CXCompileCommand
void * CXCompileCommand
Represents the command line invocation to compile a specific file.
Definition: CXCompilationDatabase.h:54
CINDEX_LINKAGE
#define CINDEX_LINKAGE
Definition: Platform.h:29
clang_CompilationDatabase_getCompileCommands
CINDEX_LINKAGE CXCompileCommands clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, const char *CompleteFileName)
Find the compile commands used for a file.
clang_CompilationDatabase_getAllCompileCommands
CINDEX_LINKAGE CXCompileCommands clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase)
Get all the compile commands in the given compilation database.
clang_CompilationDatabase_dispose
CINDEX_LINKAGE void clang_CompilationDatabase_dispose(CXCompilationDatabase)
Free the given compilation database.
clang_CompileCommand_getFilename
CINDEX_LINKAGE CXString clang_CompileCommand_getFilename(CXCompileCommand)
Get the filename associated with the CompileCommand.
clang_CompileCommands_getCommand
CINDEX_LINKAGE CXCompileCommand clang_CompileCommands_getCommand(CXCompileCommands, unsigned I)
Get the I&#39;th CompileCommand for a file.
CXCompilationDatabase_Error
CXCompilationDatabase_Error
Error codes for Compilation Database.
Definition: CXCompilationDatabase.h:59
clang_CompilationDatabase_fromDirectory
CINDEX_LINKAGE CXCompilationDatabase clang_CompilationDatabase_fromDirectory(const char *BuildDir, CXCompilationDatabase_Error *ErrorCode)
Creates a compilation database from the database found in directory buildDir.
CXCompilationDatabase_CanNotLoadDatabase
Definition: CXCompilationDatabase.h:68
CXString
A character string.
Definition: CXString.h:38
clang_CompileCommands_dispose
CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands)
Free the given CompileCommands.
CXCompilationDatabase
void * CXCompilationDatabase
A compilation database holds all information used to compile files in a project.
Definition: CXCompilationDatabase.h:38
clang_CompileCommand_getMappedSourcePath
CINDEX_LINKAGE CXString clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I)
Get the I&#39;th mapped source path for the compiler invocation.
clang_CompileCommands_getSize
CINDEX_LINKAGE unsigned clang_CompileCommands_getSize(CXCompileCommands)
Get the number of CompileCommand we have for a file.
clang_CompileCommand_getNumArgs
CINDEX_LINKAGE unsigned clang_CompileCommand_getNumArgs(CXCompileCommand)
Get the number of arguments in the compiler invocation.
CXCompileCommands
void * CXCompileCommands
Contains the results of a search in the compilation database.
Definition: CXCompilationDatabase.h:49
CXString.h
clang_CompileCommand_getMappedSourceContent
CINDEX_LINKAGE CXString clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I)
Get the I&#39;th mapped source content for the compiler invocation.
clang_CompileCommand_getArg
CINDEX_LINKAGE CXString clang_CompileCommand_getArg(CXCompileCommand, unsigned I)
Get the I&#39;th argument value in the compiler invocations.
CXCompilationDatabase_NoError
Definition: CXCompilationDatabase.h:63
clang_CompileCommand_getDirectory
CINDEX_LINKAGE CXString clang_CompileCommand_getDirectory(CXCompileCommand)
Get the working directory where the CompileCommand was executed from.
Platform.h