clang 20.0.0git
CXCompilationDatabase.h
Go to the documentation of this file.
1/*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\
2|* *|
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
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/CXString.h"
19#include "clang-c/ExternC.h"
20#include "clang-c/Platform.h"
21
23
24/** \defgroup COMPILATIONDB CompilationDatabase functions
25 * \ingroup CINDEX
26 *
27 * @{
28 */
29
30/**
31 * A compilation database holds all information used to compile files in a
32 * project. For each file in the database, it can be queried for the working
33 * directory or the command line used for the compiler invocation.
34 *
35 * Must be freed by \c clang_CompilationDatabase_dispose
36 */
37typedef void * CXCompilationDatabase;
38
39/**
40 * Contains the results of a search in the compilation database
41 *
42 * When searching for the compile command for a file, the compilation db can
43 * return several commands, as the file may have been compiled with
44 * different options in different places of the project. This choice of compile
45 * commands is wrapped in this opaque data structure. It must be freed by
46 * \c clang_CompileCommands_dispose.
47 */
48typedef void * CXCompileCommands;
49
50/**
51 * Represents the command line invocation to compile a specific file.
52 */
53typedef void * CXCompileCommand;
54
55/**
56 * Error codes for Compilation Database
57 */
58typedef enum {
59 /*
60 * No error occurred
61 */
63
64 /*
65 * Database can not be loaded
66 */
68
70
71/**
72 * Creates a compilation database from the database found in directory
73 * buildDir. For example, CMake can output a compile_commands.json which can
74 * be used to build the database.
75 *
76 * It must be freed by \c clang_CompilationDatabase_dispose.
77 */
81
82/**
83 * Free the given compilation database
84 */
87
88/**
89 * Find the compile commands used for a file. The compile commands
90 * must be freed by \c clang_CompileCommands_dispose.
91 */
94 const char *CompleteFileName);
95
96/**
97 * Get all the compile commands in the given compilation database.
98 */
101
102/**
103 * Free the given CompileCommands
104 */
106
107/**
108 * Get the number of CompileCommand we have for a file
109 */
110CINDEX_LINKAGE unsigned
112
113/**
114 * Get the I'th CompileCommand for a file
115 *
116 * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
117 */
120
121/**
122 * Get the working directory where the CompileCommand was executed from
123 */
126
127/**
128 * Get the filename associated with the CompileCommand.
129 */
132
133/**
134 * Get the number of arguments in the compiler invocation.
135 *
136 */
137CINDEX_LINKAGE unsigned
139
140/**
141 * Get the I'th argument value in the compiler invocations
142 *
143 * Invariant :
144 * - argument 0 is the compiler executable
145 */
148
149/**
150 * Get the number of source mappings for the compiler invocation.
151 */
152CINDEX_LINKAGE unsigned
154
155/**
156 * Get the I'th mapped source path for the compiler invocation.
157 */
160
161/**
162 * Get the I'th mapped source content for the compiler invocation.
163 */
166
167/**
168 * @}
169 */
170
172
173#endif
174
#define LLVM_CLANG_C_EXTERN_C_END
Definition: ExternC.h:36
#define LLVM_CLANG_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define CINDEX_LINKAGE
Definition: Platform.h:38
CINDEX_LINKAGE unsigned clang_CompileCommands_getSize(CXCompileCommands)
Get the number of CompileCommand we have for a file.
CINDEX_LINKAGE unsigned clang_CompileCommand_getNumMappedSources(CXCompileCommand)
Get the number of source mappings for the compiler invocation.
CINDEX_LINKAGE CXCompileCommands clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase)
Get all the compile commands in the given compilation database.
CINDEX_LINKAGE CXString clang_CompileCommand_getArg(CXCompileCommand, unsigned I)
Get the I'th argument value in the compiler invocations.
CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands)
Free the given CompileCommands.
CINDEX_LINKAGE CXString clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I)
Get the I'th mapped source path for the compiler invocation.
CINDEX_LINKAGE void clang_CompilationDatabase_dispose(CXCompilationDatabase)
Free the given compilation database.
CINDEX_LINKAGE CXString clang_CompileCommand_getDirectory(CXCompileCommand)
Get the working directory where the CompileCommand was executed from.
void * CXCompileCommands
Contains the results of a search in the compilation database.
CINDEX_LINKAGE CXCompileCommands clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, const char *CompleteFileName)
Find the compile commands used for a file.
CINDEX_LINKAGE CXCompilationDatabase clang_CompilationDatabase_fromDirectory(const char *BuildDir, CXCompilationDatabase_Error *ErrorCode)
Creates a compilation database from the database found in directory buildDir.
CINDEX_LINKAGE CXString clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I)
Get the I'th mapped source content for the compiler invocation.
void * CXCompileCommand
Represents the command line invocation to compile a specific file.
CINDEX_LINKAGE CXCompileCommand clang_CompileCommands_getCommand(CXCompileCommands, unsigned I)
Get the I'th CompileCommand for a file.
CINDEX_LINKAGE CXString clang_CompileCommand_getFilename(CXCompileCommand)
Get the filename associated with the CompileCommand.
CINDEX_LINKAGE unsigned clang_CompileCommand_getNumArgs(CXCompileCommand)
Get the number of arguments in the compiler invocation.
void * CXCompilationDatabase
A compilation database holds all information used to compile files in a project.
CXCompilationDatabase_Error
Error codes for Compilation Database.
@ CXCompilationDatabase_NoError
@ CXCompilationDatabase_CanNotLoadDatabase
A character string.
Definition: CXString.h:37