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 module clang.c.CXCompilationDatabase;
16 
17 public import clang.c.CXString;
18 
19 extern (C):
20 
21 /** \defgroup COMPILATIONDB CompilationDatabase functions
22  * \ingroup CINDEX
23  *
24  * @{
25  */
26 
27 /**
28  * A compilation database holds all information used to compile files in a
29  * project. For each file in the database, it can be queried for the working
30  * directory or the command line used for the compiler invocation.
31  *
32  * Must be freed by \c clang_CompilationDatabase_dispose
33  */
34 alias CXCompilationDatabase = void*;
35 
36 /**
37  * Contains the results of a search in the compilation database
38  *
39  * When searching for the compile command for a file, the compilation db can
40  * return several commands, as the file may have been compiled with
41  * different options in different places of the project. This choice of compile
42  * commands is wrapped in this opaque data structure. It must be freed by
43  * \c clang_CompileCommands_dispose.
44  */
45 alias CXCompileCommands = void*;
46 
47 /**
48  * Represents the command line invocation to compile a specific file.
49  */
50 alias CXCompileCommand = void*;
51 
52 /**
53  * Error codes for Compilation Database
54  */
55 enum CXCompilationDatabase_Error
56 {
57     /*
58      * No error occurred
59      */
60     noError = 0,
61 
62     /*
63      * Database can not be loaded
64      */
65     canNotLoadDatabase = 1
66 }
67 
68 /**
69  * Creates a compilation database from the database found in directory
70  * buildDir. For example, CMake can output a compile_commands.json which can
71  * be used to build the database.
72  *
73  * It must be freed by \c clang_CompilationDatabase_dispose.
74  */
75 CXCompilationDatabase clang_CompilationDatabase_fromDirectory(
76     const(char)* BuildDir,
77     CXCompilationDatabase_Error* ErrorCode);
78 
79 /**
80  * Free the given compilation database
81  */
82 void clang_CompilationDatabase_dispose(CXCompilationDatabase);
83 
84 /**
85  * Find the compile commands used for a file. The compile commands
86  * must be freed by \c clang_CompileCommands_dispose.
87  */
88 CXCompileCommands clang_CompilationDatabase_getCompileCommands(
89     CXCompilationDatabase,
90     const(char)* CompleteFileName);
91 
92 /**
93  * Get all the compile commands in the given compilation database.
94  */
95 CXCompileCommands clang_CompilationDatabase_getAllCompileCommands(
96     CXCompilationDatabase);
97 
98 /**
99  * Free the given CompileCommands
100  */
101 void clang_CompileCommands_dispose(CXCompileCommands);
102 
103 /**
104  * Get the number of CompileCommand we have for a file
105  */
106 uint clang_CompileCommands_getSize(CXCompileCommands);
107 
108 /**
109  * Get the I'th CompileCommand for a file
110  *
111  * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
112  */
113 CXCompileCommand clang_CompileCommands_getCommand(CXCompileCommands, uint I);
114 
115 /**
116  * Get the working directory where the CompileCommand was executed from
117  */
118 CXString clang_CompileCommand_getDirectory(CXCompileCommand);
119 
120 /**
121  * Get the filename associated with the CompileCommand.
122  */
123 CXString clang_CompileCommand_getFilename(CXCompileCommand);
124 
125 /**
126  * Get the number of arguments in the compiler invocation.
127  *
128  */
129 uint clang_CompileCommand_getNumArgs(CXCompileCommand);
130 
131 /**
132  * Get the I'th argument value in the compiler invocations
133  *
134  * Invariant :
135  *  - argument 0 is the compiler executable
136  */
137 CXString clang_CompileCommand_getArg(CXCompileCommand, uint I);
138 
139 /**
140  * Get the number of source mappings for the compiler invocation.
141  */
142 uint clang_CompileCommand_getNumMappedSources(CXCompileCommand);
143 
144 /**
145  * Get the I'th mapped source path for the compiler invocation.
146  */
147 CXString clang_CompileCommand_getMappedSourcePath(CXCompileCommand, uint I);
148 
149 /**
150  * Get the I'th mapped source content for the compiler invocation.
151  */
152 CXString clang_CompileCommand_getMappedSourceContent(CXCompileCommand, uint I);
153 
154 /**
155  * @}
156  */
157