blob: eece5fb975696521441f0f83d7cb3d6a11bb76e9 [file] [log] [blame]
Ted Kremenekb60d87c2009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- 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 inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
Chandler Carruthaacafe52009-12-17 09:27:29 +000019#include <time.h>
Steve Naroff6231f182009-10-27 14:35:18 +000020
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000021#include "clang-c/Platform.h"
22#include "clang-c/CXString.h"
Argyrios Kyrtzidis09a439d2014-02-25 03:59:16 +000023#include "clang-c/BuildSystem.h"
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000024
Argyrios Kyrtzidis1c4db8d2012-11-06 21:21:49 +000025/**
26 * \brief The version constants for the libclang API.
27 * CINDEX_VERSION_MINOR should increase when there are API additions.
28 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
29 *
30 * The policy about the libclang API was always to keep it source and ABI
31 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
32 */
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000033#define CINDEX_VERSION_MAJOR 0
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +000034#define CINDEX_VERSION_MINOR 23
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000035
36#define CINDEX_VERSION_ENCODE(major, minor) ( \
37 ((major) * 10000) \
38 + ((minor) * 1))
39
40#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
41 CINDEX_VERSION_MAJOR, \
42 CINDEX_VERSION_MINOR )
43
44#define CINDEX_VERSION_STRINGIZE_(major, minor) \
45 #major"."#minor
46#define CINDEX_VERSION_STRINGIZE(major, minor) \
47 CINDEX_VERSION_STRINGIZE_(major, minor)
48
49#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
50 CINDEX_VERSION_MAJOR, \
51 CINDEX_VERSION_MINOR)
52
Ted Kremenekb60d87c2009-08-26 22:36:44 +000053#ifdef __cplusplus
54extern "C" {
55#endif
56
Douglas Gregor4a4e0eb2011-02-23 17:45:25 +000057/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor52606ff2010-01-20 01:10:47 +000058 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000059 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorc8e390c2010-01-20 22:45:41 +000060 * facilities for parsing source code into an abstract syntax tree (AST),
61 * loading already-parsed ASTs, traversing the AST, associating
62 * physical source locations with elements within the AST, and other
63 * facilities that support Clang-based development tools.
Douglas Gregor52606ff2010-01-20 01:10:47 +000064 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000065 * This C interface to Clang will never provide all of the information
Douglas Gregorc8e390c2010-01-20 22:45:41 +000066 * representation stored in Clang's C++ AST, nor should it: the intent is to
67 * maintain an API that is relatively stable from one release to the next,
68 * providing only the basic functionality needed to support development tools.
Daniel Dunbar62ebf252010-01-24 02:54:26 +000069 *
70 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorc8e390c2010-01-20 22:45:41 +000071 * functions are prefixed with "clang_".
Douglas Gregor52606ff2010-01-20 01:10:47 +000072 *
73 * @{
74 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +000075
Douglas Gregor802f12f2010-01-20 22:28:27 +000076/**
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +000077 * \brief Error codes returned by libclang routines.
78 *
79 * Zero (\c CXError_Success) is the only error code indicating success. Other
80 * error codes, including not yet assigned non-zero values, indicate errors.
81 */
82enum CXErrorCode {
83 /**
84 * \brief No error.
85 */
86 CXError_Success = 0,
87
88 /**
89 * \brief A generic error code, no further details are available.
90 *
91 * Errors of this kind can get their own specific error codes in future
92 * libclang versions.
93 */
94 CXError_Failure = 1,
95
96 /**
97 * \brief libclang crashed while performing the requested operation.
98 */
99 CXError_Crashed = 2,
100
101 /**
102 * \brief The function detected that the arguments violate the function
103 * contract.
104 */
105 CXError_InvalidArguments = 3,
106
107 /**
108 * \brief An AST deserialization error has occurred.
109 */
110 CXError_ASTReadError = 4
111};
112
113/**
Douglas Gregor802f12f2010-01-20 22:28:27 +0000114 * \brief An "index" that consists of a set of translation units that would
115 * typically be linked together into an executable or library.
116 */
117typedef void *CXIndex;
Steve Naroffd5e8e862009-08-27 19:51:58 +0000118
Douglas Gregor802f12f2010-01-20 22:28:27 +0000119/**
120 * \brief A single translation unit, which resides in an index.
121 */
Ted Kremenek7df92ae2010-11-17 23:24:11 +0000122typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroffd5e8e862009-08-27 19:51:58 +0000123
Douglas Gregor802f12f2010-01-20 22:28:27 +0000124/**
Douglas Gregor6007cf22010-01-22 22:29:16 +0000125 * \brief Opaque pointer representing client data that will be passed through
126 * to various callbacks and visitors.
Douglas Gregor802f12f2010-01-20 22:28:27 +0000127 */
Douglas Gregor6007cf22010-01-22 22:29:16 +0000128typedef void *CXClientData;
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000129
Douglas Gregor9485bf92009-12-02 09:21:34 +0000130/**
131 * \brief Provides the contents of a file that has not yet been saved to disk.
132 *
133 * Each CXUnsavedFile instance provides the name of a file on the
134 * system along with the current contents of that file that have not
135 * yet been saved to disk.
136 */
137struct CXUnsavedFile {
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000138 /**
139 * \brief The file whose contents have not yet been saved.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000140 *
141 * This file must already exist in the file system.
142 */
143 const char *Filename;
144
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000145 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000146 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000147 */
148 const char *Contents;
149
150 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000151 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000152 */
153 unsigned long Length;
154};
155
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000156/**
157 * \brief Describes the availability of a particular entity, which indicates
158 * whether the use of this entity will result in a warning or error due to
159 * it being deprecated or unavailable.
160 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000161enum CXAvailabilityKind {
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000162 /**
163 * \brief The entity is available.
164 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000165 CXAvailability_Available,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000166 /**
167 * \brief The entity is available, but has been deprecated (and its use is
168 * not recommended).
169 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000170 CXAvailability_Deprecated,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000171 /**
172 * \brief The entity is not available; any use of it will be an error.
173 */
Erik Verbruggen2e657ff2011-10-06 07:27:49 +0000174 CXAvailability_NotAvailable,
175 /**
176 * \brief The entity is available, but not accessible; any use of it will be
177 * an error.
178 */
179 CXAvailability_NotAccessible
Douglas Gregorf757a122010-08-23 23:00:57 +0000180};
Douglas Gregord6225d32012-05-08 00:14:45 +0000181
182/**
183 * \brief Describes a version number of the form major.minor.subminor.
184 */
185typedef struct CXVersion {
186 /**
187 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
188 * value indicates that there is no version number at all.
189 */
190 int Major;
191 /**
192 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
193 * will be negative if no minor version number was provided, e.g., for
194 * version '10'.
195 */
196 int Minor;
197 /**
198 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
199 * will be negative if no minor or subminor version number was provided,
200 * e.g., in version '10' or '10.7'.
201 */
202 int Subminor;
203} CXVersion;
Douglas Gregorf757a122010-08-23 23:00:57 +0000204
Douglas Gregor802f12f2010-01-20 22:28:27 +0000205/**
James Dennett574cb4c2012-06-15 05:41:51 +0000206 * \brief Provides a shared context for creating translation units.
207 *
208 * It provides two options:
Steve Naroff531e2842009-10-20 14:46:24 +0000209 *
210 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
211 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000212 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroff531e2842009-10-20 14:46:24 +0000213 * header that was used by the translation unit. If zero, all declarations
214 * will be enumerated.
215 *
Steve Naroffbb4568a2009-10-20 16:36:34 +0000216 * Here is an example:
217 *
James Dennett574cb4c2012-06-15 05:41:51 +0000218 * \code
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000219 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
220 * Idx = clang_createIndex(1, 1);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000221 *
222 * // IndexTest.pch was produced with the following command:
223 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
224 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
225 *
226 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000227 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor990b5762010-01-20 21:37:00 +0000228 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000229 * clang_disposeTranslationUnit(TU);
230 *
231 * // This will load all the symbols from 'IndexTest.c', excluding symbols
232 * // from 'IndexTest.pch'.
Daniel Dunbard0159262010-01-25 00:43:14 +0000233 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
234 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
235 * 0, 0);
Douglas Gregorfed36b12010-01-20 23:57:43 +0000236 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
237 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000238 * clang_disposeTranslationUnit(TU);
James Dennett574cb4c2012-06-15 05:41:51 +0000239 * \endcode
Steve Naroffbb4568a2009-10-20 16:36:34 +0000240 *
241 * This process of creating the 'pch', loading it separately, and using it (via
242 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
243 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroff531e2842009-10-20 14:46:24 +0000244 */
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000245CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
246 int displayDiagnostics);
Ted Kremenekd071c602010-03-13 02:50:34 +0000247
Douglas Gregor408bb742010-02-08 23:03:06 +0000248/**
249 * \brief Destroy the given index.
250 *
251 * The index must not be destroyed until all of the translation units created
252 * within that index have been destroyed.
253 */
Daniel Dunbar11089662009-12-03 01:54:28 +0000254CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000255
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000256typedef enum {
257 /**
258 * \brief Used to indicate that no special CXIndex options are needed.
259 */
260 CXGlobalOpt_None = 0x0,
261
262 /**
263 * \brief Used to indicate that threads that libclang creates for indexing
264 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000265 *
266 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
267 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000268 */
269 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
270
271 /**
272 * \brief Used to indicate that threads that libclang creates for editing
273 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000274 *
275 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
276 * #clang_annotateTokens
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000277 */
278 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
279
280 /**
281 * \brief Used to indicate that all threads that libclang creates should use
282 * background priority.
283 */
284 CXGlobalOpt_ThreadBackgroundPriorityForAll =
285 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
286 CXGlobalOpt_ThreadBackgroundPriorityForEditing
287
288} CXGlobalOptFlags;
289
290/**
James Dennett574cb4c2012-06-15 05:41:51 +0000291 * \brief Sets general options associated with a CXIndex.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000292 *
293 * For example:
294 * \code
295 * CXIndex idx = ...;
296 * clang_CXIndex_setGlobalOptions(idx,
297 * clang_CXIndex_getGlobalOptions(idx) |
298 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
299 * \endcode
300 *
301 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
302 */
303CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
304
305/**
306 * \brief Gets the general options associated with a CXIndex.
307 *
308 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
309 * are associated with the given CXIndex object.
310 */
311CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
312
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000313/**
Douglas Gregor6007cf22010-01-22 22:29:16 +0000314 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000315 *
316 * @{
317 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000318
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000319/**
320 * \brief A particular source file that is part of a translation unit.
321 */
322typedef void *CXFile;
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000323
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000324
325/**
326 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff6231f182009-10-27 14:35:18 +0000327 */
Ted Kremenekc560b682010-02-17 00:41:20 +0000328CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000329
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000330/**
331 * \brief Retrieve the last modification time of the given file.
332 */
Douglas Gregor249c1212009-10-31 15:48:08 +0000333CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff6231f182009-10-27 14:35:18 +0000334
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000335/**
Argyrios Kyrtzidisac08b262013-01-26 04:52:52 +0000336 * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
337 * across an indexing session.
338 */
339typedef struct {
340 unsigned long long data[3];
341} CXFileUniqueID;
342
343/**
344 * \brief Retrieve the unique ID for the given \c file.
345 *
346 * \param file the file to get the ID for.
347 * \param outID stores the returned CXFileUniqueID.
348 * \returns If there was a failure getting the unique ID, returns non-zero,
349 * otherwise returns 0.
350*/
351CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
352
353/**
Douglas Gregor37aa4932011-05-04 00:14:37 +0000354 * \brief Determine whether the given header is guarded against
355 * multiple inclusions, either with the conventional
James Dennett574cb4c2012-06-15 05:41:51 +0000356 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
Douglas Gregor37aa4932011-05-04 00:14:37 +0000357 */
358CINDEX_LINKAGE unsigned
359clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
360
361/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000362 * \brief Retrieve a file handle within the given translation unit.
363 *
364 * \param tu the translation unit
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000365 *
Douglas Gregor816fd362010-01-22 21:44:22 +0000366 * \param file_name the name of the file.
367 *
368 * \returns the file handle for the named file in the translation unit \p tu,
369 * or a NULL file handle if the file was not a part of this translation unit.
370 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000371CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregor816fd362010-01-22 21:44:22 +0000372 const char *file_name);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000373
Douglas Gregor816fd362010-01-22 21:44:22 +0000374/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000375 * @}
376 */
377
378/**
379 * \defgroup CINDEX_LOCATIONS Physical source locations
380 *
381 * Clang represents physical source locations in its abstract syntax tree in
382 * great detail, with file, line, and column information for the majority of
383 * the tokens parsed in the source code. These data types and functions are
384 * used to represent source location information, either for a particular
385 * point in the program or for a range of points in the program, and extract
386 * specific location information from those data types.
387 *
388 * @{
389 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000390
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000391/**
Douglas Gregor4f46e782010-01-19 21:36:55 +0000392 * \brief Identifies a specific source location within a translation
393 * unit.
394 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000395 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregor229bebd2010-11-09 06:24:54 +0000396 * to map a source location to a particular file, line, and column.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000397 */
398typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000399 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000400 unsigned int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000401} CXSourceLocation;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000402
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000403/**
Daniel Dunbar02968e52010-02-14 10:02:57 +0000404 * \brief Identifies a half-open character range in the source code.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000405 *
Douglas Gregor4f46e782010-01-19 21:36:55 +0000406 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
407 * starting and end locations from a source range, respectively.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000408 */
409typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000410 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000411 unsigned begin_int_data;
412 unsigned end_int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000413} CXSourceRange;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000414
Douglas Gregor4f46e782010-01-19 21:36:55 +0000415/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000416 * \brief Retrieve a NULL (invalid) source location.
417 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000418CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000419
Douglas Gregor816fd362010-01-22 21:44:22 +0000420/**
James Dennett574cb4c2012-06-15 05:41:51 +0000421 * \brief Determine whether two source locations, which must refer into
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000422 * the same translation unit, refer to exactly the same point in the source
Douglas Gregor816fd362010-01-22 21:44:22 +0000423 * code.
424 *
425 * \returns non-zero if the source locations refer to the same location, zero
426 * if they refer to different locations.
427 */
428CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
429 CXSourceLocation loc2);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000430
Douglas Gregor816fd362010-01-22 21:44:22 +0000431/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000432 * \brief Retrieves the source location associated with a given file/line/column
433 * in a particular translation unit.
Douglas Gregor816fd362010-01-22 21:44:22 +0000434 */
435CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
436 CXFile file,
437 unsigned line,
438 unsigned column);
David Chisnall2e16ac52010-10-15 17:07:39 +0000439/**
440 * \brief Retrieves the source location associated with a given character offset
441 * in a particular translation unit.
442 */
443CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
444 CXFile file,
445 unsigned offset);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000446
Douglas Gregor816fd362010-01-22 21:44:22 +0000447/**
Argyrios Kyrtzidis25f7af12013-04-12 17:06:51 +0000448 * \brief Returns non-zero if the given source location is in a system header.
449 */
450CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
451
452/**
Stefanus Du Toitdb51c632013-08-08 17:48:14 +0000453 * \brief Returns non-zero if the given source location is in the main file of
454 * the corresponding translation unit.
455 */
456CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
457
458/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000459 * \brief Retrieve a NULL (invalid) source range.
460 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000461CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
Ted Kremenekd071c602010-03-13 02:50:34 +0000462
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000463/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000464 * \brief Retrieve a source range given the beginning and ending source
465 * locations.
466 */
467CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
468 CXSourceLocation end);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000469
Douglas Gregor816fd362010-01-22 21:44:22 +0000470/**
Douglas Gregor757e38b2011-07-23 19:35:14 +0000471 * \brief Determine whether two ranges are equivalent.
472 *
473 * \returns non-zero if the ranges are the same, zero if they differ.
474 */
475CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
476 CXSourceRange range2);
477
478/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +0000479 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000480 */
Erik Verbruggend610b0f2011-10-06 12:11:57 +0000481CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000482
483/**
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000484 * \brief Retrieve the file, line, column, and offset represented by
485 * the given source location.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000486 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000487 * If the location refers into a macro expansion, retrieves the
488 * location of the macro expansion.
Douglas Gregor229bebd2010-11-09 06:24:54 +0000489 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000490 * \param location the location within a source file that will be decomposed
491 * into its parts.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000492 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000493 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000494 * source location points.
495 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000496 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000497 * source location points.
498 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000499 * \param column [out] if non-NULL, will be set to the column to which the given
500 * source location points.
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000501 *
502 * \param offset [out] if non-NULL, will be set to the offset into the
503 * buffer to which the given source location points.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000504 */
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000505CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
506 CXFile *file,
507 unsigned *line,
508 unsigned *column,
509 unsigned *offset);
510
511/**
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000512 * \brief Retrieve the file, line, column, and offset represented by
513 * the given source location, as specified in a # line directive.
514 *
515 * Example: given the following source code in a file somefile.c
516 *
James Dennett574cb4c2012-06-15 05:41:51 +0000517 * \code
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000518 * #123 "dummy.c" 1
519 *
520 * static int func(void)
521 * {
522 * return 0;
523 * }
James Dennett574cb4c2012-06-15 05:41:51 +0000524 * \endcode
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000525 *
526 * the location information returned by this function would be
527 *
528 * File: dummy.c Line: 124 Column: 12
529 *
530 * whereas clang_getExpansionLocation would have returned
531 *
532 * File: somefile.c Line: 3 Column: 12
533 *
534 * \param location the location within a source file that will be decomposed
535 * into its parts.
536 *
537 * \param filename [out] if non-NULL, will be set to the filename of the
538 * source location. Note that filenames returned will be for "virtual" files,
539 * which don't necessarily exist on the machine running clang - e.g. when
540 * parsing preprocessed output obtained from a different environment. If
541 * a non-NULL value is passed in, remember to dispose of the returned value
542 * using \c clang_disposeString() once you've finished with it. For an invalid
543 * source location, an empty string is returned.
544 *
545 * \param line [out] if non-NULL, will be set to the line number of the
546 * source location. For an invalid source location, zero is returned.
547 *
548 * \param column [out] if non-NULL, will be set to the column number of the
549 * source location. For an invalid source location, zero is returned.
550 */
551CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
552 CXString *filename,
553 unsigned *line,
554 unsigned *column);
555
556/**
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000557 * \brief Legacy API to retrieve the file, line, column, and offset represented
558 * by the given source location.
559 *
560 * This interface has been replaced by the newer interface
James Dennett574cb4c2012-06-15 05:41:51 +0000561 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000562 * details.
563 */
Douglas Gregor4f46e782010-01-19 21:36:55 +0000564CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
565 CXFile *file,
566 unsigned *line,
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000567 unsigned *column,
568 unsigned *offset);
Douglas Gregor47751d62010-01-26 03:07:15 +0000569
570/**
Douglas Gregor229bebd2010-11-09 06:24:54 +0000571 * \brief Retrieve the file, line, column, and offset represented by
572 * the given source location.
573 *
574 * If the location refers into a macro instantiation, return where the
575 * location was originally spelled in the source file.
576 *
577 * \param location the location within a source file that will be decomposed
578 * into its parts.
579 *
580 * \param file [out] if non-NULL, will be set to the file to which the given
581 * source location points.
582 *
583 * \param line [out] if non-NULL, will be set to the line to which the given
584 * source location points.
585 *
586 * \param column [out] if non-NULL, will be set to the column to which the given
587 * source location points.
588 *
589 * \param offset [out] if non-NULL, will be set to the offset into the
590 * buffer to which the given source location points.
591 */
592CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
593 CXFile *file,
594 unsigned *line,
595 unsigned *column,
596 unsigned *offset);
597
598/**
Argyrios Kyrtzidis56be7162013-01-04 18:30:13 +0000599 * \brief Retrieve the file, line, column, and offset represented by
600 * the given source location.
601 *
602 * If the location refers into a macro expansion, return where the macro was
603 * expanded or where the macro argument was written, if the location points at
604 * a macro argument.
605 *
606 * \param location the location within a source file that will be decomposed
607 * into its parts.
608 *
609 * \param file [out] if non-NULL, will be set to the file to which the given
610 * source location points.
611 *
612 * \param line [out] if non-NULL, will be set to the line to which the given
613 * source location points.
614 *
615 * \param column [out] if non-NULL, will be set to the column to which the given
616 * source location points.
617 *
618 * \param offset [out] if non-NULL, will be set to the offset into the
619 * buffer to which the given source location points.
620 */
621CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
622 CXFile *file,
623 unsigned *line,
624 unsigned *column,
625 unsigned *offset);
626
627/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000628 * \brief Retrieve a source location representing the first character within a
629 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000630 */
631CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
632
633/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000634 * \brief Retrieve a source location representing the last character within a
635 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000636 */
637CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
638
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000639/**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000640 * \brief Identifies an array of ranges.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000641 */
642typedef struct {
643 /** \brief The number of ranges in the \c ranges array. */
644 unsigned count;
645 /**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000646 * \brief An array of \c CXSourceRanges.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000647 */
648 CXSourceRange *ranges;
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000649} CXSourceRangeList;
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000650
651/**
652 * \brief Retrieve all ranges that were skipped by the preprocessor.
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000653 *
654 * The preprocessor will skip lines when they are surrounded by an
655 * if/ifdef/ifndef directive whose condition does not evaluate to true.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000656 */
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000657CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
658 CXFile file);
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000659
660/**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000661 * \brief Destroy the given \c CXSourceRangeList.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000662 */
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000663CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000664
665/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000666 * @}
667 */
Douglas Gregor6007cf22010-01-22 22:29:16 +0000668
669/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000670 * \defgroup CINDEX_DIAG Diagnostic reporting
671 *
672 * @{
673 */
674
675/**
676 * \brief Describes the severity of a particular diagnostic.
677 */
678enum CXDiagnosticSeverity {
679 /**
Ted Kremenekd071c602010-03-13 02:50:34 +0000680 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000681 * option.
682 */
683 CXDiagnostic_Ignored = 0,
Ted Kremenekd071c602010-03-13 02:50:34 +0000684
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000685 /**
686 * \brief This diagnostic is a note that should be attached to the
687 * previous (non-note) diagnostic.
688 */
689 CXDiagnostic_Note = 1,
690
691 /**
692 * \brief This diagnostic indicates suspicious code that may not be
693 * wrong.
694 */
695 CXDiagnostic_Warning = 2,
696
697 /**
698 * \brief This diagnostic indicates that the code is ill-formed.
699 */
700 CXDiagnostic_Error = 3,
701
702 /**
703 * \brief This diagnostic indicates that the code is ill-formed such
704 * that future parser recovery is unlikely to produce useful
705 * results.
706 */
707 CXDiagnostic_Fatal = 4
708};
709
710/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000711 * \brief A single diagnostic, containing the diagnostic's severity,
712 * location, text, source ranges, and fix-it hints.
713 */
714typedef void *CXDiagnostic;
715
716/**
Ted Kremenekd010ba42011-11-10 08:43:12 +0000717 * \brief A group of CXDiagnostics.
718 */
719typedef void *CXDiagnosticSet;
720
721/**
722 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
723 */
724CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
725
726/**
727 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
728 *
James Dennett574cb4c2012-06-15 05:41:51 +0000729 * \param Diags the CXDiagnosticSet to query.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000730 * \param Index the zero-based diagnostic number to retrieve.
731 *
732 * \returns the requested diagnostic. This diagnostic must be freed
733 * via a call to \c clang_disposeDiagnostic().
734 */
735CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
736 unsigned Index);
737
738
739/**
740 * \brief Describes the kind of error that occurred (if any) in a call to
741 * \c clang_loadDiagnostics.
742 */
743enum CXLoadDiag_Error {
744 /**
745 * \brief Indicates that no error occurred.
746 */
747 CXLoadDiag_None = 0,
748
749 /**
750 * \brief Indicates that an unknown error occurred while attempting to
751 * deserialize diagnostics.
752 */
753 CXLoadDiag_Unknown = 1,
754
755 /**
756 * \brief Indicates that the file containing the serialized diagnostics
757 * could not be opened.
758 */
759 CXLoadDiag_CannotLoad = 2,
760
761 /**
762 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett574cb4c2012-06-15 05:41:51 +0000763 * corrupt.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000764 */
765 CXLoadDiag_InvalidFile = 3
766};
767
768/**
769 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett574cb4c2012-06-15 05:41:51 +0000770 * file.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000771 *
James Dennett574cb4c2012-06-15 05:41:51 +0000772 * \param file The name of the file to deserialize.
773 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenekd010ba42011-11-10 08:43:12 +0000774 * deserializing the diagnostics.
James Dennett574cb4c2012-06-15 05:41:51 +0000775 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenekd010ba42011-11-10 08:43:12 +0000776 * if the file was not successfully loaded.
777 *
778 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett574cb4c2012-06-15 05:41:51 +0000779 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenekd010ba42011-11-10 08:43:12 +0000780 */
781CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
782 enum CXLoadDiag_Error *error,
783 CXString *errorString);
784
785/**
786 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
787 */
788CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
789
790/**
James Dennett574cb4c2012-06-15 05:41:51 +0000791 * \brief Retrieve the child diagnostics of a CXDiagnostic.
792 *
793 * This CXDiagnosticSet does not need to be released by
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000794 * clang_disposeDiagnosticSet.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000795 */
796CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
797
798/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000799 * \brief Determine the number of diagnostics produced for the given
800 * translation unit.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000801 */
Douglas Gregor33cdd812010-02-18 18:08:43 +0000802CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
803
804/**
805 * \brief Retrieve a diagnostic associated with the given translation unit.
806 *
807 * \param Unit the translation unit to query.
808 * \param Index the zero-based diagnostic number to retrieve.
809 *
810 * \returns the requested diagnostic. This diagnostic must be freed
811 * via a call to \c clang_disposeDiagnostic().
812 */
813CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
814 unsigned Index);
815
816/**
Ted Kremenekb4a8b052011-12-09 22:28:32 +0000817 * \brief Retrieve the complete set of diagnostics associated with a
818 * translation unit.
819 *
820 * \param Unit the translation unit to query.
821 */
822CINDEX_LINKAGE CXDiagnosticSet
823 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
824
825/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000826 * \brief Destroy a diagnostic.
827 */
828CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000829
830/**
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000831 * \brief Options to control the display of diagnostics.
832 *
833 * The values in this enum are meant to be combined to customize the
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000834 * behavior of \c clang_formatDiagnostic().
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000835 */
836enum CXDiagnosticDisplayOptions {
837 /**
838 * \brief Display the source-location information where the
839 * diagnostic was located.
840 *
841 * When set, diagnostics will be prefixed by the file, line, and
842 * (optionally) column to which the diagnostic refers. For example,
843 *
844 * \code
845 * test.c:28: warning: extra tokens at end of #endif directive
846 * \endcode
847 *
848 * This option corresponds to the clang flag \c -fshow-source-location.
849 */
850 CXDiagnostic_DisplaySourceLocation = 0x01,
851
852 /**
853 * \brief If displaying the source-location information of the
854 * diagnostic, also include the column number.
855 *
856 * This option corresponds to the clang flag \c -fshow-column.
857 */
858 CXDiagnostic_DisplayColumn = 0x02,
859
860 /**
861 * \brief If displaying the source-location information of the
862 * diagnostic, also include information about source ranges in a
863 * machine-parsable format.
864 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000865 * This option corresponds to the clang flag
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000866 * \c -fdiagnostics-print-source-range-info.
867 */
Douglas Gregora750e8e2010-11-19 16:18:16 +0000868 CXDiagnostic_DisplaySourceRanges = 0x04,
869
870 /**
871 * \brief Display the option name associated with this diagnostic, if any.
872 *
873 * The option name displayed (e.g., -Wconversion) will be placed in brackets
874 * after the diagnostic text. This option corresponds to the clang flag
875 * \c -fdiagnostics-show-option.
876 */
877 CXDiagnostic_DisplayOption = 0x08,
878
879 /**
880 * \brief Display the category number associated with this diagnostic, if any.
881 *
882 * The category number is displayed within brackets after the diagnostic text.
883 * This option corresponds to the clang flag
884 * \c -fdiagnostics-show-category=id.
885 */
886 CXDiagnostic_DisplayCategoryId = 0x10,
887
888 /**
889 * \brief Display the category name associated with this diagnostic, if any.
890 *
891 * The category name is displayed within brackets after the diagnostic text.
892 * This option corresponds to the clang flag
893 * \c -fdiagnostics-show-category=name.
894 */
895 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000896};
897
898/**
Douglas Gregord770f732010-02-22 23:17:23 +0000899 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000900 *
Douglas Gregord770f732010-02-22 23:17:23 +0000901 * This routine will format the given diagnostic to a string, rendering
Ted Kremenekd071c602010-03-13 02:50:34 +0000902 * the diagnostic according to the various options given. The
903 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000904 * options that most closely mimics the behavior of the clang compiler.
905 *
906 * \param Diagnostic The diagnostic to print.
907 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000908 * \param Options A set of options that control the diagnostic display,
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000909 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregord770f732010-02-22 23:17:23 +0000910 *
911 * \returns A new string containing for formatted diagnostic.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000912 */
Douglas Gregord770f732010-02-22 23:17:23 +0000913CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
914 unsigned Options);
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000915
916/**
917 * \brief Retrieve the set of display options most similar to the
918 * default behavior of the clang compiler.
919 *
920 * \returns A set of display options suitable for use with \c
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000921 * clang_formatDiagnostic().
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000922 */
923CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
924
925/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000926 * \brief Determine the severity of the given diagnostic.
927 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000928CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000929clang_getDiagnosticSeverity(CXDiagnostic);
930
931/**
932 * \brief Retrieve the source location of the given diagnostic.
933 *
934 * This location is where Clang would print the caret ('^') when
935 * displaying the diagnostic on the command line.
936 */
937CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
938
939/**
940 * \brief Retrieve the text of the given diagnostic.
941 */
942CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000943
944/**
Douglas Gregora750e8e2010-11-19 16:18:16 +0000945 * \brief Retrieve the name of the command-line option that enabled this
946 * diagnostic.
947 *
948 * \param Diag The diagnostic to be queried.
949 *
950 * \param Disable If non-NULL, will be set to the option that disables this
951 * diagnostic (if any).
952 *
953 * \returns A string that contains the command-line option used to enable this
954 * warning, such as "-Wconversion" or "-pedantic".
955 */
956CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
957 CXString *Disable);
958
959/**
960 * \brief Retrieve the category number for this diagnostic.
961 *
962 * Diagnostics can be categorized into groups along with other, related
963 * diagnostics (e.g., diagnostics under the same warning flag). This routine
964 * retrieves the category number for the given diagnostic.
965 *
966 * \returns The number of the category that contains this diagnostic, or zero
967 * if this diagnostic is uncategorized.
968 */
969CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
970
971/**
Ted Kremenek26a6d492012-04-12 00:03:31 +0000972 * \brief Retrieve the name of a particular diagnostic category. This
973 * is now deprecated. Use clang_getDiagnosticCategoryText()
974 * instead.
Douglas Gregora750e8e2010-11-19 16:18:16 +0000975 *
976 * \param Category A diagnostic category number, as returned by
977 * \c clang_getDiagnosticCategory().
978 *
979 * \returns The name of the given diagnostic category.
980 */
Ted Kremenek26a6d492012-04-12 00:03:31 +0000981CINDEX_DEPRECATED CINDEX_LINKAGE
982CXString clang_getDiagnosticCategoryName(unsigned Category);
983
984/**
985 * \brief Retrieve the diagnostic category text for a given diagnostic.
986 *
Ted Kremenek26a6d492012-04-12 00:03:31 +0000987 * \returns The text of the given diagnostic category.
988 */
989CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregora750e8e2010-11-19 16:18:16 +0000990
991/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000992 * \brief Determine the number of source ranges associated with the given
993 * diagnostic.
994 */
995CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenekd071c602010-03-13 02:50:34 +0000996
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000997/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000998 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000999 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +00001000 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001001 * code. On the command line, Clang displays source ranges by
Ted Kremenekd071c602010-03-13 02:50:34 +00001002 * underlining them with '~' characters.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001003 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +00001004 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001005 *
Ted Kremenekd071c602010-03-13 02:50:34 +00001006 * \param Range the zero-based index specifying which range to
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001007 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +00001008 * \returns the requested source range.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001009 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001010CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +00001011 unsigned Range);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001012
1013/**
1014 * \brief Determine the number of fix-it hints associated with the
1015 * given diagnostic.
1016 */
1017CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
1018
1019/**
Douglas Gregor836ec942010-02-19 18:16:06 +00001020 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001021 *
Douglas Gregor836ec942010-02-19 18:16:06 +00001022 * Fix-its are described in terms of a source range whose contents
1023 * should be replaced by a string. This approach generalizes over
1024 * three kinds of operations: removal of source code (the range covers
1025 * the code to be removed and the replacement string is empty),
1026 * replacement of source code (the range covers the code to be
1027 * replaced and the replacement string provides the new code), and
1028 * insertion (both the start and end of the range point at the
1029 * insertion location, and the replacement string provides the text to
1030 * insert).
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001031 *
Douglas Gregor836ec942010-02-19 18:16:06 +00001032 * \param Diagnostic The diagnostic whose fix-its are being queried.
1033 *
1034 * \param FixIt The zero-based index of the fix-it.
1035 *
1036 * \param ReplacementRange The source range whose contents will be
1037 * replaced with the returned replacement string. Note that source
1038 * ranges are half-open ranges [a, b), so the source code should be
1039 * replaced from a and up to (but not including) b.
1040 *
1041 * \returns A string containing text that should be replace the source
1042 * code indicated by the \c ReplacementRange.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001043 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001044CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor836ec942010-02-19 18:16:06 +00001045 unsigned FixIt,
1046 CXSourceRange *ReplacementRange);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001047
1048/**
1049 * @}
1050 */
1051
1052/**
1053 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
1054 *
1055 * The routines in this group provide the ability to create and destroy
1056 * translation units from files, either by parsing the contents of the files or
1057 * by reading in a serialized representation of a translation unit.
1058 *
1059 * @{
1060 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001061
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001062/**
1063 * \brief Get the original translation unit source file name.
1064 */
1065CINDEX_LINKAGE CXString
1066clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1067
1068/**
1069 * \brief Return the CXTranslationUnit for a given source file and the provided
1070 * command line arguments one would pass to the compiler.
1071 *
1072 * Note: The 'source_filename' argument is optional. If the caller provides a
1073 * NULL pointer, the name of the source file is expected to reside in the
1074 * specified command line arguments.
1075 *
1076 * Note: When encountered in 'clang_command_line_args', the following options
1077 * are ignored:
1078 *
1079 * '-c'
1080 * '-emit-ast'
1081 * '-fsyntax-only'
James Dennett574cb4c2012-06-15 05:41:51 +00001082 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001083 *
Ted Kremenekbd4972442010-11-08 04:28:51 +00001084 * \param CIdx The index object with which the translation unit will be
1085 * associated.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001086 *
James Dennett574cb4c2012-06-15 05:41:51 +00001087 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenekbd4972442010-11-08 04:28:51 +00001088 * source file is included in \p clang_command_line_args.
1089 *
1090 * \param num_clang_command_line_args The number of command-line arguments in
1091 * \p clang_command_line_args.
1092 *
1093 * \param clang_command_line_args The command-line arguments that would be
1094 * passed to the \c clang executable if it were being invoked out-of-process.
1095 * These command-line options will be parsed and will affect how the translation
1096 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001097 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001098 *
1099 * \param num_unsaved_files the number of unsaved file entries in \p
1100 * unsaved_files.
1101 *
1102 * \param unsaved_files the files that have not yet been saved to disk
1103 * but may be required for code completion, including the contents of
Ted Kremenekde24a942010-04-12 18:47:26 +00001104 * those files. The contents and name of these files (as specified by
1105 * CXUnsavedFile) are copied when necessary, so the client only needs to
1106 * guarantee their validity until the call to this function returns.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001107 */
1108CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1109 CXIndex CIdx,
1110 const char *source_filename,
1111 int num_clang_command_line_args,
Douglas Gregor57879fa2010-09-01 16:43:19 +00001112 const char * const *clang_command_line_args,
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001113 unsigned num_unsaved_files,
Douglas Gregor33cdd812010-02-18 18:08:43 +00001114 struct CXUnsavedFile *unsaved_files);
Ted Kremenekd071c602010-03-13 02:50:34 +00001115
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001116/**
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001117 * \brief Same as \c clang_createTranslationUnit2, but returns
1118 * the \c CXTranslationUnit instead of an error code. In case of an error this
1119 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1120 * error codes.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001121 */
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001122CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
1123 CXIndex CIdx,
1124 const char *ast_filename);
1125
1126/**
1127 * \brief Create a translation unit from an AST file (\c -emit-ast).
1128 *
1129 * \param[out] out_TU A non-NULL pointer to store the created
1130 * \c CXTranslationUnit.
1131 *
1132 * \returns Zero on success, otherwise returns an error code.
1133 */
1134CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2(
1135 CXIndex CIdx,
1136 const char *ast_filename,
1137 CXTranslationUnit *out_TU);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001138
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001139/**
1140 * \brief Flags that control the creation of translation units.
1141 *
1142 * The enumerators in this enumeration type are meant to be bitwise
1143 * ORed together to specify which options should be used when
1144 * constructing the translation unit.
1145 */
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001146enum CXTranslationUnit_Flags {
1147 /**
1148 * \brief Used to indicate that no special translation-unit options are
1149 * needed.
1150 */
1151 CXTranslationUnit_None = 0x0,
1152
1153 /**
1154 * \brief Used to indicate that the parser should construct a "detailed"
1155 * preprocessing record, including all macro definitions and instantiations.
1156 *
1157 * Constructing a detailed preprocessing record requires more memory
1158 * and time to parse, since the information contained in the record
1159 * is usually not retained. However, it can be useful for
1160 * applications that require more detailed information about the
1161 * behavior of the preprocessor.
1162 */
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001163 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1164
1165 /**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001166 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001167 *
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001168 * When a translation unit is considered "incomplete", semantic
1169 * analysis that is typically performed at the end of the
1170 * translation unit will be suppressed. For example, this suppresses
1171 * the completion of tentative declarations in C and of
1172 * instantiation of implicitly-instantiation function templates in
1173 * C++. This option is typically used when parsing a header with the
1174 * intent of producing a precompiled header.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001175 */
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001176 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001177
1178 /**
1179 * \brief Used to indicate that the translation unit should be built with an
1180 * implicit precompiled header for the preamble.
1181 *
1182 * An implicit precompiled header is used as an optimization when a
1183 * particular translation unit is likely to be reparsed many times
1184 * when the sources aren't changing that often. In this case, an
1185 * implicit precompiled header will be built containing all of the
1186 * initial includes at the top of the main file (what we refer to as
1187 * the "preamble" of the file). In subsequent parses, if the
1188 * preamble or the files in it have not changed, \c
1189 * clang_reparseTranslationUnit() will re-use the implicit
1190 * precompiled header to improve parsing performance.
1191 */
Douglas Gregorde051182010-08-11 15:58:42 +00001192 CXTranslationUnit_PrecompiledPreamble = 0x04,
1193
1194 /**
1195 * \brief Used to indicate that the translation unit should cache some
1196 * code-completion results with each reparse of the source file.
1197 *
1198 * Caching of code-completion results is a performance optimization that
1199 * introduces some overhead to reparsing but improves the performance of
1200 * code-completion operations.
1201 */
Douglas Gregorf5a18542010-10-27 17:24:53 +00001202 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001203
Douglas Gregorf5a18542010-10-27 17:24:53 +00001204 /**
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001205 * \brief Used to indicate that the translation unit will be serialized with
1206 * \c clang_saveTranslationUnit.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001207 *
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001208 * This option is typically used when parsing a header with the intent of
1209 * producing a precompiled header.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001210 */
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001211 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregorf5a18542010-10-27 17:24:53 +00001212
1213 /**
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001214 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001215 *
1216 * Note: this is a *temporary* option that is available only while
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001217 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001218 */
Erik Verbruggen6e922512012-04-12 10:11:59 +00001219 CXTranslationUnit_CXXChainedPCH = 0x20,
1220
1221 /**
1222 * \brief Used to indicate that function/method bodies should be skipped while
1223 * parsing.
1224 *
1225 * This option can be used to search for declarations/definitions while
1226 * ignoring the usages.
1227 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00001228 CXTranslationUnit_SkipFunctionBodies = 0x40,
1229
1230 /**
1231 * \brief Used to indicate that brief documentation comments should be
1232 * included into the set of code completions returned from this translation
1233 * unit.
1234 */
1235 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001236};
1237
1238/**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001239 * \brief Returns the set of flags that is suitable for parsing a translation
1240 * unit that is being edited.
1241 *
1242 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1243 * to indicate that the translation unit is likely to be reparsed many times,
1244 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1245 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1246 * set contains an unspecified set of optimizations (e.g., the precompiled
1247 * preamble) geared toward improving the performance of these routines. The
1248 * set of optimizations enabled may change from one version to the next.
1249 */
Douglas Gregorde051182010-08-11 15:58:42 +00001250CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001251
1252/**
1253 * \brief Same as \c clang_parseTranslationUnit2, but returns
1254 * the \c CXTranslationUnit instead of an error code. In case of an error this
1255 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1256 * error codes.
1257 */
1258CINDEX_LINKAGE CXTranslationUnit
1259clang_parseTranslationUnit(CXIndex CIdx,
1260 const char *source_filename,
1261 const char *const *command_line_args,
1262 int num_command_line_args,
1263 struct CXUnsavedFile *unsaved_files,
1264 unsigned num_unsaved_files,
1265 unsigned options);
1266
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001267/**
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001268 * \brief Parse the given source file and the translation unit corresponding
1269 * to that file.
1270 *
1271 * This routine is the main entry point for the Clang C API, providing the
1272 * ability to parse a source file into a translation unit that can then be
1273 * queried by other functions in the API. This routine accepts a set of
1274 * command-line arguments so that the compilation can be configured in the same
1275 * way that the compiler is configured on the command line.
1276 *
1277 * \param CIdx The index object with which the translation unit will be
1278 * associated.
1279 *
1280 * \param source_filename The name of the source file to load, or NULL if the
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001281 * source file is included in \c command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001282 *
1283 * \param command_line_args The command-line arguments that would be
1284 * passed to the \c clang executable if it were being invoked out-of-process.
1285 * These command-line options will be parsed and will affect how the translation
1286 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001287 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001288 *
1289 * \param num_command_line_args The number of command-line arguments in
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001290 * \c command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001291 *
1292 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor8e984da2010-08-04 16:47:14 +00001293 * but may be required for parsing, including the contents of
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001294 * those files. The contents and name of these files (as specified by
1295 * CXUnsavedFile) are copied when necessary, so the client only needs to
1296 * guarantee their validity until the call to this function returns.
1297 *
1298 * \param num_unsaved_files the number of unsaved file entries in \p
1299 * unsaved_files.
1300 *
1301 * \param options A bitmask of options that affects how the translation unit
1302 * is managed but not its compilation. This should be a bitwise OR of the
1303 * CXTranslationUnit_XXX flags.
1304 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001305 * \param[out] out_TU A non-NULL pointer to store the created
1306 * \c CXTranslationUnit, describing the parsed code and containing any
1307 * diagnostics produced by the compiler.
1308 *
1309 * \returns Zero on success, otherwise returns an error code.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001310 */
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001311CINDEX_LINKAGE enum CXErrorCode
1312clang_parseTranslationUnit2(CXIndex CIdx,
1313 const char *source_filename,
1314 const char *const *command_line_args,
1315 int num_command_line_args,
1316 struct CXUnsavedFile *unsaved_files,
1317 unsigned num_unsaved_files,
1318 unsigned options,
1319 CXTranslationUnit *out_TU);
1320
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001321/**
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001322 * \brief Flags that control how translation units are saved.
1323 *
1324 * The enumerators in this enumeration type are meant to be bitwise
1325 * ORed together to specify which options should be used when
1326 * saving the translation unit.
1327 */
1328enum CXSaveTranslationUnit_Flags {
1329 /**
1330 * \brief Used to indicate that no special saving options are needed.
1331 */
1332 CXSaveTranslationUnit_None = 0x0
1333};
1334
1335/**
1336 * \brief Returns the set of flags that is suitable for saving a translation
1337 * unit.
1338 *
1339 * The set of flags returned provide options for
1340 * \c clang_saveTranslationUnit() by default. The returned flag
1341 * set contains an unspecified set of options that save translation units with
1342 * the most commonly-requested data.
1343 */
1344CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1345
1346/**
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001347 * \brief Describes the kind of error that occurred (if any) in a call to
1348 * \c clang_saveTranslationUnit().
1349 */
1350enum CXSaveError {
1351 /**
1352 * \brief Indicates that no error occurred while saving a translation unit.
1353 */
1354 CXSaveError_None = 0,
1355
1356 /**
1357 * \brief Indicates that an unknown error occurred while attempting to save
1358 * the file.
1359 *
1360 * This error typically indicates that file I/O failed when attempting to
1361 * write the file.
1362 */
1363 CXSaveError_Unknown = 1,
1364
1365 /**
1366 * \brief Indicates that errors during translation prevented this attempt
1367 * to save the translation unit.
1368 *
1369 * Errors that prevent the translation unit from being saved can be
1370 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1371 */
1372 CXSaveError_TranslationErrors = 2,
1373
1374 /**
1375 * \brief Indicates that the translation unit to be saved was somehow
1376 * invalid (e.g., NULL).
1377 */
1378 CXSaveError_InvalidTU = 3
1379};
1380
1381/**
Douglas Gregore9386682010-08-13 05:36:37 +00001382 * \brief Saves a translation unit into a serialized representation of
1383 * that translation unit on disk.
1384 *
1385 * Any translation unit that was parsed without error can be saved
1386 * into a file. The translation unit can then be deserialized into a
1387 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1388 * if it is an incomplete translation unit that corresponds to a
1389 * header, used as a precompiled header when parsing other translation
1390 * units.
1391 *
1392 * \param TU The translation unit to save.
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001393 *
Douglas Gregore9386682010-08-13 05:36:37 +00001394 * \param FileName The file to which the translation unit will be saved.
1395 *
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001396 * \param options A bitmask of options that affects how the translation unit
1397 * is saved. This should be a bitwise OR of the
1398 * CXSaveTranslationUnit_XXX flags.
1399 *
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001400 * \returns A value that will match one of the enumerators of the CXSaveError
1401 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1402 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregore9386682010-08-13 05:36:37 +00001403 */
1404CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001405 const char *FileName,
1406 unsigned options);
Douglas Gregore9386682010-08-13 05:36:37 +00001407
1408/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001409 * \brief Destroy the specified CXTranslationUnit object.
1410 */
1411CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenekd071c602010-03-13 02:50:34 +00001412
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001413/**
Douglas Gregorde051182010-08-11 15:58:42 +00001414 * \brief Flags that control the reparsing of translation units.
1415 *
1416 * The enumerators in this enumeration type are meant to be bitwise
1417 * ORed together to specify which options should be used when
1418 * reparsing the translation unit.
1419 */
1420enum CXReparse_Flags {
1421 /**
1422 * \brief Used to indicate that no special reparsing options are needed.
1423 */
1424 CXReparse_None = 0x0
1425};
1426
1427/**
1428 * \brief Returns the set of flags that is suitable for reparsing a translation
1429 * unit.
1430 *
1431 * The set of flags returned provide options for
1432 * \c clang_reparseTranslationUnit() by default. The returned flag
1433 * set contains an unspecified set of optimizations geared toward common uses
1434 * of reparsing. The set of optimizations enabled may change from one version
1435 * to the next.
1436 */
1437CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1438
1439/**
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001440 * \brief Reparse the source files that produced this translation unit.
1441 *
1442 * This routine can be used to re-parse the source files that originally
1443 * created the given translation unit, for example because those source files
1444 * have changed (either on disk or as passed via \p unsaved_files). The
1445 * source code will be reparsed with the same command-line options as it
1446 * was originally parsed.
1447 *
1448 * Reparsing a translation unit invalidates all cursors and source locations
1449 * that refer into that translation unit. This makes reparsing a translation
1450 * unit semantically equivalent to destroying the translation unit and then
1451 * creating a new translation unit with the same command-line arguments.
1452 * However, it may be more efficient to reparse a translation
1453 * unit using this routine.
1454 *
1455 * \param TU The translation unit whose contents will be re-parsed. The
1456 * translation unit must originally have been built with
1457 * \c clang_createTranslationUnitFromSourceFile().
1458 *
1459 * \param num_unsaved_files The number of unsaved file entries in \p
1460 * unsaved_files.
1461 *
1462 * \param unsaved_files The files that have not yet been saved to disk
1463 * but may be required for parsing, including the contents of
1464 * those files. The contents and name of these files (as specified by
1465 * CXUnsavedFile) are copied when necessary, so the client only needs to
1466 * guarantee their validity until the call to this function returns.
1467 *
Douglas Gregorde051182010-08-11 15:58:42 +00001468 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1469 * The function \c clang_defaultReparseOptions() produces a default set of
1470 * options recommended for most uses, based on the translation unit.
1471 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001472 * \returns 0 if the sources could be reparsed. A non-zero error code will be
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001473 * returned if reparsing was impossible, such that the translation unit is
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001474 * invalid. In such cases, the only valid call for \c TU is
1475 * \c clang_disposeTranslationUnit(TU). The error codes returned by this
1476 * routine are described by the \c CXErrorCode enum.
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001477 */
1478CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1479 unsigned num_unsaved_files,
Douglas Gregorde051182010-08-11 15:58:42 +00001480 struct CXUnsavedFile *unsaved_files,
1481 unsigned options);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001482
1483/**
1484 * \brief Categorizes how memory is being used by a translation unit.
1485 */
Ted Kremenek23324122011-04-20 16:41:07 +00001486enum CXTUResourceUsageKind {
1487 CXTUResourceUsage_AST = 1,
1488 CXTUResourceUsage_Identifiers = 2,
1489 CXTUResourceUsage_Selectors = 3,
1490 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek21735e62011-04-28 04:10:31 +00001491 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekf5df0ce2011-04-28 04:53:38 +00001492 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenek8d587902011-04-28 20:36:42 +00001493 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremenek5e1ed7b2011-04-28 23:46:20 +00001494 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1495 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1496 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek2160a0d2011-05-04 01:38:46 +00001497 CXTUResourceUsage_Preprocessor = 11,
1498 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenek120992a2011-07-26 23:46:06 +00001499 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001500 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenek23324122011-04-20 16:41:07 +00001501 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1502 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001503 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenek23324122011-04-20 16:41:07 +00001504
1505 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001506 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek83f642e2011-04-18 22:47:10 +00001507};
1508
1509/**
1510 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenek23324122011-04-20 16:41:07 +00001511 * the name of the memory category. This string should never be freed.
Ted Kremenek83f642e2011-04-18 22:47:10 +00001512 */
1513CINDEX_LINKAGE
Ted Kremenek23324122011-04-20 16:41:07 +00001514const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001515
Ted Kremenek23324122011-04-20 16:41:07 +00001516typedef struct CXTUResourceUsageEntry {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001517 /* \brief The memory usage category. */
Ted Kremenek23324122011-04-20 16:41:07 +00001518 enum CXTUResourceUsageKind kind;
1519 /* \brief Amount of resources used.
1520 The units will depend on the resource kind. */
Ted Kremenek83f642e2011-04-18 22:47:10 +00001521 unsigned long amount;
Ted Kremenek23324122011-04-20 16:41:07 +00001522} CXTUResourceUsageEntry;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001523
1524/**
1525 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1526 */
Ted Kremenek23324122011-04-20 16:41:07 +00001527typedef struct CXTUResourceUsage {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001528 /* \brief Private data member, used for queries. */
1529 void *data;
1530
1531 /* \brief The number of entries in the 'entries' array. */
1532 unsigned numEntries;
1533
1534 /* \brief An array of key-value pairs, representing the breakdown of memory
1535 usage. */
Ted Kremenek23324122011-04-20 16:41:07 +00001536 CXTUResourceUsageEntry *entries;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001537
Ted Kremenek23324122011-04-20 16:41:07 +00001538} CXTUResourceUsage;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001539
1540/**
1541 * \brief Return the memory usage of a translation unit. This object
Ted Kremenek23324122011-04-20 16:41:07 +00001542 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek83f642e2011-04-18 22:47:10 +00001543 */
Ted Kremenek23324122011-04-20 16:41:07 +00001544CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001545
Ted Kremenek23324122011-04-20 16:41:07 +00001546CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001547
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001548/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001549 * @}
1550 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001551
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001552/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001553 * \brief Describes the kind of entity that a cursor refers to.
1554 */
1555enum CXCursorKind {
1556 /* Declarations */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001557 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001558 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001559 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001560 *
1561 * Unexposed declarations have the same operations as any other kind
1562 * of declaration; one can extract their location information,
1563 * spelling, find their definitions, etc. However, the specific kind
1564 * of the declaration is not reported.
1565 */
1566 CXCursor_UnexposedDecl = 1,
1567 /** \brief A C or C++ struct. */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001568 CXCursor_StructDecl = 2,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001569 /** \brief A C or C++ union. */
1570 CXCursor_UnionDecl = 3,
1571 /** \brief A C++ class. */
1572 CXCursor_ClassDecl = 4,
1573 /** \brief An enumeration. */
1574 CXCursor_EnumDecl = 5,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001575 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001576 * \brief A field (in C) or non-static data member (in C++) in a
1577 * struct, union, or C++ class.
1578 */
1579 CXCursor_FieldDecl = 6,
1580 /** \brief An enumerator constant. */
1581 CXCursor_EnumConstantDecl = 7,
1582 /** \brief A function. */
1583 CXCursor_FunctionDecl = 8,
1584 /** \brief A variable. */
1585 CXCursor_VarDecl = 9,
1586 /** \brief A function or method parameter. */
1587 CXCursor_ParmDecl = 10,
James Dennett1355bd12012-06-11 06:19:40 +00001588 /** \brief An Objective-C \@interface. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001589 CXCursor_ObjCInterfaceDecl = 11,
James Dennett1355bd12012-06-11 06:19:40 +00001590 /** \brief An Objective-C \@interface for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001591 CXCursor_ObjCCategoryDecl = 12,
James Dennett1355bd12012-06-11 06:19:40 +00001592 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001593 CXCursor_ObjCProtocolDecl = 13,
James Dennett1355bd12012-06-11 06:19:40 +00001594 /** \brief An Objective-C \@property declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001595 CXCursor_ObjCPropertyDecl = 14,
1596 /** \brief An Objective-C instance variable. */
1597 CXCursor_ObjCIvarDecl = 15,
1598 /** \brief An Objective-C instance method. */
1599 CXCursor_ObjCInstanceMethodDecl = 16,
1600 /** \brief An Objective-C class method. */
1601 CXCursor_ObjCClassMethodDecl = 17,
James Dennett1355bd12012-06-11 06:19:40 +00001602 /** \brief An Objective-C \@implementation. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001603 CXCursor_ObjCImplementationDecl = 18,
James Dennett1355bd12012-06-11 06:19:40 +00001604 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001605 CXCursor_ObjCCategoryImplDecl = 19,
1606 /** \brief A typedef */
1607 CXCursor_TypedefDecl = 20,
Ted Kremenek225b8e32010-04-13 23:39:06 +00001608 /** \brief A C++ class method. */
1609 CXCursor_CXXMethod = 21,
Ted Kremenekbd67fb22010-05-06 23:38:21 +00001610 /** \brief A C++ namespace. */
1611 CXCursor_Namespace = 22,
Ted Kremenekb80cba52010-05-07 01:04:29 +00001612 /** \brief A linkage specification, e.g. 'extern "C"'. */
1613 CXCursor_LinkageSpec = 23,
Douglas Gregor12bca222010-08-31 14:41:23 +00001614 /** \brief A C++ constructor. */
1615 CXCursor_Constructor = 24,
1616 /** \brief A C++ destructor. */
1617 CXCursor_Destructor = 25,
1618 /** \brief A C++ conversion function. */
1619 CXCursor_ConversionFunction = 26,
Douglas Gregor713602b2010-08-31 17:01:39 +00001620 /** \brief A C++ template type parameter. */
1621 CXCursor_TemplateTypeParameter = 27,
1622 /** \brief A C++ non-type template parameter. */
1623 CXCursor_NonTypeTemplateParameter = 28,
1624 /** \brief A C++ template template parameter. */
1625 CXCursor_TemplateTemplateParameter = 29,
1626 /** \brief A C++ function template. */
1627 CXCursor_FunctionTemplate = 30,
Douglas Gregor1fbaeb12010-08-31 19:02:00 +00001628 /** \brief A C++ class template. */
1629 CXCursor_ClassTemplate = 31,
Douglas Gregorf96abb22010-08-31 19:31:58 +00001630 /** \brief A C++ class template partial specialization. */
1631 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregora89314e2010-08-31 23:48:11 +00001632 /** \brief A C++ namespace alias declaration. */
1633 CXCursor_NamespaceAlias = 33,
Douglas Gregor01a430132010-09-01 03:07:18 +00001634 /** \brief A C++ using directive. */
1635 CXCursor_UsingDirective = 34,
Richard Smithdda56e42011-04-15 14:24:37 +00001636 /** \brief A C++ using declaration. */
Douglas Gregora9aa29c2010-09-01 19:52:22 +00001637 CXCursor_UsingDeclaration = 35,
Richard Smithdda56e42011-04-15 14:24:37 +00001638 /** \brief A C++ alias declaration */
1639 CXCursor_TypeAliasDecl = 36,
James Dennett574cb4c2012-06-15 05:41:51 +00001640 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001641 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett574cb4c2012-06-15 05:41:51 +00001642 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001643 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001644 /** \brief An access specifier. */
1645 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor4c362d52011-10-05 19:00:14 +00001646
Ted Kremenek08de5c12010-05-19 21:51:10 +00001647 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001648 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001649
Douglas Gregor6007cf22010-01-22 22:29:16 +00001650 /* References */
1651 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001652 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001653 CXCursor_ObjCProtocolRef = 41,
1654 CXCursor_ObjCClassRef = 42,
1655 /**
1656 * \brief A reference to a type declaration.
1657 *
1658 * A type reference occurs anywhere where a type is named but not
1659 * declared. For example, given:
1660 *
1661 * \code
1662 * typedef unsigned size_type;
1663 * size_type size;
1664 * \endcode
1665 *
1666 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1667 * while the type of the variable "size" is referenced. The cursor
1668 * referenced by the type of size is the typedef for size_type.
1669 */
1670 CXCursor_TypeRef = 43,
Ted Kremenekae9e2212010-08-27 21:34:58 +00001671 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregora23e8f72010-08-31 20:37:03 +00001672 /**
Douglas Gregorf3af3112010-09-09 21:42:20 +00001673 * \brief A reference to a class template, function template, template
1674 * template parameter, or class template partial specialization.
Douglas Gregora23e8f72010-08-31 20:37:03 +00001675 */
1676 CXCursor_TemplateRef = 45,
Douglas Gregora89314e2010-08-31 23:48:11 +00001677 /**
1678 * \brief A reference to a namespace or namespace alias.
1679 */
1680 CXCursor_NamespaceRef = 46,
Douglas Gregorf3af3112010-09-09 21:42:20 +00001681 /**
Douglas Gregora93ab662010-09-10 00:22:18 +00001682 * \brief A reference to a member of a struct, union, or class that occurs in
1683 * some non-expression context, e.g., a designated initializer.
Douglas Gregorf3af3112010-09-09 21:42:20 +00001684 */
1685 CXCursor_MemberRef = 47,
Douglas Gregora93ab662010-09-10 00:22:18 +00001686 /**
1687 * \brief A reference to a labeled statement.
1688 *
1689 * This cursor kind is used to describe the jump to "start_over" in the
1690 * goto statement in the following example:
1691 *
1692 * \code
1693 * start_over:
1694 * ++counter;
1695 *
1696 * goto start_over;
1697 * \endcode
1698 *
1699 * A label reference cursor refers to a label statement.
1700 */
1701 CXCursor_LabelRef = 48,
1702
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00001703 /**
1704 * \brief A reference to a set of overloaded functions or function templates
1705 * that has not yet been resolved to a specific function or function template.
1706 *
1707 * An overloaded declaration reference cursor occurs in C++ templates where
1708 * a dependent name refers to a function. For example:
1709 *
1710 * \code
1711 * template<typename T> void swap(T&, T&);
1712 *
1713 * struct X { ... };
1714 * void swap(X&, X&);
1715 *
1716 * template<typename T>
1717 * void reverse(T* first, T* last) {
1718 * while (first < last - 1) {
1719 * swap(*first, *--last);
1720 * ++first;
1721 * }
1722 * }
1723 *
1724 * struct Y { };
1725 * void swap(Y&, Y&);
1726 * \endcode
1727 *
1728 * Here, the identifier "swap" is associated with an overloaded declaration
1729 * reference. In the template definition, "swap" refers to either of the two
1730 * "swap" functions declared above, so both results will be available. At
1731 * instantiation time, "swap" may also refer to other functions found via
1732 * argument-dependent lookup (e.g., the "swap" function at the end of the
1733 * example).
1734 *
1735 * The functions \c clang_getNumOverloadedDecls() and
1736 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1737 * referenced by this cursor.
1738 */
1739 CXCursor_OverloadedDeclRef = 49,
1740
Douglas Gregor30093832012-02-15 00:54:55 +00001741 /**
1742 * \brief A reference to a variable that occurs in some non-expression
1743 * context, e.g., a C++ lambda capture list.
1744 */
1745 CXCursor_VariableRef = 50,
1746
1747 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001748
Douglas Gregor6007cf22010-01-22 22:29:16 +00001749 /* Error conditions */
1750 CXCursor_FirstInvalid = 70,
1751 CXCursor_InvalidFile = 70,
1752 CXCursor_NoDeclFound = 71,
1753 CXCursor_NotImplemented = 72,
Ted Kremeneke184ac52010-03-19 20:39:03 +00001754 CXCursor_InvalidCode = 73,
1755 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001756
Douglas Gregor6007cf22010-01-22 22:29:16 +00001757 /* Expressions */
1758 CXCursor_FirstExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001759
Douglas Gregor6007cf22010-01-22 22:29:16 +00001760 /**
1761 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001762 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001763 *
1764 * Unexposed expressions have the same operations as any other kind
1765 * of expression; one can extract their location information,
1766 * spelling, children, etc. However, the specific kind of the
1767 * expression is not reported.
1768 */
1769 CXCursor_UnexposedExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001770
Douglas Gregor6007cf22010-01-22 22:29:16 +00001771 /**
1772 * \brief An expression that refers to some value declaration, such
1773 * as a function, varible, or enumerator.
1774 */
1775 CXCursor_DeclRefExpr = 101,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001776
Douglas Gregor6007cf22010-01-22 22:29:16 +00001777 /**
1778 * \brief An expression that refers to a member of a struct, union,
1779 * class, Objective-C class, etc.
1780 */
1781 CXCursor_MemberRefExpr = 102,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001782
Douglas Gregor6007cf22010-01-22 22:29:16 +00001783 /** \brief An expression that calls a function. */
1784 CXCursor_CallExpr = 103,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001785
Douglas Gregor6007cf22010-01-22 22:29:16 +00001786 /** \brief An expression that sends a message to an Objective-C
1787 object or class. */
1788 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek33b9a422010-04-11 21:47:37 +00001789
1790 /** \brief An expression that represents a block literal. */
1791 CXCursor_BlockExpr = 105,
1792
Douglas Gregor4c362d52011-10-05 19:00:14 +00001793 /** \brief An integer literal.
1794 */
1795 CXCursor_IntegerLiteral = 106,
1796
1797 /** \brief A floating point number literal.
1798 */
1799 CXCursor_FloatingLiteral = 107,
1800
1801 /** \brief An imaginary number literal.
1802 */
1803 CXCursor_ImaginaryLiteral = 108,
1804
1805 /** \brief A string literal.
1806 */
1807 CXCursor_StringLiteral = 109,
1808
1809 /** \brief A character literal.
1810 */
1811 CXCursor_CharacterLiteral = 110,
1812
1813 /** \brief A parenthesized expression, e.g. "(1)".
1814 *
1815 * This AST node is only formed if full location information is requested.
1816 */
1817 CXCursor_ParenExpr = 111,
1818
1819 /** \brief This represents the unary-expression's (except sizeof and
1820 * alignof).
1821 */
1822 CXCursor_UnaryOperator = 112,
1823
1824 /** \brief [C99 6.5.2.1] Array Subscripting.
1825 */
1826 CXCursor_ArraySubscriptExpr = 113,
1827
1828 /** \brief A builtin binary operation expression such as "x + y" or
1829 * "x <= y".
1830 */
1831 CXCursor_BinaryOperator = 114,
1832
1833 /** \brief Compound assignment such as "+=".
1834 */
1835 CXCursor_CompoundAssignOperator = 115,
1836
1837 /** \brief The ?: ternary operator.
1838 */
1839 CXCursor_ConditionalOperator = 116,
1840
1841 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1842 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1843 *
1844 * For example: (int)f.
1845 */
1846 CXCursor_CStyleCastExpr = 117,
1847
1848 /** \brief [C99 6.5.2.5]
1849 */
1850 CXCursor_CompoundLiteralExpr = 118,
1851
1852 /** \brief Describes an C or C++ initializer list.
1853 */
1854 CXCursor_InitListExpr = 119,
1855
1856 /** \brief The GNU address of label extension, representing &&label.
1857 */
1858 CXCursor_AddrLabelExpr = 120,
1859
1860 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1861 */
1862 CXCursor_StmtExpr = 121,
1863
Benjamin Kramere56f3932011-12-23 17:00:35 +00001864 /** \brief Represents a C11 generic selection.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001865 */
1866 CXCursor_GenericSelectionExpr = 122,
1867
1868 /** \brief Implements the GNU __null extension, which is a name for a null
1869 * pointer constant that has integral type (e.g., int or long) and is the same
1870 * size and alignment as a pointer.
1871 *
1872 * The __null extension is typically only used by system headers, which define
1873 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1874 * match the size of a pointer).
1875 */
1876 CXCursor_GNUNullExpr = 123,
1877
1878 /** \brief C++'s static_cast<> expression.
1879 */
1880 CXCursor_CXXStaticCastExpr = 124,
1881
1882 /** \brief C++'s dynamic_cast<> expression.
1883 */
1884 CXCursor_CXXDynamicCastExpr = 125,
1885
1886 /** \brief C++'s reinterpret_cast<> expression.
1887 */
1888 CXCursor_CXXReinterpretCastExpr = 126,
1889
1890 /** \brief C++'s const_cast<> expression.
1891 */
1892 CXCursor_CXXConstCastExpr = 127,
1893
1894 /** \brief Represents an explicit C++ type conversion that uses "functional"
1895 * notion (C++ [expr.type.conv]).
1896 *
1897 * Example:
1898 * \code
1899 * x = int(0.5);
1900 * \endcode
1901 */
1902 CXCursor_CXXFunctionalCastExpr = 128,
1903
1904 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1905 */
1906 CXCursor_CXXTypeidExpr = 129,
1907
1908 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1909 */
1910 CXCursor_CXXBoolLiteralExpr = 130,
1911
1912 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1913 */
1914 CXCursor_CXXNullPtrLiteralExpr = 131,
1915
1916 /** \brief Represents the "this" expression in C++
1917 */
1918 CXCursor_CXXThisExpr = 132,
1919
1920 /** \brief [C++ 15] C++ Throw Expression.
1921 *
1922 * This handles 'throw' and 'throw' assignment-expression. When
1923 * assignment-expression isn't present, Op will be null.
1924 */
1925 CXCursor_CXXThrowExpr = 133,
1926
1927 /** \brief A new expression for memory allocation and constructor calls, e.g:
1928 * "new CXXNewExpr(foo)".
1929 */
1930 CXCursor_CXXNewExpr = 134,
1931
1932 /** \brief A delete expression for memory deallocation and destructor calls,
1933 * e.g. "delete[] pArray".
1934 */
1935 CXCursor_CXXDeleteExpr = 135,
1936
1937 /** \brief A unary expression.
1938 */
1939 CXCursor_UnaryExpr = 136,
1940
Douglas Gregor910c37c2011-11-11 22:35:18 +00001941 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor4c362d52011-10-05 19:00:14 +00001942 */
1943 CXCursor_ObjCStringLiteral = 137,
1944
James Dennett574cb4c2012-06-15 05:41:51 +00001945 /** \brief An Objective-C \@encode expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001946 */
1947 CXCursor_ObjCEncodeExpr = 138,
1948
James Dennett574cb4c2012-06-15 05:41:51 +00001949 /** \brief An Objective-C \@selector expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001950 */
1951 CXCursor_ObjCSelectorExpr = 139,
1952
James Dennett1355bd12012-06-11 06:19:40 +00001953 /** \brief An Objective-C \@protocol expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001954 */
1955 CXCursor_ObjCProtocolExpr = 140,
1956
1957 /** \brief An Objective-C "bridged" cast expression, which casts between
1958 * Objective-C pointers and C pointers, transferring ownership in the process.
1959 *
1960 * \code
1961 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1962 * \endcode
1963 */
1964 CXCursor_ObjCBridgedCastExpr = 141,
1965
1966 /** \brief Represents a C++0x pack expansion that produces a sequence of
1967 * expressions.
1968 *
1969 * A pack expansion expression contains a pattern (which itself is an
1970 * expression) followed by an ellipsis. For example:
1971 *
1972 * \code
1973 * template<typename F, typename ...Types>
1974 * void forward(F f, Types &&...args) {
1975 * f(static_cast<Types&&>(args)...);
1976 * }
1977 * \endcode
1978 */
1979 CXCursor_PackExpansionExpr = 142,
1980
1981 /** \brief Represents an expression that computes the length of a parameter
1982 * pack.
1983 *
1984 * \code
1985 * template<typename ...Types>
1986 * struct count {
1987 * static const unsigned value = sizeof...(Types);
1988 * };
1989 * \endcode
1990 */
1991 CXCursor_SizeOfPackExpr = 143,
1992
Douglas Gregor30093832012-02-15 00:54:55 +00001993 /* \brief Represents a C++ lambda expression that produces a local function
1994 * object.
1995 *
1996 * \code
1997 * void abssort(float *x, unsigned N) {
1998 * std::sort(x, x + N,
1999 * [](float a, float b) {
2000 * return std::abs(a) < std::abs(b);
2001 * });
2002 * }
2003 * \endcode
2004 */
2005 CXCursor_LambdaExpr = 144,
2006
Ted Kremenek77006f62012-03-06 20:06:06 +00002007 /** \brief Objective-c Boolean Literal.
2008 */
2009 CXCursor_ObjCBoolLiteralExpr = 145,
2010
Argyrios Kyrtzidisc2233be2013-04-23 17:57:17 +00002011 /** \brief Represents the "self" expression in a ObjC method.
2012 */
2013 CXCursor_ObjCSelfExpr = 146,
2014
2015 CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002016
Douglas Gregor6007cf22010-01-22 22:29:16 +00002017 /* Statements */
2018 CXCursor_FirstStmt = 200,
2019 /**
2020 * \brief A statement whose specific kind is not exposed via this
2021 * interface.
2022 *
2023 * Unexposed statements have the same operations as any other kind of
2024 * statement; one can extract their location information, spelling,
2025 * children, etc. However, the specific kind of the statement is not
2026 * reported.
2027 */
2028 CXCursor_UnexposedStmt = 200,
Douglas Gregora93ab662010-09-10 00:22:18 +00002029
2030 /** \brief A labelled statement in a function.
2031 *
2032 * This cursor kind is used to describe the "start_over:" label statement in
2033 * the following example:
2034 *
2035 * \code
2036 * start_over:
2037 * ++counter;
2038 * \endcode
2039 *
2040 */
2041 CXCursor_LabelStmt = 201,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002042
2043 /** \brief A group of statements like { stmt stmt }.
2044 *
2045 * This cursor kind is used to describe compound statements, e.g. function
2046 * bodies.
2047 */
2048 CXCursor_CompoundStmt = 202,
2049
Benjamin Kramer2501f142013-10-20 11:47:15 +00002050 /** \brief A case statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002051 */
2052 CXCursor_CaseStmt = 203,
2053
2054 /** \brief A default statement.
2055 */
2056 CXCursor_DefaultStmt = 204,
2057
2058 /** \brief An if statement
2059 */
2060 CXCursor_IfStmt = 205,
2061
2062 /** \brief A switch statement.
2063 */
2064 CXCursor_SwitchStmt = 206,
2065
2066 /** \brief A while statement.
2067 */
2068 CXCursor_WhileStmt = 207,
2069
2070 /** \brief A do statement.
2071 */
2072 CXCursor_DoStmt = 208,
2073
2074 /** \brief A for statement.
2075 */
2076 CXCursor_ForStmt = 209,
2077
2078 /** \brief A goto statement.
2079 */
2080 CXCursor_GotoStmt = 210,
2081
2082 /** \brief An indirect goto statement.
2083 */
2084 CXCursor_IndirectGotoStmt = 211,
2085
2086 /** \brief A continue statement.
2087 */
2088 CXCursor_ContinueStmt = 212,
2089
2090 /** \brief A break statement.
2091 */
2092 CXCursor_BreakStmt = 213,
2093
2094 /** \brief A return statement.
2095 */
2096 CXCursor_ReturnStmt = 214,
2097
Chad Rosierde70e0e2012-08-25 00:11:56 +00002098 /** \brief A GCC inline assembly statement extension.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002099 */
Chad Rosierde70e0e2012-08-25 00:11:56 +00002100 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5eae0732012-09-24 19:27:20 +00002101 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002102
James Dennett574cb4c2012-06-15 05:41:51 +00002103 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002104 */
2105 CXCursor_ObjCAtTryStmt = 216,
2106
James Dennett574cb4c2012-06-15 05:41:51 +00002107 /** \brief Objective-C's \@catch statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002108 */
2109 CXCursor_ObjCAtCatchStmt = 217,
2110
James Dennett574cb4c2012-06-15 05:41:51 +00002111 /** \brief Objective-C's \@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002112 */
2113 CXCursor_ObjCAtFinallyStmt = 218,
2114
James Dennett574cb4c2012-06-15 05:41:51 +00002115 /** \brief Objective-C's \@throw statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002116 */
2117 CXCursor_ObjCAtThrowStmt = 219,
2118
James Dennett574cb4c2012-06-15 05:41:51 +00002119 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002120 */
2121 CXCursor_ObjCAtSynchronizedStmt = 220,
2122
2123 /** \brief Objective-C's autorelease pool statement.
2124 */
2125 CXCursor_ObjCAutoreleasePoolStmt = 221,
2126
2127 /** \brief Objective-C's collection statement.
2128 */
2129 CXCursor_ObjCForCollectionStmt = 222,
2130
2131 /** \brief C++'s catch statement.
2132 */
2133 CXCursor_CXXCatchStmt = 223,
2134
2135 /** \brief C++'s try statement.
2136 */
2137 CXCursor_CXXTryStmt = 224,
2138
2139 /** \brief C++'s for (* : *) statement.
2140 */
2141 CXCursor_CXXForRangeStmt = 225,
2142
2143 /** \brief Windows Structured Exception Handling's try statement.
2144 */
2145 CXCursor_SEHTryStmt = 226,
2146
2147 /** \brief Windows Structured Exception Handling's except statement.
2148 */
2149 CXCursor_SEHExceptStmt = 227,
2150
2151 /** \brief Windows Structured Exception Handling's finally statement.
2152 */
2153 CXCursor_SEHFinallyStmt = 228,
2154
Chad Rosier32503022012-06-11 20:47:18 +00002155 /** \brief A MS inline assembly statement extension.
2156 */
2157 CXCursor_MSAsmStmt = 229,
2158
Douglas Gregor4c362d52011-10-05 19:00:14 +00002159 /** \brief The null satement ";": C99 6.8.3p3.
2160 *
2161 * This cursor kind is used to describe the null statement.
2162 */
2163 CXCursor_NullStmt = 230,
2164
2165 /** \brief Adaptor class for mixing declarations with statements and
2166 * expressions.
2167 */
2168 CXCursor_DeclStmt = 231,
2169
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002170 /** \brief OpenMP parallel directive.
2171 */
2172 CXCursor_OMPParallelDirective = 232,
2173
2174 CXCursor_LastStmt = CXCursor_OMPParallelDirective,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002175
Douglas Gregor6007cf22010-01-22 22:29:16 +00002176 /**
2177 * \brief Cursor that represents the translation unit itself.
2178 *
2179 * The translation unit cursor exists primarily to act as the root
2180 * cursor for traversing the contents of a translation unit.
2181 */
Ted Kremenekbff31432010-02-18 03:09:07 +00002182 CXCursor_TranslationUnit = 300,
2183
Bill Wendling44426052012-12-20 19:22:21 +00002184 /* Attributes */
Ted Kremenekbff31432010-02-18 03:09:07 +00002185 CXCursor_FirstAttr = 400,
2186 /**
2187 * \brief An attribute whose specific kind is not exposed via this
2188 * interface.
2189 */
2190 CXCursor_UnexposedAttr = 400,
2191
2192 CXCursor_IBActionAttr = 401,
2193 CXCursor_IBOutletAttr = 402,
Ted Kremenek26bde772010-05-19 17:38:06 +00002194 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis2cb4e3c2011-09-13 17:39:31 +00002195 CXCursor_CXXFinalAttr = 404,
2196 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggenca98f2a2011-10-13 09:41:32 +00002197 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002198 CXCursor_AsmLabelAttr = 407,
Argyrios Kyrtzidis16834f12013-09-25 00:14:38 +00002199 CXCursor_PackedAttr = 408,
2200 CXCursor_LastAttr = CXCursor_PackedAttr,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002201
2202 /* Preprocessing */
2203 CXCursor_PreprocessingDirective = 500,
Douglas Gregor06d6d322010-03-18 18:04:21 +00002204 CXCursor_MacroDefinition = 501,
Chandler Carruth9e4704a2011-07-14 08:41:15 +00002205 CXCursor_MacroExpansion = 502,
2206 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregor796d76a2010-10-20 22:00:55 +00002207 CXCursor_InclusionDirective = 503,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002208 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis50e5b1d2012-10-05 00:22:24 +00002209 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2210
2211 /* Extra Declarations */
2212 /**
2213 * \brief A module import declaration.
2214 */
2215 CXCursor_ModuleImportDecl = 600,
2216 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2217 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregor6007cf22010-01-22 22:29:16 +00002218};
2219
2220/**
2221 * \brief A cursor representing some element in the abstract syntax tree for
2222 * a translation unit.
2223 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002224 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregor6007cf22010-01-22 22:29:16 +00002225 * program--declaration, statements, expressions, references to declarations,
2226 * etc.--under a single "cursor" abstraction with a common set of operations.
2227 * Common operation for a cursor include: getting the physical location in
2228 * a source file where the cursor points, getting the name associated with a
2229 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2230 *
2231 * Cursors can be produced in two specific ways.
2232 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2233 * from which one can use clang_visitChildren() to explore the rest of the
2234 * translation unit. clang_getCursor() maps from a physical source location
2235 * to the entity that resides at that location, allowing one to map from the
2236 * source code into the AST.
2237 */
2238typedef struct {
2239 enum CXCursorKind kind;
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00002240 int xdata;
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +00002241 const void *data[3];
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002242} CXCursor;
Douglas Gregor6007cf22010-01-22 22:29:16 +00002243
2244/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002245 * \brief A comment AST node.
2246 */
2247typedef struct {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00002248 const void *ASTNode;
2249 CXTranslationUnit TranslationUnit;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002250} CXComment;
2251
2252/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002253 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2254 *
2255 * @{
2256 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002257
Douglas Gregor6007cf22010-01-22 22:29:16 +00002258/**
2259 * \brief Retrieve the NULL cursor, which represents no entity.
2260 */
2261CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002262
Douglas Gregor6007cf22010-01-22 22:29:16 +00002263/**
2264 * \brief Retrieve the cursor that represents the given translation unit.
2265 *
2266 * The translation unit cursor can be used to start traversing the
2267 * various declarations within the given translation unit.
2268 */
2269CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2270
2271/**
2272 * \brief Determine whether two cursors are equivalent.
2273 */
2274CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002275
Douglas Gregor6007cf22010-01-22 22:29:16 +00002276/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002277 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002278 */
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002279CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002280
2281/**
Douglas Gregor06a3f302010-11-20 00:09:34 +00002282 * \brief Compute a hash value for the given cursor.
2283 */
2284CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2285
2286/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002287 * \brief Retrieve the kind of the given cursor.
2288 */
2289CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2290
2291/**
2292 * \brief Determine whether the given cursor kind represents a declaration.
2293 */
2294CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2295
2296/**
2297 * \brief Determine whether the given cursor kind represents a simple
2298 * reference.
2299 *
2300 * Note that other kinds of cursors (such as expressions) can also refer to
2301 * other cursors. Use clang_getCursorReferenced() to determine whether a
2302 * particular cursor refers to another entity.
2303 */
2304CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2305
2306/**
2307 * \brief Determine whether the given cursor kind represents an expression.
2308 */
2309CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2310
2311/**
2312 * \brief Determine whether the given cursor kind represents a statement.
2313 */
2314CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2315
2316/**
Douglas Gregora98034a2011-07-06 03:00:34 +00002317 * \brief Determine whether the given cursor kind represents an attribute.
2318 */
2319CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2320
2321/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002322 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregor6007cf22010-01-22 22:29:16 +00002323 * cursor.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002324 */
Douglas Gregor6007cf22010-01-22 22:29:16 +00002325CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2326
2327/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002328 * \brief Determine whether the given cursor kind represents a translation
2329 * unit.
Douglas Gregor6007cf22010-01-22 22:29:16 +00002330 */
2331CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002332
Ted Kremenekff9021b2010-03-08 21:17:29 +00002333/***
Douglas Gregor92a524f2010-03-18 00:42:48 +00002334 * \brief Determine whether the given cursor represents a preprocessing
2335 * element, such as a preprocessor directive or macro instantiation.
2336 */
2337CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2338
2339/***
Ted Kremenekff9021b2010-03-08 21:17:29 +00002340 * \brief Determine whether the given cursor represents a currently
2341 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2342 */
2343CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2344
Douglas Gregor6007cf22010-01-22 22:29:16 +00002345/**
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002346 * \brief Describe the linkage of the entity referred to by a cursor.
2347 */
2348enum CXLinkageKind {
2349 /** \brief This value indicates that no linkage information is available
2350 * for a provided CXCursor. */
2351 CXLinkage_Invalid,
2352 /**
2353 * \brief This is the linkage for variables, parameters, and so on that
2354 * have automatic storage. This covers normal (non-extern) local variables.
2355 */
2356 CXLinkage_NoLinkage,
2357 /** \brief This is the linkage for static variables and static functions. */
2358 CXLinkage_Internal,
2359 /** \brief This is the linkage for entities with external linkage that live
2360 * in C++ anonymous namespaces.*/
2361 CXLinkage_UniqueExternal,
2362 /** \brief This is the linkage for entities with true, external linkage. */
2363 CXLinkage_External
2364};
2365
2366/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002367 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002368 */
2369CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2370
2371/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002372 * \brief Determine the availability of the entity that this cursor refers to,
2373 * taking the current target platform into account.
Douglas Gregorf757a122010-08-23 23:00:57 +00002374 *
2375 * \param cursor The cursor to query.
2376 *
2377 * \returns The availability of the cursor.
2378 */
2379CINDEX_LINKAGE enum CXAvailabilityKind
2380clang_getCursorAvailability(CXCursor cursor);
2381
2382/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002383 * Describes the availability of a given entity on a particular platform, e.g.,
2384 * a particular class might only be available on Mac OS 10.7 or newer.
2385 */
2386typedef struct CXPlatformAvailability {
2387 /**
2388 * \brief A string that describes the platform for which this structure
2389 * provides availability information.
2390 *
2391 * Possible values are "ios" or "macosx".
2392 */
2393 CXString Platform;
2394 /**
2395 * \brief The version number in which this entity was introduced.
2396 */
2397 CXVersion Introduced;
2398 /**
2399 * \brief The version number in which this entity was deprecated (but is
2400 * still available).
2401 */
2402 CXVersion Deprecated;
2403 /**
2404 * \brief The version number in which this entity was obsoleted, and therefore
2405 * is no longer available.
2406 */
2407 CXVersion Obsoleted;
2408 /**
2409 * \brief Whether the entity is unconditionally unavailable on this platform.
2410 */
2411 int Unavailable;
2412 /**
2413 * \brief An optional message to provide to a user of this API, e.g., to
2414 * suggest replacement APIs.
2415 */
2416 CXString Message;
2417} CXPlatformAvailability;
2418
2419/**
2420 * \brief Determine the availability of the entity that this cursor refers to
2421 * on any platforms for which availability information is known.
2422 *
2423 * \param cursor The cursor to query.
2424 *
2425 * \param always_deprecated If non-NULL, will be set to indicate whether the
2426 * entity is deprecated on all platforms.
2427 *
2428 * \param deprecated_message If non-NULL, will be set to the message text
2429 * provided along with the unconditional deprecation of this entity. The client
2430 * is responsible for deallocating this string.
2431 *
James Dennett574cb4c2012-06-15 05:41:51 +00002432 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregord6225d32012-05-08 00:14:45 +00002433 * entity is unavailable on all platforms.
2434 *
2435 * \param unavailable_message If non-NULL, will be set to the message text
2436 * provided along with the unconditional unavailability of this entity. The
2437 * client is responsible for deallocating this string.
2438 *
2439 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2440 * that will be populated with platform availability information, up to either
2441 * the number of platforms for which availability information is available (as
2442 * returned by this function) or \c availability_size, whichever is smaller.
2443 *
2444 * \param availability_size The number of elements available in the
2445 * \c availability array.
2446 *
2447 * \returns The number of platforms (N) for which availability information is
2448 * available (which is unrelated to \c availability_size).
2449 *
2450 * Note that the client is responsible for calling
2451 * \c clang_disposeCXPlatformAvailability to free each of the
2452 * platform-availability structures returned. There are
2453 * \c min(N, availability_size) such structures.
2454 */
2455CINDEX_LINKAGE int
2456clang_getCursorPlatformAvailability(CXCursor cursor,
2457 int *always_deprecated,
2458 CXString *deprecated_message,
2459 int *always_unavailable,
2460 CXString *unavailable_message,
2461 CXPlatformAvailability *availability,
2462 int availability_size);
2463
2464/**
2465 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2466 */
2467CINDEX_LINKAGE void
2468clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2469
2470/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002471 * \brief Describe the "language" of the entity referred to by a cursor.
2472 */
Reid Kleckner9e3bc722013-12-30 17:48:49 +00002473enum CXLanguageKind {
Ted Kremenekee457512010-04-14 20:58:32 +00002474 CXLanguage_Invalid = 0,
Ted Kremenek4ed29252010-04-12 21:22:16 +00002475 CXLanguage_C,
2476 CXLanguage_ObjC,
Ted Kremenekee457512010-04-14 20:58:32 +00002477 CXLanguage_CPlusPlus
Ted Kremenek4ed29252010-04-12 21:22:16 +00002478};
2479
2480/**
2481 * \brief Determine the "language" of the entity referred to by a given cursor.
2482 */
2483CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2484
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002485/**
2486 * \brief Returns the translation unit that a cursor originated from.
2487 */
2488CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2489
Ted Kremenekc0b98662013-04-24 07:17:12 +00002490
2491/**
2492 * \brief A fast container representing a set of CXCursors.
2493 */
2494typedef struct CXCursorSetImpl *CXCursorSet;
2495
2496/**
2497 * \brief Creates an empty CXCursorSet.
2498 */
2499CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2500
2501/**
2502 * \brief Disposes a CXCursorSet and releases its associated memory.
2503 */
2504CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2505
2506/**
2507 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2508 *
2509 * \returns non-zero if the set contains the specified cursor.
2510*/
2511CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2512 CXCursor cursor);
2513
2514/**
2515 * \brief Inserts a CXCursor into a CXCursorSet.
2516 *
2517 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2518*/
2519CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2520 CXCursor cursor);
2521
Douglas Gregor0576ce72010-09-22 21:22:29 +00002522/**
2523 * \brief Determine the semantic parent of the given cursor.
2524 *
2525 * The semantic parent of a cursor is the cursor that semantically contains
2526 * the given \p cursor. For many declarations, the lexical and semantic parents
2527 * are equivalent (the lexical parent is returned by
2528 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2529 * definitions are provided out-of-line. For example:
2530 *
2531 * \code
2532 * class C {
2533 * void f();
2534 * };
2535 *
2536 * void C::f() { }
2537 * \endcode
2538 *
2539 * In the out-of-line definition of \c C::f, the semantic parent is the
2540 * the class \c C, of which this function is a member. The lexical parent is
2541 * the place where the declaration actually occurs in the source code; in this
2542 * case, the definition occurs in the translation unit. In general, the
2543 * lexical parent for a given entity can change without affecting the semantics
2544 * of the program, and the lexical parent of different declarations of the
2545 * same entity may be different. Changing the semantic parent of a declaration,
2546 * on the other hand, can have a major impact on semantics, and redeclarations
2547 * of a particular entity should all have the same semantic context.
2548 *
2549 * In the example above, both declarations of \c C::f have \c C as their
2550 * semantic context, while the lexical context of the first \c C::f is \c C
2551 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002552 *
2553 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002554 */
2555CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2556
2557/**
2558 * \brief Determine the lexical parent of the given cursor.
2559 *
2560 * The lexical parent of a cursor is the cursor in which the given \p cursor
2561 * was actually written. For many declarations, the lexical and semantic parents
2562 * are equivalent (the semantic parent is returned by
2563 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2564 * definitions are provided out-of-line. For example:
2565 *
2566 * \code
2567 * class C {
2568 * void f();
2569 * };
2570 *
2571 * void C::f() { }
2572 * \endcode
2573 *
2574 * In the out-of-line definition of \c C::f, the semantic parent is the
2575 * the class \c C, of which this function is a member. The lexical parent is
2576 * the place where the declaration actually occurs in the source code; in this
2577 * case, the definition occurs in the translation unit. In general, the
2578 * lexical parent for a given entity can change without affecting the semantics
2579 * of the program, and the lexical parent of different declarations of the
2580 * same entity may be different. Changing the semantic parent of a declaration,
2581 * on the other hand, can have a major impact on semantics, and redeclarations
2582 * of a particular entity should all have the same semantic context.
2583 *
2584 * In the example above, both declarations of \c C::f have \c C as their
2585 * semantic context, while the lexical context of the first \c C::f is \c C
2586 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002587 *
2588 * For declarations written in the global scope, the lexical parent is
2589 * the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002590 */
2591CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor99a26af2010-10-01 20:25:15 +00002592
2593/**
2594 * \brief Determine the set of methods that are overridden by the given
2595 * method.
2596 *
2597 * In both Objective-C and C++, a method (aka virtual member function,
2598 * in C++) can override a virtual method in a base class. For
2599 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidisbfb24252012-03-08 00:20:03 +00002600 * base class, its protocols, or its categories' protocols, that has the same
2601 * selector and is of the same kind (class or instance).
2602 * If no such method exists, the search continues to the class's superclass,
2603 * its protocols, and its categories, and so on. A method from an Objective-C
2604 * implementation is considered to override the same methods as its
2605 * corresponding method in the interface.
Douglas Gregor99a26af2010-10-01 20:25:15 +00002606 *
2607 * For C++, a virtual member function overrides any virtual member
2608 * function with the same signature that occurs in its base
2609 * classes. With multiple inheritance, a virtual member function can
2610 * override several virtual member functions coming from different
2611 * base classes.
2612 *
2613 * In all cases, this function determines the immediate overridden
2614 * method, rather than all of the overridden methods. For example, if
2615 * a method is originally declared in a class A, then overridden in B
2616 * (which in inherits from A) and also in C (which inherited from B),
2617 * then the only overridden method returned from this function when
2618 * invoked on C's method will be B's method. The client may then
2619 * invoke this function again, given the previously-found overridden
2620 * methods, to map out the complete method-override set.
2621 *
2622 * \param cursor A cursor representing an Objective-C or C++
2623 * method. This routine will compute the set of methods that this
2624 * method overrides.
2625 *
2626 * \param overridden A pointer whose pointee will be replaced with a
2627 * pointer to an array of cursors, representing the set of overridden
2628 * methods. If there are no overridden methods, the pointee will be
2629 * set to NULL. The pointee must be freed via a call to
2630 * \c clang_disposeOverriddenCursors().
2631 *
2632 * \param num_overridden A pointer to the number of overridden
2633 * functions, will be set to the number of overridden functions in the
2634 * array pointed to by \p overridden.
2635 */
2636CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2637 CXCursor **overridden,
2638 unsigned *num_overridden);
2639
2640/**
2641 * \brief Free the set of overridden cursors returned by \c
2642 * clang_getOverriddenCursors().
2643 */
2644CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2645
Ted Kremenek4ed29252010-04-12 21:22:16 +00002646/**
Douglas Gregor796d76a2010-10-20 22:00:55 +00002647 * \brief Retrieve the file that is included by the given inclusion directive
2648 * cursor.
2649 */
2650CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2651
2652/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002653 * @}
2654 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002655
Douglas Gregor6007cf22010-01-22 22:29:16 +00002656/**
2657 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2658 *
2659 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2660 * routines help map between cursors and the physical locations where the
2661 * described entities occur in the source code. The mapping is provided in
2662 * both directions, so one can map from source code to the AST and back.
2663 *
2664 * @{
Steve Naroffa1c72842009-08-28 15:28:48 +00002665 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002666
Steve Naroff20bad0b2009-10-21 13:56:23 +00002667/**
Douglas Gregor816fd362010-01-22 21:44:22 +00002668 * \brief Map a source location to the cursor that describes the entity at that
2669 * location in the source code.
2670 *
2671 * clang_getCursor() maps an arbitrary source location within a translation
2672 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002673 * location. For example, given an expression \c x + y, invoking
Douglas Gregor816fd362010-01-22 21:44:22 +00002674 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002675 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregor816fd362010-01-22 21:44:22 +00002676 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2677 * will return a cursor referring to the "+" expression.
2678 *
2679 * \returns a cursor representing the entity at the given source location, or
2680 * a NULL cursor if no such entity can be found.
Steve Naroff20bad0b2009-10-21 13:56:23 +00002681 */
Douglas Gregor816fd362010-01-22 21:44:22 +00002682CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002683
Douglas Gregor66a58812010-01-18 22:46:11 +00002684/**
2685 * \brief Retrieve the physical location of the source constructor referenced
2686 * by the given cursor.
2687 *
2688 * The location of a declaration is typically the location of the name of that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002689 * declaration, where the name of that declaration would occur if it is
2690 * unnamed, or some keyword that introduces that particular declaration.
2691 * The location of a reference is where that reference occurs within the
Douglas Gregor66a58812010-01-18 22:46:11 +00002692 * source code.
2693 */
2694CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregor6007cf22010-01-22 22:29:16 +00002695
Douglas Gregor6b8232f2010-01-19 19:34:47 +00002696/**
2697 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002698 * the given cursor.
2699 *
2700 * The extent of a cursor starts with the file/line/column pointing at the
2701 * first character within the source construct that the cursor refers to and
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002702 * ends with the last character withinin that source construct. For a
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002703 * declaration, the extent covers the declaration itself. For a reference,
2704 * the extent covers the location of the reference (e.g., where the referenced
2705 * entity was actually used).
2706 */
2707CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorad27e8b2010-01-19 01:20:04 +00002708
Douglas Gregor6007cf22010-01-22 22:29:16 +00002709/**
2710 * @}
2711 */
Ted Kremeneka5940822010-08-26 01:42:22 +00002712
Douglas Gregor6007cf22010-01-22 22:29:16 +00002713/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002714 * \defgroup CINDEX_TYPES Type information for CXCursors
2715 *
2716 * @{
2717 */
2718
2719/**
2720 * \brief Describes the kind of type
2721 */
2722enum CXTypeKind {
2723 /**
2724 * \brief Reprents an invalid type (e.g., where no type is available).
2725 */
2726 CXType_Invalid = 0,
2727
2728 /**
2729 * \brief A type whose specific kind is not exposed via this
2730 * interface.
2731 */
2732 CXType_Unexposed = 1,
2733
2734 /* Builtin types */
2735 CXType_Void = 2,
2736 CXType_Bool = 3,
2737 CXType_Char_U = 4,
2738 CXType_UChar = 5,
2739 CXType_Char16 = 6,
2740 CXType_Char32 = 7,
2741 CXType_UShort = 8,
2742 CXType_UInt = 9,
2743 CXType_ULong = 10,
2744 CXType_ULongLong = 11,
2745 CXType_UInt128 = 12,
2746 CXType_Char_S = 13,
2747 CXType_SChar = 14,
2748 CXType_WChar = 15,
2749 CXType_Short = 16,
2750 CXType_Int = 17,
2751 CXType_Long = 18,
2752 CXType_LongLong = 19,
2753 CXType_Int128 = 20,
2754 CXType_Float = 21,
2755 CXType_Double = 22,
2756 CXType_LongDouble = 23,
2757 CXType_NullPtr = 24,
2758 CXType_Overload = 25,
2759 CXType_Dependent = 26,
2760 CXType_ObjCId = 27,
2761 CXType_ObjCClass = 28,
2762 CXType_ObjCSel = 29,
2763 CXType_FirstBuiltin = CXType_Void,
2764 CXType_LastBuiltin = CXType_ObjCSel,
2765
2766 CXType_Complex = 100,
2767 CXType_Pointer = 101,
2768 CXType_BlockPointer = 102,
2769 CXType_LValueReference = 103,
2770 CXType_RValueReference = 104,
2771 CXType_Record = 105,
2772 CXType_Enum = 106,
2773 CXType_Typedef = 107,
2774 CXType_ObjCInterface = 108,
Ted Kremenekc1508872010-06-21 20:15:39 +00002775 CXType_ObjCObjectPointer = 109,
2776 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002777 CXType_FunctionProto = 111,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002778 CXType_ConstantArray = 112,
Argyrios Kyrtzidis0661a712013-07-23 17:36:21 +00002779 CXType_Vector = 113,
2780 CXType_IncompleteArray = 114,
2781 CXType_VariableArray = 115,
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00002782 CXType_DependentSizedArray = 116,
2783 CXType_MemberPointer = 117
Ted Kremenek6bca9842010-05-14 21:29:26 +00002784};
2785
2786/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002787 * \brief Describes the calling convention of a function type
2788 */
2789enum CXCallingConv {
2790 CXCallingConv_Default = 0,
2791 CXCallingConv_C = 1,
2792 CXCallingConv_X86StdCall = 2,
2793 CXCallingConv_X86FastCall = 3,
2794 CXCallingConv_X86ThisCall = 4,
2795 CXCallingConv_X86Pascal = 5,
2796 CXCallingConv_AAPCS = 6,
2797 CXCallingConv_AAPCS_VFP = 7,
Derek Schuffa2020962012-10-16 22:30:41 +00002798 CXCallingConv_PnaclCall = 8,
Guy Benyeif0a014b2012-12-25 08:53:55 +00002799 CXCallingConv_IntelOclBicc = 9,
Charles Davisb5a214e2013-08-30 04:39:01 +00002800 CXCallingConv_X86_64Win64 = 10,
2801 CXCallingConv_X86_64SysV = 11,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002802
2803 CXCallingConv_Invalid = 100,
2804 CXCallingConv_Unexposed = 200
2805};
2806
2807
2808/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002809 * \brief The type of an element in the abstract syntax tree.
2810 *
2811 */
2812typedef struct {
2813 enum CXTypeKind kind;
2814 void *data[2];
2815} CXType;
2816
2817/**
2818 * \brief Retrieve the type of a CXCursor (if any).
2819 */
2820CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2821
2822/**
Dmitri Gribenko00353722013-02-15 21:15:49 +00002823 * \brief Pretty-print the underlying type using the rules of the
2824 * language of the translation unit from which it came.
2825 *
2826 * If the type is invalid, an empty string is returned.
2827 */
2828CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2829
2830/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002831 * \brief Retrieve the underlying type of a typedef declaration.
2832 *
2833 * If the cursor does not reference a typedef declaration, an invalid type is
2834 * returned.
2835 */
2836CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2837
2838/**
2839 * \brief Retrieve the integer type of an enum declaration.
2840 *
2841 * If the cursor does not reference an enum declaration, an invalid type is
2842 * returned.
2843 */
2844CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2845
2846/**
2847 * \brief Retrieve the integer value of an enum constant declaration as a signed
2848 * long long.
2849 *
2850 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2851 * Since this is also potentially a valid constant value, the kind of the cursor
2852 * must be verified before calling this function.
2853 */
2854CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2855
2856/**
2857 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2858 * long long.
2859 *
2860 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2861 * Since this is also potentially a valid constant value, the kind of the cursor
2862 * must be verified before calling this function.
2863 */
2864CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2865
2866/**
Dmitri Gribenkob506ba12012-12-04 15:13:46 +00002867 * \brief Retrieve the bit width of a bit field declaration as an integer.
2868 *
2869 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2870 */
2871CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2872
2873/**
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002874 * \brief Retrieve the number of non-variadic arguments associated with a given
2875 * cursor.
2876 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002877 * The number of arguments can be determined for calls as well as for
2878 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002879 */
2880CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2881
2882/**
2883 * \brief Retrieve the argument cursor of a function or method.
2884 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002885 * The argument cursor can be determined for calls as well as for declarations
2886 * of functions or methods. For other cursors and for invalid indices, an
2887 * invalid cursor is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002888 */
2889CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2890
2891/**
James Dennett574cb4c2012-06-15 05:41:51 +00002892 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002893 *
James Dennett574cb4c2012-06-15 05:41:51 +00002894 * \returns non-zero if the CXTypes represent the same type and
2895 * zero otherwise.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002896 */
2897CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2898
2899/**
2900 * \brief Return the canonical type for a CXType.
2901 *
2902 * Clang's type system explicitly models typedefs and all the ways
2903 * a specific type can be represented. The canonical type is the underlying
2904 * type with all the "sugar" removed. For example, if 'T' is a typedef
2905 * for 'int', the canonical type for 'T' would be 'int'.
2906 */
2907CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2908
2909/**
James Dennett574cb4c2012-06-15 05:41:51 +00002910 * \brief Determine whether a CXType has the "const" qualifier set,
2911 * without looking through typedefs that may have added "const" at a
2912 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002913 */
2914CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2915
2916/**
James Dennett574cb4c2012-06-15 05:41:51 +00002917 * \brief Determine whether a CXType has the "volatile" qualifier set,
2918 * without looking through typedefs that may have added "volatile" at
2919 * a different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002920 */
2921CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2922
2923/**
James Dennett574cb4c2012-06-15 05:41:51 +00002924 * \brief Determine whether a CXType has the "restrict" qualifier set,
2925 * without looking through typedefs that may have added "restrict" at a
2926 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002927 */
2928CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2929
2930/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002931 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002932 */
2933CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2934
2935/**
2936 * \brief Return the cursor for the declaration of the given type.
2937 */
2938CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2939
David Chisnall50e4eba2010-12-30 14:05:53 +00002940/**
2941 * Returns the Objective-C type encoding for the specified declaration.
2942 */
2943CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek6bca9842010-05-14 21:29:26 +00002944
2945/**
2946 * \brief Retrieve the spelling of a given CXTypeKind.
2947 */
2948CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2949
2950/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002951 * \brief Retrieve the calling convention associated with a function type.
2952 *
2953 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2954 */
2955CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2956
2957/**
Alp Toker314cc812014-01-25 16:55:45 +00002958 * \brief Retrieve the return type associated with a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002959 *
2960 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenekc1508872010-06-21 20:15:39 +00002961 */
2962CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2963
2964/**
Alp Toker601b22c2014-01-21 23:35:24 +00002965 * \brief Retrieve the number of non-variadic parameters associated with a
James Dennett574cb4c2012-06-15 05:41:51 +00002966 * function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002967 *
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002968 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002969 */
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002970CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002971
2972/**
Alp Toker601b22c2014-01-21 23:35:24 +00002973 * \brief Retrieve the type of a parameter of a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002974 *
James Dennett574cb4c2012-06-15 05:41:51 +00002975 * If a non-function type is passed in or the function does not have enough
2976 * parameters, an invalid type is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002977 */
2978CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2979
2980/**
2981 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002982 */
2983CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2984
2985/**
Alp Toker314cc812014-01-25 16:55:45 +00002986 * \brief Retrieve the return type associated with a given cursor.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002987 *
2988 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00002989 */
2990CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2991
2992/**
Ted Kremenek0c7476a2010-07-30 00:14:11 +00002993 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2994 * otherwise.
2995 */
2996CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2997
2998/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002999 * \brief Return the element type of an array, complex, or vector type.
3000 *
3001 * If a type is passed in that is not an array, complex, or vector type,
3002 * an invalid type is returned.
3003 */
3004CINDEX_LINKAGE CXType clang_getElementType(CXType T);
3005
3006/**
3007 * \brief Return the number of elements of an array or vector type.
3008 *
3009 * If a type is passed in that is not an array or vector type,
3010 * -1 is returned.
3011 */
3012CINDEX_LINKAGE long long clang_getNumElements(CXType T);
3013
3014/**
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00003015 * \brief Return the element type of an array type.
3016 *
3017 * If a non-array type is passed in, an invalid type is returned.
3018 */
3019CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
3020
3021/**
Sylvestre Ledru830885c2012-07-23 08:59:39 +00003022 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00003023 *
3024 * If a non-array type is passed in, -1 is returned.
3025 */
3026CINDEX_LINKAGE long long clang_getArraySize(CXType T);
3027
3028/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003029 * \brief List the possible error codes for \c clang_Type_getSizeOf,
3030 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
3031 * \c clang_Cursor_getOffsetOf.
3032 *
3033 * A value of this enumeration type can be returned if the target type is not
3034 * a valid argument to sizeof, alignof or offsetof.
3035 */
3036enum CXTypeLayoutError {
3037 /**
3038 * \brief Type is of kind CXType_Invalid.
3039 */
3040 CXTypeLayoutError_Invalid = -1,
3041 /**
3042 * \brief The type is an incomplete Type.
3043 */
3044 CXTypeLayoutError_Incomplete = -2,
3045 /**
3046 * \brief The type is a dependent Type.
3047 */
3048 CXTypeLayoutError_Dependent = -3,
3049 /**
3050 * \brief The type is not a constant size type.
3051 */
3052 CXTypeLayoutError_NotConstantSize = -4,
3053 /**
3054 * \brief The Field name is not valid for this record.
3055 */
3056 CXTypeLayoutError_InvalidFieldName = -5
3057};
3058
3059/**
3060 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
3061 * standard.
3062 *
3063 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3064 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3065 * is returned.
3066 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3067 * returned.
3068 * If the type declaration is not a constant size type,
3069 * CXTypeLayoutError_NotConstantSize is returned.
3070 */
3071CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
3072
3073/**
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00003074 * \brief Return the class type of an member pointer type.
3075 *
3076 * If a non-member-pointer type is passed in, an invalid type is returned.
3077 */
3078CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T);
3079
3080/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003081 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
3082 *
3083 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3084 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3085 * is returned.
3086 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3087 * returned.
3088 */
3089CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
3090
3091/**
3092 * \brief Return the offset of a field named S in a record of type T in bits
3093 * as it would be returned by __offsetof__ as per C++11[18.2p4]
3094 *
3095 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
3096 * is returned.
3097 * If the field's type declaration is an incomplete type,
3098 * CXTypeLayoutError_Incomplete is returned.
3099 * If the field's type declaration is a dependent type,
3100 * CXTypeLayoutError_Dependent is returned.
3101 * If the field's name S is not found,
3102 * CXTypeLayoutError_InvalidFieldName is returned.
3103 */
3104CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
3105
Argyrios Kyrtzidisadff3ae2013-10-11 19:58:38 +00003106enum CXRefQualifierKind {
3107 /** \brief No ref-qualifier was provided. */
3108 CXRefQualifier_None = 0,
3109 /** \brief An lvalue ref-qualifier was provided (\c &). */
3110 CXRefQualifier_LValue,
3111 /** \brief An rvalue ref-qualifier was provided (\c &&). */
3112 CXRefQualifier_RValue
3113};
3114
3115/**
3116 * \brief Retrieve the ref-qualifier kind of a function or method.
3117 *
3118 * The ref-qualifier is returned for C++ functions or methods. For other types
3119 * or non-C++ declarations, CXRefQualifier_None is returned.
3120 */
3121CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
3122
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003123/**
3124 * \brief Returns non-zero if the cursor specifies a Record member that is a
3125 * bitfield.
3126 */
3127CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
3128
3129/**
Ted Kremenekae9e2212010-08-27 21:34:58 +00003130 * \brief Returns 1 if the base class specified by the cursor with kind
3131 * CX_CXXBaseSpecifier is virtual.
3132 */
3133CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3134
3135/**
3136 * \brief Represents the C++ access control level to a base class for a
3137 * cursor with kind CX_CXXBaseSpecifier.
3138 */
3139enum CX_CXXAccessSpecifier {
3140 CX_CXXInvalidAccessSpecifier,
3141 CX_CXXPublic,
3142 CX_CXXProtected,
3143 CX_CXXPrivate
3144};
3145
3146/**
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003147 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidisf6464082013-04-11 17:31:13 +00003148 *
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003149 * If the cursor refers to a C++ declaration, its access control level within its
3150 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3151 * access specifier, the specifier itself is returned.
Ted Kremenekae9e2212010-08-27 21:34:58 +00003152 */
3153CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3154
3155/**
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00003156 * \brief Determine the number of overloaded declarations referenced by a
3157 * \c CXCursor_OverloadedDeclRef cursor.
3158 *
3159 * \param cursor The cursor whose overloaded declarations are being queried.
3160 *
3161 * \returns The number of overloaded declarations referenced by \c cursor. If it
3162 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3163 */
3164CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3165
3166/**
3167 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3168 * by a \c CXCursor_OverloadedDeclRef cursor.
3169 *
3170 * \param cursor The cursor whose overloaded declarations are being queried.
3171 *
3172 * \param index The zero-based index into the set of overloaded declarations in
3173 * the cursor.
3174 *
3175 * \returns A cursor representing the declaration referenced by the given
3176 * \c cursor at the specified \c index. If the cursor does not have an
3177 * associated set of overloaded declarations, or if the index is out of bounds,
3178 * returns \c clang_getNullCursor();
3179 */
3180CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3181 unsigned index);
3182
3183/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00003184 * @}
3185 */
Ted Kremeneka5940822010-08-26 01:42:22 +00003186
3187/**
Ted Kremenek2c2c5f32010-08-27 21:34:51 +00003188 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremeneka5940822010-08-26 01:42:22 +00003189 *
3190 * @{
3191 */
3192
3193
3194/**
3195 * \brief For cursors representing an iboutletcollection attribute,
3196 * this function returns the collection element type.
3197 *
3198 */
3199CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3200
3201/**
3202 * @}
3203 */
Ted Kremenek6bca9842010-05-14 21:29:26 +00003204
3205/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003206 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3207 *
3208 * These routines provide the ability to traverse the abstract syntax tree
3209 * using cursors.
3210 *
3211 * @{
3212 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003213
Douglas Gregor6007cf22010-01-22 22:29:16 +00003214/**
3215 * \brief Describes how the traversal of the children of a particular
3216 * cursor should proceed after visiting a particular child cursor.
3217 *
3218 * A value of this enumeration type should be returned by each
3219 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3220 */
3221enum CXChildVisitResult {
3222 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003223 * \brief Terminates the cursor traversal.
Douglas Gregor6007cf22010-01-22 22:29:16 +00003224 */
3225 CXChildVisit_Break,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003226 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003227 * \brief Continues the cursor traversal with the next sibling of
3228 * the cursor just visited, without visiting its children.
3229 */
3230 CXChildVisit_Continue,
3231 /**
3232 * \brief Recursively traverse the children of this cursor, using
3233 * the same visitor and client data.
3234 */
3235 CXChildVisit_Recurse
3236};
3237
3238/**
3239 * \brief Visitor invoked for each cursor found by a traversal.
3240 *
3241 * This visitor function will be invoked for each cursor found by
3242 * clang_visitCursorChildren(). Its first argument is the cursor being
3243 * visited, its second argument is the parent visitor for that cursor,
3244 * and its third argument is the client data provided to
3245 * clang_visitCursorChildren().
3246 *
3247 * The visitor should return one of the \c CXChildVisitResult values
3248 * to direct clang_visitCursorChildren().
3249 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003250typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3251 CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003252 CXClientData client_data);
3253
3254/**
3255 * \brief Visit the children of a particular cursor.
3256 *
3257 * This function visits all the direct children of the given cursor,
3258 * invoking the given \p visitor function with the cursors of each
3259 * visited child. The traversal may be recursive, if the visitor returns
3260 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3261 * the visitor returns \c CXChildVisit_Break.
3262 *
Douglas Gregor6007cf22010-01-22 22:29:16 +00003263 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbarb9999fd2010-01-24 04:10:31 +00003264 * cursors can be visited, including invalid cursors (which, by
Douglas Gregor6007cf22010-01-22 22:29:16 +00003265 * definition, have no children).
3266 *
3267 * \param visitor the visitor function that will be invoked for each
3268 * child of \p parent.
3269 *
3270 * \param client_data pointer data supplied by the client, which will
3271 * be passed to the visitor each time it is invoked.
3272 *
3273 * \returns a non-zero value if the traversal was terminated
3274 * prematurely by the visitor returning \c CXChildVisit_Break.
3275 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003276CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003277 CXCursorVisitor visitor,
3278 CXClientData client_data);
David Chisnallb2aa0ef2010-11-03 14:12:26 +00003279#ifdef __has_feature
3280# if __has_feature(blocks)
3281/**
3282 * \brief Visitor invoked for each cursor found by a traversal.
3283 *
3284 * This visitor block will be invoked for each cursor found by
3285 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3286 * visited, its second argument is the parent visitor for that cursor.
3287 *
3288 * The visitor should return one of the \c CXChildVisitResult values
3289 * to direct clang_visitChildrenWithBlock().
3290 */
3291typedef enum CXChildVisitResult
3292 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3293
3294/**
3295 * Visits the children of a cursor using the specified block. Behaves
3296 * identically to clang_visitChildren() in all other respects.
3297 */
3298unsigned clang_visitChildrenWithBlock(CXCursor parent,
3299 CXCursorVisitorBlock block);
3300# endif
3301#endif
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003302
Douglas Gregor6007cf22010-01-22 22:29:16 +00003303/**
3304 * @}
3305 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003306
Douglas Gregor6007cf22010-01-22 22:29:16 +00003307/**
3308 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3309 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003310 * These routines provide the ability to determine references within and
Douglas Gregor6007cf22010-01-22 22:29:16 +00003311 * across translation units, by providing the names of the entities referenced
3312 * by cursors, follow reference cursors to the declarations they reference,
3313 * and associate declarations with their definitions.
3314 *
3315 * @{
3316 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003317
Douglas Gregor6007cf22010-01-22 22:29:16 +00003318/**
3319 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3320 * by the given cursor.
3321 *
3322 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3323 * entity (function, class, variable, etc.) within a program. USRs can be
3324 * compared across translation units to determine, e.g., when references in
3325 * one translation refer to an entity defined in another translation unit.
3326 */
3327CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3328
3329/**
Ted Kremenekd071c602010-03-13 02:50:34 +00003330 * \brief Construct a USR for a specified Objective-C class.
3331 */
3332CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3333
3334/**
3335 * \brief Construct a USR for a specified Objective-C category.
3336 */
3337CINDEX_LINKAGE CXString
Ted Kremenekbc1a67b2010-03-15 17:38:58 +00003338 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenekd071c602010-03-13 02:50:34 +00003339 const char *category_name);
3340
3341/**
3342 * \brief Construct a USR for a specified Objective-C protocol.
3343 */
3344CINDEX_LINKAGE CXString
3345 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3346
3347
3348/**
3349 * \brief Construct a USR for a specified Objective-C instance variable and
3350 * the USR for its containing class.
3351 */
3352CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3353 CXString classUSR);
3354
3355/**
3356 * \brief Construct a USR for a specified Objective-C method and
3357 * the USR for its containing class.
3358 */
3359CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3360 unsigned isInstanceMethod,
3361 CXString classUSR);
3362
3363/**
3364 * \brief Construct a USR for a specified Objective-C property and the USR
3365 * for its containing class.
3366 */
3367CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3368 CXString classUSR);
3369
3370/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003371 * \brief Retrieve a name for the entity referenced by this cursor.
3372 */
3373CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3374
Douglas Gregor97c75712010-10-02 22:49:11 +00003375/**
Argyrios Kyrtzidis191a6a82012-03-30 20:58:35 +00003376 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3377 * Most of the times there is only one range for the complete spelling but for
3378 * objc methods and objc message expressions, there are multiple pieces for each
3379 * selector identifier.
3380 *
3381 * \param pieceIndex the index of the spelling name piece. If this is greater
3382 * than the actual number of pieces, it will return a NULL (invalid) range.
3383 *
3384 * \param options Reserved.
3385 */
3386CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3387 unsigned pieceIndex,
3388 unsigned options);
3389
3390/**
Douglas Gregor97c75712010-10-02 22:49:11 +00003391 * \brief Retrieve the display name for the entity referenced by this cursor.
3392 *
3393 * The display name contains extra information that helps identify the cursor,
3394 * such as the parameters of a function or template or the arguments of a
3395 * class template specialization.
3396 */
3397CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3398
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003399/** \brief For a cursor that is a reference, retrieve a cursor representing the
3400 * entity that it references.
3401 *
3402 * Reference cursors refer to other entities in the AST. For example, an
3403 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003404 * This function produces the cursor for the Objective-C class from the
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003405 * cursor for the superclass reference. If the input cursor is a declaration or
3406 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003407 * Otherwise, returns the NULL cursor.
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003408 */
3409CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003410
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003411/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003412 * \brief For a cursor that is either a reference to or a declaration
3413 * of some entity, retrieve a cursor that describes the definition of
3414 * that entity.
3415 *
3416 * Some entities can be declared multiple times within a translation
3417 * unit, but only one of those declarations can also be a
3418 * definition. For example, given:
3419 *
3420 * \code
3421 * int f(int, int);
3422 * int g(int x, int y) { return f(x, y); }
3423 * int f(int a, int b) { return a + b; }
3424 * int f(int, int);
3425 * \endcode
3426 *
3427 * there are three declarations of the function "f", but only the
3428 * second one is a definition. The clang_getCursorDefinition()
3429 * function will take any cursor pointing to a declaration of "f"
3430 * (the first or fourth lines of the example) or a cursor referenced
3431 * that uses "f" (the call to "f' inside "g") and will return a
3432 * declaration cursor pointing to the definition (the second "f"
3433 * declaration).
3434 *
3435 * If given a cursor for which there is no corresponding definition,
3436 * e.g., because there is no definition of that entity within this
3437 * translation unit, returns a NULL cursor.
3438 */
3439CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3440
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003441/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003442 * \brief Determine whether the declaration pointed to by this cursor
3443 * is also a definition of that entity.
3444 */
3445CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3446
Douglas Gregor6007cf22010-01-22 22:29:16 +00003447/**
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003448 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3449 *
3450 * In the C family of languages, many kinds of entities can be declared several
3451 * times within a single translation unit. For example, a structure type can
3452 * be forward-declared (possibly multiple times) and later defined:
3453 *
3454 * \code
3455 * struct X;
3456 * struct X;
3457 * struct X {
3458 * int member;
3459 * };
3460 * \endcode
3461 *
3462 * The declarations and the definition of \c X are represented by three
3463 * different cursors, all of which are declarations of the same underlying
3464 * entity. One of these cursor is considered the "canonical" cursor, which
3465 * is effectively the representative for the underlying entity. One can
3466 * determine if two cursors are declarations of the same underlying entity by
3467 * comparing their canonical cursors.
3468 *
3469 * \returns The canonical cursor for the entity referred to by the given cursor.
3470 */
3471CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3472
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003473
3474/**
3475 * \brief If the cursor points to a selector identifier in a objc method or
3476 * message expression, this returns the selector index.
3477 *
James Dennett574cb4c2012-06-15 05:41:51 +00003478 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003479 * determine if the location points to a selector identifier.
3480 *
3481 * \returns The selector index if the cursor is an objc method or message
3482 * expression and the cursor is pointing to a selector identifier, or -1
3483 * otherwise.
3484 */
3485CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3486
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003487/**
Argyrios Kyrtzidisb6df68212012-07-02 23:54:36 +00003488 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3489 * returns non-zero if the method/message is "dynamic", meaning:
3490 *
3491 * For a C++ method: the call is virtual.
3492 * For an ObjC message: the receiver is an object instance, not 'super' or a
3493 * specific class.
3494 *
3495 * If the method/message is "static" or the cursor does not point to a
3496 * method/message, it will return zero.
3497 */
3498CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3499
3500/**
Argyrios Kyrtzidisb26a24c2012-11-01 02:01:34 +00003501 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3502 * receiver.
3503 */
3504CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3505
3506/**
Argyrios Kyrtzidis9adfd8a2013-04-18 22:15:49 +00003507 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3508 */
3509typedef enum {
3510 CXObjCPropertyAttr_noattr = 0x00,
3511 CXObjCPropertyAttr_readonly = 0x01,
3512 CXObjCPropertyAttr_getter = 0x02,
3513 CXObjCPropertyAttr_assign = 0x04,
3514 CXObjCPropertyAttr_readwrite = 0x08,
3515 CXObjCPropertyAttr_retain = 0x10,
3516 CXObjCPropertyAttr_copy = 0x20,
3517 CXObjCPropertyAttr_nonatomic = 0x40,
3518 CXObjCPropertyAttr_setter = 0x80,
3519 CXObjCPropertyAttr_atomic = 0x100,
3520 CXObjCPropertyAttr_weak = 0x200,
3521 CXObjCPropertyAttr_strong = 0x400,
3522 CXObjCPropertyAttr_unsafe_unretained = 0x800
3523} CXObjCPropertyAttrKind;
3524
3525/**
3526 * \brief Given a cursor that represents a property declaration, return the
3527 * associated property attributes. The bits are formed from
3528 * \c CXObjCPropertyAttrKind.
3529 *
3530 * \param reserved Reserved for future use, pass 0.
3531 */
3532CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3533 unsigned reserved);
3534
3535/**
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003536 * \brief 'Qualifiers' written next to the return and parameter types in
3537 * ObjC method declarations.
3538 */
3539typedef enum {
3540 CXObjCDeclQualifier_None = 0x0,
3541 CXObjCDeclQualifier_In = 0x1,
3542 CXObjCDeclQualifier_Inout = 0x2,
3543 CXObjCDeclQualifier_Out = 0x4,
3544 CXObjCDeclQualifier_Bycopy = 0x8,
3545 CXObjCDeclQualifier_Byref = 0x10,
3546 CXObjCDeclQualifier_Oneway = 0x20
3547} CXObjCDeclQualifierKind;
3548
3549/**
3550 * \brief Given a cursor that represents an ObjC method or parameter
3551 * declaration, return the associated ObjC qualifiers for the return type or the
Argyrios Kyrtzidis982934e2013-04-19 00:51:52 +00003552 * parameter respectively. The bits are formed from CXObjCDeclQualifierKind.
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003553 */
3554CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3555
3556/**
Argyrios Kyrtzidis7b50fc52013-07-05 20:44:37 +00003557 * \brief Given a cursor that represents an ObjC method or property declaration,
3558 * return non-zero if the declaration was affected by "@optional".
3559 * Returns zero if the cursor is not such a declaration or it is "@required".
3560 */
3561CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
3562
3563/**
Argyrios Kyrtzidis23814e42013-04-18 23:53:05 +00003564 * \brief Returns non-zero if the given cursor is a variadic function or method.
3565 */
3566CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3567
3568/**
Dmitri Gribenkoaab83832012-06-20 00:34:58 +00003569 * \brief Given a cursor that represents a declaration, return the associated
3570 * comment's source range. The range may include multiple consecutive comments
3571 * with whitespace in between.
3572 */
3573CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3574
3575/**
3576 * \brief Given a cursor that represents a declaration, return the associated
3577 * comment text, including comment markers.
3578 */
3579CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3580
3581/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003582 * \brief Given a cursor that represents a documentable entity (e.g.,
3583 * declaration), return the associated \\brief paragraph; otherwise return the
3584 * first paragraph.
Dmitri Gribenko5188c4b2012-06-26 20:39:18 +00003585 */
3586CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3587
3588/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003589 * \brief Given a cursor that represents a documentable entity (e.g.,
3590 * declaration), return the associated parsed comment as a
3591 * \c CXComment_FullComment AST node.
3592 */
3593CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3594
3595/**
3596 * @}
3597 */
3598
3599/**
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003600 * \defgroup CINDEX_MODULE Module introspection
3601 *
3602 * The functions in this group provide access to information about modules.
3603 *
3604 * @{
3605 */
3606
3607typedef void *CXModule;
3608
3609/**
3610 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3611 */
3612CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3613
3614/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003615 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003616 *
Argyrios Kyrtzidis12fdb9e2013-04-26 22:47:49 +00003617 * \returns the module file where the provided module object came from.
3618 */
3619CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3620
3621/**
3622 * \param Module a module object.
3623 *
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003624 * \returns the parent of a sub-module or NULL if the given module is top-level,
3625 * e.g. for 'std.vector' it will return the 'std' module.
3626 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003627CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003628
3629/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003630 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003631 *
3632 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3633 * will return "vector".
3634 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003635CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003636
3637/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003638 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003639 *
3640 * \returns the full name of the module, e.g. "std.vector".
3641 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003642CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003643
3644/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003645 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003646 *
3647 * \returns the number of top level headers associated with this module.
3648 */
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003649CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3650 CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003651
3652/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003653 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003654 *
3655 * \param Index top level header index (zero-based).
3656 *
3657 * \returns the specified top level header associated with the module.
3658 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003659CINDEX_LINKAGE
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003660CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3661 CXModule Module, unsigned Index);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003662
3663/**
3664 * @}
3665 */
3666
3667/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003668 * \defgroup CINDEX_COMMENT Comment AST introspection
3669 *
3670 * The routines in this group provide access to information in the
3671 * documentation comment ASTs.
3672 *
3673 * @{
3674 */
3675
3676/**
3677 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3678 * node can be considered block content (e. g., paragraph), inline content
3679 * (plain text) or neither (the root AST node).
3680 */
3681enum CXCommentKind {
3682 /**
3683 * \brief Null comment. No AST node is constructed at the requested location
3684 * because there is no text or a syntax error.
3685 */
3686 CXComment_Null = 0,
3687
3688 /**
3689 * \brief Plain text. Inline content.
3690 */
3691 CXComment_Text = 1,
3692
3693 /**
3694 * \brief A command with word-like arguments that is considered inline content.
3695 *
3696 * For example: \\c command.
3697 */
3698 CXComment_InlineCommand = 2,
3699
3700 /**
3701 * \brief HTML start tag with attributes (name-value pairs). Considered
3702 * inline content.
3703 *
3704 * For example:
3705 * \verbatim
3706 * <br> <br /> <a href="http://example.org/">
3707 * \endverbatim
3708 */
3709 CXComment_HTMLStartTag = 3,
3710
3711 /**
3712 * \brief HTML end tag. Considered inline content.
3713 *
3714 * For example:
3715 * \verbatim
3716 * </a>
3717 * \endverbatim
3718 */
3719 CXComment_HTMLEndTag = 4,
3720
3721 /**
3722 * \brief A paragraph, contains inline comment. The paragraph itself is
3723 * block content.
3724 */
3725 CXComment_Paragraph = 5,
3726
3727 /**
3728 * \brief A command that has zero or more word-like arguments (number of
3729 * word-like arguments depends on command name) and a paragraph as an
3730 * argument. Block command is block content.
3731 *
3732 * Paragraph argument is also a child of the block command.
3733 *
3734 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3735 *
3736 * AST nodes of special kinds that parser knows about (e. g., \\param
3737 * command) have their own node kinds.
3738 */
3739 CXComment_BlockCommand = 6,
3740
3741 /**
3742 * \brief A \\param or \\arg command that describes the function parameter
3743 * (name, passing direction, description).
3744 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003745 * For example: \\param [in] ParamName description.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003746 */
3747 CXComment_ParamCommand = 7,
3748
3749 /**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003750 * \brief A \\tparam command that describes a template parameter (name and
3751 * description).
3752 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003753 * For example: \\tparam T description.
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003754 */
3755 CXComment_TParamCommand = 8,
3756
3757 /**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003758 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3759 * block has an opening and a closing command and contains multiple lines of
3760 * text (\c CXComment_VerbatimBlockLine child nodes).
3761 *
3762 * For example:
3763 * \\verbatim
3764 * aaa
3765 * \\endverbatim
3766 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003767 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003768
3769 /**
3770 * \brief A line of text that is contained within a
3771 * CXComment_VerbatimBlockCommand node.
3772 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003773 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003774
3775 /**
3776 * \brief A verbatim line command. Verbatim line has an opening command,
3777 * a single line of text (up to the newline after the opening command) and
3778 * has no closing command.
3779 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003780 CXComment_VerbatimLine = 11,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003781
3782 /**
3783 * \brief A full comment attached to a declaration, contains block content.
3784 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003785 CXComment_FullComment = 12
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003786};
3787
3788/**
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003789 * \brief The most appropriate rendering mode for an inline command, chosen on
3790 * command semantics in Doxygen.
3791 */
3792enum CXCommentInlineCommandRenderKind {
3793 /**
3794 * \brief Command argument should be rendered in a normal font.
3795 */
3796 CXCommentInlineCommandRenderKind_Normal,
3797
3798 /**
3799 * \brief Command argument should be rendered in a bold font.
3800 */
3801 CXCommentInlineCommandRenderKind_Bold,
3802
3803 /**
3804 * \brief Command argument should be rendered in a monospaced font.
3805 */
3806 CXCommentInlineCommandRenderKind_Monospaced,
3807
3808 /**
3809 * \brief Command argument should be rendered emphasized (typically italic
3810 * font).
3811 */
3812 CXCommentInlineCommandRenderKind_Emphasized
3813};
3814
3815/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003816 * \brief Describes parameter passing direction for \\param or \\arg command.
3817 */
3818enum CXCommentParamPassDirection {
3819 /**
3820 * \brief The parameter is an input parameter.
3821 */
3822 CXCommentParamPassDirection_In,
3823
3824 /**
3825 * \brief The parameter is an output parameter.
3826 */
3827 CXCommentParamPassDirection_Out,
3828
3829 /**
3830 * \brief The parameter is an input and output parameter.
3831 */
3832 CXCommentParamPassDirection_InOut
3833};
3834
3835/**
3836 * \param Comment AST node of any kind.
3837 *
3838 * \returns the type of the AST node.
3839 */
3840CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3841
3842/**
3843 * \param Comment AST node of any kind.
3844 *
3845 * \returns number of children of the AST node.
3846 */
3847CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3848
3849/**
3850 * \param Comment AST node of any kind.
3851 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003852 * \param ChildIdx child index (zero-based).
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003853 *
3854 * \returns the specified child of the AST node.
3855 */
3856CINDEX_LINKAGE
3857CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3858
3859/**
3860 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3861 * only \c CXComment_Text nodes that are empty or whitespace.
3862 *
3863 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3864 * never considered whitespace.
3865 *
3866 * \returns non-zero if \c Comment is whitespace.
3867 */
3868CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3869
3870/**
3871 * \returns non-zero if \c Comment is inline content and has a newline
3872 * immediately following it in the comment text. Newlines between paragraphs
3873 * do not count.
3874 */
3875CINDEX_LINKAGE
3876unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3877
3878/**
3879 * \param Comment a \c CXComment_Text AST node.
3880 *
3881 * \returns text contained in the AST node.
3882 */
3883CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3884
3885/**
3886 * \param Comment a \c CXComment_InlineCommand AST node.
3887 *
3888 * \returns name of the inline command.
3889 */
3890CINDEX_LINKAGE
3891CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3892
3893/**
3894 * \param Comment a \c CXComment_InlineCommand AST node.
3895 *
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003896 * \returns the most appropriate rendering mode, chosen on command
3897 * semantics in Doxygen.
3898 */
3899CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3900clang_InlineCommandComment_getRenderKind(CXComment Comment);
3901
3902/**
3903 * \param Comment a \c CXComment_InlineCommand AST node.
3904 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003905 * \returns number of command arguments.
3906 */
3907CINDEX_LINKAGE
3908unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3909
3910/**
3911 * \param Comment a \c CXComment_InlineCommand AST node.
3912 *
3913 * \param ArgIdx argument index (zero-based).
3914 *
3915 * \returns text of the specified argument.
3916 */
3917CINDEX_LINKAGE
3918CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3919 unsigned ArgIdx);
3920
3921/**
3922 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3923 * node.
3924 *
3925 * \returns HTML tag name.
3926 */
3927CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3928
3929/**
3930 * \param Comment a \c CXComment_HTMLStartTag AST node.
3931 *
3932 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3933 */
3934CINDEX_LINKAGE
3935unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3936
3937/**
3938 * \param Comment a \c CXComment_HTMLStartTag AST node.
3939 *
3940 * \returns number of attributes (name-value pairs) attached to the start tag.
3941 */
3942CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3943
3944/**
3945 * \param Comment a \c CXComment_HTMLStartTag AST node.
3946 *
3947 * \param AttrIdx attribute index (zero-based).
3948 *
3949 * \returns name of the specified attribute.
3950 */
3951CINDEX_LINKAGE
3952CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3953
3954/**
3955 * \param Comment a \c CXComment_HTMLStartTag AST node.
3956 *
3957 * \param AttrIdx attribute index (zero-based).
3958 *
3959 * \returns value of the specified attribute.
3960 */
3961CINDEX_LINKAGE
3962CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3963
3964/**
3965 * \param Comment a \c CXComment_BlockCommand AST node.
3966 *
3967 * \returns name of the block command.
3968 */
3969CINDEX_LINKAGE
3970CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3971
3972/**
3973 * \param Comment a \c CXComment_BlockCommand AST node.
3974 *
3975 * \returns number of word-like arguments.
3976 */
3977CINDEX_LINKAGE
3978unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3979
3980/**
3981 * \param Comment a \c CXComment_BlockCommand AST node.
3982 *
3983 * \param ArgIdx argument index (zero-based).
3984 *
3985 * \returns text of the specified word-like argument.
3986 */
3987CINDEX_LINKAGE
3988CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3989 unsigned ArgIdx);
3990
3991/**
3992 * \param Comment a \c CXComment_BlockCommand or
3993 * \c CXComment_VerbatimBlockCommand AST node.
3994 *
3995 * \returns paragraph argument of the block command.
3996 */
3997CINDEX_LINKAGE
3998CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3999
4000/**
4001 * \param Comment a \c CXComment_ParamCommand AST node.
4002 *
4003 * \returns parameter name.
4004 */
4005CINDEX_LINKAGE
4006CXString clang_ParamCommandComment_getParamName(CXComment Comment);
4007
4008/**
4009 * \param Comment a \c CXComment_ParamCommand AST node.
4010 *
4011 * \returns non-zero if the parameter that this AST node represents was found
4012 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
4013 * function will return a meaningful value.
4014 */
4015CINDEX_LINKAGE
4016unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
4017
4018/**
4019 * \param Comment a \c CXComment_ParamCommand AST node.
4020 *
4021 * \returns zero-based parameter index in function prototype.
4022 */
4023CINDEX_LINKAGE
4024unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
4025
4026/**
4027 * \param Comment a \c CXComment_ParamCommand AST node.
4028 *
4029 * \returns non-zero if parameter passing direction was specified explicitly in
4030 * the comment.
4031 */
4032CINDEX_LINKAGE
4033unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
4034
4035/**
4036 * \param Comment a \c CXComment_ParamCommand AST node.
4037 *
4038 * \returns parameter passing direction.
4039 */
4040CINDEX_LINKAGE
4041enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
4042 CXComment Comment);
4043
4044/**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004045 * \param Comment a \c CXComment_TParamCommand AST node.
4046 *
4047 * \returns template parameter name.
4048 */
4049CINDEX_LINKAGE
4050CXString clang_TParamCommandComment_getParamName(CXComment Comment);
4051
4052/**
4053 * \param Comment a \c CXComment_TParamCommand AST node.
4054 *
4055 * \returns non-zero if the parameter that this AST node represents was found
4056 * in the template parameter list and
4057 * \c clang_TParamCommandComment_getDepth and
4058 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
4059 * value.
4060 */
4061CINDEX_LINKAGE
4062unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
4063
4064/**
4065 * \param Comment a \c CXComment_TParamCommand AST node.
4066 *
4067 * \returns zero-based nesting depth of this parameter in the template parameter list.
4068 *
4069 * For example,
4070 * \verbatim
4071 * template<typename C, template<typename T> class TT>
4072 * void test(TT<int> aaa);
4073 * \endverbatim
4074 * for C and TT nesting depth is 0,
4075 * for T nesting depth is 1.
4076 */
4077CINDEX_LINKAGE
4078unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
4079
4080/**
4081 * \param Comment a \c CXComment_TParamCommand AST node.
4082 *
4083 * \returns zero-based parameter index in the template parameter list at a
4084 * given nesting depth.
4085 *
4086 * For example,
4087 * \verbatim
4088 * template<typename C, template<typename T> class TT>
4089 * void test(TT<int> aaa);
4090 * \endverbatim
4091 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
4092 * at depth 0 C's index is 0, TT's index is 1.
4093 *
4094 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
4095 * at depth 0 T's index is 1 (same as TT's),
4096 * at depth 1 T's index is 0.
4097 */
4098CINDEX_LINKAGE
4099unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
4100
4101/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004102 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
4103 *
4104 * \returns text contained in the AST node.
4105 */
4106CINDEX_LINKAGE
4107CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
4108
4109/**
4110 * \param Comment a \c CXComment_VerbatimLine AST node.
4111 *
4112 * \returns text contained in the AST node.
4113 */
4114CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
4115
4116/**
4117 * \brief Convert an HTML tag AST node to string.
4118 *
4119 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
4120 * node.
4121 *
4122 * \returns string containing an HTML tag.
4123 */
4124CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
4125
4126/**
4127 * \brief Convert a given full parsed comment to an HTML fragment.
4128 *
4129 * Specific details of HTML layout are subject to change. Don't try to parse
4130 * this HTML back into an AST, use other APIs instead.
4131 *
4132 * Currently the following CSS classes are used:
4133 * \li "para-brief" for \\brief paragraph and equivalent commands;
4134 * \li "para-returns" for \\returns paragraph and equivalent commands;
4135 * \li "word-returns" for the "Returns" word in \\returns paragraph.
4136 *
Dmitri Gribenko4c6d7a22012-07-21 01:47:43 +00004137 * Function argument documentation is rendered as a \<dl\> list with arguments
4138 * sorted in function prototype order. CSS classes used:
4139 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
4140 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
4141 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
4142 * parameter index is invalid.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004143 *
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004144 * Template parameter documentation is rendered as a \<dl\> list with
4145 * parameters sorted in template parameter list order. CSS classes used:
4146 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
4147 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko58e41312012-08-01 23:47:30 +00004148 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004149 * names inside template template parameters;
4150 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
4151 * parameter position is invalid.
4152 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004153 * \param Comment a \c CXComment_FullComment AST node.
4154 *
4155 * \returns string containing an HTML fragment.
4156 */
4157CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
4158
4159/**
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004160 * \brief Convert a given full parsed comment to an XML document.
4161 *
4162 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
4163 * inside clang source tree.
4164 *
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004165 * \param Comment a \c CXComment_FullComment AST node.
4166 *
4167 * \returns string containing an XML document.
4168 */
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00004169CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004170
4171/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004172 * @}
4173 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004174
Douglas Gregor6007cf22010-01-22 22:29:16 +00004175/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004176 * \defgroup CINDEX_CPP C++ AST introspection
4177 *
4178 * The routines in this group provide access information in the ASTs specific
4179 * to C++ language features.
4180 *
4181 * @{
4182 */
4183
4184/**
Dmitri Gribenko62770be2013-05-17 18:38:35 +00004185 * \brief Determine if a C++ member function or member function template is
4186 * pure virtual.
4187 */
4188CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4189
4190/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004191 * \brief Determine if a C++ member function or member function template is
4192 * declared 'static'.
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004193 */
4194CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4195
4196/**
Douglas Gregor9519d922011-05-12 15:17:24 +00004197 * \brief Determine if a C++ member function or member function template is
4198 * explicitly declared 'virtual' or if it overrides a virtual method from
4199 * one of the base classes.
4200 */
4201CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4202
4203/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004204 * \brief Given a cursor that represents a template, determine
4205 * the cursor kind of the specializations would be generated by instantiating
4206 * the template.
4207 *
4208 * This routine can be used to determine what flavor of function template,
4209 * class template, or class template partial specialization is stored in the
4210 * cursor. For example, it can describe whether a class template cursor is
4211 * declared with "struct", "class" or "union".
4212 *
4213 * \param C The cursor to query. This cursor should represent a template
4214 * declaration.
4215 *
4216 * \returns The cursor kind of the specializations that would be generated
4217 * by instantiating the template \p C. If \p C is not a template, returns
4218 * \c CXCursor_NoDeclFound.
4219 */
4220CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4221
4222/**
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004223 * \brief Given a cursor that may represent a specialization or instantiation
4224 * of a template, retrieve the cursor that represents the template that it
4225 * specializes or from which it was instantiated.
4226 *
4227 * This routine determines the template involved both for explicit
4228 * specializations of templates and for implicit instantiations of the template,
4229 * both of which are referred to as "specializations". For a class template
4230 * specialization (e.g., \c std::vector<bool>), this routine will return
4231 * either the primary template (\c std::vector) or, if the specialization was
4232 * instantiated from a class template partial specialization, the class template
4233 * partial specialization. For a class template partial specialization and a
4234 * function template specialization (including instantiations), this
4235 * this routine will return the specialized template.
4236 *
4237 * For members of a class template (e.g., member functions, member classes, or
4238 * static data members), returns the specialized or instantiated member.
4239 * Although not strictly "templates" in the C++ language, members of class
4240 * templates have the same notions of specializations and instantiations that
4241 * templates do, so this routine treats them similarly.
4242 *
4243 * \param C A cursor that may be a specialization of a template or a member
4244 * of a template.
4245 *
4246 * \returns If the given cursor is a specialization or instantiation of a
4247 * template or a member thereof, the template or member that it specializes or
4248 * from which it was instantiated. Otherwise, returns a NULL cursor.
4249 */
4250CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004251
4252/**
4253 * \brief Given a cursor that references something else, return the source range
4254 * covering that reference.
4255 *
4256 * \param C A cursor pointing to a member reference, a declaration reference, or
4257 * an operator call.
4258 * \param NameFlags A bitset with three independent flags:
4259 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4260 * CXNameRange_WantSinglePiece.
4261 * \param PieceIndex For contiguous names or when passing the flag
4262 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4263 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer474261a2012-06-02 10:20:41 +00004264 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004265 * pieces of the name. See also CXNameRange_WantSinglePiece.
4266 *
4267 * \returns The piece of the name pointed to by the given cursor. If there is no
4268 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4269 */
Francois Pichetece689f2011-07-25 22:00:44 +00004270CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4271 unsigned NameFlags,
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004272 unsigned PieceIndex);
4273
4274enum CXNameRefFlags {
4275 /**
4276 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4277 * range.
4278 */
4279 CXNameRange_WantQualifier = 0x1,
4280
4281 /**
James Dennett574cb4c2012-06-15 05:41:51 +00004282 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4283 * in the range.
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004284 */
4285 CXNameRange_WantTemplateArgs = 0x2,
4286
4287 /**
4288 * \brief If the name is non-contiguous, return the full spanning range.
4289 *
4290 * Non-contiguous names occur in Objective-C when a selector with two or more
4291 * parameters is used, or in C++ when using an operator:
4292 * \code
4293 * [object doSomething:here withValue:there]; // ObjC
4294 * return some_vector[1]; // C++
4295 * \endcode
4296 */
4297 CXNameRange_WantSinglePiece = 0x4
4298};
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004299
4300/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004301 * @}
4302 */
4303
4304/**
Douglas Gregor61656112010-01-26 18:31:56 +00004305 * \defgroup CINDEX_LEX Token extraction and manipulation
4306 *
4307 * The routines in this group provide access to the tokens within a
4308 * translation unit, along with a semantic mapping of those tokens to
4309 * their corresponding cursors.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004310 *
4311 * @{
4312 */
4313
4314/**
4315 * \brief Describes a kind of token.
4316 */
4317typedef enum CXTokenKind {
4318 /**
4319 * \brief A token that contains some kind of punctuation.
4320 */
4321 CXToken_Punctuation,
Ted Kremenekd071c602010-03-13 02:50:34 +00004322
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004323 /**
Douglas Gregor61656112010-01-26 18:31:56 +00004324 * \brief A language keyword.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004325 */
4326 CXToken_Keyword,
Ted Kremenekd071c602010-03-13 02:50:34 +00004327
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004328 /**
4329 * \brief An identifier (that is not a keyword).
4330 */
4331 CXToken_Identifier,
Ted Kremenekd071c602010-03-13 02:50:34 +00004332
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004333 /**
4334 * \brief A numeric, string, or character literal.
4335 */
4336 CXToken_Literal,
Ted Kremenekd071c602010-03-13 02:50:34 +00004337
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004338 /**
4339 * \brief A comment.
4340 */
4341 CXToken_Comment
4342} CXTokenKind;
4343
4344/**
4345 * \brief Describes a single preprocessing token.
4346 */
4347typedef struct {
4348 unsigned int_data[4];
4349 void *ptr_data;
4350} CXToken;
4351
4352/**
4353 * \brief Determine the kind of the given token.
4354 */
4355CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004356
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004357/**
4358 * \brief Determine the spelling of the given token.
4359 *
4360 * The spelling of a token is the textual representation of that token, e.g.,
4361 * the text of an identifier or keyword.
4362 */
4363CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004364
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004365/**
4366 * \brief Retrieve the source location of the given token.
4367 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004368CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004369 CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004370
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004371/**
4372 * \brief Retrieve a source range that covers the given token.
4373 */
4374CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4375
4376/**
4377 * \brief Tokenize the source code described by the given range into raw
4378 * lexical tokens.
4379 *
4380 * \param TU the translation unit whose text is being tokenized.
4381 *
4382 * \param Range the source range in which text should be tokenized. All of the
4383 * tokens produced by tokenization will fall within this source range,
4384 *
4385 * \param Tokens this pointer will be set to point to the array of tokens
4386 * that occur within the given source range. The returned pointer must be
4387 * freed with clang_disposeTokens() before the translation unit is destroyed.
4388 *
4389 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4390 * array.
4391 *
4392 */
4393CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4394 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004395
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004396/**
4397 * \brief Annotate the given set of tokens by providing cursors for each token
4398 * that can be mapped to a specific entity within the abstract syntax tree.
4399 *
Douglas Gregor61656112010-01-26 18:31:56 +00004400 * This token-annotation routine is equivalent to invoking
4401 * clang_getCursor() for the source locations of each of the
4402 * tokens. The cursors provided are filtered, so that only those
4403 * cursors that have a direct correspondence to the token are
4404 * accepted. For example, given a function call \c f(x),
4405 * clang_getCursor() would provide the following cursors:
4406 *
4407 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4408 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4409 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4410 *
4411 * Only the first and last of these cursors will occur within the
4412 * annotate, since the tokens "f" and "x' directly refer to a function
4413 * and a variable, respectively, but the parentheses are just a small
4414 * part of the full syntax of the function call expression, which is
4415 * not provided as an annotation.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004416 *
4417 * \param TU the translation unit that owns the given tokens.
4418 *
4419 * \param Tokens the set of tokens to annotate.
4420 *
4421 * \param NumTokens the number of tokens in \p Tokens.
4422 *
4423 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4424 * replaced with the cursors corresponding to each token.
4425 */
4426CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4427 CXToken *Tokens, unsigned NumTokens,
4428 CXCursor *Cursors);
Ted Kremenekd071c602010-03-13 02:50:34 +00004429
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004430/**
4431 * \brief Free the given set of tokens.
4432 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004433CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004434 CXToken *Tokens, unsigned NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004435
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004436/**
4437 * @}
4438 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004439
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004440/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004441 * \defgroup CINDEX_DEBUG Debugging facilities
4442 *
4443 * These routines are used for testing and debugging, only, and should not
4444 * be relied upon.
4445 *
4446 * @{
4447 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004448
Steve Naroff76b8f132009-09-23 17:52:52 +00004449/* for debug/testing */
Ted Kremenek29004672010-02-17 00:41:32 +00004450CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004451CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4452 const char **startBuf,
Steve Naroff76b8f132009-09-23 17:52:52 +00004453 const char **endBuf,
4454 unsigned *startLine,
4455 unsigned *startColumn,
4456 unsigned *endLine,
4457 unsigned *endColumn);
Douglas Gregor1e21cc72010-02-18 23:07:20 +00004458CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar23420652010-11-04 01:26:29 +00004459CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4460 unsigned stack_size);
4461
Douglas Gregor9eb77012009-11-07 00:00:49 +00004462/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004463 * @}
4464 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004465
Douglas Gregor6007cf22010-01-22 22:29:16 +00004466/**
4467 * \defgroup CINDEX_CODE_COMPLET Code completion
4468 *
4469 * Code completion involves taking an (incomplete) source file, along with
4470 * knowledge of where the user is actively editing that file, and suggesting
4471 * syntactically- and semantically-valid constructs that the user might want to
4472 * use at that particular point in the source code. These data structures and
4473 * routines provide support for code completion.
4474 *
4475 * @{
4476 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004477
Douglas Gregor6007cf22010-01-22 22:29:16 +00004478/**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004479 * \brief A semantic string that describes a code-completion result.
4480 *
4481 * A semantic string that describes the formatting of a code-completion
4482 * result as a single "template" of text that should be inserted into the
4483 * source buffer when a particular code-completion result is selected.
4484 * Each semantic string is made up of some number of "chunks", each of which
4485 * contains some text along with a description of what that text means, e.g.,
4486 * the name of the entity being referenced, whether the text chunk is part of
4487 * the template, or whether it is a "placeholder" that the user should replace
4488 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004489 * description of the different kinds of chunks.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004490 */
4491typedef void *CXCompletionString;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004492
Douglas Gregor9eb77012009-11-07 00:00:49 +00004493/**
4494 * \brief A single result of code completion.
4495 */
4496typedef struct {
4497 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004498 * \brief The kind of entity that this completion refers to.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004499 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004500 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor9eb77012009-11-07 00:00:49 +00004501 * *Decl cursor kinds), describing the entity that the completion is
4502 * referring to.
4503 *
4504 * \todo In the future, we would like to provide a full cursor, to allow
4505 * the client to extract additional information from declaration.
4506 */
4507 enum CXCursorKind CursorKind;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004508
4509 /**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004510 * \brief The code-completion string that describes how to insert this
4511 * code-completion result into the editing buffer.
4512 */
4513 CXCompletionString CompletionString;
4514} CXCompletionResult;
4515
4516/**
4517 * \brief Describes a single piece of text within a code-completion string.
4518 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004519 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4520 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor9eb77012009-11-07 00:00:49 +00004521 * should be interpreted by the client or is another completion string.
4522 */
4523enum CXCompletionChunkKind {
4524 /**
4525 * \brief A code-completion string that describes "optional" text that
4526 * could be a part of the template (but is not required).
4527 *
4528 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004529 * string for its representation, which is accessible via
Douglas Gregor9eb77012009-11-07 00:00:49 +00004530 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4531 * describes an additional part of the template that is completely optional.
4532 * For example, optional chunks can be used to describe the placeholders for
4533 * arguments that match up with defaulted function parameters, e.g. given:
4534 *
4535 * \code
4536 * void f(int x, float y = 3.14, double z = 2.71828);
4537 * \endcode
4538 *
4539 * The code-completion string for this function would contain:
4540 * - a TypedText chunk for "f".
4541 * - a LeftParen chunk for "(".
4542 * - a Placeholder chunk for "int x"
4543 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4544 * - a Comma chunk for ","
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004545 * - a Placeholder chunk for "float y"
Douglas Gregor9eb77012009-11-07 00:00:49 +00004546 * - an Optional chunk containing the last defaulted argument:
4547 * - a Comma chunk for ","
4548 * - a Placeholder chunk for "double z"
4549 * - a RightParen chunk for ")"
4550 *
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004551 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor9eb77012009-11-07 00:00:49 +00004552 * - Completely ignore optional chunks, in which case the template for the
4553 * function "f" would only include the first parameter ("int x").
4554 * - Fully expand all optional chunks, in which case the template for the
4555 * function "f" would have all of the parameters.
4556 */
4557 CXCompletionChunk_Optional,
4558 /**
4559 * \brief Text that a user would be expected to type to get this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004560 * code-completion result.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004561 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004562 * There will be exactly one "typed text" chunk in a semantic string, which
4563 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004564 * declaration that could be used at the current code point. Clients are
4565 * expected to filter the code-completion results based on the text in this
4566 * chunk.
4567 */
4568 CXCompletionChunk_TypedText,
4569 /**
4570 * \brief Text that should be inserted as part of a code-completion result.
4571 *
4572 * A "text" chunk represents text that is part of the template to be
4573 * inserted into user code should this particular code-completion result
4574 * be selected.
4575 */
4576 CXCompletionChunk_Text,
4577 /**
4578 * \brief Placeholder text that should be replaced by the user.
4579 *
4580 * A "placeholder" chunk marks a place where the user should insert text
4581 * into the code-completion template. For example, placeholders might mark
4582 * the function parameters for a function declaration, to indicate that the
4583 * user should provide arguments for each of those parameters. The actual
4584 * text in a placeholder is a suggestion for the text to display before
4585 * the user replaces the placeholder with real code.
4586 */
4587 CXCompletionChunk_Placeholder,
4588 /**
4589 * \brief Informative text that should be displayed but never inserted as
4590 * part of the template.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004591 *
Douglas Gregor9eb77012009-11-07 00:00:49 +00004592 * An "informative" chunk contains annotations that can be displayed to
4593 * help the user decide whether a particular code-completion result is the
4594 * right option, but which is not part of the actual template to be inserted
4595 * by code completion.
4596 */
4597 CXCompletionChunk_Informative,
4598 /**
4599 * \brief Text that describes the current parameter when code-completion is
4600 * referring to function call, message send, or template specialization.
4601 *
4602 * A "current parameter" chunk occurs when code-completion is providing
4603 * information about a parameter corresponding to the argument at the
4604 * code-completion point. For example, given a function
4605 *
4606 * \code
4607 * int add(int x, int y);
4608 * \endcode
4609 *
4610 * and the source code \c add(, where the code-completion point is after the
4611 * "(", the code-completion string will contain a "current parameter" chunk
4612 * for "int x", indicating that the current argument will initialize that
4613 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004614 * point is after the ","), the code-completion string will contain a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004615 * "current paremeter" chunk to "int y".
4616 */
4617 CXCompletionChunk_CurrentParameter,
4618 /**
4619 * \brief A left parenthesis ('('), used to initiate a function call or
4620 * signal the beginning of a function parameter list.
4621 */
4622 CXCompletionChunk_LeftParen,
4623 /**
4624 * \brief A right parenthesis (')'), used to finish a function call or
4625 * signal the end of a function parameter list.
4626 */
4627 CXCompletionChunk_RightParen,
4628 /**
4629 * \brief A left bracket ('[').
4630 */
4631 CXCompletionChunk_LeftBracket,
4632 /**
4633 * \brief A right bracket (']').
4634 */
4635 CXCompletionChunk_RightBracket,
4636 /**
4637 * \brief A left brace ('{').
4638 */
4639 CXCompletionChunk_LeftBrace,
4640 /**
4641 * \brief A right brace ('}').
4642 */
4643 CXCompletionChunk_RightBrace,
4644 /**
4645 * \brief A left angle bracket ('<').
4646 */
4647 CXCompletionChunk_LeftAngle,
4648 /**
4649 * \brief A right angle bracket ('>').
4650 */
4651 CXCompletionChunk_RightAngle,
4652 /**
4653 * \brief A comma separator (',').
4654 */
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004655 CXCompletionChunk_Comma,
4656 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004657 * \brief Text that specifies the result type of a given result.
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004658 *
4659 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004660 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004661 * expression using the given completion string would have.
4662 */
Douglas Gregor504a6ae2010-01-10 23:08:15 +00004663 CXCompletionChunk_ResultType,
4664 /**
4665 * \brief A colon (':').
4666 */
4667 CXCompletionChunk_Colon,
4668 /**
4669 * \brief A semicolon (';').
4670 */
4671 CXCompletionChunk_SemiColon,
4672 /**
4673 * \brief An '=' sign.
4674 */
4675 CXCompletionChunk_Equal,
4676 /**
4677 * Horizontal space (' ').
4678 */
4679 CXCompletionChunk_HorizontalSpace,
4680 /**
4681 * Vertical space ('\n'), after which it is generally a good idea to
4682 * perform indentation.
4683 */
4684 CXCompletionChunk_VerticalSpace
Douglas Gregor9eb77012009-11-07 00:00:49 +00004685};
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004686
Douglas Gregor9eb77012009-11-07 00:00:49 +00004687/**
4688 * \brief Determine the kind of a particular chunk within a completion string.
4689 *
4690 * \param completion_string the completion string to query.
4691 *
4692 * \param chunk_number the 0-based index of the chunk in the completion string.
4693 *
4694 * \returns the kind of the chunk at the index \c chunk_number.
4695 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004696CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor9eb77012009-11-07 00:00:49 +00004697clang_getCompletionChunkKind(CXCompletionString completion_string,
4698 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004699
Douglas Gregor9eb77012009-11-07 00:00:49 +00004700/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004701 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004702 * completion string.
4703 *
4704 * \param completion_string the completion string to query.
4705 *
4706 * \param chunk_number the 0-based index of the chunk in the completion string.
4707 *
4708 * \returns the text associated with the chunk at index \c chunk_number.
4709 */
Ted Kremenekf602f962010-02-17 01:42:24 +00004710CINDEX_LINKAGE CXString
Douglas Gregor9eb77012009-11-07 00:00:49 +00004711clang_getCompletionChunkText(CXCompletionString completion_string,
4712 unsigned chunk_number);
4713
4714/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004715 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor9eb77012009-11-07 00:00:49 +00004716 * within a completion string.
4717 *
4718 * \param completion_string the completion string to query.
4719 *
4720 * \param chunk_number the 0-based index of the chunk in the completion string.
4721 *
4722 * \returns the completion string associated with the chunk at index
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004723 * \c chunk_number.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004724 */
4725CINDEX_LINKAGE CXCompletionString
4726clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4727 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004728
Douglas Gregor9eb77012009-11-07 00:00:49 +00004729/**
4730 * \brief Retrieve the number of chunks in the given code-completion string.
4731 */
4732CINDEX_LINKAGE unsigned
4733clang_getNumCompletionChunks(CXCompletionString completion_string);
4734
4735/**
Douglas Gregora2db7932010-05-26 22:00:08 +00004736 * \brief Determine the priority of this code completion.
4737 *
4738 * The priority of a code completion indicates how likely it is that this
4739 * particular completion is the completion that the user will select. The
4740 * priority is selected by various internal heuristics.
4741 *
4742 * \param completion_string The completion string to query.
4743 *
4744 * \returns The priority of this completion string. Smaller values indicate
4745 * higher-priority (more likely) completions.
4746 */
4747CINDEX_LINKAGE unsigned
4748clang_getCompletionPriority(CXCompletionString completion_string);
4749
4750/**
Douglas Gregorf757a122010-08-23 23:00:57 +00004751 * \brief Determine the availability of the entity that this code-completion
4752 * string refers to.
4753 *
4754 * \param completion_string The completion string to query.
4755 *
4756 * \returns The availability of the completion string.
4757 */
4758CINDEX_LINKAGE enum CXAvailabilityKind
4759clang_getCompletionAvailability(CXCompletionString completion_string);
4760
4761/**
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004762 * \brief Retrieve the number of annotations associated with the given
4763 * completion string.
4764 *
4765 * \param completion_string the completion string to query.
4766 *
4767 * \returns the number of annotations associated with the given completion
4768 * string.
4769 */
4770CINDEX_LINKAGE unsigned
4771clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4772
4773/**
4774 * \brief Retrieve the annotation associated with the given completion string.
4775 *
4776 * \param completion_string the completion string to query.
4777 *
4778 * \param annotation_number the 0-based index of the annotation of the
4779 * completion string.
4780 *
4781 * \returns annotation string associated with the completion at index
4782 * \c annotation_number, or a NULL string if that annotation is not available.
4783 */
4784CINDEX_LINKAGE CXString
4785clang_getCompletionAnnotation(CXCompletionString completion_string,
4786 unsigned annotation_number);
4787
4788/**
Douglas Gregor78254c82012-03-27 23:34:16 +00004789 * \brief Retrieve the parent context of the given completion string.
4790 *
4791 * The parent context of a completion string is the semantic parent of
4792 * the declaration (if any) that the code completion represents. For example,
4793 * a code completion for an Objective-C method would have the method's class
4794 * or protocol as its context.
4795 *
4796 * \param completion_string The code completion string whose parent is
4797 * being queried.
4798 *
Argyrios Kyrtzidis9ae39562012-09-26 16:39:56 +00004799 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregor78254c82012-03-27 23:34:16 +00004800 *
James Dennett574cb4c2012-06-15 05:41:51 +00004801 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregor78254c82012-03-27 23:34:16 +00004802 * the completion string represents a method in the NSObject class.
4803 */
4804CINDEX_LINKAGE CXString
4805clang_getCompletionParent(CXCompletionString completion_string,
4806 enum CXCursorKind *kind);
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004807
4808/**
4809 * \brief Retrieve the brief documentation comment attached to the declaration
4810 * that corresponds to the given completion string.
4811 */
4812CINDEX_LINKAGE CXString
4813clang_getCompletionBriefComment(CXCompletionString completion_string);
4814
Douglas Gregor78254c82012-03-27 23:34:16 +00004815/**
Douglas Gregor3f35bb22011-08-04 20:04:59 +00004816 * \brief Retrieve a completion string for an arbitrary declaration or macro
4817 * definition cursor.
4818 *
4819 * \param cursor The cursor to query.
4820 *
4821 * \returns A non-context-sensitive completion string for declaration and macro
4822 * definition cursors, or NULL for other kinds of cursors.
4823 */
4824CINDEX_LINKAGE CXCompletionString
4825clang_getCursorCompletionString(CXCursor cursor);
4826
4827/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004828 * \brief Contains the results of code-completion.
4829 *
4830 * This data structure contains the results of code completion, as
Douglas Gregor6a9580282010-10-11 21:51:20 +00004831 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004832 * \c clang_disposeCodeCompleteResults.
4833 */
4834typedef struct {
4835 /**
4836 * \brief The code-completion results.
4837 */
4838 CXCompletionResult *Results;
4839
4840 /**
4841 * \brief The number of code-completion results stored in the
4842 * \c Results array.
4843 */
4844 unsigned NumResults;
4845} CXCodeCompleteResults;
4846
4847/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004848 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4849 * modify its behavior.
4850 *
4851 * The enumerators in this enumeration can be bitwise-OR'd together to
4852 * provide multiple options to \c clang_codeCompleteAt().
4853 */
4854enum CXCodeComplete_Flags {
4855 /**
4856 * \brief Whether to include macros within the set of code
4857 * completions returned.
4858 */
4859 CXCodeComplete_IncludeMacros = 0x01,
4860
4861 /**
4862 * \brief Whether to include code patterns for language constructs
4863 * within the set of code completions, e.g., for loops.
4864 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004865 CXCodeComplete_IncludeCodePatterns = 0x02,
4866
4867 /**
4868 * \brief Whether to include brief documentation within the set of code
4869 * completions returned.
4870 */
4871 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorb68bc592010-08-05 09:09:23 +00004872};
4873
4874/**
Douglas Gregor21325842011-07-07 16:03:39 +00004875 * \brief Bits that represent the context under which completion is occurring.
4876 *
4877 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4878 * contexts are occurring simultaneously.
4879 */
4880enum CXCompletionContext {
4881 /**
4882 * \brief The context for completions is unexposed, as only Clang results
4883 * should be included. (This is equivalent to having no context bits set.)
4884 */
4885 CXCompletionContext_Unexposed = 0,
4886
4887 /**
4888 * \brief Completions for any possible type should be included in the results.
4889 */
4890 CXCompletionContext_AnyType = 1 << 0,
4891
4892 /**
4893 * \brief Completions for any possible value (variables, function calls, etc.)
4894 * should be included in the results.
4895 */
4896 CXCompletionContext_AnyValue = 1 << 1,
4897 /**
4898 * \brief Completions for values that resolve to an Objective-C object should
4899 * be included in the results.
4900 */
4901 CXCompletionContext_ObjCObjectValue = 1 << 2,
4902 /**
4903 * \brief Completions for values that resolve to an Objective-C selector
4904 * should be included in the results.
4905 */
4906 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4907 /**
4908 * \brief Completions for values that resolve to a C++ class type should be
4909 * included in the results.
4910 */
4911 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4912
4913 /**
4914 * \brief Completions for fields of the member being accessed using the dot
4915 * operator should be included in the results.
4916 */
4917 CXCompletionContext_DotMemberAccess = 1 << 5,
4918 /**
4919 * \brief Completions for fields of the member being accessed using the arrow
4920 * operator should be included in the results.
4921 */
4922 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4923 /**
4924 * \brief Completions for properties of the Objective-C object being accessed
4925 * using the dot operator should be included in the results.
4926 */
4927 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4928
4929 /**
4930 * \brief Completions for enum tags should be included in the results.
4931 */
4932 CXCompletionContext_EnumTag = 1 << 8,
4933 /**
4934 * \brief Completions for union tags should be included in the results.
4935 */
4936 CXCompletionContext_UnionTag = 1 << 9,
4937 /**
4938 * \brief Completions for struct tags should be included in the results.
4939 */
4940 CXCompletionContext_StructTag = 1 << 10,
4941
4942 /**
4943 * \brief Completions for C++ class names should be included in the results.
4944 */
4945 CXCompletionContext_ClassTag = 1 << 11,
4946 /**
4947 * \brief Completions for C++ namespaces and namespace aliases should be
4948 * included in the results.
4949 */
4950 CXCompletionContext_Namespace = 1 << 12,
4951 /**
4952 * \brief Completions for C++ nested name specifiers should be included in
4953 * the results.
4954 */
4955 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4956
4957 /**
4958 * \brief Completions for Objective-C interfaces (classes) should be included
4959 * in the results.
4960 */
4961 CXCompletionContext_ObjCInterface = 1 << 14,
4962 /**
4963 * \brief Completions for Objective-C protocols should be included in
4964 * the results.
4965 */
4966 CXCompletionContext_ObjCProtocol = 1 << 15,
4967 /**
4968 * \brief Completions for Objective-C categories should be included in
4969 * the results.
4970 */
4971 CXCompletionContext_ObjCCategory = 1 << 16,
4972 /**
4973 * \brief Completions for Objective-C instance messages should be included
4974 * in the results.
4975 */
4976 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4977 /**
4978 * \brief Completions for Objective-C class messages should be included in
4979 * the results.
4980 */
4981 CXCompletionContext_ObjCClassMessage = 1 << 18,
4982 /**
4983 * \brief Completions for Objective-C selector names should be included in
4984 * the results.
4985 */
4986 CXCompletionContext_ObjCSelectorName = 1 << 19,
4987
4988 /**
4989 * \brief Completions for preprocessor macro names should be included in
4990 * the results.
4991 */
4992 CXCompletionContext_MacroName = 1 << 20,
4993
4994 /**
4995 * \brief Natural language completions should be included in the results.
4996 */
4997 CXCompletionContext_NaturalLanguage = 1 << 21,
4998
4999 /**
5000 * \brief The current context is unknown, so set all contexts.
5001 */
5002 CXCompletionContext_Unknown = ((1 << 22) - 1)
5003};
5004
5005/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00005006 * \brief Returns a default set of code-completion options that can be
5007 * passed to\c clang_codeCompleteAt().
5008 */
5009CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
5010
5011/**
Douglas Gregor8e984da2010-08-04 16:47:14 +00005012 * \brief Perform code completion at a given location in a translation unit.
5013 *
5014 * This function performs code completion at a particular file, line, and
5015 * column within source code, providing results that suggest potential
5016 * code snippets based on the context of the completion. The basic model
5017 * for code completion is that Clang will parse a complete source file,
5018 * performing syntax checking up to the location where code-completion has
5019 * been requested. At that point, a special code-completion token is passed
5020 * to the parser, which recognizes this token and determines, based on the
5021 * current location in the C/Objective-C/C++ grammar and the state of
5022 * semantic analysis, what completions to provide. These completions are
5023 * returned via a new \c CXCodeCompleteResults structure.
5024 *
5025 * Code completion itself is meant to be triggered by the client when the
5026 * user types punctuation characters or whitespace, at which point the
5027 * code-completion location will coincide with the cursor. For example, if \c p
5028 * is a pointer, code-completion might be triggered after the "-" and then
5029 * after the ">" in \c p->. When the code-completion location is afer the ">",
5030 * the completion results will provide, e.g., the members of the struct that
5031 * "p" points to. The client is responsible for placing the cursor at the
5032 * beginning of the token currently being typed, then filtering the results
5033 * based on the contents of the token. For example, when code-completing for
5034 * the expression \c p->get, the client should provide the location just after
5035 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
5036 * client can filter the results based on the current token text ("get"), only
5037 * showing those results that start with "get". The intent of this interface
5038 * is to separate the relatively high-latency acquisition of code-completion
5039 * results from the filtering of results on a per-character basis, which must
5040 * have a lower latency.
5041 *
5042 * \param TU The translation unit in which code-completion should
5043 * occur. The source files for this translation unit need not be
5044 * completely up-to-date (and the contents of those source files may
5045 * be overridden via \p unsaved_files). Cursors referring into the
5046 * translation unit may be invalidated by this invocation.
5047 *
5048 * \param complete_filename The name of the source file where code
5049 * completion should be performed. This filename may be any file
5050 * included in the translation unit.
5051 *
5052 * \param complete_line The line at which code-completion should occur.
5053 *
5054 * \param complete_column The column at which code-completion should occur.
5055 * Note that the column should point just after the syntactic construct that
5056 * initiated code completion, and not in the middle of a lexical token.
5057 *
5058 * \param unsaved_files the Tiles that have not yet been saved to disk
5059 * but may be required for parsing or code completion, including the
5060 * contents of those files. The contents and name of these files (as
5061 * specified by CXUnsavedFile) are copied when necessary, so the
5062 * client only needs to guarantee their validity until the call to
5063 * this function returns.
5064 *
5065 * \param num_unsaved_files The number of unsaved file entries in \p
5066 * unsaved_files.
5067 *
Douglas Gregorb68bc592010-08-05 09:09:23 +00005068 * \param options Extra options that control the behavior of code
5069 * completion, expressed as a bitwise OR of the enumerators of the
5070 * CXCodeComplete_Flags enumeration. The
5071 * \c clang_defaultCodeCompleteOptions() function returns a default set
5072 * of code-completion options.
5073 *
Douglas Gregor8e984da2010-08-04 16:47:14 +00005074 * \returns If successful, a new \c CXCodeCompleteResults structure
5075 * containing code-completion results, which should eventually be
5076 * freed with \c clang_disposeCodeCompleteResults(). If code
5077 * completion fails, returns NULL.
5078 */
5079CINDEX_LINKAGE
5080CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
5081 const char *complete_filename,
5082 unsigned complete_line,
5083 unsigned complete_column,
5084 struct CXUnsavedFile *unsaved_files,
Douglas Gregorb68bc592010-08-05 09:09:23 +00005085 unsigned num_unsaved_files,
5086 unsigned options);
Douglas Gregor8e984da2010-08-04 16:47:14 +00005087
5088/**
Douglas Gregor49f67ce2010-08-26 13:48:20 +00005089 * \brief Sort the code-completion results in case-insensitive alphabetical
5090 * order.
5091 *
5092 * \param Results The set of results to sort.
5093 * \param NumResults The number of results in \p Results.
5094 */
5095CINDEX_LINKAGE
5096void clang_sortCodeCompletionResults(CXCompletionResult *Results,
5097 unsigned NumResults);
5098
5099/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00005100 * \brief Free the given set of code-completion results.
5101 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005102CINDEX_LINKAGE
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00005103void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregorf757a122010-08-23 23:00:57 +00005104
Douglas Gregor52606ff2010-01-20 01:10:47 +00005105/**
Douglas Gregor33cdd812010-02-18 18:08:43 +00005106 * \brief Determine the number of diagnostics produced prior to the
5107 * location where code completion was performed.
5108 */
Ted Kremenekd071c602010-03-13 02:50:34 +00005109CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00005110unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
5111
5112/**
5113 * \brief Retrieve a diagnostic associated with the given code completion.
5114 *
James Dennett574cb4c2012-06-15 05:41:51 +00005115 * \param Results the code completion results to query.
Douglas Gregor33cdd812010-02-18 18:08:43 +00005116 * \param Index the zero-based diagnostic number to retrieve.
5117 *
5118 * \returns the requested diagnostic. This diagnostic must be freed
5119 * via a call to \c clang_disposeDiagnostic().
5120 */
Ted Kremenekd071c602010-03-13 02:50:34 +00005121CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00005122CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
5123 unsigned Index);
5124
5125/**
Douglas Gregor21325842011-07-07 16:03:39 +00005126 * \brief Determines what compeltions are appropriate for the context
5127 * the given code completion.
5128 *
5129 * \param Results the code completion results to query
5130 *
5131 * \returns the kinds of completions that are appropriate for use
5132 * along with the given code completion results.
5133 */
5134CINDEX_LINKAGE
5135unsigned long long clang_codeCompleteGetContexts(
5136 CXCodeCompleteResults *Results);
Douglas Gregor63745d52011-07-21 01:05:26 +00005137
5138/**
5139 * \brief Returns the cursor kind for the container for the current code
5140 * completion context. The container is only guaranteed to be set for
5141 * contexts where a container exists (i.e. member accesses or Objective-C
5142 * message sends); if there is not a container, this function will return
5143 * CXCursor_InvalidCode.
5144 *
5145 * \param Results the code completion results to query
5146 *
5147 * \param IsIncomplete on return, this value will be false if Clang has complete
5148 * information about the container. If Clang does not have complete
5149 * information, this value will be true.
5150 *
5151 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5152 * container
5153 */
5154CINDEX_LINKAGE
5155enum CXCursorKind clang_codeCompleteGetContainerKind(
5156 CXCodeCompleteResults *Results,
5157 unsigned *IsIncomplete);
5158
5159/**
5160 * \brief Returns the USR for the container for the current code completion
5161 * context. If there is not a container for the current context, this
5162 * function will return the empty string.
5163 *
5164 * \param Results the code completion results to query
5165 *
5166 * \returns the USR for the container
5167 */
5168CINDEX_LINKAGE
5169CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor21325842011-07-07 16:03:39 +00005170
Douglas Gregorea777402011-07-26 15:24:30 +00005171
5172/**
5173 * \brief Returns the currently-entered selector for an Objective-C message
5174 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5175 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5176 * CXCompletionContext_ObjCClassMessage.
5177 *
5178 * \param Results the code completion results to query
5179 *
5180 * \returns the selector (or partial selector) that has been entered thus far
5181 * for an Objective-C message send.
5182 */
5183CINDEX_LINKAGE
5184CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5185
Douglas Gregor21325842011-07-07 16:03:39 +00005186/**
Douglas Gregor52606ff2010-01-20 01:10:47 +00005187 * @}
5188 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005189
5190
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005191/**
5192 * \defgroup CINDEX_MISC Miscellaneous utility functions
5193 *
5194 * @{
5195 */
Ted Kremenek3e315a22010-01-23 17:51:23 +00005196
5197/**
5198 * \brief Return a version string, suitable for showing to a user, but not
5199 * intended to be parsed (the format is not guaranteed to be stable).
5200 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +00005201CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005202
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005203
5204/**
5205 * \brief Enable/disable crash recovery.
5206 *
James Dennett574cb4c2012-06-15 05:41:51 +00005207 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5208 * value enables crash recovery, while 0 disables it.
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005209 */
5210CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5211
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005212 /**
Ted Kremenekd071c602010-03-13 02:50:34 +00005213 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005214 * (used with clang_getInclusions()).
5215 *
5216 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett574cb4c2012-06-15 05:41:51 +00005217 * file included (either at the top-level or by \#include directives) within
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005218 * a translation unit. The first argument is the file being included, and
5219 * the second and third arguments provide the inclusion stack. The
5220 * array is sorted in order of immediate inclusion. For example,
5221 * the first element refers to the location that included 'included_file'.
5222 */
5223typedef void (*CXInclusionVisitor)(CXFile included_file,
5224 CXSourceLocation* inclusion_stack,
5225 unsigned include_len,
5226 CXClientData client_data);
5227
5228/**
5229 * \brief Visit the set of preprocessor inclusions in a translation unit.
5230 * The visitor function is called with the provided data for every included
5231 * file. This does not include headers included by the PCH file (unless one
5232 * is inspecting the inclusions in the PCH file itself).
5233 */
5234CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5235 CXInclusionVisitor visitor,
5236 CXClientData client_data);
5237
5238/**
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005239 * @}
5240 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005241
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005242/** \defgroup CINDEX_REMAPPING Remapping functions
5243 *
5244 * @{
5245 */
5246
5247/**
5248 * \brief A remapping of original source files and their translated files.
5249 */
5250typedef void *CXRemapping;
5251
5252/**
5253 * \brief Retrieve a remapping.
5254 *
5255 * \param path the path that contains metadata about remappings.
5256 *
5257 * \returns the requested remapping. This remapping must be freed
5258 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5259 */
5260CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5261
5262/**
Ted Kremenekf7639e12012-03-06 20:06:33 +00005263 * \brief Retrieve a remapping.
5264 *
5265 * \param filePaths pointer to an array of file paths containing remapping info.
5266 *
5267 * \param numFiles number of file paths.
5268 *
5269 * \returns the requested remapping. This remapping must be freed
5270 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5271 */
5272CINDEX_LINKAGE
5273CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5274 unsigned numFiles);
5275
5276/**
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005277 * \brief Determine the number of remappings.
5278 */
5279CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5280
5281/**
5282 * \brief Get the original and the associated filename from the remapping.
5283 *
5284 * \param original If non-NULL, will be set to the original filename.
5285 *
5286 * \param transformed If non-NULL, will be set to the filename that the original
5287 * is associated with.
5288 */
5289CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5290 CXString *original, CXString *transformed);
5291
5292/**
5293 * \brief Dispose the remapping.
5294 */
5295CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5296
5297/**
5298 * @}
5299 */
5300
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005301/** \defgroup CINDEX_HIGH Higher level API functions
5302 *
5303 * @{
5304 */
5305
5306enum CXVisitorResult {
5307 CXVisit_Break,
5308 CXVisit_Continue
5309};
5310
5311typedef struct {
5312 void *context;
5313 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5314} CXCursorAndRangeVisitor;
5315
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005316typedef enum {
5317 /**
5318 * \brief Function returned successfully.
5319 */
5320 CXResult_Success = 0,
5321 /**
5322 * \brief One of the parameters was invalid for the function.
5323 */
5324 CXResult_Invalid = 1,
5325 /**
5326 * \brief The function was terminated by a callback (e.g. it returned
5327 * CXVisit_Break)
5328 */
5329 CXResult_VisitBreak = 2
5330
5331} CXResult;
5332
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005333/**
5334 * \brief Find references of a declaration in a specific file.
5335 *
5336 * \param cursor pointing to a declaration or a reference of one.
5337 *
5338 * \param file to search for references.
5339 *
5340 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5341 * each reference found.
5342 * The CXSourceRange will point inside the file; if the reference is inside
5343 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005344 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005345 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005346 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005347CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5348 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005349
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005350/**
5351 * \brief Find #import/#include directives in a specific file.
5352 *
5353 * \param TU translation unit containing the file to query.
5354 *
5355 * \param file to search for #import/#include directives.
5356 *
5357 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5358 * each directive found.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005359 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005360 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005361 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005362CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5363 CXFile file,
5364 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005365
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005366#ifdef __has_feature
5367# if __has_feature(blocks)
5368
5369typedef enum CXVisitorResult
5370 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5371
5372CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005373CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5374 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005375
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005376CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005377CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5378 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005379
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005380# endif
5381#endif
5382
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005383/**
5384 * \brief The client's data object that is associated with a CXFile.
5385 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005386typedef void *CXIdxClientFile;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005387
5388/**
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005389 * \brief The client's data object that is associated with a semantic entity.
5390 */
5391typedef void *CXIdxClientEntity;
5392
5393/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005394 * \brief The client's data object that is associated with a semantic container
5395 * of entities.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005396 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005397typedef void *CXIdxClientContainer;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005398
5399/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005400 * \brief The client's data object that is associated with an AST file (PCH
5401 * or module).
5402 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005403typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005404
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005405/**
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005406 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005407 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005408typedef struct {
5409 void *ptr_data[2];
5410 unsigned int_data;
5411} CXIdxLoc;
5412
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005413/**
James Dennett574cb4c2012-06-15 05:41:51 +00005414 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005415 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005416typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005417 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005418 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005419 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005420 CXIdxLoc hashLoc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005421 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005422 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005423 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005424 const char *filename;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005425 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005426 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005427 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005428 CXFile file;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005429 int isImport;
5430 int isAngled;
Argyrios Kyrtzidis5e2ec482012-10-18 00:17:05 +00005431 /**
5432 * \brief Non-zero if the directive was automatically turned into a module
5433 * import.
5434 */
5435 int isModuleImport;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005436} CXIdxIncludedFileInfo;
5437
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005438/**
James Dennett574cb4c2012-06-15 05:41:51 +00005439 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005440 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005441typedef struct {
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005442 /**
5443 * \brief Top level AST file containing the imported PCH, module or submodule.
5444 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005445 CXFile file;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005446 /**
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005447 * \brief The imported module or NULL if the AST file is a PCH.
5448 */
5449 CXModule module;
5450 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005451 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005452 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005453 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005454 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005455 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005456 * a module import. Applicable only for modules.
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005457 */
Argyrios Kyrtzidis184b1442012-10-03 21:05:44 +00005458 int isImplicit;
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005459
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005460} CXIdxImportedASTFileInfo;
5461
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005462typedef enum {
5463 CXIdxEntity_Unexposed = 0,
5464 CXIdxEntity_Typedef = 1,
5465 CXIdxEntity_Function = 2,
5466 CXIdxEntity_Variable = 3,
5467 CXIdxEntity_Field = 4,
5468 CXIdxEntity_EnumConstant = 5,
5469
5470 CXIdxEntity_ObjCClass = 6,
5471 CXIdxEntity_ObjCProtocol = 7,
5472 CXIdxEntity_ObjCCategory = 8,
5473
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005474 CXIdxEntity_ObjCInstanceMethod = 9,
5475 CXIdxEntity_ObjCClassMethod = 10,
5476 CXIdxEntity_ObjCProperty = 11,
5477 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005478
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005479 CXIdxEntity_Enum = 13,
5480 CXIdxEntity_Struct = 14,
5481 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005482
5483 CXIdxEntity_CXXClass = 16,
5484 CXIdxEntity_CXXNamespace = 17,
5485 CXIdxEntity_CXXNamespaceAlias = 18,
5486 CXIdxEntity_CXXStaticVariable = 19,
5487 CXIdxEntity_CXXStaticMethod = 20,
5488 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matose9a3ed42012-08-31 22:18:20 +00005489 CXIdxEntity_CXXConstructor = 22,
5490 CXIdxEntity_CXXDestructor = 23,
5491 CXIdxEntity_CXXConversionFunction = 24,
5492 CXIdxEntity_CXXTypeAlias = 25,
5493 CXIdxEntity_CXXInterface = 26
5494
5495} CXIdxEntityKind;
5496
Argyrios Kyrtzidis52002882011-12-07 20:44:12 +00005497typedef enum {
5498 CXIdxEntityLang_None = 0,
5499 CXIdxEntityLang_C = 1,
5500 CXIdxEntityLang_ObjC = 2,
5501 CXIdxEntityLang_CXX = 3
5502} CXIdxEntityLanguage;
5503
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005504/**
5505 * \brief Extra C++ template information for an entity. This can apply to:
5506 * CXIdxEntity_Function
5507 * CXIdxEntity_CXXClass
5508 * CXIdxEntity_CXXStaticMethod
5509 * CXIdxEntity_CXXInstanceMethod
5510 * CXIdxEntity_CXXConstructor
5511 * CXIdxEntity_CXXConversionFunction
5512 * CXIdxEntity_CXXTypeAlias
5513 */
5514typedef enum {
5515 CXIdxEntity_NonTemplate = 0,
5516 CXIdxEntity_Template = 1,
5517 CXIdxEntity_TemplatePartialSpecialization = 2,
5518 CXIdxEntity_TemplateSpecialization = 3
5519} CXIdxEntityCXXTemplateKind;
5520
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005521typedef enum {
5522 CXIdxAttr_Unexposed = 0,
5523 CXIdxAttr_IBAction = 1,
5524 CXIdxAttr_IBOutlet = 2,
5525 CXIdxAttr_IBOutletCollection = 3
5526} CXIdxAttrKind;
5527
5528typedef struct {
5529 CXIdxAttrKind kind;
5530 CXCursor cursor;
5531 CXIdxLoc loc;
5532} CXIdxAttrInfo;
5533
5534typedef struct {
Argyrios Kyrtzidis4d873b72011-12-15 00:05:00 +00005535 CXIdxEntityKind kind;
5536 CXIdxEntityCXXTemplateKind templateKind;
5537 CXIdxEntityLanguage lang;
5538 const char *name;
5539 const char *USR;
5540 CXCursor cursor;
5541 const CXIdxAttrInfo *const *attributes;
5542 unsigned numAttributes;
5543} CXIdxEntityInfo;
5544
5545typedef struct {
5546 CXCursor cursor;
5547} CXIdxContainerInfo;
5548
5549typedef struct {
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005550 const CXIdxAttrInfo *attrInfo;
5551 const CXIdxEntityInfo *objcClass;
5552 CXCursor classCursor;
5553 CXIdxLoc classLoc;
5554} CXIdxIBOutletCollectionAttrInfo;
5555
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005556typedef enum {
5557 CXIdxDeclFlag_Skipped = 0x1
5558} CXIdxDeclInfoFlags;
5559
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005560typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005561 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005562 CXCursor cursor;
5563 CXIdxLoc loc;
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005564 const CXIdxContainerInfo *semanticContainer;
5565 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005566 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005567 * cases like out-of-line C++ member functions.
5568 */
5569 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005570 int isRedeclaration;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005571 int isDefinition;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005572 int isContainer;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005573 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005574 /**
5575 * \brief Whether the declaration exists in code or was created implicitly
5576 * by the compiler, e.g. implicit objc methods for properties.
5577 */
5578 int isImplicit;
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005579 const CXIdxAttrInfo *const *attributes;
5580 unsigned numAttributes;
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005581
5582 unsigned flags;
5583
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005584} CXIdxDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005585
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005586typedef enum {
5587 CXIdxObjCContainer_ForwardRef = 0,
5588 CXIdxObjCContainer_Interface = 1,
5589 CXIdxObjCContainer_Implementation = 2
5590} CXIdxObjCContainerKind;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005591
5592typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005593 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005594 CXIdxObjCContainerKind kind;
5595} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005596
5597typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005598 const CXIdxEntityInfo *base;
5599 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005600 CXIdxLoc loc;
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005601} CXIdxBaseClassInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005602
5603typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005604 const CXIdxEntityInfo *protocol;
5605 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005606 CXIdxLoc loc;
5607} CXIdxObjCProtocolRefInfo;
5608
5609typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005610 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005611 unsigned numProtocols;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005612} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005613
5614typedef struct {
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005615 const CXIdxObjCContainerDeclInfo *containerInfo;
5616 const CXIdxBaseClassInfo *superInfo;
5617 const CXIdxObjCProtocolRefListInfo *protocols;
5618} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005619
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005620typedef struct {
Argyrios Kyrtzidis9b9f7a92011-12-13 18:47:45 +00005621 const CXIdxObjCContainerDeclInfo *containerInfo;
5622 const CXIdxEntityInfo *objcClass;
5623 CXCursor classCursor;
5624 CXIdxLoc classLoc;
5625 const CXIdxObjCProtocolRefListInfo *protocols;
5626} CXIdxObjCCategoryDeclInfo;
5627
5628typedef struct {
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005629 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005630 const CXIdxEntityInfo *getter;
5631 const CXIdxEntityInfo *setter;
5632} CXIdxObjCPropertyDeclInfo;
5633
5634typedef struct {
5635 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005636 const CXIdxBaseClassInfo *const *bases;
5637 unsigned numBases;
5638} CXIdxCXXClassDeclInfo;
5639
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005640/**
James Dennett574cb4c2012-06-15 05:41:51 +00005641 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005642 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005643typedef enum {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005644 /**
5645 * \brief The entity is referenced directly in user's code.
5646 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005647 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005648 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005649 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5650 * dot syntax.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005651 */
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005652 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005653} CXIdxEntityRefKind;
5654
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005655/**
James Dennett574cb4c2012-06-15 05:41:51 +00005656 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005657 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005658typedef struct {
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005659 CXIdxEntityRefKind kind;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005660 /**
5661 * \brief Reference cursor.
5662 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005663 CXCursor cursor;
5664 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005665 /**
5666 * \brief The entity that gets referenced.
5667 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005668 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005669 /**
5670 * \brief Immediate "parent" of the reference. For example:
5671 *
5672 * \code
5673 * Foo *var;
5674 * \endcode
5675 *
5676 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005677 * For references inside statement bodies of functions/methods,
5678 * the parentEntity will be the function/method.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005679 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005680 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005681 /**
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005682 * \brief Lexical container context of the reference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005683 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005684 const CXIdxContainerInfo *container;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005685} CXIdxEntityRefInfo;
5686
James Dennett574cb4c2012-06-15 05:41:51 +00005687/**
5688 * \brief A group of callbacks used by #clang_indexSourceFile and
5689 * #clang_indexTranslationUnit.
5690 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005691typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005692 /**
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005693 * \brief Called periodically to check whether indexing should be aborted.
5694 * Should return 0 to continue, and non-zero to abort.
5695 */
5696 int (*abortQuery)(CXClientData client_data, void *reserved);
5697
5698 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005699 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005700 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005701 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005702 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005703
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005704 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett574cb4c2012-06-15 05:41:51 +00005705 CXFile mainFile, void *reserved);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005706
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005707 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005708 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005709 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005710 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005711 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005712
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005713 /**
5714 * \brief Called when a AST file (PCH or module) gets imported.
5715 *
5716 * AST files will not get indexed (there will not be callbacks to index all
5717 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005718 * file is not already indexed, to initiate a new indexing job specific to
5719 * the AST file.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005720 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005721 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005722 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005723
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005724 /**
5725 * \brief Called at the beginning of indexing a translation unit.
5726 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005727 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005728 void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005729
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005730 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005731 const CXIdxDeclInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005732
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005733 /**
5734 * \brief Called to index a reference of an entity.
5735 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005736 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005737 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005738
5739} IndexerCallbacks;
5740
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005741CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005742CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5743clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005744
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005745CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5746clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5747
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005748CINDEX_LINKAGE
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005749const CXIdxObjCCategoryDeclInfo *
5750clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5751
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005752CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5753clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005754
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005755CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5756clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5757
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005758CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5759clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5760
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005761CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5762clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5763
5764/**
5765 * \brief For retrieving a custom CXIdxClientContainer attached to a
5766 * container.
5767 */
5768CINDEX_LINKAGE CXIdxClientContainer
5769clang_index_getClientContainer(const CXIdxContainerInfo *);
5770
5771/**
5772 * \brief For setting a custom CXIdxClientContainer attached to a
5773 * container.
5774 */
5775CINDEX_LINKAGE void
5776clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5777
5778/**
5779 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5780 */
5781CINDEX_LINKAGE CXIdxClientEntity
5782clang_index_getClientEntity(const CXIdxEntityInfo *);
5783
5784/**
5785 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5786 */
5787CINDEX_LINKAGE void
5788clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5789
5790/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005791 * \brief An indexing action/session, to be applied to one or multiple
5792 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005793 */
5794typedef void *CXIndexAction;
5795
5796/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005797 * \brief An indexing action/session, to be applied to one or multiple
5798 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005799 *
5800 * \param CIdx The index object with which the index action will be associated.
5801 */
5802CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5803
5804/**
5805 * \brief Destroy the given index action.
5806 *
5807 * The index action must not be destroyed until all of the translation units
5808 * created within that index action have been destroyed.
5809 */
5810CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5811
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005812typedef enum {
5813 /**
5814 * \brief Used to indicate that no special indexing options are needed.
5815 */
5816 CXIndexOpt_None = 0x0,
5817
5818 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005819 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5820 * be invoked for only one reference of an entity per source file that does
5821 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005822 */
Argyrios Kyrtzidisfb7d1452012-01-14 00:11:49 +00005823 CXIndexOpt_SuppressRedundantRefs = 0x1,
5824
5825 /**
5826 * \brief Function-local symbols should be indexed. If this is not set
5827 * function-local symbols will be ignored.
5828 */
Argyrios Kyrtzidis7e747952012-02-14 22:23:11 +00005829 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5830
5831 /**
5832 * \brief Implicit function/class template instantiations should be indexed.
5833 * If this is not set, implicit instantiations will be ignored.
5834 */
Argyrios Kyrtzidis6c9ed7d2012-03-27 21:38:03 +00005835 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5836
5837 /**
5838 * \brief Suppress all compiler warnings when parsing for indexing.
5839 */
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005840 CXIndexOpt_SuppressWarnings = 0x8,
5841
5842 /**
5843 * \brief Skip a function/method body that was already parsed during an
5844 * indexing session assosiated with a \c CXIndexAction object.
5845 * Bodies in system headers are always skipped.
5846 */
5847 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5848
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005849} CXIndexOptFlags;
5850
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005851/**
5852 * \brief Index the given source file and the translation unit corresponding
James Dennett574cb4c2012-06-15 05:41:51 +00005853 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005854 *
5855 * \param client_data pointer data supplied by the client, which will
5856 * be passed to the invoked callbacks.
5857 *
5858 * \param index_callbacks Pointer to indexing callbacks that the client
5859 * implements.
5860 *
James Dennett574cb4c2012-06-15 05:41:51 +00005861 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005862 * passed in index_callbacks.
5863 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005864 * \param index_options A bitmask of options that affects how indexing is
5865 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005866 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00005867 * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be
5868 * reused after indexing is finished. Set to \c NULL if you do not require it.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005869 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00005870 * \returns 0 on success or if there were errors from which the compiler could
5871 * recover. If there is a failure from which the there is no recovery, returns
5872 * a non-zero \c CXErrorCode.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005873 *
James Dennett574cb4c2012-06-15 05:41:51 +00005874 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005875 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005876CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005877 CXClientData client_data,
5878 IndexerCallbacks *index_callbacks,
5879 unsigned index_callbacks_size,
5880 unsigned index_options,
5881 const char *source_filename,
5882 const char * const *command_line_args,
5883 int num_command_line_args,
5884 struct CXUnsavedFile *unsaved_files,
5885 unsigned num_unsaved_files,
5886 CXTranslationUnit *out_TU,
5887 unsigned TU_options);
5888
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005889/**
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005890 * \brief Index the given translation unit via callbacks implemented through
James Dennett574cb4c2012-06-15 05:41:51 +00005891 * #IndexerCallbacks.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005892 *
5893 * The order of callback invocations is not guaranteed to be the same as
5894 * when indexing a source file. The high level order will be:
5895 *
5896 * -Preprocessor callbacks invocations
5897 * -Declaration/reference callbacks invocations
5898 * -Diagnostic callback invocations
5899 *
James Dennett574cb4c2012-06-15 05:41:51 +00005900 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005901 *
5902 * \returns If there is a failure from which the there is no recovery, returns
5903 * non-zero, otherwise returns 0.
5904 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005905CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005906 CXClientData client_data,
5907 IndexerCallbacks *index_callbacks,
5908 unsigned index_callbacks_size,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005909 unsigned index_options,
5910 CXTranslationUnit);
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005911
5912/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005913 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5914 * the given CXIdxLoc.
5915 *
5916 * If the location refers into a macro expansion, retrieves the
5917 * location of the macro expansion and if it refers into a macro argument
5918 * retrieves the location of the argument.
5919 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005920CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005921 CXIdxClientFile *indexFile,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005922 CXFile *file,
5923 unsigned *line,
5924 unsigned *column,
5925 unsigned *offset);
5926
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005927/**
5928 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5929 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005930CINDEX_LINKAGE
5931CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5932
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005933/**
5934 * @}
5935 */
5936
Douglas Gregor6007cf22010-01-22 22:29:16 +00005937/**
5938 * @}
5939 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005940
Ted Kremenekb60d87c2009-08-26 22:36:44 +00005941#ifdef __cplusplus
5942}
5943#endif
5944#endif
5945