blob: 51b1a8c2eef84b2079fa9522e64c65b7da1cb56e [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
Stefanus Du Toitad0d5702013-08-08 17:48:14 +000035#define CINDEX_VERSION_MINOR 20
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/**
Stefanus Du Toitad0d5702013-08-08 17:48:14 +0000417 * \brief Returns non-zero if the given source location is in the main file of
418 * the corresponding translation unit.
419 */
420CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
421
422/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000423 * \brief Retrieve a NULL (invalid) source range.
424 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +0000425CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000426
Douglas Gregor5352ac02010-01-28 00:27:43 +0000427/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000428 * \brief Retrieve a source range given the beginning and ending source
429 * locations.
430 */
431CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
432 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000433
Douglas Gregorb9790342010-01-22 21:44:22 +0000434/**
Douglas Gregorab4e83b2011-07-23 19:35:14 +0000435 * \brief Determine whether two ranges are equivalent.
436 *
437 * \returns non-zero if the ranges are the same, zero if they differ.
438 */
439CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
440 CXSourceRange range2);
441
442/**
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000443 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000444 */
Erik Verbruggen733dbc82011-10-06 12:11:57 +0000445CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000446
447/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000448 * \brief Retrieve the file, line, column, and offset represented by
449 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000450 *
Chandler Carruth20174222011-08-31 16:53:37 +0000451 * If the location refers into a macro expansion, retrieves the
452 * location of the macro expansion.
Douglas Gregora9b06d42010-11-09 06:24:54 +0000453 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000454 * \param location the location within a source file that will be decomposed
455 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000456 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000457 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000458 * source location points.
459 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000460 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000461 * source location points.
462 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000463 * \param column [out] if non-NULL, will be set to the column to which the given
464 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000465 *
466 * \param offset [out] if non-NULL, will be set to the offset into the
467 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000468 */
Chandler Carruth20174222011-08-31 16:53:37 +0000469CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
470 CXFile *file,
471 unsigned *line,
472 unsigned *column,
473 unsigned *offset);
474
475/**
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000476 * \brief Retrieve the file, line, column, and offset represented by
477 * the given source location, as specified in a # line directive.
478 *
479 * Example: given the following source code in a file somefile.c
480 *
James Dennett7eee0182012-06-15 05:41:51 +0000481 * \code
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000482 * #123 "dummy.c" 1
483 *
484 * static int func(void)
485 * {
486 * return 0;
487 * }
James Dennett7eee0182012-06-15 05:41:51 +0000488 * \endcode
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000489 *
490 * the location information returned by this function would be
491 *
492 * File: dummy.c Line: 124 Column: 12
493 *
494 * whereas clang_getExpansionLocation would have returned
495 *
496 * File: somefile.c Line: 3 Column: 12
497 *
498 * \param location the location within a source file that will be decomposed
499 * into its parts.
500 *
501 * \param filename [out] if non-NULL, will be set to the filename of the
502 * source location. Note that filenames returned will be for "virtual" files,
503 * which don't necessarily exist on the machine running clang - e.g. when
504 * parsing preprocessed output obtained from a different environment. If
505 * a non-NULL value is passed in, remember to dispose of the returned value
506 * using \c clang_disposeString() once you've finished with it. For an invalid
507 * source location, an empty string is returned.
508 *
509 * \param line [out] if non-NULL, will be set to the line number of the
510 * source location. For an invalid source location, zero is returned.
511 *
512 * \param column [out] if non-NULL, will be set to the column number of the
513 * source location. For an invalid source location, zero is returned.
514 */
515CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
516 CXString *filename,
517 unsigned *line,
518 unsigned *column);
519
520/**
Chandler Carruth20174222011-08-31 16:53:37 +0000521 * \brief Legacy API to retrieve the file, line, column, and offset represented
522 * by the given source location.
523 *
524 * This interface has been replaced by the newer interface
James Dennett7eee0182012-06-15 05:41:51 +0000525 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth20174222011-08-31 16:53:37 +0000526 * details.
527 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000528CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
529 CXFile *file,
530 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000531 unsigned *column,
532 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000533
534/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000535 * \brief Retrieve the file, line, column, and offset represented by
536 * the given source location.
537 *
538 * If the location refers into a macro instantiation, return where the
539 * location was originally spelled in the source file.
540 *
541 * \param location the location within a source file that will be decomposed
542 * into its parts.
543 *
544 * \param file [out] if non-NULL, will be set to the file to which the given
545 * source location points.
546 *
547 * \param line [out] if non-NULL, will be set to the line to which the given
548 * source location points.
549 *
550 * \param column [out] if non-NULL, will be set to the column to which the given
551 * source location points.
552 *
553 * \param offset [out] if non-NULL, will be set to the offset into the
554 * buffer to which the given source location points.
555 */
556CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
557 CXFile *file,
558 unsigned *line,
559 unsigned *column,
560 unsigned *offset);
561
562/**
Argyrios Kyrtzidis2d5c1332013-01-04 18:30:13 +0000563 * \brief Retrieve the file, line, column, and offset represented by
564 * the given source location.
565 *
566 * If the location refers into a macro expansion, return where the macro was
567 * expanded or where the macro argument was written, if the location points at
568 * a macro argument.
569 *
570 * \param location the location within a source file that will be decomposed
571 * into its parts.
572 *
573 * \param file [out] if non-NULL, will be set to the file to which the given
574 * source location points.
575 *
576 * \param line [out] if non-NULL, will be set to the line to which the given
577 * source location points.
578 *
579 * \param column [out] if non-NULL, will be set to the column to which the given
580 * source location points.
581 *
582 * \param offset [out] if non-NULL, will be set to the offset into the
583 * buffer to which the given source location points.
584 */
585CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
586 CXFile *file,
587 unsigned *line,
588 unsigned *column,
589 unsigned *offset);
590
591/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000592 * \brief Retrieve a source location representing the first character within a
593 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000594 */
595CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
596
597/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000598 * \brief Retrieve a source location representing the last character within a
599 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000600 */
601CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
602
Douglas Gregorf5525442010-01-20 22:45:41 +0000603/**
604 * @}
605 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000606
607/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000608 * \defgroup CINDEX_DIAG Diagnostic reporting
609 *
610 * @{
611 */
612
613/**
614 * \brief Describes the severity of a particular diagnostic.
615 */
616enum CXDiagnosticSeverity {
617 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000618 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000619 * option.
620 */
621 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000622
Douglas Gregor5352ac02010-01-28 00:27:43 +0000623 /**
624 * \brief This diagnostic is a note that should be attached to the
625 * previous (non-note) diagnostic.
626 */
627 CXDiagnostic_Note = 1,
628
629 /**
630 * \brief This diagnostic indicates suspicious code that may not be
631 * wrong.
632 */
633 CXDiagnostic_Warning = 2,
634
635 /**
636 * \brief This diagnostic indicates that the code is ill-formed.
637 */
638 CXDiagnostic_Error = 3,
639
640 /**
641 * \brief This diagnostic indicates that the code is ill-formed such
642 * that future parser recovery is unlikely to produce useful
643 * results.
644 */
645 CXDiagnostic_Fatal = 4
646};
647
648/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000649 * \brief A single diagnostic, containing the diagnostic's severity,
650 * location, text, source ranges, and fix-it hints.
651 */
652typedef void *CXDiagnostic;
653
654/**
Ted Kremenek15322172011-11-10 08:43:12 +0000655 * \brief A group of CXDiagnostics.
656 */
657typedef void *CXDiagnosticSet;
658
659/**
660 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
661 */
662CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
663
664/**
665 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
666 *
James Dennett7eee0182012-06-15 05:41:51 +0000667 * \param Diags the CXDiagnosticSet to query.
Ted Kremenek15322172011-11-10 08:43:12 +0000668 * \param Index the zero-based diagnostic number to retrieve.
669 *
670 * \returns the requested diagnostic. This diagnostic must be freed
671 * via a call to \c clang_disposeDiagnostic().
672 */
673CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
674 unsigned Index);
675
676
677/**
678 * \brief Describes the kind of error that occurred (if any) in a call to
679 * \c clang_loadDiagnostics.
680 */
681enum CXLoadDiag_Error {
682 /**
683 * \brief Indicates that no error occurred.
684 */
685 CXLoadDiag_None = 0,
686
687 /**
688 * \brief Indicates that an unknown error occurred while attempting to
689 * deserialize diagnostics.
690 */
691 CXLoadDiag_Unknown = 1,
692
693 /**
694 * \brief Indicates that the file containing the serialized diagnostics
695 * could not be opened.
696 */
697 CXLoadDiag_CannotLoad = 2,
698
699 /**
700 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett7eee0182012-06-15 05:41:51 +0000701 * corrupt.
Ted Kremenek15322172011-11-10 08:43:12 +0000702 */
703 CXLoadDiag_InvalidFile = 3
704};
705
706/**
707 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett7eee0182012-06-15 05:41:51 +0000708 * file.
Ted Kremenek15322172011-11-10 08:43:12 +0000709 *
James Dennett7eee0182012-06-15 05:41:51 +0000710 * \param file The name of the file to deserialize.
711 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenek15322172011-11-10 08:43:12 +0000712 * deserializing the diagnostics.
James Dennett7eee0182012-06-15 05:41:51 +0000713 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenek15322172011-11-10 08:43:12 +0000714 * if the file was not successfully loaded.
715 *
716 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett7eee0182012-06-15 05:41:51 +0000717 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenek15322172011-11-10 08:43:12 +0000718 */
719CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
720 enum CXLoadDiag_Error *error,
721 CXString *errorString);
722
723/**
724 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
725 */
726CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
727
728/**
James Dennett7eee0182012-06-15 05:41:51 +0000729 * \brief Retrieve the child diagnostics of a CXDiagnostic.
730 *
731 * This CXDiagnosticSet does not need to be released by
732 * clang_diposeDiagnosticSet.
Ted Kremenek15322172011-11-10 08:43:12 +0000733 */
734CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
735
736/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000737 * \brief Determine the number of diagnostics produced for the given
738 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000739 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000740CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
741
742/**
743 * \brief Retrieve a diagnostic associated with the given translation unit.
744 *
745 * \param Unit the translation unit to query.
746 * \param Index the zero-based diagnostic number to retrieve.
747 *
748 * \returns the requested diagnostic. This diagnostic must be freed
749 * via a call to \c clang_disposeDiagnostic().
750 */
751CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
752 unsigned Index);
753
754/**
Ted Kremenek0373fcc2011-12-09 22:28:32 +0000755 * \brief Retrieve the complete set of diagnostics associated with a
756 * translation unit.
757 *
758 * \param Unit the translation unit to query.
759 */
760CINDEX_LINKAGE CXDiagnosticSet
761 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
762
763/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000764 * \brief Destroy a diagnostic.
765 */
766CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000767
768/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000769 * \brief Options to control the display of diagnostics.
770 *
771 * The values in this enum are meant to be combined to customize the
772 * behavior of \c clang_displayDiagnostic().
773 */
774enum CXDiagnosticDisplayOptions {
775 /**
776 * \brief Display the source-location information where the
777 * diagnostic was located.
778 *
779 * When set, diagnostics will be prefixed by the file, line, and
780 * (optionally) column to which the diagnostic refers. For example,
781 *
782 * \code
783 * test.c:28: warning: extra tokens at end of #endif directive
784 * \endcode
785 *
786 * This option corresponds to the clang flag \c -fshow-source-location.
787 */
788 CXDiagnostic_DisplaySourceLocation = 0x01,
789
790 /**
791 * \brief If displaying the source-location information of the
792 * diagnostic, also include the column number.
793 *
794 * This option corresponds to the clang flag \c -fshow-column.
795 */
796 CXDiagnostic_DisplayColumn = 0x02,
797
798 /**
799 * \brief If displaying the source-location information of the
800 * diagnostic, also include information about source ranges in a
801 * machine-parsable format.
802 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000803 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000804 * \c -fdiagnostics-print-source-range-info.
805 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000806 CXDiagnostic_DisplaySourceRanges = 0x04,
807
808 /**
809 * \brief Display the option name associated with this diagnostic, if any.
810 *
811 * The option name displayed (e.g., -Wconversion) will be placed in brackets
812 * after the diagnostic text. This option corresponds to the clang flag
813 * \c -fdiagnostics-show-option.
814 */
815 CXDiagnostic_DisplayOption = 0x08,
816
817 /**
818 * \brief Display the category number associated with this diagnostic, if any.
819 *
820 * The category number is displayed within brackets after the diagnostic text.
821 * This option corresponds to the clang flag
822 * \c -fdiagnostics-show-category=id.
823 */
824 CXDiagnostic_DisplayCategoryId = 0x10,
825
826 /**
827 * \brief Display the category name associated with this diagnostic, if any.
828 *
829 * The category name is displayed within brackets after the diagnostic text.
830 * This option corresponds to the clang flag
831 * \c -fdiagnostics-show-category=name.
832 */
833 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000834};
835
836/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000837 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000838 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000839 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000840 * the diagnostic according to the various options given. The
841 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000842 * options that most closely mimics the behavior of the clang compiler.
843 *
844 * \param Diagnostic The diagnostic to print.
845 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000846 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000847 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000848 *
849 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000850 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000851CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
852 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000853
854/**
855 * \brief Retrieve the set of display options most similar to the
856 * default behavior of the clang compiler.
857 *
858 * \returns A set of display options suitable for use with \c
859 * clang_displayDiagnostic().
860 */
861CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
862
863/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000864 * \brief Determine the severity of the given diagnostic.
865 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000866CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000867clang_getDiagnosticSeverity(CXDiagnostic);
868
869/**
870 * \brief Retrieve the source location of the given diagnostic.
871 *
872 * This location is where Clang would print the caret ('^') when
873 * displaying the diagnostic on the command line.
874 */
875CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
876
877/**
878 * \brief Retrieve the text of the given diagnostic.
879 */
880CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000881
882/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000883 * \brief Retrieve the name of the command-line option that enabled this
884 * diagnostic.
885 *
886 * \param Diag The diagnostic to be queried.
887 *
888 * \param Disable If non-NULL, will be set to the option that disables this
889 * diagnostic (if any).
890 *
891 * \returns A string that contains the command-line option used to enable this
892 * warning, such as "-Wconversion" or "-pedantic".
893 */
894CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
895 CXString *Disable);
896
897/**
898 * \brief Retrieve the category number for this diagnostic.
899 *
900 * Diagnostics can be categorized into groups along with other, related
901 * diagnostics (e.g., diagnostics under the same warning flag). This routine
902 * retrieves the category number for the given diagnostic.
903 *
904 * \returns The number of the category that contains this diagnostic, or zero
905 * if this diagnostic is uncategorized.
906 */
907CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
908
909/**
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000910 * \brief Retrieve the name of a particular diagnostic category. This
911 * is now deprecated. Use clang_getDiagnosticCategoryText()
912 * instead.
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000913 *
914 * \param Category A diagnostic category number, as returned by
915 * \c clang_getDiagnosticCategory().
916 *
917 * \returns The name of the given diagnostic category.
918 */
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000919CINDEX_DEPRECATED CINDEX_LINKAGE
920CXString clang_getDiagnosticCategoryName(unsigned Category);
921
922/**
923 * \brief Retrieve the diagnostic category text for a given diagnostic.
924 *
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000925 * \returns The text of the given diagnostic category.
926 */
927CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000928
929/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000930 * \brief Determine the number of source ranges associated with the given
931 * diagnostic.
932 */
933CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000934
Douglas Gregor5352ac02010-01-28 00:27:43 +0000935/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000936 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000937 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000938 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000939 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000940 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000941 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000942 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000943 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000944 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000945 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000946 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000947 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000948CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000949 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000950
951/**
952 * \brief Determine the number of fix-it hints associated with the
953 * given diagnostic.
954 */
955CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
956
957/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000958 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000959 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000960 * Fix-its are described in terms of a source range whose contents
961 * should be replaced by a string. This approach generalizes over
962 * three kinds of operations: removal of source code (the range covers
963 * the code to be removed and the replacement string is empty),
964 * replacement of source code (the range covers the code to be
965 * replaced and the replacement string provides the new code), and
966 * insertion (both the start and end of the range point at the
967 * insertion location, and the replacement string provides the text to
968 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000969 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000970 * \param Diagnostic The diagnostic whose fix-its are being queried.
971 *
972 * \param FixIt The zero-based index of the fix-it.
973 *
974 * \param ReplacementRange The source range whose contents will be
975 * replaced with the returned replacement string. Note that source
976 * ranges are half-open ranges [a, b), so the source code should be
977 * replaced from a and up to (but not including) b.
978 *
979 * \returns A string containing text that should be replace the source
980 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000981 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000982CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000983 unsigned FixIt,
984 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000985
986/**
987 * @}
988 */
989
990/**
991 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
992 *
993 * The routines in this group provide the ability to create and destroy
994 * translation units from files, either by parsing the contents of the files or
995 * by reading in a serialized representation of a translation unit.
996 *
997 * @{
998 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000999
Douglas Gregor5352ac02010-01-28 00:27:43 +00001000/**
1001 * \brief Get the original translation unit source file name.
1002 */
1003CINDEX_LINKAGE CXString
1004clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1005
1006/**
1007 * \brief Return the CXTranslationUnit for a given source file and the provided
1008 * command line arguments one would pass to the compiler.
1009 *
1010 * Note: The 'source_filename' argument is optional. If the caller provides a
1011 * NULL pointer, the name of the source file is expected to reside in the
1012 * specified command line arguments.
1013 *
1014 * Note: When encountered in 'clang_command_line_args', the following options
1015 * are ignored:
1016 *
1017 * '-c'
1018 * '-emit-ast'
1019 * '-fsyntax-only'
James Dennett7eee0182012-06-15 05:41:51 +00001020 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor5352ac02010-01-28 00:27:43 +00001021 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001022 * \param CIdx The index object with which the translation unit will be
1023 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001024 *
James Dennett7eee0182012-06-15 05:41:51 +00001025 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001026 * source file is included in \p clang_command_line_args.
1027 *
1028 * \param num_clang_command_line_args The number of command-line arguments in
1029 * \p clang_command_line_args.
1030 *
1031 * \param clang_command_line_args The command-line arguments that would be
1032 * passed to the \c clang executable if it were being invoked out-of-process.
1033 * These command-line options will be parsed and will affect how the translation
1034 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett7eee0182012-06-15 05:41:51 +00001035 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001036 *
1037 * \param num_unsaved_files the number of unsaved file entries in \p
1038 * unsaved_files.
1039 *
1040 * \param unsaved_files the files that have not yet been saved to disk
1041 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +00001042 * those files. The contents and name of these files (as specified by
1043 * CXUnsavedFile) are copied when necessary, so the client only needs to
1044 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001045 */
1046CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1047 CXIndex CIdx,
1048 const char *source_filename,
1049 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001050 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +00001051 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +00001052 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001053
Douglas Gregor5352ac02010-01-28 00:27:43 +00001054/**
1055 * \brief Create a translation unit from an AST file (-emit-ast).
1056 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001057CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +00001058 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +00001059
Douglas Gregor44c181a2010-07-23 00:33:23 +00001060/**
1061 * \brief Flags that control the creation of translation units.
1062 *
1063 * The enumerators in this enumeration type are meant to be bitwise
1064 * ORed together to specify which options should be used when
1065 * constructing the translation unit.
1066 */
Douglas Gregor5a430212010-07-21 18:52:53 +00001067enum CXTranslationUnit_Flags {
1068 /**
1069 * \brief Used to indicate that no special translation-unit options are
1070 * needed.
1071 */
1072 CXTranslationUnit_None = 0x0,
1073
1074 /**
1075 * \brief Used to indicate that the parser should construct a "detailed"
1076 * preprocessing record, including all macro definitions and instantiations.
1077 *
1078 * Constructing a detailed preprocessing record requires more memory
1079 * and time to parse, since the information contained in the record
1080 * is usually not retained. However, it can be useful for
1081 * applications that require more detailed information about the
1082 * behavior of the preprocessor.
1083 */
Douglas Gregor44c181a2010-07-23 00:33:23 +00001084 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1085
1086 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001087 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001088 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001089 * When a translation unit is considered "incomplete", semantic
1090 * analysis that is typically performed at the end of the
1091 * translation unit will be suppressed. For example, this suppresses
1092 * the completion of tentative declarations in C and of
1093 * instantiation of implicitly-instantiation function templates in
1094 * C++. This option is typically used when parsing a header with the
1095 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001096 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001097 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +00001098
1099 /**
1100 * \brief Used to indicate that the translation unit should be built with an
1101 * implicit precompiled header for the preamble.
1102 *
1103 * An implicit precompiled header is used as an optimization when a
1104 * particular translation unit is likely to be reparsed many times
1105 * when the sources aren't changing that often. In this case, an
1106 * implicit precompiled header will be built containing all of the
1107 * initial includes at the top of the main file (what we refer to as
1108 * the "preamble" of the file). In subsequent parses, if the
1109 * preamble or the files in it have not changed, \c
1110 * clang_reparseTranslationUnit() will re-use the implicit
1111 * precompiled header to improve parsing performance.
1112 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001113 CXTranslationUnit_PrecompiledPreamble = 0x04,
1114
1115 /**
1116 * \brief Used to indicate that the translation unit should cache some
1117 * code-completion results with each reparse of the source file.
1118 *
1119 * Caching of code-completion results is a performance optimization that
1120 * introduces some overhead to reparsing but improves the performance of
1121 * code-completion operations.
1122 */
Douglas Gregor99ba2022010-10-27 17:24:53 +00001123 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001124
Douglas Gregor99ba2022010-10-27 17:24:53 +00001125 /**
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001126 * \brief Used to indicate that the translation unit will be serialized with
1127 * \c clang_saveTranslationUnit.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001128 *
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001129 * This option is typically used when parsing a header with the intent of
1130 * producing a precompiled header.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001131 */
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001132 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregor99ba2022010-10-27 17:24:53 +00001133
1134 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001135 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001136 *
1137 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001138 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001139 */
Erik Verbruggen6a91d382012-04-12 10:11:59 +00001140 CXTranslationUnit_CXXChainedPCH = 0x20,
1141
1142 /**
1143 * \brief Used to indicate that function/method bodies should be skipped while
1144 * parsing.
1145 *
1146 * This option can be used to search for declarations/definitions while
1147 * ignoring the usages.
1148 */
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001149 CXTranslationUnit_SkipFunctionBodies = 0x40,
1150
1151 /**
1152 * \brief Used to indicate that brief documentation comments should be
1153 * included into the set of code completions returned from this translation
1154 * unit.
1155 */
1156 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor5a430212010-07-21 18:52:53 +00001157};
1158
1159/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001160 * \brief Returns the set of flags that is suitable for parsing a translation
1161 * unit that is being edited.
1162 *
1163 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1164 * to indicate that the translation unit is likely to be reparsed many times,
1165 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1166 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1167 * set contains an unspecified set of optimizations (e.g., the precompiled
1168 * preamble) geared toward improving the performance of these routines. The
1169 * set of optimizations enabled may change from one version to the next.
1170 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001171CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001172
1173/**
Douglas Gregor5a430212010-07-21 18:52:53 +00001174 * \brief Parse the given source file and the translation unit corresponding
1175 * to that file.
1176 *
1177 * This routine is the main entry point for the Clang C API, providing the
1178 * ability to parse a source file into a translation unit that can then be
1179 * queried by other functions in the API. This routine accepts a set of
1180 * command-line arguments so that the compilation can be configured in the same
1181 * way that the compiler is configured on the command line.
1182 *
1183 * \param CIdx The index object with which the translation unit will be
1184 * associated.
1185 *
1186 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001187 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +00001188 *
1189 * \param command_line_args The command-line arguments that would be
1190 * passed to the \c clang executable if it were being invoked out-of-process.
1191 * These command-line options will be parsed and will affect how the translation
1192 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett7eee0182012-06-15 05:41:51 +00001193 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor5a430212010-07-21 18:52:53 +00001194 *
1195 * \param num_command_line_args The number of command-line arguments in
1196 * \p command_line_args.
1197 *
1198 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00001199 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +00001200 * those files. The contents and name of these files (as specified by
1201 * CXUnsavedFile) are copied when necessary, so the client only needs to
1202 * guarantee their validity until the call to this function returns.
1203 *
1204 * \param num_unsaved_files the number of unsaved file entries in \p
1205 * unsaved_files.
1206 *
1207 * \param options A bitmask of options that affects how the translation unit
1208 * is managed but not its compilation. This should be a bitwise OR of the
1209 * CXTranslationUnit_XXX flags.
1210 *
1211 * \returns A new translation unit describing the parsed code and containing
1212 * any diagnostics produced by the compiler. If there is a failure from which
1213 * the compiler cannot recover, returns NULL.
1214 */
1215CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1216 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001217 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +00001218 int num_command_line_args,
1219 struct CXUnsavedFile *unsaved_files,
1220 unsigned num_unsaved_files,
1221 unsigned options);
1222
Douglas Gregor5352ac02010-01-28 00:27:43 +00001223/**
Douglas Gregor19998442010-08-13 15:35:05 +00001224 * \brief Flags that control how translation units are saved.
1225 *
1226 * The enumerators in this enumeration type are meant to be bitwise
1227 * ORed together to specify which options should be used when
1228 * saving the translation unit.
1229 */
1230enum CXSaveTranslationUnit_Flags {
1231 /**
1232 * \brief Used to indicate that no special saving options are needed.
1233 */
1234 CXSaveTranslationUnit_None = 0x0
1235};
1236
1237/**
1238 * \brief Returns the set of flags that is suitable for saving a translation
1239 * unit.
1240 *
1241 * The set of flags returned provide options for
1242 * \c clang_saveTranslationUnit() by default. The returned flag
1243 * set contains an unspecified set of options that save translation units with
1244 * the most commonly-requested data.
1245 */
1246CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1247
1248/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001249 * \brief Describes the kind of error that occurred (if any) in a call to
1250 * \c clang_saveTranslationUnit().
1251 */
1252enum CXSaveError {
1253 /**
1254 * \brief Indicates that no error occurred while saving a translation unit.
1255 */
1256 CXSaveError_None = 0,
1257
1258 /**
1259 * \brief Indicates that an unknown error occurred while attempting to save
1260 * the file.
1261 *
1262 * This error typically indicates that file I/O failed when attempting to
1263 * write the file.
1264 */
1265 CXSaveError_Unknown = 1,
1266
1267 /**
1268 * \brief Indicates that errors during translation prevented this attempt
1269 * to save the translation unit.
1270 *
1271 * Errors that prevent the translation unit from being saved can be
1272 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1273 */
1274 CXSaveError_TranslationErrors = 2,
1275
1276 /**
1277 * \brief Indicates that the translation unit to be saved was somehow
1278 * invalid (e.g., NULL).
1279 */
1280 CXSaveError_InvalidTU = 3
1281};
1282
1283/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001284 * \brief Saves a translation unit into a serialized representation of
1285 * that translation unit on disk.
1286 *
1287 * Any translation unit that was parsed without error can be saved
1288 * into a file. The translation unit can then be deserialized into a
1289 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1290 * if it is an incomplete translation unit that corresponds to a
1291 * header, used as a precompiled header when parsing other translation
1292 * units.
1293 *
1294 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001295 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001296 * \param FileName The file to which the translation unit will be saved.
1297 *
Douglas Gregor19998442010-08-13 15:35:05 +00001298 * \param options A bitmask of options that affects how the translation unit
1299 * is saved. This should be a bitwise OR of the
1300 * CXSaveTranslationUnit_XXX flags.
1301 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001302 * \returns A value that will match one of the enumerators of the CXSaveError
1303 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1304 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001305 */
1306CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001307 const char *FileName,
1308 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001309
1310/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001311 * \brief Destroy the specified CXTranslationUnit object.
1312 */
1313CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001314
Douglas Gregor5352ac02010-01-28 00:27:43 +00001315/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001316 * \brief Flags that control the reparsing of translation units.
1317 *
1318 * The enumerators in this enumeration type are meant to be bitwise
1319 * ORed together to specify which options should be used when
1320 * reparsing the translation unit.
1321 */
1322enum CXReparse_Flags {
1323 /**
1324 * \brief Used to indicate that no special reparsing options are needed.
1325 */
1326 CXReparse_None = 0x0
1327};
1328
1329/**
1330 * \brief Returns the set of flags that is suitable for reparsing a translation
1331 * unit.
1332 *
1333 * The set of flags returned provide options for
1334 * \c clang_reparseTranslationUnit() by default. The returned flag
1335 * set contains an unspecified set of optimizations geared toward common uses
1336 * of reparsing. The set of optimizations enabled may change from one version
1337 * to the next.
1338 */
1339CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1340
1341/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001342 * \brief Reparse the source files that produced this translation unit.
1343 *
1344 * This routine can be used to re-parse the source files that originally
1345 * created the given translation unit, for example because those source files
1346 * have changed (either on disk or as passed via \p unsaved_files). The
1347 * source code will be reparsed with the same command-line options as it
1348 * was originally parsed.
1349 *
1350 * Reparsing a translation unit invalidates all cursors and source locations
1351 * that refer into that translation unit. This makes reparsing a translation
1352 * unit semantically equivalent to destroying the translation unit and then
1353 * creating a new translation unit with the same command-line arguments.
1354 * However, it may be more efficient to reparse a translation
1355 * unit using this routine.
1356 *
1357 * \param TU The translation unit whose contents will be re-parsed. The
1358 * translation unit must originally have been built with
1359 * \c clang_createTranslationUnitFromSourceFile().
1360 *
1361 * \param num_unsaved_files The number of unsaved file entries in \p
1362 * unsaved_files.
1363 *
1364 * \param unsaved_files The files that have not yet been saved to disk
1365 * but may be required for parsing, including the contents of
1366 * those files. The contents and name of these files (as specified by
1367 * CXUnsavedFile) are copied when necessary, so the client only needs to
1368 * guarantee their validity until the call to this function returns.
1369 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001370 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1371 * The function \c clang_defaultReparseOptions() produces a default set of
1372 * options recommended for most uses, based on the translation unit.
1373 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001374 * \returns 0 if the sources could be reparsed. A non-zero value will be
1375 * returned if reparsing was impossible, such that the translation unit is
1376 * invalid. In such cases, the only valid call for \p TU is
1377 * \c clang_disposeTranslationUnit(TU).
1378 */
1379CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1380 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001381 struct CXUnsavedFile *unsaved_files,
1382 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001383
1384/**
1385 * \brief Categorizes how memory is being used by a translation unit.
1386 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001387enum CXTUResourceUsageKind {
1388 CXTUResourceUsage_AST = 1,
1389 CXTUResourceUsage_Identifiers = 2,
1390 CXTUResourceUsage_Selectors = 3,
1391 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001392 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001393 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001394 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001395 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1396 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1397 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001398 CXTUResourceUsage_Preprocessor = 11,
1399 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001400 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001401 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001402 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1403 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001404 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001405
1406 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001407 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001408};
1409
1410/**
1411 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001412 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001413 */
1414CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001415const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001416
Ted Kremenekf7870022011-04-20 16:41:07 +00001417typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001418 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001419 enum CXTUResourceUsageKind kind;
1420 /* \brief Amount of resources used.
1421 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001422 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001423} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001424
1425/**
1426 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1427 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001428typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001429 /* \brief Private data member, used for queries. */
1430 void *data;
1431
1432 /* \brief The number of entries in the 'entries' array. */
1433 unsigned numEntries;
1434
1435 /* \brief An array of key-value pairs, representing the breakdown of memory
1436 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001437 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001438
Ted Kremenekf7870022011-04-20 16:41:07 +00001439} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001440
1441/**
1442 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001443 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001444 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001445CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001446
Ted Kremenekf7870022011-04-20 16:41:07 +00001447CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001448
Douglas Gregorabc563f2010-07-19 21:46:24 +00001449/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001450 * @}
1451 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001452
Douglas Gregor5352ac02010-01-28 00:27:43 +00001453/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001454 * \brief Describes the kind of entity that a cursor refers to.
1455 */
1456enum CXCursorKind {
1457 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001458 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001459 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001460 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001461 *
1462 * Unexposed declarations have the same operations as any other kind
1463 * of declaration; one can extract their location information,
1464 * spelling, find their definitions, etc. However, the specific kind
1465 * of the declaration is not reported.
1466 */
1467 CXCursor_UnexposedDecl = 1,
1468 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001469 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001470 /** \brief A C or C++ union. */
1471 CXCursor_UnionDecl = 3,
1472 /** \brief A C++ class. */
1473 CXCursor_ClassDecl = 4,
1474 /** \brief An enumeration. */
1475 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001476 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001477 * \brief A field (in C) or non-static data member (in C++) in a
1478 * struct, union, or C++ class.
1479 */
1480 CXCursor_FieldDecl = 6,
1481 /** \brief An enumerator constant. */
1482 CXCursor_EnumConstantDecl = 7,
1483 /** \brief A function. */
1484 CXCursor_FunctionDecl = 8,
1485 /** \brief A variable. */
1486 CXCursor_VarDecl = 9,
1487 /** \brief A function or method parameter. */
1488 CXCursor_ParmDecl = 10,
James Dennett17d26a62012-06-11 06:19:40 +00001489 /** \brief An Objective-C \@interface. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001490 CXCursor_ObjCInterfaceDecl = 11,
James Dennett17d26a62012-06-11 06:19:40 +00001491 /** \brief An Objective-C \@interface for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001492 CXCursor_ObjCCategoryDecl = 12,
James Dennett17d26a62012-06-11 06:19:40 +00001493 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001494 CXCursor_ObjCProtocolDecl = 13,
James Dennett17d26a62012-06-11 06:19:40 +00001495 /** \brief An Objective-C \@property declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001496 CXCursor_ObjCPropertyDecl = 14,
1497 /** \brief An Objective-C instance variable. */
1498 CXCursor_ObjCIvarDecl = 15,
1499 /** \brief An Objective-C instance method. */
1500 CXCursor_ObjCInstanceMethodDecl = 16,
1501 /** \brief An Objective-C class method. */
1502 CXCursor_ObjCClassMethodDecl = 17,
James Dennett17d26a62012-06-11 06:19:40 +00001503 /** \brief An Objective-C \@implementation. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001504 CXCursor_ObjCImplementationDecl = 18,
James Dennett17d26a62012-06-11 06:19:40 +00001505 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001506 CXCursor_ObjCCategoryImplDecl = 19,
1507 /** \brief A typedef */
1508 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001509 /** \brief A C++ class method. */
1510 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001511 /** \brief A C++ namespace. */
1512 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001513 /** \brief A linkage specification, e.g. 'extern "C"'. */
1514 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001515 /** \brief A C++ constructor. */
1516 CXCursor_Constructor = 24,
1517 /** \brief A C++ destructor. */
1518 CXCursor_Destructor = 25,
1519 /** \brief A C++ conversion function. */
1520 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001521 /** \brief A C++ template type parameter. */
1522 CXCursor_TemplateTypeParameter = 27,
1523 /** \brief A C++ non-type template parameter. */
1524 CXCursor_NonTypeTemplateParameter = 28,
1525 /** \brief A C++ template template parameter. */
1526 CXCursor_TemplateTemplateParameter = 29,
1527 /** \brief A C++ function template. */
1528 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001529 /** \brief A C++ class template. */
1530 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001531 /** \brief A C++ class template partial specialization. */
1532 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001533 /** \brief A C++ namespace alias declaration. */
1534 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001535 /** \brief A C++ using directive. */
1536 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001537 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001538 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001539 /** \brief A C++ alias declaration */
1540 CXCursor_TypeAliasDecl = 36,
James Dennett7eee0182012-06-15 05:41:51 +00001541 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor352697a2011-06-03 23:08:58 +00001542 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett7eee0182012-06-15 05:41:51 +00001543 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor352697a2011-06-03 23:08:58 +00001544 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001545 /** \brief An access specifier. */
1546 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor42b29842011-10-05 19:00:14 +00001547
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001548 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001549 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001550
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001551 /* References */
1552 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001553 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001554 CXCursor_ObjCProtocolRef = 41,
1555 CXCursor_ObjCClassRef = 42,
1556 /**
1557 * \brief A reference to a type declaration.
1558 *
1559 * A type reference occurs anywhere where a type is named but not
1560 * declared. For example, given:
1561 *
1562 * \code
1563 * typedef unsigned size_type;
1564 * size_type size;
1565 * \endcode
1566 *
1567 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1568 * while the type of the variable "size" is referenced. The cursor
1569 * referenced by the type of size is the typedef for size_type.
1570 */
1571 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001572 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001573 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001574 * \brief A reference to a class template, function template, template
1575 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001576 */
1577 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001578 /**
1579 * \brief A reference to a namespace or namespace alias.
1580 */
1581 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001582 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001583 * \brief A reference to a member of a struct, union, or class that occurs in
1584 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001585 */
1586 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001587 /**
1588 * \brief A reference to a labeled statement.
1589 *
1590 * This cursor kind is used to describe the jump to "start_over" in the
1591 * goto statement in the following example:
1592 *
1593 * \code
1594 * start_over:
1595 * ++counter;
1596 *
1597 * goto start_over;
1598 * \endcode
1599 *
1600 * A label reference cursor refers to a label statement.
1601 */
1602 CXCursor_LabelRef = 48,
1603
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001604 /**
1605 * \brief A reference to a set of overloaded functions or function templates
1606 * that has not yet been resolved to a specific function or function template.
1607 *
1608 * An overloaded declaration reference cursor occurs in C++ templates where
1609 * a dependent name refers to a function. For example:
1610 *
1611 * \code
1612 * template<typename T> void swap(T&, T&);
1613 *
1614 * struct X { ... };
1615 * void swap(X&, X&);
1616 *
1617 * template<typename T>
1618 * void reverse(T* first, T* last) {
1619 * while (first < last - 1) {
1620 * swap(*first, *--last);
1621 * ++first;
1622 * }
1623 * }
1624 *
1625 * struct Y { };
1626 * void swap(Y&, Y&);
1627 * \endcode
1628 *
1629 * Here, the identifier "swap" is associated with an overloaded declaration
1630 * reference. In the template definition, "swap" refers to either of the two
1631 * "swap" functions declared above, so both results will be available. At
1632 * instantiation time, "swap" may also refer to other functions found via
1633 * argument-dependent lookup (e.g., the "swap" function at the end of the
1634 * example).
1635 *
1636 * The functions \c clang_getNumOverloadedDecls() and
1637 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1638 * referenced by this cursor.
1639 */
1640 CXCursor_OverloadedDeclRef = 49,
1641
Douglas Gregor011d8b92012-02-15 00:54:55 +00001642 /**
1643 * \brief A reference to a variable that occurs in some non-expression
1644 * context, e.g., a C++ lambda capture list.
1645 */
1646 CXCursor_VariableRef = 50,
1647
1648 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001649
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001650 /* Error conditions */
1651 CXCursor_FirstInvalid = 70,
1652 CXCursor_InvalidFile = 70,
1653 CXCursor_NoDeclFound = 71,
1654 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001655 CXCursor_InvalidCode = 73,
1656 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001657
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001658 /* Expressions */
1659 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001660
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001661 /**
1662 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001663 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001664 *
1665 * Unexposed expressions have the same operations as any other kind
1666 * of expression; one can extract their location information,
1667 * spelling, children, etc. However, the specific kind of the
1668 * expression is not reported.
1669 */
1670 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001671
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001672 /**
1673 * \brief An expression that refers to some value declaration, such
1674 * as a function, varible, or enumerator.
1675 */
1676 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001677
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001678 /**
1679 * \brief An expression that refers to a member of a struct, union,
1680 * class, Objective-C class, etc.
1681 */
1682 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001683
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001684 /** \brief An expression that calls a function. */
1685 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001686
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001687 /** \brief An expression that sends a message to an Objective-C
1688 object or class. */
1689 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001690
1691 /** \brief An expression that represents a block literal. */
1692 CXCursor_BlockExpr = 105,
1693
Douglas Gregor42b29842011-10-05 19:00:14 +00001694 /** \brief An integer literal.
1695 */
1696 CXCursor_IntegerLiteral = 106,
1697
1698 /** \brief A floating point number literal.
1699 */
1700 CXCursor_FloatingLiteral = 107,
1701
1702 /** \brief An imaginary number literal.
1703 */
1704 CXCursor_ImaginaryLiteral = 108,
1705
1706 /** \brief A string literal.
1707 */
1708 CXCursor_StringLiteral = 109,
1709
1710 /** \brief A character literal.
1711 */
1712 CXCursor_CharacterLiteral = 110,
1713
1714 /** \brief A parenthesized expression, e.g. "(1)".
1715 *
1716 * This AST node is only formed if full location information is requested.
1717 */
1718 CXCursor_ParenExpr = 111,
1719
1720 /** \brief This represents the unary-expression's (except sizeof and
1721 * alignof).
1722 */
1723 CXCursor_UnaryOperator = 112,
1724
1725 /** \brief [C99 6.5.2.1] Array Subscripting.
1726 */
1727 CXCursor_ArraySubscriptExpr = 113,
1728
1729 /** \brief A builtin binary operation expression such as "x + y" or
1730 * "x <= y".
1731 */
1732 CXCursor_BinaryOperator = 114,
1733
1734 /** \brief Compound assignment such as "+=".
1735 */
1736 CXCursor_CompoundAssignOperator = 115,
1737
1738 /** \brief The ?: ternary operator.
1739 */
1740 CXCursor_ConditionalOperator = 116,
1741
1742 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1743 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1744 *
1745 * For example: (int)f.
1746 */
1747 CXCursor_CStyleCastExpr = 117,
1748
1749 /** \brief [C99 6.5.2.5]
1750 */
1751 CXCursor_CompoundLiteralExpr = 118,
1752
1753 /** \brief Describes an C or C++ initializer list.
1754 */
1755 CXCursor_InitListExpr = 119,
1756
1757 /** \brief The GNU address of label extension, representing &&label.
1758 */
1759 CXCursor_AddrLabelExpr = 120,
1760
1761 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1762 */
1763 CXCursor_StmtExpr = 121,
1764
Benjamin Kramerffbe9b92011-12-23 17:00:35 +00001765 /** \brief Represents a C11 generic selection.
Douglas Gregor42b29842011-10-05 19:00:14 +00001766 */
1767 CXCursor_GenericSelectionExpr = 122,
1768
1769 /** \brief Implements the GNU __null extension, which is a name for a null
1770 * pointer constant that has integral type (e.g., int or long) and is the same
1771 * size and alignment as a pointer.
1772 *
1773 * The __null extension is typically only used by system headers, which define
1774 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1775 * match the size of a pointer).
1776 */
1777 CXCursor_GNUNullExpr = 123,
1778
1779 /** \brief C++'s static_cast<> expression.
1780 */
1781 CXCursor_CXXStaticCastExpr = 124,
1782
1783 /** \brief C++'s dynamic_cast<> expression.
1784 */
1785 CXCursor_CXXDynamicCastExpr = 125,
1786
1787 /** \brief C++'s reinterpret_cast<> expression.
1788 */
1789 CXCursor_CXXReinterpretCastExpr = 126,
1790
1791 /** \brief C++'s const_cast<> expression.
1792 */
1793 CXCursor_CXXConstCastExpr = 127,
1794
1795 /** \brief Represents an explicit C++ type conversion that uses "functional"
1796 * notion (C++ [expr.type.conv]).
1797 *
1798 * Example:
1799 * \code
1800 * x = int(0.5);
1801 * \endcode
1802 */
1803 CXCursor_CXXFunctionalCastExpr = 128,
1804
1805 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1806 */
1807 CXCursor_CXXTypeidExpr = 129,
1808
1809 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1810 */
1811 CXCursor_CXXBoolLiteralExpr = 130,
1812
1813 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1814 */
1815 CXCursor_CXXNullPtrLiteralExpr = 131,
1816
1817 /** \brief Represents the "this" expression in C++
1818 */
1819 CXCursor_CXXThisExpr = 132,
1820
1821 /** \brief [C++ 15] C++ Throw Expression.
1822 *
1823 * This handles 'throw' and 'throw' assignment-expression. When
1824 * assignment-expression isn't present, Op will be null.
1825 */
1826 CXCursor_CXXThrowExpr = 133,
1827
1828 /** \brief A new expression for memory allocation and constructor calls, e.g:
1829 * "new CXXNewExpr(foo)".
1830 */
1831 CXCursor_CXXNewExpr = 134,
1832
1833 /** \brief A delete expression for memory deallocation and destructor calls,
1834 * e.g. "delete[] pArray".
1835 */
1836 CXCursor_CXXDeleteExpr = 135,
1837
1838 /** \brief A unary expression.
1839 */
1840 CXCursor_UnaryExpr = 136,
1841
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001842 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor42b29842011-10-05 19:00:14 +00001843 */
1844 CXCursor_ObjCStringLiteral = 137,
1845
James Dennett7eee0182012-06-15 05:41:51 +00001846 /** \brief An Objective-C \@encode expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001847 */
1848 CXCursor_ObjCEncodeExpr = 138,
1849
James Dennett7eee0182012-06-15 05:41:51 +00001850 /** \brief An Objective-C \@selector expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001851 */
1852 CXCursor_ObjCSelectorExpr = 139,
1853
James Dennett17d26a62012-06-11 06:19:40 +00001854 /** \brief An Objective-C \@protocol expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001855 */
1856 CXCursor_ObjCProtocolExpr = 140,
1857
1858 /** \brief An Objective-C "bridged" cast expression, which casts between
1859 * Objective-C pointers and C pointers, transferring ownership in the process.
1860 *
1861 * \code
1862 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1863 * \endcode
1864 */
1865 CXCursor_ObjCBridgedCastExpr = 141,
1866
1867 /** \brief Represents a C++0x pack expansion that produces a sequence of
1868 * expressions.
1869 *
1870 * A pack expansion expression contains a pattern (which itself is an
1871 * expression) followed by an ellipsis. For example:
1872 *
1873 * \code
1874 * template<typename F, typename ...Types>
1875 * void forward(F f, Types &&...args) {
1876 * f(static_cast<Types&&>(args)...);
1877 * }
1878 * \endcode
1879 */
1880 CXCursor_PackExpansionExpr = 142,
1881
1882 /** \brief Represents an expression that computes the length of a parameter
1883 * pack.
1884 *
1885 * \code
1886 * template<typename ...Types>
1887 * struct count {
1888 * static const unsigned value = sizeof...(Types);
1889 * };
1890 * \endcode
1891 */
1892 CXCursor_SizeOfPackExpr = 143,
1893
Douglas Gregor011d8b92012-02-15 00:54:55 +00001894 /* \brief Represents a C++ lambda expression that produces a local function
1895 * object.
1896 *
1897 * \code
1898 * void abssort(float *x, unsigned N) {
1899 * std::sort(x, x + N,
1900 * [](float a, float b) {
1901 * return std::abs(a) < std::abs(b);
1902 * });
1903 * }
1904 * \endcode
1905 */
1906 CXCursor_LambdaExpr = 144,
1907
Ted Kremenekb3f75422012-03-06 20:06:06 +00001908 /** \brief Objective-c Boolean Literal.
1909 */
1910 CXCursor_ObjCBoolLiteralExpr = 145,
1911
Argyrios Kyrtzidisedab0472013-04-23 17:57:17 +00001912 /** \brief Represents the "self" expression in a ObjC method.
1913 */
1914 CXCursor_ObjCSelfExpr = 146,
1915
1916 CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001917
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001918 /* Statements */
1919 CXCursor_FirstStmt = 200,
1920 /**
1921 * \brief A statement whose specific kind is not exposed via this
1922 * interface.
1923 *
1924 * Unexposed statements have the same operations as any other kind of
1925 * statement; one can extract their location information, spelling,
1926 * children, etc. However, the specific kind of the statement is not
1927 * reported.
1928 */
1929 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001930
1931 /** \brief A labelled statement in a function.
1932 *
1933 * This cursor kind is used to describe the "start_over:" label statement in
1934 * the following example:
1935 *
1936 * \code
1937 * start_over:
1938 * ++counter;
1939 * \endcode
1940 *
1941 */
1942 CXCursor_LabelStmt = 201,
Douglas Gregor42b29842011-10-05 19:00:14 +00001943
1944 /** \brief A group of statements like { stmt stmt }.
1945 *
1946 * This cursor kind is used to describe compound statements, e.g. function
1947 * bodies.
1948 */
1949 CXCursor_CompoundStmt = 202,
1950
1951 /** \brief A case statment.
1952 */
1953 CXCursor_CaseStmt = 203,
1954
1955 /** \brief A default statement.
1956 */
1957 CXCursor_DefaultStmt = 204,
1958
1959 /** \brief An if statement
1960 */
1961 CXCursor_IfStmt = 205,
1962
1963 /** \brief A switch statement.
1964 */
1965 CXCursor_SwitchStmt = 206,
1966
1967 /** \brief A while statement.
1968 */
1969 CXCursor_WhileStmt = 207,
1970
1971 /** \brief A do statement.
1972 */
1973 CXCursor_DoStmt = 208,
1974
1975 /** \brief A for statement.
1976 */
1977 CXCursor_ForStmt = 209,
1978
1979 /** \brief A goto statement.
1980 */
1981 CXCursor_GotoStmt = 210,
1982
1983 /** \brief An indirect goto statement.
1984 */
1985 CXCursor_IndirectGotoStmt = 211,
1986
1987 /** \brief A continue statement.
1988 */
1989 CXCursor_ContinueStmt = 212,
1990
1991 /** \brief A break statement.
1992 */
1993 CXCursor_BreakStmt = 213,
1994
1995 /** \brief A return statement.
1996 */
1997 CXCursor_ReturnStmt = 214,
1998
Chad Rosierdf5faf52012-08-25 00:11:56 +00001999 /** \brief A GCC inline assembly statement extension.
Douglas Gregor42b29842011-10-05 19:00:14 +00002000 */
Chad Rosierdf5faf52012-08-25 00:11:56 +00002001 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5e02f652012-09-24 19:27:20 +00002002 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor42b29842011-10-05 19:00:14 +00002003
James Dennett7eee0182012-06-15 05:41:51 +00002004 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002005 */
2006 CXCursor_ObjCAtTryStmt = 216,
2007
James Dennett7eee0182012-06-15 05:41:51 +00002008 /** \brief Objective-C's \@catch statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002009 */
2010 CXCursor_ObjCAtCatchStmt = 217,
2011
James Dennett7eee0182012-06-15 05:41:51 +00002012 /** \brief Objective-C's \@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002013 */
2014 CXCursor_ObjCAtFinallyStmt = 218,
2015
James Dennett7eee0182012-06-15 05:41:51 +00002016 /** \brief Objective-C's \@throw statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002017 */
2018 CXCursor_ObjCAtThrowStmt = 219,
2019
James Dennett7eee0182012-06-15 05:41:51 +00002020 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002021 */
2022 CXCursor_ObjCAtSynchronizedStmt = 220,
2023
2024 /** \brief Objective-C's autorelease pool statement.
2025 */
2026 CXCursor_ObjCAutoreleasePoolStmt = 221,
2027
2028 /** \brief Objective-C's collection statement.
2029 */
2030 CXCursor_ObjCForCollectionStmt = 222,
2031
2032 /** \brief C++'s catch statement.
2033 */
2034 CXCursor_CXXCatchStmt = 223,
2035
2036 /** \brief C++'s try statement.
2037 */
2038 CXCursor_CXXTryStmt = 224,
2039
2040 /** \brief C++'s for (* : *) statement.
2041 */
2042 CXCursor_CXXForRangeStmt = 225,
2043
2044 /** \brief Windows Structured Exception Handling's try statement.
2045 */
2046 CXCursor_SEHTryStmt = 226,
2047
2048 /** \brief Windows Structured Exception Handling's except statement.
2049 */
2050 CXCursor_SEHExceptStmt = 227,
2051
2052 /** \brief Windows Structured Exception Handling's finally statement.
2053 */
2054 CXCursor_SEHFinallyStmt = 228,
2055
Chad Rosier8cd64b42012-06-11 20:47:18 +00002056 /** \brief A MS inline assembly statement extension.
2057 */
2058 CXCursor_MSAsmStmt = 229,
2059
Douglas Gregor42b29842011-10-05 19:00:14 +00002060 /** \brief The null satement ";": C99 6.8.3p3.
2061 *
2062 * This cursor kind is used to describe the null statement.
2063 */
2064 CXCursor_NullStmt = 230,
2065
2066 /** \brief Adaptor class for mixing declarations with statements and
2067 * expressions.
2068 */
2069 CXCursor_DeclStmt = 231,
2070
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002071 /** \brief OpenMP parallel directive.
2072 */
2073 CXCursor_OMPParallelDirective = 232,
2074
2075 CXCursor_LastStmt = CXCursor_OMPParallelDirective,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002076
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002077 /**
2078 * \brief Cursor that represents the translation unit itself.
2079 *
2080 * The translation unit cursor exists primarily to act as the root
2081 * cursor for traversing the contents of a translation unit.
2082 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002083 CXCursor_TranslationUnit = 300,
2084
Bill Wendlingad017fa2012-12-20 19:22:21 +00002085 /* Attributes */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002086 CXCursor_FirstAttr = 400,
2087 /**
2088 * \brief An attribute whose specific kind is not exposed via this
2089 * interface.
2090 */
2091 CXCursor_UnexposedAttr = 400,
2092
2093 CXCursor_IBActionAttr = 401,
2094 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00002095 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00002096 CXCursor_CXXFinalAttr = 404,
2097 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002098 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002099 CXCursor_AsmLabelAttr = 407,
2100 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002101
2102 /* Preprocessing */
2103 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00002104 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00002105 CXCursor_MacroExpansion = 502,
2106 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002107 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002108 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis6a010122012-10-05 00:22:24 +00002109 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2110
2111 /* Extra Declarations */
2112 /**
2113 * \brief A module import declaration.
2114 */
2115 CXCursor_ModuleImportDecl = 600,
2116 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2117 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002118};
2119
2120/**
2121 * \brief A cursor representing some element in the abstract syntax tree for
2122 * a translation unit.
2123 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002124 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002125 * program--declaration, statements, expressions, references to declarations,
2126 * etc.--under a single "cursor" abstraction with a common set of operations.
2127 * Common operation for a cursor include: getting the physical location in
2128 * a source file where the cursor points, getting the name associated with a
2129 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2130 *
2131 * Cursors can be produced in two specific ways.
2132 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2133 * from which one can use clang_visitChildren() to explore the rest of the
2134 * translation unit. clang_getCursor() maps from a physical source location
2135 * to the entity that resides at that location, allowing one to map from the
2136 * source code into the AST.
2137 */
2138typedef struct {
2139 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00002140 int xdata;
Dmitri Gribenko67812b22013-01-11 21:01:49 +00002141 const void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002142} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002143
2144/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00002145 * \brief A comment AST node.
2146 */
2147typedef struct {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00002148 const void *ASTNode;
2149 CXTranslationUnit TranslationUnit;
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00002150} CXComment;
2151
2152/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002153 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2154 *
2155 * @{
2156 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002157
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002158/**
2159 * \brief Retrieve the NULL cursor, which represents no entity.
2160 */
2161CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002162
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002163/**
2164 * \brief Retrieve the cursor that represents the given translation unit.
2165 *
2166 * The translation unit cursor can be used to start traversing the
2167 * various declarations within the given translation unit.
2168 */
2169CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2170
2171/**
2172 * \brief Determine whether two cursors are equivalent.
2173 */
2174CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002175
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002176/**
Dmitri Gribenko1824d542012-09-13 13:11:20 +00002177 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002178 */
Dmitri Gribenko1824d542012-09-13 13:11:20 +00002179CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002180
2181/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00002182 * \brief Compute a hash value for the given cursor.
2183 */
2184CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2185
2186/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002187 * \brief Retrieve the kind of the given cursor.
2188 */
2189CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2190
2191/**
2192 * \brief Determine whether the given cursor kind represents a declaration.
2193 */
2194CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2195
2196/**
2197 * \brief Determine whether the given cursor kind represents a simple
2198 * reference.
2199 *
2200 * Note that other kinds of cursors (such as expressions) can also refer to
2201 * other cursors. Use clang_getCursorReferenced() to determine whether a
2202 * particular cursor refers to another entity.
2203 */
2204CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2205
2206/**
2207 * \brief Determine whether the given cursor kind represents an expression.
2208 */
2209CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2210
2211/**
2212 * \brief Determine whether the given cursor kind represents a statement.
2213 */
2214CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2215
2216/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002217 * \brief Determine whether the given cursor kind represents an attribute.
2218 */
2219CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2220
2221/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002222 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002223 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002224 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002225CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2226
2227/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002228 * \brief Determine whether the given cursor kind represents a translation
2229 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002230 */
2231CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002232
Ted Kremenekad6eff62010-03-08 21:17:29 +00002233/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002234 * \brief Determine whether the given cursor represents a preprocessing
2235 * element, such as a preprocessor directive or macro instantiation.
2236 */
2237CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2238
2239/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002240 * \brief Determine whether the given cursor represents a currently
2241 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2242 */
2243CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2244
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002245/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002246 * \brief Describe the linkage of the entity referred to by a cursor.
2247 */
2248enum CXLinkageKind {
2249 /** \brief This value indicates that no linkage information is available
2250 * for a provided CXCursor. */
2251 CXLinkage_Invalid,
2252 /**
2253 * \brief This is the linkage for variables, parameters, and so on that
2254 * have automatic storage. This covers normal (non-extern) local variables.
2255 */
2256 CXLinkage_NoLinkage,
2257 /** \brief This is the linkage for static variables and static functions. */
2258 CXLinkage_Internal,
2259 /** \brief This is the linkage for entities with external linkage that live
2260 * in C++ anonymous namespaces.*/
2261 CXLinkage_UniqueExternal,
2262 /** \brief This is the linkage for entities with true, external linkage. */
2263 CXLinkage_External
2264};
2265
2266/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002267 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002268 */
2269CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2270
2271/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002272 * \brief Determine the availability of the entity that this cursor refers to,
2273 * taking the current target platform into account.
Douglas Gregor58ddb602010-08-23 23:00:57 +00002274 *
2275 * \param cursor The cursor to query.
2276 *
2277 * \returns The availability of the cursor.
2278 */
2279CINDEX_LINKAGE enum CXAvailabilityKind
2280clang_getCursorAvailability(CXCursor cursor);
2281
2282/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002283 * Describes the availability of a given entity on a particular platform, e.g.,
2284 * a particular class might only be available on Mac OS 10.7 or newer.
2285 */
2286typedef struct CXPlatformAvailability {
2287 /**
2288 * \brief A string that describes the platform for which this structure
2289 * provides availability information.
2290 *
2291 * Possible values are "ios" or "macosx".
2292 */
2293 CXString Platform;
2294 /**
2295 * \brief The version number in which this entity was introduced.
2296 */
2297 CXVersion Introduced;
2298 /**
2299 * \brief The version number in which this entity was deprecated (but is
2300 * still available).
2301 */
2302 CXVersion Deprecated;
2303 /**
2304 * \brief The version number in which this entity was obsoleted, and therefore
2305 * is no longer available.
2306 */
2307 CXVersion Obsoleted;
2308 /**
2309 * \brief Whether the entity is unconditionally unavailable on this platform.
2310 */
2311 int Unavailable;
2312 /**
2313 * \brief An optional message to provide to a user of this API, e.g., to
2314 * suggest replacement APIs.
2315 */
2316 CXString Message;
2317} CXPlatformAvailability;
2318
2319/**
2320 * \brief Determine the availability of the entity that this cursor refers to
2321 * on any platforms for which availability information is known.
2322 *
2323 * \param cursor The cursor to query.
2324 *
2325 * \param always_deprecated If non-NULL, will be set to indicate whether the
2326 * entity is deprecated on all platforms.
2327 *
2328 * \param deprecated_message If non-NULL, will be set to the message text
2329 * provided along with the unconditional deprecation of this entity. The client
2330 * is responsible for deallocating this string.
2331 *
James Dennett7eee0182012-06-15 05:41:51 +00002332 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregorcc889662012-05-08 00:14:45 +00002333 * entity is unavailable on all platforms.
2334 *
2335 * \param unavailable_message If non-NULL, will be set to the message text
2336 * provided along with the unconditional unavailability of this entity. The
2337 * client is responsible for deallocating this string.
2338 *
2339 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2340 * that will be populated with platform availability information, up to either
2341 * the number of platforms for which availability information is available (as
2342 * returned by this function) or \c availability_size, whichever is smaller.
2343 *
2344 * \param availability_size The number of elements available in the
2345 * \c availability array.
2346 *
2347 * \returns The number of platforms (N) for which availability information is
2348 * available (which is unrelated to \c availability_size).
2349 *
2350 * Note that the client is responsible for calling
2351 * \c clang_disposeCXPlatformAvailability to free each of the
2352 * platform-availability structures returned. There are
2353 * \c min(N, availability_size) such structures.
2354 */
2355CINDEX_LINKAGE int
2356clang_getCursorPlatformAvailability(CXCursor cursor,
2357 int *always_deprecated,
2358 CXString *deprecated_message,
2359 int *always_unavailable,
2360 CXString *unavailable_message,
2361 CXPlatformAvailability *availability,
2362 int availability_size);
2363
2364/**
2365 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2366 */
2367CINDEX_LINKAGE void
2368clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2369
2370/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002371 * \brief Describe the "language" of the entity referred to by a cursor.
2372 */
2373CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002374 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002375 CXLanguage_C,
2376 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002377 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002378};
2379
2380/**
2381 * \brief Determine the "language" of the entity referred to by a given cursor.
2382 */
2383CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2384
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002385/**
2386 * \brief Returns the translation unit that a cursor originated from.
2387 */
2388CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2389
Ted Kremenek017dd742013-04-24 07:17:12 +00002390
2391/**
2392 * \brief A fast container representing a set of CXCursors.
2393 */
2394typedef struct CXCursorSetImpl *CXCursorSet;
2395
2396/**
2397 * \brief Creates an empty CXCursorSet.
2398 */
2399CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2400
2401/**
2402 * \brief Disposes a CXCursorSet and releases its associated memory.
2403 */
2404CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2405
2406/**
2407 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2408 *
2409 * \returns non-zero if the set contains the specified cursor.
2410*/
2411CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2412 CXCursor cursor);
2413
2414/**
2415 * \brief Inserts a CXCursor into a CXCursorSet.
2416 *
2417 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2418*/
2419CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2420 CXCursor cursor);
2421
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002422/**
2423 * \brief Determine the semantic parent of the given cursor.
2424 *
2425 * The semantic parent of a cursor is the cursor that semantically contains
2426 * the given \p cursor. For many declarations, the lexical and semantic parents
2427 * are equivalent (the lexical parent is returned by
2428 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2429 * definitions are provided out-of-line. For example:
2430 *
2431 * \code
2432 * class C {
2433 * void f();
2434 * };
2435 *
2436 * void C::f() { }
2437 * \endcode
2438 *
2439 * In the out-of-line definition of \c C::f, the semantic parent is the
2440 * the class \c C, of which this function is a member. The lexical parent is
2441 * the place where the declaration actually occurs in the source code; in this
2442 * case, the definition occurs in the translation unit. In general, the
2443 * lexical parent for a given entity can change without affecting the semantics
2444 * of the program, and the lexical parent of different declarations of the
2445 * same entity may be different. Changing the semantic parent of a declaration,
2446 * on the other hand, can have a major impact on semantics, and redeclarations
2447 * of a particular entity should all have the same semantic context.
2448 *
2449 * In the example above, both declarations of \c C::f have \c C as their
2450 * semantic context, while the lexical context of the first \c C::f is \c C
2451 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002452 *
2453 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002454 */
2455CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2456
2457/**
2458 * \brief Determine the lexical parent of the given cursor.
2459 *
2460 * The lexical parent of a cursor is the cursor in which the given \p cursor
2461 * was actually written. For many declarations, the lexical and semantic parents
2462 * are equivalent (the semantic parent is returned by
2463 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2464 * definitions are provided out-of-line. For example:
2465 *
2466 * \code
2467 * class C {
2468 * void f();
2469 * };
2470 *
2471 * void C::f() { }
2472 * \endcode
2473 *
2474 * In the out-of-line definition of \c C::f, the semantic parent is the
2475 * the class \c C, of which this function is a member. The lexical parent is
2476 * the place where the declaration actually occurs in the source code; in this
2477 * case, the definition occurs in the translation unit. In general, the
2478 * lexical parent for a given entity can change without affecting the semantics
2479 * of the program, and the lexical parent of different declarations of the
2480 * same entity may be different. Changing the semantic parent of a declaration,
2481 * on the other hand, can have a major impact on semantics, and redeclarations
2482 * of a particular entity should all have the same semantic context.
2483 *
2484 * In the example above, both declarations of \c C::f have \c C as their
2485 * semantic context, while the lexical context of the first \c C::f is \c C
2486 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002487 *
2488 * For declarations written in the global scope, the lexical parent is
2489 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002490 */
2491CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002492
2493/**
2494 * \brief Determine the set of methods that are overridden by the given
2495 * method.
2496 *
2497 * In both Objective-C and C++, a method (aka virtual member function,
2498 * in C++) can override a virtual method in a base class. For
2499 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002500 * base class, its protocols, or its categories' protocols, that has the same
2501 * selector and is of the same kind (class or instance).
2502 * If no such method exists, the search continues to the class's superclass,
2503 * its protocols, and its categories, and so on. A method from an Objective-C
2504 * implementation is considered to override the same methods as its
2505 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002506 *
2507 * For C++, a virtual member function overrides any virtual member
2508 * function with the same signature that occurs in its base
2509 * classes. With multiple inheritance, a virtual member function can
2510 * override several virtual member functions coming from different
2511 * base classes.
2512 *
2513 * In all cases, this function determines the immediate overridden
2514 * method, rather than all of the overridden methods. For example, if
2515 * a method is originally declared in a class A, then overridden in B
2516 * (which in inherits from A) and also in C (which inherited from B),
2517 * then the only overridden method returned from this function when
2518 * invoked on C's method will be B's method. The client may then
2519 * invoke this function again, given the previously-found overridden
2520 * methods, to map out the complete method-override set.
2521 *
2522 * \param cursor A cursor representing an Objective-C or C++
2523 * method. This routine will compute the set of methods that this
2524 * method overrides.
2525 *
2526 * \param overridden A pointer whose pointee will be replaced with a
2527 * pointer to an array of cursors, representing the set of overridden
2528 * methods. If there are no overridden methods, the pointee will be
2529 * set to NULL. The pointee must be freed via a call to
2530 * \c clang_disposeOverriddenCursors().
2531 *
2532 * \param num_overridden A pointer to the number of overridden
2533 * functions, will be set to the number of overridden functions in the
2534 * array pointed to by \p overridden.
2535 */
2536CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2537 CXCursor **overridden,
2538 unsigned *num_overridden);
2539
2540/**
2541 * \brief Free the set of overridden cursors returned by \c
2542 * clang_getOverriddenCursors().
2543 */
2544CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2545
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002546/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002547 * \brief Retrieve the file that is included by the given inclusion directive
2548 * cursor.
2549 */
2550CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2551
2552/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002553 * @}
2554 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002555
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002556/**
2557 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2558 *
2559 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2560 * routines help map between cursors and the physical locations where the
2561 * described entities occur in the source code. The mapping is provided in
2562 * both directions, so one can map from source code to the AST and back.
2563 *
2564 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002565 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002566
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002567/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002568 * \brief Map a source location to the cursor that describes the entity at that
2569 * location in the source code.
2570 *
2571 * clang_getCursor() maps an arbitrary source location within a translation
2572 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002573 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002574 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002575 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002576 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2577 * will return a cursor referring to the "+" expression.
2578 *
2579 * \returns a cursor representing the entity at the given source location, or
2580 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002581 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002582CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002583
Douglas Gregor98258af2010-01-18 22:46:11 +00002584/**
2585 * \brief Retrieve the physical location of the source constructor referenced
2586 * by the given cursor.
2587 *
2588 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002589 * declaration, where the name of that declaration would occur if it is
2590 * unnamed, or some keyword that introduces that particular declaration.
2591 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002592 * source code.
2593 */
2594CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002595
Douglas Gregorb6998662010-01-19 19:34:47 +00002596/**
2597 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002598 * the given cursor.
2599 *
2600 * The extent of a cursor starts with the file/line/column pointing at the
2601 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002602 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002603 * declaration, the extent covers the declaration itself. For a reference,
2604 * the extent covers the location of the reference (e.g., where the referenced
2605 * entity was actually used).
2606 */
2607CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002608
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002609/**
2610 * @}
2611 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002612
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002613/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002614 * \defgroup CINDEX_TYPES Type information for CXCursors
2615 *
2616 * @{
2617 */
2618
2619/**
2620 * \brief Describes the kind of type
2621 */
2622enum CXTypeKind {
2623 /**
2624 * \brief Reprents an invalid type (e.g., where no type is available).
2625 */
2626 CXType_Invalid = 0,
2627
2628 /**
2629 * \brief A type whose specific kind is not exposed via this
2630 * interface.
2631 */
2632 CXType_Unexposed = 1,
2633
2634 /* Builtin types */
2635 CXType_Void = 2,
2636 CXType_Bool = 3,
2637 CXType_Char_U = 4,
2638 CXType_UChar = 5,
2639 CXType_Char16 = 6,
2640 CXType_Char32 = 7,
2641 CXType_UShort = 8,
2642 CXType_UInt = 9,
2643 CXType_ULong = 10,
2644 CXType_ULongLong = 11,
2645 CXType_UInt128 = 12,
2646 CXType_Char_S = 13,
2647 CXType_SChar = 14,
2648 CXType_WChar = 15,
2649 CXType_Short = 16,
2650 CXType_Int = 17,
2651 CXType_Long = 18,
2652 CXType_LongLong = 19,
2653 CXType_Int128 = 20,
2654 CXType_Float = 21,
2655 CXType_Double = 22,
2656 CXType_LongDouble = 23,
2657 CXType_NullPtr = 24,
2658 CXType_Overload = 25,
2659 CXType_Dependent = 26,
2660 CXType_ObjCId = 27,
2661 CXType_ObjCClass = 28,
2662 CXType_ObjCSel = 29,
2663 CXType_FirstBuiltin = CXType_Void,
2664 CXType_LastBuiltin = CXType_ObjCSel,
2665
2666 CXType_Complex = 100,
2667 CXType_Pointer = 101,
2668 CXType_BlockPointer = 102,
2669 CXType_LValueReference = 103,
2670 CXType_RValueReference = 104,
2671 CXType_Record = 105,
2672 CXType_Enum = 106,
2673 CXType_Typedef = 107,
2674 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002675 CXType_ObjCObjectPointer = 109,
2676 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002677 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002678 CXType_ConstantArray = 112,
Argyrios Kyrtzidis4c4f6fe2013-07-23 17:36:21 +00002679 CXType_Vector = 113,
2680 CXType_IncompleteArray = 114,
2681 CXType_VariableArray = 115,
2682 CXType_DependentSizedArray = 116
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002683};
2684
2685/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002686 * \brief Describes the calling convention of a function type
2687 */
2688enum CXCallingConv {
2689 CXCallingConv_Default = 0,
2690 CXCallingConv_C = 1,
2691 CXCallingConv_X86StdCall = 2,
2692 CXCallingConv_X86FastCall = 3,
2693 CXCallingConv_X86ThisCall = 4,
2694 CXCallingConv_X86Pascal = 5,
2695 CXCallingConv_AAPCS = 6,
2696 CXCallingConv_AAPCS_VFP = 7,
Derek Schuff263366f2012-10-16 22:30:41 +00002697 CXCallingConv_PnaclCall = 8,
Guy Benyei38980082012-12-25 08:53:55 +00002698 CXCallingConv_IntelOclBicc = 9,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002699
2700 CXCallingConv_Invalid = 100,
2701 CXCallingConv_Unexposed = 200
2702};
2703
2704
2705/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002706 * \brief The type of an element in the abstract syntax tree.
2707 *
2708 */
2709typedef struct {
2710 enum CXTypeKind kind;
2711 void *data[2];
2712} CXType;
2713
2714/**
2715 * \brief Retrieve the type of a CXCursor (if any).
2716 */
2717CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2718
2719/**
Dmitri Gribenkoae03d8e2013-02-15 21:15:49 +00002720 * \brief Pretty-print the underlying type using the rules of the
2721 * language of the translation unit from which it came.
2722 *
2723 * If the type is invalid, an empty string is returned.
2724 */
2725CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2726
2727/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002728 * \brief Retrieve the underlying type of a typedef declaration.
2729 *
2730 * If the cursor does not reference a typedef declaration, an invalid type is
2731 * returned.
2732 */
2733CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2734
2735/**
2736 * \brief Retrieve the integer type of an enum declaration.
2737 *
2738 * If the cursor does not reference an enum declaration, an invalid type is
2739 * returned.
2740 */
2741CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2742
2743/**
2744 * \brief Retrieve the integer value of an enum constant declaration as a signed
2745 * long long.
2746 *
2747 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2748 * Since this is also potentially a valid constant value, the kind of the cursor
2749 * must be verified before calling this function.
2750 */
2751CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2752
2753/**
2754 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2755 * long long.
2756 *
2757 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2758 * Since this is also potentially a valid constant value, the kind of the cursor
2759 * must be verified before calling this function.
2760 */
2761CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2762
2763/**
Dmitri Gribenko1eb60822012-12-04 15:13:46 +00002764 * \brief Retrieve the bit width of a bit field declaration as an integer.
2765 *
2766 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2767 */
2768CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2769
2770/**
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002771 * \brief Retrieve the number of non-variadic arguments associated with a given
2772 * cursor.
2773 *
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +00002774 * The number of arguments can be determined for calls as well as for
2775 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002776 */
2777CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2778
2779/**
2780 * \brief Retrieve the argument cursor of a function or method.
2781 *
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +00002782 * The argument cursor can be determined for calls as well as for declarations
2783 * of functions or methods. For other cursors and for invalid indices, an
2784 * invalid cursor is returned.
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002785 */
2786CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2787
2788/**
James Dennett7eee0182012-06-15 05:41:51 +00002789 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002790 *
James Dennett7eee0182012-06-15 05:41:51 +00002791 * \returns non-zero if the CXTypes represent the same type and
2792 * zero otherwise.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002793 */
2794CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2795
2796/**
2797 * \brief Return the canonical type for a CXType.
2798 *
2799 * Clang's type system explicitly models typedefs and all the ways
2800 * a specific type can be represented. The canonical type is the underlying
2801 * type with all the "sugar" removed. For example, if 'T' is a typedef
2802 * for 'int', the canonical type for 'T' would be 'int'.
2803 */
2804CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2805
2806/**
James Dennett7eee0182012-06-15 05:41:51 +00002807 * \brief Determine whether a CXType has the "const" qualifier set,
2808 * without looking through typedefs that may have added "const" at a
2809 * different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002810 */
2811CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2812
2813/**
James Dennett7eee0182012-06-15 05:41:51 +00002814 * \brief Determine whether a CXType has the "volatile" qualifier set,
2815 * without looking through typedefs that may have added "volatile" at
2816 * a different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002817 */
2818CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2819
2820/**
James Dennett7eee0182012-06-15 05:41:51 +00002821 * \brief Determine whether a CXType has the "restrict" qualifier set,
2822 * without looking through typedefs that may have added "restrict" at a
2823 * different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002824 */
2825CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2826
2827/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002828 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002829 */
2830CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2831
2832/**
2833 * \brief Return the cursor for the declaration of the given type.
2834 */
2835CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2836
David Chisnall5389f482010-12-30 14:05:53 +00002837/**
2838 * Returns the Objective-C type encoding for the specified declaration.
2839 */
2840CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002841
2842/**
2843 * \brief Retrieve the spelling of a given CXTypeKind.
2844 */
2845CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2846
2847/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002848 * \brief Retrieve the calling convention associated with a function type.
2849 *
2850 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2851 */
2852CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2853
2854/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002855 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002856 *
2857 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002858 */
2859CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2860
2861/**
James Dennett7eee0182012-06-15 05:41:51 +00002862 * \brief Retrieve the number of non-variadic arguments associated with a
2863 * function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002864 *
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002865 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002866 */
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002867CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002868
2869/**
2870 * \brief Retrieve the type of an argument of a function type.
2871 *
James Dennett7eee0182012-06-15 05:41:51 +00002872 * If a non-function type is passed in or the function does not have enough
2873 * parameters, an invalid type is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002874 */
2875CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2876
2877/**
2878 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002879 */
2880CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2881
2882/**
2883 * \brief Retrieve the result type associated with a given cursor.
2884 *
2885 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002886 */
2887CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2888
2889/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002890 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2891 * otherwise.
2892 */
2893CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2894
2895/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002896 * \brief Return the element type of an array, complex, or vector type.
2897 *
2898 * If a type is passed in that is not an array, complex, or vector type,
2899 * an invalid type is returned.
2900 */
2901CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2902
2903/**
2904 * \brief Return the number of elements of an array or vector type.
2905 *
2906 * If a type is passed in that is not an array or vector type,
2907 * -1 is returned.
2908 */
2909CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2910
2911/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002912 * \brief Return the element type of an array type.
2913 *
2914 * If a non-array type is passed in, an invalid type is returned.
2915 */
2916CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2917
2918/**
Sylvestre Ledrubed28ac2012-07-23 08:59:39 +00002919 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002920 *
2921 * If a non-array type is passed in, -1 is returned.
2922 */
2923CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2924
2925/**
Argyrios Kyrtzidis411d33a2013-04-11 01:20:11 +00002926 * \brief List the possible error codes for \c clang_Type_getSizeOf,
2927 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
2928 * \c clang_Cursor_getOffsetOf.
2929 *
2930 * A value of this enumeration type can be returned if the target type is not
2931 * a valid argument to sizeof, alignof or offsetof.
2932 */
2933enum CXTypeLayoutError {
2934 /**
2935 * \brief Type is of kind CXType_Invalid.
2936 */
2937 CXTypeLayoutError_Invalid = -1,
2938 /**
2939 * \brief The type is an incomplete Type.
2940 */
2941 CXTypeLayoutError_Incomplete = -2,
2942 /**
2943 * \brief The type is a dependent Type.
2944 */
2945 CXTypeLayoutError_Dependent = -3,
2946 /**
2947 * \brief The type is not a constant size type.
2948 */
2949 CXTypeLayoutError_NotConstantSize = -4,
2950 /**
2951 * \brief The Field name is not valid for this record.
2952 */
2953 CXTypeLayoutError_InvalidFieldName = -5
2954};
2955
2956/**
2957 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
2958 * 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 * If the type declaration is not a constant size type,
2966 * CXTypeLayoutError_NotConstantSize is returned.
2967 */
2968CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
2969
2970/**
2971 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
2972 *
2973 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2974 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2975 * is returned.
2976 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2977 * returned.
2978 */
2979CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
2980
2981/**
2982 * \brief Return the offset of a field named S in a record of type T in bits
2983 * as it would be returned by __offsetof__ as per C++11[18.2p4]
2984 *
2985 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
2986 * is returned.
2987 * If the field's type declaration is an incomplete type,
2988 * CXTypeLayoutError_Incomplete is returned.
2989 * If the field's type declaration is a dependent type,
2990 * CXTypeLayoutError_Dependent is returned.
2991 * If the field's name S is not found,
2992 * CXTypeLayoutError_InvalidFieldName is returned.
2993 */
2994CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
2995
2996/**
2997 * \brief Returns non-zero if the cursor specifies a Record member that is a
2998 * bitfield.
2999 */
3000CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
3001
3002/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00003003 * \brief Returns 1 if the base class specified by the cursor with kind
3004 * CX_CXXBaseSpecifier is virtual.
3005 */
3006CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3007
3008/**
3009 * \brief Represents the C++ access control level to a base class for a
3010 * cursor with kind CX_CXXBaseSpecifier.
3011 */
3012enum CX_CXXAccessSpecifier {
3013 CX_CXXInvalidAccessSpecifier,
3014 CX_CXXPublic,
3015 CX_CXXProtected,
3016 CX_CXXPrivate
3017};
3018
3019/**
Argyrios Kyrtzidis04b67482013-04-11 17:02:10 +00003020 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidis5142be62013-04-11 17:31:13 +00003021 *
Argyrios Kyrtzidis04b67482013-04-11 17:02:10 +00003022 * If the cursor refers to a C++ declaration, its access control level within its
3023 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3024 * access specifier, the specifier itself is returned.
Ted Kremenek3064ef92010-08-27 21:34:58 +00003025 */
3026CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3027
3028/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00003029 * \brief Determine the number of overloaded declarations referenced by a
3030 * \c CXCursor_OverloadedDeclRef cursor.
3031 *
3032 * \param cursor The cursor whose overloaded declarations are being queried.
3033 *
3034 * \returns The number of overloaded declarations referenced by \c cursor. If it
3035 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3036 */
3037CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3038
3039/**
3040 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3041 * by a \c CXCursor_OverloadedDeclRef cursor.
3042 *
3043 * \param cursor The cursor whose overloaded declarations are being queried.
3044 *
3045 * \param index The zero-based index into the set of overloaded declarations in
3046 * the cursor.
3047 *
3048 * \returns A cursor representing the declaration referenced by the given
3049 * \c cursor at the specified \c index. If the cursor does not have an
3050 * associated set of overloaded declarations, or if the index is out of bounds,
3051 * returns \c clang_getNullCursor();
3052 */
3053CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3054 unsigned index);
3055
3056/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00003057 * @}
3058 */
Ted Kremenek95f33552010-08-26 01:42:22 +00003059
3060/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00003061 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00003062 *
3063 * @{
3064 */
3065
3066
3067/**
3068 * \brief For cursors representing an iboutletcollection attribute,
3069 * this function returns the collection element type.
3070 *
3071 */
3072CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3073
3074/**
3075 * @}
3076 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00003077
3078/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003079 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3080 *
3081 * These routines provide the ability to traverse the abstract syntax tree
3082 * using cursors.
3083 *
3084 * @{
3085 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003086
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003087/**
3088 * \brief Describes how the traversal of the children of a particular
3089 * cursor should proceed after visiting a particular child cursor.
3090 *
3091 * A value of this enumeration type should be returned by each
3092 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3093 */
3094enum CXChildVisitResult {
3095 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003096 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003097 */
3098 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003099 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003100 * \brief Continues the cursor traversal with the next sibling of
3101 * the cursor just visited, without visiting its children.
3102 */
3103 CXChildVisit_Continue,
3104 /**
3105 * \brief Recursively traverse the children of this cursor, using
3106 * the same visitor and client data.
3107 */
3108 CXChildVisit_Recurse
3109};
3110
3111/**
3112 * \brief Visitor invoked for each cursor found by a traversal.
3113 *
3114 * This visitor function will be invoked for each cursor found by
3115 * clang_visitCursorChildren(). Its first argument is the cursor being
3116 * visited, its second argument is the parent visitor for that cursor,
3117 * and its third argument is the client data provided to
3118 * clang_visitCursorChildren().
3119 *
3120 * The visitor should return one of the \c CXChildVisitResult values
3121 * to direct clang_visitCursorChildren().
3122 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003123typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3124 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003125 CXClientData client_data);
3126
3127/**
3128 * \brief Visit the children of a particular cursor.
3129 *
3130 * This function visits all the direct children of the given cursor,
3131 * invoking the given \p visitor function with the cursors of each
3132 * visited child. The traversal may be recursive, if the visitor returns
3133 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3134 * the visitor returns \c CXChildVisit_Break.
3135 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003136 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00003137 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003138 * definition, have no children).
3139 *
3140 * \param visitor the visitor function that will be invoked for each
3141 * child of \p parent.
3142 *
3143 * \param client_data pointer data supplied by the client, which will
3144 * be passed to the visitor each time it is invoked.
3145 *
3146 * \returns a non-zero value if the traversal was terminated
3147 * prematurely by the visitor returning \c CXChildVisit_Break.
3148 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003149CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003150 CXCursorVisitor visitor,
3151 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00003152#ifdef __has_feature
3153# if __has_feature(blocks)
3154/**
3155 * \brief Visitor invoked for each cursor found by a traversal.
3156 *
3157 * This visitor block will be invoked for each cursor found by
3158 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3159 * visited, its second argument is the parent visitor for that cursor.
3160 *
3161 * The visitor should return one of the \c CXChildVisitResult values
3162 * to direct clang_visitChildrenWithBlock().
3163 */
3164typedef enum CXChildVisitResult
3165 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3166
3167/**
3168 * Visits the children of a cursor using the specified block. Behaves
3169 * identically to clang_visitChildren() in all other respects.
3170 */
3171unsigned clang_visitChildrenWithBlock(CXCursor parent,
3172 CXCursorVisitorBlock block);
3173# endif
3174#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003175
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003176/**
3177 * @}
3178 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003179
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003180/**
3181 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3182 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003183 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003184 * across translation units, by providing the names of the entities referenced
3185 * by cursors, follow reference cursors to the declarations they reference,
3186 * and associate declarations with their definitions.
3187 *
3188 * @{
3189 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003190
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003191/**
3192 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3193 * by the given cursor.
3194 *
3195 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3196 * entity (function, class, variable, etc.) within a program. USRs can be
3197 * compared across translation units to determine, e.g., when references in
3198 * one translation refer to an entity defined in another translation unit.
3199 */
3200CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3201
3202/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003203 * \brief Construct a USR for a specified Objective-C class.
3204 */
3205CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3206
3207/**
3208 * \brief Construct a USR for a specified Objective-C category.
3209 */
3210CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00003211 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003212 const char *category_name);
3213
3214/**
3215 * \brief Construct a USR for a specified Objective-C protocol.
3216 */
3217CINDEX_LINKAGE CXString
3218 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3219
3220
3221/**
3222 * \brief Construct a USR for a specified Objective-C instance variable and
3223 * the USR for its containing class.
3224 */
3225CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3226 CXString classUSR);
3227
3228/**
3229 * \brief Construct a USR for a specified Objective-C method and
3230 * the USR for its containing class.
3231 */
3232CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3233 unsigned isInstanceMethod,
3234 CXString classUSR);
3235
3236/**
3237 * \brief Construct a USR for a specified Objective-C property and the USR
3238 * for its containing class.
3239 */
3240CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3241 CXString classUSR);
3242
3243/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003244 * \brief Retrieve a name for the entity referenced by this cursor.
3245 */
3246CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3247
Douglas Gregor358559d2010-10-02 22:49:11 +00003248/**
Argyrios Kyrtzidisba1da142012-03-30 20:58:35 +00003249 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3250 * Most of the times there is only one range for the complete spelling but for
3251 * objc methods and objc message expressions, there are multiple pieces for each
3252 * selector identifier.
3253 *
3254 * \param pieceIndex the index of the spelling name piece. If this is greater
3255 * than the actual number of pieces, it will return a NULL (invalid) range.
3256 *
3257 * \param options Reserved.
3258 */
3259CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3260 unsigned pieceIndex,
3261 unsigned options);
3262
3263/**
Douglas Gregor358559d2010-10-02 22:49:11 +00003264 * \brief Retrieve the display name for the entity referenced by this cursor.
3265 *
3266 * The display name contains extra information that helps identify the cursor,
3267 * such as the parameters of a function or template or the arguments of a
3268 * class template specialization.
3269 */
3270CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3271
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003272/** \brief For a cursor that is a reference, retrieve a cursor representing the
3273 * entity that it references.
3274 *
3275 * Reference cursors refer to other entities in the AST. For example, an
3276 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003277 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003278 * cursor for the superclass reference. If the input cursor is a declaration or
3279 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003280 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003281 */
3282CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00003283
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003284/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003285 * \brief For a cursor that is either a reference to or a declaration
3286 * of some entity, retrieve a cursor that describes the definition of
3287 * that entity.
3288 *
3289 * Some entities can be declared multiple times within a translation
3290 * unit, but only one of those declarations can also be a
3291 * definition. For example, given:
3292 *
3293 * \code
3294 * int f(int, int);
3295 * int g(int x, int y) { return f(x, y); }
3296 * int f(int a, int b) { return a + b; }
3297 * int f(int, int);
3298 * \endcode
3299 *
3300 * there are three declarations of the function "f", but only the
3301 * second one is a definition. The clang_getCursorDefinition()
3302 * function will take any cursor pointing to a declaration of "f"
3303 * (the first or fourth lines of the example) or a cursor referenced
3304 * that uses "f" (the call to "f' inside "g") and will return a
3305 * declaration cursor pointing to the definition (the second "f"
3306 * declaration).
3307 *
3308 * If given a cursor for which there is no corresponding definition,
3309 * e.g., because there is no definition of that entity within this
3310 * translation unit, returns a NULL cursor.
3311 */
3312CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3313
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003314/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003315 * \brief Determine whether the declaration pointed to by this cursor
3316 * is also a definition of that entity.
3317 */
3318CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3319
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003320/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003321 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3322 *
3323 * In the C family of languages, many kinds of entities can be declared several
3324 * times within a single translation unit. For example, a structure type can
3325 * be forward-declared (possibly multiple times) and later defined:
3326 *
3327 * \code
3328 * struct X;
3329 * struct X;
3330 * struct X {
3331 * int member;
3332 * };
3333 * \endcode
3334 *
3335 * The declarations and the definition of \c X are represented by three
3336 * different cursors, all of which are declarations of the same underlying
3337 * entity. One of these cursor is considered the "canonical" cursor, which
3338 * is effectively the representative for the underlying entity. One can
3339 * determine if two cursors are declarations of the same underlying entity by
3340 * comparing their canonical cursors.
3341 *
3342 * \returns The canonical cursor for the entity referred to by the given cursor.
3343 */
3344CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3345
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003346
3347/**
3348 * \brief If the cursor points to a selector identifier in a objc method or
3349 * message expression, this returns the selector index.
3350 *
James Dennett7eee0182012-06-15 05:41:51 +00003351 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003352 * determine if the location points to a selector identifier.
3353 *
3354 * \returns The selector index if the cursor is an objc method or message
3355 * expression and the cursor is pointing to a selector identifier, or -1
3356 * otherwise.
3357 */
3358CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3359
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003360/**
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00003361 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3362 * returns non-zero if the method/message is "dynamic", meaning:
3363 *
3364 * For a C++ method: the call is virtual.
3365 * For an ObjC message: the receiver is an object instance, not 'super' or a
3366 * specific class.
3367 *
3368 * If the method/message is "static" or the cursor does not point to a
3369 * method/message, it will return zero.
3370 */
3371CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3372
3373/**
Argyrios Kyrtzidise4a990f2012-11-01 02:01:34 +00003374 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3375 * receiver.
3376 */
3377CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3378
3379/**
Argyrios Kyrtzidis9ee6a662013-04-18 22:15:49 +00003380 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3381 */
3382typedef enum {
3383 CXObjCPropertyAttr_noattr = 0x00,
3384 CXObjCPropertyAttr_readonly = 0x01,
3385 CXObjCPropertyAttr_getter = 0x02,
3386 CXObjCPropertyAttr_assign = 0x04,
3387 CXObjCPropertyAttr_readwrite = 0x08,
3388 CXObjCPropertyAttr_retain = 0x10,
3389 CXObjCPropertyAttr_copy = 0x20,
3390 CXObjCPropertyAttr_nonatomic = 0x40,
3391 CXObjCPropertyAttr_setter = 0x80,
3392 CXObjCPropertyAttr_atomic = 0x100,
3393 CXObjCPropertyAttr_weak = 0x200,
3394 CXObjCPropertyAttr_strong = 0x400,
3395 CXObjCPropertyAttr_unsafe_unretained = 0x800
3396} CXObjCPropertyAttrKind;
3397
3398/**
3399 * \brief Given a cursor that represents a property declaration, return the
3400 * associated property attributes. The bits are formed from
3401 * \c CXObjCPropertyAttrKind.
3402 *
3403 * \param reserved Reserved for future use, pass 0.
3404 */
3405CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3406 unsigned reserved);
3407
3408/**
Argyrios Kyrtzidis38dbad22013-04-18 23:29:12 +00003409 * \brief 'Qualifiers' written next to the return and parameter types in
3410 * ObjC method declarations.
3411 */
3412typedef enum {
3413 CXObjCDeclQualifier_None = 0x0,
3414 CXObjCDeclQualifier_In = 0x1,
3415 CXObjCDeclQualifier_Inout = 0x2,
3416 CXObjCDeclQualifier_Out = 0x4,
3417 CXObjCDeclQualifier_Bycopy = 0x8,
3418 CXObjCDeclQualifier_Byref = 0x10,
3419 CXObjCDeclQualifier_Oneway = 0x20
3420} CXObjCDeclQualifierKind;
3421
3422/**
3423 * \brief Given a cursor that represents an ObjC method or parameter
3424 * declaration, return the associated ObjC qualifiers for the return type or the
Argyrios Kyrtzidis8be71a62013-04-19 00:51:52 +00003425 * parameter respectively. The bits are formed from CXObjCDeclQualifierKind.
Argyrios Kyrtzidis38dbad22013-04-18 23:29:12 +00003426 */
3427CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3428
3429/**
Argyrios Kyrtzidis514afc72013-07-05 20:44:37 +00003430 * \brief Given a cursor that represents an ObjC method or property declaration,
3431 * return non-zero if the declaration was affected by "@optional".
3432 * Returns zero if the cursor is not such a declaration or it is "@required".
3433 */
3434CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
3435
3436/**
Argyrios Kyrtzidis80e1aca2013-04-18 23:53:05 +00003437 * \brief Returns non-zero if the given cursor is a variadic function or method.
3438 */
3439CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3440
3441/**
Dmitri Gribenkoaa0cd852012-06-20 00:34:58 +00003442 * \brief Given a cursor that represents a declaration, return the associated
3443 * comment's source range. The range may include multiple consecutive comments
3444 * with whitespace in between.
3445 */
3446CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3447
3448/**
3449 * \brief Given a cursor that represents a declaration, return the associated
3450 * comment text, including comment markers.
3451 */
3452CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3453
3454/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003455 * \brief Given a cursor that represents a documentable entity (e.g.,
3456 * declaration), return the associated \\brief paragraph; otherwise return the
3457 * first paragraph.
Dmitri Gribenko2d44d772012-06-26 20:39:18 +00003458 */
3459CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3460
3461/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003462 * \brief Given a cursor that represents a documentable entity (e.g.,
3463 * declaration), return the associated parsed comment as a
3464 * \c CXComment_FullComment AST node.
3465 */
3466CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3467
3468/**
3469 * @}
3470 */
3471
3472/**
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003473 * \defgroup CINDEX_MODULE Module introspection
3474 *
3475 * The functions in this group provide access to information about modules.
3476 *
3477 * @{
3478 */
3479
3480typedef void *CXModule;
3481
3482/**
3483 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3484 */
3485CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3486
3487/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003488 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003489 *
Argyrios Kyrtzidise858e662013-04-26 22:47:49 +00003490 * \returns the module file where the provided module object came from.
3491 */
3492CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3493
3494/**
3495 * \param Module a module object.
3496 *
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003497 * \returns the parent of a sub-module or NULL if the given module is top-level,
3498 * e.g. for 'std.vector' it will return the 'std' module.
3499 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003500CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003501
3502/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003503 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003504 *
3505 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3506 * will return "vector".
3507 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003508CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003509
3510/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003511 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003512 *
3513 * \returns the full name of the module, e.g. "std.vector".
3514 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003515CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003516
3517/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003518 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003519 *
3520 * \returns the number of top level headers associated with this module.
3521 */
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +00003522CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3523 CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003524
3525/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003526 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003527 *
3528 * \param Index top level header index (zero-based).
3529 *
3530 * \returns the specified top level header associated with the module.
3531 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003532CINDEX_LINKAGE
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +00003533CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3534 CXModule Module, unsigned Index);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003535
3536/**
3537 * @}
3538 */
3539
3540/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003541 * \defgroup CINDEX_COMMENT Comment AST introspection
3542 *
3543 * The routines in this group provide access to information in the
3544 * documentation comment ASTs.
3545 *
3546 * @{
3547 */
3548
3549/**
3550 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3551 * node can be considered block content (e. g., paragraph), inline content
3552 * (plain text) or neither (the root AST node).
3553 */
3554enum CXCommentKind {
3555 /**
3556 * \brief Null comment. No AST node is constructed at the requested location
3557 * because there is no text or a syntax error.
3558 */
3559 CXComment_Null = 0,
3560
3561 /**
3562 * \brief Plain text. Inline content.
3563 */
3564 CXComment_Text = 1,
3565
3566 /**
3567 * \brief A command with word-like arguments that is considered inline content.
3568 *
3569 * For example: \\c command.
3570 */
3571 CXComment_InlineCommand = 2,
3572
3573 /**
3574 * \brief HTML start tag with attributes (name-value pairs). Considered
3575 * inline content.
3576 *
3577 * For example:
3578 * \verbatim
3579 * <br> <br /> <a href="http://example.org/">
3580 * \endverbatim
3581 */
3582 CXComment_HTMLStartTag = 3,
3583
3584 /**
3585 * \brief HTML end tag. Considered inline content.
3586 *
3587 * For example:
3588 * \verbatim
3589 * </a>
3590 * \endverbatim
3591 */
3592 CXComment_HTMLEndTag = 4,
3593
3594 /**
3595 * \brief A paragraph, contains inline comment. The paragraph itself is
3596 * block content.
3597 */
3598 CXComment_Paragraph = 5,
3599
3600 /**
3601 * \brief A command that has zero or more word-like arguments (number of
3602 * word-like arguments depends on command name) and a paragraph as an
3603 * argument. Block command is block content.
3604 *
3605 * Paragraph argument is also a child of the block command.
3606 *
3607 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3608 *
3609 * AST nodes of special kinds that parser knows about (e. g., \\param
3610 * command) have their own node kinds.
3611 */
3612 CXComment_BlockCommand = 6,
3613
3614 /**
3615 * \brief A \\param or \\arg command that describes the function parameter
3616 * (name, passing direction, description).
3617 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003618 * For example: \\param [in] ParamName description.
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003619 */
3620 CXComment_ParamCommand = 7,
3621
3622 /**
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003623 * \brief A \\tparam command that describes a template parameter (name and
3624 * description).
3625 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003626 * For example: \\tparam T description.
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003627 */
3628 CXComment_TParamCommand = 8,
3629
3630 /**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003631 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3632 * block has an opening and a closing command and contains multiple lines of
3633 * text (\c CXComment_VerbatimBlockLine child nodes).
3634 *
3635 * For example:
3636 * \\verbatim
3637 * aaa
3638 * \\endverbatim
3639 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003640 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003641
3642 /**
3643 * \brief A line of text that is contained within a
3644 * CXComment_VerbatimBlockCommand node.
3645 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003646 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003647
3648 /**
3649 * \brief A verbatim line command. Verbatim line has an opening command,
3650 * a single line of text (up to the newline after the opening command) and
3651 * has no closing command.
3652 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003653 CXComment_VerbatimLine = 11,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003654
3655 /**
3656 * \brief A full comment attached to a declaration, contains block content.
3657 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003658 CXComment_FullComment = 12
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003659};
3660
3661/**
Dmitri Gribenko2d66a502012-07-23 16:43:01 +00003662 * \brief The most appropriate rendering mode for an inline command, chosen on
3663 * command semantics in Doxygen.
3664 */
3665enum CXCommentInlineCommandRenderKind {
3666 /**
3667 * \brief Command argument should be rendered in a normal font.
3668 */
3669 CXCommentInlineCommandRenderKind_Normal,
3670
3671 /**
3672 * \brief Command argument should be rendered in a bold font.
3673 */
3674 CXCommentInlineCommandRenderKind_Bold,
3675
3676 /**
3677 * \brief Command argument should be rendered in a monospaced font.
3678 */
3679 CXCommentInlineCommandRenderKind_Monospaced,
3680
3681 /**
3682 * \brief Command argument should be rendered emphasized (typically italic
3683 * font).
3684 */
3685 CXCommentInlineCommandRenderKind_Emphasized
3686};
3687
3688/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003689 * \brief Describes parameter passing direction for \\param or \\arg command.
3690 */
3691enum CXCommentParamPassDirection {
3692 /**
3693 * \brief The parameter is an input parameter.
3694 */
3695 CXCommentParamPassDirection_In,
3696
3697 /**
3698 * \brief The parameter is an output parameter.
3699 */
3700 CXCommentParamPassDirection_Out,
3701
3702 /**
3703 * \brief The parameter is an input and output parameter.
3704 */
3705 CXCommentParamPassDirection_InOut
3706};
3707
3708/**
3709 * \param Comment AST node of any kind.
3710 *
3711 * \returns the type of the AST node.
3712 */
3713CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3714
3715/**
3716 * \param Comment AST node of any kind.
3717 *
3718 * \returns number of children of the AST node.
3719 */
3720CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3721
3722/**
3723 * \param Comment AST node of any kind.
3724 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003725 * \param ChildIdx child index (zero-based).
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003726 *
3727 * \returns the specified child of the AST node.
3728 */
3729CINDEX_LINKAGE
3730CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3731
3732/**
3733 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3734 * only \c CXComment_Text nodes that are empty or whitespace.
3735 *
3736 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3737 * never considered whitespace.
3738 *
3739 * \returns non-zero if \c Comment is whitespace.
3740 */
3741CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3742
3743/**
3744 * \returns non-zero if \c Comment is inline content and has a newline
3745 * immediately following it in the comment text. Newlines between paragraphs
3746 * do not count.
3747 */
3748CINDEX_LINKAGE
3749unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3750
3751/**
3752 * \param Comment a \c CXComment_Text AST node.
3753 *
3754 * \returns text contained in the AST node.
3755 */
3756CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3757
3758/**
3759 * \param Comment a \c CXComment_InlineCommand AST node.
3760 *
3761 * \returns name of the inline command.
3762 */
3763CINDEX_LINKAGE
3764CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3765
3766/**
3767 * \param Comment a \c CXComment_InlineCommand AST node.
3768 *
Dmitri Gribenko2d66a502012-07-23 16:43:01 +00003769 * \returns the most appropriate rendering mode, chosen on command
3770 * semantics in Doxygen.
3771 */
3772CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3773clang_InlineCommandComment_getRenderKind(CXComment Comment);
3774
3775/**
3776 * \param Comment a \c CXComment_InlineCommand AST node.
3777 *
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003778 * \returns number of command arguments.
3779 */
3780CINDEX_LINKAGE
3781unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3782
3783/**
3784 * \param Comment a \c CXComment_InlineCommand AST node.
3785 *
3786 * \param ArgIdx argument index (zero-based).
3787 *
3788 * \returns text of the specified argument.
3789 */
3790CINDEX_LINKAGE
3791CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3792 unsigned ArgIdx);
3793
3794/**
3795 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3796 * node.
3797 *
3798 * \returns HTML tag name.
3799 */
3800CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3801
3802/**
3803 * \param Comment a \c CXComment_HTMLStartTag AST node.
3804 *
3805 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3806 */
3807CINDEX_LINKAGE
3808unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3809
3810/**
3811 * \param Comment a \c CXComment_HTMLStartTag AST node.
3812 *
3813 * \returns number of attributes (name-value pairs) attached to the start tag.
3814 */
3815CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3816
3817/**
3818 * \param Comment a \c CXComment_HTMLStartTag AST node.
3819 *
3820 * \param AttrIdx attribute index (zero-based).
3821 *
3822 * \returns name of the specified attribute.
3823 */
3824CINDEX_LINKAGE
3825CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3826
3827/**
3828 * \param Comment a \c CXComment_HTMLStartTag AST node.
3829 *
3830 * \param AttrIdx attribute index (zero-based).
3831 *
3832 * \returns value of the specified attribute.
3833 */
3834CINDEX_LINKAGE
3835CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3836
3837/**
3838 * \param Comment a \c CXComment_BlockCommand AST node.
3839 *
3840 * \returns name of the block command.
3841 */
3842CINDEX_LINKAGE
3843CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3844
3845/**
3846 * \param Comment a \c CXComment_BlockCommand AST node.
3847 *
3848 * \returns number of word-like arguments.
3849 */
3850CINDEX_LINKAGE
3851unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3852
3853/**
3854 * \param Comment a \c CXComment_BlockCommand AST node.
3855 *
3856 * \param ArgIdx argument index (zero-based).
3857 *
3858 * \returns text of the specified word-like argument.
3859 */
3860CINDEX_LINKAGE
3861CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3862 unsigned ArgIdx);
3863
3864/**
3865 * \param Comment a \c CXComment_BlockCommand or
3866 * \c CXComment_VerbatimBlockCommand AST node.
3867 *
3868 * \returns paragraph argument of the block command.
3869 */
3870CINDEX_LINKAGE
3871CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3872
3873/**
3874 * \param Comment a \c CXComment_ParamCommand AST node.
3875 *
3876 * \returns parameter name.
3877 */
3878CINDEX_LINKAGE
3879CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3880
3881/**
3882 * \param Comment a \c CXComment_ParamCommand AST node.
3883 *
3884 * \returns non-zero if the parameter that this AST node represents was found
3885 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3886 * function will return a meaningful value.
3887 */
3888CINDEX_LINKAGE
3889unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3890
3891/**
3892 * \param Comment a \c CXComment_ParamCommand AST node.
3893 *
3894 * \returns zero-based parameter index in function prototype.
3895 */
3896CINDEX_LINKAGE
3897unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3898
3899/**
3900 * \param Comment a \c CXComment_ParamCommand AST node.
3901 *
3902 * \returns non-zero if parameter passing direction was specified explicitly in
3903 * the comment.
3904 */
3905CINDEX_LINKAGE
3906unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3907
3908/**
3909 * \param Comment a \c CXComment_ParamCommand AST node.
3910 *
3911 * \returns parameter passing direction.
3912 */
3913CINDEX_LINKAGE
3914enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
3915 CXComment Comment);
3916
3917/**
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003918 * \param Comment a \c CXComment_TParamCommand AST node.
3919 *
3920 * \returns template parameter name.
3921 */
3922CINDEX_LINKAGE
3923CXString clang_TParamCommandComment_getParamName(CXComment Comment);
3924
3925/**
3926 * \param Comment a \c CXComment_TParamCommand AST node.
3927 *
3928 * \returns non-zero if the parameter that this AST node represents was found
3929 * in the template parameter list and
3930 * \c clang_TParamCommandComment_getDepth and
3931 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
3932 * value.
3933 */
3934CINDEX_LINKAGE
3935unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
3936
3937/**
3938 * \param Comment a \c CXComment_TParamCommand AST node.
3939 *
3940 * \returns zero-based nesting depth of this parameter in the template parameter list.
3941 *
3942 * For example,
3943 * \verbatim
3944 * template<typename C, template<typename T> class TT>
3945 * void test(TT<int> aaa);
3946 * \endverbatim
3947 * for C and TT nesting depth is 0,
3948 * for T nesting depth is 1.
3949 */
3950CINDEX_LINKAGE
3951unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
3952
3953/**
3954 * \param Comment a \c CXComment_TParamCommand AST node.
3955 *
3956 * \returns zero-based parameter index in the template parameter list at a
3957 * given nesting depth.
3958 *
3959 * For example,
3960 * \verbatim
3961 * template<typename C, template<typename T> class TT>
3962 * void test(TT<int> aaa);
3963 * \endverbatim
3964 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
3965 * at depth 0 C's index is 0, TT's index is 1.
3966 *
3967 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
3968 * at depth 0 T's index is 1 (same as TT's),
3969 * at depth 1 T's index is 0.
3970 */
3971CINDEX_LINKAGE
3972unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
3973
3974/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003975 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
3976 *
3977 * \returns text contained in the AST node.
3978 */
3979CINDEX_LINKAGE
3980CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
3981
3982/**
3983 * \param Comment a \c CXComment_VerbatimLine AST node.
3984 *
3985 * \returns text contained in the AST node.
3986 */
3987CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
3988
3989/**
3990 * \brief Convert an HTML tag AST node to string.
3991 *
3992 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3993 * node.
3994 *
3995 * \returns string containing an HTML tag.
3996 */
3997CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
3998
3999/**
4000 * \brief Convert a given full parsed comment to an HTML fragment.
4001 *
4002 * Specific details of HTML layout are subject to change. Don't try to parse
4003 * this HTML back into an AST, use other APIs instead.
4004 *
4005 * Currently the following CSS classes are used:
4006 * \li "para-brief" for \\brief paragraph and equivalent commands;
4007 * \li "para-returns" for \\returns paragraph and equivalent commands;
4008 * \li "word-returns" for the "Returns" word in \\returns paragraph.
4009 *
Dmitri Gribenko3e63d332012-07-21 01:47:43 +00004010 * Function argument documentation is rendered as a \<dl\> list with arguments
4011 * sorted in function prototype order. CSS classes used:
4012 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
4013 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
4014 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
4015 * parameter index is invalid.
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00004016 *
Dmitri Gribenko96b09862012-07-31 22:37:06 +00004017 * Template parameter documentation is rendered as a \<dl\> list with
4018 * parameters sorted in template parameter list order. CSS classes used:
4019 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
4020 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko6a425522012-08-01 23:47:30 +00004021 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko96b09862012-07-31 22:37:06 +00004022 * names inside template template parameters;
4023 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
4024 * parameter position is invalid.
4025 *
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00004026 * \param Comment a \c CXComment_FullComment AST node.
4027 *
4028 * \returns string containing an HTML fragment.
4029 */
4030CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
4031
4032/**
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00004033 * \brief Convert a given full parsed comment to an XML document.
4034 *
4035 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
4036 * inside clang source tree.
4037 *
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00004038 * \param Comment a \c CXComment_FullComment AST node.
4039 *
4040 * \returns string containing an XML document.
4041 */
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00004042CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00004043
4044/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004045 * @}
4046 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004047
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004048/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00004049 * \defgroup CINDEX_CPP C++ AST introspection
4050 *
4051 * The routines in this group provide access information in the ASTs specific
4052 * to C++ language features.
4053 *
4054 * @{
4055 */
4056
4057/**
Dmitri Gribenkoc965f762013-05-17 18:38:35 +00004058 * \brief Determine if a C++ member function or member function template is
4059 * pure virtual.
4060 */
4061CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4062
4063/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00004064 * \brief Determine if a C++ member function or member function template is
4065 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00004066 */
4067CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4068
4069/**
Douglas Gregor211924b2011-05-12 15:17:24 +00004070 * \brief Determine if a C++ member function or member function template is
4071 * explicitly declared 'virtual' or if it overrides a virtual method from
4072 * one of the base classes.
4073 */
4074CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4075
4076/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00004077 * \brief Given a cursor that represents a template, determine
4078 * the cursor kind of the specializations would be generated by instantiating
4079 * the template.
4080 *
4081 * This routine can be used to determine what flavor of function template,
4082 * class template, or class template partial specialization is stored in the
4083 * cursor. For example, it can describe whether a class template cursor is
4084 * declared with "struct", "class" or "union".
4085 *
4086 * \param C The cursor to query. This cursor should represent a template
4087 * declaration.
4088 *
4089 * \returns The cursor kind of the specializations that would be generated
4090 * by instantiating the template \p C. If \p C is not a template, returns
4091 * \c CXCursor_NoDeclFound.
4092 */
4093CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4094
4095/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00004096 * \brief Given a cursor that may represent a specialization or instantiation
4097 * of a template, retrieve the cursor that represents the template that it
4098 * specializes or from which it was instantiated.
4099 *
4100 * This routine determines the template involved both for explicit
4101 * specializations of templates and for implicit instantiations of the template,
4102 * both of which are referred to as "specializations". For a class template
4103 * specialization (e.g., \c std::vector<bool>), this routine will return
4104 * either the primary template (\c std::vector) or, if the specialization was
4105 * instantiated from a class template partial specialization, the class template
4106 * partial specialization. For a class template partial specialization and a
4107 * function template specialization (including instantiations), this
4108 * this routine will return the specialized template.
4109 *
4110 * For members of a class template (e.g., member functions, member classes, or
4111 * static data members), returns the specialized or instantiated member.
4112 * Although not strictly "templates" in the C++ language, members of class
4113 * templates have the same notions of specializations and instantiations that
4114 * templates do, so this routine treats them similarly.
4115 *
4116 * \param C A cursor that may be a specialization of a template or a member
4117 * of a template.
4118 *
4119 * \returns If the given cursor is a specialization or instantiation of a
4120 * template or a member thereof, the template or member that it specializes or
4121 * from which it was instantiated. Otherwise, returns a NULL cursor.
4122 */
4123CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00004124
4125/**
4126 * \brief Given a cursor that references something else, return the source range
4127 * covering that reference.
4128 *
4129 * \param C A cursor pointing to a member reference, a declaration reference, or
4130 * an operator call.
4131 * \param NameFlags A bitset with three independent flags:
4132 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4133 * CXNameRange_WantSinglePiece.
4134 * \param PieceIndex For contiguous names or when passing the flag
4135 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4136 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer48d798c2012-06-02 10:20:41 +00004137 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregor430d7a12011-07-25 17:48:11 +00004138 * pieces of the name. See also CXNameRange_WantSinglePiece.
4139 *
4140 * \returns The piece of the name pointed to by the given cursor. If there is no
4141 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4142 */
Francois Pichet48a8d142011-07-25 22:00:44 +00004143CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4144 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00004145 unsigned PieceIndex);
4146
4147enum CXNameRefFlags {
4148 /**
4149 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4150 * range.
4151 */
4152 CXNameRange_WantQualifier = 0x1,
4153
4154 /**
James Dennett7eee0182012-06-15 05:41:51 +00004155 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4156 * in the range.
Douglas Gregor430d7a12011-07-25 17:48:11 +00004157 */
4158 CXNameRange_WantTemplateArgs = 0x2,
4159
4160 /**
4161 * \brief If the name is non-contiguous, return the full spanning range.
4162 *
4163 * Non-contiguous names occur in Objective-C when a selector with two or more
4164 * parameters is used, or in C++ when using an operator:
4165 * \code
4166 * [object doSomething:here withValue:there]; // ObjC
4167 * return some_vector[1]; // C++
4168 * \endcode
4169 */
4170 CXNameRange_WantSinglePiece = 0x4
4171};
Douglas Gregore0329ac2010-09-02 00:07:54 +00004172
4173/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00004174 * @}
4175 */
4176
4177/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004178 * \defgroup CINDEX_LEX Token extraction and manipulation
4179 *
4180 * The routines in this group provide access to the tokens within a
4181 * translation unit, along with a semantic mapping of those tokens to
4182 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004183 *
4184 * @{
4185 */
4186
4187/**
4188 * \brief Describes a kind of token.
4189 */
4190typedef enum CXTokenKind {
4191 /**
4192 * \brief A token that contains some kind of punctuation.
4193 */
4194 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004195
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004196 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004197 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004198 */
4199 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004200
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004201 /**
4202 * \brief An identifier (that is not a keyword).
4203 */
4204 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004205
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004206 /**
4207 * \brief A numeric, string, or character literal.
4208 */
4209 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004210
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004211 /**
4212 * \brief A comment.
4213 */
4214 CXToken_Comment
4215} CXTokenKind;
4216
4217/**
4218 * \brief Describes a single preprocessing token.
4219 */
4220typedef struct {
4221 unsigned int_data[4];
4222 void *ptr_data;
4223} CXToken;
4224
4225/**
4226 * \brief Determine the kind of the given token.
4227 */
4228CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004229
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004230/**
4231 * \brief Determine the spelling of the given token.
4232 *
4233 * The spelling of a token is the textual representation of that token, e.g.,
4234 * the text of an identifier or keyword.
4235 */
4236CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004237
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004238/**
4239 * \brief Retrieve the source location of the given token.
4240 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004241CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004242 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004243
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004244/**
4245 * \brief Retrieve a source range that covers the given token.
4246 */
4247CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4248
4249/**
4250 * \brief Tokenize the source code described by the given range into raw
4251 * lexical tokens.
4252 *
4253 * \param TU the translation unit whose text is being tokenized.
4254 *
4255 * \param Range the source range in which text should be tokenized. All of the
4256 * tokens produced by tokenization will fall within this source range,
4257 *
4258 * \param Tokens this pointer will be set to point to the array of tokens
4259 * that occur within the given source range. The returned pointer must be
4260 * freed with clang_disposeTokens() before the translation unit is destroyed.
4261 *
4262 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4263 * array.
4264 *
4265 */
4266CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4267 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004268
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004269/**
4270 * \brief Annotate the given set of tokens by providing cursors for each token
4271 * that can be mapped to a specific entity within the abstract syntax tree.
4272 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004273 * This token-annotation routine is equivalent to invoking
4274 * clang_getCursor() for the source locations of each of the
4275 * tokens. The cursors provided are filtered, so that only those
4276 * cursors that have a direct correspondence to the token are
4277 * accepted. For example, given a function call \c f(x),
4278 * clang_getCursor() would provide the following cursors:
4279 *
4280 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4281 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4282 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4283 *
4284 * Only the first and last of these cursors will occur within the
4285 * annotate, since the tokens "f" and "x' directly refer to a function
4286 * and a variable, respectively, but the parentheses are just a small
4287 * part of the full syntax of the function call expression, which is
4288 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004289 *
4290 * \param TU the translation unit that owns the given tokens.
4291 *
4292 * \param Tokens the set of tokens to annotate.
4293 *
4294 * \param NumTokens the number of tokens in \p Tokens.
4295 *
4296 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4297 * replaced with the cursors corresponding to each token.
4298 */
4299CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4300 CXToken *Tokens, unsigned NumTokens,
4301 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004302
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004303/**
4304 * \brief Free the given set of tokens.
4305 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004306CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004307 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004308
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004309/**
4310 * @}
4311 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004312
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004313/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004314 * \defgroup CINDEX_DEBUG Debugging facilities
4315 *
4316 * These routines are used for testing and debugging, only, and should not
4317 * be relied upon.
4318 *
4319 * @{
4320 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004321
Steve Naroff4ade6d62009-09-23 17:52:52 +00004322/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00004323CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004324CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4325 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00004326 const char **endBuf,
4327 unsigned *startLine,
4328 unsigned *startColumn,
4329 unsigned *endLine,
4330 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00004331CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00004332CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4333 unsigned stack_size);
4334
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004335/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004336 * @}
4337 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004338
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004339/**
4340 * \defgroup CINDEX_CODE_COMPLET Code completion
4341 *
4342 * Code completion involves taking an (incomplete) source file, along with
4343 * knowledge of where the user is actively editing that file, and suggesting
4344 * syntactically- and semantically-valid constructs that the user might want to
4345 * use at that particular point in the source code. These data structures and
4346 * routines provide support for code completion.
4347 *
4348 * @{
4349 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004350
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004351/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004352 * \brief A semantic string that describes a code-completion result.
4353 *
4354 * A semantic string that describes the formatting of a code-completion
4355 * result as a single "template" of text that should be inserted into the
4356 * source buffer when a particular code-completion result is selected.
4357 * Each semantic string is made up of some number of "chunks", each of which
4358 * contains some text along with a description of what that text means, e.g.,
4359 * the name of the entity being referenced, whether the text chunk is part of
4360 * the template, or whether it is a "placeholder" that the user should replace
4361 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004362 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004363 */
4364typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004365
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004366/**
4367 * \brief A single result of code completion.
4368 */
4369typedef struct {
4370 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004371 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004372 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004373 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004374 * *Decl cursor kinds), describing the entity that the completion is
4375 * referring to.
4376 *
4377 * \todo In the future, we would like to provide a full cursor, to allow
4378 * the client to extract additional information from declaration.
4379 */
4380 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004381
4382 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004383 * \brief The code-completion string that describes how to insert this
4384 * code-completion result into the editing buffer.
4385 */
4386 CXCompletionString CompletionString;
4387} CXCompletionResult;
4388
4389/**
4390 * \brief Describes a single piece of text within a code-completion string.
4391 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004392 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4393 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004394 * should be interpreted by the client or is another completion string.
4395 */
4396enum CXCompletionChunkKind {
4397 /**
4398 * \brief A code-completion string that describes "optional" text that
4399 * could be a part of the template (but is not required).
4400 *
4401 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004402 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004403 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4404 * describes an additional part of the template that is completely optional.
4405 * For example, optional chunks can be used to describe the placeholders for
4406 * arguments that match up with defaulted function parameters, e.g. given:
4407 *
4408 * \code
4409 * void f(int x, float y = 3.14, double z = 2.71828);
4410 * \endcode
4411 *
4412 * The code-completion string for this function would contain:
4413 * - a TypedText chunk for "f".
4414 * - a LeftParen chunk for "(".
4415 * - a Placeholder chunk for "int x"
4416 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4417 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00004418 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004419 * - an Optional chunk containing the last defaulted argument:
4420 * - a Comma chunk for ","
4421 * - a Placeholder chunk for "double z"
4422 * - a RightParen chunk for ")"
4423 *
Daniel Dunbar71570182010-02-17 08:07:44 +00004424 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004425 * - Completely ignore optional chunks, in which case the template for the
4426 * function "f" would only include the first parameter ("int x").
4427 * - Fully expand all optional chunks, in which case the template for the
4428 * function "f" would have all of the parameters.
4429 */
4430 CXCompletionChunk_Optional,
4431 /**
4432 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004433 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004434 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004435 * There will be exactly one "typed text" chunk in a semantic string, which
4436 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004437 * declaration that could be used at the current code point. Clients are
4438 * expected to filter the code-completion results based on the text in this
4439 * chunk.
4440 */
4441 CXCompletionChunk_TypedText,
4442 /**
4443 * \brief Text that should be inserted as part of a code-completion result.
4444 *
4445 * A "text" chunk represents text that is part of the template to be
4446 * inserted into user code should this particular code-completion result
4447 * be selected.
4448 */
4449 CXCompletionChunk_Text,
4450 /**
4451 * \brief Placeholder text that should be replaced by the user.
4452 *
4453 * A "placeholder" chunk marks a place where the user should insert text
4454 * into the code-completion template. For example, placeholders might mark
4455 * the function parameters for a function declaration, to indicate that the
4456 * user should provide arguments for each of those parameters. The actual
4457 * text in a placeholder is a suggestion for the text to display before
4458 * the user replaces the placeholder with real code.
4459 */
4460 CXCompletionChunk_Placeholder,
4461 /**
4462 * \brief Informative text that should be displayed but never inserted as
4463 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004464 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004465 * An "informative" chunk contains annotations that can be displayed to
4466 * help the user decide whether a particular code-completion result is the
4467 * right option, but which is not part of the actual template to be inserted
4468 * by code completion.
4469 */
4470 CXCompletionChunk_Informative,
4471 /**
4472 * \brief Text that describes the current parameter when code-completion is
4473 * referring to function call, message send, or template specialization.
4474 *
4475 * A "current parameter" chunk occurs when code-completion is providing
4476 * information about a parameter corresponding to the argument at the
4477 * code-completion point. For example, given a function
4478 *
4479 * \code
4480 * int add(int x, int y);
4481 * \endcode
4482 *
4483 * and the source code \c add(, where the code-completion point is after the
4484 * "(", the code-completion string will contain a "current parameter" chunk
4485 * for "int x", indicating that the current argument will initialize that
4486 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004487 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004488 * "current paremeter" chunk to "int y".
4489 */
4490 CXCompletionChunk_CurrentParameter,
4491 /**
4492 * \brief A left parenthesis ('('), used to initiate a function call or
4493 * signal the beginning of a function parameter list.
4494 */
4495 CXCompletionChunk_LeftParen,
4496 /**
4497 * \brief A right parenthesis (')'), used to finish a function call or
4498 * signal the end of a function parameter list.
4499 */
4500 CXCompletionChunk_RightParen,
4501 /**
4502 * \brief A left bracket ('[').
4503 */
4504 CXCompletionChunk_LeftBracket,
4505 /**
4506 * \brief A right bracket (']').
4507 */
4508 CXCompletionChunk_RightBracket,
4509 /**
4510 * \brief A left brace ('{').
4511 */
4512 CXCompletionChunk_LeftBrace,
4513 /**
4514 * \brief A right brace ('}').
4515 */
4516 CXCompletionChunk_RightBrace,
4517 /**
4518 * \brief A left angle bracket ('<').
4519 */
4520 CXCompletionChunk_LeftAngle,
4521 /**
4522 * \brief A right angle bracket ('>').
4523 */
4524 CXCompletionChunk_RightAngle,
4525 /**
4526 * \brief A comma separator (',').
4527 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004528 CXCompletionChunk_Comma,
4529 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004530 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004531 *
4532 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004533 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004534 * expression using the given completion string would have.
4535 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00004536 CXCompletionChunk_ResultType,
4537 /**
4538 * \brief A colon (':').
4539 */
4540 CXCompletionChunk_Colon,
4541 /**
4542 * \brief A semicolon (';').
4543 */
4544 CXCompletionChunk_SemiColon,
4545 /**
4546 * \brief An '=' sign.
4547 */
4548 CXCompletionChunk_Equal,
4549 /**
4550 * Horizontal space (' ').
4551 */
4552 CXCompletionChunk_HorizontalSpace,
4553 /**
4554 * Vertical space ('\n'), after which it is generally a good idea to
4555 * perform indentation.
4556 */
4557 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004558};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004559
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004560/**
4561 * \brief Determine the kind of a particular chunk within a completion string.
4562 *
4563 * \param completion_string the completion string to query.
4564 *
4565 * \param chunk_number the 0-based index of the chunk in the completion string.
4566 *
4567 * \returns the kind of the chunk at the index \c chunk_number.
4568 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004569CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004570clang_getCompletionChunkKind(CXCompletionString completion_string,
4571 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004572
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004573/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004574 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004575 * completion string.
4576 *
4577 * \param completion_string the completion string to query.
4578 *
4579 * \param chunk_number the 0-based index of the chunk in the completion string.
4580 *
4581 * \returns the text associated with the chunk at index \c chunk_number.
4582 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00004583CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004584clang_getCompletionChunkText(CXCompletionString completion_string,
4585 unsigned chunk_number);
4586
4587/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004588 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004589 * within a completion string.
4590 *
4591 * \param completion_string the completion string to query.
4592 *
4593 * \param chunk_number the 0-based index of the chunk in the completion string.
4594 *
4595 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00004596 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004597 */
4598CINDEX_LINKAGE CXCompletionString
4599clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4600 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004601
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004602/**
4603 * \brief Retrieve the number of chunks in the given code-completion string.
4604 */
4605CINDEX_LINKAGE unsigned
4606clang_getNumCompletionChunks(CXCompletionString completion_string);
4607
4608/**
Douglas Gregor12e13132010-05-26 22:00:08 +00004609 * \brief Determine the priority of this code completion.
4610 *
4611 * The priority of a code completion indicates how likely it is that this
4612 * particular completion is the completion that the user will select. The
4613 * priority is selected by various internal heuristics.
4614 *
4615 * \param completion_string The completion string to query.
4616 *
4617 * \returns The priority of this completion string. Smaller values indicate
4618 * higher-priority (more likely) completions.
4619 */
4620CINDEX_LINKAGE unsigned
4621clang_getCompletionPriority(CXCompletionString completion_string);
4622
4623/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00004624 * \brief Determine the availability of the entity that this code-completion
4625 * string refers to.
4626 *
4627 * \param completion_string The completion string to query.
4628 *
4629 * \returns The availability of the completion string.
4630 */
4631CINDEX_LINKAGE enum CXAvailabilityKind
4632clang_getCompletionAvailability(CXCompletionString completion_string);
4633
4634/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00004635 * \brief Retrieve the number of annotations associated with the given
4636 * completion string.
4637 *
4638 * \param completion_string the completion string to query.
4639 *
4640 * \returns the number of annotations associated with the given completion
4641 * string.
4642 */
4643CINDEX_LINKAGE unsigned
4644clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4645
4646/**
4647 * \brief Retrieve the annotation associated with the given completion string.
4648 *
4649 * \param completion_string the completion string to query.
4650 *
4651 * \param annotation_number the 0-based index of the annotation of the
4652 * completion string.
4653 *
4654 * \returns annotation string associated with the completion at index
4655 * \c annotation_number, or a NULL string if that annotation is not available.
4656 */
4657CINDEX_LINKAGE CXString
4658clang_getCompletionAnnotation(CXCompletionString completion_string,
4659 unsigned annotation_number);
4660
4661/**
Douglas Gregorba103062012-03-27 23:34:16 +00004662 * \brief Retrieve the parent context of the given completion string.
4663 *
4664 * The parent context of a completion string is the semantic parent of
4665 * the declaration (if any) that the code completion represents. For example,
4666 * a code completion for an Objective-C method would have the method's class
4667 * or protocol as its context.
4668 *
4669 * \param completion_string The code completion string whose parent is
4670 * being queried.
4671 *
Argyrios Kyrtzidis526d2442012-09-26 16:39:56 +00004672 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregorba103062012-03-27 23:34:16 +00004673 *
James Dennett7eee0182012-06-15 05:41:51 +00004674 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregorba103062012-03-27 23:34:16 +00004675 * the completion string represents a method in the NSObject class.
4676 */
4677CINDEX_LINKAGE CXString
4678clang_getCompletionParent(CXCompletionString completion_string,
4679 enum CXCursorKind *kind);
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00004680
4681/**
4682 * \brief Retrieve the brief documentation comment attached to the declaration
4683 * that corresponds to the given completion string.
4684 */
4685CINDEX_LINKAGE CXString
4686clang_getCompletionBriefComment(CXCompletionString completion_string);
4687
Douglas Gregorba103062012-03-27 23:34:16 +00004688/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00004689 * \brief Retrieve a completion string for an arbitrary declaration or macro
4690 * definition cursor.
4691 *
4692 * \param cursor The cursor to query.
4693 *
4694 * \returns A non-context-sensitive completion string for declaration and macro
4695 * definition cursors, or NULL for other kinds of cursors.
4696 */
4697CINDEX_LINKAGE CXCompletionString
4698clang_getCursorCompletionString(CXCursor cursor);
4699
4700/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004701 * \brief Contains the results of code-completion.
4702 *
4703 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00004704 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00004705 * \c clang_disposeCodeCompleteResults.
4706 */
4707typedef struct {
4708 /**
4709 * \brief The code-completion results.
4710 */
4711 CXCompletionResult *Results;
4712
4713 /**
4714 * \brief The number of code-completion results stored in the
4715 * \c Results array.
4716 */
4717 unsigned NumResults;
4718} CXCodeCompleteResults;
4719
4720/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00004721 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4722 * modify its behavior.
4723 *
4724 * The enumerators in this enumeration can be bitwise-OR'd together to
4725 * provide multiple options to \c clang_codeCompleteAt().
4726 */
4727enum CXCodeComplete_Flags {
4728 /**
4729 * \brief Whether to include macros within the set of code
4730 * completions returned.
4731 */
4732 CXCodeComplete_IncludeMacros = 0x01,
4733
4734 /**
4735 * \brief Whether to include code patterns for language constructs
4736 * within the set of code completions, e.g., for loops.
4737 */
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00004738 CXCodeComplete_IncludeCodePatterns = 0x02,
4739
4740 /**
4741 * \brief Whether to include brief documentation within the set of code
4742 * completions returned.
4743 */
4744 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorcee235c2010-08-05 09:09:23 +00004745};
4746
4747/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004748 * \brief Bits that represent the context under which completion is occurring.
4749 *
4750 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4751 * contexts are occurring simultaneously.
4752 */
4753enum CXCompletionContext {
4754 /**
4755 * \brief The context for completions is unexposed, as only Clang results
4756 * should be included. (This is equivalent to having no context bits set.)
4757 */
4758 CXCompletionContext_Unexposed = 0,
4759
4760 /**
4761 * \brief Completions for any possible type should be included in the results.
4762 */
4763 CXCompletionContext_AnyType = 1 << 0,
4764
4765 /**
4766 * \brief Completions for any possible value (variables, function calls, etc.)
4767 * should be included in the results.
4768 */
4769 CXCompletionContext_AnyValue = 1 << 1,
4770 /**
4771 * \brief Completions for values that resolve to an Objective-C object should
4772 * be included in the results.
4773 */
4774 CXCompletionContext_ObjCObjectValue = 1 << 2,
4775 /**
4776 * \brief Completions for values that resolve to an Objective-C selector
4777 * should be included in the results.
4778 */
4779 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4780 /**
4781 * \brief Completions for values that resolve to a C++ class type should be
4782 * included in the results.
4783 */
4784 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4785
4786 /**
4787 * \brief Completions for fields of the member being accessed using the dot
4788 * operator should be included in the results.
4789 */
4790 CXCompletionContext_DotMemberAccess = 1 << 5,
4791 /**
4792 * \brief Completions for fields of the member being accessed using the arrow
4793 * operator should be included in the results.
4794 */
4795 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4796 /**
4797 * \brief Completions for properties of the Objective-C object being accessed
4798 * using the dot operator should be included in the results.
4799 */
4800 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4801
4802 /**
4803 * \brief Completions for enum tags should be included in the results.
4804 */
4805 CXCompletionContext_EnumTag = 1 << 8,
4806 /**
4807 * \brief Completions for union tags should be included in the results.
4808 */
4809 CXCompletionContext_UnionTag = 1 << 9,
4810 /**
4811 * \brief Completions for struct tags should be included in the results.
4812 */
4813 CXCompletionContext_StructTag = 1 << 10,
4814
4815 /**
4816 * \brief Completions for C++ class names should be included in the results.
4817 */
4818 CXCompletionContext_ClassTag = 1 << 11,
4819 /**
4820 * \brief Completions for C++ namespaces and namespace aliases should be
4821 * included in the results.
4822 */
4823 CXCompletionContext_Namespace = 1 << 12,
4824 /**
4825 * \brief Completions for C++ nested name specifiers should be included in
4826 * the results.
4827 */
4828 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4829
4830 /**
4831 * \brief Completions for Objective-C interfaces (classes) should be included
4832 * in the results.
4833 */
4834 CXCompletionContext_ObjCInterface = 1 << 14,
4835 /**
4836 * \brief Completions for Objective-C protocols should be included in
4837 * the results.
4838 */
4839 CXCompletionContext_ObjCProtocol = 1 << 15,
4840 /**
4841 * \brief Completions for Objective-C categories should be included in
4842 * the results.
4843 */
4844 CXCompletionContext_ObjCCategory = 1 << 16,
4845 /**
4846 * \brief Completions for Objective-C instance messages should be included
4847 * in the results.
4848 */
4849 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4850 /**
4851 * \brief Completions for Objective-C class messages should be included in
4852 * the results.
4853 */
4854 CXCompletionContext_ObjCClassMessage = 1 << 18,
4855 /**
4856 * \brief Completions for Objective-C selector names should be included in
4857 * the results.
4858 */
4859 CXCompletionContext_ObjCSelectorName = 1 << 19,
4860
4861 /**
4862 * \brief Completions for preprocessor macro names should be included in
4863 * the results.
4864 */
4865 CXCompletionContext_MacroName = 1 << 20,
4866
4867 /**
4868 * \brief Natural language completions should be included in the results.
4869 */
4870 CXCompletionContext_NaturalLanguage = 1 << 21,
4871
4872 /**
4873 * \brief The current context is unknown, so set all contexts.
4874 */
4875 CXCompletionContext_Unknown = ((1 << 22) - 1)
4876};
4877
4878/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00004879 * \brief Returns a default set of code-completion options that can be
4880 * passed to\c clang_codeCompleteAt().
4881 */
4882CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4883
4884/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004885 * \brief Perform code completion at a given location in a translation unit.
4886 *
4887 * This function performs code completion at a particular file, line, and
4888 * column within source code, providing results that suggest potential
4889 * code snippets based on the context of the completion. The basic model
4890 * for code completion is that Clang will parse a complete source file,
4891 * performing syntax checking up to the location where code-completion has
4892 * been requested. At that point, a special code-completion token is passed
4893 * to the parser, which recognizes this token and determines, based on the
4894 * current location in the C/Objective-C/C++ grammar and the state of
4895 * semantic analysis, what completions to provide. These completions are
4896 * returned via a new \c CXCodeCompleteResults structure.
4897 *
4898 * Code completion itself is meant to be triggered by the client when the
4899 * user types punctuation characters or whitespace, at which point the
4900 * code-completion location will coincide with the cursor. For example, if \c p
4901 * is a pointer, code-completion might be triggered after the "-" and then
4902 * after the ">" in \c p->. When the code-completion location is afer the ">",
4903 * the completion results will provide, e.g., the members of the struct that
4904 * "p" points to. The client is responsible for placing the cursor at the
4905 * beginning of the token currently being typed, then filtering the results
4906 * based on the contents of the token. For example, when code-completing for
4907 * the expression \c p->get, the client should provide the location just after
4908 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4909 * client can filter the results based on the current token text ("get"), only
4910 * showing those results that start with "get". The intent of this interface
4911 * is to separate the relatively high-latency acquisition of code-completion
4912 * results from the filtering of results on a per-character basis, which must
4913 * have a lower latency.
4914 *
4915 * \param TU The translation unit in which code-completion should
4916 * occur. The source files for this translation unit need not be
4917 * completely up-to-date (and the contents of those source files may
4918 * be overridden via \p unsaved_files). Cursors referring into the
4919 * translation unit may be invalidated by this invocation.
4920 *
4921 * \param complete_filename The name of the source file where code
4922 * completion should be performed. This filename may be any file
4923 * included in the translation unit.
4924 *
4925 * \param complete_line The line at which code-completion should occur.
4926 *
4927 * \param complete_column The column at which code-completion should occur.
4928 * Note that the column should point just after the syntactic construct that
4929 * initiated code completion, and not in the middle of a lexical token.
4930 *
4931 * \param unsaved_files the Tiles that have not yet been saved to disk
4932 * but may be required for parsing or code completion, including the
4933 * contents of those files. The contents and name of these files (as
4934 * specified by CXUnsavedFile) are copied when necessary, so the
4935 * client only needs to guarantee their validity until the call to
4936 * this function returns.
4937 *
4938 * \param num_unsaved_files The number of unsaved file entries in \p
4939 * unsaved_files.
4940 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00004941 * \param options Extra options that control the behavior of code
4942 * completion, expressed as a bitwise OR of the enumerators of the
4943 * CXCodeComplete_Flags enumeration. The
4944 * \c clang_defaultCodeCompleteOptions() function returns a default set
4945 * of code-completion options.
4946 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004947 * \returns If successful, a new \c CXCodeCompleteResults structure
4948 * containing code-completion results, which should eventually be
4949 * freed with \c clang_disposeCodeCompleteResults(). If code
4950 * completion fails, returns NULL.
4951 */
4952CINDEX_LINKAGE
4953CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4954 const char *complete_filename,
4955 unsigned complete_line,
4956 unsigned complete_column,
4957 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00004958 unsigned num_unsaved_files,
4959 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004960
4961/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00004962 * \brief Sort the code-completion results in case-insensitive alphabetical
4963 * order.
4964 *
4965 * \param Results The set of results to sort.
4966 * \param NumResults The number of results in \p Results.
4967 */
4968CINDEX_LINKAGE
4969void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4970 unsigned NumResults);
4971
4972/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004973 * \brief Free the given set of code-completion results.
4974 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004975CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00004976void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00004977
Douglas Gregor20d416c2010-01-20 01:10:47 +00004978/**
Douglas Gregora88084b2010-02-18 18:08:43 +00004979 * \brief Determine the number of diagnostics produced prior to the
4980 * location where code completion was performed.
4981 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004982CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004983unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4984
4985/**
4986 * \brief Retrieve a diagnostic associated with the given code completion.
4987 *
James Dennett7eee0182012-06-15 05:41:51 +00004988 * \param Results the code completion results to query.
Douglas Gregora88084b2010-02-18 18:08:43 +00004989 * \param Index the zero-based diagnostic number to retrieve.
4990 *
4991 * \returns the requested diagnostic. This diagnostic must be freed
4992 * via a call to \c clang_disposeDiagnostic().
4993 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004994CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004995CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4996 unsigned Index);
4997
4998/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004999 * \brief Determines what compeltions are appropriate for the context
5000 * the given code completion.
5001 *
5002 * \param Results the code completion results to query
5003 *
5004 * \returns the kinds of completions that are appropriate for use
5005 * along with the given code completion results.
5006 */
5007CINDEX_LINKAGE
5008unsigned long long clang_codeCompleteGetContexts(
5009 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00005010
5011/**
5012 * \brief Returns the cursor kind for the container for the current code
5013 * completion context. The container is only guaranteed to be set for
5014 * contexts where a container exists (i.e. member accesses or Objective-C
5015 * message sends); if there is not a container, this function will return
5016 * CXCursor_InvalidCode.
5017 *
5018 * \param Results the code completion results to query
5019 *
5020 * \param IsIncomplete on return, this value will be false if Clang has complete
5021 * information about the container. If Clang does not have complete
5022 * information, this value will be true.
5023 *
5024 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5025 * container
5026 */
5027CINDEX_LINKAGE
5028enum CXCursorKind clang_codeCompleteGetContainerKind(
5029 CXCodeCompleteResults *Results,
5030 unsigned *IsIncomplete);
5031
5032/**
5033 * \brief Returns the USR for the container for the current code completion
5034 * context. If there is not a container for the current context, this
5035 * function will return the empty string.
5036 *
5037 * \param Results the code completion results to query
5038 *
5039 * \returns the USR for the container
5040 */
5041CINDEX_LINKAGE
5042CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00005043
Douglas Gregor0a47d692011-07-26 15:24:30 +00005044
5045/**
5046 * \brief Returns the currently-entered selector for an Objective-C message
5047 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5048 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5049 * CXCompletionContext_ObjCClassMessage.
5050 *
5051 * \param Results the code completion results to query
5052 *
5053 * \returns the selector (or partial selector) that has been entered thus far
5054 * for an Objective-C message send.
5055 */
5056CINDEX_LINKAGE
5057CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5058
Douglas Gregor3da626b2011-07-07 16:03:39 +00005059/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00005060 * @}
5061 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005062
5063
Ted Kremenek04bb7162010-01-22 22:44:15 +00005064/**
5065 * \defgroup CINDEX_MISC Miscellaneous utility functions
5066 *
5067 * @{
5068 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00005069
5070/**
5071 * \brief Return a version string, suitable for showing to a user, but not
5072 * intended to be parsed (the format is not guaranteed to be stable).
5073 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +00005074CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenek04bb7162010-01-22 22:44:15 +00005075
Ted Kremenekd2427dd2011-03-18 23:05:39 +00005076
5077/**
5078 * \brief Enable/disable crash recovery.
5079 *
James Dennett7eee0182012-06-15 05:41:51 +00005080 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5081 * value enables crash recovery, while 0 disables it.
Ted Kremenekd2427dd2011-03-18 23:05:39 +00005082 */
5083CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5084
Ted Kremenek16b55a72010-01-26 19:31:51 +00005085 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00005086 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00005087 * (used with clang_getInclusions()).
5088 *
5089 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett7eee0182012-06-15 05:41:51 +00005090 * file included (either at the top-level or by \#include directives) within
Ted Kremenek16b55a72010-01-26 19:31:51 +00005091 * a translation unit. The first argument is the file being included, and
5092 * the second and third arguments provide the inclusion stack. The
5093 * array is sorted in order of immediate inclusion. For example,
5094 * the first element refers to the location that included 'included_file'.
5095 */
5096typedef void (*CXInclusionVisitor)(CXFile included_file,
5097 CXSourceLocation* inclusion_stack,
5098 unsigned include_len,
5099 CXClientData client_data);
5100
5101/**
5102 * \brief Visit the set of preprocessor inclusions in a translation unit.
5103 * The visitor function is called with the provided data for every included
5104 * file. This does not include headers included by the PCH file (unless one
5105 * is inspecting the inclusions in the PCH file itself).
5106 */
5107CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5108 CXInclusionVisitor visitor,
5109 CXClientData client_data);
5110
5111/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00005112 * @}
5113 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005114
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00005115/** \defgroup CINDEX_REMAPPING Remapping functions
5116 *
5117 * @{
5118 */
5119
5120/**
5121 * \brief A remapping of original source files and their translated files.
5122 */
5123typedef void *CXRemapping;
5124
5125/**
5126 * \brief Retrieve a remapping.
5127 *
5128 * \param path the path that contains metadata about remappings.
5129 *
5130 * \returns the requested remapping. This remapping must be freed
5131 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5132 */
5133CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5134
5135/**
Ted Kremenek30660a82012-03-06 20:06:33 +00005136 * \brief Retrieve a remapping.
5137 *
5138 * \param filePaths pointer to an array of file paths containing remapping info.
5139 *
5140 * \param numFiles number of file paths.
5141 *
5142 * \returns the requested remapping. This remapping must be freed
5143 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5144 */
5145CINDEX_LINKAGE
5146CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5147 unsigned numFiles);
5148
5149/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00005150 * \brief Determine the number of remappings.
5151 */
5152CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5153
5154/**
5155 * \brief Get the original and the associated filename from the remapping.
5156 *
5157 * \param original If non-NULL, will be set to the original filename.
5158 *
5159 * \param transformed If non-NULL, will be set to the filename that the original
5160 * is associated with.
5161 */
5162CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5163 CXString *original, CXString *transformed);
5164
5165/**
5166 * \brief Dispose the remapping.
5167 */
5168CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5169
5170/**
5171 * @}
5172 */
5173
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005174/** \defgroup CINDEX_HIGH Higher level API functions
5175 *
5176 * @{
5177 */
5178
5179enum CXVisitorResult {
5180 CXVisit_Break,
5181 CXVisit_Continue
5182};
5183
5184typedef struct {
5185 void *context;
5186 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5187} CXCursorAndRangeVisitor;
5188
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005189typedef enum {
5190 /**
5191 * \brief Function returned successfully.
5192 */
5193 CXResult_Success = 0,
5194 /**
5195 * \brief One of the parameters was invalid for the function.
5196 */
5197 CXResult_Invalid = 1,
5198 /**
5199 * \brief The function was terminated by a callback (e.g. it returned
5200 * CXVisit_Break)
5201 */
5202 CXResult_VisitBreak = 2
5203
5204} CXResult;
5205
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005206/**
5207 * \brief Find references of a declaration in a specific file.
5208 *
5209 * \param cursor pointing to a declaration or a reference of one.
5210 *
5211 * \param file to search for references.
5212 *
5213 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5214 * each reference found.
5215 * The CXSourceRange will point inside the file; if the reference is inside
5216 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis389dc562013-03-08 20:42:33 +00005217 *
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005218 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005219 */
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005220CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5221 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005222
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005223/**
5224 * \brief Find #import/#include directives in a specific file.
5225 *
5226 * \param TU translation unit containing the file to query.
5227 *
5228 * \param file to search for #import/#include directives.
5229 *
5230 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5231 * each directive found.
Argyrios Kyrtzidis389dc562013-03-08 20:42:33 +00005232 *
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005233 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005234 */
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005235CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5236 CXFile file,
5237 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005238
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005239#ifdef __has_feature
5240# if __has_feature(blocks)
5241
5242typedef enum CXVisitorResult
5243 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5244
5245CINDEX_LINKAGE
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005246CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5247 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005248
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005249CINDEX_LINKAGE
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005250CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5251 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005252
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005253# endif
5254#endif
5255
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005256/**
5257 * \brief The client's data object that is associated with a CXFile.
5258 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005259typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005260
5261/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005262 * \brief The client's data object that is associated with a semantic entity.
5263 */
5264typedef void *CXIdxClientEntity;
5265
5266/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005267 * \brief The client's data object that is associated with a semantic container
5268 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005269 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005270typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005271
5272/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005273 * \brief The client's data object that is associated with an AST file (PCH
5274 * or module).
5275 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005276typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005277
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005278/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005279 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005280 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005281typedef struct {
5282 void *ptr_data[2];
5283 unsigned int_data;
5284} CXIdxLoc;
5285
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005286/**
James Dennett7eee0182012-06-15 05:41:51 +00005287 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005288 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005289typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005290 /**
James Dennett7eee0182012-06-15 05:41:51 +00005291 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005292 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005293 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005294 /**
James Dennett7eee0182012-06-15 05:41:51 +00005295 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005296 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005297 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005298 /**
James Dennett7eee0182012-06-15 05:41:51 +00005299 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005300 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005301 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005302 int isImport;
5303 int isAngled;
Argyrios Kyrtzidis8d7a24e2012-10-18 00:17:05 +00005304 /**
5305 * \brief Non-zero if the directive was automatically turned into a module
5306 * import.
5307 */
5308 int isModuleImport;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005309} CXIdxIncludedFileInfo;
5310
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005311/**
James Dennett7eee0182012-06-15 05:41:51 +00005312 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005313 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005314typedef struct {
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005315 /**
5316 * \brief Top level AST file containing the imported PCH, module or submodule.
5317 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005318 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005319 /**
Argyrios Kyrtzidis134d1e8a2012-10-05 00:22:40 +00005320 * \brief The imported module or NULL if the AST file is a PCH.
5321 */
5322 CXModule module;
5323 /**
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005324 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005325 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005326 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005327 /**
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005328 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidis134d1e8a2012-10-05 00:22:40 +00005329 * a module import. Applicable only for modules.
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005330 */
Argyrios Kyrtzidis37f2f522012-10-03 21:05:44 +00005331 int isImplicit;
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005332
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005333} CXIdxImportedASTFileInfo;
5334
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005335typedef enum {
5336 CXIdxEntity_Unexposed = 0,
5337 CXIdxEntity_Typedef = 1,
5338 CXIdxEntity_Function = 2,
5339 CXIdxEntity_Variable = 3,
5340 CXIdxEntity_Field = 4,
5341 CXIdxEntity_EnumConstant = 5,
5342
5343 CXIdxEntity_ObjCClass = 6,
5344 CXIdxEntity_ObjCProtocol = 7,
5345 CXIdxEntity_ObjCCategory = 8,
5346
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005347 CXIdxEntity_ObjCInstanceMethod = 9,
5348 CXIdxEntity_ObjCClassMethod = 10,
5349 CXIdxEntity_ObjCProperty = 11,
5350 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005351
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005352 CXIdxEntity_Enum = 13,
5353 CXIdxEntity_Struct = 14,
5354 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005355
5356 CXIdxEntity_CXXClass = 16,
5357 CXIdxEntity_CXXNamespace = 17,
5358 CXIdxEntity_CXXNamespaceAlias = 18,
5359 CXIdxEntity_CXXStaticVariable = 19,
5360 CXIdxEntity_CXXStaticMethod = 20,
5361 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matos17d35c32012-08-31 22:18:20 +00005362 CXIdxEntity_CXXConstructor = 22,
5363 CXIdxEntity_CXXDestructor = 23,
5364 CXIdxEntity_CXXConversionFunction = 24,
5365 CXIdxEntity_CXXTypeAlias = 25,
5366 CXIdxEntity_CXXInterface = 26
5367
5368} CXIdxEntityKind;
5369
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00005370typedef enum {
5371 CXIdxEntityLang_None = 0,
5372 CXIdxEntityLang_C = 1,
5373 CXIdxEntityLang_ObjC = 2,
5374 CXIdxEntityLang_CXX = 3
5375} CXIdxEntityLanguage;
5376
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005377/**
5378 * \brief Extra C++ template information for an entity. This can apply to:
5379 * CXIdxEntity_Function
5380 * CXIdxEntity_CXXClass
5381 * CXIdxEntity_CXXStaticMethod
5382 * CXIdxEntity_CXXInstanceMethod
5383 * CXIdxEntity_CXXConstructor
5384 * CXIdxEntity_CXXConversionFunction
5385 * CXIdxEntity_CXXTypeAlias
5386 */
5387typedef enum {
5388 CXIdxEntity_NonTemplate = 0,
5389 CXIdxEntity_Template = 1,
5390 CXIdxEntity_TemplatePartialSpecialization = 2,
5391 CXIdxEntity_TemplateSpecialization = 3
5392} CXIdxEntityCXXTemplateKind;
5393
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005394typedef enum {
5395 CXIdxAttr_Unexposed = 0,
5396 CXIdxAttr_IBAction = 1,
5397 CXIdxAttr_IBOutlet = 2,
5398 CXIdxAttr_IBOutletCollection = 3
5399} CXIdxAttrKind;
5400
5401typedef struct {
5402 CXIdxAttrKind kind;
5403 CXCursor cursor;
5404 CXIdxLoc loc;
5405} CXIdxAttrInfo;
5406
5407typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00005408 CXIdxEntityKind kind;
5409 CXIdxEntityCXXTemplateKind templateKind;
5410 CXIdxEntityLanguage lang;
5411 const char *name;
5412 const char *USR;
5413 CXCursor cursor;
5414 const CXIdxAttrInfo *const *attributes;
5415 unsigned numAttributes;
5416} CXIdxEntityInfo;
5417
5418typedef struct {
5419 CXCursor cursor;
5420} CXIdxContainerInfo;
5421
5422typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005423 const CXIdxAttrInfo *attrInfo;
5424 const CXIdxEntityInfo *objcClass;
5425 CXCursor classCursor;
5426 CXIdxLoc classLoc;
5427} CXIdxIBOutletCollectionAttrInfo;
5428
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005429typedef enum {
5430 CXIdxDeclFlag_Skipped = 0x1
5431} CXIdxDeclInfoFlags;
5432
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005433typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005434 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005435 CXCursor cursor;
5436 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005437 const CXIdxContainerInfo *semanticContainer;
5438 /**
James Dennett7eee0182012-06-15 05:41:51 +00005439 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005440 * cases like out-of-line C++ member functions.
5441 */
5442 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005443 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005444 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005445 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005446 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005447 /**
5448 * \brief Whether the declaration exists in code or was created implicitly
5449 * by the compiler, e.g. implicit objc methods for properties.
5450 */
5451 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005452 const CXIdxAttrInfo *const *attributes;
5453 unsigned numAttributes;
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005454
5455 unsigned flags;
5456
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005457} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005458
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005459typedef enum {
5460 CXIdxObjCContainer_ForwardRef = 0,
5461 CXIdxObjCContainer_Interface = 1,
5462 CXIdxObjCContainer_Implementation = 2
5463} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005464
5465typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005466 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005467 CXIdxObjCContainerKind kind;
5468} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005469
5470typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005471 const CXIdxEntityInfo *base;
5472 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005473 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005474} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005475
5476typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005477 const CXIdxEntityInfo *protocol;
5478 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005479 CXIdxLoc loc;
5480} CXIdxObjCProtocolRefInfo;
5481
5482typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005483 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005484 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005485} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005486
5487typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005488 const CXIdxObjCContainerDeclInfo *containerInfo;
5489 const CXIdxBaseClassInfo *superInfo;
5490 const CXIdxObjCProtocolRefListInfo *protocols;
5491} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005492
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005493typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00005494 const CXIdxObjCContainerDeclInfo *containerInfo;
5495 const CXIdxEntityInfo *objcClass;
5496 CXCursor classCursor;
5497 CXIdxLoc classLoc;
5498 const CXIdxObjCProtocolRefListInfo *protocols;
5499} CXIdxObjCCategoryDeclInfo;
5500
5501typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005502 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00005503 const CXIdxEntityInfo *getter;
5504 const CXIdxEntityInfo *setter;
5505} CXIdxObjCPropertyDeclInfo;
5506
5507typedef struct {
5508 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005509 const CXIdxBaseClassInfo *const *bases;
5510 unsigned numBases;
5511} CXIdxCXXClassDeclInfo;
5512
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005513/**
James Dennett7eee0182012-06-15 05:41:51 +00005514 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005515 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005516typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005517 /**
5518 * \brief The entity is referenced directly in user's code.
5519 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005520 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005521 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005522 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5523 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005524 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005525 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005526} CXIdxEntityRefKind;
5527
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005528/**
James Dennett7eee0182012-06-15 05:41:51 +00005529 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005530 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005531typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005532 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005533 /**
5534 * \brief Reference cursor.
5535 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005536 CXCursor cursor;
5537 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005538 /**
5539 * \brief The entity that gets referenced.
5540 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005541 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005542 /**
5543 * \brief Immediate "parent" of the reference. For example:
5544 *
5545 * \code
5546 * Foo *var;
5547 * \endcode
5548 *
5549 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00005550 * For references inside statement bodies of functions/methods,
5551 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005552 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005553 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005554 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00005555 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005556 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005557 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005558} CXIdxEntityRefInfo;
5559
James Dennett7eee0182012-06-15 05:41:51 +00005560/**
5561 * \brief A group of callbacks used by #clang_indexSourceFile and
5562 * #clang_indexTranslationUnit.
5563 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005564typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005565 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005566 * \brief Called periodically to check whether indexing should be aborted.
5567 * Should return 0 to continue, and non-zero to abort.
5568 */
5569 int (*abortQuery)(CXClientData client_data, void *reserved);
5570
5571 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005572 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005573 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005574 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005575 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005576
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005577 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett7eee0182012-06-15 05:41:51 +00005578 CXFile mainFile, void *reserved);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005579
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005580 /**
James Dennett7eee0182012-06-15 05:41:51 +00005581 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005582 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005583 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005584 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005585
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005586 /**
5587 * \brief Called when a AST file (PCH or module) gets imported.
5588 *
5589 * AST files will not get indexed (there will not be callbacks to index all
5590 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005591 * file is not already indexed, to initiate a new indexing job specific to
5592 * the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005593 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005594 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005595 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005596
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005597 /**
5598 * \brief Called at the beginning of indexing a translation unit.
5599 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005600 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005601 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005602
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005603 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005604 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005605
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005606 /**
5607 * \brief Called to index a reference of an entity.
5608 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005609 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005610 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005611
5612} IndexerCallbacks;
5613
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00005614CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005615CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5616clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005617
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005618CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5619clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5620
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00005621CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005622const CXIdxObjCCategoryDeclInfo *
5623clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5624
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005625CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5626clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005627
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00005628CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5629clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5630
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005631CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5632clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5633
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005634CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5635clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5636
5637/**
5638 * \brief For retrieving a custom CXIdxClientContainer attached to a
5639 * container.
5640 */
5641CINDEX_LINKAGE CXIdxClientContainer
5642clang_index_getClientContainer(const CXIdxContainerInfo *);
5643
5644/**
5645 * \brief For setting a custom CXIdxClientContainer attached to a
5646 * container.
5647 */
5648CINDEX_LINKAGE void
5649clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5650
5651/**
5652 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5653 */
5654CINDEX_LINKAGE CXIdxClientEntity
5655clang_index_getClientEntity(const CXIdxEntityInfo *);
5656
5657/**
5658 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5659 */
5660CINDEX_LINKAGE void
5661clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5662
5663/**
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005664 * \brief An indexing action/session, to be applied to one or multiple
5665 * translation units.
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005666 */
5667typedef void *CXIndexAction;
5668
5669/**
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005670 * \brief An indexing action/session, to be applied to one or multiple
5671 * translation units.
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005672 *
5673 * \param CIdx The index object with which the index action will be associated.
5674 */
5675CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5676
5677/**
5678 * \brief Destroy the given index action.
5679 *
5680 * The index action must not be destroyed until all of the translation units
5681 * created within that index action have been destroyed.
5682 */
5683CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5684
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005685typedef enum {
5686 /**
5687 * \brief Used to indicate that no special indexing options are needed.
5688 */
5689 CXIndexOpt_None = 0x0,
5690
5691 /**
James Dennett7eee0182012-06-15 05:41:51 +00005692 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5693 * be invoked for only one reference of an entity per source file that does
5694 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005695 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00005696 CXIndexOpt_SuppressRedundantRefs = 0x1,
5697
5698 /**
5699 * \brief Function-local symbols should be indexed. If this is not set
5700 * function-local symbols will be ignored.
5701 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00005702 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5703
5704 /**
5705 * \brief Implicit function/class template instantiations should be indexed.
5706 * If this is not set, implicit instantiations will be ignored.
5707 */
Argyrios Kyrtzidisb49a29f2012-03-27 21:38:03 +00005708 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5709
5710 /**
5711 * \brief Suppress all compiler warnings when parsing for indexing.
5712 */
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005713 CXIndexOpt_SuppressWarnings = 0x8,
5714
5715 /**
5716 * \brief Skip a function/method body that was already parsed during an
5717 * indexing session assosiated with a \c CXIndexAction object.
5718 * Bodies in system headers are always skipped.
5719 */
5720 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5721
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005722} CXIndexOptFlags;
5723
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005724/**
5725 * \brief Index the given source file and the translation unit corresponding
James Dennett7eee0182012-06-15 05:41:51 +00005726 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005727 *
5728 * \param client_data pointer data supplied by the client, which will
5729 * be passed to the invoked callbacks.
5730 *
5731 * \param index_callbacks Pointer to indexing callbacks that the client
5732 * implements.
5733 *
James Dennett7eee0182012-06-15 05:41:51 +00005734 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005735 * passed in index_callbacks.
5736 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005737 * \param index_options A bitmask of options that affects how indexing is
5738 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005739 *
5740 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
5741 * after indexing is finished. Set to NULL if you do not require it.
5742 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005743 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005744 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005745 *
James Dennett7eee0182012-06-15 05:41:51 +00005746 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005747 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005748CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005749 CXClientData client_data,
5750 IndexerCallbacks *index_callbacks,
5751 unsigned index_callbacks_size,
5752 unsigned index_options,
5753 const char *source_filename,
5754 const char * const *command_line_args,
5755 int num_command_line_args,
5756 struct CXUnsavedFile *unsaved_files,
5757 unsigned num_unsaved_files,
5758 CXTranslationUnit *out_TU,
5759 unsigned TU_options);
5760
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005761/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005762 * \brief Index the given translation unit via callbacks implemented through
James Dennett7eee0182012-06-15 05:41:51 +00005763 * #IndexerCallbacks.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005764 *
5765 * The order of callback invocations is not guaranteed to be the same as
5766 * when indexing a source file. The high level order will be:
5767 *
5768 * -Preprocessor callbacks invocations
5769 * -Declaration/reference callbacks invocations
5770 * -Diagnostic callback invocations
5771 *
James Dennett7eee0182012-06-15 05:41:51 +00005772 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005773 *
5774 * \returns If there is a failure from which the there is no recovery, returns
5775 * non-zero, otherwise returns 0.
5776 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005777CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005778 CXClientData client_data,
5779 IndexerCallbacks *index_callbacks,
5780 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005781 unsigned index_options,
5782 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005783
5784/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005785 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5786 * the given CXIdxLoc.
5787 *
5788 * If the location refers into a macro expansion, retrieves the
5789 * location of the macro expansion and if it refers into a macro argument
5790 * retrieves the location of the argument.
5791 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005792CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005793 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005794 CXFile *file,
5795 unsigned *line,
5796 unsigned *column,
5797 unsigned *offset);
5798
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005799/**
5800 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5801 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005802CINDEX_LINKAGE
5803CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5804
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005805/**
5806 * @}
5807 */
5808
Douglas Gregorc42fefa2010-01-22 22:29:16 +00005809/**
5810 * @}
5811 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005812
Ted Kremenekd2fa5662009-08-26 22:36:44 +00005813#ifdef __cplusplus
5814}
5815#endif
5816#endif
5817