blob: 21b7dba0763172eb6d5ed37d8a5b81110d91bdd8 [file] [log] [blame]
Ted Kremenekd2fa5662009-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
Steve Naroff88145032009-10-27 14:35:18 +000019#include <sys/stat.h>
Chandler Carruth3d315602009-12-17 09:27:29 +000020#include <time.h>
Douglas Gregor0a812cf2010-02-18 23:07:20 +000021#include <stdio.h>
Steve Naroff88145032009-10-27 14:35:18 +000022
Arnaud A. de Grandmaisondb2a6852012-06-28 22:01:06 +000023#include "clang-c/Platform.h"
24#include "clang-c/CXString.h"
25
Argyrios Kyrtzidis4d9eff52012-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 Kyrtzidisca9805a2012-10-29 23:24:44 +000034#define CINDEX_VERSION_MAJOR 0
Argyrios Kyrtzidisedab0472013-04-23 17:57:17 +000035#define CINDEX_VERSION_MINOR 19
Argyrios Kyrtzidisca9805a2012-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 Kremenekd2fa5662009-08-26 22:36:44 +000054#ifdef __cplusplus
55extern "C" {
56#endif
57
Douglas Gregor87fb9402011-02-23 17:45:25 +000058/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000059 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000060 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-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 Gregor20d416c2010-01-20 01:10:47 +000065 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000066 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-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 Dunbar1efcf3d2010-01-24 02:54:26 +000070 *
71 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000072 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000073 *
74 * @{
75 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000076
Douglas Gregor7f173762010-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 Naroff600866c2009-08-27 19:51:58 +000082
Douglas Gregor7f173762010-01-20 22:28:27 +000083/**
84 * \brief A single translation unit, which resides in an index.
85 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000086typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000087
Douglas Gregor7f173762010-01-20 22:28:27 +000088/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000089 * \brief Opaque pointer representing client data that will be passed through
90 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000091 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000092typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000093
Douglas Gregor735df882009-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000102 /**
103 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +0000104 *
105 * This file must already exist in the file system.
106 */
107 const char *Filename;
108
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000109 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000110 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +0000111 */
112 const char *Contents;
113
114 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000115 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +0000116 */
117 unsigned long Length;
118};
119
Peter Collingbourne076c22a2010-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 Gregor58ddb602010-08-23 23:00:57 +0000125enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000126 /**
127 * \brief The entity is available.
128 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000129 CXAvailability_Available,
Peter Collingbourne076c22a2010-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 Gregor58ddb602010-08-23 23:00:57 +0000134 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000135 /**
136 * \brief The entity is not available; any use of it will be an error.
137 */
Erik Verbruggend1205962011-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 Gregor58ddb602010-08-23 23:00:57 +0000144};
Douglas Gregorcc889662012-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 Gregor58ddb602010-08-23 23:00:57 +0000168
Douglas Gregor7f173762010-01-20 22:28:27 +0000169/**
James Dennett7eee0182012-06-15 05:41:51 +0000170 * \brief Provides a shared context for creating translation units.
171 *
172 * It provides two options:
Steve Naroffe56b4ba2009-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000176 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000177 * header that was used by the translation unit. If zero, all declarations
178 * will be enumerated.
179 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000180 * Here is an example:
181 *
James Dennett7eee0182012-06-15 05:41:51 +0000182 * \code
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000183 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
184 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000191 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000192 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-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 Dunbarfd9f2342010-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 Gregorb2cd4872010-01-20 23:57:43 +0000200 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
201 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000202 * clang_disposeTranslationUnit(TU);
James Dennett7eee0182012-06-15 05:41:51 +0000203 * \endcode
Steve Naroffb4ece632009-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 Naroffe56b4ba2009-10-20 14:46:24 +0000208 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000209CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
210 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000211
Douglas Gregor0087e1a2010-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 Dunbar8506dde2009-12-03 01:54:28 +0000218CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000219
Argyrios Kyrtzidisfdc17952012-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 Dennett7eee0182012-06-15 05:41:51 +0000229 *
230 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
231 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
Argyrios Kyrtzidisfdc17952012-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 Dennett7eee0182012-06-15 05:41:51 +0000238 *
239 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
240 * #clang_annotateTokens
Argyrios Kyrtzidisfdc17952012-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 Dennett7eee0182012-06-15 05:41:51 +0000255 * \brief Sets general options associated with a CXIndex.
Argyrios Kyrtzidisfdc17952012-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000277/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000278 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000279 *
280 * @{
281 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000282
Douglas Gregorf5525442010-01-20 22:45:41 +0000283/**
284 * \brief A particular source file that is part of a translation unit.
285 */
286typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000287
Douglas Gregorf5525442010-01-20 22:45:41 +0000288
289/**
290 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000291 */
Ted Kremenek74844072010-02-17 00:41:20 +0000292CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000293
Douglas Gregorf5525442010-01-20 22:45:41 +0000294/**
295 * \brief Retrieve the last modification time of the given file.
296 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000297CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000298
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000299/**
Argyrios Kyrtzidisdb84e7a2013-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 Gregordd3e5542011-05-04 00:14:37 +0000318 * \brief Determine whether the given header is guarded against
319 * multiple inclusions, either with the conventional
James Dennett7eee0182012-06-15 05:41:51 +0000320 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
Douglas Gregordd3e5542011-05-04 00:14:37 +0000321 */
322CINDEX_LINKAGE unsigned
323clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
324
325/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000326 * \brief Retrieve a file handle within the given translation unit.
327 *
328 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000329 *
Douglas Gregorb9790342010-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000335CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000336 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000337
Douglas Gregorb9790342010-01-22 21:44:22 +0000338/**
Douglas Gregorf5525442010-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000354
Douglas Gregorf5525442010-01-20 22:45:41 +0000355/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000356 * \brief Identifies a specific source location within a translation
357 * unit.
358 *
Chandler Carruth20174222011-08-31 16:53:37 +0000359 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregora9b06d42010-11-09 06:24:54 +0000360 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000361 */
362typedef struct {
Argyrios Kyrtzidise2748282013-01-11 22:29:47 +0000363 const void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000364 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000365} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000366
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000367/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000368 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000369 *
Douglas Gregor1db19de2010-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 Gregor3c7313d2010-01-18 22:13:09 +0000372 */
373typedef struct {
Argyrios Kyrtzidise2748282013-01-11 22:29:47 +0000374 const void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000375 unsigned begin_int_data;
376 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000377} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000378
Douglas Gregor1db19de2010-01-19 21:36:55 +0000379/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000380 * \brief Retrieve a NULL (invalid) source location.
381 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +0000382CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000383
Douglas Gregorb9790342010-01-22 21:44:22 +0000384/**
James Dennett7eee0182012-06-15 05:41:51 +0000385 * \brief Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000386 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000394
Douglas Gregorb9790342010-01-22 21:44:22 +0000395/**
Daniel Dunbar1efcf3d2010-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 Gregorb9790342010-01-22 21:44:22 +0000398 */
399CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
400 CXFile file,
401 unsigned line,
402 unsigned column);
David Chisnall83889a72010-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 Dunbar1efcf3d2010-01-24 02:54:26 +0000410
Douglas Gregorb9790342010-01-22 21:44:22 +0000411/**
Argyrios Kyrtzidis4522f632013-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/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000417 * \brief Retrieve a NULL (invalid) source range.
418 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +0000419CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000420
Douglas Gregor5352ac02010-01-28 00:27:43 +0000421/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000422 * \brief Retrieve a source range given the beginning and ending source
423 * locations.
424 */
425CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
426 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000427
Douglas Gregorb9790342010-01-22 21:44:22 +0000428/**
Douglas Gregorab4e83b2011-07-23 19:35:14 +0000429 * \brief Determine whether two ranges are equivalent.
430 *
431 * \returns non-zero if the ranges are the same, zero if they differ.
432 */
433CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
434 CXSourceRange range2);
435
436/**
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000437 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000438 */
Erik Verbruggen733dbc82011-10-06 12:11:57 +0000439CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000440
441/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000442 * \brief Retrieve the file, line, column, and offset represented by
443 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000444 *
Chandler Carruth20174222011-08-31 16:53:37 +0000445 * If the location refers into a macro expansion, retrieves the
446 * location of the macro expansion.
Douglas Gregora9b06d42010-11-09 06:24:54 +0000447 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000448 * \param location the location within a source file that will be decomposed
449 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000450 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000451 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000452 * source location points.
453 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000454 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000455 * source location points.
456 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000457 * \param column [out] if non-NULL, will be set to the column to which the given
458 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000459 *
460 * \param offset [out] if non-NULL, will be set to the offset into the
461 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000462 */
Chandler Carruth20174222011-08-31 16:53:37 +0000463CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
464 CXFile *file,
465 unsigned *line,
466 unsigned *column,
467 unsigned *offset);
468
469/**
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000470 * \brief Retrieve the file, line, column, and offset represented by
471 * the given source location, as specified in a # line directive.
472 *
473 * Example: given the following source code in a file somefile.c
474 *
James Dennett7eee0182012-06-15 05:41:51 +0000475 * \code
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000476 * #123 "dummy.c" 1
477 *
478 * static int func(void)
479 * {
480 * return 0;
481 * }
James Dennett7eee0182012-06-15 05:41:51 +0000482 * \endcode
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000483 *
484 * the location information returned by this function would be
485 *
486 * File: dummy.c Line: 124 Column: 12
487 *
488 * whereas clang_getExpansionLocation would have returned
489 *
490 * File: somefile.c Line: 3 Column: 12
491 *
492 * \param location the location within a source file that will be decomposed
493 * into its parts.
494 *
495 * \param filename [out] if non-NULL, will be set to the filename of the
496 * source location. Note that filenames returned will be for "virtual" files,
497 * which don't necessarily exist on the machine running clang - e.g. when
498 * parsing preprocessed output obtained from a different environment. If
499 * a non-NULL value is passed in, remember to dispose of the returned value
500 * using \c clang_disposeString() once you've finished with it. For an invalid
501 * source location, an empty string is returned.
502 *
503 * \param line [out] if non-NULL, will be set to the line number of the
504 * source location. For an invalid source location, zero is returned.
505 *
506 * \param column [out] if non-NULL, will be set to the column number of the
507 * source location. For an invalid source location, zero is returned.
508 */
509CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
510 CXString *filename,
511 unsigned *line,
512 unsigned *column);
513
514/**
Chandler Carruth20174222011-08-31 16:53:37 +0000515 * \brief Legacy API to retrieve the file, line, column, and offset represented
516 * by the given source location.
517 *
518 * This interface has been replaced by the newer interface
James Dennett7eee0182012-06-15 05:41:51 +0000519 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth20174222011-08-31 16:53:37 +0000520 * details.
521 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000522CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
523 CXFile *file,
524 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000525 unsigned *column,
526 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000527
528/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000529 * \brief Retrieve the file, line, column, and offset represented by
530 * the given source location.
531 *
532 * If the location refers into a macro instantiation, return where the
533 * location was originally spelled in the source file.
534 *
535 * \param location the location within a source file that will be decomposed
536 * into its parts.
537 *
538 * \param file [out] if non-NULL, will be set to the file to which the given
539 * source location points.
540 *
541 * \param line [out] if non-NULL, will be set to the line to which the given
542 * source location points.
543 *
544 * \param column [out] if non-NULL, will be set to the column to which the given
545 * source location points.
546 *
547 * \param offset [out] if non-NULL, will be set to the offset into the
548 * buffer to which the given source location points.
549 */
550CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
551 CXFile *file,
552 unsigned *line,
553 unsigned *column,
554 unsigned *offset);
555
556/**
Argyrios Kyrtzidis2d5c1332013-01-04 18:30:13 +0000557 * \brief Retrieve the file, line, column, and offset represented by
558 * the given source location.
559 *
560 * If the location refers into a macro expansion, return where the macro was
561 * expanded or where the macro argument was written, if the location points at
562 * a macro argument.
563 *
564 * \param location the location within a source file that will be decomposed
565 * into its parts.
566 *
567 * \param file [out] if non-NULL, will be set to the file to which the given
568 * source location points.
569 *
570 * \param line [out] if non-NULL, will be set to the line to which the given
571 * source location points.
572 *
573 * \param column [out] if non-NULL, will be set to the column to which the given
574 * source location points.
575 *
576 * \param offset [out] if non-NULL, will be set to the offset into the
577 * buffer to which the given source location points.
578 */
579CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
580 CXFile *file,
581 unsigned *line,
582 unsigned *column,
583 unsigned *offset);
584
585/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000586 * \brief Retrieve a source location representing the first character within a
587 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000588 */
589CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
590
591/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000592 * \brief Retrieve a source location representing the last character within a
593 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000594 */
595CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
596
Douglas Gregorf5525442010-01-20 22:45:41 +0000597/**
598 * @}
599 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000600
601/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000602 * \defgroup CINDEX_DIAG Diagnostic reporting
603 *
604 * @{
605 */
606
607/**
608 * \brief Describes the severity of a particular diagnostic.
609 */
610enum CXDiagnosticSeverity {
611 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000612 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000613 * option.
614 */
615 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000616
Douglas Gregor5352ac02010-01-28 00:27:43 +0000617 /**
618 * \brief This diagnostic is a note that should be attached to the
619 * previous (non-note) diagnostic.
620 */
621 CXDiagnostic_Note = 1,
622
623 /**
624 * \brief This diagnostic indicates suspicious code that may not be
625 * wrong.
626 */
627 CXDiagnostic_Warning = 2,
628
629 /**
630 * \brief This diagnostic indicates that the code is ill-formed.
631 */
632 CXDiagnostic_Error = 3,
633
634 /**
635 * \brief This diagnostic indicates that the code is ill-formed such
636 * that future parser recovery is unlikely to produce useful
637 * results.
638 */
639 CXDiagnostic_Fatal = 4
640};
641
642/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000643 * \brief A single diagnostic, containing the diagnostic's severity,
644 * location, text, source ranges, and fix-it hints.
645 */
646typedef void *CXDiagnostic;
647
648/**
Ted Kremenek15322172011-11-10 08:43:12 +0000649 * \brief A group of CXDiagnostics.
650 */
651typedef void *CXDiagnosticSet;
652
653/**
654 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
655 */
656CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
657
658/**
659 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
660 *
James Dennett7eee0182012-06-15 05:41:51 +0000661 * \param Diags the CXDiagnosticSet to query.
Ted Kremenek15322172011-11-10 08:43:12 +0000662 * \param Index the zero-based diagnostic number to retrieve.
663 *
664 * \returns the requested diagnostic. This diagnostic must be freed
665 * via a call to \c clang_disposeDiagnostic().
666 */
667CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
668 unsigned Index);
669
670
671/**
672 * \brief Describes the kind of error that occurred (if any) in a call to
673 * \c clang_loadDiagnostics.
674 */
675enum CXLoadDiag_Error {
676 /**
677 * \brief Indicates that no error occurred.
678 */
679 CXLoadDiag_None = 0,
680
681 /**
682 * \brief Indicates that an unknown error occurred while attempting to
683 * deserialize diagnostics.
684 */
685 CXLoadDiag_Unknown = 1,
686
687 /**
688 * \brief Indicates that the file containing the serialized diagnostics
689 * could not be opened.
690 */
691 CXLoadDiag_CannotLoad = 2,
692
693 /**
694 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett7eee0182012-06-15 05:41:51 +0000695 * corrupt.
Ted Kremenek15322172011-11-10 08:43:12 +0000696 */
697 CXLoadDiag_InvalidFile = 3
698};
699
700/**
701 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett7eee0182012-06-15 05:41:51 +0000702 * file.
Ted Kremenek15322172011-11-10 08:43:12 +0000703 *
James Dennett7eee0182012-06-15 05:41:51 +0000704 * \param file The name of the file to deserialize.
705 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenek15322172011-11-10 08:43:12 +0000706 * deserializing the diagnostics.
James Dennett7eee0182012-06-15 05:41:51 +0000707 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenek15322172011-11-10 08:43:12 +0000708 * if the file was not successfully loaded.
709 *
710 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett7eee0182012-06-15 05:41:51 +0000711 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenek15322172011-11-10 08:43:12 +0000712 */
713CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
714 enum CXLoadDiag_Error *error,
715 CXString *errorString);
716
717/**
718 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
719 */
720CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
721
722/**
James Dennett7eee0182012-06-15 05:41:51 +0000723 * \brief Retrieve the child diagnostics of a CXDiagnostic.
724 *
725 * This CXDiagnosticSet does not need to be released by
726 * clang_diposeDiagnosticSet.
Ted Kremenek15322172011-11-10 08:43:12 +0000727 */
728CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
729
730/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000731 * \brief Determine the number of diagnostics produced for the given
732 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000733 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000734CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
735
736/**
737 * \brief Retrieve a diagnostic associated with the given translation unit.
738 *
739 * \param Unit the translation unit to query.
740 * \param Index the zero-based diagnostic number to retrieve.
741 *
742 * \returns the requested diagnostic. This diagnostic must be freed
743 * via a call to \c clang_disposeDiagnostic().
744 */
745CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
746 unsigned Index);
747
748/**
Ted Kremenek0373fcc2011-12-09 22:28:32 +0000749 * \brief Retrieve the complete set of diagnostics associated with a
750 * translation unit.
751 *
752 * \param Unit the translation unit to query.
753 */
754CINDEX_LINKAGE CXDiagnosticSet
755 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
756
757/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000758 * \brief Destroy a diagnostic.
759 */
760CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000761
762/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000763 * \brief Options to control the display of diagnostics.
764 *
765 * The values in this enum are meant to be combined to customize the
766 * behavior of \c clang_displayDiagnostic().
767 */
768enum CXDiagnosticDisplayOptions {
769 /**
770 * \brief Display the source-location information where the
771 * diagnostic was located.
772 *
773 * When set, diagnostics will be prefixed by the file, line, and
774 * (optionally) column to which the diagnostic refers. For example,
775 *
776 * \code
777 * test.c:28: warning: extra tokens at end of #endif directive
778 * \endcode
779 *
780 * This option corresponds to the clang flag \c -fshow-source-location.
781 */
782 CXDiagnostic_DisplaySourceLocation = 0x01,
783
784 /**
785 * \brief If displaying the source-location information of the
786 * diagnostic, also include the column number.
787 *
788 * This option corresponds to the clang flag \c -fshow-column.
789 */
790 CXDiagnostic_DisplayColumn = 0x02,
791
792 /**
793 * \brief If displaying the source-location information of the
794 * diagnostic, also include information about source ranges in a
795 * machine-parsable format.
796 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000797 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000798 * \c -fdiagnostics-print-source-range-info.
799 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000800 CXDiagnostic_DisplaySourceRanges = 0x04,
801
802 /**
803 * \brief Display the option name associated with this diagnostic, if any.
804 *
805 * The option name displayed (e.g., -Wconversion) will be placed in brackets
806 * after the diagnostic text. This option corresponds to the clang flag
807 * \c -fdiagnostics-show-option.
808 */
809 CXDiagnostic_DisplayOption = 0x08,
810
811 /**
812 * \brief Display the category number associated with this diagnostic, if any.
813 *
814 * The category number is displayed within brackets after the diagnostic text.
815 * This option corresponds to the clang flag
816 * \c -fdiagnostics-show-category=id.
817 */
818 CXDiagnostic_DisplayCategoryId = 0x10,
819
820 /**
821 * \brief Display the category name associated with this diagnostic, if any.
822 *
823 * The category name is displayed within brackets after the diagnostic text.
824 * This option corresponds to the clang flag
825 * \c -fdiagnostics-show-category=name.
826 */
827 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000828};
829
830/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000831 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000832 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000833 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000834 * the diagnostic according to the various options given. The
835 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000836 * options that most closely mimics the behavior of the clang compiler.
837 *
838 * \param Diagnostic The diagnostic to print.
839 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000840 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000841 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000842 *
843 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000844 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000845CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
846 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000847
848/**
849 * \brief Retrieve the set of display options most similar to the
850 * default behavior of the clang compiler.
851 *
852 * \returns A set of display options suitable for use with \c
853 * clang_displayDiagnostic().
854 */
855CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
856
857/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000858 * \brief Determine the severity of the given diagnostic.
859 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000860CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000861clang_getDiagnosticSeverity(CXDiagnostic);
862
863/**
864 * \brief Retrieve the source location of the given diagnostic.
865 *
866 * This location is where Clang would print the caret ('^') when
867 * displaying the diagnostic on the command line.
868 */
869CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
870
871/**
872 * \brief Retrieve the text of the given diagnostic.
873 */
874CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000875
876/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000877 * \brief Retrieve the name of the command-line option that enabled this
878 * diagnostic.
879 *
880 * \param Diag The diagnostic to be queried.
881 *
882 * \param Disable If non-NULL, will be set to the option that disables this
883 * diagnostic (if any).
884 *
885 * \returns A string that contains the command-line option used to enable this
886 * warning, such as "-Wconversion" or "-pedantic".
887 */
888CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
889 CXString *Disable);
890
891/**
892 * \brief Retrieve the category number for this diagnostic.
893 *
894 * Diagnostics can be categorized into groups along with other, related
895 * diagnostics (e.g., diagnostics under the same warning flag). This routine
896 * retrieves the category number for the given diagnostic.
897 *
898 * \returns The number of the category that contains this diagnostic, or zero
899 * if this diagnostic is uncategorized.
900 */
901CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
902
903/**
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000904 * \brief Retrieve the name of a particular diagnostic category. This
905 * is now deprecated. Use clang_getDiagnosticCategoryText()
906 * instead.
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000907 *
908 * \param Category A diagnostic category number, as returned by
909 * \c clang_getDiagnosticCategory().
910 *
911 * \returns The name of the given diagnostic category.
912 */
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000913CINDEX_DEPRECATED CINDEX_LINKAGE
914CXString clang_getDiagnosticCategoryName(unsigned Category);
915
916/**
917 * \brief Retrieve the diagnostic category text for a given diagnostic.
918 *
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000919 * \returns The text of the given diagnostic category.
920 */
921CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000922
923/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000924 * \brief Determine the number of source ranges associated with the given
925 * diagnostic.
926 */
927CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000928
Douglas Gregor5352ac02010-01-28 00:27:43 +0000929/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000930 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000931 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000932 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000933 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000934 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000935 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000936 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000937 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000938 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000939 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000940 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000941 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000942CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000943 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000944
945/**
946 * \brief Determine the number of fix-it hints associated with the
947 * given diagnostic.
948 */
949CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
950
951/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000952 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000953 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000954 * Fix-its are described in terms of a source range whose contents
955 * should be replaced by a string. This approach generalizes over
956 * three kinds of operations: removal of source code (the range covers
957 * the code to be removed and the replacement string is empty),
958 * replacement of source code (the range covers the code to be
959 * replaced and the replacement string provides the new code), and
960 * insertion (both the start and end of the range point at the
961 * insertion location, and the replacement string provides the text to
962 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000963 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000964 * \param Diagnostic The diagnostic whose fix-its are being queried.
965 *
966 * \param FixIt The zero-based index of the fix-it.
967 *
968 * \param ReplacementRange The source range whose contents will be
969 * replaced with the returned replacement string. Note that source
970 * ranges are half-open ranges [a, b), so the source code should be
971 * replaced from a and up to (but not including) b.
972 *
973 * \returns A string containing text that should be replace the source
974 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000975 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000976CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000977 unsigned FixIt,
978 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000979
980/**
981 * @}
982 */
983
984/**
985 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
986 *
987 * The routines in this group provide the ability to create and destroy
988 * translation units from files, either by parsing the contents of the files or
989 * by reading in a serialized representation of a translation unit.
990 *
991 * @{
992 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000993
Douglas Gregor5352ac02010-01-28 00:27:43 +0000994/**
995 * \brief Get the original translation unit source file name.
996 */
997CINDEX_LINKAGE CXString
998clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
999
1000/**
1001 * \brief Return the CXTranslationUnit for a given source file and the provided
1002 * command line arguments one would pass to the compiler.
1003 *
1004 * Note: The 'source_filename' argument is optional. If the caller provides a
1005 * NULL pointer, the name of the source file is expected to reside in the
1006 * specified command line arguments.
1007 *
1008 * Note: When encountered in 'clang_command_line_args', the following options
1009 * are ignored:
1010 *
1011 * '-c'
1012 * '-emit-ast'
1013 * '-fsyntax-only'
James Dennett7eee0182012-06-15 05:41:51 +00001014 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor5352ac02010-01-28 00:27:43 +00001015 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001016 * \param CIdx The index object with which the translation unit will be
1017 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001018 *
James Dennett7eee0182012-06-15 05:41:51 +00001019 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001020 * source file is included in \p clang_command_line_args.
1021 *
1022 * \param num_clang_command_line_args The number of command-line arguments in
1023 * \p clang_command_line_args.
1024 *
1025 * \param clang_command_line_args The command-line arguments that would be
1026 * passed to the \c clang executable if it were being invoked out-of-process.
1027 * These command-line options will be parsed and will affect how the translation
1028 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett7eee0182012-06-15 05:41:51 +00001029 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001030 *
1031 * \param num_unsaved_files the number of unsaved file entries in \p
1032 * unsaved_files.
1033 *
1034 * \param unsaved_files the files that have not yet been saved to disk
1035 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +00001036 * those files. The contents and name of these files (as specified by
1037 * CXUnsavedFile) are copied when necessary, so the client only needs to
1038 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001039 */
1040CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1041 CXIndex CIdx,
1042 const char *source_filename,
1043 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001044 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +00001045 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +00001046 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001047
Douglas Gregor5352ac02010-01-28 00:27:43 +00001048/**
1049 * \brief Create a translation unit from an AST file (-emit-ast).
1050 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001051CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +00001052 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +00001053
Douglas Gregor44c181a2010-07-23 00:33:23 +00001054/**
1055 * \brief Flags that control the creation of translation units.
1056 *
1057 * The enumerators in this enumeration type are meant to be bitwise
1058 * ORed together to specify which options should be used when
1059 * constructing the translation unit.
1060 */
Douglas Gregor5a430212010-07-21 18:52:53 +00001061enum CXTranslationUnit_Flags {
1062 /**
1063 * \brief Used to indicate that no special translation-unit options are
1064 * needed.
1065 */
1066 CXTranslationUnit_None = 0x0,
1067
1068 /**
1069 * \brief Used to indicate that the parser should construct a "detailed"
1070 * preprocessing record, including all macro definitions and instantiations.
1071 *
1072 * Constructing a detailed preprocessing record requires more memory
1073 * and time to parse, since the information contained in the record
1074 * is usually not retained. However, it can be useful for
1075 * applications that require more detailed information about the
1076 * behavior of the preprocessor.
1077 */
Douglas Gregor44c181a2010-07-23 00:33:23 +00001078 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1079
1080 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001081 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001082 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001083 * When a translation unit is considered "incomplete", semantic
1084 * analysis that is typically performed at the end of the
1085 * translation unit will be suppressed. For example, this suppresses
1086 * the completion of tentative declarations in C and of
1087 * instantiation of implicitly-instantiation function templates in
1088 * C++. This option is typically used when parsing a header with the
1089 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001090 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001091 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +00001092
1093 /**
1094 * \brief Used to indicate that the translation unit should be built with an
1095 * implicit precompiled header for the preamble.
1096 *
1097 * An implicit precompiled header is used as an optimization when a
1098 * particular translation unit is likely to be reparsed many times
1099 * when the sources aren't changing that often. In this case, an
1100 * implicit precompiled header will be built containing all of the
1101 * initial includes at the top of the main file (what we refer to as
1102 * the "preamble" of the file). In subsequent parses, if the
1103 * preamble or the files in it have not changed, \c
1104 * clang_reparseTranslationUnit() will re-use the implicit
1105 * precompiled header to improve parsing performance.
1106 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001107 CXTranslationUnit_PrecompiledPreamble = 0x04,
1108
1109 /**
1110 * \brief Used to indicate that the translation unit should cache some
1111 * code-completion results with each reparse of the source file.
1112 *
1113 * Caching of code-completion results is a performance optimization that
1114 * introduces some overhead to reparsing but improves the performance of
1115 * code-completion operations.
1116 */
Douglas Gregor99ba2022010-10-27 17:24:53 +00001117 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001118
Douglas Gregor99ba2022010-10-27 17:24:53 +00001119 /**
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001120 * \brief Used to indicate that the translation unit will be serialized with
1121 * \c clang_saveTranslationUnit.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001122 *
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001123 * This option is typically used when parsing a header with the intent of
1124 * producing a precompiled header.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001125 */
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001126 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregor99ba2022010-10-27 17:24:53 +00001127
1128 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001129 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001130 *
1131 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001132 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001133 */
Erik Verbruggen6a91d382012-04-12 10:11:59 +00001134 CXTranslationUnit_CXXChainedPCH = 0x20,
1135
1136 /**
1137 * \brief Used to indicate that function/method bodies should be skipped while
1138 * parsing.
1139 *
1140 * This option can be used to search for declarations/definitions while
1141 * ignoring the usages.
1142 */
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001143 CXTranslationUnit_SkipFunctionBodies = 0x40,
1144
1145 /**
1146 * \brief Used to indicate that brief documentation comments should be
1147 * included into the set of code completions returned from this translation
1148 * unit.
1149 */
1150 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor5a430212010-07-21 18:52:53 +00001151};
1152
1153/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001154 * \brief Returns the set of flags that is suitable for parsing a translation
1155 * unit that is being edited.
1156 *
1157 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1158 * to indicate that the translation unit is likely to be reparsed many times,
1159 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1160 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1161 * set contains an unspecified set of optimizations (e.g., the precompiled
1162 * preamble) geared toward improving the performance of these routines. The
1163 * set of optimizations enabled may change from one version to the next.
1164 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001165CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001166
1167/**
Douglas Gregor5a430212010-07-21 18:52:53 +00001168 * \brief Parse the given source file and the translation unit corresponding
1169 * to that file.
1170 *
1171 * This routine is the main entry point for the Clang C API, providing the
1172 * ability to parse a source file into a translation unit that can then be
1173 * queried by other functions in the API. This routine accepts a set of
1174 * command-line arguments so that the compilation can be configured in the same
1175 * way that the compiler is configured on the command line.
1176 *
1177 * \param CIdx The index object with which the translation unit will be
1178 * associated.
1179 *
1180 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001181 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +00001182 *
1183 * \param command_line_args The command-line arguments that would be
1184 * passed to the \c clang executable if it were being invoked out-of-process.
1185 * These command-line options will be parsed and will affect how the translation
1186 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett7eee0182012-06-15 05:41:51 +00001187 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor5a430212010-07-21 18:52:53 +00001188 *
1189 * \param num_command_line_args The number of command-line arguments in
1190 * \p command_line_args.
1191 *
1192 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00001193 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +00001194 * those files. The contents and name of these files (as specified by
1195 * CXUnsavedFile) are copied when necessary, so the client only needs to
1196 * guarantee their validity until the call to this function returns.
1197 *
1198 * \param num_unsaved_files the number of unsaved file entries in \p
1199 * unsaved_files.
1200 *
1201 * \param options A bitmask of options that affects how the translation unit
1202 * is managed but not its compilation. This should be a bitwise OR of the
1203 * CXTranslationUnit_XXX flags.
1204 *
1205 * \returns A new translation unit describing the parsed code and containing
1206 * any diagnostics produced by the compiler. If there is a failure from which
1207 * the compiler cannot recover, returns NULL.
1208 */
1209CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1210 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001211 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +00001212 int num_command_line_args,
1213 struct CXUnsavedFile *unsaved_files,
1214 unsigned num_unsaved_files,
1215 unsigned options);
1216
Douglas Gregor5352ac02010-01-28 00:27:43 +00001217/**
Douglas Gregor19998442010-08-13 15:35:05 +00001218 * \brief Flags that control how translation units are saved.
1219 *
1220 * The enumerators in this enumeration type are meant to be bitwise
1221 * ORed together to specify which options should be used when
1222 * saving the translation unit.
1223 */
1224enum CXSaveTranslationUnit_Flags {
1225 /**
1226 * \brief Used to indicate that no special saving options are needed.
1227 */
1228 CXSaveTranslationUnit_None = 0x0
1229};
1230
1231/**
1232 * \brief Returns the set of flags that is suitable for saving a translation
1233 * unit.
1234 *
1235 * The set of flags returned provide options for
1236 * \c clang_saveTranslationUnit() by default. The returned flag
1237 * set contains an unspecified set of options that save translation units with
1238 * the most commonly-requested data.
1239 */
1240CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1241
1242/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001243 * \brief Describes the kind of error that occurred (if any) in a call to
1244 * \c clang_saveTranslationUnit().
1245 */
1246enum CXSaveError {
1247 /**
1248 * \brief Indicates that no error occurred while saving a translation unit.
1249 */
1250 CXSaveError_None = 0,
1251
1252 /**
1253 * \brief Indicates that an unknown error occurred while attempting to save
1254 * the file.
1255 *
1256 * This error typically indicates that file I/O failed when attempting to
1257 * write the file.
1258 */
1259 CXSaveError_Unknown = 1,
1260
1261 /**
1262 * \brief Indicates that errors during translation prevented this attempt
1263 * to save the translation unit.
1264 *
1265 * Errors that prevent the translation unit from being saved can be
1266 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1267 */
1268 CXSaveError_TranslationErrors = 2,
1269
1270 /**
1271 * \brief Indicates that the translation unit to be saved was somehow
1272 * invalid (e.g., NULL).
1273 */
1274 CXSaveError_InvalidTU = 3
1275};
1276
1277/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001278 * \brief Saves a translation unit into a serialized representation of
1279 * that translation unit on disk.
1280 *
1281 * Any translation unit that was parsed without error can be saved
1282 * into a file. The translation unit can then be deserialized into a
1283 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1284 * if it is an incomplete translation unit that corresponds to a
1285 * header, used as a precompiled header when parsing other translation
1286 * units.
1287 *
1288 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001289 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001290 * \param FileName The file to which the translation unit will be saved.
1291 *
Douglas Gregor19998442010-08-13 15:35:05 +00001292 * \param options A bitmask of options that affects how the translation unit
1293 * is saved. This should be a bitwise OR of the
1294 * CXSaveTranslationUnit_XXX flags.
1295 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001296 * \returns A value that will match one of the enumerators of the CXSaveError
1297 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1298 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001299 */
1300CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001301 const char *FileName,
1302 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001303
1304/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001305 * \brief Destroy the specified CXTranslationUnit object.
1306 */
1307CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001308
Douglas Gregor5352ac02010-01-28 00:27:43 +00001309/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001310 * \brief Flags that control the reparsing of translation units.
1311 *
1312 * The enumerators in this enumeration type are meant to be bitwise
1313 * ORed together to specify which options should be used when
1314 * reparsing the translation unit.
1315 */
1316enum CXReparse_Flags {
1317 /**
1318 * \brief Used to indicate that no special reparsing options are needed.
1319 */
1320 CXReparse_None = 0x0
1321};
1322
1323/**
1324 * \brief Returns the set of flags that is suitable for reparsing a translation
1325 * unit.
1326 *
1327 * The set of flags returned provide options for
1328 * \c clang_reparseTranslationUnit() by default. The returned flag
1329 * set contains an unspecified set of optimizations geared toward common uses
1330 * of reparsing. The set of optimizations enabled may change from one version
1331 * to the next.
1332 */
1333CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1334
1335/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001336 * \brief Reparse the source files that produced this translation unit.
1337 *
1338 * This routine can be used to re-parse the source files that originally
1339 * created the given translation unit, for example because those source files
1340 * have changed (either on disk or as passed via \p unsaved_files). The
1341 * source code will be reparsed with the same command-line options as it
1342 * was originally parsed.
1343 *
1344 * Reparsing a translation unit invalidates all cursors and source locations
1345 * that refer into that translation unit. This makes reparsing a translation
1346 * unit semantically equivalent to destroying the translation unit and then
1347 * creating a new translation unit with the same command-line arguments.
1348 * However, it may be more efficient to reparse a translation
1349 * unit using this routine.
1350 *
1351 * \param TU The translation unit whose contents will be re-parsed. The
1352 * translation unit must originally have been built with
1353 * \c clang_createTranslationUnitFromSourceFile().
1354 *
1355 * \param num_unsaved_files The number of unsaved file entries in \p
1356 * unsaved_files.
1357 *
1358 * \param unsaved_files The files that have not yet been saved to disk
1359 * but may be required for parsing, including the contents of
1360 * those files. The contents and name of these files (as specified by
1361 * CXUnsavedFile) are copied when necessary, so the client only needs to
1362 * guarantee their validity until the call to this function returns.
1363 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001364 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1365 * The function \c clang_defaultReparseOptions() produces a default set of
1366 * options recommended for most uses, based on the translation unit.
1367 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001368 * \returns 0 if the sources could be reparsed. A non-zero value will be
1369 * returned if reparsing was impossible, such that the translation unit is
1370 * invalid. In such cases, the only valid call for \p TU is
1371 * \c clang_disposeTranslationUnit(TU).
1372 */
1373CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1374 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001375 struct CXUnsavedFile *unsaved_files,
1376 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001377
1378/**
1379 * \brief Categorizes how memory is being used by a translation unit.
1380 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001381enum CXTUResourceUsageKind {
1382 CXTUResourceUsage_AST = 1,
1383 CXTUResourceUsage_Identifiers = 2,
1384 CXTUResourceUsage_Selectors = 3,
1385 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001386 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001387 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001388 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001389 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1390 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1391 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001392 CXTUResourceUsage_Preprocessor = 11,
1393 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001394 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001395 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001396 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1397 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001398 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001399
1400 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001401 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001402};
1403
1404/**
1405 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001406 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001407 */
1408CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001409const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001410
Ted Kremenekf7870022011-04-20 16:41:07 +00001411typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001412 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001413 enum CXTUResourceUsageKind kind;
1414 /* \brief Amount of resources used.
1415 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001416 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001417} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001418
1419/**
1420 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1421 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001422typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001423 /* \brief Private data member, used for queries. */
1424 void *data;
1425
1426 /* \brief The number of entries in the 'entries' array. */
1427 unsigned numEntries;
1428
1429 /* \brief An array of key-value pairs, representing the breakdown of memory
1430 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001431 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001432
Ted Kremenekf7870022011-04-20 16:41:07 +00001433} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001434
1435/**
1436 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001437 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001438 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001439CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001440
Ted Kremenekf7870022011-04-20 16:41:07 +00001441CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001442
Douglas Gregorabc563f2010-07-19 21:46:24 +00001443/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001444 * @}
1445 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001446
Douglas Gregor5352ac02010-01-28 00:27:43 +00001447/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001448 * \brief Describes the kind of entity that a cursor refers to.
1449 */
1450enum CXCursorKind {
1451 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001452 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001453 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001454 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001455 *
1456 * Unexposed declarations have the same operations as any other kind
1457 * of declaration; one can extract their location information,
1458 * spelling, find their definitions, etc. However, the specific kind
1459 * of the declaration is not reported.
1460 */
1461 CXCursor_UnexposedDecl = 1,
1462 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001463 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001464 /** \brief A C or C++ union. */
1465 CXCursor_UnionDecl = 3,
1466 /** \brief A C++ class. */
1467 CXCursor_ClassDecl = 4,
1468 /** \brief An enumeration. */
1469 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001470 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001471 * \brief A field (in C) or non-static data member (in C++) in a
1472 * struct, union, or C++ class.
1473 */
1474 CXCursor_FieldDecl = 6,
1475 /** \brief An enumerator constant. */
1476 CXCursor_EnumConstantDecl = 7,
1477 /** \brief A function. */
1478 CXCursor_FunctionDecl = 8,
1479 /** \brief A variable. */
1480 CXCursor_VarDecl = 9,
1481 /** \brief A function or method parameter. */
1482 CXCursor_ParmDecl = 10,
James Dennett17d26a62012-06-11 06:19:40 +00001483 /** \brief An Objective-C \@interface. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001484 CXCursor_ObjCInterfaceDecl = 11,
James Dennett17d26a62012-06-11 06:19:40 +00001485 /** \brief An Objective-C \@interface for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001486 CXCursor_ObjCCategoryDecl = 12,
James Dennett17d26a62012-06-11 06:19:40 +00001487 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001488 CXCursor_ObjCProtocolDecl = 13,
James Dennett17d26a62012-06-11 06:19:40 +00001489 /** \brief An Objective-C \@property declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001490 CXCursor_ObjCPropertyDecl = 14,
1491 /** \brief An Objective-C instance variable. */
1492 CXCursor_ObjCIvarDecl = 15,
1493 /** \brief An Objective-C instance method. */
1494 CXCursor_ObjCInstanceMethodDecl = 16,
1495 /** \brief An Objective-C class method. */
1496 CXCursor_ObjCClassMethodDecl = 17,
James Dennett17d26a62012-06-11 06:19:40 +00001497 /** \brief An Objective-C \@implementation. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001498 CXCursor_ObjCImplementationDecl = 18,
James Dennett17d26a62012-06-11 06:19:40 +00001499 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001500 CXCursor_ObjCCategoryImplDecl = 19,
1501 /** \brief A typedef */
1502 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001503 /** \brief A C++ class method. */
1504 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001505 /** \brief A C++ namespace. */
1506 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001507 /** \brief A linkage specification, e.g. 'extern "C"'. */
1508 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001509 /** \brief A C++ constructor. */
1510 CXCursor_Constructor = 24,
1511 /** \brief A C++ destructor. */
1512 CXCursor_Destructor = 25,
1513 /** \brief A C++ conversion function. */
1514 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001515 /** \brief A C++ template type parameter. */
1516 CXCursor_TemplateTypeParameter = 27,
1517 /** \brief A C++ non-type template parameter. */
1518 CXCursor_NonTypeTemplateParameter = 28,
1519 /** \brief A C++ template template parameter. */
1520 CXCursor_TemplateTemplateParameter = 29,
1521 /** \brief A C++ function template. */
1522 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001523 /** \brief A C++ class template. */
1524 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001525 /** \brief A C++ class template partial specialization. */
1526 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001527 /** \brief A C++ namespace alias declaration. */
1528 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001529 /** \brief A C++ using directive. */
1530 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001531 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001532 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001533 /** \brief A C++ alias declaration */
1534 CXCursor_TypeAliasDecl = 36,
James Dennett7eee0182012-06-15 05:41:51 +00001535 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor352697a2011-06-03 23:08:58 +00001536 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett7eee0182012-06-15 05:41:51 +00001537 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor352697a2011-06-03 23:08:58 +00001538 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001539 /** \brief An access specifier. */
1540 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor42b29842011-10-05 19:00:14 +00001541
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001542 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001543 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001544
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001545 /* References */
1546 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001547 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001548 CXCursor_ObjCProtocolRef = 41,
1549 CXCursor_ObjCClassRef = 42,
1550 /**
1551 * \brief A reference to a type declaration.
1552 *
1553 * A type reference occurs anywhere where a type is named but not
1554 * declared. For example, given:
1555 *
1556 * \code
1557 * typedef unsigned size_type;
1558 * size_type size;
1559 * \endcode
1560 *
1561 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1562 * while the type of the variable "size" is referenced. The cursor
1563 * referenced by the type of size is the typedef for size_type.
1564 */
1565 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001566 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001567 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001568 * \brief A reference to a class template, function template, template
1569 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001570 */
1571 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001572 /**
1573 * \brief A reference to a namespace or namespace alias.
1574 */
1575 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001576 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001577 * \brief A reference to a member of a struct, union, or class that occurs in
1578 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001579 */
1580 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001581 /**
1582 * \brief A reference to a labeled statement.
1583 *
1584 * This cursor kind is used to describe the jump to "start_over" in the
1585 * goto statement in the following example:
1586 *
1587 * \code
1588 * start_over:
1589 * ++counter;
1590 *
1591 * goto start_over;
1592 * \endcode
1593 *
1594 * A label reference cursor refers to a label statement.
1595 */
1596 CXCursor_LabelRef = 48,
1597
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001598 /**
1599 * \brief A reference to a set of overloaded functions or function templates
1600 * that has not yet been resolved to a specific function or function template.
1601 *
1602 * An overloaded declaration reference cursor occurs in C++ templates where
1603 * a dependent name refers to a function. For example:
1604 *
1605 * \code
1606 * template<typename T> void swap(T&, T&);
1607 *
1608 * struct X { ... };
1609 * void swap(X&, X&);
1610 *
1611 * template<typename T>
1612 * void reverse(T* first, T* last) {
1613 * while (first < last - 1) {
1614 * swap(*first, *--last);
1615 * ++first;
1616 * }
1617 * }
1618 *
1619 * struct Y { };
1620 * void swap(Y&, Y&);
1621 * \endcode
1622 *
1623 * Here, the identifier "swap" is associated with an overloaded declaration
1624 * reference. In the template definition, "swap" refers to either of the two
1625 * "swap" functions declared above, so both results will be available. At
1626 * instantiation time, "swap" may also refer to other functions found via
1627 * argument-dependent lookup (e.g., the "swap" function at the end of the
1628 * example).
1629 *
1630 * The functions \c clang_getNumOverloadedDecls() and
1631 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1632 * referenced by this cursor.
1633 */
1634 CXCursor_OverloadedDeclRef = 49,
1635
Douglas Gregor011d8b92012-02-15 00:54:55 +00001636 /**
1637 * \brief A reference to a variable that occurs in some non-expression
1638 * context, e.g., a C++ lambda capture list.
1639 */
1640 CXCursor_VariableRef = 50,
1641
1642 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001643
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001644 /* Error conditions */
1645 CXCursor_FirstInvalid = 70,
1646 CXCursor_InvalidFile = 70,
1647 CXCursor_NoDeclFound = 71,
1648 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001649 CXCursor_InvalidCode = 73,
1650 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001651
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001652 /* Expressions */
1653 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001654
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001655 /**
1656 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001657 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001658 *
1659 * Unexposed expressions have the same operations as any other kind
1660 * of expression; one can extract their location information,
1661 * spelling, children, etc. However, the specific kind of the
1662 * expression is not reported.
1663 */
1664 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001665
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001666 /**
1667 * \brief An expression that refers to some value declaration, such
1668 * as a function, varible, or enumerator.
1669 */
1670 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001671
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001672 /**
1673 * \brief An expression that refers to a member of a struct, union,
1674 * class, Objective-C class, etc.
1675 */
1676 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001677
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001678 /** \brief An expression that calls a function. */
1679 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001680
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001681 /** \brief An expression that sends a message to an Objective-C
1682 object or class. */
1683 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001684
1685 /** \brief An expression that represents a block literal. */
1686 CXCursor_BlockExpr = 105,
1687
Douglas Gregor42b29842011-10-05 19:00:14 +00001688 /** \brief An integer literal.
1689 */
1690 CXCursor_IntegerLiteral = 106,
1691
1692 /** \brief A floating point number literal.
1693 */
1694 CXCursor_FloatingLiteral = 107,
1695
1696 /** \brief An imaginary number literal.
1697 */
1698 CXCursor_ImaginaryLiteral = 108,
1699
1700 /** \brief A string literal.
1701 */
1702 CXCursor_StringLiteral = 109,
1703
1704 /** \brief A character literal.
1705 */
1706 CXCursor_CharacterLiteral = 110,
1707
1708 /** \brief A parenthesized expression, e.g. "(1)".
1709 *
1710 * This AST node is only formed if full location information is requested.
1711 */
1712 CXCursor_ParenExpr = 111,
1713
1714 /** \brief This represents the unary-expression's (except sizeof and
1715 * alignof).
1716 */
1717 CXCursor_UnaryOperator = 112,
1718
1719 /** \brief [C99 6.5.2.1] Array Subscripting.
1720 */
1721 CXCursor_ArraySubscriptExpr = 113,
1722
1723 /** \brief A builtin binary operation expression such as "x + y" or
1724 * "x <= y".
1725 */
1726 CXCursor_BinaryOperator = 114,
1727
1728 /** \brief Compound assignment such as "+=".
1729 */
1730 CXCursor_CompoundAssignOperator = 115,
1731
1732 /** \brief The ?: ternary operator.
1733 */
1734 CXCursor_ConditionalOperator = 116,
1735
1736 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1737 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1738 *
1739 * For example: (int)f.
1740 */
1741 CXCursor_CStyleCastExpr = 117,
1742
1743 /** \brief [C99 6.5.2.5]
1744 */
1745 CXCursor_CompoundLiteralExpr = 118,
1746
1747 /** \brief Describes an C or C++ initializer list.
1748 */
1749 CXCursor_InitListExpr = 119,
1750
1751 /** \brief The GNU address of label extension, representing &&label.
1752 */
1753 CXCursor_AddrLabelExpr = 120,
1754
1755 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1756 */
1757 CXCursor_StmtExpr = 121,
1758
Benjamin Kramerffbe9b92011-12-23 17:00:35 +00001759 /** \brief Represents a C11 generic selection.
Douglas Gregor42b29842011-10-05 19:00:14 +00001760 */
1761 CXCursor_GenericSelectionExpr = 122,
1762
1763 /** \brief Implements the GNU __null extension, which is a name for a null
1764 * pointer constant that has integral type (e.g., int or long) and is the same
1765 * size and alignment as a pointer.
1766 *
1767 * The __null extension is typically only used by system headers, which define
1768 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1769 * match the size of a pointer).
1770 */
1771 CXCursor_GNUNullExpr = 123,
1772
1773 /** \brief C++'s static_cast<> expression.
1774 */
1775 CXCursor_CXXStaticCastExpr = 124,
1776
1777 /** \brief C++'s dynamic_cast<> expression.
1778 */
1779 CXCursor_CXXDynamicCastExpr = 125,
1780
1781 /** \brief C++'s reinterpret_cast<> expression.
1782 */
1783 CXCursor_CXXReinterpretCastExpr = 126,
1784
1785 /** \brief C++'s const_cast<> expression.
1786 */
1787 CXCursor_CXXConstCastExpr = 127,
1788
1789 /** \brief Represents an explicit C++ type conversion that uses "functional"
1790 * notion (C++ [expr.type.conv]).
1791 *
1792 * Example:
1793 * \code
1794 * x = int(0.5);
1795 * \endcode
1796 */
1797 CXCursor_CXXFunctionalCastExpr = 128,
1798
1799 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1800 */
1801 CXCursor_CXXTypeidExpr = 129,
1802
1803 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1804 */
1805 CXCursor_CXXBoolLiteralExpr = 130,
1806
1807 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1808 */
1809 CXCursor_CXXNullPtrLiteralExpr = 131,
1810
1811 /** \brief Represents the "this" expression in C++
1812 */
1813 CXCursor_CXXThisExpr = 132,
1814
1815 /** \brief [C++ 15] C++ Throw Expression.
1816 *
1817 * This handles 'throw' and 'throw' assignment-expression. When
1818 * assignment-expression isn't present, Op will be null.
1819 */
1820 CXCursor_CXXThrowExpr = 133,
1821
1822 /** \brief A new expression for memory allocation and constructor calls, e.g:
1823 * "new CXXNewExpr(foo)".
1824 */
1825 CXCursor_CXXNewExpr = 134,
1826
1827 /** \brief A delete expression for memory deallocation and destructor calls,
1828 * e.g. "delete[] pArray".
1829 */
1830 CXCursor_CXXDeleteExpr = 135,
1831
1832 /** \brief A unary expression.
1833 */
1834 CXCursor_UnaryExpr = 136,
1835
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001836 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor42b29842011-10-05 19:00:14 +00001837 */
1838 CXCursor_ObjCStringLiteral = 137,
1839
James Dennett7eee0182012-06-15 05:41:51 +00001840 /** \brief An Objective-C \@encode expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001841 */
1842 CXCursor_ObjCEncodeExpr = 138,
1843
James Dennett7eee0182012-06-15 05:41:51 +00001844 /** \brief An Objective-C \@selector expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001845 */
1846 CXCursor_ObjCSelectorExpr = 139,
1847
James Dennett17d26a62012-06-11 06:19:40 +00001848 /** \brief An Objective-C \@protocol expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001849 */
1850 CXCursor_ObjCProtocolExpr = 140,
1851
1852 /** \brief An Objective-C "bridged" cast expression, which casts between
1853 * Objective-C pointers and C pointers, transferring ownership in the process.
1854 *
1855 * \code
1856 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1857 * \endcode
1858 */
1859 CXCursor_ObjCBridgedCastExpr = 141,
1860
1861 /** \brief Represents a C++0x pack expansion that produces a sequence of
1862 * expressions.
1863 *
1864 * A pack expansion expression contains a pattern (which itself is an
1865 * expression) followed by an ellipsis. For example:
1866 *
1867 * \code
1868 * template<typename F, typename ...Types>
1869 * void forward(F f, Types &&...args) {
1870 * f(static_cast<Types&&>(args)...);
1871 * }
1872 * \endcode
1873 */
1874 CXCursor_PackExpansionExpr = 142,
1875
1876 /** \brief Represents an expression that computes the length of a parameter
1877 * pack.
1878 *
1879 * \code
1880 * template<typename ...Types>
1881 * struct count {
1882 * static const unsigned value = sizeof...(Types);
1883 * };
1884 * \endcode
1885 */
1886 CXCursor_SizeOfPackExpr = 143,
1887
Douglas Gregor011d8b92012-02-15 00:54:55 +00001888 /* \brief Represents a C++ lambda expression that produces a local function
1889 * object.
1890 *
1891 * \code
1892 * void abssort(float *x, unsigned N) {
1893 * std::sort(x, x + N,
1894 * [](float a, float b) {
1895 * return std::abs(a) < std::abs(b);
1896 * });
1897 * }
1898 * \endcode
1899 */
1900 CXCursor_LambdaExpr = 144,
1901
Ted Kremenekb3f75422012-03-06 20:06:06 +00001902 /** \brief Objective-c Boolean Literal.
1903 */
1904 CXCursor_ObjCBoolLiteralExpr = 145,
1905
Argyrios Kyrtzidisedab0472013-04-23 17:57:17 +00001906 /** \brief Represents the "self" expression in a ObjC method.
1907 */
1908 CXCursor_ObjCSelfExpr = 146,
1909
1910 CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001911
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001912 /* Statements */
1913 CXCursor_FirstStmt = 200,
1914 /**
1915 * \brief A statement whose specific kind is not exposed via this
1916 * interface.
1917 *
1918 * Unexposed statements have the same operations as any other kind of
1919 * statement; one can extract their location information, spelling,
1920 * children, etc. However, the specific kind of the statement is not
1921 * reported.
1922 */
1923 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001924
1925 /** \brief A labelled statement in a function.
1926 *
1927 * This cursor kind is used to describe the "start_over:" label statement in
1928 * the following example:
1929 *
1930 * \code
1931 * start_over:
1932 * ++counter;
1933 * \endcode
1934 *
1935 */
1936 CXCursor_LabelStmt = 201,
Douglas Gregor42b29842011-10-05 19:00:14 +00001937
1938 /** \brief A group of statements like { stmt stmt }.
1939 *
1940 * This cursor kind is used to describe compound statements, e.g. function
1941 * bodies.
1942 */
1943 CXCursor_CompoundStmt = 202,
1944
1945 /** \brief A case statment.
1946 */
1947 CXCursor_CaseStmt = 203,
1948
1949 /** \brief A default statement.
1950 */
1951 CXCursor_DefaultStmt = 204,
1952
1953 /** \brief An if statement
1954 */
1955 CXCursor_IfStmt = 205,
1956
1957 /** \brief A switch statement.
1958 */
1959 CXCursor_SwitchStmt = 206,
1960
1961 /** \brief A while statement.
1962 */
1963 CXCursor_WhileStmt = 207,
1964
1965 /** \brief A do statement.
1966 */
1967 CXCursor_DoStmt = 208,
1968
1969 /** \brief A for statement.
1970 */
1971 CXCursor_ForStmt = 209,
1972
1973 /** \brief A goto statement.
1974 */
1975 CXCursor_GotoStmt = 210,
1976
1977 /** \brief An indirect goto statement.
1978 */
1979 CXCursor_IndirectGotoStmt = 211,
1980
1981 /** \brief A continue statement.
1982 */
1983 CXCursor_ContinueStmt = 212,
1984
1985 /** \brief A break statement.
1986 */
1987 CXCursor_BreakStmt = 213,
1988
1989 /** \brief A return statement.
1990 */
1991 CXCursor_ReturnStmt = 214,
1992
Chad Rosierdf5faf52012-08-25 00:11:56 +00001993 /** \brief A GCC inline assembly statement extension.
Douglas Gregor42b29842011-10-05 19:00:14 +00001994 */
Chad Rosierdf5faf52012-08-25 00:11:56 +00001995 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5e02f652012-09-24 19:27:20 +00001996 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor42b29842011-10-05 19:00:14 +00001997
James Dennett7eee0182012-06-15 05:41:51 +00001998 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001999 */
2000 CXCursor_ObjCAtTryStmt = 216,
2001
James Dennett7eee0182012-06-15 05:41:51 +00002002 /** \brief Objective-C's \@catch statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002003 */
2004 CXCursor_ObjCAtCatchStmt = 217,
2005
James Dennett7eee0182012-06-15 05:41:51 +00002006 /** \brief Objective-C's \@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002007 */
2008 CXCursor_ObjCAtFinallyStmt = 218,
2009
James Dennett7eee0182012-06-15 05:41:51 +00002010 /** \brief Objective-C's \@throw statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002011 */
2012 CXCursor_ObjCAtThrowStmt = 219,
2013
James Dennett7eee0182012-06-15 05:41:51 +00002014 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002015 */
2016 CXCursor_ObjCAtSynchronizedStmt = 220,
2017
2018 /** \brief Objective-C's autorelease pool statement.
2019 */
2020 CXCursor_ObjCAutoreleasePoolStmt = 221,
2021
2022 /** \brief Objective-C's collection statement.
2023 */
2024 CXCursor_ObjCForCollectionStmt = 222,
2025
2026 /** \brief C++'s catch statement.
2027 */
2028 CXCursor_CXXCatchStmt = 223,
2029
2030 /** \brief C++'s try statement.
2031 */
2032 CXCursor_CXXTryStmt = 224,
2033
2034 /** \brief C++'s for (* : *) statement.
2035 */
2036 CXCursor_CXXForRangeStmt = 225,
2037
2038 /** \brief Windows Structured Exception Handling's try statement.
2039 */
2040 CXCursor_SEHTryStmt = 226,
2041
2042 /** \brief Windows Structured Exception Handling's except statement.
2043 */
2044 CXCursor_SEHExceptStmt = 227,
2045
2046 /** \brief Windows Structured Exception Handling's finally statement.
2047 */
2048 CXCursor_SEHFinallyStmt = 228,
2049
Chad Rosier8cd64b42012-06-11 20:47:18 +00002050 /** \brief A MS inline assembly statement extension.
2051 */
2052 CXCursor_MSAsmStmt = 229,
2053
Douglas Gregor42b29842011-10-05 19:00:14 +00002054 /** \brief The null satement ";": C99 6.8.3p3.
2055 *
2056 * This cursor kind is used to describe the null statement.
2057 */
2058 CXCursor_NullStmt = 230,
2059
2060 /** \brief Adaptor class for mixing declarations with statements and
2061 * expressions.
2062 */
2063 CXCursor_DeclStmt = 231,
2064
Joao Matos4c5fa422012-09-04 17:33:09 +00002065 CXCursor_LastStmt = CXCursor_DeclStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002066
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002067 /**
2068 * \brief Cursor that represents the translation unit itself.
2069 *
2070 * The translation unit cursor exists primarily to act as the root
2071 * cursor for traversing the contents of a translation unit.
2072 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002073 CXCursor_TranslationUnit = 300,
2074
Bill Wendlingad017fa2012-12-20 19:22:21 +00002075 /* Attributes */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002076 CXCursor_FirstAttr = 400,
2077 /**
2078 * \brief An attribute whose specific kind is not exposed via this
2079 * interface.
2080 */
2081 CXCursor_UnexposedAttr = 400,
2082
2083 CXCursor_IBActionAttr = 401,
2084 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00002085 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00002086 CXCursor_CXXFinalAttr = 404,
2087 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002088 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002089 CXCursor_AsmLabelAttr = 407,
2090 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002091
2092 /* Preprocessing */
2093 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00002094 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00002095 CXCursor_MacroExpansion = 502,
2096 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002097 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002098 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis6a010122012-10-05 00:22:24 +00002099 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2100
2101 /* Extra Declarations */
2102 /**
2103 * \brief A module import declaration.
2104 */
2105 CXCursor_ModuleImportDecl = 600,
2106 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2107 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002108};
2109
2110/**
2111 * \brief A cursor representing some element in the abstract syntax tree for
2112 * a translation unit.
2113 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002114 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002115 * program--declaration, statements, expressions, references to declarations,
2116 * etc.--under a single "cursor" abstraction with a common set of operations.
2117 * Common operation for a cursor include: getting the physical location in
2118 * a source file where the cursor points, getting the name associated with a
2119 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2120 *
2121 * Cursors can be produced in two specific ways.
2122 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2123 * from which one can use clang_visitChildren() to explore the rest of the
2124 * translation unit. clang_getCursor() maps from a physical source location
2125 * to the entity that resides at that location, allowing one to map from the
2126 * source code into the AST.
2127 */
2128typedef struct {
2129 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00002130 int xdata;
Dmitri Gribenko67812b22013-01-11 21:01:49 +00002131 const void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002132} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002133
2134/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00002135 * \brief A comment AST node.
2136 */
2137typedef struct {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00002138 const void *ASTNode;
2139 CXTranslationUnit TranslationUnit;
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00002140} CXComment;
2141
2142/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002143 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2144 *
2145 * @{
2146 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002147
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002148/**
2149 * \brief Retrieve the NULL cursor, which represents no entity.
2150 */
2151CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002152
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002153/**
2154 * \brief Retrieve the cursor that represents the given translation unit.
2155 *
2156 * The translation unit cursor can be used to start traversing the
2157 * various declarations within the given translation unit.
2158 */
2159CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2160
2161/**
2162 * \brief Determine whether two cursors are equivalent.
2163 */
2164CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002165
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002166/**
Dmitri Gribenko1824d542012-09-13 13:11:20 +00002167 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002168 */
Dmitri Gribenko1824d542012-09-13 13:11:20 +00002169CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002170
2171/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00002172 * \brief Compute a hash value for the given cursor.
2173 */
2174CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2175
2176/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002177 * \brief Retrieve the kind of the given cursor.
2178 */
2179CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2180
2181/**
2182 * \brief Determine whether the given cursor kind represents a declaration.
2183 */
2184CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2185
2186/**
2187 * \brief Determine whether the given cursor kind represents a simple
2188 * reference.
2189 *
2190 * Note that other kinds of cursors (such as expressions) can also refer to
2191 * other cursors. Use clang_getCursorReferenced() to determine whether a
2192 * particular cursor refers to another entity.
2193 */
2194CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2195
2196/**
2197 * \brief Determine whether the given cursor kind represents an expression.
2198 */
2199CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2200
2201/**
2202 * \brief Determine whether the given cursor kind represents a statement.
2203 */
2204CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2205
2206/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002207 * \brief Determine whether the given cursor kind represents an attribute.
2208 */
2209CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2210
2211/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002212 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002213 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002214 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002215CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2216
2217/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002218 * \brief Determine whether the given cursor kind represents a translation
2219 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002220 */
2221CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002222
Ted Kremenekad6eff62010-03-08 21:17:29 +00002223/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002224 * \brief Determine whether the given cursor represents a preprocessing
2225 * element, such as a preprocessor directive or macro instantiation.
2226 */
2227CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2228
2229/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002230 * \brief Determine whether the given cursor represents a currently
2231 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2232 */
2233CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2234
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002235/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002236 * \brief Describe the linkage of the entity referred to by a cursor.
2237 */
2238enum CXLinkageKind {
2239 /** \brief This value indicates that no linkage information is available
2240 * for a provided CXCursor. */
2241 CXLinkage_Invalid,
2242 /**
2243 * \brief This is the linkage for variables, parameters, and so on that
2244 * have automatic storage. This covers normal (non-extern) local variables.
2245 */
2246 CXLinkage_NoLinkage,
2247 /** \brief This is the linkage for static variables and static functions. */
2248 CXLinkage_Internal,
2249 /** \brief This is the linkage for entities with external linkage that live
2250 * in C++ anonymous namespaces.*/
2251 CXLinkage_UniqueExternal,
2252 /** \brief This is the linkage for entities with true, external linkage. */
2253 CXLinkage_External
2254};
2255
2256/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002257 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002258 */
2259CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2260
2261/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002262 * \brief Determine the availability of the entity that this cursor refers to,
2263 * taking the current target platform into account.
Douglas Gregor58ddb602010-08-23 23:00:57 +00002264 *
2265 * \param cursor The cursor to query.
2266 *
2267 * \returns The availability of the cursor.
2268 */
2269CINDEX_LINKAGE enum CXAvailabilityKind
2270clang_getCursorAvailability(CXCursor cursor);
2271
2272/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002273 * Describes the availability of a given entity on a particular platform, e.g.,
2274 * a particular class might only be available on Mac OS 10.7 or newer.
2275 */
2276typedef struct CXPlatformAvailability {
2277 /**
2278 * \brief A string that describes the platform for which this structure
2279 * provides availability information.
2280 *
2281 * Possible values are "ios" or "macosx".
2282 */
2283 CXString Platform;
2284 /**
2285 * \brief The version number in which this entity was introduced.
2286 */
2287 CXVersion Introduced;
2288 /**
2289 * \brief The version number in which this entity was deprecated (but is
2290 * still available).
2291 */
2292 CXVersion Deprecated;
2293 /**
2294 * \brief The version number in which this entity was obsoleted, and therefore
2295 * is no longer available.
2296 */
2297 CXVersion Obsoleted;
2298 /**
2299 * \brief Whether the entity is unconditionally unavailable on this platform.
2300 */
2301 int Unavailable;
2302 /**
2303 * \brief An optional message to provide to a user of this API, e.g., to
2304 * suggest replacement APIs.
2305 */
2306 CXString Message;
2307} CXPlatformAvailability;
2308
2309/**
2310 * \brief Determine the availability of the entity that this cursor refers to
2311 * on any platforms for which availability information is known.
2312 *
2313 * \param cursor The cursor to query.
2314 *
2315 * \param always_deprecated If non-NULL, will be set to indicate whether the
2316 * entity is deprecated on all platforms.
2317 *
2318 * \param deprecated_message If non-NULL, will be set to the message text
2319 * provided along with the unconditional deprecation of this entity. The client
2320 * is responsible for deallocating this string.
2321 *
James Dennett7eee0182012-06-15 05:41:51 +00002322 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregorcc889662012-05-08 00:14:45 +00002323 * entity is unavailable on all platforms.
2324 *
2325 * \param unavailable_message If non-NULL, will be set to the message text
2326 * provided along with the unconditional unavailability of this entity. The
2327 * client is responsible for deallocating this string.
2328 *
2329 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2330 * that will be populated with platform availability information, up to either
2331 * the number of platforms for which availability information is available (as
2332 * returned by this function) or \c availability_size, whichever is smaller.
2333 *
2334 * \param availability_size The number of elements available in the
2335 * \c availability array.
2336 *
2337 * \returns The number of platforms (N) for which availability information is
2338 * available (which is unrelated to \c availability_size).
2339 *
2340 * Note that the client is responsible for calling
2341 * \c clang_disposeCXPlatformAvailability to free each of the
2342 * platform-availability structures returned. There are
2343 * \c min(N, availability_size) such structures.
2344 */
2345CINDEX_LINKAGE int
2346clang_getCursorPlatformAvailability(CXCursor cursor,
2347 int *always_deprecated,
2348 CXString *deprecated_message,
2349 int *always_unavailable,
2350 CXString *unavailable_message,
2351 CXPlatformAvailability *availability,
2352 int availability_size);
2353
2354/**
2355 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2356 */
2357CINDEX_LINKAGE void
2358clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2359
2360/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002361 * \brief Describe the "language" of the entity referred to by a cursor.
2362 */
2363CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002364 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002365 CXLanguage_C,
2366 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002367 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002368};
2369
2370/**
2371 * \brief Determine the "language" of the entity referred to by a given cursor.
2372 */
2373CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2374
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002375/**
2376 * \brief Returns the translation unit that a cursor originated from.
2377 */
2378CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2379
Ted Kremenek017dd742013-04-24 07:17:12 +00002380
2381/**
2382 * \brief A fast container representing a set of CXCursors.
2383 */
2384typedef struct CXCursorSetImpl *CXCursorSet;
2385
2386/**
2387 * \brief Creates an empty CXCursorSet.
2388 */
2389CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2390
2391/**
2392 * \brief Disposes a CXCursorSet and releases its associated memory.
2393 */
2394CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2395
2396/**
2397 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2398 *
2399 * \returns non-zero if the set contains the specified cursor.
2400*/
2401CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2402 CXCursor cursor);
2403
2404/**
2405 * \brief Inserts a CXCursor into a CXCursorSet.
2406 *
2407 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2408*/
2409CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2410 CXCursor cursor);
2411
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002412/**
2413 * \brief Determine the semantic parent of the given cursor.
2414 *
2415 * The semantic parent of a cursor is the cursor that semantically contains
2416 * the given \p cursor. For many declarations, the lexical and semantic parents
2417 * are equivalent (the lexical parent is returned by
2418 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2419 * definitions are provided out-of-line. For example:
2420 *
2421 * \code
2422 * class C {
2423 * void f();
2424 * };
2425 *
2426 * void C::f() { }
2427 * \endcode
2428 *
2429 * In the out-of-line definition of \c C::f, the semantic parent is the
2430 * the class \c C, of which this function is a member. The lexical parent is
2431 * the place where the declaration actually occurs in the source code; in this
2432 * case, the definition occurs in the translation unit. In general, the
2433 * lexical parent for a given entity can change without affecting the semantics
2434 * of the program, and the lexical parent of different declarations of the
2435 * same entity may be different. Changing the semantic parent of a declaration,
2436 * on the other hand, can have a major impact on semantics, and redeclarations
2437 * of a particular entity should all have the same semantic context.
2438 *
2439 * In the example above, both declarations of \c C::f have \c C as their
2440 * semantic context, while the lexical context of the first \c C::f is \c C
2441 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002442 *
2443 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002444 */
2445CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2446
2447/**
2448 * \brief Determine the lexical parent of the given cursor.
2449 *
2450 * The lexical parent of a cursor is the cursor in which the given \p cursor
2451 * was actually written. For many declarations, the lexical and semantic parents
2452 * are equivalent (the semantic parent is returned by
2453 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2454 * definitions are provided out-of-line. For example:
2455 *
2456 * \code
2457 * class C {
2458 * void f();
2459 * };
2460 *
2461 * void C::f() { }
2462 * \endcode
2463 *
2464 * In the out-of-line definition of \c C::f, the semantic parent is the
2465 * the class \c C, of which this function is a member. The lexical parent is
2466 * the place where the declaration actually occurs in the source code; in this
2467 * case, the definition occurs in the translation unit. In general, the
2468 * lexical parent for a given entity can change without affecting the semantics
2469 * of the program, and the lexical parent of different declarations of the
2470 * same entity may be different. Changing the semantic parent of a declaration,
2471 * on the other hand, can have a major impact on semantics, and redeclarations
2472 * of a particular entity should all have the same semantic context.
2473 *
2474 * In the example above, both declarations of \c C::f have \c C as their
2475 * semantic context, while the lexical context of the first \c C::f is \c C
2476 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002477 *
2478 * For declarations written in the global scope, the lexical parent is
2479 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002480 */
2481CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002482
2483/**
2484 * \brief Determine the set of methods that are overridden by the given
2485 * method.
2486 *
2487 * In both Objective-C and C++, a method (aka virtual member function,
2488 * in C++) can override a virtual method in a base class. For
2489 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002490 * base class, its protocols, or its categories' protocols, that has the same
2491 * selector and is of the same kind (class or instance).
2492 * If no such method exists, the search continues to the class's superclass,
2493 * its protocols, and its categories, and so on. A method from an Objective-C
2494 * implementation is considered to override the same methods as its
2495 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002496 *
2497 * For C++, a virtual member function overrides any virtual member
2498 * function with the same signature that occurs in its base
2499 * classes. With multiple inheritance, a virtual member function can
2500 * override several virtual member functions coming from different
2501 * base classes.
2502 *
2503 * In all cases, this function determines the immediate overridden
2504 * method, rather than all of the overridden methods. For example, if
2505 * a method is originally declared in a class A, then overridden in B
2506 * (which in inherits from A) and also in C (which inherited from B),
2507 * then the only overridden method returned from this function when
2508 * invoked on C's method will be B's method. The client may then
2509 * invoke this function again, given the previously-found overridden
2510 * methods, to map out the complete method-override set.
2511 *
2512 * \param cursor A cursor representing an Objective-C or C++
2513 * method. This routine will compute the set of methods that this
2514 * method overrides.
2515 *
2516 * \param overridden A pointer whose pointee will be replaced with a
2517 * pointer to an array of cursors, representing the set of overridden
2518 * methods. If there are no overridden methods, the pointee will be
2519 * set to NULL. The pointee must be freed via a call to
2520 * \c clang_disposeOverriddenCursors().
2521 *
2522 * \param num_overridden A pointer to the number of overridden
2523 * functions, will be set to the number of overridden functions in the
2524 * array pointed to by \p overridden.
2525 */
2526CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2527 CXCursor **overridden,
2528 unsigned *num_overridden);
2529
2530/**
2531 * \brief Free the set of overridden cursors returned by \c
2532 * clang_getOverriddenCursors().
2533 */
2534CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2535
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002536/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002537 * \brief Retrieve the file that is included by the given inclusion directive
2538 * cursor.
2539 */
2540CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2541
2542/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002543 * @}
2544 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002545
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002546/**
2547 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2548 *
2549 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2550 * routines help map between cursors and the physical locations where the
2551 * described entities occur in the source code. The mapping is provided in
2552 * both directions, so one can map from source code to the AST and back.
2553 *
2554 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002555 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002556
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002557/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002558 * \brief Map a source location to the cursor that describes the entity at that
2559 * location in the source code.
2560 *
2561 * clang_getCursor() maps an arbitrary source location within a translation
2562 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002563 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002564 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002565 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002566 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2567 * will return a cursor referring to the "+" expression.
2568 *
2569 * \returns a cursor representing the entity at the given source location, or
2570 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002571 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002572CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002573
Douglas Gregor98258af2010-01-18 22:46:11 +00002574/**
2575 * \brief Retrieve the physical location of the source constructor referenced
2576 * by the given cursor.
2577 *
2578 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002579 * declaration, where the name of that declaration would occur if it is
2580 * unnamed, or some keyword that introduces that particular declaration.
2581 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002582 * source code.
2583 */
2584CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002585
Douglas Gregorb6998662010-01-19 19:34:47 +00002586/**
2587 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002588 * the given cursor.
2589 *
2590 * The extent of a cursor starts with the file/line/column pointing at the
2591 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002592 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002593 * declaration, the extent covers the declaration itself. For a reference,
2594 * the extent covers the location of the reference (e.g., where the referenced
2595 * entity was actually used).
2596 */
2597CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002598
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002599/**
2600 * @}
2601 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002602
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002603/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002604 * \defgroup CINDEX_TYPES Type information for CXCursors
2605 *
2606 * @{
2607 */
2608
2609/**
2610 * \brief Describes the kind of type
2611 */
2612enum CXTypeKind {
2613 /**
2614 * \brief Reprents an invalid type (e.g., where no type is available).
2615 */
2616 CXType_Invalid = 0,
2617
2618 /**
2619 * \brief A type whose specific kind is not exposed via this
2620 * interface.
2621 */
2622 CXType_Unexposed = 1,
2623
2624 /* Builtin types */
2625 CXType_Void = 2,
2626 CXType_Bool = 3,
2627 CXType_Char_U = 4,
2628 CXType_UChar = 5,
2629 CXType_Char16 = 6,
2630 CXType_Char32 = 7,
2631 CXType_UShort = 8,
2632 CXType_UInt = 9,
2633 CXType_ULong = 10,
2634 CXType_ULongLong = 11,
2635 CXType_UInt128 = 12,
2636 CXType_Char_S = 13,
2637 CXType_SChar = 14,
2638 CXType_WChar = 15,
2639 CXType_Short = 16,
2640 CXType_Int = 17,
2641 CXType_Long = 18,
2642 CXType_LongLong = 19,
2643 CXType_Int128 = 20,
2644 CXType_Float = 21,
2645 CXType_Double = 22,
2646 CXType_LongDouble = 23,
2647 CXType_NullPtr = 24,
2648 CXType_Overload = 25,
2649 CXType_Dependent = 26,
2650 CXType_ObjCId = 27,
2651 CXType_ObjCClass = 28,
2652 CXType_ObjCSel = 29,
2653 CXType_FirstBuiltin = CXType_Void,
2654 CXType_LastBuiltin = CXType_ObjCSel,
2655
2656 CXType_Complex = 100,
2657 CXType_Pointer = 101,
2658 CXType_BlockPointer = 102,
2659 CXType_LValueReference = 103,
2660 CXType_RValueReference = 104,
2661 CXType_Record = 105,
2662 CXType_Enum = 106,
2663 CXType_Typedef = 107,
2664 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002665 CXType_ObjCObjectPointer = 109,
2666 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002667 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002668 CXType_ConstantArray = 112,
2669 CXType_Vector = 113
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002670};
2671
2672/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002673 * \brief Describes the calling convention of a function type
2674 */
2675enum CXCallingConv {
2676 CXCallingConv_Default = 0,
2677 CXCallingConv_C = 1,
2678 CXCallingConv_X86StdCall = 2,
2679 CXCallingConv_X86FastCall = 3,
2680 CXCallingConv_X86ThisCall = 4,
2681 CXCallingConv_X86Pascal = 5,
2682 CXCallingConv_AAPCS = 6,
2683 CXCallingConv_AAPCS_VFP = 7,
Derek Schuff263366f2012-10-16 22:30:41 +00002684 CXCallingConv_PnaclCall = 8,
Guy Benyei38980082012-12-25 08:53:55 +00002685 CXCallingConv_IntelOclBicc = 9,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002686
2687 CXCallingConv_Invalid = 100,
2688 CXCallingConv_Unexposed = 200
2689};
2690
2691
2692/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002693 * \brief The type of an element in the abstract syntax tree.
2694 *
2695 */
2696typedef struct {
2697 enum CXTypeKind kind;
2698 void *data[2];
2699} CXType;
2700
2701/**
2702 * \brief Retrieve the type of a CXCursor (if any).
2703 */
2704CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2705
2706/**
Dmitri Gribenkoae03d8e2013-02-15 21:15:49 +00002707 * \brief Pretty-print the underlying type using the rules of the
2708 * language of the translation unit from which it came.
2709 *
2710 * If the type is invalid, an empty string is returned.
2711 */
2712CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2713
2714/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002715 * \brief Retrieve the underlying type of a typedef declaration.
2716 *
2717 * If the cursor does not reference a typedef declaration, an invalid type is
2718 * returned.
2719 */
2720CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2721
2722/**
2723 * \brief Retrieve the integer type of an enum declaration.
2724 *
2725 * If the cursor does not reference an enum declaration, an invalid type is
2726 * returned.
2727 */
2728CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2729
2730/**
2731 * \brief Retrieve the integer value of an enum constant declaration as a signed
2732 * long long.
2733 *
2734 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2735 * Since this is also potentially a valid constant value, the kind of the cursor
2736 * must be verified before calling this function.
2737 */
2738CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2739
2740/**
2741 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2742 * long long.
2743 *
2744 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2745 * Since this is also potentially a valid constant value, the kind of the cursor
2746 * must be verified before calling this function.
2747 */
2748CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2749
2750/**
Dmitri Gribenko1eb60822012-12-04 15:13:46 +00002751 * \brief Retrieve the bit width of a bit field declaration as an integer.
2752 *
2753 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2754 */
2755CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2756
2757/**
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002758 * \brief Retrieve the number of non-variadic arguments associated with a given
2759 * cursor.
2760 *
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +00002761 * The number of arguments can be determined for calls as well as for
2762 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002763 */
2764CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2765
2766/**
2767 * \brief Retrieve the argument cursor of a function or method.
2768 *
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +00002769 * The argument cursor can be determined for calls as well as for declarations
2770 * of functions or methods. For other cursors and for invalid indices, an
2771 * invalid cursor is returned.
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002772 */
2773CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2774
2775/**
James Dennett7eee0182012-06-15 05:41:51 +00002776 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002777 *
James Dennett7eee0182012-06-15 05:41:51 +00002778 * \returns non-zero if the CXTypes represent the same type and
2779 * zero otherwise.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002780 */
2781CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2782
2783/**
2784 * \brief Return the canonical type for a CXType.
2785 *
2786 * Clang's type system explicitly models typedefs and all the ways
2787 * a specific type can be represented. The canonical type is the underlying
2788 * type with all the "sugar" removed. For example, if 'T' is a typedef
2789 * for 'int', the canonical type for 'T' would be 'int'.
2790 */
2791CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2792
2793/**
James Dennett7eee0182012-06-15 05:41:51 +00002794 * \brief Determine whether a CXType has the "const" qualifier set,
2795 * without looking through typedefs that may have added "const" at a
2796 * different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002797 */
2798CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2799
2800/**
James Dennett7eee0182012-06-15 05:41:51 +00002801 * \brief Determine whether a CXType has the "volatile" qualifier set,
2802 * without looking through typedefs that may have added "volatile" at
2803 * a different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002804 */
2805CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2806
2807/**
James Dennett7eee0182012-06-15 05:41:51 +00002808 * \brief Determine whether a CXType has the "restrict" qualifier set,
2809 * without looking through typedefs that may have added "restrict" at a
2810 * different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002811 */
2812CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2813
2814/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002815 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002816 */
2817CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2818
2819/**
2820 * \brief Return the cursor for the declaration of the given type.
2821 */
2822CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2823
David Chisnall5389f482010-12-30 14:05:53 +00002824/**
2825 * Returns the Objective-C type encoding for the specified declaration.
2826 */
2827CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002828
2829/**
2830 * \brief Retrieve the spelling of a given CXTypeKind.
2831 */
2832CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2833
2834/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002835 * \brief Retrieve the calling convention associated with a function type.
2836 *
2837 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2838 */
2839CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2840
2841/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002842 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002843 *
2844 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002845 */
2846CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2847
2848/**
James Dennett7eee0182012-06-15 05:41:51 +00002849 * \brief Retrieve the number of non-variadic arguments associated with a
2850 * function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002851 *
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002852 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002853 */
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002854CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002855
2856/**
2857 * \brief Retrieve the type of an argument of a function type.
2858 *
James Dennett7eee0182012-06-15 05:41:51 +00002859 * If a non-function type is passed in or the function does not have enough
2860 * parameters, an invalid type is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002861 */
2862CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2863
2864/**
2865 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002866 */
2867CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2868
2869/**
2870 * \brief Retrieve the result type associated with a given cursor.
2871 *
2872 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002873 */
2874CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2875
2876/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002877 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2878 * otherwise.
2879 */
2880CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2881
2882/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002883 * \brief Return the element type of an array, complex, or vector type.
2884 *
2885 * If a type is passed in that is not an array, complex, or vector type,
2886 * an invalid type is returned.
2887 */
2888CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2889
2890/**
2891 * \brief Return the number of elements of an array or vector type.
2892 *
2893 * If a type is passed in that is not an array or vector type,
2894 * -1 is returned.
2895 */
2896CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2897
2898/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002899 * \brief Return the element type of an array type.
2900 *
2901 * If a non-array type is passed in, an invalid type is returned.
2902 */
2903CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2904
2905/**
Sylvestre Ledrubed28ac2012-07-23 08:59:39 +00002906 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002907 *
2908 * If a non-array type is passed in, -1 is returned.
2909 */
2910CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2911
2912/**
Argyrios Kyrtzidis411d33a2013-04-11 01:20:11 +00002913 * \brief List the possible error codes for \c clang_Type_getSizeOf,
2914 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
2915 * \c clang_Cursor_getOffsetOf.
2916 *
2917 * A value of this enumeration type can be returned if the target type is not
2918 * a valid argument to sizeof, alignof or offsetof.
2919 */
2920enum CXTypeLayoutError {
2921 /**
2922 * \brief Type is of kind CXType_Invalid.
2923 */
2924 CXTypeLayoutError_Invalid = -1,
2925 /**
2926 * \brief The type is an incomplete Type.
2927 */
2928 CXTypeLayoutError_Incomplete = -2,
2929 /**
2930 * \brief The type is a dependent Type.
2931 */
2932 CXTypeLayoutError_Dependent = -3,
2933 /**
2934 * \brief The type is not a constant size type.
2935 */
2936 CXTypeLayoutError_NotConstantSize = -4,
2937 /**
2938 * \brief The Field name is not valid for this record.
2939 */
2940 CXTypeLayoutError_InvalidFieldName = -5
2941};
2942
2943/**
2944 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
2945 * standard.
2946 *
2947 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2948 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2949 * is returned.
2950 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2951 * returned.
2952 * If the type declaration is not a constant size type,
2953 * CXTypeLayoutError_NotConstantSize is returned.
2954 */
2955CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
2956
2957/**
2958 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
2959 *
2960 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2961 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2962 * is returned.
2963 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2964 * returned.
2965 */
2966CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
2967
2968/**
2969 * \brief Return the offset of a field named S in a record of type T in bits
2970 * as it would be returned by __offsetof__ as per C++11[18.2p4]
2971 *
2972 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
2973 * is returned.
2974 * If the field's type declaration is an incomplete type,
2975 * CXTypeLayoutError_Incomplete is returned.
2976 * If the field's type declaration is a dependent type,
2977 * CXTypeLayoutError_Dependent is returned.
2978 * If the field's name S is not found,
2979 * CXTypeLayoutError_InvalidFieldName is returned.
2980 */
2981CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
2982
2983/**
2984 * \brief Returns non-zero if the cursor specifies a Record member that is a
2985 * bitfield.
2986 */
2987CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
2988
2989/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002990 * \brief Returns 1 if the base class specified by the cursor with kind
2991 * CX_CXXBaseSpecifier is virtual.
2992 */
2993CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2994
2995/**
2996 * \brief Represents the C++ access control level to a base class for a
2997 * cursor with kind CX_CXXBaseSpecifier.
2998 */
2999enum CX_CXXAccessSpecifier {
3000 CX_CXXInvalidAccessSpecifier,
3001 CX_CXXPublic,
3002 CX_CXXProtected,
3003 CX_CXXPrivate
3004};
3005
3006/**
Argyrios Kyrtzidis04b67482013-04-11 17:02:10 +00003007 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidis5142be62013-04-11 17:31:13 +00003008 *
Argyrios Kyrtzidis04b67482013-04-11 17:02:10 +00003009 * If the cursor refers to a C++ declaration, its access control level within its
3010 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3011 * access specifier, the specifier itself is returned.
Ted Kremenek3064ef92010-08-27 21:34:58 +00003012 */
3013CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3014
3015/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00003016 * \brief Determine the number of overloaded declarations referenced by a
3017 * \c CXCursor_OverloadedDeclRef cursor.
3018 *
3019 * \param cursor The cursor whose overloaded declarations are being queried.
3020 *
3021 * \returns The number of overloaded declarations referenced by \c cursor. If it
3022 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3023 */
3024CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3025
3026/**
3027 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3028 * by a \c CXCursor_OverloadedDeclRef cursor.
3029 *
3030 * \param cursor The cursor whose overloaded declarations are being queried.
3031 *
3032 * \param index The zero-based index into the set of overloaded declarations in
3033 * the cursor.
3034 *
3035 * \returns A cursor representing the declaration referenced by the given
3036 * \c cursor at the specified \c index. If the cursor does not have an
3037 * associated set of overloaded declarations, or if the index is out of bounds,
3038 * returns \c clang_getNullCursor();
3039 */
3040CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3041 unsigned index);
3042
3043/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00003044 * @}
3045 */
Ted Kremenek95f33552010-08-26 01:42:22 +00003046
3047/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00003048 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00003049 *
3050 * @{
3051 */
3052
3053
3054/**
3055 * \brief For cursors representing an iboutletcollection attribute,
3056 * this function returns the collection element type.
3057 *
3058 */
3059CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3060
3061/**
3062 * @}
3063 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00003064
3065/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003066 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3067 *
3068 * These routines provide the ability to traverse the abstract syntax tree
3069 * using cursors.
3070 *
3071 * @{
3072 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003073
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003074/**
3075 * \brief Describes how the traversal of the children of a particular
3076 * cursor should proceed after visiting a particular child cursor.
3077 *
3078 * A value of this enumeration type should be returned by each
3079 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3080 */
3081enum CXChildVisitResult {
3082 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003083 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003084 */
3085 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003086 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003087 * \brief Continues the cursor traversal with the next sibling of
3088 * the cursor just visited, without visiting its children.
3089 */
3090 CXChildVisit_Continue,
3091 /**
3092 * \brief Recursively traverse the children of this cursor, using
3093 * the same visitor and client data.
3094 */
3095 CXChildVisit_Recurse
3096};
3097
3098/**
3099 * \brief Visitor invoked for each cursor found by a traversal.
3100 *
3101 * This visitor function will be invoked for each cursor found by
3102 * clang_visitCursorChildren(). Its first argument is the cursor being
3103 * visited, its second argument is the parent visitor for that cursor,
3104 * and its third argument is the client data provided to
3105 * clang_visitCursorChildren().
3106 *
3107 * The visitor should return one of the \c CXChildVisitResult values
3108 * to direct clang_visitCursorChildren().
3109 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003110typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3111 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003112 CXClientData client_data);
3113
3114/**
3115 * \brief Visit the children of a particular cursor.
3116 *
3117 * This function visits all the direct children of the given cursor,
3118 * invoking the given \p visitor function with the cursors of each
3119 * visited child. The traversal may be recursive, if the visitor returns
3120 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3121 * the visitor returns \c CXChildVisit_Break.
3122 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003123 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00003124 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003125 * definition, have no children).
3126 *
3127 * \param visitor the visitor function that will be invoked for each
3128 * child of \p parent.
3129 *
3130 * \param client_data pointer data supplied by the client, which will
3131 * be passed to the visitor each time it is invoked.
3132 *
3133 * \returns a non-zero value if the traversal was terminated
3134 * prematurely by the visitor returning \c CXChildVisit_Break.
3135 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003136CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003137 CXCursorVisitor visitor,
3138 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00003139#ifdef __has_feature
3140# if __has_feature(blocks)
3141/**
3142 * \brief Visitor invoked for each cursor found by a traversal.
3143 *
3144 * This visitor block will be invoked for each cursor found by
3145 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3146 * visited, its second argument is the parent visitor for that cursor.
3147 *
3148 * The visitor should return one of the \c CXChildVisitResult values
3149 * to direct clang_visitChildrenWithBlock().
3150 */
3151typedef enum CXChildVisitResult
3152 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3153
3154/**
3155 * Visits the children of a cursor using the specified block. Behaves
3156 * identically to clang_visitChildren() in all other respects.
3157 */
3158unsigned clang_visitChildrenWithBlock(CXCursor parent,
3159 CXCursorVisitorBlock block);
3160# endif
3161#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003162
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003163/**
3164 * @}
3165 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003166
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003167/**
3168 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3169 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003170 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003171 * across translation units, by providing the names of the entities referenced
3172 * by cursors, follow reference cursors to the declarations they reference,
3173 * and associate declarations with their definitions.
3174 *
3175 * @{
3176 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003177
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003178/**
3179 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3180 * by the given cursor.
3181 *
3182 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3183 * entity (function, class, variable, etc.) within a program. USRs can be
3184 * compared across translation units to determine, e.g., when references in
3185 * one translation refer to an entity defined in another translation unit.
3186 */
3187CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3188
3189/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003190 * \brief Construct a USR for a specified Objective-C class.
3191 */
3192CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3193
3194/**
3195 * \brief Construct a USR for a specified Objective-C category.
3196 */
3197CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00003198 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003199 const char *category_name);
3200
3201/**
3202 * \brief Construct a USR for a specified Objective-C protocol.
3203 */
3204CINDEX_LINKAGE CXString
3205 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3206
3207
3208/**
3209 * \brief Construct a USR for a specified Objective-C instance variable and
3210 * the USR for its containing class.
3211 */
3212CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3213 CXString classUSR);
3214
3215/**
3216 * \brief Construct a USR for a specified Objective-C method and
3217 * the USR for its containing class.
3218 */
3219CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3220 unsigned isInstanceMethod,
3221 CXString classUSR);
3222
3223/**
3224 * \brief Construct a USR for a specified Objective-C property and the USR
3225 * for its containing class.
3226 */
3227CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3228 CXString classUSR);
3229
3230/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003231 * \brief Retrieve a name for the entity referenced by this cursor.
3232 */
3233CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3234
Douglas Gregor358559d2010-10-02 22:49:11 +00003235/**
Argyrios Kyrtzidisba1da142012-03-30 20:58:35 +00003236 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3237 * Most of the times there is only one range for the complete spelling but for
3238 * objc methods and objc message expressions, there are multiple pieces for each
3239 * selector identifier.
3240 *
3241 * \param pieceIndex the index of the spelling name piece. If this is greater
3242 * than the actual number of pieces, it will return a NULL (invalid) range.
3243 *
3244 * \param options Reserved.
3245 */
3246CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3247 unsigned pieceIndex,
3248 unsigned options);
3249
3250/**
Douglas Gregor358559d2010-10-02 22:49:11 +00003251 * \brief Retrieve the display name for the entity referenced by this cursor.
3252 *
3253 * The display name contains extra information that helps identify the cursor,
3254 * such as the parameters of a function or template or the arguments of a
3255 * class template specialization.
3256 */
3257CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3258
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003259/** \brief For a cursor that is a reference, retrieve a cursor representing the
3260 * entity that it references.
3261 *
3262 * Reference cursors refer to other entities in the AST. For example, an
3263 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003264 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003265 * cursor for the superclass reference. If the input cursor is a declaration or
3266 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003267 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003268 */
3269CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00003270
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003271/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003272 * \brief For a cursor that is either a reference to or a declaration
3273 * of some entity, retrieve a cursor that describes the definition of
3274 * that entity.
3275 *
3276 * Some entities can be declared multiple times within a translation
3277 * unit, but only one of those declarations can also be a
3278 * definition. For example, given:
3279 *
3280 * \code
3281 * int f(int, int);
3282 * int g(int x, int y) { return f(x, y); }
3283 * int f(int a, int b) { return a + b; }
3284 * int f(int, int);
3285 * \endcode
3286 *
3287 * there are three declarations of the function "f", but only the
3288 * second one is a definition. The clang_getCursorDefinition()
3289 * function will take any cursor pointing to a declaration of "f"
3290 * (the first or fourth lines of the example) or a cursor referenced
3291 * that uses "f" (the call to "f' inside "g") and will return a
3292 * declaration cursor pointing to the definition (the second "f"
3293 * declaration).
3294 *
3295 * If given a cursor for which there is no corresponding definition,
3296 * e.g., because there is no definition of that entity within this
3297 * translation unit, returns a NULL cursor.
3298 */
3299CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3300
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003301/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003302 * \brief Determine whether the declaration pointed to by this cursor
3303 * is also a definition of that entity.
3304 */
3305CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3306
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003307/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003308 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3309 *
3310 * In the C family of languages, many kinds of entities can be declared several
3311 * times within a single translation unit. For example, a structure type can
3312 * be forward-declared (possibly multiple times) and later defined:
3313 *
3314 * \code
3315 * struct X;
3316 * struct X;
3317 * struct X {
3318 * int member;
3319 * };
3320 * \endcode
3321 *
3322 * The declarations and the definition of \c X are represented by three
3323 * different cursors, all of which are declarations of the same underlying
3324 * entity. One of these cursor is considered the "canonical" cursor, which
3325 * is effectively the representative for the underlying entity. One can
3326 * determine if two cursors are declarations of the same underlying entity by
3327 * comparing their canonical cursors.
3328 *
3329 * \returns The canonical cursor for the entity referred to by the given cursor.
3330 */
3331CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3332
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003333
3334/**
3335 * \brief If the cursor points to a selector identifier in a objc method or
3336 * message expression, this returns the selector index.
3337 *
James Dennett7eee0182012-06-15 05:41:51 +00003338 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003339 * determine if the location points to a selector identifier.
3340 *
3341 * \returns The selector index if the cursor is an objc method or message
3342 * expression and the cursor is pointing to a selector identifier, or -1
3343 * otherwise.
3344 */
3345CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3346
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003347/**
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00003348 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3349 * returns non-zero if the method/message is "dynamic", meaning:
3350 *
3351 * For a C++ method: the call is virtual.
3352 * For an ObjC message: the receiver is an object instance, not 'super' or a
3353 * specific class.
3354 *
3355 * If the method/message is "static" or the cursor does not point to a
3356 * method/message, it will return zero.
3357 */
3358CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3359
3360/**
Argyrios Kyrtzidise4a990f2012-11-01 02:01:34 +00003361 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3362 * receiver.
3363 */
3364CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3365
3366/**
Argyrios Kyrtzidis9ee6a662013-04-18 22:15:49 +00003367 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3368 */
3369typedef enum {
3370 CXObjCPropertyAttr_noattr = 0x00,
3371 CXObjCPropertyAttr_readonly = 0x01,
3372 CXObjCPropertyAttr_getter = 0x02,
3373 CXObjCPropertyAttr_assign = 0x04,
3374 CXObjCPropertyAttr_readwrite = 0x08,
3375 CXObjCPropertyAttr_retain = 0x10,
3376 CXObjCPropertyAttr_copy = 0x20,
3377 CXObjCPropertyAttr_nonatomic = 0x40,
3378 CXObjCPropertyAttr_setter = 0x80,
3379 CXObjCPropertyAttr_atomic = 0x100,
3380 CXObjCPropertyAttr_weak = 0x200,
3381 CXObjCPropertyAttr_strong = 0x400,
3382 CXObjCPropertyAttr_unsafe_unretained = 0x800
3383} CXObjCPropertyAttrKind;
3384
3385/**
3386 * \brief Given a cursor that represents a property declaration, return the
3387 * associated property attributes. The bits are formed from
3388 * \c CXObjCPropertyAttrKind.
3389 *
3390 * \param reserved Reserved for future use, pass 0.
3391 */
3392CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3393 unsigned reserved);
3394
3395/**
Argyrios Kyrtzidis38dbad22013-04-18 23:29:12 +00003396 * \brief 'Qualifiers' written next to the return and parameter types in
3397 * ObjC method declarations.
3398 */
3399typedef enum {
3400 CXObjCDeclQualifier_None = 0x0,
3401 CXObjCDeclQualifier_In = 0x1,
3402 CXObjCDeclQualifier_Inout = 0x2,
3403 CXObjCDeclQualifier_Out = 0x4,
3404 CXObjCDeclQualifier_Bycopy = 0x8,
3405 CXObjCDeclQualifier_Byref = 0x10,
3406 CXObjCDeclQualifier_Oneway = 0x20
3407} CXObjCDeclQualifierKind;
3408
3409/**
3410 * \brief Given a cursor that represents an ObjC method or parameter
3411 * declaration, return the associated ObjC qualifiers for the return type or the
Argyrios Kyrtzidis8be71a62013-04-19 00:51:52 +00003412 * parameter respectively. The bits are formed from CXObjCDeclQualifierKind.
Argyrios Kyrtzidis38dbad22013-04-18 23:29:12 +00003413 */
3414CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3415
3416/**
Argyrios Kyrtzidis80e1aca2013-04-18 23:53:05 +00003417 * \brief Returns non-zero if the given cursor is a variadic function or method.
3418 */
3419CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3420
3421/**
Dmitri Gribenkoaa0cd852012-06-20 00:34:58 +00003422 * \brief Given a cursor that represents a declaration, return the associated
3423 * comment's source range. The range may include multiple consecutive comments
3424 * with whitespace in between.
3425 */
3426CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3427
3428/**
3429 * \brief Given a cursor that represents a declaration, return the associated
3430 * comment text, including comment markers.
3431 */
3432CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3433
3434/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003435 * \brief Given a cursor that represents a documentable entity (e.g.,
3436 * declaration), return the associated \\brief paragraph; otherwise return the
3437 * first paragraph.
Dmitri Gribenko2d44d772012-06-26 20:39:18 +00003438 */
3439CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3440
3441/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003442 * \brief Given a cursor that represents a documentable entity (e.g.,
3443 * declaration), return the associated parsed comment as a
3444 * \c CXComment_FullComment AST node.
3445 */
3446CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3447
3448/**
3449 * @}
3450 */
3451
3452/**
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003453 * \defgroup CINDEX_MODULE Module introspection
3454 *
3455 * The functions in this group provide access to information about modules.
3456 *
3457 * @{
3458 */
3459
3460typedef void *CXModule;
3461
3462/**
3463 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3464 */
3465CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3466
3467/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003468 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003469 *
Argyrios Kyrtzidise858e662013-04-26 22:47:49 +00003470 * \returns the module file where the provided module object came from.
3471 */
3472CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3473
3474/**
3475 * \param Module a module object.
3476 *
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003477 * \returns the parent of a sub-module or NULL if the given module is top-level,
3478 * e.g. for 'std.vector' it will return the 'std' module.
3479 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003480CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003481
3482/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003483 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003484 *
3485 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3486 * will return "vector".
3487 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003488CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003489
3490/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003491 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003492 *
3493 * \returns the full name of the module, e.g. "std.vector".
3494 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003495CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003496
3497/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003498 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003499 *
3500 * \returns the number of top level headers associated with this module.
3501 */
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +00003502CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3503 CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003504
3505/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003506 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003507 *
3508 * \param Index top level header index (zero-based).
3509 *
3510 * \returns the specified top level header associated with the module.
3511 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003512CINDEX_LINKAGE
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +00003513CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3514 CXModule Module, unsigned Index);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003515
3516/**
3517 * @}
3518 */
3519
3520/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003521 * \defgroup CINDEX_COMMENT Comment AST introspection
3522 *
3523 * The routines in this group provide access to information in the
3524 * documentation comment ASTs.
3525 *
3526 * @{
3527 */
3528
3529/**
3530 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3531 * node can be considered block content (e. g., paragraph), inline content
3532 * (plain text) or neither (the root AST node).
3533 */
3534enum CXCommentKind {
3535 /**
3536 * \brief Null comment. No AST node is constructed at the requested location
3537 * because there is no text or a syntax error.
3538 */
3539 CXComment_Null = 0,
3540
3541 /**
3542 * \brief Plain text. Inline content.
3543 */
3544 CXComment_Text = 1,
3545
3546 /**
3547 * \brief A command with word-like arguments that is considered inline content.
3548 *
3549 * For example: \\c command.
3550 */
3551 CXComment_InlineCommand = 2,
3552
3553 /**
3554 * \brief HTML start tag with attributes (name-value pairs). Considered
3555 * inline content.
3556 *
3557 * For example:
3558 * \verbatim
3559 * <br> <br /> <a href="http://example.org/">
3560 * \endverbatim
3561 */
3562 CXComment_HTMLStartTag = 3,
3563
3564 /**
3565 * \brief HTML end tag. Considered inline content.
3566 *
3567 * For example:
3568 * \verbatim
3569 * </a>
3570 * \endverbatim
3571 */
3572 CXComment_HTMLEndTag = 4,
3573
3574 /**
3575 * \brief A paragraph, contains inline comment. The paragraph itself is
3576 * block content.
3577 */
3578 CXComment_Paragraph = 5,
3579
3580 /**
3581 * \brief A command that has zero or more word-like arguments (number of
3582 * word-like arguments depends on command name) and a paragraph as an
3583 * argument. Block command is block content.
3584 *
3585 * Paragraph argument is also a child of the block command.
3586 *
3587 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3588 *
3589 * AST nodes of special kinds that parser knows about (e. g., \\param
3590 * command) have their own node kinds.
3591 */
3592 CXComment_BlockCommand = 6,
3593
3594 /**
3595 * \brief A \\param or \\arg command that describes the function parameter
3596 * (name, passing direction, description).
3597 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003598 * For example: \\param [in] ParamName description.
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003599 */
3600 CXComment_ParamCommand = 7,
3601
3602 /**
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003603 * \brief A \\tparam command that describes a template parameter (name and
3604 * description).
3605 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003606 * For example: \\tparam T description.
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003607 */
3608 CXComment_TParamCommand = 8,
3609
3610 /**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003611 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3612 * block has an opening and a closing command and contains multiple lines of
3613 * text (\c CXComment_VerbatimBlockLine child nodes).
3614 *
3615 * For example:
3616 * \\verbatim
3617 * aaa
3618 * \\endverbatim
3619 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003620 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003621
3622 /**
3623 * \brief A line of text that is contained within a
3624 * CXComment_VerbatimBlockCommand node.
3625 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003626 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003627
3628 /**
3629 * \brief A verbatim line command. Verbatim line has an opening command,
3630 * a single line of text (up to the newline after the opening command) and
3631 * has no closing command.
3632 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003633 CXComment_VerbatimLine = 11,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003634
3635 /**
3636 * \brief A full comment attached to a declaration, contains block content.
3637 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003638 CXComment_FullComment = 12
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003639};
3640
3641/**
Dmitri Gribenko2d66a502012-07-23 16:43:01 +00003642 * \brief The most appropriate rendering mode for an inline command, chosen on
3643 * command semantics in Doxygen.
3644 */
3645enum CXCommentInlineCommandRenderKind {
3646 /**
3647 * \brief Command argument should be rendered in a normal font.
3648 */
3649 CXCommentInlineCommandRenderKind_Normal,
3650
3651 /**
3652 * \brief Command argument should be rendered in a bold font.
3653 */
3654 CXCommentInlineCommandRenderKind_Bold,
3655
3656 /**
3657 * \brief Command argument should be rendered in a monospaced font.
3658 */
3659 CXCommentInlineCommandRenderKind_Monospaced,
3660
3661 /**
3662 * \brief Command argument should be rendered emphasized (typically italic
3663 * font).
3664 */
3665 CXCommentInlineCommandRenderKind_Emphasized
3666};
3667
3668/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003669 * \brief Describes parameter passing direction for \\param or \\arg command.
3670 */
3671enum CXCommentParamPassDirection {
3672 /**
3673 * \brief The parameter is an input parameter.
3674 */
3675 CXCommentParamPassDirection_In,
3676
3677 /**
3678 * \brief The parameter is an output parameter.
3679 */
3680 CXCommentParamPassDirection_Out,
3681
3682 /**
3683 * \brief The parameter is an input and output parameter.
3684 */
3685 CXCommentParamPassDirection_InOut
3686};
3687
3688/**
3689 * \param Comment AST node of any kind.
3690 *
3691 * \returns the type of the AST node.
3692 */
3693CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3694
3695/**
3696 * \param Comment AST node of any kind.
3697 *
3698 * \returns number of children of the AST node.
3699 */
3700CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3701
3702/**
3703 * \param Comment AST node of any kind.
3704 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003705 * \param ChildIdx child index (zero-based).
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003706 *
3707 * \returns the specified child of the AST node.
3708 */
3709CINDEX_LINKAGE
3710CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3711
3712/**
3713 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3714 * only \c CXComment_Text nodes that are empty or whitespace.
3715 *
3716 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3717 * never considered whitespace.
3718 *
3719 * \returns non-zero if \c Comment is whitespace.
3720 */
3721CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3722
3723/**
3724 * \returns non-zero if \c Comment is inline content and has a newline
3725 * immediately following it in the comment text. Newlines between paragraphs
3726 * do not count.
3727 */
3728CINDEX_LINKAGE
3729unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3730
3731/**
3732 * \param Comment a \c CXComment_Text AST node.
3733 *
3734 * \returns text contained in the AST node.
3735 */
3736CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3737
3738/**
3739 * \param Comment a \c CXComment_InlineCommand AST node.
3740 *
3741 * \returns name of the inline command.
3742 */
3743CINDEX_LINKAGE
3744CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3745
3746/**
3747 * \param Comment a \c CXComment_InlineCommand AST node.
3748 *
Dmitri Gribenko2d66a502012-07-23 16:43:01 +00003749 * \returns the most appropriate rendering mode, chosen on command
3750 * semantics in Doxygen.
3751 */
3752CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3753clang_InlineCommandComment_getRenderKind(CXComment Comment);
3754
3755/**
3756 * \param Comment a \c CXComment_InlineCommand AST node.
3757 *
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003758 * \returns number of command arguments.
3759 */
3760CINDEX_LINKAGE
3761unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3762
3763/**
3764 * \param Comment a \c CXComment_InlineCommand AST node.
3765 *
3766 * \param ArgIdx argument index (zero-based).
3767 *
3768 * \returns text of the specified argument.
3769 */
3770CINDEX_LINKAGE
3771CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3772 unsigned ArgIdx);
3773
3774/**
3775 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3776 * node.
3777 *
3778 * \returns HTML tag name.
3779 */
3780CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3781
3782/**
3783 * \param Comment a \c CXComment_HTMLStartTag AST node.
3784 *
3785 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3786 */
3787CINDEX_LINKAGE
3788unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3789
3790/**
3791 * \param Comment a \c CXComment_HTMLStartTag AST node.
3792 *
3793 * \returns number of attributes (name-value pairs) attached to the start tag.
3794 */
3795CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3796
3797/**
3798 * \param Comment a \c CXComment_HTMLStartTag AST node.
3799 *
3800 * \param AttrIdx attribute index (zero-based).
3801 *
3802 * \returns name of the specified attribute.
3803 */
3804CINDEX_LINKAGE
3805CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3806
3807/**
3808 * \param Comment a \c CXComment_HTMLStartTag AST node.
3809 *
3810 * \param AttrIdx attribute index (zero-based).
3811 *
3812 * \returns value of the specified attribute.
3813 */
3814CINDEX_LINKAGE
3815CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3816
3817/**
3818 * \param Comment a \c CXComment_BlockCommand AST node.
3819 *
3820 * \returns name of the block command.
3821 */
3822CINDEX_LINKAGE
3823CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3824
3825/**
3826 * \param Comment a \c CXComment_BlockCommand AST node.
3827 *
3828 * \returns number of word-like arguments.
3829 */
3830CINDEX_LINKAGE
3831unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3832
3833/**
3834 * \param Comment a \c CXComment_BlockCommand AST node.
3835 *
3836 * \param ArgIdx argument index (zero-based).
3837 *
3838 * \returns text of the specified word-like argument.
3839 */
3840CINDEX_LINKAGE
3841CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3842 unsigned ArgIdx);
3843
3844/**
3845 * \param Comment a \c CXComment_BlockCommand or
3846 * \c CXComment_VerbatimBlockCommand AST node.
3847 *
3848 * \returns paragraph argument of the block command.
3849 */
3850CINDEX_LINKAGE
3851CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3852
3853/**
3854 * \param Comment a \c CXComment_ParamCommand AST node.
3855 *
3856 * \returns parameter name.
3857 */
3858CINDEX_LINKAGE
3859CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3860
3861/**
3862 * \param Comment a \c CXComment_ParamCommand AST node.
3863 *
3864 * \returns non-zero if the parameter that this AST node represents was found
3865 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3866 * function will return a meaningful value.
3867 */
3868CINDEX_LINKAGE
3869unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3870
3871/**
3872 * \param Comment a \c CXComment_ParamCommand AST node.
3873 *
3874 * \returns zero-based parameter index in function prototype.
3875 */
3876CINDEX_LINKAGE
3877unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3878
3879/**
3880 * \param Comment a \c CXComment_ParamCommand AST node.
3881 *
3882 * \returns non-zero if parameter passing direction was specified explicitly in
3883 * the comment.
3884 */
3885CINDEX_LINKAGE
3886unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3887
3888/**
3889 * \param Comment a \c CXComment_ParamCommand AST node.
3890 *
3891 * \returns parameter passing direction.
3892 */
3893CINDEX_LINKAGE
3894enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
3895 CXComment Comment);
3896
3897/**
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003898 * \param Comment a \c CXComment_TParamCommand AST node.
3899 *
3900 * \returns template parameter name.
3901 */
3902CINDEX_LINKAGE
3903CXString clang_TParamCommandComment_getParamName(CXComment Comment);
3904
3905/**
3906 * \param Comment a \c CXComment_TParamCommand AST node.
3907 *
3908 * \returns non-zero if the parameter that this AST node represents was found
3909 * in the template parameter list and
3910 * \c clang_TParamCommandComment_getDepth and
3911 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
3912 * value.
3913 */
3914CINDEX_LINKAGE
3915unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
3916
3917/**
3918 * \param Comment a \c CXComment_TParamCommand AST node.
3919 *
3920 * \returns zero-based nesting depth of this parameter in the template parameter list.
3921 *
3922 * For example,
3923 * \verbatim
3924 * template<typename C, template<typename T> class TT>
3925 * void test(TT<int> aaa);
3926 * \endverbatim
3927 * for C and TT nesting depth is 0,
3928 * for T nesting depth is 1.
3929 */
3930CINDEX_LINKAGE
3931unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
3932
3933/**
3934 * \param Comment a \c CXComment_TParamCommand AST node.
3935 *
3936 * \returns zero-based parameter index in the template parameter list at a
3937 * given nesting depth.
3938 *
3939 * For example,
3940 * \verbatim
3941 * template<typename C, template<typename T> class TT>
3942 * void test(TT<int> aaa);
3943 * \endverbatim
3944 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
3945 * at depth 0 C's index is 0, TT's index is 1.
3946 *
3947 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
3948 * at depth 0 T's index is 1 (same as TT's),
3949 * at depth 1 T's index is 0.
3950 */
3951CINDEX_LINKAGE
3952unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
3953
3954/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003955 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
3956 *
3957 * \returns text contained in the AST node.
3958 */
3959CINDEX_LINKAGE
3960CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
3961
3962/**
3963 * \param Comment a \c CXComment_VerbatimLine AST node.
3964 *
3965 * \returns text contained in the AST node.
3966 */
3967CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
3968
3969/**
3970 * \brief Convert an HTML tag AST node to string.
3971 *
3972 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3973 * node.
3974 *
3975 * \returns string containing an HTML tag.
3976 */
3977CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
3978
3979/**
3980 * \brief Convert a given full parsed comment to an HTML fragment.
3981 *
3982 * Specific details of HTML layout are subject to change. Don't try to parse
3983 * this HTML back into an AST, use other APIs instead.
3984 *
3985 * Currently the following CSS classes are used:
3986 * \li "para-brief" for \\brief paragraph and equivalent commands;
3987 * \li "para-returns" for \\returns paragraph and equivalent commands;
3988 * \li "word-returns" for the "Returns" word in \\returns paragraph.
3989 *
Dmitri Gribenko3e63d332012-07-21 01:47:43 +00003990 * Function argument documentation is rendered as a \<dl\> list with arguments
3991 * sorted in function prototype order. CSS classes used:
3992 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
3993 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
3994 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
3995 * parameter index is invalid.
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003996 *
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003997 * Template parameter documentation is rendered as a \<dl\> list with
3998 * parameters sorted in template parameter list order. CSS classes used:
3999 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
4000 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko6a425522012-08-01 23:47:30 +00004001 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko96b09862012-07-31 22:37:06 +00004002 * names inside template template parameters;
4003 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
4004 * parameter position is invalid.
4005 *
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00004006 * \param Comment a \c CXComment_FullComment AST node.
4007 *
4008 * \returns string containing an HTML fragment.
4009 */
4010CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
4011
4012/**
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00004013 * \brief Convert a given full parsed comment to an XML document.
4014 *
4015 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
4016 * inside clang source tree.
4017 *
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00004018 * \param Comment a \c CXComment_FullComment AST node.
4019 *
4020 * \returns string containing an XML document.
4021 */
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00004022CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00004023
4024/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004025 * @}
4026 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004027
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004028/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00004029 * \defgroup CINDEX_CPP C++ AST introspection
4030 *
4031 * The routines in this group provide access information in the ASTs specific
4032 * to C++ language features.
4033 *
4034 * @{
4035 */
4036
4037/**
Dmitri Gribenkoc965f762013-05-17 18:38:35 +00004038 * \brief Determine if a C++ member function or member function template is
4039 * pure virtual.
4040 */
4041CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4042
4043/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00004044 * \brief Determine if a C++ member function or member function template is
4045 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00004046 */
4047CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4048
4049/**
Douglas Gregor211924b2011-05-12 15:17:24 +00004050 * \brief Determine if a C++ member function or member function template is
4051 * explicitly declared 'virtual' or if it overrides a virtual method from
4052 * one of the base classes.
4053 */
4054CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4055
4056/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00004057 * \brief Given a cursor that represents a template, determine
4058 * the cursor kind of the specializations would be generated by instantiating
4059 * the template.
4060 *
4061 * This routine can be used to determine what flavor of function template,
4062 * class template, or class template partial specialization is stored in the
4063 * cursor. For example, it can describe whether a class template cursor is
4064 * declared with "struct", "class" or "union".
4065 *
4066 * \param C The cursor to query. This cursor should represent a template
4067 * declaration.
4068 *
4069 * \returns The cursor kind of the specializations that would be generated
4070 * by instantiating the template \p C. If \p C is not a template, returns
4071 * \c CXCursor_NoDeclFound.
4072 */
4073CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4074
4075/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00004076 * \brief Given a cursor that may represent a specialization or instantiation
4077 * of a template, retrieve the cursor that represents the template that it
4078 * specializes or from which it was instantiated.
4079 *
4080 * This routine determines the template involved both for explicit
4081 * specializations of templates and for implicit instantiations of the template,
4082 * both of which are referred to as "specializations". For a class template
4083 * specialization (e.g., \c std::vector<bool>), this routine will return
4084 * either the primary template (\c std::vector) or, if the specialization was
4085 * instantiated from a class template partial specialization, the class template
4086 * partial specialization. For a class template partial specialization and a
4087 * function template specialization (including instantiations), this
4088 * this routine will return the specialized template.
4089 *
4090 * For members of a class template (e.g., member functions, member classes, or
4091 * static data members), returns the specialized or instantiated member.
4092 * Although not strictly "templates" in the C++ language, members of class
4093 * templates have the same notions of specializations and instantiations that
4094 * templates do, so this routine treats them similarly.
4095 *
4096 * \param C A cursor that may be a specialization of a template or a member
4097 * of a template.
4098 *
4099 * \returns If the given cursor is a specialization or instantiation of a
4100 * template or a member thereof, the template or member that it specializes or
4101 * from which it was instantiated. Otherwise, returns a NULL cursor.
4102 */
4103CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00004104
4105/**
4106 * \brief Given a cursor that references something else, return the source range
4107 * covering that reference.
4108 *
4109 * \param C A cursor pointing to a member reference, a declaration reference, or
4110 * an operator call.
4111 * \param NameFlags A bitset with three independent flags:
4112 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4113 * CXNameRange_WantSinglePiece.
4114 * \param PieceIndex For contiguous names or when passing the flag
4115 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4116 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer48d798c2012-06-02 10:20:41 +00004117 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregor430d7a12011-07-25 17:48:11 +00004118 * pieces of the name. See also CXNameRange_WantSinglePiece.
4119 *
4120 * \returns The piece of the name pointed to by the given cursor. If there is no
4121 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4122 */
Francois Pichet48a8d142011-07-25 22:00:44 +00004123CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4124 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00004125 unsigned PieceIndex);
4126
4127enum CXNameRefFlags {
4128 /**
4129 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4130 * range.
4131 */
4132 CXNameRange_WantQualifier = 0x1,
4133
4134 /**
James Dennett7eee0182012-06-15 05:41:51 +00004135 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4136 * in the range.
Douglas Gregor430d7a12011-07-25 17:48:11 +00004137 */
4138 CXNameRange_WantTemplateArgs = 0x2,
4139
4140 /**
4141 * \brief If the name is non-contiguous, return the full spanning range.
4142 *
4143 * Non-contiguous names occur in Objective-C when a selector with two or more
4144 * parameters is used, or in C++ when using an operator:
4145 * \code
4146 * [object doSomething:here withValue:there]; // ObjC
4147 * return some_vector[1]; // C++
4148 * \endcode
4149 */
4150 CXNameRange_WantSinglePiece = 0x4
4151};
Douglas Gregore0329ac2010-09-02 00:07:54 +00004152
4153/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00004154 * @}
4155 */
4156
4157/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004158 * \defgroup CINDEX_LEX Token extraction and manipulation
4159 *
4160 * The routines in this group provide access to the tokens within a
4161 * translation unit, along with a semantic mapping of those tokens to
4162 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004163 *
4164 * @{
4165 */
4166
4167/**
4168 * \brief Describes a kind of token.
4169 */
4170typedef enum CXTokenKind {
4171 /**
4172 * \brief A token that contains some kind of punctuation.
4173 */
4174 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004175
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004176 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004177 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004178 */
4179 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004180
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004181 /**
4182 * \brief An identifier (that is not a keyword).
4183 */
4184 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004185
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004186 /**
4187 * \brief A numeric, string, or character literal.
4188 */
4189 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004190
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004191 /**
4192 * \brief A comment.
4193 */
4194 CXToken_Comment
4195} CXTokenKind;
4196
4197/**
4198 * \brief Describes a single preprocessing token.
4199 */
4200typedef struct {
4201 unsigned int_data[4];
4202 void *ptr_data;
4203} CXToken;
4204
4205/**
4206 * \brief Determine the kind of the given token.
4207 */
4208CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004209
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004210/**
4211 * \brief Determine the spelling of the given token.
4212 *
4213 * The spelling of a token is the textual representation of that token, e.g.,
4214 * the text of an identifier or keyword.
4215 */
4216CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004217
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004218/**
4219 * \brief Retrieve the source location of the given token.
4220 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004221CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004222 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004223
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004224/**
4225 * \brief Retrieve a source range that covers the given token.
4226 */
4227CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4228
4229/**
4230 * \brief Tokenize the source code described by the given range into raw
4231 * lexical tokens.
4232 *
4233 * \param TU the translation unit whose text is being tokenized.
4234 *
4235 * \param Range the source range in which text should be tokenized. All of the
4236 * tokens produced by tokenization will fall within this source range,
4237 *
4238 * \param Tokens this pointer will be set to point to the array of tokens
4239 * that occur within the given source range. The returned pointer must be
4240 * freed with clang_disposeTokens() before the translation unit is destroyed.
4241 *
4242 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4243 * array.
4244 *
4245 */
4246CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4247 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004248
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004249/**
4250 * \brief Annotate the given set of tokens by providing cursors for each token
4251 * that can be mapped to a specific entity within the abstract syntax tree.
4252 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004253 * This token-annotation routine is equivalent to invoking
4254 * clang_getCursor() for the source locations of each of the
4255 * tokens. The cursors provided are filtered, so that only those
4256 * cursors that have a direct correspondence to the token are
4257 * accepted. For example, given a function call \c f(x),
4258 * clang_getCursor() would provide the following cursors:
4259 *
4260 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4261 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4262 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4263 *
4264 * Only the first and last of these cursors will occur within the
4265 * annotate, since the tokens "f" and "x' directly refer to a function
4266 * and a variable, respectively, but the parentheses are just a small
4267 * part of the full syntax of the function call expression, which is
4268 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004269 *
4270 * \param TU the translation unit that owns the given tokens.
4271 *
4272 * \param Tokens the set of tokens to annotate.
4273 *
4274 * \param NumTokens the number of tokens in \p Tokens.
4275 *
4276 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4277 * replaced with the cursors corresponding to each token.
4278 */
4279CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4280 CXToken *Tokens, unsigned NumTokens,
4281 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004282
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004283/**
4284 * \brief Free the given set of tokens.
4285 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004286CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004287 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004288
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004289/**
4290 * @}
4291 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004292
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004293/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004294 * \defgroup CINDEX_DEBUG Debugging facilities
4295 *
4296 * These routines are used for testing and debugging, only, and should not
4297 * be relied upon.
4298 *
4299 * @{
4300 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004301
Steve Naroff4ade6d62009-09-23 17:52:52 +00004302/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00004303CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004304CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4305 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00004306 const char **endBuf,
4307 unsigned *startLine,
4308 unsigned *startColumn,
4309 unsigned *endLine,
4310 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00004311CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00004312CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4313 unsigned stack_size);
4314
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004315/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004316 * @}
4317 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004318
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004319/**
4320 * \defgroup CINDEX_CODE_COMPLET Code completion
4321 *
4322 * Code completion involves taking an (incomplete) source file, along with
4323 * knowledge of where the user is actively editing that file, and suggesting
4324 * syntactically- and semantically-valid constructs that the user might want to
4325 * use at that particular point in the source code. These data structures and
4326 * routines provide support for code completion.
4327 *
4328 * @{
4329 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004330
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004331/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004332 * \brief A semantic string that describes a code-completion result.
4333 *
4334 * A semantic string that describes the formatting of a code-completion
4335 * result as a single "template" of text that should be inserted into the
4336 * source buffer when a particular code-completion result is selected.
4337 * Each semantic string is made up of some number of "chunks", each of which
4338 * contains some text along with a description of what that text means, e.g.,
4339 * the name of the entity being referenced, whether the text chunk is part of
4340 * the template, or whether it is a "placeholder" that the user should replace
4341 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004342 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004343 */
4344typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004345
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004346/**
4347 * \brief A single result of code completion.
4348 */
4349typedef struct {
4350 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004351 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004352 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004353 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004354 * *Decl cursor kinds), describing the entity that the completion is
4355 * referring to.
4356 *
4357 * \todo In the future, we would like to provide a full cursor, to allow
4358 * the client to extract additional information from declaration.
4359 */
4360 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004361
4362 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004363 * \brief The code-completion string that describes how to insert this
4364 * code-completion result into the editing buffer.
4365 */
4366 CXCompletionString CompletionString;
4367} CXCompletionResult;
4368
4369/**
4370 * \brief Describes a single piece of text within a code-completion string.
4371 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004372 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4373 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004374 * should be interpreted by the client or is another completion string.
4375 */
4376enum CXCompletionChunkKind {
4377 /**
4378 * \brief A code-completion string that describes "optional" text that
4379 * could be a part of the template (but is not required).
4380 *
4381 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004382 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004383 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4384 * describes an additional part of the template that is completely optional.
4385 * For example, optional chunks can be used to describe the placeholders for
4386 * arguments that match up with defaulted function parameters, e.g. given:
4387 *
4388 * \code
4389 * void f(int x, float y = 3.14, double z = 2.71828);
4390 * \endcode
4391 *
4392 * The code-completion string for this function would contain:
4393 * - a TypedText chunk for "f".
4394 * - a LeftParen chunk for "(".
4395 * - a Placeholder chunk for "int x"
4396 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4397 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00004398 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004399 * - an Optional chunk containing the last defaulted argument:
4400 * - a Comma chunk for ","
4401 * - a Placeholder chunk for "double z"
4402 * - a RightParen chunk for ")"
4403 *
Daniel Dunbar71570182010-02-17 08:07:44 +00004404 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004405 * - Completely ignore optional chunks, in which case the template for the
4406 * function "f" would only include the first parameter ("int x").
4407 * - Fully expand all optional chunks, in which case the template for the
4408 * function "f" would have all of the parameters.
4409 */
4410 CXCompletionChunk_Optional,
4411 /**
4412 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004413 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004414 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004415 * There will be exactly one "typed text" chunk in a semantic string, which
4416 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004417 * declaration that could be used at the current code point. Clients are
4418 * expected to filter the code-completion results based on the text in this
4419 * chunk.
4420 */
4421 CXCompletionChunk_TypedText,
4422 /**
4423 * \brief Text that should be inserted as part of a code-completion result.
4424 *
4425 * A "text" chunk represents text that is part of the template to be
4426 * inserted into user code should this particular code-completion result
4427 * be selected.
4428 */
4429 CXCompletionChunk_Text,
4430 /**
4431 * \brief Placeholder text that should be replaced by the user.
4432 *
4433 * A "placeholder" chunk marks a place where the user should insert text
4434 * into the code-completion template. For example, placeholders might mark
4435 * the function parameters for a function declaration, to indicate that the
4436 * user should provide arguments for each of those parameters. The actual
4437 * text in a placeholder is a suggestion for the text to display before
4438 * the user replaces the placeholder with real code.
4439 */
4440 CXCompletionChunk_Placeholder,
4441 /**
4442 * \brief Informative text that should be displayed but never inserted as
4443 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004444 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004445 * An "informative" chunk contains annotations that can be displayed to
4446 * help the user decide whether a particular code-completion result is the
4447 * right option, but which is not part of the actual template to be inserted
4448 * by code completion.
4449 */
4450 CXCompletionChunk_Informative,
4451 /**
4452 * \brief Text that describes the current parameter when code-completion is
4453 * referring to function call, message send, or template specialization.
4454 *
4455 * A "current parameter" chunk occurs when code-completion is providing
4456 * information about a parameter corresponding to the argument at the
4457 * code-completion point. For example, given a function
4458 *
4459 * \code
4460 * int add(int x, int y);
4461 * \endcode
4462 *
4463 * and the source code \c add(, where the code-completion point is after the
4464 * "(", the code-completion string will contain a "current parameter" chunk
4465 * for "int x", indicating that the current argument will initialize that
4466 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004467 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004468 * "current paremeter" chunk to "int y".
4469 */
4470 CXCompletionChunk_CurrentParameter,
4471 /**
4472 * \brief A left parenthesis ('('), used to initiate a function call or
4473 * signal the beginning of a function parameter list.
4474 */
4475 CXCompletionChunk_LeftParen,
4476 /**
4477 * \brief A right parenthesis (')'), used to finish a function call or
4478 * signal the end of a function parameter list.
4479 */
4480 CXCompletionChunk_RightParen,
4481 /**
4482 * \brief A left bracket ('[').
4483 */
4484 CXCompletionChunk_LeftBracket,
4485 /**
4486 * \brief A right bracket (']').
4487 */
4488 CXCompletionChunk_RightBracket,
4489 /**
4490 * \brief A left brace ('{').
4491 */
4492 CXCompletionChunk_LeftBrace,
4493 /**
4494 * \brief A right brace ('}').
4495 */
4496 CXCompletionChunk_RightBrace,
4497 /**
4498 * \brief A left angle bracket ('<').
4499 */
4500 CXCompletionChunk_LeftAngle,
4501 /**
4502 * \brief A right angle bracket ('>').
4503 */
4504 CXCompletionChunk_RightAngle,
4505 /**
4506 * \brief A comma separator (',').
4507 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004508 CXCompletionChunk_Comma,
4509 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004510 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004511 *
4512 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004513 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004514 * expression using the given completion string would have.
4515 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00004516 CXCompletionChunk_ResultType,
4517 /**
4518 * \brief A colon (':').
4519 */
4520 CXCompletionChunk_Colon,
4521 /**
4522 * \brief A semicolon (';').
4523 */
4524 CXCompletionChunk_SemiColon,
4525 /**
4526 * \brief An '=' sign.
4527 */
4528 CXCompletionChunk_Equal,
4529 /**
4530 * Horizontal space (' ').
4531 */
4532 CXCompletionChunk_HorizontalSpace,
4533 /**
4534 * Vertical space ('\n'), after which it is generally a good idea to
4535 * perform indentation.
4536 */
4537 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004538};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004539
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004540/**
4541 * \brief Determine the kind of a particular chunk within a completion string.
4542 *
4543 * \param completion_string the completion string to query.
4544 *
4545 * \param chunk_number the 0-based index of the chunk in the completion string.
4546 *
4547 * \returns the kind of the chunk at the index \c chunk_number.
4548 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004549CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004550clang_getCompletionChunkKind(CXCompletionString completion_string,
4551 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004552
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004553/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004554 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004555 * completion string.
4556 *
4557 * \param completion_string the completion string to query.
4558 *
4559 * \param chunk_number the 0-based index of the chunk in the completion string.
4560 *
4561 * \returns the text associated with the chunk at index \c chunk_number.
4562 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00004563CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004564clang_getCompletionChunkText(CXCompletionString completion_string,
4565 unsigned chunk_number);
4566
4567/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004568 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004569 * within a completion string.
4570 *
4571 * \param completion_string the completion string to query.
4572 *
4573 * \param chunk_number the 0-based index of the chunk in the completion string.
4574 *
4575 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00004576 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004577 */
4578CINDEX_LINKAGE CXCompletionString
4579clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4580 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004581
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004582/**
4583 * \brief Retrieve the number of chunks in the given code-completion string.
4584 */
4585CINDEX_LINKAGE unsigned
4586clang_getNumCompletionChunks(CXCompletionString completion_string);
4587
4588/**
Douglas Gregor12e13132010-05-26 22:00:08 +00004589 * \brief Determine the priority of this code completion.
4590 *
4591 * The priority of a code completion indicates how likely it is that this
4592 * particular completion is the completion that the user will select. The
4593 * priority is selected by various internal heuristics.
4594 *
4595 * \param completion_string The completion string to query.
4596 *
4597 * \returns The priority of this completion string. Smaller values indicate
4598 * higher-priority (more likely) completions.
4599 */
4600CINDEX_LINKAGE unsigned
4601clang_getCompletionPriority(CXCompletionString completion_string);
4602
4603/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00004604 * \brief Determine the availability of the entity that this code-completion
4605 * string refers to.
4606 *
4607 * \param completion_string The completion string to query.
4608 *
4609 * \returns The availability of the completion string.
4610 */
4611CINDEX_LINKAGE enum CXAvailabilityKind
4612clang_getCompletionAvailability(CXCompletionString completion_string);
4613
4614/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00004615 * \brief Retrieve the number of annotations associated with the given
4616 * completion string.
4617 *
4618 * \param completion_string the completion string to query.
4619 *
4620 * \returns the number of annotations associated with the given completion
4621 * string.
4622 */
4623CINDEX_LINKAGE unsigned
4624clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4625
4626/**
4627 * \brief Retrieve the annotation associated with the given completion string.
4628 *
4629 * \param completion_string the completion string to query.
4630 *
4631 * \param annotation_number the 0-based index of the annotation of the
4632 * completion string.
4633 *
4634 * \returns annotation string associated with the completion at index
4635 * \c annotation_number, or a NULL string if that annotation is not available.
4636 */
4637CINDEX_LINKAGE CXString
4638clang_getCompletionAnnotation(CXCompletionString completion_string,
4639 unsigned annotation_number);
4640
4641/**
Douglas Gregorba103062012-03-27 23:34:16 +00004642 * \brief Retrieve the parent context of the given completion string.
4643 *
4644 * The parent context of a completion string is the semantic parent of
4645 * the declaration (if any) that the code completion represents. For example,
4646 * a code completion for an Objective-C method would have the method's class
4647 * or protocol as its context.
4648 *
4649 * \param completion_string The code completion string whose parent is
4650 * being queried.
4651 *
Argyrios Kyrtzidis526d2442012-09-26 16:39:56 +00004652 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregorba103062012-03-27 23:34:16 +00004653 *
James Dennett7eee0182012-06-15 05:41:51 +00004654 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregorba103062012-03-27 23:34:16 +00004655 * the completion string represents a method in the NSObject class.
4656 */
4657CINDEX_LINKAGE CXString
4658clang_getCompletionParent(CXCompletionString completion_string,
4659 enum CXCursorKind *kind);
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00004660
4661/**
4662 * \brief Retrieve the brief documentation comment attached to the declaration
4663 * that corresponds to the given completion string.
4664 */
4665CINDEX_LINKAGE CXString
4666clang_getCompletionBriefComment(CXCompletionString completion_string);
4667
Douglas Gregorba103062012-03-27 23:34:16 +00004668/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00004669 * \brief Retrieve a completion string for an arbitrary declaration or macro
4670 * definition cursor.
4671 *
4672 * \param cursor The cursor to query.
4673 *
4674 * \returns A non-context-sensitive completion string for declaration and macro
4675 * definition cursors, or NULL for other kinds of cursors.
4676 */
4677CINDEX_LINKAGE CXCompletionString
4678clang_getCursorCompletionString(CXCursor cursor);
4679
4680/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004681 * \brief Contains the results of code-completion.
4682 *
4683 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00004684 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00004685 * \c clang_disposeCodeCompleteResults.
4686 */
4687typedef struct {
4688 /**
4689 * \brief The code-completion results.
4690 */
4691 CXCompletionResult *Results;
4692
4693 /**
4694 * \brief The number of code-completion results stored in the
4695 * \c Results array.
4696 */
4697 unsigned NumResults;
4698} CXCodeCompleteResults;
4699
4700/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00004701 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4702 * modify its behavior.
4703 *
4704 * The enumerators in this enumeration can be bitwise-OR'd together to
4705 * provide multiple options to \c clang_codeCompleteAt().
4706 */
4707enum CXCodeComplete_Flags {
4708 /**
4709 * \brief Whether to include macros within the set of code
4710 * completions returned.
4711 */
4712 CXCodeComplete_IncludeMacros = 0x01,
4713
4714 /**
4715 * \brief Whether to include code patterns for language constructs
4716 * within the set of code completions, e.g., for loops.
4717 */
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00004718 CXCodeComplete_IncludeCodePatterns = 0x02,
4719
4720 /**
4721 * \brief Whether to include brief documentation within the set of code
4722 * completions returned.
4723 */
4724 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorcee235c2010-08-05 09:09:23 +00004725};
4726
4727/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004728 * \brief Bits that represent the context under which completion is occurring.
4729 *
4730 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4731 * contexts are occurring simultaneously.
4732 */
4733enum CXCompletionContext {
4734 /**
4735 * \brief The context for completions is unexposed, as only Clang results
4736 * should be included. (This is equivalent to having no context bits set.)
4737 */
4738 CXCompletionContext_Unexposed = 0,
4739
4740 /**
4741 * \brief Completions for any possible type should be included in the results.
4742 */
4743 CXCompletionContext_AnyType = 1 << 0,
4744
4745 /**
4746 * \brief Completions for any possible value (variables, function calls, etc.)
4747 * should be included in the results.
4748 */
4749 CXCompletionContext_AnyValue = 1 << 1,
4750 /**
4751 * \brief Completions for values that resolve to an Objective-C object should
4752 * be included in the results.
4753 */
4754 CXCompletionContext_ObjCObjectValue = 1 << 2,
4755 /**
4756 * \brief Completions for values that resolve to an Objective-C selector
4757 * should be included in the results.
4758 */
4759 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4760 /**
4761 * \brief Completions for values that resolve to a C++ class type should be
4762 * included in the results.
4763 */
4764 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4765
4766 /**
4767 * \brief Completions for fields of the member being accessed using the dot
4768 * operator should be included in the results.
4769 */
4770 CXCompletionContext_DotMemberAccess = 1 << 5,
4771 /**
4772 * \brief Completions for fields of the member being accessed using the arrow
4773 * operator should be included in the results.
4774 */
4775 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4776 /**
4777 * \brief Completions for properties of the Objective-C object being accessed
4778 * using the dot operator should be included in the results.
4779 */
4780 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4781
4782 /**
4783 * \brief Completions for enum tags should be included in the results.
4784 */
4785 CXCompletionContext_EnumTag = 1 << 8,
4786 /**
4787 * \brief Completions for union tags should be included in the results.
4788 */
4789 CXCompletionContext_UnionTag = 1 << 9,
4790 /**
4791 * \brief Completions for struct tags should be included in the results.
4792 */
4793 CXCompletionContext_StructTag = 1 << 10,
4794
4795 /**
4796 * \brief Completions for C++ class names should be included in the results.
4797 */
4798 CXCompletionContext_ClassTag = 1 << 11,
4799 /**
4800 * \brief Completions for C++ namespaces and namespace aliases should be
4801 * included in the results.
4802 */
4803 CXCompletionContext_Namespace = 1 << 12,
4804 /**
4805 * \brief Completions for C++ nested name specifiers should be included in
4806 * the results.
4807 */
4808 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4809
4810 /**
4811 * \brief Completions for Objective-C interfaces (classes) should be included
4812 * in the results.
4813 */
4814 CXCompletionContext_ObjCInterface = 1 << 14,
4815 /**
4816 * \brief Completions for Objective-C protocols should be included in
4817 * the results.
4818 */
4819 CXCompletionContext_ObjCProtocol = 1 << 15,
4820 /**
4821 * \brief Completions for Objective-C categories should be included in
4822 * the results.
4823 */
4824 CXCompletionContext_ObjCCategory = 1 << 16,
4825 /**
4826 * \brief Completions for Objective-C instance messages should be included
4827 * in the results.
4828 */
4829 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4830 /**
4831 * \brief Completions for Objective-C class messages should be included in
4832 * the results.
4833 */
4834 CXCompletionContext_ObjCClassMessage = 1 << 18,
4835 /**
4836 * \brief Completions for Objective-C selector names should be included in
4837 * the results.
4838 */
4839 CXCompletionContext_ObjCSelectorName = 1 << 19,
4840
4841 /**
4842 * \brief Completions for preprocessor macro names should be included in
4843 * the results.
4844 */
4845 CXCompletionContext_MacroName = 1 << 20,
4846
4847 /**
4848 * \brief Natural language completions should be included in the results.
4849 */
4850 CXCompletionContext_NaturalLanguage = 1 << 21,
4851
4852 /**
4853 * \brief The current context is unknown, so set all contexts.
4854 */
4855 CXCompletionContext_Unknown = ((1 << 22) - 1)
4856};
4857
4858/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00004859 * \brief Returns a default set of code-completion options that can be
4860 * passed to\c clang_codeCompleteAt().
4861 */
4862CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4863
4864/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004865 * \brief Perform code completion at a given location in a translation unit.
4866 *
4867 * This function performs code completion at a particular file, line, and
4868 * column within source code, providing results that suggest potential
4869 * code snippets based on the context of the completion. The basic model
4870 * for code completion is that Clang will parse a complete source file,
4871 * performing syntax checking up to the location where code-completion has
4872 * been requested. At that point, a special code-completion token is passed
4873 * to the parser, which recognizes this token and determines, based on the
4874 * current location in the C/Objective-C/C++ grammar and the state of
4875 * semantic analysis, what completions to provide. These completions are
4876 * returned via a new \c CXCodeCompleteResults structure.
4877 *
4878 * Code completion itself is meant to be triggered by the client when the
4879 * user types punctuation characters or whitespace, at which point the
4880 * code-completion location will coincide with the cursor. For example, if \c p
4881 * is a pointer, code-completion might be triggered after the "-" and then
4882 * after the ">" in \c p->. When the code-completion location is afer the ">",
4883 * the completion results will provide, e.g., the members of the struct that
4884 * "p" points to. The client is responsible for placing the cursor at the
4885 * beginning of the token currently being typed, then filtering the results
4886 * based on the contents of the token. For example, when code-completing for
4887 * the expression \c p->get, the client should provide the location just after
4888 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4889 * client can filter the results based on the current token text ("get"), only
4890 * showing those results that start with "get". The intent of this interface
4891 * is to separate the relatively high-latency acquisition of code-completion
4892 * results from the filtering of results on a per-character basis, which must
4893 * have a lower latency.
4894 *
4895 * \param TU The translation unit in which code-completion should
4896 * occur. The source files for this translation unit need not be
4897 * completely up-to-date (and the contents of those source files may
4898 * be overridden via \p unsaved_files). Cursors referring into the
4899 * translation unit may be invalidated by this invocation.
4900 *
4901 * \param complete_filename The name of the source file where code
4902 * completion should be performed. This filename may be any file
4903 * included in the translation unit.
4904 *
4905 * \param complete_line The line at which code-completion should occur.
4906 *
4907 * \param complete_column The column at which code-completion should occur.
4908 * Note that the column should point just after the syntactic construct that
4909 * initiated code completion, and not in the middle of a lexical token.
4910 *
4911 * \param unsaved_files the Tiles that have not yet been saved to disk
4912 * but may be required for parsing or code completion, including the
4913 * contents of those files. The contents and name of these files (as
4914 * specified by CXUnsavedFile) are copied when necessary, so the
4915 * client only needs to guarantee their validity until the call to
4916 * this function returns.
4917 *
4918 * \param num_unsaved_files The number of unsaved file entries in \p
4919 * unsaved_files.
4920 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00004921 * \param options Extra options that control the behavior of code
4922 * completion, expressed as a bitwise OR of the enumerators of the
4923 * CXCodeComplete_Flags enumeration. The
4924 * \c clang_defaultCodeCompleteOptions() function returns a default set
4925 * of code-completion options.
4926 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004927 * \returns If successful, a new \c CXCodeCompleteResults structure
4928 * containing code-completion results, which should eventually be
4929 * freed with \c clang_disposeCodeCompleteResults(). If code
4930 * completion fails, returns NULL.
4931 */
4932CINDEX_LINKAGE
4933CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4934 const char *complete_filename,
4935 unsigned complete_line,
4936 unsigned complete_column,
4937 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00004938 unsigned num_unsaved_files,
4939 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004940
4941/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00004942 * \brief Sort the code-completion results in case-insensitive alphabetical
4943 * order.
4944 *
4945 * \param Results The set of results to sort.
4946 * \param NumResults The number of results in \p Results.
4947 */
4948CINDEX_LINKAGE
4949void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4950 unsigned NumResults);
4951
4952/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004953 * \brief Free the given set of code-completion results.
4954 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004955CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00004956void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00004957
Douglas Gregor20d416c2010-01-20 01:10:47 +00004958/**
Douglas Gregora88084b2010-02-18 18:08:43 +00004959 * \brief Determine the number of diagnostics produced prior to the
4960 * location where code completion was performed.
4961 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004962CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004963unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4964
4965/**
4966 * \brief Retrieve a diagnostic associated with the given code completion.
4967 *
James Dennett7eee0182012-06-15 05:41:51 +00004968 * \param Results the code completion results to query.
Douglas Gregora88084b2010-02-18 18:08:43 +00004969 * \param Index the zero-based diagnostic number to retrieve.
4970 *
4971 * \returns the requested diagnostic. This diagnostic must be freed
4972 * via a call to \c clang_disposeDiagnostic().
4973 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004974CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004975CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4976 unsigned Index);
4977
4978/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004979 * \brief Determines what compeltions are appropriate for the context
4980 * the given code completion.
4981 *
4982 * \param Results the code completion results to query
4983 *
4984 * \returns the kinds of completions that are appropriate for use
4985 * along with the given code completion results.
4986 */
4987CINDEX_LINKAGE
4988unsigned long long clang_codeCompleteGetContexts(
4989 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00004990
4991/**
4992 * \brief Returns the cursor kind for the container for the current code
4993 * completion context. The container is only guaranteed to be set for
4994 * contexts where a container exists (i.e. member accesses or Objective-C
4995 * message sends); if there is not a container, this function will return
4996 * CXCursor_InvalidCode.
4997 *
4998 * \param Results the code completion results to query
4999 *
5000 * \param IsIncomplete on return, this value will be false if Clang has complete
5001 * information about the container. If Clang does not have complete
5002 * information, this value will be true.
5003 *
5004 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5005 * container
5006 */
5007CINDEX_LINKAGE
5008enum CXCursorKind clang_codeCompleteGetContainerKind(
5009 CXCodeCompleteResults *Results,
5010 unsigned *IsIncomplete);
5011
5012/**
5013 * \brief Returns the USR for the container for the current code completion
5014 * context. If there is not a container for the current context, this
5015 * function will return the empty string.
5016 *
5017 * \param Results the code completion results to query
5018 *
5019 * \returns the USR for the container
5020 */
5021CINDEX_LINKAGE
5022CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00005023
Douglas Gregor0a47d692011-07-26 15:24:30 +00005024
5025/**
5026 * \brief Returns the currently-entered selector for an Objective-C message
5027 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5028 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5029 * CXCompletionContext_ObjCClassMessage.
5030 *
5031 * \param Results the code completion results to query
5032 *
5033 * \returns the selector (or partial selector) that has been entered thus far
5034 * for an Objective-C message send.
5035 */
5036CINDEX_LINKAGE
5037CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5038
Douglas Gregor3da626b2011-07-07 16:03:39 +00005039/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00005040 * @}
5041 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005042
5043
Ted Kremenek04bb7162010-01-22 22:44:15 +00005044/**
5045 * \defgroup CINDEX_MISC Miscellaneous utility functions
5046 *
5047 * @{
5048 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00005049
5050/**
5051 * \brief Return a version string, suitable for showing to a user, but not
5052 * intended to be parsed (the format is not guaranteed to be stable).
5053 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +00005054CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenek04bb7162010-01-22 22:44:15 +00005055
Ted Kremenekd2427dd2011-03-18 23:05:39 +00005056
5057/**
5058 * \brief Enable/disable crash recovery.
5059 *
James Dennett7eee0182012-06-15 05:41:51 +00005060 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5061 * value enables crash recovery, while 0 disables it.
Ted Kremenekd2427dd2011-03-18 23:05:39 +00005062 */
5063CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5064
Ted Kremenek16b55a72010-01-26 19:31:51 +00005065 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00005066 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00005067 * (used with clang_getInclusions()).
5068 *
5069 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett7eee0182012-06-15 05:41:51 +00005070 * file included (either at the top-level or by \#include directives) within
Ted Kremenek16b55a72010-01-26 19:31:51 +00005071 * a translation unit. The first argument is the file being included, and
5072 * the second and third arguments provide the inclusion stack. The
5073 * array is sorted in order of immediate inclusion. For example,
5074 * the first element refers to the location that included 'included_file'.
5075 */
5076typedef void (*CXInclusionVisitor)(CXFile included_file,
5077 CXSourceLocation* inclusion_stack,
5078 unsigned include_len,
5079 CXClientData client_data);
5080
5081/**
5082 * \brief Visit the set of preprocessor inclusions in a translation unit.
5083 * The visitor function is called with the provided data for every included
5084 * file. This does not include headers included by the PCH file (unless one
5085 * is inspecting the inclusions in the PCH file itself).
5086 */
5087CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5088 CXInclusionVisitor visitor,
5089 CXClientData client_data);
5090
5091/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00005092 * @}
5093 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005094
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00005095/** \defgroup CINDEX_REMAPPING Remapping functions
5096 *
5097 * @{
5098 */
5099
5100/**
5101 * \brief A remapping of original source files and their translated files.
5102 */
5103typedef void *CXRemapping;
5104
5105/**
5106 * \brief Retrieve a remapping.
5107 *
5108 * \param path the path that contains metadata about remappings.
5109 *
5110 * \returns the requested remapping. This remapping must be freed
5111 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5112 */
5113CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5114
5115/**
Ted Kremenek30660a82012-03-06 20:06:33 +00005116 * \brief Retrieve a remapping.
5117 *
5118 * \param filePaths pointer to an array of file paths containing remapping info.
5119 *
5120 * \param numFiles number of file paths.
5121 *
5122 * \returns the requested remapping. This remapping must be freed
5123 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5124 */
5125CINDEX_LINKAGE
5126CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5127 unsigned numFiles);
5128
5129/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00005130 * \brief Determine the number of remappings.
5131 */
5132CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5133
5134/**
5135 * \brief Get the original and the associated filename from the remapping.
5136 *
5137 * \param original If non-NULL, will be set to the original filename.
5138 *
5139 * \param transformed If non-NULL, will be set to the filename that the original
5140 * is associated with.
5141 */
5142CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5143 CXString *original, CXString *transformed);
5144
5145/**
5146 * \brief Dispose the remapping.
5147 */
5148CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5149
5150/**
5151 * @}
5152 */
5153
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005154/** \defgroup CINDEX_HIGH Higher level API functions
5155 *
5156 * @{
5157 */
5158
5159enum CXVisitorResult {
5160 CXVisit_Break,
5161 CXVisit_Continue
5162};
5163
5164typedef struct {
5165 void *context;
5166 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5167} CXCursorAndRangeVisitor;
5168
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005169typedef enum {
5170 /**
5171 * \brief Function returned successfully.
5172 */
5173 CXResult_Success = 0,
5174 /**
5175 * \brief One of the parameters was invalid for the function.
5176 */
5177 CXResult_Invalid = 1,
5178 /**
5179 * \brief The function was terminated by a callback (e.g. it returned
5180 * CXVisit_Break)
5181 */
5182 CXResult_VisitBreak = 2
5183
5184} CXResult;
5185
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005186/**
5187 * \brief Find references of a declaration in a specific file.
5188 *
5189 * \param cursor pointing to a declaration or a reference of one.
5190 *
5191 * \param file to search for references.
5192 *
5193 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5194 * each reference found.
5195 * The CXSourceRange will point inside the file; if the reference is inside
5196 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis389dc562013-03-08 20:42:33 +00005197 *
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005198 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005199 */
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005200CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5201 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005202
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005203/**
5204 * \brief Find #import/#include directives in a specific file.
5205 *
5206 * \param TU translation unit containing the file to query.
5207 *
5208 * \param file to search for #import/#include directives.
5209 *
5210 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5211 * each directive found.
Argyrios Kyrtzidis389dc562013-03-08 20:42:33 +00005212 *
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005213 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005214 */
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005215CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5216 CXFile file,
5217 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005218
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005219#ifdef __has_feature
5220# if __has_feature(blocks)
5221
5222typedef enum CXVisitorResult
5223 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5224
5225CINDEX_LINKAGE
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005226CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5227 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005228
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005229CINDEX_LINKAGE
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005230CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5231 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005232
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005233# endif
5234#endif
5235
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005236/**
5237 * \brief The client's data object that is associated with a CXFile.
5238 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005239typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005240
5241/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005242 * \brief The client's data object that is associated with a semantic entity.
5243 */
5244typedef void *CXIdxClientEntity;
5245
5246/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005247 * \brief The client's data object that is associated with a semantic container
5248 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005249 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005250typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005251
5252/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005253 * \brief The client's data object that is associated with an AST file (PCH
5254 * or module).
5255 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005256typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005257
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005258/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005259 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005260 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005261typedef struct {
5262 void *ptr_data[2];
5263 unsigned int_data;
5264} CXIdxLoc;
5265
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005266/**
James Dennett7eee0182012-06-15 05:41:51 +00005267 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005268 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005269typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005270 /**
James Dennett7eee0182012-06-15 05:41:51 +00005271 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005272 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005273 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005274 /**
James Dennett7eee0182012-06-15 05:41:51 +00005275 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005276 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005277 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005278 /**
James Dennett7eee0182012-06-15 05:41:51 +00005279 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005280 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005281 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005282 int isImport;
5283 int isAngled;
Argyrios Kyrtzidis8d7a24e2012-10-18 00:17:05 +00005284 /**
5285 * \brief Non-zero if the directive was automatically turned into a module
5286 * import.
5287 */
5288 int isModuleImport;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005289} CXIdxIncludedFileInfo;
5290
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005291/**
James Dennett7eee0182012-06-15 05:41:51 +00005292 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005293 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005294typedef struct {
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005295 /**
5296 * \brief Top level AST file containing the imported PCH, module or submodule.
5297 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005298 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005299 /**
Argyrios Kyrtzidis134d1e8a2012-10-05 00:22:40 +00005300 * \brief The imported module or NULL if the AST file is a PCH.
5301 */
5302 CXModule module;
5303 /**
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005304 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005305 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005306 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005307 /**
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005308 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidis134d1e8a2012-10-05 00:22:40 +00005309 * a module import. Applicable only for modules.
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005310 */
Argyrios Kyrtzidis37f2f522012-10-03 21:05:44 +00005311 int isImplicit;
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005312
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005313} CXIdxImportedASTFileInfo;
5314
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005315typedef enum {
5316 CXIdxEntity_Unexposed = 0,
5317 CXIdxEntity_Typedef = 1,
5318 CXIdxEntity_Function = 2,
5319 CXIdxEntity_Variable = 3,
5320 CXIdxEntity_Field = 4,
5321 CXIdxEntity_EnumConstant = 5,
5322
5323 CXIdxEntity_ObjCClass = 6,
5324 CXIdxEntity_ObjCProtocol = 7,
5325 CXIdxEntity_ObjCCategory = 8,
5326
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005327 CXIdxEntity_ObjCInstanceMethod = 9,
5328 CXIdxEntity_ObjCClassMethod = 10,
5329 CXIdxEntity_ObjCProperty = 11,
5330 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005331
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005332 CXIdxEntity_Enum = 13,
5333 CXIdxEntity_Struct = 14,
5334 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005335
5336 CXIdxEntity_CXXClass = 16,
5337 CXIdxEntity_CXXNamespace = 17,
5338 CXIdxEntity_CXXNamespaceAlias = 18,
5339 CXIdxEntity_CXXStaticVariable = 19,
5340 CXIdxEntity_CXXStaticMethod = 20,
5341 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matos17d35c32012-08-31 22:18:20 +00005342 CXIdxEntity_CXXConstructor = 22,
5343 CXIdxEntity_CXXDestructor = 23,
5344 CXIdxEntity_CXXConversionFunction = 24,
5345 CXIdxEntity_CXXTypeAlias = 25,
5346 CXIdxEntity_CXXInterface = 26
5347
5348} CXIdxEntityKind;
5349
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00005350typedef enum {
5351 CXIdxEntityLang_None = 0,
5352 CXIdxEntityLang_C = 1,
5353 CXIdxEntityLang_ObjC = 2,
5354 CXIdxEntityLang_CXX = 3
5355} CXIdxEntityLanguage;
5356
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005357/**
5358 * \brief Extra C++ template information for an entity. This can apply to:
5359 * CXIdxEntity_Function
5360 * CXIdxEntity_CXXClass
5361 * CXIdxEntity_CXXStaticMethod
5362 * CXIdxEntity_CXXInstanceMethod
5363 * CXIdxEntity_CXXConstructor
5364 * CXIdxEntity_CXXConversionFunction
5365 * CXIdxEntity_CXXTypeAlias
5366 */
5367typedef enum {
5368 CXIdxEntity_NonTemplate = 0,
5369 CXIdxEntity_Template = 1,
5370 CXIdxEntity_TemplatePartialSpecialization = 2,
5371 CXIdxEntity_TemplateSpecialization = 3
5372} CXIdxEntityCXXTemplateKind;
5373
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005374typedef enum {
5375 CXIdxAttr_Unexposed = 0,
5376 CXIdxAttr_IBAction = 1,
5377 CXIdxAttr_IBOutlet = 2,
5378 CXIdxAttr_IBOutletCollection = 3
5379} CXIdxAttrKind;
5380
5381typedef struct {
5382 CXIdxAttrKind kind;
5383 CXCursor cursor;
5384 CXIdxLoc loc;
5385} CXIdxAttrInfo;
5386
5387typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00005388 CXIdxEntityKind kind;
5389 CXIdxEntityCXXTemplateKind templateKind;
5390 CXIdxEntityLanguage lang;
5391 const char *name;
5392 const char *USR;
5393 CXCursor cursor;
5394 const CXIdxAttrInfo *const *attributes;
5395 unsigned numAttributes;
5396} CXIdxEntityInfo;
5397
5398typedef struct {
5399 CXCursor cursor;
5400} CXIdxContainerInfo;
5401
5402typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005403 const CXIdxAttrInfo *attrInfo;
5404 const CXIdxEntityInfo *objcClass;
5405 CXCursor classCursor;
5406 CXIdxLoc classLoc;
5407} CXIdxIBOutletCollectionAttrInfo;
5408
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005409typedef enum {
5410 CXIdxDeclFlag_Skipped = 0x1
5411} CXIdxDeclInfoFlags;
5412
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005413typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005414 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005415 CXCursor cursor;
5416 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005417 const CXIdxContainerInfo *semanticContainer;
5418 /**
James Dennett7eee0182012-06-15 05:41:51 +00005419 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005420 * cases like out-of-line C++ member functions.
5421 */
5422 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005423 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005424 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005425 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005426 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005427 /**
5428 * \brief Whether the declaration exists in code or was created implicitly
5429 * by the compiler, e.g. implicit objc methods for properties.
5430 */
5431 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005432 const CXIdxAttrInfo *const *attributes;
5433 unsigned numAttributes;
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005434
5435 unsigned flags;
5436
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005437} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005438
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005439typedef enum {
5440 CXIdxObjCContainer_ForwardRef = 0,
5441 CXIdxObjCContainer_Interface = 1,
5442 CXIdxObjCContainer_Implementation = 2
5443} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005444
5445typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005446 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005447 CXIdxObjCContainerKind kind;
5448} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005449
5450typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005451 const CXIdxEntityInfo *base;
5452 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005453 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005454} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005455
5456typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005457 const CXIdxEntityInfo *protocol;
5458 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005459 CXIdxLoc loc;
5460} CXIdxObjCProtocolRefInfo;
5461
5462typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005463 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005464 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005465} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005466
5467typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005468 const CXIdxObjCContainerDeclInfo *containerInfo;
5469 const CXIdxBaseClassInfo *superInfo;
5470 const CXIdxObjCProtocolRefListInfo *protocols;
5471} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005472
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005473typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00005474 const CXIdxObjCContainerDeclInfo *containerInfo;
5475 const CXIdxEntityInfo *objcClass;
5476 CXCursor classCursor;
5477 CXIdxLoc classLoc;
5478 const CXIdxObjCProtocolRefListInfo *protocols;
5479} CXIdxObjCCategoryDeclInfo;
5480
5481typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005482 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00005483 const CXIdxEntityInfo *getter;
5484 const CXIdxEntityInfo *setter;
5485} CXIdxObjCPropertyDeclInfo;
5486
5487typedef struct {
5488 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005489 const CXIdxBaseClassInfo *const *bases;
5490 unsigned numBases;
5491} CXIdxCXXClassDeclInfo;
5492
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005493/**
James Dennett7eee0182012-06-15 05:41:51 +00005494 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005495 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005496typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005497 /**
5498 * \brief The entity is referenced directly in user's code.
5499 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005500 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005501 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005502 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5503 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005504 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005505 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005506} CXIdxEntityRefKind;
5507
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005508/**
James Dennett7eee0182012-06-15 05:41:51 +00005509 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005510 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005511typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005512 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005513 /**
5514 * \brief Reference cursor.
5515 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005516 CXCursor cursor;
5517 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005518 /**
5519 * \brief The entity that gets referenced.
5520 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005521 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005522 /**
5523 * \brief Immediate "parent" of the reference. For example:
5524 *
5525 * \code
5526 * Foo *var;
5527 * \endcode
5528 *
5529 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00005530 * For references inside statement bodies of functions/methods,
5531 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005532 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005533 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005534 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00005535 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005536 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005537 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005538} CXIdxEntityRefInfo;
5539
James Dennett7eee0182012-06-15 05:41:51 +00005540/**
5541 * \brief A group of callbacks used by #clang_indexSourceFile and
5542 * #clang_indexTranslationUnit.
5543 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005544typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005545 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005546 * \brief Called periodically to check whether indexing should be aborted.
5547 * Should return 0 to continue, and non-zero to abort.
5548 */
5549 int (*abortQuery)(CXClientData client_data, void *reserved);
5550
5551 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005552 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005553 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005554 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005555 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005556
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005557 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett7eee0182012-06-15 05:41:51 +00005558 CXFile mainFile, void *reserved);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005559
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005560 /**
James Dennett7eee0182012-06-15 05:41:51 +00005561 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005562 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005563 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005564 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005565
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005566 /**
5567 * \brief Called when a AST file (PCH or module) gets imported.
5568 *
5569 * AST files will not get indexed (there will not be callbacks to index all
5570 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005571 * file is not already indexed, to initiate a new indexing job specific to
5572 * the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005573 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005574 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005575 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005576
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005577 /**
5578 * \brief Called at the beginning of indexing a translation unit.
5579 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005580 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005581 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005582
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005583 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005584 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005585
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005586 /**
5587 * \brief Called to index a reference of an entity.
5588 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005589 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005590 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005591
5592} IndexerCallbacks;
5593
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00005594CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005595CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5596clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005597
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005598CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5599clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5600
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00005601CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005602const CXIdxObjCCategoryDeclInfo *
5603clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5604
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005605CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5606clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005607
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00005608CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5609clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5610
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005611CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5612clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5613
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005614CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5615clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5616
5617/**
5618 * \brief For retrieving a custom CXIdxClientContainer attached to a
5619 * container.
5620 */
5621CINDEX_LINKAGE CXIdxClientContainer
5622clang_index_getClientContainer(const CXIdxContainerInfo *);
5623
5624/**
5625 * \brief For setting a custom CXIdxClientContainer attached to a
5626 * container.
5627 */
5628CINDEX_LINKAGE void
5629clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5630
5631/**
5632 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5633 */
5634CINDEX_LINKAGE CXIdxClientEntity
5635clang_index_getClientEntity(const CXIdxEntityInfo *);
5636
5637/**
5638 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5639 */
5640CINDEX_LINKAGE void
5641clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5642
5643/**
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005644 * \brief An indexing action/session, to be applied to one or multiple
5645 * translation units.
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005646 */
5647typedef void *CXIndexAction;
5648
5649/**
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005650 * \brief An indexing action/session, to be applied to one or multiple
5651 * translation units.
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005652 *
5653 * \param CIdx The index object with which the index action will be associated.
5654 */
5655CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5656
5657/**
5658 * \brief Destroy the given index action.
5659 *
5660 * The index action must not be destroyed until all of the translation units
5661 * created within that index action have been destroyed.
5662 */
5663CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5664
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005665typedef enum {
5666 /**
5667 * \brief Used to indicate that no special indexing options are needed.
5668 */
5669 CXIndexOpt_None = 0x0,
5670
5671 /**
James Dennett7eee0182012-06-15 05:41:51 +00005672 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5673 * be invoked for only one reference of an entity per source file that does
5674 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005675 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00005676 CXIndexOpt_SuppressRedundantRefs = 0x1,
5677
5678 /**
5679 * \brief Function-local symbols should be indexed. If this is not set
5680 * function-local symbols will be ignored.
5681 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00005682 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5683
5684 /**
5685 * \brief Implicit function/class template instantiations should be indexed.
5686 * If this is not set, implicit instantiations will be ignored.
5687 */
Argyrios Kyrtzidisb49a29f2012-03-27 21:38:03 +00005688 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5689
5690 /**
5691 * \brief Suppress all compiler warnings when parsing for indexing.
5692 */
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005693 CXIndexOpt_SuppressWarnings = 0x8,
5694
5695 /**
5696 * \brief Skip a function/method body that was already parsed during an
5697 * indexing session assosiated with a \c CXIndexAction object.
5698 * Bodies in system headers are always skipped.
5699 */
5700 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5701
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005702} CXIndexOptFlags;
5703
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005704/**
5705 * \brief Index the given source file and the translation unit corresponding
James Dennett7eee0182012-06-15 05:41:51 +00005706 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005707 *
5708 * \param client_data pointer data supplied by the client, which will
5709 * be passed to the invoked callbacks.
5710 *
5711 * \param index_callbacks Pointer to indexing callbacks that the client
5712 * implements.
5713 *
James Dennett7eee0182012-06-15 05:41:51 +00005714 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005715 * passed in index_callbacks.
5716 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005717 * \param index_options A bitmask of options that affects how indexing is
5718 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005719 *
5720 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
5721 * after indexing is finished. Set to NULL if you do not require it.
5722 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005723 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005724 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005725 *
James Dennett7eee0182012-06-15 05:41:51 +00005726 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005727 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005728CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005729 CXClientData client_data,
5730 IndexerCallbacks *index_callbacks,
5731 unsigned index_callbacks_size,
5732 unsigned index_options,
5733 const char *source_filename,
5734 const char * const *command_line_args,
5735 int num_command_line_args,
5736 struct CXUnsavedFile *unsaved_files,
5737 unsigned num_unsaved_files,
5738 CXTranslationUnit *out_TU,
5739 unsigned TU_options);
5740
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005741/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005742 * \brief Index the given translation unit via callbacks implemented through
James Dennett7eee0182012-06-15 05:41:51 +00005743 * #IndexerCallbacks.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005744 *
5745 * The order of callback invocations is not guaranteed to be the same as
5746 * when indexing a source file. The high level order will be:
5747 *
5748 * -Preprocessor callbacks invocations
5749 * -Declaration/reference callbacks invocations
5750 * -Diagnostic callback invocations
5751 *
James Dennett7eee0182012-06-15 05:41:51 +00005752 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005753 *
5754 * \returns If there is a failure from which the there is no recovery, returns
5755 * non-zero, otherwise returns 0.
5756 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005757CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005758 CXClientData client_data,
5759 IndexerCallbacks *index_callbacks,
5760 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005761 unsigned index_options,
5762 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005763
5764/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005765 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5766 * the given CXIdxLoc.
5767 *
5768 * If the location refers into a macro expansion, retrieves the
5769 * location of the macro expansion and if it refers into a macro argument
5770 * retrieves the location of the argument.
5771 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005772CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005773 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005774 CXFile *file,
5775 unsigned *line,
5776 unsigned *column,
5777 unsigned *offset);
5778
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005779/**
5780 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5781 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005782CINDEX_LINKAGE
5783CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5784
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005785/**
5786 * @}
5787 */
5788
Douglas Gregorc42fefa2010-01-22 22:29:16 +00005789/**
5790 * @}
5791 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005792
Ted Kremenekd2fa5662009-08-26 22:36:44 +00005793#ifdef __cplusplus
5794}
5795#endif
5796#endif
5797