blob: 2669c1a792c1199d988f07b17bc37995681b7912 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001/*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\
2|* *|
Andrew Walbran16937d02019-10-22 13:54:20 +01003|* 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 *|
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01007|* *|
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
22extern "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 */
38typedef void * CXCompilationDatabase;
39
40/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010041 * Contains the results of a search in the compilation database
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010042 *
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 */
49typedef void * CXCompileCommands;
50
51/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010052 * Represents the command line invocation to compile a specific file.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010053 */
54typedef void * CXCompileCommand;
55
56/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010057 * Error codes for Compilation Database
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010058 */
59typedef enum {
60 /*
Andrew Scullcdfcccc2018-10-05 20:58:37 +010061 * No error occurred
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010062 */
63 CXCompilationDatabase_NoError = 0,
64
65 /*
Andrew Scullcdfcccc2018-10-05 20:58:37 +010066 * Database can not be loaded
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010067 */
68 CXCompilationDatabase_CanNotLoadDatabase = 1
69
70} CXCompilationDatabase_Error;
71
72/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010073 * Creates a compilation database from the database found in directory
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010074 * 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 */
79CINDEX_LINKAGE CXCompilationDatabase
80clang_CompilationDatabase_fromDirectory(const char *BuildDir,
81 CXCompilationDatabase_Error *ErrorCode);
82
83/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010084 * Free the given compilation database
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010085 */
86CINDEX_LINKAGE void
87clang_CompilationDatabase_dispose(CXCompilationDatabase);
88
89/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010090 * Find the compile commands used for a file. The compile commands
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010091 * must be freed by \c clang_CompileCommands_dispose.
92 */
93CINDEX_LINKAGE CXCompileCommands
94clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
95 const char *CompleteFileName);
96
97/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010098 * Get all the compile commands in the given compilation database.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010099 */
100CINDEX_LINKAGE CXCompileCommands
101clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase);
102
103/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100104 * Free the given CompileCommands
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100105 */
106CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
107
108/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100109 * Get the number of CompileCommand we have for a file
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100110 */
111CINDEX_LINKAGE unsigned
112clang_CompileCommands_getSize(CXCompileCommands);
113
114/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100115 * Get the I'th CompileCommand for a file
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100116 *
117 * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
118 */
119CINDEX_LINKAGE CXCompileCommand
120clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
121
122/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100123 * Get the working directory where the CompileCommand was executed from
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100124 */
125CINDEX_LINKAGE CXString
126clang_CompileCommand_getDirectory(CXCompileCommand);
127
128/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100129 * Get the filename associated with the CompileCommand.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100130 */
131CINDEX_LINKAGE CXString
132clang_CompileCommand_getFilename(CXCompileCommand);
133
134/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100135 * Get the number of arguments in the compiler invocation.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100136 *
137 */
138CINDEX_LINKAGE unsigned
139clang_CompileCommand_getNumArgs(CXCompileCommand);
140
141/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100142 * Get the I'th argument value in the compiler invocations
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100143 *
144 * Invariant :
145 * - argument 0 is the compiler executable
146 */
147CINDEX_LINKAGE CXString
148clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
149
150/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100151 * Get the number of source mappings for the compiler invocation.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100152 */
153CINDEX_LINKAGE unsigned
154clang_CompileCommand_getNumMappedSources(CXCompileCommand);
155
156/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100157 * Get the I'th mapped source path for the compiler invocation.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100158 */
159CINDEX_LINKAGE CXString
160clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
161
162/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100163 * Get the I'th mapped source content for the compiler invocation.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100164 */
165CINDEX_LINKAGE CXString
166clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
167
168/**
169 * @}
170 */
171
172#ifdef __cplusplus
173}
174#endif
175#endif
176