blob: 9c37ac745bb5f66f5f95c87808dbedf1434923d3 [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"
Argyrios Kyrtzidis0b9682e2014-02-25 03:59:23 +000022#include "clang-c/CXErrorCode.h"
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000023#include "clang-c/CXString.h"
Argyrios Kyrtzidis09a439d2014-02-25 03:59:16 +000024#include "clang-c/BuildSystem.h"
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000025
Argyrios Kyrtzidis1c4db8d2012-11-06 21:21:49 +000026/**
27 * \brief The version constants for the libclang API.
28 * CINDEX_VERSION_MINOR should increase when there are API additions.
29 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
30 *
31 * The policy about the libclang API was always to keep it source and ABI
32 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
33 */
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000034#define CINDEX_VERSION_MAJOR 0
Argyrios Kyrtzidis0b9682e2014-02-25 03:59:23 +000035#define CINDEX_VERSION_MINOR 24
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000036
37#define CINDEX_VERSION_ENCODE(major, minor) ( \
38 ((major) * 10000) \
39 + ((minor) * 1))
40
41#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
42 CINDEX_VERSION_MAJOR, \
43 CINDEX_VERSION_MINOR )
44
45#define CINDEX_VERSION_STRINGIZE_(major, minor) \
46 #major"."#minor
47#define CINDEX_VERSION_STRINGIZE(major, minor) \
48 CINDEX_VERSION_STRINGIZE_(major, minor)
49
50#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
51 CINDEX_VERSION_MAJOR, \
52 CINDEX_VERSION_MINOR)
53
Ted Kremenekb60d87c2009-08-26 22:36:44 +000054#ifdef __cplusplus
55extern "C" {
56#endif
57
Douglas Gregor4a4e0eb2011-02-23 17:45:25 +000058/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor52606ff2010-01-20 01:10:47 +000059 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000060 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorc8e390c2010-01-20 22:45:41 +000061 * facilities for parsing source code into an abstract syntax tree (AST),
62 * loading already-parsed ASTs, traversing the AST, associating
63 * physical source locations with elements within the AST, and other
64 * facilities that support Clang-based development tools.
Douglas Gregor52606ff2010-01-20 01:10:47 +000065 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000066 * This C interface to Clang will never provide all of the information
Douglas Gregorc8e390c2010-01-20 22:45:41 +000067 * representation stored in Clang's C++ AST, nor should it: the intent is to
68 * maintain an API that is relatively stable from one release to the next,
69 * providing only the basic functionality needed to support development tools.
Daniel Dunbar62ebf252010-01-24 02:54:26 +000070 *
71 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorc8e390c2010-01-20 22:45:41 +000072 * functions are prefixed with "clang_".
Douglas Gregor52606ff2010-01-20 01:10:47 +000073 *
74 * @{
75 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +000076
Douglas Gregor802f12f2010-01-20 22:28:27 +000077/**
78 * \brief An "index" that consists of a set of translation units that would
79 * typically be linked together into an executable or library.
80 */
81typedef void *CXIndex;
Steve Naroffd5e8e862009-08-27 19:51:58 +000082
Douglas Gregor802f12f2010-01-20 22:28:27 +000083/**
84 * \brief A single translation unit, which resides in an index.
85 */
Ted Kremenek7df92ae2010-11-17 23:24:11 +000086typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroffd5e8e862009-08-27 19:51:58 +000087
Douglas Gregor802f12f2010-01-20 22:28:27 +000088/**
Douglas Gregor6007cf22010-01-22 22:29:16 +000089 * \brief Opaque pointer representing client data that will be passed through
90 * to various callbacks and visitors.
Douglas Gregor802f12f2010-01-20 22:28:27 +000091 */
Douglas Gregor6007cf22010-01-22 22:29:16 +000092typedef void *CXClientData;
Daniel Dunbar62ebf252010-01-24 02:54:26 +000093
Douglas Gregor9485bf92009-12-02 09:21:34 +000094/**
95 * \brief Provides the contents of a file that has not yet been saved to disk.
96 *
97 * Each CXUnsavedFile instance provides the name of a file on the
98 * system along with the current contents of that file that have not
99 * yet been saved to disk.
100 */
101struct CXUnsavedFile {
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000102 /**
103 * \brief The file whose contents have not yet been saved.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000104 *
105 * This file must already exist in the file system.
106 */
107 const char *Filename;
108
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000109 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000110 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000111 */
112 const char *Contents;
113
114 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000115 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000116 */
117 unsigned long Length;
118};
119
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000120/**
121 * \brief Describes the availability of a particular entity, which indicates
122 * whether the use of this entity will result in a warning or error due to
123 * it being deprecated or unavailable.
124 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000125enum CXAvailabilityKind {
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000126 /**
127 * \brief The entity is available.
128 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000129 CXAvailability_Available,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000130 /**
131 * \brief The entity is available, but has been deprecated (and its use is
132 * not recommended).
133 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000134 CXAvailability_Deprecated,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000135 /**
136 * \brief The entity is not available; any use of it will be an error.
137 */
Erik Verbruggen2e657ff2011-10-06 07:27:49 +0000138 CXAvailability_NotAvailable,
139 /**
140 * \brief The entity is available, but not accessible; any use of it will be
141 * an error.
142 */
143 CXAvailability_NotAccessible
Douglas Gregorf757a122010-08-23 23:00:57 +0000144};
Douglas Gregord6225d32012-05-08 00:14:45 +0000145
146/**
147 * \brief Describes a version number of the form major.minor.subminor.
148 */
149typedef struct CXVersion {
150 /**
151 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
152 * value indicates that there is no version number at all.
153 */
154 int Major;
155 /**
156 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
157 * will be negative if no minor version number was provided, e.g., for
158 * version '10'.
159 */
160 int Minor;
161 /**
162 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
163 * will be negative if no minor or subminor version number was provided,
164 * e.g., in version '10' or '10.7'.
165 */
166 int Subminor;
167} CXVersion;
Douglas Gregorf757a122010-08-23 23:00:57 +0000168
Douglas Gregor802f12f2010-01-20 22:28:27 +0000169/**
James Dennett574cb4c2012-06-15 05:41:51 +0000170 * \brief Provides a shared context for creating translation units.
171 *
172 * It provides two options:
Steve Naroff531e2842009-10-20 14:46:24 +0000173 *
174 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
175 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000176 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroff531e2842009-10-20 14:46:24 +0000177 * header that was used by the translation unit. If zero, all declarations
178 * will be enumerated.
179 *
Steve Naroffbb4568a2009-10-20 16:36:34 +0000180 * Here is an example:
181 *
James Dennett574cb4c2012-06-15 05:41:51 +0000182 * \code
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000183 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
184 * Idx = clang_createIndex(1, 1);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000185 *
186 * // IndexTest.pch was produced with the following command:
187 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
188 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
189 *
190 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000191 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor990b5762010-01-20 21:37:00 +0000192 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000193 * clang_disposeTranslationUnit(TU);
194 *
195 * // This will load all the symbols from 'IndexTest.c', excluding symbols
196 * // from 'IndexTest.pch'.
Daniel Dunbard0159262010-01-25 00:43:14 +0000197 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
198 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
199 * 0, 0);
Douglas Gregorfed36b12010-01-20 23:57:43 +0000200 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
201 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000202 * clang_disposeTranslationUnit(TU);
James Dennett574cb4c2012-06-15 05:41:51 +0000203 * \endcode
Steve Naroffbb4568a2009-10-20 16:36:34 +0000204 *
205 * This process of creating the 'pch', loading it separately, and using it (via
206 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
207 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroff531e2842009-10-20 14:46:24 +0000208 */
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000209CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
210 int displayDiagnostics);
Ted Kremenekd071c602010-03-13 02:50:34 +0000211
Douglas Gregor408bb742010-02-08 23:03:06 +0000212/**
213 * \brief Destroy the given index.
214 *
215 * The index must not be destroyed until all of the translation units created
216 * within that index have been destroyed.
217 */
Daniel Dunbar11089662009-12-03 01:54:28 +0000218CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000219
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000220typedef enum {
221 /**
222 * \brief Used to indicate that no special CXIndex options are needed.
223 */
224 CXGlobalOpt_None = 0x0,
225
226 /**
227 * \brief Used to indicate that threads that libclang creates for indexing
228 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000229 *
230 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
231 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000232 */
233 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
234
235 /**
236 * \brief Used to indicate that threads that libclang creates for editing
237 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000238 *
239 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
240 * #clang_annotateTokens
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000241 */
242 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
243
244 /**
245 * \brief Used to indicate that all threads that libclang creates should use
246 * background priority.
247 */
248 CXGlobalOpt_ThreadBackgroundPriorityForAll =
249 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
250 CXGlobalOpt_ThreadBackgroundPriorityForEditing
251
252} CXGlobalOptFlags;
253
254/**
James Dennett574cb4c2012-06-15 05:41:51 +0000255 * \brief Sets general options associated with a CXIndex.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000256 *
257 * For example:
258 * \code
259 * CXIndex idx = ...;
260 * clang_CXIndex_setGlobalOptions(idx,
261 * clang_CXIndex_getGlobalOptions(idx) |
262 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
263 * \endcode
264 *
265 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
266 */
267CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
268
269/**
270 * \brief Gets the general options associated with a CXIndex.
271 *
272 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
273 * are associated with the given CXIndex object.
274 */
275CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
276
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000277/**
Douglas Gregor6007cf22010-01-22 22:29:16 +0000278 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000279 *
280 * @{
281 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000282
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000283/**
284 * \brief A particular source file that is part of a translation unit.
285 */
286typedef void *CXFile;
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000287
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000288
289/**
290 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff6231f182009-10-27 14:35:18 +0000291 */
Ted Kremenekc560b682010-02-17 00:41:20 +0000292CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000293
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000294/**
295 * \brief Retrieve the last modification time of the given file.
296 */
Douglas Gregor249c1212009-10-31 15:48:08 +0000297CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff6231f182009-10-27 14:35:18 +0000298
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000299/**
Argyrios Kyrtzidisac08b262013-01-26 04:52:52 +0000300 * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
301 * across an indexing session.
302 */
303typedef struct {
304 unsigned long long data[3];
305} CXFileUniqueID;
306
307/**
308 * \brief Retrieve the unique ID for the given \c file.
309 *
310 * \param file the file to get the ID for.
311 * \param outID stores the returned CXFileUniqueID.
312 * \returns If there was a failure getting the unique ID, returns non-zero,
313 * otherwise returns 0.
314*/
315CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
316
317/**
Douglas Gregor37aa4932011-05-04 00:14:37 +0000318 * \brief Determine whether the given header is guarded against
319 * multiple inclusions, either with the conventional
James Dennett574cb4c2012-06-15 05:41:51 +0000320 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
Douglas Gregor37aa4932011-05-04 00:14:37 +0000321 */
322CINDEX_LINKAGE unsigned
323clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
324
325/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000326 * \brief Retrieve a file handle within the given translation unit.
327 *
328 * \param tu the translation unit
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000329 *
Douglas Gregor816fd362010-01-22 21:44:22 +0000330 * \param file_name the name of the file.
331 *
332 * \returns the file handle for the named file in the translation unit \p tu,
333 * or a NULL file handle if the file was not a part of this translation unit.
334 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000335CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregor816fd362010-01-22 21:44:22 +0000336 const char *file_name);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000337
Douglas Gregor816fd362010-01-22 21:44:22 +0000338/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000339 * @}
340 */
341
342/**
343 * \defgroup CINDEX_LOCATIONS Physical source locations
344 *
345 * Clang represents physical source locations in its abstract syntax tree in
346 * great detail, with file, line, and column information for the majority of
347 * the tokens parsed in the source code. These data types and functions are
348 * used to represent source location information, either for a particular
349 * point in the program or for a range of points in the program, and extract
350 * specific location information from those data types.
351 *
352 * @{
353 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000354
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000355/**
Douglas Gregor4f46e782010-01-19 21:36:55 +0000356 * \brief Identifies a specific source location within a translation
357 * unit.
358 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000359 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregor229bebd2010-11-09 06:24:54 +0000360 * to map a source location to a particular file, line, and column.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000361 */
362typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000363 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000364 unsigned int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000365} CXSourceLocation;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000366
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000367/**
Daniel Dunbar02968e52010-02-14 10:02:57 +0000368 * \brief Identifies a half-open character range in the source code.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000369 *
Douglas Gregor4f46e782010-01-19 21:36:55 +0000370 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
371 * starting and end locations from a source range, respectively.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000372 */
373typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000374 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000375 unsigned begin_int_data;
376 unsigned end_int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000377} CXSourceRange;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000378
Douglas Gregor4f46e782010-01-19 21:36:55 +0000379/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000380 * \brief Retrieve a NULL (invalid) source location.
381 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000382CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000383
Douglas Gregor816fd362010-01-22 21:44:22 +0000384/**
James Dennett574cb4c2012-06-15 05:41:51 +0000385 * \brief Determine whether two source locations, which must refer into
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000386 * the same translation unit, refer to exactly the same point in the source
Douglas Gregor816fd362010-01-22 21:44:22 +0000387 * code.
388 *
389 * \returns non-zero if the source locations refer to the same location, zero
390 * if they refer to different locations.
391 */
392CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
393 CXSourceLocation loc2);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000394
Douglas Gregor816fd362010-01-22 21:44:22 +0000395/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000396 * \brief Retrieves the source location associated with a given file/line/column
397 * in a particular translation unit.
Douglas Gregor816fd362010-01-22 21:44:22 +0000398 */
399CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
400 CXFile file,
401 unsigned line,
402 unsigned column);
David Chisnall2e16ac52010-10-15 17:07:39 +0000403/**
404 * \brief Retrieves the source location associated with a given character offset
405 * in a particular translation unit.
406 */
407CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
408 CXFile file,
409 unsigned offset);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000410
Douglas Gregor816fd362010-01-22 21:44:22 +0000411/**
Argyrios Kyrtzidis25f7af12013-04-12 17:06:51 +0000412 * \brief Returns non-zero if the given source location is in a system header.
413 */
414CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
415
416/**
Stefanus Du Toitdb51c632013-08-08 17:48:14 +0000417 * \brief Returns non-zero if the given source location is in the main file of
418 * the corresponding translation unit.
419 */
420CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
421
422/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000423 * \brief Retrieve a NULL (invalid) source range.
424 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000425CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
Ted Kremenekd071c602010-03-13 02:50:34 +0000426
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000427/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000428 * \brief Retrieve a source range given the beginning and ending source
429 * locations.
430 */
431CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
432 CXSourceLocation end);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000433
Douglas Gregor816fd362010-01-22 21:44:22 +0000434/**
Douglas Gregor757e38b2011-07-23 19:35:14 +0000435 * \brief Determine whether two ranges are equivalent.
436 *
437 * \returns non-zero if the ranges are the same, zero if they differ.
438 */
439CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
440 CXSourceRange range2);
441
442/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +0000443 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000444 */
Erik Verbruggend610b0f2011-10-06 12:11:57 +0000445CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000446
447/**
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000448 * \brief Retrieve the file, line, column, and offset represented by
449 * the given source location.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000450 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000451 * If the location refers into a macro expansion, retrieves the
452 * location of the macro expansion.
Douglas Gregor229bebd2010-11-09 06:24:54 +0000453 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000454 * \param location the location within a source file that will be decomposed
455 * into its parts.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000456 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000457 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000458 * source location points.
459 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000460 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000461 * source location points.
462 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000463 * \param column [out] if non-NULL, will be set to the column to which the given
464 * source location points.
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000465 *
466 * \param offset [out] if non-NULL, will be set to the offset into the
467 * buffer to which the given source location points.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000468 */
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000469CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
470 CXFile *file,
471 unsigned *line,
472 unsigned *column,
473 unsigned *offset);
474
475/**
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000476 * \brief Retrieve the file, line, column, and offset represented by
477 * the given source location, as specified in a # line directive.
478 *
479 * Example: given the following source code in a file somefile.c
480 *
James Dennett574cb4c2012-06-15 05:41:51 +0000481 * \code
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000482 * #123 "dummy.c" 1
483 *
484 * static int func(void)
485 * {
486 * return 0;
487 * }
James Dennett574cb4c2012-06-15 05:41:51 +0000488 * \endcode
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000489 *
490 * the location information returned by this function would be
491 *
492 * File: dummy.c Line: 124 Column: 12
493 *
494 * whereas clang_getExpansionLocation would have returned
495 *
496 * File: somefile.c Line: 3 Column: 12
497 *
498 * \param location the location within a source file that will be decomposed
499 * into its parts.
500 *
501 * \param filename [out] if non-NULL, will be set to the filename of the
502 * source location. Note that filenames returned will be for "virtual" files,
503 * which don't necessarily exist on the machine running clang - e.g. when
504 * parsing preprocessed output obtained from a different environment. If
505 * a non-NULL value is passed in, remember to dispose of the returned value
506 * using \c clang_disposeString() once you've finished with it. For an invalid
507 * source location, an empty string is returned.
508 *
509 * \param line [out] if non-NULL, will be set to the line number of the
510 * source location. For an invalid source location, zero is returned.
511 *
512 * \param column [out] if non-NULL, will be set to the column number of the
513 * source location. For an invalid source location, zero is returned.
514 */
515CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
516 CXString *filename,
517 unsigned *line,
518 unsigned *column);
519
520/**
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000521 * \brief Legacy API to retrieve the file, line, column, and offset represented
522 * by the given source location.
523 *
524 * This interface has been replaced by the newer interface
James Dennett574cb4c2012-06-15 05:41:51 +0000525 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000526 * details.
527 */
Douglas Gregor4f46e782010-01-19 21:36:55 +0000528CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
529 CXFile *file,
530 unsigned *line,
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000531 unsigned *column,
532 unsigned *offset);
Douglas Gregor47751d62010-01-26 03:07:15 +0000533
534/**
Douglas Gregor229bebd2010-11-09 06:24:54 +0000535 * \brief Retrieve the file, line, column, and offset represented by
536 * the given source location.
537 *
538 * If the location refers into a macro instantiation, return where the
539 * location was originally spelled in the source file.
540 *
541 * \param location the location within a source file that will be decomposed
542 * into its parts.
543 *
544 * \param file [out] if non-NULL, will be set to the file to which the given
545 * source location points.
546 *
547 * \param line [out] if non-NULL, will be set to the line to which the given
548 * source location points.
549 *
550 * \param column [out] if non-NULL, will be set to the column to which the given
551 * source location points.
552 *
553 * \param offset [out] if non-NULL, will be set to the offset into the
554 * buffer to which the given source location points.
555 */
556CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
557 CXFile *file,
558 unsigned *line,
559 unsigned *column,
560 unsigned *offset);
561
562/**
Argyrios Kyrtzidis56be7162013-01-04 18:30:13 +0000563 * \brief Retrieve the file, line, column, and offset represented by
564 * the given source location.
565 *
566 * If the location refers into a macro expansion, return where the macro was
567 * expanded or where the macro argument was written, if the location points at
568 * a macro argument.
569 *
570 * \param location the location within a source file that will be decomposed
571 * into its parts.
572 *
573 * \param file [out] if non-NULL, will be set to the file to which the given
574 * source location points.
575 *
576 * \param line [out] if non-NULL, will be set to the line to which the given
577 * source location points.
578 *
579 * \param column [out] if non-NULL, will be set to the column to which the given
580 * source location points.
581 *
582 * \param offset [out] if non-NULL, will be set to the offset into the
583 * buffer to which the given source location points.
584 */
585CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
586 CXFile *file,
587 unsigned *line,
588 unsigned *column,
589 unsigned *offset);
590
591/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000592 * \brief Retrieve a source location representing the first character within a
593 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000594 */
595CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
596
597/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000598 * \brief Retrieve a source location representing the last character within a
599 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000600 */
601CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
602
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000603/**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000604 * \brief Identifies an array of ranges.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000605 */
606typedef struct {
607 /** \brief The number of ranges in the \c ranges array. */
608 unsigned count;
609 /**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000610 * \brief An array of \c CXSourceRanges.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000611 */
612 CXSourceRange *ranges;
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000613} CXSourceRangeList;
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000614
615/**
616 * \brief Retrieve all ranges that were skipped by the preprocessor.
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000617 *
618 * The preprocessor will skip lines when they are surrounded by an
619 * if/ifdef/ifndef directive whose condition does not evaluate to true.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000620 */
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000621CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
622 CXFile file);
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000623
624/**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000625 * \brief Destroy the given \c CXSourceRangeList.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000626 */
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000627CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000628
629/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000630 * @}
631 */
Douglas Gregor6007cf22010-01-22 22:29:16 +0000632
633/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000634 * \defgroup CINDEX_DIAG Diagnostic reporting
635 *
636 * @{
637 */
638
639/**
640 * \brief Describes the severity of a particular diagnostic.
641 */
642enum CXDiagnosticSeverity {
643 /**
Ted Kremenekd071c602010-03-13 02:50:34 +0000644 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000645 * option.
646 */
647 CXDiagnostic_Ignored = 0,
Ted Kremenekd071c602010-03-13 02:50:34 +0000648
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000649 /**
650 * \brief This diagnostic is a note that should be attached to the
651 * previous (non-note) diagnostic.
652 */
653 CXDiagnostic_Note = 1,
654
655 /**
656 * \brief This diagnostic indicates suspicious code that may not be
657 * wrong.
658 */
659 CXDiagnostic_Warning = 2,
660
661 /**
662 * \brief This diagnostic indicates that the code is ill-formed.
663 */
664 CXDiagnostic_Error = 3,
665
666 /**
667 * \brief This diagnostic indicates that the code is ill-formed such
668 * that future parser recovery is unlikely to produce useful
669 * results.
670 */
671 CXDiagnostic_Fatal = 4
672};
673
674/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000675 * \brief A single diagnostic, containing the diagnostic's severity,
676 * location, text, source ranges, and fix-it hints.
677 */
678typedef void *CXDiagnostic;
679
680/**
Ted Kremenekd010ba42011-11-10 08:43:12 +0000681 * \brief A group of CXDiagnostics.
682 */
683typedef void *CXDiagnosticSet;
684
685/**
686 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
687 */
688CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
689
690/**
691 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
692 *
James Dennett574cb4c2012-06-15 05:41:51 +0000693 * \param Diags the CXDiagnosticSet to query.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000694 * \param Index the zero-based diagnostic number to retrieve.
695 *
696 * \returns the requested diagnostic. This diagnostic must be freed
697 * via a call to \c clang_disposeDiagnostic().
698 */
699CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
700 unsigned Index);
701
702
703/**
704 * \brief Describes the kind of error that occurred (if any) in a call to
705 * \c clang_loadDiagnostics.
706 */
707enum CXLoadDiag_Error {
708 /**
709 * \brief Indicates that no error occurred.
710 */
711 CXLoadDiag_None = 0,
712
713 /**
714 * \brief Indicates that an unknown error occurred while attempting to
715 * deserialize diagnostics.
716 */
717 CXLoadDiag_Unknown = 1,
718
719 /**
720 * \brief Indicates that the file containing the serialized diagnostics
721 * could not be opened.
722 */
723 CXLoadDiag_CannotLoad = 2,
724
725 /**
726 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett574cb4c2012-06-15 05:41:51 +0000727 * corrupt.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000728 */
729 CXLoadDiag_InvalidFile = 3
730};
731
732/**
733 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett574cb4c2012-06-15 05:41:51 +0000734 * file.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000735 *
James Dennett574cb4c2012-06-15 05:41:51 +0000736 * \param file The name of the file to deserialize.
737 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenekd010ba42011-11-10 08:43:12 +0000738 * deserializing the diagnostics.
James Dennett574cb4c2012-06-15 05:41:51 +0000739 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenekd010ba42011-11-10 08:43:12 +0000740 * if the file was not successfully loaded.
741 *
742 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett574cb4c2012-06-15 05:41:51 +0000743 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenekd010ba42011-11-10 08:43:12 +0000744 */
745CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
746 enum CXLoadDiag_Error *error,
747 CXString *errorString);
748
749/**
750 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
751 */
752CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
753
754/**
James Dennett574cb4c2012-06-15 05:41:51 +0000755 * \brief Retrieve the child diagnostics of a CXDiagnostic.
756 *
757 * This CXDiagnosticSet does not need to be released by
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000758 * clang_disposeDiagnosticSet.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000759 */
760CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
761
762/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000763 * \brief Determine the number of diagnostics produced for the given
764 * translation unit.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000765 */
Douglas Gregor33cdd812010-02-18 18:08:43 +0000766CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
767
768/**
769 * \brief Retrieve a diagnostic associated with the given translation unit.
770 *
771 * \param Unit the translation unit to query.
772 * \param Index the zero-based diagnostic number to retrieve.
773 *
774 * \returns the requested diagnostic. This diagnostic must be freed
775 * via a call to \c clang_disposeDiagnostic().
776 */
777CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
778 unsigned Index);
779
780/**
Ted Kremenekb4a8b052011-12-09 22:28:32 +0000781 * \brief Retrieve the complete set of diagnostics associated with a
782 * translation unit.
783 *
784 * \param Unit the translation unit to query.
785 */
786CINDEX_LINKAGE CXDiagnosticSet
787 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
788
789/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000790 * \brief Destroy a diagnostic.
791 */
792CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000793
794/**
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000795 * \brief Options to control the display of diagnostics.
796 *
797 * The values in this enum are meant to be combined to customize the
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000798 * behavior of \c clang_formatDiagnostic().
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000799 */
800enum CXDiagnosticDisplayOptions {
801 /**
802 * \brief Display the source-location information where the
803 * diagnostic was located.
804 *
805 * When set, diagnostics will be prefixed by the file, line, and
806 * (optionally) column to which the diagnostic refers. For example,
807 *
808 * \code
809 * test.c:28: warning: extra tokens at end of #endif directive
810 * \endcode
811 *
812 * This option corresponds to the clang flag \c -fshow-source-location.
813 */
814 CXDiagnostic_DisplaySourceLocation = 0x01,
815
816 /**
817 * \brief If displaying the source-location information of the
818 * diagnostic, also include the column number.
819 *
820 * This option corresponds to the clang flag \c -fshow-column.
821 */
822 CXDiagnostic_DisplayColumn = 0x02,
823
824 /**
825 * \brief If displaying the source-location information of the
826 * diagnostic, also include information about source ranges in a
827 * machine-parsable format.
828 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000829 * This option corresponds to the clang flag
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000830 * \c -fdiagnostics-print-source-range-info.
831 */
Douglas Gregora750e8e2010-11-19 16:18:16 +0000832 CXDiagnostic_DisplaySourceRanges = 0x04,
833
834 /**
835 * \brief Display the option name associated with this diagnostic, if any.
836 *
837 * The option name displayed (e.g., -Wconversion) will be placed in brackets
838 * after the diagnostic text. This option corresponds to the clang flag
839 * \c -fdiagnostics-show-option.
840 */
841 CXDiagnostic_DisplayOption = 0x08,
842
843 /**
844 * \brief Display the category number associated with this diagnostic, if any.
845 *
846 * The category number is displayed within brackets after the diagnostic text.
847 * This option corresponds to the clang flag
848 * \c -fdiagnostics-show-category=id.
849 */
850 CXDiagnostic_DisplayCategoryId = 0x10,
851
852 /**
853 * \brief Display the category name associated with this diagnostic, if any.
854 *
855 * The category name is displayed within brackets after the diagnostic text.
856 * This option corresponds to the clang flag
857 * \c -fdiagnostics-show-category=name.
858 */
859 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000860};
861
862/**
Douglas Gregord770f732010-02-22 23:17:23 +0000863 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000864 *
Douglas Gregord770f732010-02-22 23:17:23 +0000865 * This routine will format the given diagnostic to a string, rendering
Ted Kremenekd071c602010-03-13 02:50:34 +0000866 * the diagnostic according to the various options given. The
867 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000868 * options that most closely mimics the behavior of the clang compiler.
869 *
870 * \param Diagnostic The diagnostic to print.
871 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000872 * \param Options A set of options that control the diagnostic display,
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000873 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregord770f732010-02-22 23:17:23 +0000874 *
875 * \returns A new string containing for formatted diagnostic.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000876 */
Douglas Gregord770f732010-02-22 23:17:23 +0000877CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
878 unsigned Options);
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000879
880/**
881 * \brief Retrieve the set of display options most similar to the
882 * default behavior of the clang compiler.
883 *
884 * \returns A set of display options suitable for use with \c
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000885 * clang_formatDiagnostic().
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000886 */
887CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
888
889/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000890 * \brief Determine the severity of the given diagnostic.
891 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000892CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000893clang_getDiagnosticSeverity(CXDiagnostic);
894
895/**
896 * \brief Retrieve the source location of the given diagnostic.
897 *
898 * This location is where Clang would print the caret ('^') when
899 * displaying the diagnostic on the command line.
900 */
901CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
902
903/**
904 * \brief Retrieve the text of the given diagnostic.
905 */
906CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000907
908/**
Douglas Gregora750e8e2010-11-19 16:18:16 +0000909 * \brief Retrieve the name of the command-line option that enabled this
910 * diagnostic.
911 *
912 * \param Diag The diagnostic to be queried.
913 *
914 * \param Disable If non-NULL, will be set to the option that disables this
915 * diagnostic (if any).
916 *
917 * \returns A string that contains the command-line option used to enable this
918 * warning, such as "-Wconversion" or "-pedantic".
919 */
920CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
921 CXString *Disable);
922
923/**
924 * \brief Retrieve the category number for this diagnostic.
925 *
926 * Diagnostics can be categorized into groups along with other, related
927 * diagnostics (e.g., diagnostics under the same warning flag). This routine
928 * retrieves the category number for the given diagnostic.
929 *
930 * \returns The number of the category that contains this diagnostic, or zero
931 * if this diagnostic is uncategorized.
932 */
933CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
934
935/**
Ted Kremenek26a6d492012-04-12 00:03:31 +0000936 * \brief Retrieve the name of a particular diagnostic category. This
937 * is now deprecated. Use clang_getDiagnosticCategoryText()
938 * instead.
Douglas Gregora750e8e2010-11-19 16:18:16 +0000939 *
940 * \param Category A diagnostic category number, as returned by
941 * \c clang_getDiagnosticCategory().
942 *
943 * \returns The name of the given diagnostic category.
944 */
Ted Kremenek26a6d492012-04-12 00:03:31 +0000945CINDEX_DEPRECATED CINDEX_LINKAGE
946CXString clang_getDiagnosticCategoryName(unsigned Category);
947
948/**
949 * \brief Retrieve the diagnostic category text for a given diagnostic.
950 *
Ted Kremenek26a6d492012-04-12 00:03:31 +0000951 * \returns The text of the given diagnostic category.
952 */
953CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregora750e8e2010-11-19 16:18:16 +0000954
955/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000956 * \brief Determine the number of source ranges associated with the given
957 * diagnostic.
958 */
959CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenekd071c602010-03-13 02:50:34 +0000960
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000961/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000962 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000963 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000964 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000965 * code. On the command line, Clang displays source ranges by
Ted Kremenekd071c602010-03-13 02:50:34 +0000966 * underlining them with '~' characters.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000967 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000968 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000969 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000970 * \param Range the zero-based index specifying which range to
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000971 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000972 * \returns the requested source range.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000973 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000974CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000975 unsigned Range);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000976
977/**
978 * \brief Determine the number of fix-it hints associated with the
979 * given diagnostic.
980 */
981CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
982
983/**
Douglas Gregor836ec942010-02-19 18:16:06 +0000984 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000985 *
Douglas Gregor836ec942010-02-19 18:16:06 +0000986 * Fix-its are described in terms of a source range whose contents
987 * should be replaced by a string. This approach generalizes over
988 * three kinds of operations: removal of source code (the range covers
989 * the code to be removed and the replacement string is empty),
990 * replacement of source code (the range covers the code to be
991 * replaced and the replacement string provides the new code), and
992 * insertion (both the start and end of the range point at the
993 * insertion location, and the replacement string provides the text to
994 * insert).
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000995 *
Douglas Gregor836ec942010-02-19 18:16:06 +0000996 * \param Diagnostic The diagnostic whose fix-its are being queried.
997 *
998 * \param FixIt The zero-based index of the fix-it.
999 *
1000 * \param ReplacementRange The source range whose contents will be
1001 * replaced with the returned replacement string. Note that source
1002 * ranges are half-open ranges [a, b), so the source code should be
1003 * replaced from a and up to (but not including) b.
1004 *
1005 * \returns A string containing text that should be replace the source
1006 * code indicated by the \c ReplacementRange.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001007 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001008CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor836ec942010-02-19 18:16:06 +00001009 unsigned FixIt,
1010 CXSourceRange *ReplacementRange);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001011
1012/**
1013 * @}
1014 */
1015
1016/**
1017 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
1018 *
1019 * The routines in this group provide the ability to create and destroy
1020 * translation units from files, either by parsing the contents of the files or
1021 * by reading in a serialized representation of a translation unit.
1022 *
1023 * @{
1024 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001025
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001026/**
1027 * \brief Get the original translation unit source file name.
1028 */
1029CINDEX_LINKAGE CXString
1030clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1031
1032/**
1033 * \brief Return the CXTranslationUnit for a given source file and the provided
1034 * command line arguments one would pass to the compiler.
1035 *
1036 * Note: The 'source_filename' argument is optional. If the caller provides a
1037 * NULL pointer, the name of the source file is expected to reside in the
1038 * specified command line arguments.
1039 *
1040 * Note: When encountered in 'clang_command_line_args', the following options
1041 * are ignored:
1042 *
1043 * '-c'
1044 * '-emit-ast'
1045 * '-fsyntax-only'
James Dennett574cb4c2012-06-15 05:41:51 +00001046 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001047 *
Ted Kremenekbd4972442010-11-08 04:28:51 +00001048 * \param CIdx The index object with which the translation unit will be
1049 * associated.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001050 *
James Dennett574cb4c2012-06-15 05:41:51 +00001051 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenekbd4972442010-11-08 04:28:51 +00001052 * source file is included in \p clang_command_line_args.
1053 *
1054 * \param num_clang_command_line_args The number of command-line arguments in
1055 * \p clang_command_line_args.
1056 *
1057 * \param clang_command_line_args The command-line arguments that would be
1058 * passed to the \c clang executable if it were being invoked out-of-process.
1059 * These command-line options will be parsed and will affect how the translation
1060 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001061 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001062 *
1063 * \param num_unsaved_files the number of unsaved file entries in \p
1064 * unsaved_files.
1065 *
1066 * \param unsaved_files the files that have not yet been saved to disk
1067 * but may be required for code completion, including the contents of
Ted Kremenekde24a942010-04-12 18:47:26 +00001068 * those files. The contents and name of these files (as specified by
1069 * CXUnsavedFile) are copied when necessary, so the client only needs to
1070 * guarantee their validity until the call to this function returns.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001071 */
1072CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1073 CXIndex CIdx,
1074 const char *source_filename,
1075 int num_clang_command_line_args,
Douglas Gregor57879fa2010-09-01 16:43:19 +00001076 const char * const *clang_command_line_args,
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001077 unsigned num_unsaved_files,
Douglas Gregor33cdd812010-02-18 18:08:43 +00001078 struct CXUnsavedFile *unsaved_files);
Ted Kremenekd071c602010-03-13 02:50:34 +00001079
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001080/**
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001081 * \brief Same as \c clang_createTranslationUnit2, but returns
1082 * the \c CXTranslationUnit instead of an error code. In case of an error this
1083 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1084 * error codes.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001085 */
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001086CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
1087 CXIndex CIdx,
1088 const char *ast_filename);
1089
1090/**
1091 * \brief Create a translation unit from an AST file (\c -emit-ast).
1092 *
1093 * \param[out] out_TU A non-NULL pointer to store the created
1094 * \c CXTranslationUnit.
1095 *
1096 * \returns Zero on success, otherwise returns an error code.
1097 */
1098CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2(
1099 CXIndex CIdx,
1100 const char *ast_filename,
1101 CXTranslationUnit *out_TU);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001102
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001103/**
1104 * \brief Flags that control the creation of translation units.
1105 *
1106 * The enumerators in this enumeration type are meant to be bitwise
1107 * ORed together to specify which options should be used when
1108 * constructing the translation unit.
1109 */
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001110enum CXTranslationUnit_Flags {
1111 /**
1112 * \brief Used to indicate that no special translation-unit options are
1113 * needed.
1114 */
1115 CXTranslationUnit_None = 0x0,
1116
1117 /**
1118 * \brief Used to indicate that the parser should construct a "detailed"
1119 * preprocessing record, including all macro definitions and instantiations.
1120 *
1121 * Constructing a detailed preprocessing record requires more memory
1122 * and time to parse, since the information contained in the record
1123 * is usually not retained. However, it can be useful for
1124 * applications that require more detailed information about the
1125 * behavior of the preprocessor.
1126 */
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001127 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1128
1129 /**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001130 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001131 *
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001132 * When a translation unit is considered "incomplete", semantic
1133 * analysis that is typically performed at the end of the
1134 * translation unit will be suppressed. For example, this suppresses
1135 * the completion of tentative declarations in C and of
1136 * instantiation of implicitly-instantiation function templates in
1137 * C++. This option is typically used when parsing a header with the
1138 * intent of producing a precompiled header.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001139 */
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001140 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001141
1142 /**
1143 * \brief Used to indicate that the translation unit should be built with an
1144 * implicit precompiled header for the preamble.
1145 *
1146 * An implicit precompiled header is used as an optimization when a
1147 * particular translation unit is likely to be reparsed many times
1148 * when the sources aren't changing that often. In this case, an
1149 * implicit precompiled header will be built containing all of the
1150 * initial includes at the top of the main file (what we refer to as
1151 * the "preamble" of the file). In subsequent parses, if the
1152 * preamble or the files in it have not changed, \c
1153 * clang_reparseTranslationUnit() will re-use the implicit
1154 * precompiled header to improve parsing performance.
1155 */
Douglas Gregorde051182010-08-11 15:58:42 +00001156 CXTranslationUnit_PrecompiledPreamble = 0x04,
1157
1158 /**
1159 * \brief Used to indicate that the translation unit should cache some
1160 * code-completion results with each reparse of the source file.
1161 *
1162 * Caching of code-completion results is a performance optimization that
1163 * introduces some overhead to reparsing but improves the performance of
1164 * code-completion operations.
1165 */
Douglas Gregorf5a18542010-10-27 17:24:53 +00001166 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001167
Douglas Gregorf5a18542010-10-27 17:24:53 +00001168 /**
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001169 * \brief Used to indicate that the translation unit will be serialized with
1170 * \c clang_saveTranslationUnit.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001171 *
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001172 * This option is typically used when parsing a header with the intent of
1173 * producing a precompiled header.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001174 */
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001175 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregorf5a18542010-10-27 17:24:53 +00001176
1177 /**
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001178 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001179 *
1180 * Note: this is a *temporary* option that is available only while
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001181 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001182 */
Erik Verbruggen6e922512012-04-12 10:11:59 +00001183 CXTranslationUnit_CXXChainedPCH = 0x20,
1184
1185 /**
1186 * \brief Used to indicate that function/method bodies should be skipped while
1187 * parsing.
1188 *
1189 * This option can be used to search for declarations/definitions while
1190 * ignoring the usages.
1191 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00001192 CXTranslationUnit_SkipFunctionBodies = 0x40,
1193
1194 /**
1195 * \brief Used to indicate that brief documentation comments should be
1196 * included into the set of code completions returned from this translation
1197 * unit.
1198 */
1199 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001200};
1201
1202/**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001203 * \brief Returns the set of flags that is suitable for parsing a translation
1204 * unit that is being edited.
1205 *
1206 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1207 * to indicate that the translation unit is likely to be reparsed many times,
1208 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1209 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1210 * set contains an unspecified set of optimizations (e.g., the precompiled
1211 * preamble) geared toward improving the performance of these routines. The
1212 * set of optimizations enabled may change from one version to the next.
1213 */
Douglas Gregorde051182010-08-11 15:58:42 +00001214CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001215
1216/**
1217 * \brief Same as \c clang_parseTranslationUnit2, but returns
1218 * the \c CXTranslationUnit instead of an error code. In case of an error this
1219 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1220 * error codes.
1221 */
1222CINDEX_LINKAGE CXTranslationUnit
1223clang_parseTranslationUnit(CXIndex CIdx,
1224 const char *source_filename,
1225 const char *const *command_line_args,
1226 int num_command_line_args,
1227 struct CXUnsavedFile *unsaved_files,
1228 unsigned num_unsaved_files,
1229 unsigned options);
1230
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001231/**
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001232 * \brief Parse the given source file and the translation unit corresponding
1233 * to that file.
1234 *
1235 * This routine is the main entry point for the Clang C API, providing the
1236 * ability to parse a source file into a translation unit that can then be
1237 * queried by other functions in the API. This routine accepts a set of
1238 * command-line arguments so that the compilation can be configured in the same
1239 * way that the compiler is configured on the command line.
1240 *
1241 * \param CIdx The index object with which the translation unit will be
1242 * associated.
1243 *
1244 * \param source_filename The name of the source file to load, or NULL if the
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001245 * source file is included in \c command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001246 *
1247 * \param command_line_args The command-line arguments that would be
1248 * passed to the \c clang executable if it were being invoked out-of-process.
1249 * These command-line options will be parsed and will affect how the translation
1250 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001251 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001252 *
1253 * \param num_command_line_args The number of command-line arguments in
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001254 * \c command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001255 *
1256 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor8e984da2010-08-04 16:47:14 +00001257 * but may be required for parsing, including the contents of
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001258 * those files. The contents and name of these files (as specified by
1259 * CXUnsavedFile) are copied when necessary, so the client only needs to
1260 * guarantee their validity until the call to this function returns.
1261 *
1262 * \param num_unsaved_files the number of unsaved file entries in \p
1263 * unsaved_files.
1264 *
1265 * \param options A bitmask of options that affects how the translation unit
1266 * is managed but not its compilation. This should be a bitwise OR of the
1267 * CXTranslationUnit_XXX flags.
1268 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001269 * \param[out] out_TU A non-NULL pointer to store the created
1270 * \c CXTranslationUnit, describing the parsed code and containing any
1271 * diagnostics produced by the compiler.
1272 *
1273 * \returns Zero on success, otherwise returns an error code.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001274 */
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001275CINDEX_LINKAGE enum CXErrorCode
1276clang_parseTranslationUnit2(CXIndex CIdx,
1277 const char *source_filename,
1278 const char *const *command_line_args,
1279 int num_command_line_args,
1280 struct CXUnsavedFile *unsaved_files,
1281 unsigned num_unsaved_files,
1282 unsigned options,
1283 CXTranslationUnit *out_TU);
1284
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001285/**
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001286 * \brief Flags that control how translation units are saved.
1287 *
1288 * The enumerators in this enumeration type are meant to be bitwise
1289 * ORed together to specify which options should be used when
1290 * saving the translation unit.
1291 */
1292enum CXSaveTranslationUnit_Flags {
1293 /**
1294 * \brief Used to indicate that no special saving options are needed.
1295 */
1296 CXSaveTranslationUnit_None = 0x0
1297};
1298
1299/**
1300 * \brief Returns the set of flags that is suitable for saving a translation
1301 * unit.
1302 *
1303 * The set of flags returned provide options for
1304 * \c clang_saveTranslationUnit() by default. The returned flag
1305 * set contains an unspecified set of options that save translation units with
1306 * the most commonly-requested data.
1307 */
1308CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1309
1310/**
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001311 * \brief Describes the kind of error that occurred (if any) in a call to
1312 * \c clang_saveTranslationUnit().
1313 */
1314enum CXSaveError {
1315 /**
1316 * \brief Indicates that no error occurred while saving a translation unit.
1317 */
1318 CXSaveError_None = 0,
1319
1320 /**
1321 * \brief Indicates that an unknown error occurred while attempting to save
1322 * the file.
1323 *
1324 * This error typically indicates that file I/O failed when attempting to
1325 * write the file.
1326 */
1327 CXSaveError_Unknown = 1,
1328
1329 /**
1330 * \brief Indicates that errors during translation prevented this attempt
1331 * to save the translation unit.
1332 *
1333 * Errors that prevent the translation unit from being saved can be
1334 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1335 */
1336 CXSaveError_TranslationErrors = 2,
1337
1338 /**
1339 * \brief Indicates that the translation unit to be saved was somehow
1340 * invalid (e.g., NULL).
1341 */
1342 CXSaveError_InvalidTU = 3
1343};
1344
1345/**
Douglas Gregore9386682010-08-13 05:36:37 +00001346 * \brief Saves a translation unit into a serialized representation of
1347 * that translation unit on disk.
1348 *
1349 * Any translation unit that was parsed without error can be saved
1350 * into a file. The translation unit can then be deserialized into a
1351 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1352 * if it is an incomplete translation unit that corresponds to a
1353 * header, used as a precompiled header when parsing other translation
1354 * units.
1355 *
1356 * \param TU The translation unit to save.
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001357 *
Douglas Gregore9386682010-08-13 05:36:37 +00001358 * \param FileName The file to which the translation unit will be saved.
1359 *
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001360 * \param options A bitmask of options that affects how the translation unit
1361 * is saved. This should be a bitwise OR of the
1362 * CXSaveTranslationUnit_XXX flags.
1363 *
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001364 * \returns A value that will match one of the enumerators of the CXSaveError
1365 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1366 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregore9386682010-08-13 05:36:37 +00001367 */
1368CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001369 const char *FileName,
1370 unsigned options);
Douglas Gregore9386682010-08-13 05:36:37 +00001371
1372/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001373 * \brief Destroy the specified CXTranslationUnit object.
1374 */
1375CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenekd071c602010-03-13 02:50:34 +00001376
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001377/**
Douglas Gregorde051182010-08-11 15:58:42 +00001378 * \brief Flags that control the reparsing of translation units.
1379 *
1380 * The enumerators in this enumeration type are meant to be bitwise
1381 * ORed together to specify which options should be used when
1382 * reparsing the translation unit.
1383 */
1384enum CXReparse_Flags {
1385 /**
1386 * \brief Used to indicate that no special reparsing options are needed.
1387 */
1388 CXReparse_None = 0x0
1389};
1390
1391/**
1392 * \brief Returns the set of flags that is suitable for reparsing a translation
1393 * unit.
1394 *
1395 * The set of flags returned provide options for
1396 * \c clang_reparseTranslationUnit() by default. The returned flag
1397 * set contains an unspecified set of optimizations geared toward common uses
1398 * of reparsing. The set of optimizations enabled may change from one version
1399 * to the next.
1400 */
1401CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1402
1403/**
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001404 * \brief Reparse the source files that produced this translation unit.
1405 *
1406 * This routine can be used to re-parse the source files that originally
1407 * created the given translation unit, for example because those source files
1408 * have changed (either on disk or as passed via \p unsaved_files). The
1409 * source code will be reparsed with the same command-line options as it
1410 * was originally parsed.
1411 *
1412 * Reparsing a translation unit invalidates all cursors and source locations
1413 * that refer into that translation unit. This makes reparsing a translation
1414 * unit semantically equivalent to destroying the translation unit and then
1415 * creating a new translation unit with the same command-line arguments.
1416 * However, it may be more efficient to reparse a translation
1417 * unit using this routine.
1418 *
1419 * \param TU The translation unit whose contents will be re-parsed. The
1420 * translation unit must originally have been built with
1421 * \c clang_createTranslationUnitFromSourceFile().
1422 *
1423 * \param num_unsaved_files The number of unsaved file entries in \p
1424 * unsaved_files.
1425 *
1426 * \param unsaved_files The files that have not yet been saved to disk
1427 * but may be required for parsing, including the contents of
1428 * those files. The contents and name of these files (as specified by
1429 * CXUnsavedFile) are copied when necessary, so the client only needs to
1430 * guarantee their validity until the call to this function returns.
1431 *
Douglas Gregorde051182010-08-11 15:58:42 +00001432 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1433 * The function \c clang_defaultReparseOptions() produces a default set of
1434 * options recommended for most uses, based on the translation unit.
1435 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001436 * \returns 0 if the sources could be reparsed. A non-zero error code will be
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001437 * returned if reparsing was impossible, such that the translation unit is
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001438 * invalid. In such cases, the only valid call for \c TU is
1439 * \c clang_disposeTranslationUnit(TU). The error codes returned by this
1440 * routine are described by the \c CXErrorCode enum.
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001441 */
1442CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1443 unsigned num_unsaved_files,
Douglas Gregorde051182010-08-11 15:58:42 +00001444 struct CXUnsavedFile *unsaved_files,
1445 unsigned options);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001446
1447/**
1448 * \brief Categorizes how memory is being used by a translation unit.
1449 */
Ted Kremenek23324122011-04-20 16:41:07 +00001450enum CXTUResourceUsageKind {
1451 CXTUResourceUsage_AST = 1,
1452 CXTUResourceUsage_Identifiers = 2,
1453 CXTUResourceUsage_Selectors = 3,
1454 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek21735e62011-04-28 04:10:31 +00001455 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekf5df0ce2011-04-28 04:53:38 +00001456 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenek8d587902011-04-28 20:36:42 +00001457 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremenek5e1ed7b2011-04-28 23:46:20 +00001458 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1459 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1460 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek2160a0d2011-05-04 01:38:46 +00001461 CXTUResourceUsage_Preprocessor = 11,
1462 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenek120992a2011-07-26 23:46:06 +00001463 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001464 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenek23324122011-04-20 16:41:07 +00001465 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1466 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001467 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenek23324122011-04-20 16:41:07 +00001468
1469 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001470 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek83f642e2011-04-18 22:47:10 +00001471};
1472
1473/**
1474 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenek23324122011-04-20 16:41:07 +00001475 * the name of the memory category. This string should never be freed.
Ted Kremenek83f642e2011-04-18 22:47:10 +00001476 */
1477CINDEX_LINKAGE
Ted Kremenek23324122011-04-20 16:41:07 +00001478const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001479
Ted Kremenek23324122011-04-20 16:41:07 +00001480typedef struct CXTUResourceUsageEntry {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001481 /* \brief The memory usage category. */
Ted Kremenek23324122011-04-20 16:41:07 +00001482 enum CXTUResourceUsageKind kind;
1483 /* \brief Amount of resources used.
1484 The units will depend on the resource kind. */
Ted Kremenek83f642e2011-04-18 22:47:10 +00001485 unsigned long amount;
Ted Kremenek23324122011-04-20 16:41:07 +00001486} CXTUResourceUsageEntry;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001487
1488/**
1489 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1490 */
Ted Kremenek23324122011-04-20 16:41:07 +00001491typedef struct CXTUResourceUsage {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001492 /* \brief Private data member, used for queries. */
1493 void *data;
1494
1495 /* \brief The number of entries in the 'entries' array. */
1496 unsigned numEntries;
1497
1498 /* \brief An array of key-value pairs, representing the breakdown of memory
1499 usage. */
Ted Kremenek23324122011-04-20 16:41:07 +00001500 CXTUResourceUsageEntry *entries;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001501
Ted Kremenek23324122011-04-20 16:41:07 +00001502} CXTUResourceUsage;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001503
1504/**
1505 * \brief Return the memory usage of a translation unit. This object
Ted Kremenek23324122011-04-20 16:41:07 +00001506 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek83f642e2011-04-18 22:47:10 +00001507 */
Ted Kremenek23324122011-04-20 16:41:07 +00001508CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001509
Ted Kremenek23324122011-04-20 16:41:07 +00001510CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001511
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001512/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001513 * @}
1514 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001515
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001516/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001517 * \brief Describes the kind of entity that a cursor refers to.
1518 */
1519enum CXCursorKind {
1520 /* Declarations */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001521 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001522 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001523 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001524 *
1525 * Unexposed declarations have the same operations as any other kind
1526 * of declaration; one can extract their location information,
1527 * spelling, find their definitions, etc. However, the specific kind
1528 * of the declaration is not reported.
1529 */
1530 CXCursor_UnexposedDecl = 1,
1531 /** \brief A C or C++ struct. */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001532 CXCursor_StructDecl = 2,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001533 /** \brief A C or C++ union. */
1534 CXCursor_UnionDecl = 3,
1535 /** \brief A C++ class. */
1536 CXCursor_ClassDecl = 4,
1537 /** \brief An enumeration. */
1538 CXCursor_EnumDecl = 5,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001539 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001540 * \brief A field (in C) or non-static data member (in C++) in a
1541 * struct, union, or C++ class.
1542 */
1543 CXCursor_FieldDecl = 6,
1544 /** \brief An enumerator constant. */
1545 CXCursor_EnumConstantDecl = 7,
1546 /** \brief A function. */
1547 CXCursor_FunctionDecl = 8,
1548 /** \brief A variable. */
1549 CXCursor_VarDecl = 9,
1550 /** \brief A function or method parameter. */
1551 CXCursor_ParmDecl = 10,
James Dennett1355bd12012-06-11 06:19:40 +00001552 /** \brief An Objective-C \@interface. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001553 CXCursor_ObjCInterfaceDecl = 11,
James Dennett1355bd12012-06-11 06:19:40 +00001554 /** \brief An Objective-C \@interface for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001555 CXCursor_ObjCCategoryDecl = 12,
James Dennett1355bd12012-06-11 06:19:40 +00001556 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001557 CXCursor_ObjCProtocolDecl = 13,
James Dennett1355bd12012-06-11 06:19:40 +00001558 /** \brief An Objective-C \@property declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001559 CXCursor_ObjCPropertyDecl = 14,
1560 /** \brief An Objective-C instance variable. */
1561 CXCursor_ObjCIvarDecl = 15,
1562 /** \brief An Objective-C instance method. */
1563 CXCursor_ObjCInstanceMethodDecl = 16,
1564 /** \brief An Objective-C class method. */
1565 CXCursor_ObjCClassMethodDecl = 17,
James Dennett1355bd12012-06-11 06:19:40 +00001566 /** \brief An Objective-C \@implementation. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001567 CXCursor_ObjCImplementationDecl = 18,
James Dennett1355bd12012-06-11 06:19:40 +00001568 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001569 CXCursor_ObjCCategoryImplDecl = 19,
1570 /** \brief A typedef */
1571 CXCursor_TypedefDecl = 20,
Ted Kremenek225b8e32010-04-13 23:39:06 +00001572 /** \brief A C++ class method. */
1573 CXCursor_CXXMethod = 21,
Ted Kremenekbd67fb22010-05-06 23:38:21 +00001574 /** \brief A C++ namespace. */
1575 CXCursor_Namespace = 22,
Ted Kremenekb80cba52010-05-07 01:04:29 +00001576 /** \brief A linkage specification, e.g. 'extern "C"'. */
1577 CXCursor_LinkageSpec = 23,
Douglas Gregor12bca222010-08-31 14:41:23 +00001578 /** \brief A C++ constructor. */
1579 CXCursor_Constructor = 24,
1580 /** \brief A C++ destructor. */
1581 CXCursor_Destructor = 25,
1582 /** \brief A C++ conversion function. */
1583 CXCursor_ConversionFunction = 26,
Douglas Gregor713602b2010-08-31 17:01:39 +00001584 /** \brief A C++ template type parameter. */
1585 CXCursor_TemplateTypeParameter = 27,
1586 /** \brief A C++ non-type template parameter. */
1587 CXCursor_NonTypeTemplateParameter = 28,
1588 /** \brief A C++ template template parameter. */
1589 CXCursor_TemplateTemplateParameter = 29,
1590 /** \brief A C++ function template. */
1591 CXCursor_FunctionTemplate = 30,
Douglas Gregor1fbaeb12010-08-31 19:02:00 +00001592 /** \brief A C++ class template. */
1593 CXCursor_ClassTemplate = 31,
Douglas Gregorf96abb22010-08-31 19:31:58 +00001594 /** \brief A C++ class template partial specialization. */
1595 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregora89314e2010-08-31 23:48:11 +00001596 /** \brief A C++ namespace alias declaration. */
1597 CXCursor_NamespaceAlias = 33,
Douglas Gregor01a430132010-09-01 03:07:18 +00001598 /** \brief A C++ using directive. */
1599 CXCursor_UsingDirective = 34,
Richard Smithdda56e42011-04-15 14:24:37 +00001600 /** \brief A C++ using declaration. */
Douglas Gregora9aa29c2010-09-01 19:52:22 +00001601 CXCursor_UsingDeclaration = 35,
Richard Smithdda56e42011-04-15 14:24:37 +00001602 /** \brief A C++ alias declaration */
1603 CXCursor_TypeAliasDecl = 36,
James Dennett574cb4c2012-06-15 05:41:51 +00001604 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001605 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett574cb4c2012-06-15 05:41:51 +00001606 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001607 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001608 /** \brief An access specifier. */
1609 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor4c362d52011-10-05 19:00:14 +00001610
Ted Kremenek08de5c12010-05-19 21:51:10 +00001611 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001612 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001613
Douglas Gregor6007cf22010-01-22 22:29:16 +00001614 /* References */
1615 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001616 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001617 CXCursor_ObjCProtocolRef = 41,
1618 CXCursor_ObjCClassRef = 42,
1619 /**
1620 * \brief A reference to a type declaration.
1621 *
1622 * A type reference occurs anywhere where a type is named but not
1623 * declared. For example, given:
1624 *
1625 * \code
1626 * typedef unsigned size_type;
1627 * size_type size;
1628 * \endcode
1629 *
1630 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1631 * while the type of the variable "size" is referenced. The cursor
1632 * referenced by the type of size is the typedef for size_type.
1633 */
1634 CXCursor_TypeRef = 43,
Ted Kremenekae9e2212010-08-27 21:34:58 +00001635 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregora23e8f72010-08-31 20:37:03 +00001636 /**
Douglas Gregorf3af3112010-09-09 21:42:20 +00001637 * \brief A reference to a class template, function template, template
1638 * template parameter, or class template partial specialization.
Douglas Gregora23e8f72010-08-31 20:37:03 +00001639 */
1640 CXCursor_TemplateRef = 45,
Douglas Gregora89314e2010-08-31 23:48:11 +00001641 /**
1642 * \brief A reference to a namespace or namespace alias.
1643 */
1644 CXCursor_NamespaceRef = 46,
Douglas Gregorf3af3112010-09-09 21:42:20 +00001645 /**
Douglas Gregora93ab662010-09-10 00:22:18 +00001646 * \brief A reference to a member of a struct, union, or class that occurs in
1647 * some non-expression context, e.g., a designated initializer.
Douglas Gregorf3af3112010-09-09 21:42:20 +00001648 */
1649 CXCursor_MemberRef = 47,
Douglas Gregora93ab662010-09-10 00:22:18 +00001650 /**
1651 * \brief A reference to a labeled statement.
1652 *
1653 * This cursor kind is used to describe the jump to "start_over" in the
1654 * goto statement in the following example:
1655 *
1656 * \code
1657 * start_over:
1658 * ++counter;
1659 *
1660 * goto start_over;
1661 * \endcode
1662 *
1663 * A label reference cursor refers to a label statement.
1664 */
1665 CXCursor_LabelRef = 48,
1666
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00001667 /**
1668 * \brief A reference to a set of overloaded functions or function templates
1669 * that has not yet been resolved to a specific function or function template.
1670 *
1671 * An overloaded declaration reference cursor occurs in C++ templates where
1672 * a dependent name refers to a function. For example:
1673 *
1674 * \code
1675 * template<typename T> void swap(T&, T&);
1676 *
1677 * struct X { ... };
1678 * void swap(X&, X&);
1679 *
1680 * template<typename T>
1681 * void reverse(T* first, T* last) {
1682 * while (first < last - 1) {
1683 * swap(*first, *--last);
1684 * ++first;
1685 * }
1686 * }
1687 *
1688 * struct Y { };
1689 * void swap(Y&, Y&);
1690 * \endcode
1691 *
1692 * Here, the identifier "swap" is associated with an overloaded declaration
1693 * reference. In the template definition, "swap" refers to either of the two
1694 * "swap" functions declared above, so both results will be available. At
1695 * instantiation time, "swap" may also refer to other functions found via
1696 * argument-dependent lookup (e.g., the "swap" function at the end of the
1697 * example).
1698 *
1699 * The functions \c clang_getNumOverloadedDecls() and
1700 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1701 * referenced by this cursor.
1702 */
1703 CXCursor_OverloadedDeclRef = 49,
1704
Douglas Gregor30093832012-02-15 00:54:55 +00001705 /**
1706 * \brief A reference to a variable that occurs in some non-expression
1707 * context, e.g., a C++ lambda capture list.
1708 */
1709 CXCursor_VariableRef = 50,
1710
1711 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001712
Douglas Gregor6007cf22010-01-22 22:29:16 +00001713 /* Error conditions */
1714 CXCursor_FirstInvalid = 70,
1715 CXCursor_InvalidFile = 70,
1716 CXCursor_NoDeclFound = 71,
1717 CXCursor_NotImplemented = 72,
Ted Kremeneke184ac52010-03-19 20:39:03 +00001718 CXCursor_InvalidCode = 73,
1719 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001720
Douglas Gregor6007cf22010-01-22 22:29:16 +00001721 /* Expressions */
1722 CXCursor_FirstExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001723
Douglas Gregor6007cf22010-01-22 22:29:16 +00001724 /**
1725 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001726 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001727 *
1728 * Unexposed expressions have the same operations as any other kind
1729 * of expression; one can extract their location information,
1730 * spelling, children, etc. However, the specific kind of the
1731 * expression is not reported.
1732 */
1733 CXCursor_UnexposedExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001734
Douglas Gregor6007cf22010-01-22 22:29:16 +00001735 /**
1736 * \brief An expression that refers to some value declaration, such
1737 * as a function, varible, or enumerator.
1738 */
1739 CXCursor_DeclRefExpr = 101,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001740
Douglas Gregor6007cf22010-01-22 22:29:16 +00001741 /**
1742 * \brief An expression that refers to a member of a struct, union,
1743 * class, Objective-C class, etc.
1744 */
1745 CXCursor_MemberRefExpr = 102,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001746
Douglas Gregor6007cf22010-01-22 22:29:16 +00001747 /** \brief An expression that calls a function. */
1748 CXCursor_CallExpr = 103,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001749
Douglas Gregor6007cf22010-01-22 22:29:16 +00001750 /** \brief An expression that sends a message to an Objective-C
1751 object or class. */
1752 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek33b9a422010-04-11 21:47:37 +00001753
1754 /** \brief An expression that represents a block literal. */
1755 CXCursor_BlockExpr = 105,
1756
Douglas Gregor4c362d52011-10-05 19:00:14 +00001757 /** \brief An integer literal.
1758 */
1759 CXCursor_IntegerLiteral = 106,
1760
1761 /** \brief A floating point number literal.
1762 */
1763 CXCursor_FloatingLiteral = 107,
1764
1765 /** \brief An imaginary number literal.
1766 */
1767 CXCursor_ImaginaryLiteral = 108,
1768
1769 /** \brief A string literal.
1770 */
1771 CXCursor_StringLiteral = 109,
1772
1773 /** \brief A character literal.
1774 */
1775 CXCursor_CharacterLiteral = 110,
1776
1777 /** \brief A parenthesized expression, e.g. "(1)".
1778 *
1779 * This AST node is only formed if full location information is requested.
1780 */
1781 CXCursor_ParenExpr = 111,
1782
1783 /** \brief This represents the unary-expression's (except sizeof and
1784 * alignof).
1785 */
1786 CXCursor_UnaryOperator = 112,
1787
1788 /** \brief [C99 6.5.2.1] Array Subscripting.
1789 */
1790 CXCursor_ArraySubscriptExpr = 113,
1791
1792 /** \brief A builtin binary operation expression such as "x + y" or
1793 * "x <= y".
1794 */
1795 CXCursor_BinaryOperator = 114,
1796
1797 /** \brief Compound assignment such as "+=".
1798 */
1799 CXCursor_CompoundAssignOperator = 115,
1800
1801 /** \brief The ?: ternary operator.
1802 */
1803 CXCursor_ConditionalOperator = 116,
1804
1805 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1806 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1807 *
1808 * For example: (int)f.
1809 */
1810 CXCursor_CStyleCastExpr = 117,
1811
1812 /** \brief [C99 6.5.2.5]
1813 */
1814 CXCursor_CompoundLiteralExpr = 118,
1815
1816 /** \brief Describes an C or C++ initializer list.
1817 */
1818 CXCursor_InitListExpr = 119,
1819
1820 /** \brief The GNU address of label extension, representing &&label.
1821 */
1822 CXCursor_AddrLabelExpr = 120,
1823
1824 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1825 */
1826 CXCursor_StmtExpr = 121,
1827
Benjamin Kramere56f3932011-12-23 17:00:35 +00001828 /** \brief Represents a C11 generic selection.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001829 */
1830 CXCursor_GenericSelectionExpr = 122,
1831
1832 /** \brief Implements the GNU __null extension, which is a name for a null
1833 * pointer constant that has integral type (e.g., int or long) and is the same
1834 * size and alignment as a pointer.
1835 *
1836 * The __null extension is typically only used by system headers, which define
1837 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1838 * match the size of a pointer).
1839 */
1840 CXCursor_GNUNullExpr = 123,
1841
1842 /** \brief C++'s static_cast<> expression.
1843 */
1844 CXCursor_CXXStaticCastExpr = 124,
1845
1846 /** \brief C++'s dynamic_cast<> expression.
1847 */
1848 CXCursor_CXXDynamicCastExpr = 125,
1849
1850 /** \brief C++'s reinterpret_cast<> expression.
1851 */
1852 CXCursor_CXXReinterpretCastExpr = 126,
1853
1854 /** \brief C++'s const_cast<> expression.
1855 */
1856 CXCursor_CXXConstCastExpr = 127,
1857
1858 /** \brief Represents an explicit C++ type conversion that uses "functional"
1859 * notion (C++ [expr.type.conv]).
1860 *
1861 * Example:
1862 * \code
1863 * x = int(0.5);
1864 * \endcode
1865 */
1866 CXCursor_CXXFunctionalCastExpr = 128,
1867
1868 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1869 */
1870 CXCursor_CXXTypeidExpr = 129,
1871
1872 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1873 */
1874 CXCursor_CXXBoolLiteralExpr = 130,
1875
1876 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1877 */
1878 CXCursor_CXXNullPtrLiteralExpr = 131,
1879
1880 /** \brief Represents the "this" expression in C++
1881 */
1882 CXCursor_CXXThisExpr = 132,
1883
1884 /** \brief [C++ 15] C++ Throw Expression.
1885 *
1886 * This handles 'throw' and 'throw' assignment-expression. When
1887 * assignment-expression isn't present, Op will be null.
1888 */
1889 CXCursor_CXXThrowExpr = 133,
1890
1891 /** \brief A new expression for memory allocation and constructor calls, e.g:
1892 * "new CXXNewExpr(foo)".
1893 */
1894 CXCursor_CXXNewExpr = 134,
1895
1896 /** \brief A delete expression for memory deallocation and destructor calls,
1897 * e.g. "delete[] pArray".
1898 */
1899 CXCursor_CXXDeleteExpr = 135,
1900
1901 /** \brief A unary expression.
1902 */
1903 CXCursor_UnaryExpr = 136,
1904
Douglas Gregor910c37c2011-11-11 22:35:18 +00001905 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor4c362d52011-10-05 19:00:14 +00001906 */
1907 CXCursor_ObjCStringLiteral = 137,
1908
James Dennett574cb4c2012-06-15 05:41:51 +00001909 /** \brief An Objective-C \@encode expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001910 */
1911 CXCursor_ObjCEncodeExpr = 138,
1912
James Dennett574cb4c2012-06-15 05:41:51 +00001913 /** \brief An Objective-C \@selector expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001914 */
1915 CXCursor_ObjCSelectorExpr = 139,
1916
James Dennett1355bd12012-06-11 06:19:40 +00001917 /** \brief An Objective-C \@protocol expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001918 */
1919 CXCursor_ObjCProtocolExpr = 140,
1920
1921 /** \brief An Objective-C "bridged" cast expression, which casts between
1922 * Objective-C pointers and C pointers, transferring ownership in the process.
1923 *
1924 * \code
1925 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1926 * \endcode
1927 */
1928 CXCursor_ObjCBridgedCastExpr = 141,
1929
1930 /** \brief Represents a C++0x pack expansion that produces a sequence of
1931 * expressions.
1932 *
1933 * A pack expansion expression contains a pattern (which itself is an
1934 * expression) followed by an ellipsis. For example:
1935 *
1936 * \code
1937 * template<typename F, typename ...Types>
1938 * void forward(F f, Types &&...args) {
1939 * f(static_cast<Types&&>(args)...);
1940 * }
1941 * \endcode
1942 */
1943 CXCursor_PackExpansionExpr = 142,
1944
1945 /** \brief Represents an expression that computes the length of a parameter
1946 * pack.
1947 *
1948 * \code
1949 * template<typename ...Types>
1950 * struct count {
1951 * static const unsigned value = sizeof...(Types);
1952 * };
1953 * \endcode
1954 */
1955 CXCursor_SizeOfPackExpr = 143,
1956
Douglas Gregor30093832012-02-15 00:54:55 +00001957 /* \brief Represents a C++ lambda expression that produces a local function
1958 * object.
1959 *
1960 * \code
1961 * void abssort(float *x, unsigned N) {
1962 * std::sort(x, x + N,
1963 * [](float a, float b) {
1964 * return std::abs(a) < std::abs(b);
1965 * });
1966 * }
1967 * \endcode
1968 */
1969 CXCursor_LambdaExpr = 144,
1970
Ted Kremenek77006f62012-03-06 20:06:06 +00001971 /** \brief Objective-c Boolean Literal.
1972 */
1973 CXCursor_ObjCBoolLiteralExpr = 145,
1974
Argyrios Kyrtzidisc2233be2013-04-23 17:57:17 +00001975 /** \brief Represents the "self" expression in a ObjC method.
1976 */
1977 CXCursor_ObjCSelfExpr = 146,
1978
1979 CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001980
Douglas Gregor6007cf22010-01-22 22:29:16 +00001981 /* Statements */
1982 CXCursor_FirstStmt = 200,
1983 /**
1984 * \brief A statement whose specific kind is not exposed via this
1985 * interface.
1986 *
1987 * Unexposed statements have the same operations as any other kind of
1988 * statement; one can extract their location information, spelling,
1989 * children, etc. However, the specific kind of the statement is not
1990 * reported.
1991 */
1992 CXCursor_UnexposedStmt = 200,
Douglas Gregora93ab662010-09-10 00:22:18 +00001993
1994 /** \brief A labelled statement in a function.
1995 *
1996 * This cursor kind is used to describe the "start_over:" label statement in
1997 * the following example:
1998 *
1999 * \code
2000 * start_over:
2001 * ++counter;
2002 * \endcode
2003 *
2004 */
2005 CXCursor_LabelStmt = 201,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002006
2007 /** \brief A group of statements like { stmt stmt }.
2008 *
2009 * This cursor kind is used to describe compound statements, e.g. function
2010 * bodies.
2011 */
2012 CXCursor_CompoundStmt = 202,
2013
Benjamin Kramer2501f142013-10-20 11:47:15 +00002014 /** \brief A case statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002015 */
2016 CXCursor_CaseStmt = 203,
2017
2018 /** \brief A default statement.
2019 */
2020 CXCursor_DefaultStmt = 204,
2021
2022 /** \brief An if statement
2023 */
2024 CXCursor_IfStmt = 205,
2025
2026 /** \brief A switch statement.
2027 */
2028 CXCursor_SwitchStmt = 206,
2029
2030 /** \brief A while statement.
2031 */
2032 CXCursor_WhileStmt = 207,
2033
2034 /** \brief A do statement.
2035 */
2036 CXCursor_DoStmt = 208,
2037
2038 /** \brief A for statement.
2039 */
2040 CXCursor_ForStmt = 209,
2041
2042 /** \brief A goto statement.
2043 */
2044 CXCursor_GotoStmt = 210,
2045
2046 /** \brief An indirect goto statement.
2047 */
2048 CXCursor_IndirectGotoStmt = 211,
2049
2050 /** \brief A continue statement.
2051 */
2052 CXCursor_ContinueStmt = 212,
2053
2054 /** \brief A break statement.
2055 */
2056 CXCursor_BreakStmt = 213,
2057
2058 /** \brief A return statement.
2059 */
2060 CXCursor_ReturnStmt = 214,
2061
Chad Rosierde70e0e2012-08-25 00:11:56 +00002062 /** \brief A GCC inline assembly statement extension.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002063 */
Chad Rosierde70e0e2012-08-25 00:11:56 +00002064 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5eae0732012-09-24 19:27:20 +00002065 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002066
James Dennett574cb4c2012-06-15 05:41:51 +00002067 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002068 */
2069 CXCursor_ObjCAtTryStmt = 216,
2070
James Dennett574cb4c2012-06-15 05:41:51 +00002071 /** \brief Objective-C's \@catch statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002072 */
2073 CXCursor_ObjCAtCatchStmt = 217,
2074
James Dennett574cb4c2012-06-15 05:41:51 +00002075 /** \brief Objective-C's \@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002076 */
2077 CXCursor_ObjCAtFinallyStmt = 218,
2078
James Dennett574cb4c2012-06-15 05:41:51 +00002079 /** \brief Objective-C's \@throw statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002080 */
2081 CXCursor_ObjCAtThrowStmt = 219,
2082
James Dennett574cb4c2012-06-15 05:41:51 +00002083 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002084 */
2085 CXCursor_ObjCAtSynchronizedStmt = 220,
2086
2087 /** \brief Objective-C's autorelease pool statement.
2088 */
2089 CXCursor_ObjCAutoreleasePoolStmt = 221,
2090
2091 /** \brief Objective-C's collection statement.
2092 */
2093 CXCursor_ObjCForCollectionStmt = 222,
2094
2095 /** \brief C++'s catch statement.
2096 */
2097 CXCursor_CXXCatchStmt = 223,
2098
2099 /** \brief C++'s try statement.
2100 */
2101 CXCursor_CXXTryStmt = 224,
2102
2103 /** \brief C++'s for (* : *) statement.
2104 */
2105 CXCursor_CXXForRangeStmt = 225,
2106
2107 /** \brief Windows Structured Exception Handling's try statement.
2108 */
2109 CXCursor_SEHTryStmt = 226,
2110
2111 /** \brief Windows Structured Exception Handling's except statement.
2112 */
2113 CXCursor_SEHExceptStmt = 227,
2114
2115 /** \brief Windows Structured Exception Handling's finally statement.
2116 */
2117 CXCursor_SEHFinallyStmt = 228,
2118
Chad Rosier32503022012-06-11 20:47:18 +00002119 /** \brief A MS inline assembly statement extension.
2120 */
2121 CXCursor_MSAsmStmt = 229,
2122
Douglas Gregor4c362d52011-10-05 19:00:14 +00002123 /** \brief The null satement ";": C99 6.8.3p3.
2124 *
2125 * This cursor kind is used to describe the null statement.
2126 */
2127 CXCursor_NullStmt = 230,
2128
2129 /** \brief Adaptor class for mixing declarations with statements and
2130 * expressions.
2131 */
2132 CXCursor_DeclStmt = 231,
2133
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002134 /** \brief OpenMP parallel directive.
2135 */
2136 CXCursor_OMPParallelDirective = 232,
2137
2138 CXCursor_LastStmt = CXCursor_OMPParallelDirective,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002139
Douglas Gregor6007cf22010-01-22 22:29:16 +00002140 /**
2141 * \brief Cursor that represents the translation unit itself.
2142 *
2143 * The translation unit cursor exists primarily to act as the root
2144 * cursor for traversing the contents of a translation unit.
2145 */
Ted Kremenekbff31432010-02-18 03:09:07 +00002146 CXCursor_TranslationUnit = 300,
2147
Bill Wendling44426052012-12-20 19:22:21 +00002148 /* Attributes */
Ted Kremenekbff31432010-02-18 03:09:07 +00002149 CXCursor_FirstAttr = 400,
2150 /**
2151 * \brief An attribute whose specific kind is not exposed via this
2152 * interface.
2153 */
2154 CXCursor_UnexposedAttr = 400,
2155
2156 CXCursor_IBActionAttr = 401,
2157 CXCursor_IBOutletAttr = 402,
Ted Kremenek26bde772010-05-19 17:38:06 +00002158 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis2cb4e3c2011-09-13 17:39:31 +00002159 CXCursor_CXXFinalAttr = 404,
2160 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggenca98f2a2011-10-13 09:41:32 +00002161 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002162 CXCursor_AsmLabelAttr = 407,
Argyrios Kyrtzidis16834f12013-09-25 00:14:38 +00002163 CXCursor_PackedAttr = 408,
2164 CXCursor_LastAttr = CXCursor_PackedAttr,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002165
2166 /* Preprocessing */
2167 CXCursor_PreprocessingDirective = 500,
Douglas Gregor06d6d322010-03-18 18:04:21 +00002168 CXCursor_MacroDefinition = 501,
Chandler Carruth9e4704a2011-07-14 08:41:15 +00002169 CXCursor_MacroExpansion = 502,
2170 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregor796d76a2010-10-20 22:00:55 +00002171 CXCursor_InclusionDirective = 503,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002172 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis50e5b1d2012-10-05 00:22:24 +00002173 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2174
2175 /* Extra Declarations */
2176 /**
2177 * \brief A module import declaration.
2178 */
2179 CXCursor_ModuleImportDecl = 600,
2180 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2181 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregor6007cf22010-01-22 22:29:16 +00002182};
2183
2184/**
2185 * \brief A cursor representing some element in the abstract syntax tree for
2186 * a translation unit.
2187 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002188 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregor6007cf22010-01-22 22:29:16 +00002189 * program--declaration, statements, expressions, references to declarations,
2190 * etc.--under a single "cursor" abstraction with a common set of operations.
2191 * Common operation for a cursor include: getting the physical location in
2192 * a source file where the cursor points, getting the name associated with a
2193 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2194 *
2195 * Cursors can be produced in two specific ways.
2196 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2197 * from which one can use clang_visitChildren() to explore the rest of the
2198 * translation unit. clang_getCursor() maps from a physical source location
2199 * to the entity that resides at that location, allowing one to map from the
2200 * source code into the AST.
2201 */
2202typedef struct {
2203 enum CXCursorKind kind;
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00002204 int xdata;
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +00002205 const void *data[3];
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002206} CXCursor;
Douglas Gregor6007cf22010-01-22 22:29:16 +00002207
2208/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002209 * \brief A comment AST node.
2210 */
2211typedef struct {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00002212 const void *ASTNode;
2213 CXTranslationUnit TranslationUnit;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002214} CXComment;
2215
2216/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002217 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2218 *
2219 * @{
2220 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002221
Douglas Gregor6007cf22010-01-22 22:29:16 +00002222/**
2223 * \brief Retrieve the NULL cursor, which represents no entity.
2224 */
2225CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002226
Douglas Gregor6007cf22010-01-22 22:29:16 +00002227/**
2228 * \brief Retrieve the cursor that represents the given translation unit.
2229 *
2230 * The translation unit cursor can be used to start traversing the
2231 * various declarations within the given translation unit.
2232 */
2233CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2234
2235/**
2236 * \brief Determine whether two cursors are equivalent.
2237 */
2238CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002239
Douglas Gregor6007cf22010-01-22 22:29:16 +00002240/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002241 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002242 */
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002243CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002244
2245/**
Douglas Gregor06a3f302010-11-20 00:09:34 +00002246 * \brief Compute a hash value for the given cursor.
2247 */
2248CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2249
2250/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002251 * \brief Retrieve the kind of the given cursor.
2252 */
2253CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2254
2255/**
2256 * \brief Determine whether the given cursor kind represents a declaration.
2257 */
2258CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2259
2260/**
2261 * \brief Determine whether the given cursor kind represents a simple
2262 * reference.
2263 *
2264 * Note that other kinds of cursors (such as expressions) can also refer to
2265 * other cursors. Use clang_getCursorReferenced() to determine whether a
2266 * particular cursor refers to another entity.
2267 */
2268CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2269
2270/**
2271 * \brief Determine whether the given cursor kind represents an expression.
2272 */
2273CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2274
2275/**
2276 * \brief Determine whether the given cursor kind represents a statement.
2277 */
2278CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2279
2280/**
Douglas Gregora98034a2011-07-06 03:00:34 +00002281 * \brief Determine whether the given cursor kind represents an attribute.
2282 */
2283CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2284
2285/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002286 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregor6007cf22010-01-22 22:29:16 +00002287 * cursor.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002288 */
Douglas Gregor6007cf22010-01-22 22:29:16 +00002289CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2290
2291/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002292 * \brief Determine whether the given cursor kind represents a translation
2293 * unit.
Douglas Gregor6007cf22010-01-22 22:29:16 +00002294 */
2295CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002296
Ted Kremenekff9021b2010-03-08 21:17:29 +00002297/***
Douglas Gregor92a524f2010-03-18 00:42:48 +00002298 * \brief Determine whether the given cursor represents a preprocessing
2299 * element, such as a preprocessor directive or macro instantiation.
2300 */
2301CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2302
2303/***
Ted Kremenekff9021b2010-03-08 21:17:29 +00002304 * \brief Determine whether the given cursor represents a currently
2305 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2306 */
2307CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2308
Douglas Gregor6007cf22010-01-22 22:29:16 +00002309/**
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002310 * \brief Describe the linkage of the entity referred to by a cursor.
2311 */
2312enum CXLinkageKind {
2313 /** \brief This value indicates that no linkage information is available
2314 * for a provided CXCursor. */
2315 CXLinkage_Invalid,
2316 /**
2317 * \brief This is the linkage for variables, parameters, and so on that
2318 * have automatic storage. This covers normal (non-extern) local variables.
2319 */
2320 CXLinkage_NoLinkage,
2321 /** \brief This is the linkage for static variables and static functions. */
2322 CXLinkage_Internal,
2323 /** \brief This is the linkage for entities with external linkage that live
2324 * in C++ anonymous namespaces.*/
2325 CXLinkage_UniqueExternal,
2326 /** \brief This is the linkage for entities with true, external linkage. */
2327 CXLinkage_External
2328};
2329
2330/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002331 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002332 */
2333CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2334
2335/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002336 * \brief Determine the availability of the entity that this cursor refers to,
2337 * taking the current target platform into account.
Douglas Gregorf757a122010-08-23 23:00:57 +00002338 *
2339 * \param cursor The cursor to query.
2340 *
2341 * \returns The availability of the cursor.
2342 */
2343CINDEX_LINKAGE enum CXAvailabilityKind
2344clang_getCursorAvailability(CXCursor cursor);
2345
2346/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002347 * Describes the availability of a given entity on a particular platform, e.g.,
2348 * a particular class might only be available on Mac OS 10.7 or newer.
2349 */
2350typedef struct CXPlatformAvailability {
2351 /**
2352 * \brief A string that describes the platform for which this structure
2353 * provides availability information.
2354 *
2355 * Possible values are "ios" or "macosx".
2356 */
2357 CXString Platform;
2358 /**
2359 * \brief The version number in which this entity was introduced.
2360 */
2361 CXVersion Introduced;
2362 /**
2363 * \brief The version number in which this entity was deprecated (but is
2364 * still available).
2365 */
2366 CXVersion Deprecated;
2367 /**
2368 * \brief The version number in which this entity was obsoleted, and therefore
2369 * is no longer available.
2370 */
2371 CXVersion Obsoleted;
2372 /**
2373 * \brief Whether the entity is unconditionally unavailable on this platform.
2374 */
2375 int Unavailable;
2376 /**
2377 * \brief An optional message to provide to a user of this API, e.g., to
2378 * suggest replacement APIs.
2379 */
2380 CXString Message;
2381} CXPlatformAvailability;
2382
2383/**
2384 * \brief Determine the availability of the entity that this cursor refers to
2385 * on any platforms for which availability information is known.
2386 *
2387 * \param cursor The cursor to query.
2388 *
2389 * \param always_deprecated If non-NULL, will be set to indicate whether the
2390 * entity is deprecated on all platforms.
2391 *
2392 * \param deprecated_message If non-NULL, will be set to the message text
2393 * provided along with the unconditional deprecation of this entity. The client
2394 * is responsible for deallocating this string.
2395 *
James Dennett574cb4c2012-06-15 05:41:51 +00002396 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregord6225d32012-05-08 00:14:45 +00002397 * entity is unavailable on all platforms.
2398 *
2399 * \param unavailable_message If non-NULL, will be set to the message text
2400 * provided along with the unconditional unavailability of this entity. The
2401 * client is responsible for deallocating this string.
2402 *
2403 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2404 * that will be populated with platform availability information, up to either
2405 * the number of platforms for which availability information is available (as
2406 * returned by this function) or \c availability_size, whichever is smaller.
2407 *
2408 * \param availability_size The number of elements available in the
2409 * \c availability array.
2410 *
2411 * \returns The number of platforms (N) for which availability information is
2412 * available (which is unrelated to \c availability_size).
2413 *
2414 * Note that the client is responsible for calling
2415 * \c clang_disposeCXPlatformAvailability to free each of the
2416 * platform-availability structures returned. There are
2417 * \c min(N, availability_size) such structures.
2418 */
2419CINDEX_LINKAGE int
2420clang_getCursorPlatformAvailability(CXCursor cursor,
2421 int *always_deprecated,
2422 CXString *deprecated_message,
2423 int *always_unavailable,
2424 CXString *unavailable_message,
2425 CXPlatformAvailability *availability,
2426 int availability_size);
2427
2428/**
2429 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2430 */
2431CINDEX_LINKAGE void
2432clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2433
2434/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002435 * \brief Describe the "language" of the entity referred to by a cursor.
2436 */
Reid Kleckner9e3bc722013-12-30 17:48:49 +00002437enum CXLanguageKind {
Ted Kremenekee457512010-04-14 20:58:32 +00002438 CXLanguage_Invalid = 0,
Ted Kremenek4ed29252010-04-12 21:22:16 +00002439 CXLanguage_C,
2440 CXLanguage_ObjC,
Ted Kremenekee457512010-04-14 20:58:32 +00002441 CXLanguage_CPlusPlus
Ted Kremenek4ed29252010-04-12 21:22:16 +00002442};
2443
2444/**
2445 * \brief Determine the "language" of the entity referred to by a given cursor.
2446 */
2447CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2448
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002449/**
2450 * \brief Returns the translation unit that a cursor originated from.
2451 */
2452CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2453
Ted Kremenekc0b98662013-04-24 07:17:12 +00002454
2455/**
2456 * \brief A fast container representing a set of CXCursors.
2457 */
2458typedef struct CXCursorSetImpl *CXCursorSet;
2459
2460/**
2461 * \brief Creates an empty CXCursorSet.
2462 */
2463CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2464
2465/**
2466 * \brief Disposes a CXCursorSet and releases its associated memory.
2467 */
2468CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2469
2470/**
2471 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2472 *
2473 * \returns non-zero if the set contains the specified cursor.
2474*/
2475CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2476 CXCursor cursor);
2477
2478/**
2479 * \brief Inserts a CXCursor into a CXCursorSet.
2480 *
2481 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2482*/
2483CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2484 CXCursor cursor);
2485
Douglas Gregor0576ce72010-09-22 21:22:29 +00002486/**
2487 * \brief Determine the semantic parent of the given cursor.
2488 *
2489 * The semantic parent of a cursor is the cursor that semantically contains
2490 * the given \p cursor. For many declarations, the lexical and semantic parents
2491 * are equivalent (the lexical parent is returned by
2492 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2493 * definitions are provided out-of-line. For example:
2494 *
2495 * \code
2496 * class C {
2497 * void f();
2498 * };
2499 *
2500 * void C::f() { }
2501 * \endcode
2502 *
2503 * In the out-of-line definition of \c C::f, the semantic parent is the
2504 * the class \c C, of which this function is a member. The lexical parent is
2505 * the place where the declaration actually occurs in the source code; in this
2506 * case, the definition occurs in the translation unit. In general, the
2507 * lexical parent for a given entity can change without affecting the semantics
2508 * of the program, and the lexical parent of different declarations of the
2509 * same entity may be different. Changing the semantic parent of a declaration,
2510 * on the other hand, can have a major impact on semantics, and redeclarations
2511 * of a particular entity should all have the same semantic context.
2512 *
2513 * In the example above, both declarations of \c C::f have \c C as their
2514 * semantic context, while the lexical context of the first \c C::f is \c C
2515 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002516 *
2517 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002518 */
2519CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2520
2521/**
2522 * \brief Determine the lexical parent of the given cursor.
2523 *
2524 * The lexical parent of a cursor is the cursor in which the given \p cursor
2525 * was actually written. For many declarations, the lexical and semantic parents
2526 * are equivalent (the semantic parent is returned by
2527 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2528 * definitions are provided out-of-line. For example:
2529 *
2530 * \code
2531 * class C {
2532 * void f();
2533 * };
2534 *
2535 * void C::f() { }
2536 * \endcode
2537 *
2538 * In the out-of-line definition of \c C::f, the semantic parent is the
2539 * the class \c C, of which this function is a member. The lexical parent is
2540 * the place where the declaration actually occurs in the source code; in this
2541 * case, the definition occurs in the translation unit. In general, the
2542 * lexical parent for a given entity can change without affecting the semantics
2543 * of the program, and the lexical parent of different declarations of the
2544 * same entity may be different. Changing the semantic parent of a declaration,
2545 * on the other hand, can have a major impact on semantics, and redeclarations
2546 * of a particular entity should all have the same semantic context.
2547 *
2548 * In the example above, both declarations of \c C::f have \c C as their
2549 * semantic context, while the lexical context of the first \c C::f is \c C
2550 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002551 *
2552 * For declarations written in the global scope, the lexical parent is
2553 * the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002554 */
2555CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor99a26af2010-10-01 20:25:15 +00002556
2557/**
2558 * \brief Determine the set of methods that are overridden by the given
2559 * method.
2560 *
2561 * In both Objective-C and C++, a method (aka virtual member function,
2562 * in C++) can override a virtual method in a base class. For
2563 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidisbfb24252012-03-08 00:20:03 +00002564 * base class, its protocols, or its categories' protocols, that has the same
2565 * selector and is of the same kind (class or instance).
2566 * If no such method exists, the search continues to the class's superclass,
2567 * its protocols, and its categories, and so on. A method from an Objective-C
2568 * implementation is considered to override the same methods as its
2569 * corresponding method in the interface.
Douglas Gregor99a26af2010-10-01 20:25:15 +00002570 *
2571 * For C++, a virtual member function overrides any virtual member
2572 * function with the same signature that occurs in its base
2573 * classes. With multiple inheritance, a virtual member function can
2574 * override several virtual member functions coming from different
2575 * base classes.
2576 *
2577 * In all cases, this function determines the immediate overridden
2578 * method, rather than all of the overridden methods. For example, if
2579 * a method is originally declared in a class A, then overridden in B
2580 * (which in inherits from A) and also in C (which inherited from B),
2581 * then the only overridden method returned from this function when
2582 * invoked on C's method will be B's method. The client may then
2583 * invoke this function again, given the previously-found overridden
2584 * methods, to map out the complete method-override set.
2585 *
2586 * \param cursor A cursor representing an Objective-C or C++
2587 * method. This routine will compute the set of methods that this
2588 * method overrides.
2589 *
2590 * \param overridden A pointer whose pointee will be replaced with a
2591 * pointer to an array of cursors, representing the set of overridden
2592 * methods. If there are no overridden methods, the pointee will be
2593 * set to NULL. The pointee must be freed via a call to
2594 * \c clang_disposeOverriddenCursors().
2595 *
2596 * \param num_overridden A pointer to the number of overridden
2597 * functions, will be set to the number of overridden functions in the
2598 * array pointed to by \p overridden.
2599 */
2600CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2601 CXCursor **overridden,
2602 unsigned *num_overridden);
2603
2604/**
2605 * \brief Free the set of overridden cursors returned by \c
2606 * clang_getOverriddenCursors().
2607 */
2608CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2609
Ted Kremenek4ed29252010-04-12 21:22:16 +00002610/**
Douglas Gregor796d76a2010-10-20 22:00:55 +00002611 * \brief Retrieve the file that is included by the given inclusion directive
2612 * cursor.
2613 */
2614CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2615
2616/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002617 * @}
2618 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002619
Douglas Gregor6007cf22010-01-22 22:29:16 +00002620/**
2621 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2622 *
2623 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2624 * routines help map between cursors and the physical locations where the
2625 * described entities occur in the source code. The mapping is provided in
2626 * both directions, so one can map from source code to the AST and back.
2627 *
2628 * @{
Steve Naroffa1c72842009-08-28 15:28:48 +00002629 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002630
Steve Naroff20bad0b2009-10-21 13:56:23 +00002631/**
Douglas Gregor816fd362010-01-22 21:44:22 +00002632 * \brief Map a source location to the cursor that describes the entity at that
2633 * location in the source code.
2634 *
2635 * clang_getCursor() maps an arbitrary source location within a translation
2636 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002637 * location. For example, given an expression \c x + y, invoking
Douglas Gregor816fd362010-01-22 21:44:22 +00002638 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002639 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregor816fd362010-01-22 21:44:22 +00002640 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2641 * will return a cursor referring to the "+" expression.
2642 *
2643 * \returns a cursor representing the entity at the given source location, or
2644 * a NULL cursor if no such entity can be found.
Steve Naroff20bad0b2009-10-21 13:56:23 +00002645 */
Douglas Gregor816fd362010-01-22 21:44:22 +00002646CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002647
Douglas Gregor66a58812010-01-18 22:46:11 +00002648/**
2649 * \brief Retrieve the physical location of the source constructor referenced
2650 * by the given cursor.
2651 *
2652 * The location of a declaration is typically the location of the name of that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002653 * declaration, where the name of that declaration would occur if it is
2654 * unnamed, or some keyword that introduces that particular declaration.
2655 * The location of a reference is where that reference occurs within the
Douglas Gregor66a58812010-01-18 22:46:11 +00002656 * source code.
2657 */
2658CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregor6007cf22010-01-22 22:29:16 +00002659
Douglas Gregor6b8232f2010-01-19 19:34:47 +00002660/**
2661 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002662 * the given cursor.
2663 *
2664 * The extent of a cursor starts with the file/line/column pointing at the
2665 * first character within the source construct that the cursor refers to and
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002666 * ends with the last character withinin that source construct. For a
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002667 * declaration, the extent covers the declaration itself. For a reference,
2668 * the extent covers the location of the reference (e.g., where the referenced
2669 * entity was actually used).
2670 */
2671CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorad27e8b2010-01-19 01:20:04 +00002672
Douglas Gregor6007cf22010-01-22 22:29:16 +00002673/**
2674 * @}
2675 */
Ted Kremeneka5940822010-08-26 01:42:22 +00002676
Douglas Gregor6007cf22010-01-22 22:29:16 +00002677/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002678 * \defgroup CINDEX_TYPES Type information for CXCursors
2679 *
2680 * @{
2681 */
2682
2683/**
2684 * \brief Describes the kind of type
2685 */
2686enum CXTypeKind {
2687 /**
2688 * \brief Reprents an invalid type (e.g., where no type is available).
2689 */
2690 CXType_Invalid = 0,
2691
2692 /**
2693 * \brief A type whose specific kind is not exposed via this
2694 * interface.
2695 */
2696 CXType_Unexposed = 1,
2697
2698 /* Builtin types */
2699 CXType_Void = 2,
2700 CXType_Bool = 3,
2701 CXType_Char_U = 4,
2702 CXType_UChar = 5,
2703 CXType_Char16 = 6,
2704 CXType_Char32 = 7,
2705 CXType_UShort = 8,
2706 CXType_UInt = 9,
2707 CXType_ULong = 10,
2708 CXType_ULongLong = 11,
2709 CXType_UInt128 = 12,
2710 CXType_Char_S = 13,
2711 CXType_SChar = 14,
2712 CXType_WChar = 15,
2713 CXType_Short = 16,
2714 CXType_Int = 17,
2715 CXType_Long = 18,
2716 CXType_LongLong = 19,
2717 CXType_Int128 = 20,
2718 CXType_Float = 21,
2719 CXType_Double = 22,
2720 CXType_LongDouble = 23,
2721 CXType_NullPtr = 24,
2722 CXType_Overload = 25,
2723 CXType_Dependent = 26,
2724 CXType_ObjCId = 27,
2725 CXType_ObjCClass = 28,
2726 CXType_ObjCSel = 29,
2727 CXType_FirstBuiltin = CXType_Void,
2728 CXType_LastBuiltin = CXType_ObjCSel,
2729
2730 CXType_Complex = 100,
2731 CXType_Pointer = 101,
2732 CXType_BlockPointer = 102,
2733 CXType_LValueReference = 103,
2734 CXType_RValueReference = 104,
2735 CXType_Record = 105,
2736 CXType_Enum = 106,
2737 CXType_Typedef = 107,
2738 CXType_ObjCInterface = 108,
Ted Kremenekc1508872010-06-21 20:15:39 +00002739 CXType_ObjCObjectPointer = 109,
2740 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002741 CXType_FunctionProto = 111,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002742 CXType_ConstantArray = 112,
Argyrios Kyrtzidis0661a712013-07-23 17:36:21 +00002743 CXType_Vector = 113,
2744 CXType_IncompleteArray = 114,
2745 CXType_VariableArray = 115,
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00002746 CXType_DependentSizedArray = 116,
2747 CXType_MemberPointer = 117
Ted Kremenek6bca9842010-05-14 21:29:26 +00002748};
2749
2750/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002751 * \brief Describes the calling convention of a function type
2752 */
2753enum CXCallingConv {
2754 CXCallingConv_Default = 0,
2755 CXCallingConv_C = 1,
2756 CXCallingConv_X86StdCall = 2,
2757 CXCallingConv_X86FastCall = 3,
2758 CXCallingConv_X86ThisCall = 4,
2759 CXCallingConv_X86Pascal = 5,
2760 CXCallingConv_AAPCS = 6,
2761 CXCallingConv_AAPCS_VFP = 7,
Derek Schuffa2020962012-10-16 22:30:41 +00002762 CXCallingConv_PnaclCall = 8,
Guy Benyeif0a014b2012-12-25 08:53:55 +00002763 CXCallingConv_IntelOclBicc = 9,
Charles Davisb5a214e2013-08-30 04:39:01 +00002764 CXCallingConv_X86_64Win64 = 10,
2765 CXCallingConv_X86_64SysV = 11,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002766
2767 CXCallingConv_Invalid = 100,
2768 CXCallingConv_Unexposed = 200
2769};
2770
2771
2772/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002773 * \brief The type of an element in the abstract syntax tree.
2774 *
2775 */
2776typedef struct {
2777 enum CXTypeKind kind;
2778 void *data[2];
2779} CXType;
2780
2781/**
2782 * \brief Retrieve the type of a CXCursor (if any).
2783 */
2784CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2785
2786/**
Dmitri Gribenko00353722013-02-15 21:15:49 +00002787 * \brief Pretty-print the underlying type using the rules of the
2788 * language of the translation unit from which it came.
2789 *
2790 * If the type is invalid, an empty string is returned.
2791 */
2792CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2793
2794/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002795 * \brief Retrieve the underlying type of a typedef declaration.
2796 *
2797 * If the cursor does not reference a typedef declaration, an invalid type is
2798 * returned.
2799 */
2800CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2801
2802/**
2803 * \brief Retrieve the integer type of an enum declaration.
2804 *
2805 * If the cursor does not reference an enum declaration, an invalid type is
2806 * returned.
2807 */
2808CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2809
2810/**
2811 * \brief Retrieve the integer value of an enum constant declaration as a signed
2812 * long long.
2813 *
2814 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2815 * Since this is also potentially a valid constant value, the kind of the cursor
2816 * must be verified before calling this function.
2817 */
2818CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2819
2820/**
2821 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2822 * long long.
2823 *
2824 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2825 * Since this is also potentially a valid constant value, the kind of the cursor
2826 * must be verified before calling this function.
2827 */
2828CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2829
2830/**
Dmitri Gribenkob506ba12012-12-04 15:13:46 +00002831 * \brief Retrieve the bit width of a bit field declaration as an integer.
2832 *
2833 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2834 */
2835CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2836
2837/**
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002838 * \brief Retrieve the number of non-variadic arguments associated with a given
2839 * cursor.
2840 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002841 * The number of arguments can be determined for calls as well as for
2842 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002843 */
2844CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2845
2846/**
2847 * \brief Retrieve the argument cursor of a function or method.
2848 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002849 * The argument cursor can be determined for calls as well as for declarations
2850 * of functions or methods. For other cursors and for invalid indices, an
2851 * invalid cursor is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002852 */
2853CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2854
2855/**
James Dennett574cb4c2012-06-15 05:41:51 +00002856 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002857 *
James Dennett574cb4c2012-06-15 05:41:51 +00002858 * \returns non-zero if the CXTypes represent the same type and
2859 * zero otherwise.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002860 */
2861CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2862
2863/**
2864 * \brief Return the canonical type for a CXType.
2865 *
2866 * Clang's type system explicitly models typedefs and all the ways
2867 * a specific type can be represented. The canonical type is the underlying
2868 * type with all the "sugar" removed. For example, if 'T' is a typedef
2869 * for 'int', the canonical type for 'T' would be 'int'.
2870 */
2871CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2872
2873/**
James Dennett574cb4c2012-06-15 05:41:51 +00002874 * \brief Determine whether a CXType has the "const" qualifier set,
2875 * without looking through typedefs that may have added "const" at a
2876 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002877 */
2878CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2879
2880/**
James Dennett574cb4c2012-06-15 05:41:51 +00002881 * \brief Determine whether a CXType has the "volatile" qualifier set,
2882 * without looking through typedefs that may have added "volatile" at
2883 * a different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002884 */
2885CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2886
2887/**
James Dennett574cb4c2012-06-15 05:41:51 +00002888 * \brief Determine whether a CXType has the "restrict" qualifier set,
2889 * without looking through typedefs that may have added "restrict" at a
2890 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002891 */
2892CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2893
2894/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002895 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002896 */
2897CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2898
2899/**
2900 * \brief Return the cursor for the declaration of the given type.
2901 */
2902CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2903
David Chisnall50e4eba2010-12-30 14:05:53 +00002904/**
2905 * Returns the Objective-C type encoding for the specified declaration.
2906 */
2907CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek6bca9842010-05-14 21:29:26 +00002908
2909/**
2910 * \brief Retrieve the spelling of a given CXTypeKind.
2911 */
2912CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2913
2914/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002915 * \brief Retrieve the calling convention associated with a function type.
2916 *
2917 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2918 */
2919CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2920
2921/**
Alp Toker314cc812014-01-25 16:55:45 +00002922 * \brief Retrieve the return type associated with a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002923 *
2924 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenekc1508872010-06-21 20:15:39 +00002925 */
2926CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2927
2928/**
Alp Toker601b22c2014-01-21 23:35:24 +00002929 * \brief Retrieve the number of non-variadic parameters associated with a
James Dennett574cb4c2012-06-15 05:41:51 +00002930 * function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002931 *
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002932 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002933 */
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002934CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002935
2936/**
Alp Toker601b22c2014-01-21 23:35:24 +00002937 * \brief Retrieve the type of a parameter of a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002938 *
James Dennett574cb4c2012-06-15 05:41:51 +00002939 * If a non-function type is passed in or the function does not have enough
2940 * parameters, an invalid type is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002941 */
2942CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2943
2944/**
2945 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002946 */
2947CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2948
2949/**
Alp Toker314cc812014-01-25 16:55:45 +00002950 * \brief Retrieve the return type associated with a given cursor.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002951 *
2952 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00002953 */
2954CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2955
2956/**
Ted Kremenek0c7476a2010-07-30 00:14:11 +00002957 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2958 * otherwise.
2959 */
2960CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2961
2962/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002963 * \brief Return the element type of an array, complex, or vector type.
2964 *
2965 * If a type is passed in that is not an array, complex, or vector type,
2966 * an invalid type is returned.
2967 */
2968CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2969
2970/**
2971 * \brief Return the number of elements of an array or vector type.
2972 *
2973 * If a type is passed in that is not an array or vector type,
2974 * -1 is returned.
2975 */
2976CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2977
2978/**
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002979 * \brief Return the element type of an array type.
2980 *
2981 * If a non-array type is passed in, an invalid type is returned.
2982 */
2983CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2984
2985/**
Sylvestre Ledru830885c2012-07-23 08:59:39 +00002986 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002987 *
2988 * If a non-array type is passed in, -1 is returned.
2989 */
2990CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2991
2992/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00002993 * \brief List the possible error codes for \c clang_Type_getSizeOf,
2994 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
2995 * \c clang_Cursor_getOffsetOf.
2996 *
2997 * A value of this enumeration type can be returned if the target type is not
2998 * a valid argument to sizeof, alignof or offsetof.
2999 */
3000enum CXTypeLayoutError {
3001 /**
3002 * \brief Type is of kind CXType_Invalid.
3003 */
3004 CXTypeLayoutError_Invalid = -1,
3005 /**
3006 * \brief The type is an incomplete Type.
3007 */
3008 CXTypeLayoutError_Incomplete = -2,
3009 /**
3010 * \brief The type is a dependent Type.
3011 */
3012 CXTypeLayoutError_Dependent = -3,
3013 /**
3014 * \brief The type is not a constant size type.
3015 */
3016 CXTypeLayoutError_NotConstantSize = -4,
3017 /**
3018 * \brief The Field name is not valid for this record.
3019 */
3020 CXTypeLayoutError_InvalidFieldName = -5
3021};
3022
3023/**
3024 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
3025 * standard.
3026 *
3027 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3028 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3029 * is returned.
3030 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3031 * returned.
3032 * If the type declaration is not a constant size type,
3033 * CXTypeLayoutError_NotConstantSize is returned.
3034 */
3035CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
3036
3037/**
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00003038 * \brief Return the class type of an member pointer type.
3039 *
3040 * If a non-member-pointer type is passed in, an invalid type is returned.
3041 */
3042CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T);
3043
3044/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003045 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
3046 *
3047 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3048 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3049 * is returned.
3050 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3051 * returned.
3052 */
3053CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
3054
3055/**
3056 * \brief Return the offset of a field named S in a record of type T in bits
3057 * as it would be returned by __offsetof__ as per C++11[18.2p4]
3058 *
3059 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
3060 * is returned.
3061 * If the field's type declaration is an incomplete type,
3062 * CXTypeLayoutError_Incomplete is returned.
3063 * If the field's type declaration is a dependent type,
3064 * CXTypeLayoutError_Dependent is returned.
3065 * If the field's name S is not found,
3066 * CXTypeLayoutError_InvalidFieldName is returned.
3067 */
3068CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
3069
Argyrios Kyrtzidisadff3ae2013-10-11 19:58:38 +00003070enum CXRefQualifierKind {
3071 /** \brief No ref-qualifier was provided. */
3072 CXRefQualifier_None = 0,
3073 /** \brief An lvalue ref-qualifier was provided (\c &). */
3074 CXRefQualifier_LValue,
3075 /** \brief An rvalue ref-qualifier was provided (\c &&). */
3076 CXRefQualifier_RValue
3077};
3078
3079/**
3080 * \brief Retrieve the ref-qualifier kind of a function or method.
3081 *
3082 * The ref-qualifier is returned for C++ functions or methods. For other types
3083 * or non-C++ declarations, CXRefQualifier_None is returned.
3084 */
3085CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
3086
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003087/**
3088 * \brief Returns non-zero if the cursor specifies a Record member that is a
3089 * bitfield.
3090 */
3091CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
3092
3093/**
Ted Kremenekae9e2212010-08-27 21:34:58 +00003094 * \brief Returns 1 if the base class specified by the cursor with kind
3095 * CX_CXXBaseSpecifier is virtual.
3096 */
3097CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3098
3099/**
3100 * \brief Represents the C++ access control level to a base class for a
3101 * cursor with kind CX_CXXBaseSpecifier.
3102 */
3103enum CX_CXXAccessSpecifier {
3104 CX_CXXInvalidAccessSpecifier,
3105 CX_CXXPublic,
3106 CX_CXXProtected,
3107 CX_CXXPrivate
3108};
3109
3110/**
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003111 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidisf6464082013-04-11 17:31:13 +00003112 *
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003113 * If the cursor refers to a C++ declaration, its access control level within its
3114 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3115 * access specifier, the specifier itself is returned.
Ted Kremenekae9e2212010-08-27 21:34:58 +00003116 */
3117CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3118
3119/**
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00003120 * \brief Determine the number of overloaded declarations referenced by a
3121 * \c CXCursor_OverloadedDeclRef cursor.
3122 *
3123 * \param cursor The cursor whose overloaded declarations are being queried.
3124 *
3125 * \returns The number of overloaded declarations referenced by \c cursor. If it
3126 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3127 */
3128CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3129
3130/**
3131 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3132 * by a \c CXCursor_OverloadedDeclRef cursor.
3133 *
3134 * \param cursor The cursor whose overloaded declarations are being queried.
3135 *
3136 * \param index The zero-based index into the set of overloaded declarations in
3137 * the cursor.
3138 *
3139 * \returns A cursor representing the declaration referenced by the given
3140 * \c cursor at the specified \c index. If the cursor does not have an
3141 * associated set of overloaded declarations, or if the index is out of bounds,
3142 * returns \c clang_getNullCursor();
3143 */
3144CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3145 unsigned index);
3146
3147/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00003148 * @}
3149 */
Ted Kremeneka5940822010-08-26 01:42:22 +00003150
3151/**
Ted Kremenek2c2c5f32010-08-27 21:34:51 +00003152 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremeneka5940822010-08-26 01:42:22 +00003153 *
3154 * @{
3155 */
3156
3157
3158/**
3159 * \brief For cursors representing an iboutletcollection attribute,
3160 * this function returns the collection element type.
3161 *
3162 */
3163CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3164
3165/**
3166 * @}
3167 */
Ted Kremenek6bca9842010-05-14 21:29:26 +00003168
3169/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003170 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3171 *
3172 * These routines provide the ability to traverse the abstract syntax tree
3173 * using cursors.
3174 *
3175 * @{
3176 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003177
Douglas Gregor6007cf22010-01-22 22:29:16 +00003178/**
3179 * \brief Describes how the traversal of the children of a particular
3180 * cursor should proceed after visiting a particular child cursor.
3181 *
3182 * A value of this enumeration type should be returned by each
3183 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3184 */
3185enum CXChildVisitResult {
3186 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003187 * \brief Terminates the cursor traversal.
Douglas Gregor6007cf22010-01-22 22:29:16 +00003188 */
3189 CXChildVisit_Break,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003190 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003191 * \brief Continues the cursor traversal with the next sibling of
3192 * the cursor just visited, without visiting its children.
3193 */
3194 CXChildVisit_Continue,
3195 /**
3196 * \brief Recursively traverse the children of this cursor, using
3197 * the same visitor and client data.
3198 */
3199 CXChildVisit_Recurse
3200};
3201
3202/**
3203 * \brief Visitor invoked for each cursor found by a traversal.
3204 *
3205 * This visitor function will be invoked for each cursor found by
3206 * clang_visitCursorChildren(). Its first argument is the cursor being
3207 * visited, its second argument is the parent visitor for that cursor,
3208 * and its third argument is the client data provided to
3209 * clang_visitCursorChildren().
3210 *
3211 * The visitor should return one of the \c CXChildVisitResult values
3212 * to direct clang_visitCursorChildren().
3213 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003214typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3215 CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003216 CXClientData client_data);
3217
3218/**
3219 * \brief Visit the children of a particular cursor.
3220 *
3221 * This function visits all the direct children of the given cursor,
3222 * invoking the given \p visitor function with the cursors of each
3223 * visited child. The traversal may be recursive, if the visitor returns
3224 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3225 * the visitor returns \c CXChildVisit_Break.
3226 *
Douglas Gregor6007cf22010-01-22 22:29:16 +00003227 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbarb9999fd2010-01-24 04:10:31 +00003228 * cursors can be visited, including invalid cursors (which, by
Douglas Gregor6007cf22010-01-22 22:29:16 +00003229 * definition, have no children).
3230 *
3231 * \param visitor the visitor function that will be invoked for each
3232 * child of \p parent.
3233 *
3234 * \param client_data pointer data supplied by the client, which will
3235 * be passed to the visitor each time it is invoked.
3236 *
3237 * \returns a non-zero value if the traversal was terminated
3238 * prematurely by the visitor returning \c CXChildVisit_Break.
3239 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003240CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003241 CXCursorVisitor visitor,
3242 CXClientData client_data);
David Chisnallb2aa0ef2010-11-03 14:12:26 +00003243#ifdef __has_feature
3244# if __has_feature(blocks)
3245/**
3246 * \brief Visitor invoked for each cursor found by a traversal.
3247 *
3248 * This visitor block will be invoked for each cursor found by
3249 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3250 * visited, its second argument is the parent visitor for that cursor.
3251 *
3252 * The visitor should return one of the \c CXChildVisitResult values
3253 * to direct clang_visitChildrenWithBlock().
3254 */
3255typedef enum CXChildVisitResult
3256 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3257
3258/**
3259 * Visits the children of a cursor using the specified block. Behaves
3260 * identically to clang_visitChildren() in all other respects.
3261 */
3262unsigned clang_visitChildrenWithBlock(CXCursor parent,
3263 CXCursorVisitorBlock block);
3264# endif
3265#endif
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003266
Douglas Gregor6007cf22010-01-22 22:29:16 +00003267/**
3268 * @}
3269 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003270
Douglas Gregor6007cf22010-01-22 22:29:16 +00003271/**
3272 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3273 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003274 * These routines provide the ability to determine references within and
Douglas Gregor6007cf22010-01-22 22:29:16 +00003275 * across translation units, by providing the names of the entities referenced
3276 * by cursors, follow reference cursors to the declarations they reference,
3277 * and associate declarations with their definitions.
3278 *
3279 * @{
3280 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003281
Douglas Gregor6007cf22010-01-22 22:29:16 +00003282/**
3283 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3284 * by the given cursor.
3285 *
3286 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3287 * entity (function, class, variable, etc.) within a program. USRs can be
3288 * compared across translation units to determine, e.g., when references in
3289 * one translation refer to an entity defined in another translation unit.
3290 */
3291CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3292
3293/**
Ted Kremenekd071c602010-03-13 02:50:34 +00003294 * \brief Construct a USR for a specified Objective-C class.
3295 */
3296CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3297
3298/**
3299 * \brief Construct a USR for a specified Objective-C category.
3300 */
3301CINDEX_LINKAGE CXString
Ted Kremenekbc1a67b2010-03-15 17:38:58 +00003302 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenekd071c602010-03-13 02:50:34 +00003303 const char *category_name);
3304
3305/**
3306 * \brief Construct a USR for a specified Objective-C protocol.
3307 */
3308CINDEX_LINKAGE CXString
3309 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3310
3311
3312/**
3313 * \brief Construct a USR for a specified Objective-C instance variable and
3314 * the USR for its containing class.
3315 */
3316CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3317 CXString classUSR);
3318
3319/**
3320 * \brief Construct a USR for a specified Objective-C method and
3321 * the USR for its containing class.
3322 */
3323CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3324 unsigned isInstanceMethod,
3325 CXString classUSR);
3326
3327/**
3328 * \brief Construct a USR for a specified Objective-C property and the USR
3329 * for its containing class.
3330 */
3331CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3332 CXString classUSR);
3333
3334/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003335 * \brief Retrieve a name for the entity referenced by this cursor.
3336 */
3337CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3338
Douglas Gregor97c75712010-10-02 22:49:11 +00003339/**
Argyrios Kyrtzidis191a6a82012-03-30 20:58:35 +00003340 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3341 * Most of the times there is only one range for the complete spelling but for
3342 * objc methods and objc message expressions, there are multiple pieces for each
3343 * selector identifier.
3344 *
3345 * \param pieceIndex the index of the spelling name piece. If this is greater
3346 * than the actual number of pieces, it will return a NULL (invalid) range.
3347 *
3348 * \param options Reserved.
3349 */
3350CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3351 unsigned pieceIndex,
3352 unsigned options);
3353
3354/**
Douglas Gregor97c75712010-10-02 22:49:11 +00003355 * \brief Retrieve the display name for the entity referenced by this cursor.
3356 *
3357 * The display name contains extra information that helps identify the cursor,
3358 * such as the parameters of a function or template or the arguments of a
3359 * class template specialization.
3360 */
3361CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3362
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003363/** \brief For a cursor that is a reference, retrieve a cursor representing the
3364 * entity that it references.
3365 *
3366 * Reference cursors refer to other entities in the AST. For example, an
3367 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003368 * This function produces the cursor for the Objective-C class from the
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003369 * cursor for the superclass reference. If the input cursor is a declaration or
3370 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003371 * Otherwise, returns the NULL cursor.
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003372 */
3373CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003374
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003375/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003376 * \brief For a cursor that is either a reference to or a declaration
3377 * of some entity, retrieve a cursor that describes the definition of
3378 * that entity.
3379 *
3380 * Some entities can be declared multiple times within a translation
3381 * unit, but only one of those declarations can also be a
3382 * definition. For example, given:
3383 *
3384 * \code
3385 * int f(int, int);
3386 * int g(int x, int y) { return f(x, y); }
3387 * int f(int a, int b) { return a + b; }
3388 * int f(int, int);
3389 * \endcode
3390 *
3391 * there are three declarations of the function "f", but only the
3392 * second one is a definition. The clang_getCursorDefinition()
3393 * function will take any cursor pointing to a declaration of "f"
3394 * (the first or fourth lines of the example) or a cursor referenced
3395 * that uses "f" (the call to "f' inside "g") and will return a
3396 * declaration cursor pointing to the definition (the second "f"
3397 * declaration).
3398 *
3399 * If given a cursor for which there is no corresponding definition,
3400 * e.g., because there is no definition of that entity within this
3401 * translation unit, returns a NULL cursor.
3402 */
3403CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3404
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003405/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003406 * \brief Determine whether the declaration pointed to by this cursor
3407 * is also a definition of that entity.
3408 */
3409CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3410
Douglas Gregor6007cf22010-01-22 22:29:16 +00003411/**
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003412 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3413 *
3414 * In the C family of languages, many kinds of entities can be declared several
3415 * times within a single translation unit. For example, a structure type can
3416 * be forward-declared (possibly multiple times) and later defined:
3417 *
3418 * \code
3419 * struct X;
3420 * struct X;
3421 * struct X {
3422 * int member;
3423 * };
3424 * \endcode
3425 *
3426 * The declarations and the definition of \c X are represented by three
3427 * different cursors, all of which are declarations of the same underlying
3428 * entity. One of these cursor is considered the "canonical" cursor, which
3429 * is effectively the representative for the underlying entity. One can
3430 * determine if two cursors are declarations of the same underlying entity by
3431 * comparing their canonical cursors.
3432 *
3433 * \returns The canonical cursor for the entity referred to by the given cursor.
3434 */
3435CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3436
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003437
3438/**
3439 * \brief If the cursor points to a selector identifier in a objc method or
3440 * message expression, this returns the selector index.
3441 *
James Dennett574cb4c2012-06-15 05:41:51 +00003442 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003443 * determine if the location points to a selector identifier.
3444 *
3445 * \returns The selector index if the cursor is an objc method or message
3446 * expression and the cursor is pointing to a selector identifier, or -1
3447 * otherwise.
3448 */
3449CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3450
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003451/**
Argyrios Kyrtzidisb6df68212012-07-02 23:54:36 +00003452 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3453 * returns non-zero if the method/message is "dynamic", meaning:
3454 *
3455 * For a C++ method: the call is virtual.
3456 * For an ObjC message: the receiver is an object instance, not 'super' or a
3457 * specific class.
3458 *
3459 * If the method/message is "static" or the cursor does not point to a
3460 * method/message, it will return zero.
3461 */
3462CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3463
3464/**
Argyrios Kyrtzidisb26a24c2012-11-01 02:01:34 +00003465 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3466 * receiver.
3467 */
3468CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3469
3470/**
Argyrios Kyrtzidis9adfd8a2013-04-18 22:15:49 +00003471 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3472 */
3473typedef enum {
3474 CXObjCPropertyAttr_noattr = 0x00,
3475 CXObjCPropertyAttr_readonly = 0x01,
3476 CXObjCPropertyAttr_getter = 0x02,
3477 CXObjCPropertyAttr_assign = 0x04,
3478 CXObjCPropertyAttr_readwrite = 0x08,
3479 CXObjCPropertyAttr_retain = 0x10,
3480 CXObjCPropertyAttr_copy = 0x20,
3481 CXObjCPropertyAttr_nonatomic = 0x40,
3482 CXObjCPropertyAttr_setter = 0x80,
3483 CXObjCPropertyAttr_atomic = 0x100,
3484 CXObjCPropertyAttr_weak = 0x200,
3485 CXObjCPropertyAttr_strong = 0x400,
3486 CXObjCPropertyAttr_unsafe_unretained = 0x800
3487} CXObjCPropertyAttrKind;
3488
3489/**
3490 * \brief Given a cursor that represents a property declaration, return the
3491 * associated property attributes. The bits are formed from
3492 * \c CXObjCPropertyAttrKind.
3493 *
3494 * \param reserved Reserved for future use, pass 0.
3495 */
3496CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3497 unsigned reserved);
3498
3499/**
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003500 * \brief 'Qualifiers' written next to the return and parameter types in
3501 * ObjC method declarations.
3502 */
3503typedef enum {
3504 CXObjCDeclQualifier_None = 0x0,
3505 CXObjCDeclQualifier_In = 0x1,
3506 CXObjCDeclQualifier_Inout = 0x2,
3507 CXObjCDeclQualifier_Out = 0x4,
3508 CXObjCDeclQualifier_Bycopy = 0x8,
3509 CXObjCDeclQualifier_Byref = 0x10,
3510 CXObjCDeclQualifier_Oneway = 0x20
3511} CXObjCDeclQualifierKind;
3512
3513/**
3514 * \brief Given a cursor that represents an ObjC method or parameter
3515 * declaration, return the associated ObjC qualifiers for the return type or the
Argyrios Kyrtzidis982934e2013-04-19 00:51:52 +00003516 * parameter respectively. The bits are formed from CXObjCDeclQualifierKind.
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003517 */
3518CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3519
3520/**
Argyrios Kyrtzidis7b50fc52013-07-05 20:44:37 +00003521 * \brief Given a cursor that represents an ObjC method or property declaration,
3522 * return non-zero if the declaration was affected by "@optional".
3523 * Returns zero if the cursor is not such a declaration or it is "@required".
3524 */
3525CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
3526
3527/**
Argyrios Kyrtzidis23814e42013-04-18 23:53:05 +00003528 * \brief Returns non-zero if the given cursor is a variadic function or method.
3529 */
3530CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3531
3532/**
Dmitri Gribenkoaab83832012-06-20 00:34:58 +00003533 * \brief Given a cursor that represents a declaration, return the associated
3534 * comment's source range. The range may include multiple consecutive comments
3535 * with whitespace in between.
3536 */
3537CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3538
3539/**
3540 * \brief Given a cursor that represents a declaration, return the associated
3541 * comment text, including comment markers.
3542 */
3543CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3544
3545/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003546 * \brief Given a cursor that represents a documentable entity (e.g.,
3547 * declaration), return the associated \\brief paragraph; otherwise return the
3548 * first paragraph.
Dmitri Gribenko5188c4b2012-06-26 20:39:18 +00003549 */
3550CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3551
3552/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003553 * \brief Given a cursor that represents a documentable entity (e.g.,
3554 * declaration), return the associated parsed comment as a
3555 * \c CXComment_FullComment AST node.
3556 */
3557CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3558
3559/**
3560 * @}
3561 */
3562
3563/**
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003564 * \defgroup CINDEX_MODULE Module introspection
3565 *
3566 * The functions in this group provide access to information about modules.
3567 *
3568 * @{
3569 */
3570
3571typedef void *CXModule;
3572
3573/**
3574 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3575 */
3576CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3577
3578/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003579 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003580 *
Argyrios Kyrtzidis12fdb9e2013-04-26 22:47:49 +00003581 * \returns the module file where the provided module object came from.
3582 */
3583CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3584
3585/**
3586 * \param Module a module object.
3587 *
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003588 * \returns the parent of a sub-module or NULL if the given module is top-level,
3589 * e.g. for 'std.vector' it will return the 'std' module.
3590 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003591CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003592
3593/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003594 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003595 *
3596 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3597 * will return "vector".
3598 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003599CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003600
3601/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003602 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003603 *
3604 * \returns the full name of the module, e.g. "std.vector".
3605 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003606CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003607
3608/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003609 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003610 *
3611 * \returns the number of top level headers associated with this module.
3612 */
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003613CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3614 CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003615
3616/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003617 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003618 *
3619 * \param Index top level header index (zero-based).
3620 *
3621 * \returns the specified top level header associated with the module.
3622 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003623CINDEX_LINKAGE
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003624CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3625 CXModule Module, unsigned Index);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003626
3627/**
3628 * @}
3629 */
3630
3631/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003632 * \defgroup CINDEX_COMMENT Comment AST introspection
3633 *
3634 * The routines in this group provide access to information in the
3635 * documentation comment ASTs.
3636 *
3637 * @{
3638 */
3639
3640/**
3641 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3642 * node can be considered block content (e. g., paragraph), inline content
3643 * (plain text) or neither (the root AST node).
3644 */
3645enum CXCommentKind {
3646 /**
3647 * \brief Null comment. No AST node is constructed at the requested location
3648 * because there is no text or a syntax error.
3649 */
3650 CXComment_Null = 0,
3651
3652 /**
3653 * \brief Plain text. Inline content.
3654 */
3655 CXComment_Text = 1,
3656
3657 /**
3658 * \brief A command with word-like arguments that is considered inline content.
3659 *
3660 * For example: \\c command.
3661 */
3662 CXComment_InlineCommand = 2,
3663
3664 /**
3665 * \brief HTML start tag with attributes (name-value pairs). Considered
3666 * inline content.
3667 *
3668 * For example:
3669 * \verbatim
3670 * <br> <br /> <a href="http://example.org/">
3671 * \endverbatim
3672 */
3673 CXComment_HTMLStartTag = 3,
3674
3675 /**
3676 * \brief HTML end tag. Considered inline content.
3677 *
3678 * For example:
3679 * \verbatim
3680 * </a>
3681 * \endverbatim
3682 */
3683 CXComment_HTMLEndTag = 4,
3684
3685 /**
3686 * \brief A paragraph, contains inline comment. The paragraph itself is
3687 * block content.
3688 */
3689 CXComment_Paragraph = 5,
3690
3691 /**
3692 * \brief A command that has zero or more word-like arguments (number of
3693 * word-like arguments depends on command name) and a paragraph as an
3694 * argument. Block command is block content.
3695 *
3696 * Paragraph argument is also a child of the block command.
3697 *
3698 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3699 *
3700 * AST nodes of special kinds that parser knows about (e. g., \\param
3701 * command) have their own node kinds.
3702 */
3703 CXComment_BlockCommand = 6,
3704
3705 /**
3706 * \brief A \\param or \\arg command that describes the function parameter
3707 * (name, passing direction, description).
3708 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003709 * For example: \\param [in] ParamName description.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003710 */
3711 CXComment_ParamCommand = 7,
3712
3713 /**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003714 * \brief A \\tparam command that describes a template parameter (name and
3715 * description).
3716 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003717 * For example: \\tparam T description.
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003718 */
3719 CXComment_TParamCommand = 8,
3720
3721 /**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003722 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3723 * block has an opening and a closing command and contains multiple lines of
3724 * text (\c CXComment_VerbatimBlockLine child nodes).
3725 *
3726 * For example:
3727 * \\verbatim
3728 * aaa
3729 * \\endverbatim
3730 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003731 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003732
3733 /**
3734 * \brief A line of text that is contained within a
3735 * CXComment_VerbatimBlockCommand node.
3736 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003737 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003738
3739 /**
3740 * \brief A verbatim line command. Verbatim line has an opening command,
3741 * a single line of text (up to the newline after the opening command) and
3742 * has no closing command.
3743 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003744 CXComment_VerbatimLine = 11,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003745
3746 /**
3747 * \brief A full comment attached to a declaration, contains block content.
3748 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003749 CXComment_FullComment = 12
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003750};
3751
3752/**
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003753 * \brief The most appropriate rendering mode for an inline command, chosen on
3754 * command semantics in Doxygen.
3755 */
3756enum CXCommentInlineCommandRenderKind {
3757 /**
3758 * \brief Command argument should be rendered in a normal font.
3759 */
3760 CXCommentInlineCommandRenderKind_Normal,
3761
3762 /**
3763 * \brief Command argument should be rendered in a bold font.
3764 */
3765 CXCommentInlineCommandRenderKind_Bold,
3766
3767 /**
3768 * \brief Command argument should be rendered in a monospaced font.
3769 */
3770 CXCommentInlineCommandRenderKind_Monospaced,
3771
3772 /**
3773 * \brief Command argument should be rendered emphasized (typically italic
3774 * font).
3775 */
3776 CXCommentInlineCommandRenderKind_Emphasized
3777};
3778
3779/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003780 * \brief Describes parameter passing direction for \\param or \\arg command.
3781 */
3782enum CXCommentParamPassDirection {
3783 /**
3784 * \brief The parameter is an input parameter.
3785 */
3786 CXCommentParamPassDirection_In,
3787
3788 /**
3789 * \brief The parameter is an output parameter.
3790 */
3791 CXCommentParamPassDirection_Out,
3792
3793 /**
3794 * \brief The parameter is an input and output parameter.
3795 */
3796 CXCommentParamPassDirection_InOut
3797};
3798
3799/**
3800 * \param Comment AST node of any kind.
3801 *
3802 * \returns the type of the AST node.
3803 */
3804CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3805
3806/**
3807 * \param Comment AST node of any kind.
3808 *
3809 * \returns number of children of the AST node.
3810 */
3811CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3812
3813/**
3814 * \param Comment AST node of any kind.
3815 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003816 * \param ChildIdx child index (zero-based).
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003817 *
3818 * \returns the specified child of the AST node.
3819 */
3820CINDEX_LINKAGE
3821CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3822
3823/**
3824 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3825 * only \c CXComment_Text nodes that are empty or whitespace.
3826 *
3827 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3828 * never considered whitespace.
3829 *
3830 * \returns non-zero if \c Comment is whitespace.
3831 */
3832CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3833
3834/**
3835 * \returns non-zero if \c Comment is inline content and has a newline
3836 * immediately following it in the comment text. Newlines between paragraphs
3837 * do not count.
3838 */
3839CINDEX_LINKAGE
3840unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3841
3842/**
3843 * \param Comment a \c CXComment_Text AST node.
3844 *
3845 * \returns text contained in the AST node.
3846 */
3847CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3848
3849/**
3850 * \param Comment a \c CXComment_InlineCommand AST node.
3851 *
3852 * \returns name of the inline command.
3853 */
3854CINDEX_LINKAGE
3855CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3856
3857/**
3858 * \param Comment a \c CXComment_InlineCommand AST node.
3859 *
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003860 * \returns the most appropriate rendering mode, chosen on command
3861 * semantics in Doxygen.
3862 */
3863CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3864clang_InlineCommandComment_getRenderKind(CXComment Comment);
3865
3866/**
3867 * \param Comment a \c CXComment_InlineCommand AST node.
3868 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003869 * \returns number of command arguments.
3870 */
3871CINDEX_LINKAGE
3872unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3873
3874/**
3875 * \param Comment a \c CXComment_InlineCommand AST node.
3876 *
3877 * \param ArgIdx argument index (zero-based).
3878 *
3879 * \returns text of the specified argument.
3880 */
3881CINDEX_LINKAGE
3882CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3883 unsigned ArgIdx);
3884
3885/**
3886 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3887 * node.
3888 *
3889 * \returns HTML tag name.
3890 */
3891CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3892
3893/**
3894 * \param Comment a \c CXComment_HTMLStartTag AST node.
3895 *
3896 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3897 */
3898CINDEX_LINKAGE
3899unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3900
3901/**
3902 * \param Comment a \c CXComment_HTMLStartTag AST node.
3903 *
3904 * \returns number of attributes (name-value pairs) attached to the start tag.
3905 */
3906CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3907
3908/**
3909 * \param Comment a \c CXComment_HTMLStartTag AST node.
3910 *
3911 * \param AttrIdx attribute index (zero-based).
3912 *
3913 * \returns name of the specified attribute.
3914 */
3915CINDEX_LINKAGE
3916CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3917
3918/**
3919 * \param Comment a \c CXComment_HTMLStartTag AST node.
3920 *
3921 * \param AttrIdx attribute index (zero-based).
3922 *
3923 * \returns value of the specified attribute.
3924 */
3925CINDEX_LINKAGE
3926CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3927
3928/**
3929 * \param Comment a \c CXComment_BlockCommand AST node.
3930 *
3931 * \returns name of the block command.
3932 */
3933CINDEX_LINKAGE
3934CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3935
3936/**
3937 * \param Comment a \c CXComment_BlockCommand AST node.
3938 *
3939 * \returns number of word-like arguments.
3940 */
3941CINDEX_LINKAGE
3942unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3943
3944/**
3945 * \param Comment a \c CXComment_BlockCommand AST node.
3946 *
3947 * \param ArgIdx argument index (zero-based).
3948 *
3949 * \returns text of the specified word-like argument.
3950 */
3951CINDEX_LINKAGE
3952CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3953 unsigned ArgIdx);
3954
3955/**
3956 * \param Comment a \c CXComment_BlockCommand or
3957 * \c CXComment_VerbatimBlockCommand AST node.
3958 *
3959 * \returns paragraph argument of the block command.
3960 */
3961CINDEX_LINKAGE
3962CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3963
3964/**
3965 * \param Comment a \c CXComment_ParamCommand AST node.
3966 *
3967 * \returns parameter name.
3968 */
3969CINDEX_LINKAGE
3970CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3971
3972/**
3973 * \param Comment a \c CXComment_ParamCommand AST node.
3974 *
3975 * \returns non-zero if the parameter that this AST node represents was found
3976 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3977 * function will return a meaningful value.
3978 */
3979CINDEX_LINKAGE
3980unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3981
3982/**
3983 * \param Comment a \c CXComment_ParamCommand AST node.
3984 *
3985 * \returns zero-based parameter index in function prototype.
3986 */
3987CINDEX_LINKAGE
3988unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3989
3990/**
3991 * \param Comment a \c CXComment_ParamCommand AST node.
3992 *
3993 * \returns non-zero if parameter passing direction was specified explicitly in
3994 * the comment.
3995 */
3996CINDEX_LINKAGE
3997unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3998
3999/**
4000 * \param Comment a \c CXComment_ParamCommand AST node.
4001 *
4002 * \returns parameter passing direction.
4003 */
4004CINDEX_LINKAGE
4005enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
4006 CXComment Comment);
4007
4008/**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004009 * \param Comment a \c CXComment_TParamCommand AST node.
4010 *
4011 * \returns template parameter name.
4012 */
4013CINDEX_LINKAGE
4014CXString clang_TParamCommandComment_getParamName(CXComment Comment);
4015
4016/**
4017 * \param Comment a \c CXComment_TParamCommand AST node.
4018 *
4019 * \returns non-zero if the parameter that this AST node represents was found
4020 * in the template parameter list and
4021 * \c clang_TParamCommandComment_getDepth and
4022 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
4023 * value.
4024 */
4025CINDEX_LINKAGE
4026unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
4027
4028/**
4029 * \param Comment a \c CXComment_TParamCommand AST node.
4030 *
4031 * \returns zero-based nesting depth of this parameter in the template parameter list.
4032 *
4033 * For example,
4034 * \verbatim
4035 * template<typename C, template<typename T> class TT>
4036 * void test(TT<int> aaa);
4037 * \endverbatim
4038 * for C and TT nesting depth is 0,
4039 * for T nesting depth is 1.
4040 */
4041CINDEX_LINKAGE
4042unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
4043
4044/**
4045 * \param Comment a \c CXComment_TParamCommand AST node.
4046 *
4047 * \returns zero-based parameter index in the template parameter list at a
4048 * given nesting depth.
4049 *
4050 * For example,
4051 * \verbatim
4052 * template<typename C, template<typename T> class TT>
4053 * void test(TT<int> aaa);
4054 * \endverbatim
4055 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
4056 * at depth 0 C's index is 0, TT's index is 1.
4057 *
4058 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
4059 * at depth 0 T's index is 1 (same as TT's),
4060 * at depth 1 T's index is 0.
4061 */
4062CINDEX_LINKAGE
4063unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
4064
4065/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004066 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
4067 *
4068 * \returns text contained in the AST node.
4069 */
4070CINDEX_LINKAGE
4071CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
4072
4073/**
4074 * \param Comment a \c CXComment_VerbatimLine AST node.
4075 *
4076 * \returns text contained in the AST node.
4077 */
4078CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
4079
4080/**
4081 * \brief Convert an HTML tag AST node to string.
4082 *
4083 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
4084 * node.
4085 *
4086 * \returns string containing an HTML tag.
4087 */
4088CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
4089
4090/**
4091 * \brief Convert a given full parsed comment to an HTML fragment.
4092 *
4093 * Specific details of HTML layout are subject to change. Don't try to parse
4094 * this HTML back into an AST, use other APIs instead.
4095 *
4096 * Currently the following CSS classes are used:
4097 * \li "para-brief" for \\brief paragraph and equivalent commands;
4098 * \li "para-returns" for \\returns paragraph and equivalent commands;
4099 * \li "word-returns" for the "Returns" word in \\returns paragraph.
4100 *
Dmitri Gribenko4c6d7a22012-07-21 01:47:43 +00004101 * Function argument documentation is rendered as a \<dl\> list with arguments
4102 * sorted in function prototype order. CSS classes used:
4103 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
4104 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
4105 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
4106 * parameter index is invalid.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004107 *
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004108 * Template parameter documentation is rendered as a \<dl\> list with
4109 * parameters sorted in template parameter list order. CSS classes used:
4110 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
4111 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko58e41312012-08-01 23:47:30 +00004112 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004113 * names inside template template parameters;
4114 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
4115 * parameter position is invalid.
4116 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004117 * \param Comment a \c CXComment_FullComment AST node.
4118 *
4119 * \returns string containing an HTML fragment.
4120 */
4121CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
4122
4123/**
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004124 * \brief Convert a given full parsed comment to an XML document.
4125 *
4126 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
4127 * inside clang source tree.
4128 *
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004129 * \param Comment a \c CXComment_FullComment AST node.
4130 *
4131 * \returns string containing an XML document.
4132 */
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00004133CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004134
4135/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004136 * @}
4137 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004138
Douglas Gregor6007cf22010-01-22 22:29:16 +00004139/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004140 * \defgroup CINDEX_CPP C++ AST introspection
4141 *
4142 * The routines in this group provide access information in the ASTs specific
4143 * to C++ language features.
4144 *
4145 * @{
4146 */
4147
4148/**
Dmitri Gribenko62770be2013-05-17 18:38:35 +00004149 * \brief Determine if a C++ member function or member function template is
4150 * pure virtual.
4151 */
4152CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4153
4154/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004155 * \brief Determine if a C++ member function or member function template is
4156 * declared 'static'.
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004157 */
4158CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4159
4160/**
Douglas Gregor9519d922011-05-12 15:17:24 +00004161 * \brief Determine if a C++ member function or member function template is
4162 * explicitly declared 'virtual' or if it overrides a virtual method from
4163 * one of the base classes.
4164 */
4165CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4166
4167/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004168 * \brief Given a cursor that represents a template, determine
4169 * the cursor kind of the specializations would be generated by instantiating
4170 * the template.
4171 *
4172 * This routine can be used to determine what flavor of function template,
4173 * class template, or class template partial specialization is stored in the
4174 * cursor. For example, it can describe whether a class template cursor is
4175 * declared with "struct", "class" or "union".
4176 *
4177 * \param C The cursor to query. This cursor should represent a template
4178 * declaration.
4179 *
4180 * \returns The cursor kind of the specializations that would be generated
4181 * by instantiating the template \p C. If \p C is not a template, returns
4182 * \c CXCursor_NoDeclFound.
4183 */
4184CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4185
4186/**
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004187 * \brief Given a cursor that may represent a specialization or instantiation
4188 * of a template, retrieve the cursor that represents the template that it
4189 * specializes or from which it was instantiated.
4190 *
4191 * This routine determines the template involved both for explicit
4192 * specializations of templates and for implicit instantiations of the template,
4193 * both of which are referred to as "specializations". For a class template
4194 * specialization (e.g., \c std::vector<bool>), this routine will return
4195 * either the primary template (\c std::vector) or, if the specialization was
4196 * instantiated from a class template partial specialization, the class template
4197 * partial specialization. For a class template partial specialization and a
4198 * function template specialization (including instantiations), this
4199 * this routine will return the specialized template.
4200 *
4201 * For members of a class template (e.g., member functions, member classes, or
4202 * static data members), returns the specialized or instantiated member.
4203 * Although not strictly "templates" in the C++ language, members of class
4204 * templates have the same notions of specializations and instantiations that
4205 * templates do, so this routine treats them similarly.
4206 *
4207 * \param C A cursor that may be a specialization of a template or a member
4208 * of a template.
4209 *
4210 * \returns If the given cursor is a specialization or instantiation of a
4211 * template or a member thereof, the template or member that it specializes or
4212 * from which it was instantiated. Otherwise, returns a NULL cursor.
4213 */
4214CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004215
4216/**
4217 * \brief Given a cursor that references something else, return the source range
4218 * covering that reference.
4219 *
4220 * \param C A cursor pointing to a member reference, a declaration reference, or
4221 * an operator call.
4222 * \param NameFlags A bitset with three independent flags:
4223 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4224 * CXNameRange_WantSinglePiece.
4225 * \param PieceIndex For contiguous names or when passing the flag
4226 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4227 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer474261a2012-06-02 10:20:41 +00004228 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004229 * pieces of the name. See also CXNameRange_WantSinglePiece.
4230 *
4231 * \returns The piece of the name pointed to by the given cursor. If there is no
4232 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4233 */
Francois Pichetece689f2011-07-25 22:00:44 +00004234CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4235 unsigned NameFlags,
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004236 unsigned PieceIndex);
4237
4238enum CXNameRefFlags {
4239 /**
4240 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4241 * range.
4242 */
4243 CXNameRange_WantQualifier = 0x1,
4244
4245 /**
James Dennett574cb4c2012-06-15 05:41:51 +00004246 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4247 * in the range.
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004248 */
4249 CXNameRange_WantTemplateArgs = 0x2,
4250
4251 /**
4252 * \brief If the name is non-contiguous, return the full spanning range.
4253 *
4254 * Non-contiguous names occur in Objective-C when a selector with two or more
4255 * parameters is used, or in C++ when using an operator:
4256 * \code
4257 * [object doSomething:here withValue:there]; // ObjC
4258 * return some_vector[1]; // C++
4259 * \endcode
4260 */
4261 CXNameRange_WantSinglePiece = 0x4
4262};
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004263
4264/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004265 * @}
4266 */
4267
4268/**
Douglas Gregor61656112010-01-26 18:31:56 +00004269 * \defgroup CINDEX_LEX Token extraction and manipulation
4270 *
4271 * The routines in this group provide access to the tokens within a
4272 * translation unit, along with a semantic mapping of those tokens to
4273 * their corresponding cursors.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004274 *
4275 * @{
4276 */
4277
4278/**
4279 * \brief Describes a kind of token.
4280 */
4281typedef enum CXTokenKind {
4282 /**
4283 * \brief A token that contains some kind of punctuation.
4284 */
4285 CXToken_Punctuation,
Ted Kremenekd071c602010-03-13 02:50:34 +00004286
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004287 /**
Douglas Gregor61656112010-01-26 18:31:56 +00004288 * \brief A language keyword.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004289 */
4290 CXToken_Keyword,
Ted Kremenekd071c602010-03-13 02:50:34 +00004291
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004292 /**
4293 * \brief An identifier (that is not a keyword).
4294 */
4295 CXToken_Identifier,
Ted Kremenekd071c602010-03-13 02:50:34 +00004296
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004297 /**
4298 * \brief A numeric, string, or character literal.
4299 */
4300 CXToken_Literal,
Ted Kremenekd071c602010-03-13 02:50:34 +00004301
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004302 /**
4303 * \brief A comment.
4304 */
4305 CXToken_Comment
4306} CXTokenKind;
4307
4308/**
4309 * \brief Describes a single preprocessing token.
4310 */
4311typedef struct {
4312 unsigned int_data[4];
4313 void *ptr_data;
4314} CXToken;
4315
4316/**
4317 * \brief Determine the kind of the given token.
4318 */
4319CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004320
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004321/**
4322 * \brief Determine the spelling of the given token.
4323 *
4324 * The spelling of a token is the textual representation of that token, e.g.,
4325 * the text of an identifier or keyword.
4326 */
4327CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004328
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004329/**
4330 * \brief Retrieve the source location of the given token.
4331 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004332CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004333 CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004334
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004335/**
4336 * \brief Retrieve a source range that covers the given token.
4337 */
4338CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4339
4340/**
4341 * \brief Tokenize the source code described by the given range into raw
4342 * lexical tokens.
4343 *
4344 * \param TU the translation unit whose text is being tokenized.
4345 *
4346 * \param Range the source range in which text should be tokenized. All of the
4347 * tokens produced by tokenization will fall within this source range,
4348 *
4349 * \param Tokens this pointer will be set to point to the array of tokens
4350 * that occur within the given source range. The returned pointer must be
4351 * freed with clang_disposeTokens() before the translation unit is destroyed.
4352 *
4353 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4354 * array.
4355 *
4356 */
4357CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4358 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004359
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004360/**
4361 * \brief Annotate the given set of tokens by providing cursors for each token
4362 * that can be mapped to a specific entity within the abstract syntax tree.
4363 *
Douglas Gregor61656112010-01-26 18:31:56 +00004364 * This token-annotation routine is equivalent to invoking
4365 * clang_getCursor() for the source locations of each of the
4366 * tokens. The cursors provided are filtered, so that only those
4367 * cursors that have a direct correspondence to the token are
4368 * accepted. For example, given a function call \c f(x),
4369 * clang_getCursor() would provide the following cursors:
4370 *
4371 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4372 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4373 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4374 *
4375 * Only the first and last of these cursors will occur within the
4376 * annotate, since the tokens "f" and "x' directly refer to a function
4377 * and a variable, respectively, but the parentheses are just a small
4378 * part of the full syntax of the function call expression, which is
4379 * not provided as an annotation.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004380 *
4381 * \param TU the translation unit that owns the given tokens.
4382 *
4383 * \param Tokens the set of tokens to annotate.
4384 *
4385 * \param NumTokens the number of tokens in \p Tokens.
4386 *
4387 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4388 * replaced with the cursors corresponding to each token.
4389 */
4390CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4391 CXToken *Tokens, unsigned NumTokens,
4392 CXCursor *Cursors);
Ted Kremenekd071c602010-03-13 02:50:34 +00004393
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004394/**
4395 * \brief Free the given set of tokens.
4396 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004397CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004398 CXToken *Tokens, unsigned NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004399
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004400/**
4401 * @}
4402 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004403
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004404/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004405 * \defgroup CINDEX_DEBUG Debugging facilities
4406 *
4407 * These routines are used for testing and debugging, only, and should not
4408 * be relied upon.
4409 *
4410 * @{
4411 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004412
Steve Naroff76b8f132009-09-23 17:52:52 +00004413/* for debug/testing */
Ted Kremenek29004672010-02-17 00:41:32 +00004414CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004415CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4416 const char **startBuf,
Steve Naroff76b8f132009-09-23 17:52:52 +00004417 const char **endBuf,
4418 unsigned *startLine,
4419 unsigned *startColumn,
4420 unsigned *endLine,
4421 unsigned *endColumn);
Douglas Gregor1e21cc72010-02-18 23:07:20 +00004422CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar23420652010-11-04 01:26:29 +00004423CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4424 unsigned stack_size);
4425
Douglas Gregor9eb77012009-11-07 00:00:49 +00004426/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004427 * @}
4428 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004429
Douglas Gregor6007cf22010-01-22 22:29:16 +00004430/**
4431 * \defgroup CINDEX_CODE_COMPLET Code completion
4432 *
4433 * Code completion involves taking an (incomplete) source file, along with
4434 * knowledge of where the user is actively editing that file, and suggesting
4435 * syntactically- and semantically-valid constructs that the user might want to
4436 * use at that particular point in the source code. These data structures and
4437 * routines provide support for code completion.
4438 *
4439 * @{
4440 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004441
Douglas Gregor6007cf22010-01-22 22:29:16 +00004442/**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004443 * \brief A semantic string that describes a code-completion result.
4444 *
4445 * A semantic string that describes the formatting of a code-completion
4446 * result as a single "template" of text that should be inserted into the
4447 * source buffer when a particular code-completion result is selected.
4448 * Each semantic string is made up of some number of "chunks", each of which
4449 * contains some text along with a description of what that text means, e.g.,
4450 * the name of the entity being referenced, whether the text chunk is part of
4451 * the template, or whether it is a "placeholder" that the user should replace
4452 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004453 * description of the different kinds of chunks.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004454 */
4455typedef void *CXCompletionString;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004456
Douglas Gregor9eb77012009-11-07 00:00:49 +00004457/**
4458 * \brief A single result of code completion.
4459 */
4460typedef struct {
4461 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004462 * \brief The kind of entity that this completion refers to.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004463 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004464 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor9eb77012009-11-07 00:00:49 +00004465 * *Decl cursor kinds), describing the entity that the completion is
4466 * referring to.
4467 *
4468 * \todo In the future, we would like to provide a full cursor, to allow
4469 * the client to extract additional information from declaration.
4470 */
4471 enum CXCursorKind CursorKind;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004472
4473 /**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004474 * \brief The code-completion string that describes how to insert this
4475 * code-completion result into the editing buffer.
4476 */
4477 CXCompletionString CompletionString;
4478} CXCompletionResult;
4479
4480/**
4481 * \brief Describes a single piece of text within a code-completion string.
4482 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004483 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4484 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor9eb77012009-11-07 00:00:49 +00004485 * should be interpreted by the client or is another completion string.
4486 */
4487enum CXCompletionChunkKind {
4488 /**
4489 * \brief A code-completion string that describes "optional" text that
4490 * could be a part of the template (but is not required).
4491 *
4492 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004493 * string for its representation, which is accessible via
Douglas Gregor9eb77012009-11-07 00:00:49 +00004494 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4495 * describes an additional part of the template that is completely optional.
4496 * For example, optional chunks can be used to describe the placeholders for
4497 * arguments that match up with defaulted function parameters, e.g. given:
4498 *
4499 * \code
4500 * void f(int x, float y = 3.14, double z = 2.71828);
4501 * \endcode
4502 *
4503 * The code-completion string for this function would contain:
4504 * - a TypedText chunk for "f".
4505 * - a LeftParen chunk for "(".
4506 * - a Placeholder chunk for "int x"
4507 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4508 * - a Comma chunk for ","
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004509 * - a Placeholder chunk for "float y"
Douglas Gregor9eb77012009-11-07 00:00:49 +00004510 * - an Optional chunk containing the last defaulted argument:
4511 * - a Comma chunk for ","
4512 * - a Placeholder chunk for "double z"
4513 * - a RightParen chunk for ")"
4514 *
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004515 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor9eb77012009-11-07 00:00:49 +00004516 * - Completely ignore optional chunks, in which case the template for the
4517 * function "f" would only include the first parameter ("int x").
4518 * - Fully expand all optional chunks, in which case the template for the
4519 * function "f" would have all of the parameters.
4520 */
4521 CXCompletionChunk_Optional,
4522 /**
4523 * \brief Text that a user would be expected to type to get this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004524 * code-completion result.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004525 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004526 * There will be exactly one "typed text" chunk in a semantic string, which
4527 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004528 * declaration that could be used at the current code point. Clients are
4529 * expected to filter the code-completion results based on the text in this
4530 * chunk.
4531 */
4532 CXCompletionChunk_TypedText,
4533 /**
4534 * \brief Text that should be inserted as part of a code-completion result.
4535 *
4536 * A "text" chunk represents text that is part of the template to be
4537 * inserted into user code should this particular code-completion result
4538 * be selected.
4539 */
4540 CXCompletionChunk_Text,
4541 /**
4542 * \brief Placeholder text that should be replaced by the user.
4543 *
4544 * A "placeholder" chunk marks a place where the user should insert text
4545 * into the code-completion template. For example, placeholders might mark
4546 * the function parameters for a function declaration, to indicate that the
4547 * user should provide arguments for each of those parameters. The actual
4548 * text in a placeholder is a suggestion for the text to display before
4549 * the user replaces the placeholder with real code.
4550 */
4551 CXCompletionChunk_Placeholder,
4552 /**
4553 * \brief Informative text that should be displayed but never inserted as
4554 * part of the template.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004555 *
Douglas Gregor9eb77012009-11-07 00:00:49 +00004556 * An "informative" chunk contains annotations that can be displayed to
4557 * help the user decide whether a particular code-completion result is the
4558 * right option, but which is not part of the actual template to be inserted
4559 * by code completion.
4560 */
4561 CXCompletionChunk_Informative,
4562 /**
4563 * \brief Text that describes the current parameter when code-completion is
4564 * referring to function call, message send, or template specialization.
4565 *
4566 * A "current parameter" chunk occurs when code-completion is providing
4567 * information about a parameter corresponding to the argument at the
4568 * code-completion point. For example, given a function
4569 *
4570 * \code
4571 * int add(int x, int y);
4572 * \endcode
4573 *
4574 * and the source code \c add(, where the code-completion point is after the
4575 * "(", the code-completion string will contain a "current parameter" chunk
4576 * for "int x", indicating that the current argument will initialize that
4577 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004578 * point is after the ","), the code-completion string will contain a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004579 * "current paremeter" chunk to "int y".
4580 */
4581 CXCompletionChunk_CurrentParameter,
4582 /**
4583 * \brief A left parenthesis ('('), used to initiate a function call or
4584 * signal the beginning of a function parameter list.
4585 */
4586 CXCompletionChunk_LeftParen,
4587 /**
4588 * \brief A right parenthesis (')'), used to finish a function call or
4589 * signal the end of a function parameter list.
4590 */
4591 CXCompletionChunk_RightParen,
4592 /**
4593 * \brief A left bracket ('[').
4594 */
4595 CXCompletionChunk_LeftBracket,
4596 /**
4597 * \brief A right bracket (']').
4598 */
4599 CXCompletionChunk_RightBracket,
4600 /**
4601 * \brief A left brace ('{').
4602 */
4603 CXCompletionChunk_LeftBrace,
4604 /**
4605 * \brief A right brace ('}').
4606 */
4607 CXCompletionChunk_RightBrace,
4608 /**
4609 * \brief A left angle bracket ('<').
4610 */
4611 CXCompletionChunk_LeftAngle,
4612 /**
4613 * \brief A right angle bracket ('>').
4614 */
4615 CXCompletionChunk_RightAngle,
4616 /**
4617 * \brief A comma separator (',').
4618 */
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004619 CXCompletionChunk_Comma,
4620 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004621 * \brief Text that specifies the result type of a given result.
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004622 *
4623 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004624 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004625 * expression using the given completion string would have.
4626 */
Douglas Gregor504a6ae2010-01-10 23:08:15 +00004627 CXCompletionChunk_ResultType,
4628 /**
4629 * \brief A colon (':').
4630 */
4631 CXCompletionChunk_Colon,
4632 /**
4633 * \brief A semicolon (';').
4634 */
4635 CXCompletionChunk_SemiColon,
4636 /**
4637 * \brief An '=' sign.
4638 */
4639 CXCompletionChunk_Equal,
4640 /**
4641 * Horizontal space (' ').
4642 */
4643 CXCompletionChunk_HorizontalSpace,
4644 /**
4645 * Vertical space ('\n'), after which it is generally a good idea to
4646 * perform indentation.
4647 */
4648 CXCompletionChunk_VerticalSpace
Douglas Gregor9eb77012009-11-07 00:00:49 +00004649};
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004650
Douglas Gregor9eb77012009-11-07 00:00:49 +00004651/**
4652 * \brief Determine the kind of a particular chunk within a completion string.
4653 *
4654 * \param completion_string the completion string to query.
4655 *
4656 * \param chunk_number the 0-based index of the chunk in the completion string.
4657 *
4658 * \returns the kind of the chunk at the index \c chunk_number.
4659 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004660CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor9eb77012009-11-07 00:00:49 +00004661clang_getCompletionChunkKind(CXCompletionString completion_string,
4662 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004663
Douglas Gregor9eb77012009-11-07 00:00:49 +00004664/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004665 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004666 * completion string.
4667 *
4668 * \param completion_string the completion string to query.
4669 *
4670 * \param chunk_number the 0-based index of the chunk in the completion string.
4671 *
4672 * \returns the text associated with the chunk at index \c chunk_number.
4673 */
Ted Kremenekf602f962010-02-17 01:42:24 +00004674CINDEX_LINKAGE CXString
Douglas Gregor9eb77012009-11-07 00:00:49 +00004675clang_getCompletionChunkText(CXCompletionString completion_string,
4676 unsigned chunk_number);
4677
4678/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004679 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor9eb77012009-11-07 00:00:49 +00004680 * within a completion string.
4681 *
4682 * \param completion_string the completion string to query.
4683 *
4684 * \param chunk_number the 0-based index of the chunk in the completion string.
4685 *
4686 * \returns the completion string associated with the chunk at index
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004687 * \c chunk_number.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004688 */
4689CINDEX_LINKAGE CXCompletionString
4690clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4691 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004692
Douglas Gregor9eb77012009-11-07 00:00:49 +00004693/**
4694 * \brief Retrieve the number of chunks in the given code-completion string.
4695 */
4696CINDEX_LINKAGE unsigned
4697clang_getNumCompletionChunks(CXCompletionString completion_string);
4698
4699/**
Douglas Gregora2db7932010-05-26 22:00:08 +00004700 * \brief Determine the priority of this code completion.
4701 *
4702 * The priority of a code completion indicates how likely it is that this
4703 * particular completion is the completion that the user will select. The
4704 * priority is selected by various internal heuristics.
4705 *
4706 * \param completion_string The completion string to query.
4707 *
4708 * \returns The priority of this completion string. Smaller values indicate
4709 * higher-priority (more likely) completions.
4710 */
4711CINDEX_LINKAGE unsigned
4712clang_getCompletionPriority(CXCompletionString completion_string);
4713
4714/**
Douglas Gregorf757a122010-08-23 23:00:57 +00004715 * \brief Determine the availability of the entity that this code-completion
4716 * string refers to.
4717 *
4718 * \param completion_string The completion string to query.
4719 *
4720 * \returns The availability of the completion string.
4721 */
4722CINDEX_LINKAGE enum CXAvailabilityKind
4723clang_getCompletionAvailability(CXCompletionString completion_string);
4724
4725/**
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004726 * \brief Retrieve the number of annotations associated with the given
4727 * completion string.
4728 *
4729 * \param completion_string the completion string to query.
4730 *
4731 * \returns the number of annotations associated with the given completion
4732 * string.
4733 */
4734CINDEX_LINKAGE unsigned
4735clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4736
4737/**
4738 * \brief Retrieve the annotation associated with the given completion string.
4739 *
4740 * \param completion_string the completion string to query.
4741 *
4742 * \param annotation_number the 0-based index of the annotation of the
4743 * completion string.
4744 *
4745 * \returns annotation string associated with the completion at index
4746 * \c annotation_number, or a NULL string if that annotation is not available.
4747 */
4748CINDEX_LINKAGE CXString
4749clang_getCompletionAnnotation(CXCompletionString completion_string,
4750 unsigned annotation_number);
4751
4752/**
Douglas Gregor78254c82012-03-27 23:34:16 +00004753 * \brief Retrieve the parent context of the given completion string.
4754 *
4755 * The parent context of a completion string is the semantic parent of
4756 * the declaration (if any) that the code completion represents. For example,
4757 * a code completion for an Objective-C method would have the method's class
4758 * or protocol as its context.
4759 *
4760 * \param completion_string The code completion string whose parent is
4761 * being queried.
4762 *
Argyrios Kyrtzidis9ae39562012-09-26 16:39:56 +00004763 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregor78254c82012-03-27 23:34:16 +00004764 *
James Dennett574cb4c2012-06-15 05:41:51 +00004765 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregor78254c82012-03-27 23:34:16 +00004766 * the completion string represents a method in the NSObject class.
4767 */
4768CINDEX_LINKAGE CXString
4769clang_getCompletionParent(CXCompletionString completion_string,
4770 enum CXCursorKind *kind);
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004771
4772/**
4773 * \brief Retrieve the brief documentation comment attached to the declaration
4774 * that corresponds to the given completion string.
4775 */
4776CINDEX_LINKAGE CXString
4777clang_getCompletionBriefComment(CXCompletionString completion_string);
4778
Douglas Gregor78254c82012-03-27 23:34:16 +00004779/**
Douglas Gregor3f35bb22011-08-04 20:04:59 +00004780 * \brief Retrieve a completion string for an arbitrary declaration or macro
4781 * definition cursor.
4782 *
4783 * \param cursor The cursor to query.
4784 *
4785 * \returns A non-context-sensitive completion string for declaration and macro
4786 * definition cursors, or NULL for other kinds of cursors.
4787 */
4788CINDEX_LINKAGE CXCompletionString
4789clang_getCursorCompletionString(CXCursor cursor);
4790
4791/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004792 * \brief Contains the results of code-completion.
4793 *
4794 * This data structure contains the results of code completion, as
Douglas Gregor6a9580282010-10-11 21:51:20 +00004795 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004796 * \c clang_disposeCodeCompleteResults.
4797 */
4798typedef struct {
4799 /**
4800 * \brief The code-completion results.
4801 */
4802 CXCompletionResult *Results;
4803
4804 /**
4805 * \brief The number of code-completion results stored in the
4806 * \c Results array.
4807 */
4808 unsigned NumResults;
4809} CXCodeCompleteResults;
4810
4811/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004812 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4813 * modify its behavior.
4814 *
4815 * The enumerators in this enumeration can be bitwise-OR'd together to
4816 * provide multiple options to \c clang_codeCompleteAt().
4817 */
4818enum CXCodeComplete_Flags {
4819 /**
4820 * \brief Whether to include macros within the set of code
4821 * completions returned.
4822 */
4823 CXCodeComplete_IncludeMacros = 0x01,
4824
4825 /**
4826 * \brief Whether to include code patterns for language constructs
4827 * within the set of code completions, e.g., for loops.
4828 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004829 CXCodeComplete_IncludeCodePatterns = 0x02,
4830
4831 /**
4832 * \brief Whether to include brief documentation within the set of code
4833 * completions returned.
4834 */
4835 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorb68bc592010-08-05 09:09:23 +00004836};
4837
4838/**
Douglas Gregor21325842011-07-07 16:03:39 +00004839 * \brief Bits that represent the context under which completion is occurring.
4840 *
4841 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4842 * contexts are occurring simultaneously.
4843 */
4844enum CXCompletionContext {
4845 /**
4846 * \brief The context for completions is unexposed, as only Clang results
4847 * should be included. (This is equivalent to having no context bits set.)
4848 */
4849 CXCompletionContext_Unexposed = 0,
4850
4851 /**
4852 * \brief Completions for any possible type should be included in the results.
4853 */
4854 CXCompletionContext_AnyType = 1 << 0,
4855
4856 /**
4857 * \brief Completions for any possible value (variables, function calls, etc.)
4858 * should be included in the results.
4859 */
4860 CXCompletionContext_AnyValue = 1 << 1,
4861 /**
4862 * \brief Completions for values that resolve to an Objective-C object should
4863 * be included in the results.
4864 */
4865 CXCompletionContext_ObjCObjectValue = 1 << 2,
4866 /**
4867 * \brief Completions for values that resolve to an Objective-C selector
4868 * should be included in the results.
4869 */
4870 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4871 /**
4872 * \brief Completions for values that resolve to a C++ class type should be
4873 * included in the results.
4874 */
4875 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4876
4877 /**
4878 * \brief Completions for fields of the member being accessed using the dot
4879 * operator should be included in the results.
4880 */
4881 CXCompletionContext_DotMemberAccess = 1 << 5,
4882 /**
4883 * \brief Completions for fields of the member being accessed using the arrow
4884 * operator should be included in the results.
4885 */
4886 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4887 /**
4888 * \brief Completions for properties of the Objective-C object being accessed
4889 * using the dot operator should be included in the results.
4890 */
4891 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4892
4893 /**
4894 * \brief Completions for enum tags should be included in the results.
4895 */
4896 CXCompletionContext_EnumTag = 1 << 8,
4897 /**
4898 * \brief Completions for union tags should be included in the results.
4899 */
4900 CXCompletionContext_UnionTag = 1 << 9,
4901 /**
4902 * \brief Completions for struct tags should be included in the results.
4903 */
4904 CXCompletionContext_StructTag = 1 << 10,
4905
4906 /**
4907 * \brief Completions for C++ class names should be included in the results.
4908 */
4909 CXCompletionContext_ClassTag = 1 << 11,
4910 /**
4911 * \brief Completions for C++ namespaces and namespace aliases should be
4912 * included in the results.
4913 */
4914 CXCompletionContext_Namespace = 1 << 12,
4915 /**
4916 * \brief Completions for C++ nested name specifiers should be included in
4917 * the results.
4918 */
4919 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4920
4921 /**
4922 * \brief Completions for Objective-C interfaces (classes) should be included
4923 * in the results.
4924 */
4925 CXCompletionContext_ObjCInterface = 1 << 14,
4926 /**
4927 * \brief Completions for Objective-C protocols should be included in
4928 * the results.
4929 */
4930 CXCompletionContext_ObjCProtocol = 1 << 15,
4931 /**
4932 * \brief Completions for Objective-C categories should be included in
4933 * the results.
4934 */
4935 CXCompletionContext_ObjCCategory = 1 << 16,
4936 /**
4937 * \brief Completions for Objective-C instance messages should be included
4938 * in the results.
4939 */
4940 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4941 /**
4942 * \brief Completions for Objective-C class messages should be included in
4943 * the results.
4944 */
4945 CXCompletionContext_ObjCClassMessage = 1 << 18,
4946 /**
4947 * \brief Completions for Objective-C selector names should be included in
4948 * the results.
4949 */
4950 CXCompletionContext_ObjCSelectorName = 1 << 19,
4951
4952 /**
4953 * \brief Completions for preprocessor macro names should be included in
4954 * the results.
4955 */
4956 CXCompletionContext_MacroName = 1 << 20,
4957
4958 /**
4959 * \brief Natural language completions should be included in the results.
4960 */
4961 CXCompletionContext_NaturalLanguage = 1 << 21,
4962
4963 /**
4964 * \brief The current context is unknown, so set all contexts.
4965 */
4966 CXCompletionContext_Unknown = ((1 << 22) - 1)
4967};
4968
4969/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004970 * \brief Returns a default set of code-completion options that can be
4971 * passed to\c clang_codeCompleteAt().
4972 */
4973CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4974
4975/**
Douglas Gregor8e984da2010-08-04 16:47:14 +00004976 * \brief Perform code completion at a given location in a translation unit.
4977 *
4978 * This function performs code completion at a particular file, line, and
4979 * column within source code, providing results that suggest potential
4980 * code snippets based on the context of the completion. The basic model
4981 * for code completion is that Clang will parse a complete source file,
4982 * performing syntax checking up to the location where code-completion has
4983 * been requested. At that point, a special code-completion token is passed
4984 * to the parser, which recognizes this token and determines, based on the
4985 * current location in the C/Objective-C/C++ grammar and the state of
4986 * semantic analysis, what completions to provide. These completions are
4987 * returned via a new \c CXCodeCompleteResults structure.
4988 *
4989 * Code completion itself is meant to be triggered by the client when the
4990 * user types punctuation characters or whitespace, at which point the
4991 * code-completion location will coincide with the cursor. For example, if \c p
4992 * is a pointer, code-completion might be triggered after the "-" and then
4993 * after the ">" in \c p->. When the code-completion location is afer the ">",
4994 * the completion results will provide, e.g., the members of the struct that
4995 * "p" points to. The client is responsible for placing the cursor at the
4996 * beginning of the token currently being typed, then filtering the results
4997 * based on the contents of the token. For example, when code-completing for
4998 * the expression \c p->get, the client should provide the location just after
4999 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
5000 * client can filter the results based on the current token text ("get"), only
5001 * showing those results that start with "get". The intent of this interface
5002 * is to separate the relatively high-latency acquisition of code-completion
5003 * results from the filtering of results on a per-character basis, which must
5004 * have a lower latency.
5005 *
5006 * \param TU The translation unit in which code-completion should
5007 * occur. The source files for this translation unit need not be
5008 * completely up-to-date (and the contents of those source files may
5009 * be overridden via \p unsaved_files). Cursors referring into the
5010 * translation unit may be invalidated by this invocation.
5011 *
5012 * \param complete_filename The name of the source file where code
5013 * completion should be performed. This filename may be any file
5014 * included in the translation unit.
5015 *
5016 * \param complete_line The line at which code-completion should occur.
5017 *
5018 * \param complete_column The column at which code-completion should occur.
5019 * Note that the column should point just after the syntactic construct that
5020 * initiated code completion, and not in the middle of a lexical token.
5021 *
5022 * \param unsaved_files the Tiles that have not yet been saved to disk
5023 * but may be required for parsing or code completion, including the
5024 * contents of those files. The contents and name of these files (as
5025 * specified by CXUnsavedFile) are copied when necessary, so the
5026 * client only needs to guarantee their validity until the call to
5027 * this function returns.
5028 *
5029 * \param num_unsaved_files The number of unsaved file entries in \p
5030 * unsaved_files.
5031 *
Douglas Gregorb68bc592010-08-05 09:09:23 +00005032 * \param options Extra options that control the behavior of code
5033 * completion, expressed as a bitwise OR of the enumerators of the
5034 * CXCodeComplete_Flags enumeration. The
5035 * \c clang_defaultCodeCompleteOptions() function returns a default set
5036 * of code-completion options.
5037 *
Douglas Gregor8e984da2010-08-04 16:47:14 +00005038 * \returns If successful, a new \c CXCodeCompleteResults structure
5039 * containing code-completion results, which should eventually be
5040 * freed with \c clang_disposeCodeCompleteResults(). If code
5041 * completion fails, returns NULL.
5042 */
5043CINDEX_LINKAGE
5044CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
5045 const char *complete_filename,
5046 unsigned complete_line,
5047 unsigned complete_column,
5048 struct CXUnsavedFile *unsaved_files,
Douglas Gregorb68bc592010-08-05 09:09:23 +00005049 unsigned num_unsaved_files,
5050 unsigned options);
Douglas Gregor8e984da2010-08-04 16:47:14 +00005051
5052/**
Douglas Gregor49f67ce2010-08-26 13:48:20 +00005053 * \brief Sort the code-completion results in case-insensitive alphabetical
5054 * order.
5055 *
5056 * \param Results The set of results to sort.
5057 * \param NumResults The number of results in \p Results.
5058 */
5059CINDEX_LINKAGE
5060void clang_sortCodeCompletionResults(CXCompletionResult *Results,
5061 unsigned NumResults);
5062
5063/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00005064 * \brief Free the given set of code-completion results.
5065 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005066CINDEX_LINKAGE
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00005067void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregorf757a122010-08-23 23:00:57 +00005068
Douglas Gregor52606ff2010-01-20 01:10:47 +00005069/**
Douglas Gregor33cdd812010-02-18 18:08:43 +00005070 * \brief Determine the number of diagnostics produced prior to the
5071 * location where code completion was performed.
5072 */
Ted Kremenekd071c602010-03-13 02:50:34 +00005073CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00005074unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
5075
5076/**
5077 * \brief Retrieve a diagnostic associated with the given code completion.
5078 *
James Dennett574cb4c2012-06-15 05:41:51 +00005079 * \param Results the code completion results to query.
Douglas Gregor33cdd812010-02-18 18:08:43 +00005080 * \param Index the zero-based diagnostic number to retrieve.
5081 *
5082 * \returns the requested diagnostic. This diagnostic must be freed
5083 * via a call to \c clang_disposeDiagnostic().
5084 */
Ted Kremenekd071c602010-03-13 02:50:34 +00005085CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00005086CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
5087 unsigned Index);
5088
5089/**
Douglas Gregor21325842011-07-07 16:03:39 +00005090 * \brief Determines what compeltions are appropriate for the context
5091 * the given code completion.
5092 *
5093 * \param Results the code completion results to query
5094 *
5095 * \returns the kinds of completions that are appropriate for use
5096 * along with the given code completion results.
5097 */
5098CINDEX_LINKAGE
5099unsigned long long clang_codeCompleteGetContexts(
5100 CXCodeCompleteResults *Results);
Douglas Gregor63745d52011-07-21 01:05:26 +00005101
5102/**
5103 * \brief Returns the cursor kind for the container for the current code
5104 * completion context. The container is only guaranteed to be set for
5105 * contexts where a container exists (i.e. member accesses or Objective-C
5106 * message sends); if there is not a container, this function will return
5107 * CXCursor_InvalidCode.
5108 *
5109 * \param Results the code completion results to query
5110 *
5111 * \param IsIncomplete on return, this value will be false if Clang has complete
5112 * information about the container. If Clang does not have complete
5113 * information, this value will be true.
5114 *
5115 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5116 * container
5117 */
5118CINDEX_LINKAGE
5119enum CXCursorKind clang_codeCompleteGetContainerKind(
5120 CXCodeCompleteResults *Results,
5121 unsigned *IsIncomplete);
5122
5123/**
5124 * \brief Returns the USR for the container for the current code completion
5125 * context. If there is not a container for the current context, this
5126 * function will return the empty string.
5127 *
5128 * \param Results the code completion results to query
5129 *
5130 * \returns the USR for the container
5131 */
5132CINDEX_LINKAGE
5133CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor21325842011-07-07 16:03:39 +00005134
Douglas Gregorea777402011-07-26 15:24:30 +00005135
5136/**
5137 * \brief Returns the currently-entered selector for an Objective-C message
5138 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5139 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5140 * CXCompletionContext_ObjCClassMessage.
5141 *
5142 * \param Results the code completion results to query
5143 *
5144 * \returns the selector (or partial selector) that has been entered thus far
5145 * for an Objective-C message send.
5146 */
5147CINDEX_LINKAGE
5148CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5149
Douglas Gregor21325842011-07-07 16:03:39 +00005150/**
Douglas Gregor52606ff2010-01-20 01:10:47 +00005151 * @}
5152 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005153
5154
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005155/**
5156 * \defgroup CINDEX_MISC Miscellaneous utility functions
5157 *
5158 * @{
5159 */
Ted Kremenek3e315a22010-01-23 17:51:23 +00005160
5161/**
5162 * \brief Return a version string, suitable for showing to a user, but not
5163 * intended to be parsed (the format is not guaranteed to be stable).
5164 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +00005165CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005166
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005167
5168/**
5169 * \brief Enable/disable crash recovery.
5170 *
James Dennett574cb4c2012-06-15 05:41:51 +00005171 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5172 * value enables crash recovery, while 0 disables it.
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005173 */
5174CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5175
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005176 /**
Ted Kremenekd071c602010-03-13 02:50:34 +00005177 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005178 * (used with clang_getInclusions()).
5179 *
5180 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett574cb4c2012-06-15 05:41:51 +00005181 * file included (either at the top-level or by \#include directives) within
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005182 * a translation unit. The first argument is the file being included, and
5183 * the second and third arguments provide the inclusion stack. The
5184 * array is sorted in order of immediate inclusion. For example,
5185 * the first element refers to the location that included 'included_file'.
5186 */
5187typedef void (*CXInclusionVisitor)(CXFile included_file,
5188 CXSourceLocation* inclusion_stack,
5189 unsigned include_len,
5190 CXClientData client_data);
5191
5192/**
5193 * \brief Visit the set of preprocessor inclusions in a translation unit.
5194 * The visitor function is called with the provided data for every included
5195 * file. This does not include headers included by the PCH file (unless one
5196 * is inspecting the inclusions in the PCH file itself).
5197 */
5198CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5199 CXInclusionVisitor visitor,
5200 CXClientData client_data);
5201
5202/**
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005203 * @}
5204 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005205
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005206/** \defgroup CINDEX_REMAPPING Remapping functions
5207 *
5208 * @{
5209 */
5210
5211/**
5212 * \brief A remapping of original source files and their translated files.
5213 */
5214typedef void *CXRemapping;
5215
5216/**
5217 * \brief Retrieve a remapping.
5218 *
5219 * \param path the path that contains metadata about remappings.
5220 *
5221 * \returns the requested remapping. This remapping must be freed
5222 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5223 */
5224CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5225
5226/**
Ted Kremenekf7639e12012-03-06 20:06:33 +00005227 * \brief Retrieve a remapping.
5228 *
5229 * \param filePaths pointer to an array of file paths containing remapping info.
5230 *
5231 * \param numFiles number of file paths.
5232 *
5233 * \returns the requested remapping. This remapping must be freed
5234 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5235 */
5236CINDEX_LINKAGE
5237CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5238 unsigned numFiles);
5239
5240/**
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005241 * \brief Determine the number of remappings.
5242 */
5243CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5244
5245/**
5246 * \brief Get the original and the associated filename from the remapping.
5247 *
5248 * \param original If non-NULL, will be set to the original filename.
5249 *
5250 * \param transformed If non-NULL, will be set to the filename that the original
5251 * is associated with.
5252 */
5253CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5254 CXString *original, CXString *transformed);
5255
5256/**
5257 * \brief Dispose the remapping.
5258 */
5259CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5260
5261/**
5262 * @}
5263 */
5264
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005265/** \defgroup CINDEX_HIGH Higher level API functions
5266 *
5267 * @{
5268 */
5269
5270enum CXVisitorResult {
5271 CXVisit_Break,
5272 CXVisit_Continue
5273};
5274
5275typedef struct {
5276 void *context;
5277 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5278} CXCursorAndRangeVisitor;
5279
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005280typedef enum {
5281 /**
5282 * \brief Function returned successfully.
5283 */
5284 CXResult_Success = 0,
5285 /**
5286 * \brief One of the parameters was invalid for the function.
5287 */
5288 CXResult_Invalid = 1,
5289 /**
5290 * \brief The function was terminated by a callback (e.g. it returned
5291 * CXVisit_Break)
5292 */
5293 CXResult_VisitBreak = 2
5294
5295} CXResult;
5296
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005297/**
5298 * \brief Find references of a declaration in a specific file.
5299 *
5300 * \param cursor pointing to a declaration or a reference of one.
5301 *
5302 * \param file to search for references.
5303 *
5304 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5305 * each reference found.
5306 * The CXSourceRange will point inside the file; if the reference is inside
5307 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005308 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005309 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005310 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005311CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5312 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005313
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005314/**
5315 * \brief Find #import/#include directives in a specific file.
5316 *
5317 * \param TU translation unit containing the file to query.
5318 *
5319 * \param file to search for #import/#include directives.
5320 *
5321 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5322 * each directive found.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005323 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005324 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005325 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005326CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5327 CXFile file,
5328 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005329
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005330#ifdef __has_feature
5331# if __has_feature(blocks)
5332
5333typedef enum CXVisitorResult
5334 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5335
5336CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005337CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5338 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005339
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005340CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005341CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5342 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005343
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005344# endif
5345#endif
5346
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005347/**
5348 * \brief The client's data object that is associated with a CXFile.
5349 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005350typedef void *CXIdxClientFile;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005351
5352/**
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005353 * \brief The client's data object that is associated with a semantic entity.
5354 */
5355typedef void *CXIdxClientEntity;
5356
5357/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005358 * \brief The client's data object that is associated with a semantic container
5359 * of entities.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005360 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005361typedef void *CXIdxClientContainer;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005362
5363/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005364 * \brief The client's data object that is associated with an AST file (PCH
5365 * or module).
5366 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005367typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005368
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005369/**
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005370 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005371 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005372typedef struct {
5373 void *ptr_data[2];
5374 unsigned int_data;
5375} CXIdxLoc;
5376
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005377/**
James Dennett574cb4c2012-06-15 05:41:51 +00005378 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005379 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005380typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005381 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005382 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005383 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005384 CXIdxLoc hashLoc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005385 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005386 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005387 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005388 const char *filename;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005389 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005390 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005391 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005392 CXFile file;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005393 int isImport;
5394 int isAngled;
Argyrios Kyrtzidis5e2ec482012-10-18 00:17:05 +00005395 /**
5396 * \brief Non-zero if the directive was automatically turned into a module
5397 * import.
5398 */
5399 int isModuleImport;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005400} CXIdxIncludedFileInfo;
5401
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005402/**
James Dennett574cb4c2012-06-15 05:41:51 +00005403 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005404 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005405typedef struct {
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005406 /**
5407 * \brief Top level AST file containing the imported PCH, module or submodule.
5408 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005409 CXFile file;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005410 /**
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005411 * \brief The imported module or NULL if the AST file is a PCH.
5412 */
5413 CXModule module;
5414 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005415 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005416 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005417 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005418 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005419 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005420 * a module import. Applicable only for modules.
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005421 */
Argyrios Kyrtzidis184b1442012-10-03 21:05:44 +00005422 int isImplicit;
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005423
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005424} CXIdxImportedASTFileInfo;
5425
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005426typedef enum {
5427 CXIdxEntity_Unexposed = 0,
5428 CXIdxEntity_Typedef = 1,
5429 CXIdxEntity_Function = 2,
5430 CXIdxEntity_Variable = 3,
5431 CXIdxEntity_Field = 4,
5432 CXIdxEntity_EnumConstant = 5,
5433
5434 CXIdxEntity_ObjCClass = 6,
5435 CXIdxEntity_ObjCProtocol = 7,
5436 CXIdxEntity_ObjCCategory = 8,
5437
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005438 CXIdxEntity_ObjCInstanceMethod = 9,
5439 CXIdxEntity_ObjCClassMethod = 10,
5440 CXIdxEntity_ObjCProperty = 11,
5441 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005442
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005443 CXIdxEntity_Enum = 13,
5444 CXIdxEntity_Struct = 14,
5445 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005446
5447 CXIdxEntity_CXXClass = 16,
5448 CXIdxEntity_CXXNamespace = 17,
5449 CXIdxEntity_CXXNamespaceAlias = 18,
5450 CXIdxEntity_CXXStaticVariable = 19,
5451 CXIdxEntity_CXXStaticMethod = 20,
5452 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matose9a3ed42012-08-31 22:18:20 +00005453 CXIdxEntity_CXXConstructor = 22,
5454 CXIdxEntity_CXXDestructor = 23,
5455 CXIdxEntity_CXXConversionFunction = 24,
5456 CXIdxEntity_CXXTypeAlias = 25,
5457 CXIdxEntity_CXXInterface = 26
5458
5459} CXIdxEntityKind;
5460
Argyrios Kyrtzidis52002882011-12-07 20:44:12 +00005461typedef enum {
5462 CXIdxEntityLang_None = 0,
5463 CXIdxEntityLang_C = 1,
5464 CXIdxEntityLang_ObjC = 2,
5465 CXIdxEntityLang_CXX = 3
5466} CXIdxEntityLanguage;
5467
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005468/**
5469 * \brief Extra C++ template information for an entity. This can apply to:
5470 * CXIdxEntity_Function
5471 * CXIdxEntity_CXXClass
5472 * CXIdxEntity_CXXStaticMethod
5473 * CXIdxEntity_CXXInstanceMethod
5474 * CXIdxEntity_CXXConstructor
5475 * CXIdxEntity_CXXConversionFunction
5476 * CXIdxEntity_CXXTypeAlias
5477 */
5478typedef enum {
5479 CXIdxEntity_NonTemplate = 0,
5480 CXIdxEntity_Template = 1,
5481 CXIdxEntity_TemplatePartialSpecialization = 2,
5482 CXIdxEntity_TemplateSpecialization = 3
5483} CXIdxEntityCXXTemplateKind;
5484
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005485typedef enum {
5486 CXIdxAttr_Unexposed = 0,
5487 CXIdxAttr_IBAction = 1,
5488 CXIdxAttr_IBOutlet = 2,
5489 CXIdxAttr_IBOutletCollection = 3
5490} CXIdxAttrKind;
5491
5492typedef struct {
5493 CXIdxAttrKind kind;
5494 CXCursor cursor;
5495 CXIdxLoc loc;
5496} CXIdxAttrInfo;
5497
5498typedef struct {
Argyrios Kyrtzidis4d873b72011-12-15 00:05:00 +00005499 CXIdxEntityKind kind;
5500 CXIdxEntityCXXTemplateKind templateKind;
5501 CXIdxEntityLanguage lang;
5502 const char *name;
5503 const char *USR;
5504 CXCursor cursor;
5505 const CXIdxAttrInfo *const *attributes;
5506 unsigned numAttributes;
5507} CXIdxEntityInfo;
5508
5509typedef struct {
5510 CXCursor cursor;
5511} CXIdxContainerInfo;
5512
5513typedef struct {
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005514 const CXIdxAttrInfo *attrInfo;
5515 const CXIdxEntityInfo *objcClass;
5516 CXCursor classCursor;
5517 CXIdxLoc classLoc;
5518} CXIdxIBOutletCollectionAttrInfo;
5519
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005520typedef enum {
5521 CXIdxDeclFlag_Skipped = 0x1
5522} CXIdxDeclInfoFlags;
5523
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005524typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005525 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005526 CXCursor cursor;
5527 CXIdxLoc loc;
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005528 const CXIdxContainerInfo *semanticContainer;
5529 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005530 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005531 * cases like out-of-line C++ member functions.
5532 */
5533 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005534 int isRedeclaration;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005535 int isDefinition;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005536 int isContainer;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005537 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005538 /**
5539 * \brief Whether the declaration exists in code or was created implicitly
5540 * by the compiler, e.g. implicit objc methods for properties.
5541 */
5542 int isImplicit;
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005543 const CXIdxAttrInfo *const *attributes;
5544 unsigned numAttributes;
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005545
5546 unsigned flags;
5547
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005548} CXIdxDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005549
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005550typedef enum {
5551 CXIdxObjCContainer_ForwardRef = 0,
5552 CXIdxObjCContainer_Interface = 1,
5553 CXIdxObjCContainer_Implementation = 2
5554} CXIdxObjCContainerKind;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005555
5556typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005557 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005558 CXIdxObjCContainerKind kind;
5559} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005560
5561typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005562 const CXIdxEntityInfo *base;
5563 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005564 CXIdxLoc loc;
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005565} CXIdxBaseClassInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005566
5567typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005568 const CXIdxEntityInfo *protocol;
5569 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005570 CXIdxLoc loc;
5571} CXIdxObjCProtocolRefInfo;
5572
5573typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005574 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005575 unsigned numProtocols;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005576} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005577
5578typedef struct {
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005579 const CXIdxObjCContainerDeclInfo *containerInfo;
5580 const CXIdxBaseClassInfo *superInfo;
5581 const CXIdxObjCProtocolRefListInfo *protocols;
5582} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005583
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005584typedef struct {
Argyrios Kyrtzidis9b9f7a92011-12-13 18:47:45 +00005585 const CXIdxObjCContainerDeclInfo *containerInfo;
5586 const CXIdxEntityInfo *objcClass;
5587 CXCursor classCursor;
5588 CXIdxLoc classLoc;
5589 const CXIdxObjCProtocolRefListInfo *protocols;
5590} CXIdxObjCCategoryDeclInfo;
5591
5592typedef struct {
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005593 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005594 const CXIdxEntityInfo *getter;
5595 const CXIdxEntityInfo *setter;
5596} CXIdxObjCPropertyDeclInfo;
5597
5598typedef struct {
5599 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005600 const CXIdxBaseClassInfo *const *bases;
5601 unsigned numBases;
5602} CXIdxCXXClassDeclInfo;
5603
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005604/**
James Dennett574cb4c2012-06-15 05:41:51 +00005605 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005606 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005607typedef enum {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005608 /**
5609 * \brief The entity is referenced directly in user's code.
5610 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005611 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005612 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005613 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5614 * dot syntax.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005615 */
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005616 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005617} CXIdxEntityRefKind;
5618
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005619/**
James Dennett574cb4c2012-06-15 05:41:51 +00005620 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005621 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005622typedef struct {
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005623 CXIdxEntityRefKind kind;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005624 /**
5625 * \brief Reference cursor.
5626 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005627 CXCursor cursor;
5628 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005629 /**
5630 * \brief The entity that gets referenced.
5631 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005632 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005633 /**
5634 * \brief Immediate "parent" of the reference. For example:
5635 *
5636 * \code
5637 * Foo *var;
5638 * \endcode
5639 *
5640 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005641 * For references inside statement bodies of functions/methods,
5642 * the parentEntity will be the function/method.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005643 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005644 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005645 /**
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005646 * \brief Lexical container context of the reference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005647 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005648 const CXIdxContainerInfo *container;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005649} CXIdxEntityRefInfo;
5650
James Dennett574cb4c2012-06-15 05:41:51 +00005651/**
5652 * \brief A group of callbacks used by #clang_indexSourceFile and
5653 * #clang_indexTranslationUnit.
5654 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005655typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005656 /**
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005657 * \brief Called periodically to check whether indexing should be aborted.
5658 * Should return 0 to continue, and non-zero to abort.
5659 */
5660 int (*abortQuery)(CXClientData client_data, void *reserved);
5661
5662 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005663 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005664 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005665 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005666 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005667
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005668 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett574cb4c2012-06-15 05:41:51 +00005669 CXFile mainFile, void *reserved);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005670
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005671 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005672 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005673 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005674 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005675 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005676
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005677 /**
5678 * \brief Called when a AST file (PCH or module) gets imported.
5679 *
5680 * AST files will not get indexed (there will not be callbacks to index all
5681 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005682 * file is not already indexed, to initiate a new indexing job specific to
5683 * the AST file.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005684 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005685 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005686 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005687
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005688 /**
5689 * \brief Called at the beginning of indexing a translation unit.
5690 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005691 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005692 void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005693
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005694 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005695 const CXIdxDeclInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005696
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005697 /**
5698 * \brief Called to index a reference of an entity.
5699 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005700 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005701 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005702
5703} IndexerCallbacks;
5704
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005705CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005706CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5707clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005708
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005709CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5710clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5711
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005712CINDEX_LINKAGE
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005713const CXIdxObjCCategoryDeclInfo *
5714clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5715
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005716CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5717clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005718
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005719CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5720clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5721
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005722CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5723clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5724
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005725CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5726clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5727
5728/**
5729 * \brief For retrieving a custom CXIdxClientContainer attached to a
5730 * container.
5731 */
5732CINDEX_LINKAGE CXIdxClientContainer
5733clang_index_getClientContainer(const CXIdxContainerInfo *);
5734
5735/**
5736 * \brief For setting a custom CXIdxClientContainer attached to a
5737 * container.
5738 */
5739CINDEX_LINKAGE void
5740clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5741
5742/**
5743 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5744 */
5745CINDEX_LINKAGE CXIdxClientEntity
5746clang_index_getClientEntity(const CXIdxEntityInfo *);
5747
5748/**
5749 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5750 */
5751CINDEX_LINKAGE void
5752clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5753
5754/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005755 * \brief An indexing action/session, to be applied to one or multiple
5756 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005757 */
5758typedef void *CXIndexAction;
5759
5760/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005761 * \brief An indexing action/session, to be applied to one or multiple
5762 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005763 *
5764 * \param CIdx The index object with which the index action will be associated.
5765 */
5766CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5767
5768/**
5769 * \brief Destroy the given index action.
5770 *
5771 * The index action must not be destroyed until all of the translation units
5772 * created within that index action have been destroyed.
5773 */
5774CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5775
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005776typedef enum {
5777 /**
5778 * \brief Used to indicate that no special indexing options are needed.
5779 */
5780 CXIndexOpt_None = 0x0,
5781
5782 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005783 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5784 * be invoked for only one reference of an entity per source file that does
5785 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005786 */
Argyrios Kyrtzidisfb7d1452012-01-14 00:11:49 +00005787 CXIndexOpt_SuppressRedundantRefs = 0x1,
5788
5789 /**
5790 * \brief Function-local symbols should be indexed. If this is not set
5791 * function-local symbols will be ignored.
5792 */
Argyrios Kyrtzidis7e747952012-02-14 22:23:11 +00005793 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5794
5795 /**
5796 * \brief Implicit function/class template instantiations should be indexed.
5797 * If this is not set, implicit instantiations will be ignored.
5798 */
Argyrios Kyrtzidis6c9ed7d2012-03-27 21:38:03 +00005799 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5800
5801 /**
5802 * \brief Suppress all compiler warnings when parsing for indexing.
5803 */
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005804 CXIndexOpt_SuppressWarnings = 0x8,
5805
5806 /**
5807 * \brief Skip a function/method body that was already parsed during an
5808 * indexing session assosiated with a \c CXIndexAction object.
5809 * Bodies in system headers are always skipped.
5810 */
5811 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5812
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005813} CXIndexOptFlags;
5814
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005815/**
5816 * \brief Index the given source file and the translation unit corresponding
James Dennett574cb4c2012-06-15 05:41:51 +00005817 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005818 *
5819 * \param client_data pointer data supplied by the client, which will
5820 * be passed to the invoked callbacks.
5821 *
5822 * \param index_callbacks Pointer to indexing callbacks that the client
5823 * implements.
5824 *
James Dennett574cb4c2012-06-15 05:41:51 +00005825 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005826 * passed in index_callbacks.
5827 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005828 * \param index_options A bitmask of options that affects how indexing is
5829 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005830 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00005831 * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be
5832 * reused after indexing is finished. Set to \c NULL if you do not require it.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005833 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00005834 * \returns 0 on success or if there were errors from which the compiler could
5835 * recover. If there is a failure from which the there is no recovery, returns
5836 * a non-zero \c CXErrorCode.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005837 *
James Dennett574cb4c2012-06-15 05:41:51 +00005838 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005839 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005840CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005841 CXClientData client_data,
5842 IndexerCallbacks *index_callbacks,
5843 unsigned index_callbacks_size,
5844 unsigned index_options,
5845 const char *source_filename,
5846 const char * const *command_line_args,
5847 int num_command_line_args,
5848 struct CXUnsavedFile *unsaved_files,
5849 unsigned num_unsaved_files,
5850 CXTranslationUnit *out_TU,
5851 unsigned TU_options);
5852
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005853/**
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005854 * \brief Index the given translation unit via callbacks implemented through
James Dennett574cb4c2012-06-15 05:41:51 +00005855 * #IndexerCallbacks.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005856 *
5857 * The order of callback invocations is not guaranteed to be the same as
5858 * when indexing a source file. The high level order will be:
5859 *
5860 * -Preprocessor callbacks invocations
5861 * -Declaration/reference callbacks invocations
5862 * -Diagnostic callback invocations
5863 *
James Dennett574cb4c2012-06-15 05:41:51 +00005864 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005865 *
5866 * \returns If there is a failure from which the there is no recovery, returns
5867 * non-zero, otherwise returns 0.
5868 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005869CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005870 CXClientData client_data,
5871 IndexerCallbacks *index_callbacks,
5872 unsigned index_callbacks_size,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005873 unsigned index_options,
5874 CXTranslationUnit);
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005875
5876/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005877 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5878 * the given CXIdxLoc.
5879 *
5880 * If the location refers into a macro expansion, retrieves the
5881 * location of the macro expansion and if it refers into a macro argument
5882 * retrieves the location of the argument.
5883 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005884CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005885 CXIdxClientFile *indexFile,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005886 CXFile *file,
5887 unsigned *line,
5888 unsigned *column,
5889 unsigned *offset);
5890
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005891/**
5892 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5893 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005894CINDEX_LINKAGE
5895CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5896
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005897/**
5898 * @}
5899 */
5900
Douglas Gregor6007cf22010-01-22 22:29:16 +00005901/**
5902 * @}
5903 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005904
Ted Kremenekb60d87c2009-08-26 22:36:44 +00005905#ifdef __cplusplus
5906}
5907#endif
5908#endif
5909