blob: 8fffc39e541cb621604532131654613db4541cf5 [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
Ted Kremenekd2fa5662009-08-26 22:36:44 +000023#ifdef __cplusplus
24extern "C" {
25#endif
26
Steve Naroff88145032009-10-27 14:35:18 +000027/* MSVC DLL import/export. */
John Thompson2e06fc82009-10-27 13:42:56 +000028#ifdef _MSC_VER
29 #ifdef _CINDEX_LIB_
30 #define CINDEX_LINKAGE __declspec(dllexport)
31 #else
32 #define CINDEX_LINKAGE __declspec(dllimport)
33 #endif
34#else
35 #define CINDEX_LINKAGE
36#endif
37
Ted Kremenek78d5d3b2012-04-12 00:03:31 +000038#ifdef __GNUC__
39 #define CINDEX_DEPRECATED __attribute__((deprecated))
40#else
41 #ifdef _MSC_VER
42 #define CINDEX_DEPRECATED __declspec(deprecated)
43 #else
44 #define CINDEX_DEPRECATED
45 #endif
46#endif
47
Douglas Gregor87fb9402011-02-23 17:45:25 +000048/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000049 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000050 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000051 * facilities for parsing source code into an abstract syntax tree (AST),
52 * loading already-parsed ASTs, traversing the AST, associating
53 * physical source locations with elements within the AST, and other
54 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000055 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000056 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000057 * representation stored in Clang's C++ AST, nor should it: the intent is to
58 * maintain an API that is relatively stable from one release to the next,
59 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000060 *
61 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000062 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000063 *
64 * @{
65 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000066
Douglas Gregor7f173762010-01-20 22:28:27 +000067/**
68 * \brief An "index" that consists of a set of translation units that would
69 * typically be linked together into an executable or library.
70 */
71typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000072
Douglas Gregor7f173762010-01-20 22:28:27 +000073/**
74 * \brief A single translation unit, which resides in an index.
75 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000076typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000077
Douglas Gregor7f173762010-01-20 22:28:27 +000078/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000079 * \brief Opaque pointer representing client data that will be passed through
80 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000081 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000082typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000083
Douglas Gregor735df882009-12-02 09:21:34 +000084/**
85 * \brief Provides the contents of a file that has not yet been saved to disk.
86 *
87 * Each CXUnsavedFile instance provides the name of a file on the
88 * system along with the current contents of that file that have not
89 * yet been saved to disk.
90 */
91struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000092 /**
93 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000094 *
95 * This file must already exist in the file system.
96 */
97 const char *Filename;
98
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000099 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000100 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +0000101 */
102 const char *Contents;
103
104 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000105 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +0000106 */
107 unsigned long Length;
108};
109
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000110/**
111 * \brief Describes the availability of a particular entity, which indicates
112 * whether the use of this entity will result in a warning or error due to
113 * it being deprecated or unavailable.
114 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000115enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000116 /**
117 * \brief The entity is available.
118 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000119 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000120 /**
121 * \brief The entity is available, but has been deprecated (and its use is
122 * not recommended).
123 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000124 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000125 /**
126 * \brief The entity is not available; any use of it will be an error.
127 */
Erik Verbruggend1205962011-10-06 07:27:49 +0000128 CXAvailability_NotAvailable,
129 /**
130 * \brief The entity is available, but not accessible; any use of it will be
131 * an error.
132 */
133 CXAvailability_NotAccessible
Douglas Gregor58ddb602010-08-23 23:00:57 +0000134};
Douglas Gregorcc889662012-05-08 00:14:45 +0000135
136/**
137 * \brief Describes a version number of the form major.minor.subminor.
138 */
139typedef struct CXVersion {
140 /**
141 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
142 * value indicates that there is no version number at all.
143 */
144 int Major;
145 /**
146 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
147 * will be negative if no minor version number was provided, e.g., for
148 * version '10'.
149 */
150 int Minor;
151 /**
152 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
153 * will be negative if no minor or subminor version number was provided,
154 * e.g., in version '10' or '10.7'.
155 */
156 int Subminor;
157} CXVersion;
Douglas Gregor58ddb602010-08-23 23:00:57 +0000158
Douglas Gregor7f173762010-01-20 22:28:27 +0000159/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000160 * \defgroup CINDEX_STRING String manipulation routines
161 *
162 * @{
163 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000164
Douglas Gregor7f173762010-01-20 22:28:27 +0000165/**
166 * \brief A character string.
167 *
168 * The \c CXString type is used to return strings from the interface when
169 * the ownership of that string might different from one call to the next.
170 * Use \c clang_getCString() to retrieve the string data and, once finished
171 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000172 */
173typedef struct {
Ted Kremeneka60ed472010-11-16 08:15:36 +0000174 void *data;
Ted Kremeneked122732010-11-16 01:56:27 +0000175 unsigned private_flags;
Steve Naroffef0cef62009-11-09 17:45:52 +0000176} CXString;
177
Douglas Gregor7f173762010-01-20 22:28:27 +0000178/**
179 * \brief Retrieve the character data associated with the given string.
180 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000181CINDEX_LINKAGE const char *clang_getCString(CXString string);
182
Douglas Gregor7f173762010-01-20 22:28:27 +0000183/**
184 * \brief Free the given string,
185 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000186CINDEX_LINKAGE void clang_disposeString(CXString string);
187
Douglas Gregor7f173762010-01-20 22:28:27 +0000188/**
189 * @}
190 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000191
192/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000193 * \brief clang_createIndex() provides a shared context for creating
194 * translation units. It provides two options:
195 *
196 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
197 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000198 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000199 * header that was used by the translation unit. If zero, all declarations
200 * will be enumerated.
201 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000202 * Here is an example:
203 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000204 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
205 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000206 *
207 * // IndexTest.pch was produced with the following command:
208 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
209 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
210 *
211 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000212 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000213 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000214 * clang_disposeTranslationUnit(TU);
215 *
216 * // This will load all the symbols from 'IndexTest.c', excluding symbols
217 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000218 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
219 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
220 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000221 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
222 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000223 * clang_disposeTranslationUnit(TU);
224 *
225 * This process of creating the 'pch', loading it separately, and using it (via
226 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
227 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000228 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000229CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
230 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000231
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000232/**
233 * \brief Destroy the given index.
234 *
235 * The index must not be destroyed until all of the translation units created
236 * within that index have been destroyed.
237 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000238CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000239
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +0000240typedef enum {
241 /**
242 * \brief Used to indicate that no special CXIndex options are needed.
243 */
244 CXGlobalOpt_None = 0x0,
245
246 /**
247 * \brief Used to indicate that threads that libclang creates for indexing
248 * purposes should use background priority.
249 * Affects \see clang_indexSourceFile, \see clang_indexTranslationUnit,
250 * \see clang_parseTranslationUnit, \see clang_saveTranslationUnit.
251 */
252 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
253
254 /**
255 * \brief Used to indicate that threads that libclang creates for editing
256 * purposes should use background priority.
257 * Affects \see clang_reparseTranslationUnit, \see clang_codeCompleteAt,
258 * \see clang_annotateTokens
259 */
260 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
261
262 /**
263 * \brief Used to indicate that all threads that libclang creates should use
264 * background priority.
265 */
266 CXGlobalOpt_ThreadBackgroundPriorityForAll =
267 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
268 CXGlobalOpt_ThreadBackgroundPriorityForEditing
269
270} CXGlobalOptFlags;
271
272/**
273 * \brief Sets general options associated with a CXIndex.
274 *
275 * For example:
276 * \code
277 * CXIndex idx = ...;
278 * clang_CXIndex_setGlobalOptions(idx,
279 * clang_CXIndex_getGlobalOptions(idx) |
280 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
281 * \endcode
282 *
283 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
284 */
285CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
286
287/**
288 * \brief Gets the general options associated with a CXIndex.
289 *
290 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
291 * are associated with the given CXIndex object.
292 */
293CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
294
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000295/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000296 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000297 *
298 * @{
299 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000300
Douglas Gregorf5525442010-01-20 22:45:41 +0000301/**
302 * \brief A particular source file that is part of a translation unit.
303 */
304typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000305
Douglas Gregorf5525442010-01-20 22:45:41 +0000306
307/**
308 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000309 */
Ted Kremenek74844072010-02-17 00:41:20 +0000310CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000311
Douglas Gregorf5525442010-01-20 22:45:41 +0000312/**
313 * \brief Retrieve the last modification time of the given file.
314 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000315CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000316
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000317/**
Douglas Gregordd3e5542011-05-04 00:14:37 +0000318 * \brief Determine whether the given header is guarded against
319 * multiple inclusions, either with the conventional
320 * #ifndef/#define/#endif macro guards or with #pragma once.
321 */
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 {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000363 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 {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000374 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 */
382CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000383
Douglas Gregorb9790342010-01-22 21:44:22 +0000384/**
385 * \determine 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/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000412 * \brief Retrieve a NULL (invalid) source range.
413 */
414CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000415
Douglas Gregor5352ac02010-01-28 00:27:43 +0000416/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000417 * \brief Retrieve a source range given the beginning and ending source
418 * locations.
419 */
420CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
421 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000422
Douglas Gregorb9790342010-01-22 21:44:22 +0000423/**
Douglas Gregorab4e83b2011-07-23 19:35:14 +0000424 * \brief Determine whether two ranges are equivalent.
425 *
426 * \returns non-zero if the ranges are the same, zero if they differ.
427 */
428CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
429 CXSourceRange range2);
430
431/**
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000432 * \brief Returns non-zero if \arg range is null.
433 */
Erik Verbruggen733dbc82011-10-06 12:11:57 +0000434CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000435
436/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000437 * \brief Retrieve the file, line, column, and offset represented by
438 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000439 *
Chandler Carruth20174222011-08-31 16:53:37 +0000440 * If the location refers into a macro expansion, retrieves the
441 * location of the macro expansion.
Douglas Gregora9b06d42010-11-09 06:24:54 +0000442 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000443 * \param location the location within a source file that will be decomposed
444 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000445 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000446 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000447 * source location points.
448 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000449 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000450 * source location points.
451 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000452 * \param column [out] if non-NULL, will be set to the column to which the given
453 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000454 *
455 * \param offset [out] if non-NULL, will be set to the offset into the
456 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000457 */
Chandler Carruth20174222011-08-31 16:53:37 +0000458CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
459 CXFile *file,
460 unsigned *line,
461 unsigned *column,
462 unsigned *offset);
463
464/**
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000465 * \brief Retrieve the file, line, column, and offset represented by
466 * the given source location, as specified in a # line directive.
467 *
468 * Example: given the following source code in a file somefile.c
469 *
470 * #123 "dummy.c" 1
471 *
472 * static int func(void)
473 * {
474 * return 0;
475 * }
476 *
477 * the location information returned by this function would be
478 *
479 * File: dummy.c Line: 124 Column: 12
480 *
481 * whereas clang_getExpansionLocation would have returned
482 *
483 * File: somefile.c Line: 3 Column: 12
484 *
485 * \param location the location within a source file that will be decomposed
486 * into its parts.
487 *
488 * \param filename [out] if non-NULL, will be set to the filename of the
489 * source location. Note that filenames returned will be for "virtual" files,
490 * which don't necessarily exist on the machine running clang - e.g. when
491 * parsing preprocessed output obtained from a different environment. If
492 * a non-NULL value is passed in, remember to dispose of the returned value
493 * using \c clang_disposeString() once you've finished with it. For an invalid
494 * source location, an empty string is returned.
495 *
496 * \param line [out] if non-NULL, will be set to the line number of the
497 * source location. For an invalid source location, zero is returned.
498 *
499 * \param column [out] if non-NULL, will be set to the column number of the
500 * source location. For an invalid source location, zero is returned.
501 */
502CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
503 CXString *filename,
504 unsigned *line,
505 unsigned *column);
506
507/**
Chandler Carruth20174222011-08-31 16:53:37 +0000508 * \brief Legacy API to retrieve the file, line, column, and offset represented
509 * by the given source location.
510 *
511 * This interface has been replaced by the newer interface
512 * \see clang_getExpansionLocation(). See that interface's documentation for
513 * details.
514 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000515CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
516 CXFile *file,
517 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000518 unsigned *column,
519 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000520
521/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000522 * \brief Retrieve the file, line, column, and offset represented by
523 * the given source location.
524 *
525 * If the location refers into a macro instantiation, return where the
526 * location was originally spelled in the source file.
527 *
528 * \param location the location within a source file that will be decomposed
529 * into its parts.
530 *
531 * \param file [out] if non-NULL, will be set to the file to which the given
532 * source location points.
533 *
534 * \param line [out] if non-NULL, will be set to the line to which the given
535 * source location points.
536 *
537 * \param column [out] if non-NULL, will be set to the column to which the given
538 * source location points.
539 *
540 * \param offset [out] if non-NULL, will be set to the offset into the
541 * buffer to which the given source location points.
542 */
543CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
544 CXFile *file,
545 unsigned *line,
546 unsigned *column,
547 unsigned *offset);
548
549/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000550 * \brief Retrieve a source location representing the first character within a
551 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000552 */
553CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
554
555/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000556 * \brief Retrieve a source location representing the last character within a
557 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000558 */
559CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
560
Douglas Gregorf5525442010-01-20 22:45:41 +0000561/**
562 * @}
563 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000564
565/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000566 * \defgroup CINDEX_DIAG Diagnostic reporting
567 *
568 * @{
569 */
570
571/**
572 * \brief Describes the severity of a particular diagnostic.
573 */
574enum CXDiagnosticSeverity {
575 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000576 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000577 * option.
578 */
579 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000580
Douglas Gregor5352ac02010-01-28 00:27:43 +0000581 /**
582 * \brief This diagnostic is a note that should be attached to the
583 * previous (non-note) diagnostic.
584 */
585 CXDiagnostic_Note = 1,
586
587 /**
588 * \brief This diagnostic indicates suspicious code that may not be
589 * wrong.
590 */
591 CXDiagnostic_Warning = 2,
592
593 /**
594 * \brief This diagnostic indicates that the code is ill-formed.
595 */
596 CXDiagnostic_Error = 3,
597
598 /**
599 * \brief This diagnostic indicates that the code is ill-formed such
600 * that future parser recovery is unlikely to produce useful
601 * results.
602 */
603 CXDiagnostic_Fatal = 4
604};
605
606/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000607 * \brief A single diagnostic, containing the diagnostic's severity,
608 * location, text, source ranges, and fix-it hints.
609 */
610typedef void *CXDiagnostic;
611
612/**
Ted Kremenek15322172011-11-10 08:43:12 +0000613 * \brief A group of CXDiagnostics.
614 */
615typedef void *CXDiagnosticSet;
616
617/**
618 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
619 */
620CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
621
622/**
623 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
624 *
625 * \param Unit the CXDiagnosticSet to query.
626 * \param Index the zero-based diagnostic number to retrieve.
627 *
628 * \returns the requested diagnostic. This diagnostic must be freed
629 * via a call to \c clang_disposeDiagnostic().
630 */
631CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
632 unsigned Index);
633
634
635/**
636 * \brief Describes the kind of error that occurred (if any) in a call to
637 * \c clang_loadDiagnostics.
638 */
639enum CXLoadDiag_Error {
640 /**
641 * \brief Indicates that no error occurred.
642 */
643 CXLoadDiag_None = 0,
644
645 /**
646 * \brief Indicates that an unknown error occurred while attempting to
647 * deserialize diagnostics.
648 */
649 CXLoadDiag_Unknown = 1,
650
651 /**
652 * \brief Indicates that the file containing the serialized diagnostics
653 * could not be opened.
654 */
655 CXLoadDiag_CannotLoad = 2,
656
657 /**
658 * \brief Indicates that the serialized diagnostics file is invalid or
659 * corrupt.
660 */
661 CXLoadDiag_InvalidFile = 3
662};
663
664/**
665 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
666 * file.
667 *
668 * \param The name of the file to deserialize.
669 * \param A pointer to a enum value recording if there was a problem
670 * deserializing the diagnostics.
671 * \param A pointer to a CXString for recording the error string
672 * if the file was not successfully loaded.
673 *
674 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
675 * diagnostics should be released using clang_disposeDiagnosticSet().
676 */
677CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
678 enum CXLoadDiag_Error *error,
679 CXString *errorString);
680
681/**
682 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
683 */
684CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
685
686/**
687 * \brief Retrieve the child diagnostics of a CXDiagnostic. This
688 * CXDiagnosticSet does not need to be released by clang_diposeDiagnosticSet.
689 */
690CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
691
692/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000693 * \brief Determine the number of diagnostics produced for the given
694 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000695 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000696CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
697
698/**
699 * \brief Retrieve a diagnostic associated with the given translation unit.
700 *
701 * \param Unit the translation unit to query.
702 * \param Index the zero-based diagnostic number to retrieve.
703 *
704 * \returns the requested diagnostic. This diagnostic must be freed
705 * via a call to \c clang_disposeDiagnostic().
706 */
707CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
708 unsigned Index);
709
710/**
Ted Kremenek0373fcc2011-12-09 22:28:32 +0000711 * \brief Retrieve the complete set of diagnostics associated with a
712 * translation unit.
713 *
714 * \param Unit the translation unit to query.
715 */
716CINDEX_LINKAGE CXDiagnosticSet
717 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
718
719/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000720 * \brief Destroy a diagnostic.
721 */
722CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000723
724/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000725 * \brief Options to control the display of diagnostics.
726 *
727 * The values in this enum are meant to be combined to customize the
728 * behavior of \c clang_displayDiagnostic().
729 */
730enum CXDiagnosticDisplayOptions {
731 /**
732 * \brief Display the source-location information where the
733 * diagnostic was located.
734 *
735 * When set, diagnostics will be prefixed by the file, line, and
736 * (optionally) column to which the diagnostic refers. For example,
737 *
738 * \code
739 * test.c:28: warning: extra tokens at end of #endif directive
740 * \endcode
741 *
742 * This option corresponds to the clang flag \c -fshow-source-location.
743 */
744 CXDiagnostic_DisplaySourceLocation = 0x01,
745
746 /**
747 * \brief If displaying the source-location information of the
748 * diagnostic, also include the column number.
749 *
750 * This option corresponds to the clang flag \c -fshow-column.
751 */
752 CXDiagnostic_DisplayColumn = 0x02,
753
754 /**
755 * \brief If displaying the source-location information of the
756 * diagnostic, also include information about source ranges in a
757 * machine-parsable format.
758 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000759 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000760 * \c -fdiagnostics-print-source-range-info.
761 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000762 CXDiagnostic_DisplaySourceRanges = 0x04,
763
764 /**
765 * \brief Display the option name associated with this diagnostic, if any.
766 *
767 * The option name displayed (e.g., -Wconversion) will be placed in brackets
768 * after the diagnostic text. This option corresponds to the clang flag
769 * \c -fdiagnostics-show-option.
770 */
771 CXDiagnostic_DisplayOption = 0x08,
772
773 /**
774 * \brief Display the category number associated with this diagnostic, if any.
775 *
776 * The category number is displayed within brackets after the diagnostic text.
777 * This option corresponds to the clang flag
778 * \c -fdiagnostics-show-category=id.
779 */
780 CXDiagnostic_DisplayCategoryId = 0x10,
781
782 /**
783 * \brief Display the category name associated with this diagnostic, if any.
784 *
785 * The category name is displayed within brackets after the diagnostic text.
786 * This option corresponds to the clang flag
787 * \c -fdiagnostics-show-category=name.
788 */
789 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000790};
791
792/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000793 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000794 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000795 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000796 * the diagnostic according to the various options given. The
797 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000798 * options that most closely mimics the behavior of the clang compiler.
799 *
800 * \param Diagnostic The diagnostic to print.
801 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000802 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000803 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000804 *
805 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000806 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000807CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
808 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000809
810/**
811 * \brief Retrieve the set of display options most similar to the
812 * default behavior of the clang compiler.
813 *
814 * \returns A set of display options suitable for use with \c
815 * clang_displayDiagnostic().
816 */
817CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
818
819/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000820 * \brief Determine the severity of the given diagnostic.
821 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000822CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000823clang_getDiagnosticSeverity(CXDiagnostic);
824
825/**
826 * \brief Retrieve the source location of the given diagnostic.
827 *
828 * This location is where Clang would print the caret ('^') when
829 * displaying the diagnostic on the command line.
830 */
831CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
832
833/**
834 * \brief Retrieve the text of the given diagnostic.
835 */
836CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000837
838/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000839 * \brief Retrieve the name of the command-line option that enabled this
840 * diagnostic.
841 *
842 * \param Diag The diagnostic to be queried.
843 *
844 * \param Disable If non-NULL, will be set to the option that disables this
845 * diagnostic (if any).
846 *
847 * \returns A string that contains the command-line option used to enable this
848 * warning, such as "-Wconversion" or "-pedantic".
849 */
850CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
851 CXString *Disable);
852
853/**
854 * \brief Retrieve the category number for this diagnostic.
855 *
856 * Diagnostics can be categorized into groups along with other, related
857 * diagnostics (e.g., diagnostics under the same warning flag). This routine
858 * retrieves the category number for the given diagnostic.
859 *
860 * \returns The number of the category that contains this diagnostic, or zero
861 * if this diagnostic is uncategorized.
862 */
863CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
864
865/**
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000866 * \brief Retrieve the name of a particular diagnostic category. This
867 * is now deprecated. Use clang_getDiagnosticCategoryText()
868 * instead.
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000869 *
870 * \param Category A diagnostic category number, as returned by
871 * \c clang_getDiagnosticCategory().
872 *
873 * \returns The name of the given diagnostic category.
874 */
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000875CINDEX_DEPRECATED CINDEX_LINKAGE
876CXString clang_getDiagnosticCategoryName(unsigned Category);
877
878/**
879 * \brief Retrieve the diagnostic category text for a given diagnostic.
880 *
881 *
882 * \returns The text of the given diagnostic category.
883 */
884CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000885
886/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000887 * \brief Determine the number of source ranges associated with the given
888 * diagnostic.
889 */
890CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000891
Douglas Gregor5352ac02010-01-28 00:27:43 +0000892/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000893 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000894 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000895 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000896 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000897 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000898 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000899 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000900 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000901 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000902 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000903 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000904 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000905CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000906 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000907
908/**
909 * \brief Determine the number of fix-it hints associated with the
910 * given diagnostic.
911 */
912CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
913
914/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000915 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000916 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000917 * Fix-its are described in terms of a source range whose contents
918 * should be replaced by a string. This approach generalizes over
919 * three kinds of operations: removal of source code (the range covers
920 * the code to be removed and the replacement string is empty),
921 * replacement of source code (the range covers the code to be
922 * replaced and the replacement string provides the new code), and
923 * insertion (both the start and end of the range point at the
924 * insertion location, and the replacement string provides the text to
925 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000926 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000927 * \param Diagnostic The diagnostic whose fix-its are being queried.
928 *
929 * \param FixIt The zero-based index of the fix-it.
930 *
931 * \param ReplacementRange The source range whose contents will be
932 * replaced with the returned replacement string. Note that source
933 * ranges are half-open ranges [a, b), so the source code should be
934 * replaced from a and up to (but not including) b.
935 *
936 * \returns A string containing text that should be replace the source
937 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000938 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000939CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000940 unsigned FixIt,
941 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000942
943/**
944 * @}
945 */
946
947/**
948 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
949 *
950 * The routines in this group provide the ability to create and destroy
951 * translation units from files, either by parsing the contents of the files or
952 * by reading in a serialized representation of a translation unit.
953 *
954 * @{
955 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000956
Douglas Gregor5352ac02010-01-28 00:27:43 +0000957/**
958 * \brief Get the original translation unit source file name.
959 */
960CINDEX_LINKAGE CXString
961clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
962
963/**
964 * \brief Return the CXTranslationUnit for a given source file and the provided
965 * command line arguments one would pass to the compiler.
966 *
967 * Note: The 'source_filename' argument is optional. If the caller provides a
968 * NULL pointer, the name of the source file is expected to reside in the
969 * specified command line arguments.
970 *
971 * Note: When encountered in 'clang_command_line_args', the following options
972 * are ignored:
973 *
974 * '-c'
975 * '-emit-ast'
976 * '-fsyntax-only'
977 * '-o <output file>' (both '-o' and '<output file>' are ignored)
978 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000979 * \param CIdx The index object with which the translation unit will be
980 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000981 *
982 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000983 * source file is included in \p clang_command_line_args.
984 *
985 * \param num_clang_command_line_args The number of command-line arguments in
986 * \p clang_command_line_args.
987 *
988 * \param clang_command_line_args The command-line arguments that would be
989 * passed to the \c clang executable if it were being invoked out-of-process.
990 * These command-line options will be parsed and will affect how the translation
991 * unit is parsed. Note that the following options are ignored: '-c',
Aaron Ballmand0f709e2012-05-06 16:07:45 +0000992 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000993 *
994 * \param num_unsaved_files the number of unsaved file entries in \p
995 * unsaved_files.
996 *
997 * \param unsaved_files the files that have not yet been saved to disk
998 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000999 * those files. The contents and name of these files (as specified by
1000 * CXUnsavedFile) are copied when necessary, so the client only needs to
1001 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001002 */
1003CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1004 CXIndex CIdx,
1005 const char *source_filename,
1006 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001007 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +00001008 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +00001009 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001010
Douglas Gregor5352ac02010-01-28 00:27:43 +00001011/**
1012 * \brief Create a translation unit from an AST file (-emit-ast).
1013 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001014CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +00001015 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +00001016
Douglas Gregor44c181a2010-07-23 00:33:23 +00001017/**
1018 * \brief Flags that control the creation of translation units.
1019 *
1020 * The enumerators in this enumeration type are meant to be bitwise
1021 * ORed together to specify which options should be used when
1022 * constructing the translation unit.
1023 */
Douglas Gregor5a430212010-07-21 18:52:53 +00001024enum CXTranslationUnit_Flags {
1025 /**
1026 * \brief Used to indicate that no special translation-unit options are
1027 * needed.
1028 */
1029 CXTranslationUnit_None = 0x0,
1030
1031 /**
1032 * \brief Used to indicate that the parser should construct a "detailed"
1033 * preprocessing record, including all macro definitions and instantiations.
1034 *
1035 * Constructing a detailed preprocessing record requires more memory
1036 * and time to parse, since the information contained in the record
1037 * is usually not retained. However, it can be useful for
1038 * applications that require more detailed information about the
1039 * behavior of the preprocessor.
1040 */
Douglas Gregor44c181a2010-07-23 00:33:23 +00001041 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1042
1043 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001044 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001045 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001046 * When a translation unit is considered "incomplete", semantic
1047 * analysis that is typically performed at the end of the
1048 * translation unit will be suppressed. For example, this suppresses
1049 * the completion of tentative declarations in C and of
1050 * instantiation of implicitly-instantiation function templates in
1051 * C++. This option is typically used when parsing a header with the
1052 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001053 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001054 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +00001055
1056 /**
1057 * \brief Used to indicate that the translation unit should be built with an
1058 * implicit precompiled header for the preamble.
1059 *
1060 * An implicit precompiled header is used as an optimization when a
1061 * particular translation unit is likely to be reparsed many times
1062 * when the sources aren't changing that often. In this case, an
1063 * implicit precompiled header will be built containing all of the
1064 * initial includes at the top of the main file (what we refer to as
1065 * the "preamble" of the file). In subsequent parses, if the
1066 * preamble or the files in it have not changed, \c
1067 * clang_reparseTranslationUnit() will re-use the implicit
1068 * precompiled header to improve parsing performance.
1069 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001070 CXTranslationUnit_PrecompiledPreamble = 0x04,
1071
1072 /**
1073 * \brief Used to indicate that the translation unit should cache some
1074 * code-completion results with each reparse of the source file.
1075 *
1076 * Caching of code-completion results is a performance optimization that
1077 * introduces some overhead to reparsing but improves the performance of
1078 * code-completion operations.
1079 */
Douglas Gregor99ba2022010-10-27 17:24:53 +00001080 CXTranslationUnit_CacheCompletionResults = 0x08,
1081 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001082 * \brief DEPRECATED: Enable precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001083 *
1084 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001085 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001086 */
1087 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
1088
1089 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001090 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001091 *
1092 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001093 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001094 */
Erik Verbruggen6a91d382012-04-12 10:11:59 +00001095 CXTranslationUnit_CXXChainedPCH = 0x20,
1096
1097 /**
1098 * \brief Used to indicate that function/method bodies should be skipped while
1099 * parsing.
1100 *
1101 * This option can be used to search for declarations/definitions while
1102 * ignoring the usages.
1103 */
1104 CXTranslationUnit_SkipFunctionBodies = 0x40
Douglas Gregor5a430212010-07-21 18:52:53 +00001105};
1106
1107/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001108 * \brief Returns the set of flags that is suitable for parsing a translation
1109 * unit that is being edited.
1110 *
1111 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1112 * to indicate that the translation unit is likely to be reparsed many times,
1113 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1114 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1115 * set contains an unspecified set of optimizations (e.g., the precompiled
1116 * preamble) geared toward improving the performance of these routines. The
1117 * set of optimizations enabled may change from one version to the next.
1118 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001119CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001120
1121/**
Douglas Gregor5a430212010-07-21 18:52:53 +00001122 * \brief Parse the given source file and the translation unit corresponding
1123 * to that file.
1124 *
1125 * This routine is the main entry point for the Clang C API, providing the
1126 * ability to parse a source file into a translation unit that can then be
1127 * queried by other functions in the API. This routine accepts a set of
1128 * command-line arguments so that the compilation can be configured in the same
1129 * way that the compiler is configured on the command line.
1130 *
1131 * \param CIdx The index object with which the translation unit will be
1132 * associated.
1133 *
1134 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001135 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +00001136 *
1137 * \param command_line_args The command-line arguments that would be
1138 * passed to the \c clang executable if it were being invoked out-of-process.
1139 * These command-line options will be parsed and will affect how the translation
1140 * unit is parsed. Note that the following options are ignored: '-c',
Aaron Ballmand0f709e2012-05-06 16:07:45 +00001141 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o <output file>'.
Douglas Gregor5a430212010-07-21 18:52:53 +00001142 *
1143 * \param num_command_line_args The number of command-line arguments in
1144 * \p command_line_args.
1145 *
1146 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00001147 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +00001148 * those files. The contents and name of these files (as specified by
1149 * CXUnsavedFile) are copied when necessary, so the client only needs to
1150 * guarantee their validity until the call to this function returns.
1151 *
1152 * \param num_unsaved_files the number of unsaved file entries in \p
1153 * unsaved_files.
1154 *
1155 * \param options A bitmask of options that affects how the translation unit
1156 * is managed but not its compilation. This should be a bitwise OR of the
1157 * CXTranslationUnit_XXX flags.
1158 *
1159 * \returns A new translation unit describing the parsed code and containing
1160 * any diagnostics produced by the compiler. If there is a failure from which
1161 * the compiler cannot recover, returns NULL.
1162 */
1163CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1164 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001165 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +00001166 int num_command_line_args,
1167 struct CXUnsavedFile *unsaved_files,
1168 unsigned num_unsaved_files,
1169 unsigned options);
1170
Douglas Gregor5352ac02010-01-28 00:27:43 +00001171/**
Douglas Gregor19998442010-08-13 15:35:05 +00001172 * \brief Flags that control how translation units are saved.
1173 *
1174 * The enumerators in this enumeration type are meant to be bitwise
1175 * ORed together to specify which options should be used when
1176 * saving the translation unit.
1177 */
1178enum CXSaveTranslationUnit_Flags {
1179 /**
1180 * \brief Used to indicate that no special saving options are needed.
1181 */
1182 CXSaveTranslationUnit_None = 0x0
1183};
1184
1185/**
1186 * \brief Returns the set of flags that is suitable for saving a translation
1187 * unit.
1188 *
1189 * The set of flags returned provide options for
1190 * \c clang_saveTranslationUnit() by default. The returned flag
1191 * set contains an unspecified set of options that save translation units with
1192 * the most commonly-requested data.
1193 */
1194CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1195
1196/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001197 * \brief Describes the kind of error that occurred (if any) in a call to
1198 * \c clang_saveTranslationUnit().
1199 */
1200enum CXSaveError {
1201 /**
1202 * \brief Indicates that no error occurred while saving a translation unit.
1203 */
1204 CXSaveError_None = 0,
1205
1206 /**
1207 * \brief Indicates that an unknown error occurred while attempting to save
1208 * the file.
1209 *
1210 * This error typically indicates that file I/O failed when attempting to
1211 * write the file.
1212 */
1213 CXSaveError_Unknown = 1,
1214
1215 /**
1216 * \brief Indicates that errors during translation prevented this attempt
1217 * to save the translation unit.
1218 *
1219 * Errors that prevent the translation unit from being saved can be
1220 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1221 */
1222 CXSaveError_TranslationErrors = 2,
1223
1224 /**
1225 * \brief Indicates that the translation unit to be saved was somehow
1226 * invalid (e.g., NULL).
1227 */
1228 CXSaveError_InvalidTU = 3
1229};
1230
1231/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001232 * \brief Saves a translation unit into a serialized representation of
1233 * that translation unit on disk.
1234 *
1235 * Any translation unit that was parsed without error can be saved
1236 * into a file. The translation unit can then be deserialized into a
1237 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1238 * if it is an incomplete translation unit that corresponds to a
1239 * header, used as a precompiled header when parsing other translation
1240 * units.
1241 *
1242 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001243 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001244 * \param FileName The file to which the translation unit will be saved.
1245 *
Douglas Gregor19998442010-08-13 15:35:05 +00001246 * \param options A bitmask of options that affects how the translation unit
1247 * is saved. This should be a bitwise OR of the
1248 * CXSaveTranslationUnit_XXX flags.
1249 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001250 * \returns A value that will match one of the enumerators of the CXSaveError
1251 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1252 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001253 */
1254CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001255 const char *FileName,
1256 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001257
1258/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001259 * \brief Destroy the specified CXTranslationUnit object.
1260 */
1261CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001262
Douglas Gregor5352ac02010-01-28 00:27:43 +00001263/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001264 * \brief Flags that control the reparsing of translation units.
1265 *
1266 * The enumerators in this enumeration type are meant to be bitwise
1267 * ORed together to specify which options should be used when
1268 * reparsing the translation unit.
1269 */
1270enum CXReparse_Flags {
1271 /**
1272 * \brief Used to indicate that no special reparsing options are needed.
1273 */
1274 CXReparse_None = 0x0
1275};
1276
1277/**
1278 * \brief Returns the set of flags that is suitable for reparsing a translation
1279 * unit.
1280 *
1281 * The set of flags returned provide options for
1282 * \c clang_reparseTranslationUnit() by default. The returned flag
1283 * set contains an unspecified set of optimizations geared toward common uses
1284 * of reparsing. The set of optimizations enabled may change from one version
1285 * to the next.
1286 */
1287CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1288
1289/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001290 * \brief Reparse the source files that produced this translation unit.
1291 *
1292 * This routine can be used to re-parse the source files that originally
1293 * created the given translation unit, for example because those source files
1294 * have changed (either on disk or as passed via \p unsaved_files). The
1295 * source code will be reparsed with the same command-line options as it
1296 * was originally parsed.
1297 *
1298 * Reparsing a translation unit invalidates all cursors and source locations
1299 * that refer into that translation unit. This makes reparsing a translation
1300 * unit semantically equivalent to destroying the translation unit and then
1301 * creating a new translation unit with the same command-line arguments.
1302 * However, it may be more efficient to reparse a translation
1303 * unit using this routine.
1304 *
1305 * \param TU The translation unit whose contents will be re-parsed. The
1306 * translation unit must originally have been built with
1307 * \c clang_createTranslationUnitFromSourceFile().
1308 *
1309 * \param num_unsaved_files The number of unsaved file entries in \p
1310 * unsaved_files.
1311 *
1312 * \param unsaved_files The files that have not yet been saved to disk
1313 * but may be required for parsing, including the contents of
1314 * those files. The contents and name of these files (as specified by
1315 * CXUnsavedFile) are copied when necessary, so the client only needs to
1316 * guarantee their validity until the call to this function returns.
1317 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001318 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1319 * The function \c clang_defaultReparseOptions() produces a default set of
1320 * options recommended for most uses, based on the translation unit.
1321 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001322 * \returns 0 if the sources could be reparsed. A non-zero value will be
1323 * returned if reparsing was impossible, such that the translation unit is
1324 * invalid. In such cases, the only valid call for \p TU is
1325 * \c clang_disposeTranslationUnit(TU).
1326 */
1327CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1328 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001329 struct CXUnsavedFile *unsaved_files,
1330 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001331
1332/**
1333 * \brief Categorizes how memory is being used by a translation unit.
1334 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001335enum CXTUResourceUsageKind {
1336 CXTUResourceUsage_AST = 1,
1337 CXTUResourceUsage_Identifiers = 2,
1338 CXTUResourceUsage_Selectors = 3,
1339 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001340 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001341 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001342 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001343 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1344 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1345 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001346 CXTUResourceUsage_Preprocessor = 11,
1347 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001348 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001349 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001350 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1351 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001352 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001353
1354 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001355 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001356};
1357
1358/**
1359 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001360 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001361 */
1362CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001363const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001364
Ted Kremenekf7870022011-04-20 16:41:07 +00001365typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001366 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001367 enum CXTUResourceUsageKind kind;
1368 /* \brief Amount of resources used.
1369 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001370 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001371} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001372
1373/**
1374 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1375 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001376typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001377 /* \brief Private data member, used for queries. */
1378 void *data;
1379
1380 /* \brief The number of entries in the 'entries' array. */
1381 unsigned numEntries;
1382
1383 /* \brief An array of key-value pairs, representing the breakdown of memory
1384 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001385 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001386
Ted Kremenekf7870022011-04-20 16:41:07 +00001387} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001388
1389/**
1390 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001391 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001392 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001393CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001394
Ted Kremenekf7870022011-04-20 16:41:07 +00001395CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001396
Douglas Gregorabc563f2010-07-19 21:46:24 +00001397/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001398 * @}
1399 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001400
Douglas Gregor5352ac02010-01-28 00:27:43 +00001401/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001402 * \brief Describes the kind of entity that a cursor refers to.
1403 */
1404enum CXCursorKind {
1405 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001406 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001407 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001408 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001409 *
1410 * Unexposed declarations have the same operations as any other kind
1411 * of declaration; one can extract their location information,
1412 * spelling, find their definitions, etc. However, the specific kind
1413 * of the declaration is not reported.
1414 */
1415 CXCursor_UnexposedDecl = 1,
1416 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001417 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001418 /** \brief A C or C++ union. */
1419 CXCursor_UnionDecl = 3,
1420 /** \brief A C++ class. */
1421 CXCursor_ClassDecl = 4,
1422 /** \brief An enumeration. */
1423 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001424 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001425 * \brief A field (in C) or non-static data member (in C++) in a
1426 * struct, union, or C++ class.
1427 */
1428 CXCursor_FieldDecl = 6,
1429 /** \brief An enumerator constant. */
1430 CXCursor_EnumConstantDecl = 7,
1431 /** \brief A function. */
1432 CXCursor_FunctionDecl = 8,
1433 /** \brief A variable. */
1434 CXCursor_VarDecl = 9,
1435 /** \brief A function or method parameter. */
1436 CXCursor_ParmDecl = 10,
James Dennett17d26a62012-06-11 06:19:40 +00001437 /** \brief An Objective-C \@interface. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001438 CXCursor_ObjCInterfaceDecl = 11,
James Dennett17d26a62012-06-11 06:19:40 +00001439 /** \brief An Objective-C \@interface for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001440 CXCursor_ObjCCategoryDecl = 12,
James Dennett17d26a62012-06-11 06:19:40 +00001441 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001442 CXCursor_ObjCProtocolDecl = 13,
James Dennett17d26a62012-06-11 06:19:40 +00001443 /** \brief An Objective-C \@property declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001444 CXCursor_ObjCPropertyDecl = 14,
1445 /** \brief An Objective-C instance variable. */
1446 CXCursor_ObjCIvarDecl = 15,
1447 /** \brief An Objective-C instance method. */
1448 CXCursor_ObjCInstanceMethodDecl = 16,
1449 /** \brief An Objective-C class method. */
1450 CXCursor_ObjCClassMethodDecl = 17,
James Dennett17d26a62012-06-11 06:19:40 +00001451 /** \brief An Objective-C \@implementation. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001452 CXCursor_ObjCImplementationDecl = 18,
James Dennett17d26a62012-06-11 06:19:40 +00001453 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001454 CXCursor_ObjCCategoryImplDecl = 19,
1455 /** \brief A typedef */
1456 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001457 /** \brief A C++ class method. */
1458 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001459 /** \brief A C++ namespace. */
1460 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001461 /** \brief A linkage specification, e.g. 'extern "C"'. */
1462 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001463 /** \brief A C++ constructor. */
1464 CXCursor_Constructor = 24,
1465 /** \brief A C++ destructor. */
1466 CXCursor_Destructor = 25,
1467 /** \brief A C++ conversion function. */
1468 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001469 /** \brief A C++ template type parameter. */
1470 CXCursor_TemplateTypeParameter = 27,
1471 /** \brief A C++ non-type template parameter. */
1472 CXCursor_NonTypeTemplateParameter = 28,
1473 /** \brief A C++ template template parameter. */
1474 CXCursor_TemplateTemplateParameter = 29,
1475 /** \brief A C++ function template. */
1476 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001477 /** \brief A C++ class template. */
1478 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001479 /** \brief A C++ class template partial specialization. */
1480 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001481 /** \brief A C++ namespace alias declaration. */
1482 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001483 /** \brief A C++ using directive. */
1484 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001485 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001486 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001487 /** \brief A C++ alias declaration */
1488 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001489 /** \brief An Objective-C @synthesize definition. */
1490 CXCursor_ObjCSynthesizeDecl = 37,
1491 /** \brief An Objective-C @dynamic definition. */
1492 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001493 /** \brief An access specifier. */
1494 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor42b29842011-10-05 19:00:14 +00001495
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001496 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001497 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001498
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001499 /* References */
1500 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001501 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001502 CXCursor_ObjCProtocolRef = 41,
1503 CXCursor_ObjCClassRef = 42,
1504 /**
1505 * \brief A reference to a type declaration.
1506 *
1507 * A type reference occurs anywhere where a type is named but not
1508 * declared. For example, given:
1509 *
1510 * \code
1511 * typedef unsigned size_type;
1512 * size_type size;
1513 * \endcode
1514 *
1515 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1516 * while the type of the variable "size" is referenced. The cursor
1517 * referenced by the type of size is the typedef for size_type.
1518 */
1519 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001520 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001521 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001522 * \brief A reference to a class template, function template, template
1523 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001524 */
1525 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001526 /**
1527 * \brief A reference to a namespace or namespace alias.
1528 */
1529 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001530 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001531 * \brief A reference to a member of a struct, union, or class that occurs in
1532 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001533 */
1534 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001535 /**
1536 * \brief A reference to a labeled statement.
1537 *
1538 * This cursor kind is used to describe the jump to "start_over" in the
1539 * goto statement in the following example:
1540 *
1541 * \code
1542 * start_over:
1543 * ++counter;
1544 *
1545 * goto start_over;
1546 * \endcode
1547 *
1548 * A label reference cursor refers to a label statement.
1549 */
1550 CXCursor_LabelRef = 48,
1551
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001552 /**
1553 * \brief A reference to a set of overloaded functions or function templates
1554 * that has not yet been resolved to a specific function or function template.
1555 *
1556 * An overloaded declaration reference cursor occurs in C++ templates where
1557 * a dependent name refers to a function. For example:
1558 *
1559 * \code
1560 * template<typename T> void swap(T&, T&);
1561 *
1562 * struct X { ... };
1563 * void swap(X&, X&);
1564 *
1565 * template<typename T>
1566 * void reverse(T* first, T* last) {
1567 * while (first < last - 1) {
1568 * swap(*first, *--last);
1569 * ++first;
1570 * }
1571 * }
1572 *
1573 * struct Y { };
1574 * void swap(Y&, Y&);
1575 * \endcode
1576 *
1577 * Here, the identifier "swap" is associated with an overloaded declaration
1578 * reference. In the template definition, "swap" refers to either of the two
1579 * "swap" functions declared above, so both results will be available. At
1580 * instantiation time, "swap" may also refer to other functions found via
1581 * argument-dependent lookup (e.g., the "swap" function at the end of the
1582 * example).
1583 *
1584 * The functions \c clang_getNumOverloadedDecls() and
1585 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1586 * referenced by this cursor.
1587 */
1588 CXCursor_OverloadedDeclRef = 49,
1589
Douglas Gregor011d8b92012-02-15 00:54:55 +00001590 /**
1591 * \brief A reference to a variable that occurs in some non-expression
1592 * context, e.g., a C++ lambda capture list.
1593 */
1594 CXCursor_VariableRef = 50,
1595
1596 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001597
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001598 /* Error conditions */
1599 CXCursor_FirstInvalid = 70,
1600 CXCursor_InvalidFile = 70,
1601 CXCursor_NoDeclFound = 71,
1602 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001603 CXCursor_InvalidCode = 73,
1604 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001605
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001606 /* Expressions */
1607 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001608
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001609 /**
1610 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001611 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001612 *
1613 * Unexposed expressions have the same operations as any other kind
1614 * of expression; one can extract their location information,
1615 * spelling, children, etc. However, the specific kind of the
1616 * expression is not reported.
1617 */
1618 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001619
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001620 /**
1621 * \brief An expression that refers to some value declaration, such
1622 * as a function, varible, or enumerator.
1623 */
1624 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001625
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001626 /**
1627 * \brief An expression that refers to a member of a struct, union,
1628 * class, Objective-C class, etc.
1629 */
1630 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001631
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001632 /** \brief An expression that calls a function. */
1633 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001634
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001635 /** \brief An expression that sends a message to an Objective-C
1636 object or class. */
1637 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001638
1639 /** \brief An expression that represents a block literal. */
1640 CXCursor_BlockExpr = 105,
1641
Douglas Gregor42b29842011-10-05 19:00:14 +00001642 /** \brief An integer literal.
1643 */
1644 CXCursor_IntegerLiteral = 106,
1645
1646 /** \brief A floating point number literal.
1647 */
1648 CXCursor_FloatingLiteral = 107,
1649
1650 /** \brief An imaginary number literal.
1651 */
1652 CXCursor_ImaginaryLiteral = 108,
1653
1654 /** \brief A string literal.
1655 */
1656 CXCursor_StringLiteral = 109,
1657
1658 /** \brief A character literal.
1659 */
1660 CXCursor_CharacterLiteral = 110,
1661
1662 /** \brief A parenthesized expression, e.g. "(1)".
1663 *
1664 * This AST node is only formed if full location information is requested.
1665 */
1666 CXCursor_ParenExpr = 111,
1667
1668 /** \brief This represents the unary-expression's (except sizeof and
1669 * alignof).
1670 */
1671 CXCursor_UnaryOperator = 112,
1672
1673 /** \brief [C99 6.5.2.1] Array Subscripting.
1674 */
1675 CXCursor_ArraySubscriptExpr = 113,
1676
1677 /** \brief A builtin binary operation expression such as "x + y" or
1678 * "x <= y".
1679 */
1680 CXCursor_BinaryOperator = 114,
1681
1682 /** \brief Compound assignment such as "+=".
1683 */
1684 CXCursor_CompoundAssignOperator = 115,
1685
1686 /** \brief The ?: ternary operator.
1687 */
1688 CXCursor_ConditionalOperator = 116,
1689
1690 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1691 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1692 *
1693 * For example: (int)f.
1694 */
1695 CXCursor_CStyleCastExpr = 117,
1696
1697 /** \brief [C99 6.5.2.5]
1698 */
1699 CXCursor_CompoundLiteralExpr = 118,
1700
1701 /** \brief Describes an C or C++ initializer list.
1702 */
1703 CXCursor_InitListExpr = 119,
1704
1705 /** \brief The GNU address of label extension, representing &&label.
1706 */
1707 CXCursor_AddrLabelExpr = 120,
1708
1709 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1710 */
1711 CXCursor_StmtExpr = 121,
1712
Benjamin Kramerffbe9b92011-12-23 17:00:35 +00001713 /** \brief Represents a C11 generic selection.
Douglas Gregor42b29842011-10-05 19:00:14 +00001714 */
1715 CXCursor_GenericSelectionExpr = 122,
1716
1717 /** \brief Implements the GNU __null extension, which is a name for a null
1718 * pointer constant that has integral type (e.g., int or long) and is the same
1719 * size and alignment as a pointer.
1720 *
1721 * The __null extension is typically only used by system headers, which define
1722 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1723 * match the size of a pointer).
1724 */
1725 CXCursor_GNUNullExpr = 123,
1726
1727 /** \brief C++'s static_cast<> expression.
1728 */
1729 CXCursor_CXXStaticCastExpr = 124,
1730
1731 /** \brief C++'s dynamic_cast<> expression.
1732 */
1733 CXCursor_CXXDynamicCastExpr = 125,
1734
1735 /** \brief C++'s reinterpret_cast<> expression.
1736 */
1737 CXCursor_CXXReinterpretCastExpr = 126,
1738
1739 /** \brief C++'s const_cast<> expression.
1740 */
1741 CXCursor_CXXConstCastExpr = 127,
1742
1743 /** \brief Represents an explicit C++ type conversion that uses "functional"
1744 * notion (C++ [expr.type.conv]).
1745 *
1746 * Example:
1747 * \code
1748 * x = int(0.5);
1749 * \endcode
1750 */
1751 CXCursor_CXXFunctionalCastExpr = 128,
1752
1753 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1754 */
1755 CXCursor_CXXTypeidExpr = 129,
1756
1757 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1758 */
1759 CXCursor_CXXBoolLiteralExpr = 130,
1760
1761 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1762 */
1763 CXCursor_CXXNullPtrLiteralExpr = 131,
1764
1765 /** \brief Represents the "this" expression in C++
1766 */
1767 CXCursor_CXXThisExpr = 132,
1768
1769 /** \brief [C++ 15] C++ Throw Expression.
1770 *
1771 * This handles 'throw' and 'throw' assignment-expression. When
1772 * assignment-expression isn't present, Op will be null.
1773 */
1774 CXCursor_CXXThrowExpr = 133,
1775
1776 /** \brief A new expression for memory allocation and constructor calls, e.g:
1777 * "new CXXNewExpr(foo)".
1778 */
1779 CXCursor_CXXNewExpr = 134,
1780
1781 /** \brief A delete expression for memory deallocation and destructor calls,
1782 * e.g. "delete[] pArray".
1783 */
1784 CXCursor_CXXDeleteExpr = 135,
1785
1786 /** \brief A unary expression.
1787 */
1788 CXCursor_UnaryExpr = 136,
1789
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001790 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor42b29842011-10-05 19:00:14 +00001791 */
1792 CXCursor_ObjCStringLiteral = 137,
1793
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001794 /** \brief An Objective-C @encode expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001795 */
1796 CXCursor_ObjCEncodeExpr = 138,
1797
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001798 /** \brief An Objective-C @selector expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001799 */
1800 CXCursor_ObjCSelectorExpr = 139,
1801
James Dennett17d26a62012-06-11 06:19:40 +00001802 /** \brief An Objective-C \@protocol expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001803 */
1804 CXCursor_ObjCProtocolExpr = 140,
1805
1806 /** \brief An Objective-C "bridged" cast expression, which casts between
1807 * Objective-C pointers and C pointers, transferring ownership in the process.
1808 *
1809 * \code
1810 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1811 * \endcode
1812 */
1813 CXCursor_ObjCBridgedCastExpr = 141,
1814
1815 /** \brief Represents a C++0x pack expansion that produces a sequence of
1816 * expressions.
1817 *
1818 * A pack expansion expression contains a pattern (which itself is an
1819 * expression) followed by an ellipsis. For example:
1820 *
1821 * \code
1822 * template<typename F, typename ...Types>
1823 * void forward(F f, Types &&...args) {
1824 * f(static_cast<Types&&>(args)...);
1825 * }
1826 * \endcode
1827 */
1828 CXCursor_PackExpansionExpr = 142,
1829
1830 /** \brief Represents an expression that computes the length of a parameter
1831 * pack.
1832 *
1833 * \code
1834 * template<typename ...Types>
1835 * struct count {
1836 * static const unsigned value = sizeof...(Types);
1837 * };
1838 * \endcode
1839 */
1840 CXCursor_SizeOfPackExpr = 143,
1841
Douglas Gregor011d8b92012-02-15 00:54:55 +00001842 /* \brief Represents a C++ lambda expression that produces a local function
1843 * object.
1844 *
1845 * \code
1846 * void abssort(float *x, unsigned N) {
1847 * std::sort(x, x + N,
1848 * [](float a, float b) {
1849 * return std::abs(a) < std::abs(b);
1850 * });
1851 * }
1852 * \endcode
1853 */
1854 CXCursor_LambdaExpr = 144,
1855
Ted Kremenekb3f75422012-03-06 20:06:06 +00001856 /** \brief Objective-c Boolean Literal.
1857 */
1858 CXCursor_ObjCBoolLiteralExpr = 145,
1859
1860 CXCursor_LastExpr = CXCursor_ObjCBoolLiteralExpr,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001861
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001862 /* Statements */
1863 CXCursor_FirstStmt = 200,
1864 /**
1865 * \brief A statement whose specific kind is not exposed via this
1866 * interface.
1867 *
1868 * Unexposed statements have the same operations as any other kind of
1869 * statement; one can extract their location information, spelling,
1870 * children, etc. However, the specific kind of the statement is not
1871 * reported.
1872 */
1873 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001874
1875 /** \brief A labelled statement in a function.
1876 *
1877 * This cursor kind is used to describe the "start_over:" label statement in
1878 * the following example:
1879 *
1880 * \code
1881 * start_over:
1882 * ++counter;
1883 * \endcode
1884 *
1885 */
1886 CXCursor_LabelStmt = 201,
Douglas Gregor42b29842011-10-05 19:00:14 +00001887
1888 /** \brief A group of statements like { stmt stmt }.
1889 *
1890 * This cursor kind is used to describe compound statements, e.g. function
1891 * bodies.
1892 */
1893 CXCursor_CompoundStmt = 202,
1894
1895 /** \brief A case statment.
1896 */
1897 CXCursor_CaseStmt = 203,
1898
1899 /** \brief A default statement.
1900 */
1901 CXCursor_DefaultStmt = 204,
1902
1903 /** \brief An if statement
1904 */
1905 CXCursor_IfStmt = 205,
1906
1907 /** \brief A switch statement.
1908 */
1909 CXCursor_SwitchStmt = 206,
1910
1911 /** \brief A while statement.
1912 */
1913 CXCursor_WhileStmt = 207,
1914
1915 /** \brief A do statement.
1916 */
1917 CXCursor_DoStmt = 208,
1918
1919 /** \brief A for statement.
1920 */
1921 CXCursor_ForStmt = 209,
1922
1923 /** \brief A goto statement.
1924 */
1925 CXCursor_GotoStmt = 210,
1926
1927 /** \brief An indirect goto statement.
1928 */
1929 CXCursor_IndirectGotoStmt = 211,
1930
1931 /** \brief A continue statement.
1932 */
1933 CXCursor_ContinueStmt = 212,
1934
1935 /** \brief A break statement.
1936 */
1937 CXCursor_BreakStmt = 213,
1938
1939 /** \brief A return statement.
1940 */
1941 CXCursor_ReturnStmt = 214,
1942
1943 /** \brief A GNU inline assembly statement extension.
1944 */
1945 CXCursor_AsmStmt = 215,
1946
Douglas Gregor3f54d482011-11-08 21:07:04 +00001947 /** \brief Objective-C's overall @try-@catch-@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001948 */
1949 CXCursor_ObjCAtTryStmt = 216,
1950
1951 /** \brief Objective-C's @catch statement.
1952 */
1953 CXCursor_ObjCAtCatchStmt = 217,
1954
1955 /** \brief Objective-C's @finally statement.
1956 */
1957 CXCursor_ObjCAtFinallyStmt = 218,
1958
1959 /** \brief Objective-C's @throw statement.
1960 */
1961 CXCursor_ObjCAtThrowStmt = 219,
1962
1963 /** \brief Objective-C's @synchronized statement.
1964 */
1965 CXCursor_ObjCAtSynchronizedStmt = 220,
1966
1967 /** \brief Objective-C's autorelease pool statement.
1968 */
1969 CXCursor_ObjCAutoreleasePoolStmt = 221,
1970
1971 /** \brief Objective-C's collection statement.
1972 */
1973 CXCursor_ObjCForCollectionStmt = 222,
1974
1975 /** \brief C++'s catch statement.
1976 */
1977 CXCursor_CXXCatchStmt = 223,
1978
1979 /** \brief C++'s try statement.
1980 */
1981 CXCursor_CXXTryStmt = 224,
1982
1983 /** \brief C++'s for (* : *) statement.
1984 */
1985 CXCursor_CXXForRangeStmt = 225,
1986
1987 /** \brief Windows Structured Exception Handling's try statement.
1988 */
1989 CXCursor_SEHTryStmt = 226,
1990
1991 /** \brief Windows Structured Exception Handling's except statement.
1992 */
1993 CXCursor_SEHExceptStmt = 227,
1994
1995 /** \brief Windows Structured Exception Handling's finally statement.
1996 */
1997 CXCursor_SEHFinallyStmt = 228,
1998
1999 /** \brief The null satement ";": C99 6.8.3p3.
2000 *
2001 * This cursor kind is used to describe the null statement.
2002 */
2003 CXCursor_NullStmt = 230,
2004
2005 /** \brief Adaptor class for mixing declarations with statements and
2006 * expressions.
2007 */
2008 CXCursor_DeclStmt = 231,
2009
2010 CXCursor_LastStmt = CXCursor_DeclStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002011
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002012 /**
2013 * \brief Cursor that represents the translation unit itself.
2014 *
2015 * The translation unit cursor exists primarily to act as the root
2016 * cursor for traversing the contents of a translation unit.
2017 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002018 CXCursor_TranslationUnit = 300,
2019
2020 /* Attributes */
2021 CXCursor_FirstAttr = 400,
2022 /**
2023 * \brief An attribute whose specific kind is not exposed via this
2024 * interface.
2025 */
2026 CXCursor_UnexposedAttr = 400,
2027
2028 CXCursor_IBActionAttr = 401,
2029 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00002030 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00002031 CXCursor_CXXFinalAttr = 404,
2032 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002033 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002034 CXCursor_AsmLabelAttr = 407,
2035 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002036
2037 /* Preprocessing */
2038 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00002039 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00002040 CXCursor_MacroExpansion = 502,
2041 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002042 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002043 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002044 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002045};
2046
2047/**
2048 * \brief A cursor representing some element in the abstract syntax tree for
2049 * a translation unit.
2050 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002051 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002052 * program--declaration, statements, expressions, references to declarations,
2053 * etc.--under a single "cursor" abstraction with a common set of operations.
2054 * Common operation for a cursor include: getting the physical location in
2055 * a source file where the cursor points, getting the name associated with a
2056 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2057 *
2058 * Cursors can be produced in two specific ways.
2059 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2060 * from which one can use clang_visitChildren() to explore the rest of the
2061 * translation unit. clang_getCursor() maps from a physical source location
2062 * to the entity that resides at that location, allowing one to map from the
2063 * source code into the AST.
2064 */
2065typedef struct {
2066 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00002067 int xdata;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002068 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002069} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002070
2071/**
2072 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2073 *
2074 * @{
2075 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002076
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002077/**
2078 * \brief Retrieve the NULL cursor, which represents no entity.
2079 */
2080CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002081
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002082/**
2083 * \brief Retrieve the cursor that represents the given translation unit.
2084 *
2085 * The translation unit cursor can be used to start traversing the
2086 * various declarations within the given translation unit.
2087 */
2088CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2089
2090/**
2091 * \brief Determine whether two cursors are equivalent.
2092 */
2093CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002094
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002095/**
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002096 * \brief Returns non-zero if \arg cursor is null.
2097 */
Benjamin Kramer5b419362012-02-01 20:37:28 +00002098CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002099
2100/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00002101 * \brief Compute a hash value for the given cursor.
2102 */
2103CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2104
2105/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002106 * \brief Retrieve the kind of the given cursor.
2107 */
2108CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2109
2110/**
2111 * \brief Determine whether the given cursor kind represents a declaration.
2112 */
2113CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2114
2115/**
2116 * \brief Determine whether the given cursor kind represents a simple
2117 * reference.
2118 *
2119 * Note that other kinds of cursors (such as expressions) can also refer to
2120 * other cursors. Use clang_getCursorReferenced() to determine whether a
2121 * particular cursor refers to another entity.
2122 */
2123CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2124
2125/**
2126 * \brief Determine whether the given cursor kind represents an expression.
2127 */
2128CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2129
2130/**
2131 * \brief Determine whether the given cursor kind represents a statement.
2132 */
2133CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2134
2135/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002136 * \brief Determine whether the given cursor kind represents an attribute.
2137 */
2138CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2139
2140/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002141 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002142 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002143 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002144CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2145
2146/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002147 * \brief Determine whether the given cursor kind represents a translation
2148 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002149 */
2150CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002151
Ted Kremenekad6eff62010-03-08 21:17:29 +00002152/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002153 * \brief Determine whether the given cursor represents a preprocessing
2154 * element, such as a preprocessor directive or macro instantiation.
2155 */
2156CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2157
2158/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002159 * \brief Determine whether the given cursor represents a currently
2160 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2161 */
2162CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2163
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002164/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002165 * \brief Describe the linkage of the entity referred to by a cursor.
2166 */
2167enum CXLinkageKind {
2168 /** \brief This value indicates that no linkage information is available
2169 * for a provided CXCursor. */
2170 CXLinkage_Invalid,
2171 /**
2172 * \brief This is the linkage for variables, parameters, and so on that
2173 * have automatic storage. This covers normal (non-extern) local variables.
2174 */
2175 CXLinkage_NoLinkage,
2176 /** \brief This is the linkage for static variables and static functions. */
2177 CXLinkage_Internal,
2178 /** \brief This is the linkage for entities with external linkage that live
2179 * in C++ anonymous namespaces.*/
2180 CXLinkage_UniqueExternal,
2181 /** \brief This is the linkage for entities with true, external linkage. */
2182 CXLinkage_External
2183};
2184
2185/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002186 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002187 */
2188CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2189
2190/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002191 * \brief Determine the availability of the entity that this cursor refers to,
2192 * taking the current target platform into account.
Douglas Gregor58ddb602010-08-23 23:00:57 +00002193 *
2194 * \param cursor The cursor to query.
2195 *
2196 * \returns The availability of the cursor.
2197 */
2198CINDEX_LINKAGE enum CXAvailabilityKind
2199clang_getCursorAvailability(CXCursor cursor);
2200
2201/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002202 * Describes the availability of a given entity on a particular platform, e.g.,
2203 * a particular class might only be available on Mac OS 10.7 or newer.
2204 */
2205typedef struct CXPlatformAvailability {
2206 /**
2207 * \brief A string that describes the platform for which this structure
2208 * provides availability information.
2209 *
2210 * Possible values are "ios" or "macosx".
2211 */
2212 CXString Platform;
2213 /**
2214 * \brief The version number in which this entity was introduced.
2215 */
2216 CXVersion Introduced;
2217 /**
2218 * \brief The version number in which this entity was deprecated (but is
2219 * still available).
2220 */
2221 CXVersion Deprecated;
2222 /**
2223 * \brief The version number in which this entity was obsoleted, and therefore
2224 * is no longer available.
2225 */
2226 CXVersion Obsoleted;
2227 /**
2228 * \brief Whether the entity is unconditionally unavailable on this platform.
2229 */
2230 int Unavailable;
2231 /**
2232 * \brief An optional message to provide to a user of this API, e.g., to
2233 * suggest replacement APIs.
2234 */
2235 CXString Message;
2236} CXPlatformAvailability;
2237
2238/**
2239 * \brief Determine the availability of the entity that this cursor refers to
2240 * on any platforms for which availability information is known.
2241 *
2242 * \param cursor The cursor to query.
2243 *
2244 * \param always_deprecated If non-NULL, will be set to indicate whether the
2245 * entity is deprecated on all platforms.
2246 *
2247 * \param deprecated_message If non-NULL, will be set to the message text
2248 * provided along with the unconditional deprecation of this entity. The client
2249 * is responsible for deallocating this string.
2250 *
2251 * \param always_unavailabile If non-NULL, will be set to indicate whether the
2252 * entity is unavailable on all platforms.
2253 *
2254 * \param unavailable_message If non-NULL, will be set to the message text
2255 * provided along with the unconditional unavailability of this entity. The
2256 * client is responsible for deallocating this string.
2257 *
2258 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2259 * that will be populated with platform availability information, up to either
2260 * the number of platforms for which availability information is available (as
2261 * returned by this function) or \c availability_size, whichever is smaller.
2262 *
2263 * \param availability_size The number of elements available in the
2264 * \c availability array.
2265 *
2266 * \returns The number of platforms (N) for which availability information is
2267 * available (which is unrelated to \c availability_size).
2268 *
2269 * Note that the client is responsible for calling
2270 * \c clang_disposeCXPlatformAvailability to free each of the
2271 * platform-availability structures returned. There are
2272 * \c min(N, availability_size) such structures.
2273 */
2274CINDEX_LINKAGE int
2275clang_getCursorPlatformAvailability(CXCursor cursor,
2276 int *always_deprecated,
2277 CXString *deprecated_message,
2278 int *always_unavailable,
2279 CXString *unavailable_message,
2280 CXPlatformAvailability *availability,
2281 int availability_size);
2282
2283/**
2284 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2285 */
2286CINDEX_LINKAGE void
2287clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2288
2289/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002290 * \brief Describe the "language" of the entity referred to by a cursor.
2291 */
2292CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002293 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002294 CXLanguage_C,
2295 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002296 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002297};
2298
2299/**
2300 * \brief Determine the "language" of the entity referred to by a given cursor.
2301 */
2302CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2303
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002304/**
2305 * \brief Returns the translation unit that a cursor originated from.
2306 */
2307CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2308
Ted Kremenekeca099b2010-12-08 23:43:14 +00002309
2310/**
2311 * \brief A fast container representing a set of CXCursors.
2312 */
2313typedef struct CXCursorSetImpl *CXCursorSet;
2314
2315/**
2316 * \brief Creates an empty CXCursorSet.
2317 */
2318CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2319
2320/**
2321 * \brief Disposes a CXCursorSet and releases its associated memory.
2322 */
2323CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2324
2325/**
2326 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2327 *
2328 * \returns non-zero if the set contains the specified cursor.
2329*/
2330CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2331 CXCursor cursor);
2332
2333/**
2334 * \brief Inserts a CXCursor into a CXCursorSet.
2335 *
2336 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2337*/
2338CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2339 CXCursor cursor);
2340
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002341/**
2342 * \brief Determine the semantic parent of the given cursor.
2343 *
2344 * The semantic parent of a cursor is the cursor that semantically contains
2345 * the given \p cursor. For many declarations, the lexical and semantic parents
2346 * are equivalent (the lexical parent is returned by
2347 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2348 * definitions are provided out-of-line. For example:
2349 *
2350 * \code
2351 * class C {
2352 * void f();
2353 * };
2354 *
2355 * void C::f() { }
2356 * \endcode
2357 *
2358 * In the out-of-line definition of \c C::f, the semantic parent is the
2359 * the class \c C, of which this function is a member. The lexical parent is
2360 * the place where the declaration actually occurs in the source code; in this
2361 * case, the definition occurs in the translation unit. In general, the
2362 * lexical parent for a given entity can change without affecting the semantics
2363 * of the program, and the lexical parent of different declarations of the
2364 * same entity may be different. Changing the semantic parent of a declaration,
2365 * on the other hand, can have a major impact on semantics, and redeclarations
2366 * of a particular entity should all have the same semantic context.
2367 *
2368 * In the example above, both declarations of \c C::f have \c C as their
2369 * semantic context, while the lexical context of the first \c C::f is \c C
2370 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002371 *
2372 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002373 */
2374CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2375
2376/**
2377 * \brief Determine the lexical parent of the given cursor.
2378 *
2379 * The lexical parent of a cursor is the cursor in which the given \p cursor
2380 * was actually written. For many declarations, the lexical and semantic parents
2381 * are equivalent (the semantic parent is returned by
2382 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2383 * definitions are provided out-of-line. For example:
2384 *
2385 * \code
2386 * class C {
2387 * void f();
2388 * };
2389 *
2390 * void C::f() { }
2391 * \endcode
2392 *
2393 * In the out-of-line definition of \c C::f, the semantic parent is the
2394 * the class \c C, of which this function is a member. The lexical parent is
2395 * the place where the declaration actually occurs in the source code; in this
2396 * case, the definition occurs in the translation unit. In general, the
2397 * lexical parent for a given entity can change without affecting the semantics
2398 * of the program, and the lexical parent of different declarations of the
2399 * same entity may be different. Changing the semantic parent of a declaration,
2400 * on the other hand, can have a major impact on semantics, and redeclarations
2401 * of a particular entity should all have the same semantic context.
2402 *
2403 * In the example above, both declarations of \c C::f have \c C as their
2404 * semantic context, while the lexical context of the first \c C::f is \c C
2405 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002406 *
2407 * For declarations written in the global scope, the lexical parent is
2408 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002409 */
2410CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002411
2412/**
2413 * \brief Determine the set of methods that are overridden by the given
2414 * method.
2415 *
2416 * In both Objective-C and C++, a method (aka virtual member function,
2417 * in C++) can override a virtual method in a base class. For
2418 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002419 * base class, its protocols, or its categories' protocols, that has the same
2420 * selector and is of the same kind (class or instance).
2421 * If no such method exists, the search continues to the class's superclass,
2422 * its protocols, and its categories, and so on. A method from an Objective-C
2423 * implementation is considered to override the same methods as its
2424 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002425 *
2426 * For C++, a virtual member function overrides any virtual member
2427 * function with the same signature that occurs in its base
2428 * classes. With multiple inheritance, a virtual member function can
2429 * override several virtual member functions coming from different
2430 * base classes.
2431 *
2432 * In all cases, this function determines the immediate overridden
2433 * method, rather than all of the overridden methods. For example, if
2434 * a method is originally declared in a class A, then overridden in B
2435 * (which in inherits from A) and also in C (which inherited from B),
2436 * then the only overridden method returned from this function when
2437 * invoked on C's method will be B's method. The client may then
2438 * invoke this function again, given the previously-found overridden
2439 * methods, to map out the complete method-override set.
2440 *
2441 * \param cursor A cursor representing an Objective-C or C++
2442 * method. This routine will compute the set of methods that this
2443 * method overrides.
2444 *
2445 * \param overridden A pointer whose pointee will be replaced with a
2446 * pointer to an array of cursors, representing the set of overridden
2447 * methods. If there are no overridden methods, the pointee will be
2448 * set to NULL. The pointee must be freed via a call to
2449 * \c clang_disposeOverriddenCursors().
2450 *
2451 * \param num_overridden A pointer to the number of overridden
2452 * functions, will be set to the number of overridden functions in the
2453 * array pointed to by \p overridden.
2454 */
2455CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2456 CXCursor **overridden,
2457 unsigned *num_overridden);
2458
2459/**
2460 * \brief Free the set of overridden cursors returned by \c
2461 * clang_getOverriddenCursors().
2462 */
2463CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2464
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002465/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002466 * \brief Retrieve the file that is included by the given inclusion directive
2467 * cursor.
2468 */
2469CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2470
2471/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002472 * @}
2473 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002474
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002475/**
2476 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2477 *
2478 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2479 * routines help map between cursors and the physical locations where the
2480 * described entities occur in the source code. The mapping is provided in
2481 * both directions, so one can map from source code to the AST and back.
2482 *
2483 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002484 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002485
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002486/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002487 * \brief Map a source location to the cursor that describes the entity at that
2488 * location in the source code.
2489 *
2490 * clang_getCursor() maps an arbitrary source location within a translation
2491 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002492 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002493 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002494 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002495 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2496 * will return a cursor referring to the "+" expression.
2497 *
2498 * \returns a cursor representing the entity at the given source location, or
2499 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002500 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002501CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002502
Douglas Gregor98258af2010-01-18 22:46:11 +00002503/**
2504 * \brief Retrieve the physical location of the source constructor referenced
2505 * by the given cursor.
2506 *
2507 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002508 * declaration, where the name of that declaration would occur if it is
2509 * unnamed, or some keyword that introduces that particular declaration.
2510 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002511 * source code.
2512 */
2513CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002514
Douglas Gregorb6998662010-01-19 19:34:47 +00002515/**
2516 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002517 * the given cursor.
2518 *
2519 * The extent of a cursor starts with the file/line/column pointing at the
2520 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002521 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002522 * declaration, the extent covers the declaration itself. For a reference,
2523 * the extent covers the location of the reference (e.g., where the referenced
2524 * entity was actually used).
2525 */
2526CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002527
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002528/**
2529 * @}
2530 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002531
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002532/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002533 * \defgroup CINDEX_TYPES Type information for CXCursors
2534 *
2535 * @{
2536 */
2537
2538/**
2539 * \brief Describes the kind of type
2540 */
2541enum CXTypeKind {
2542 /**
2543 * \brief Reprents an invalid type (e.g., where no type is available).
2544 */
2545 CXType_Invalid = 0,
2546
2547 /**
2548 * \brief A type whose specific kind is not exposed via this
2549 * interface.
2550 */
2551 CXType_Unexposed = 1,
2552
2553 /* Builtin types */
2554 CXType_Void = 2,
2555 CXType_Bool = 3,
2556 CXType_Char_U = 4,
2557 CXType_UChar = 5,
2558 CXType_Char16 = 6,
2559 CXType_Char32 = 7,
2560 CXType_UShort = 8,
2561 CXType_UInt = 9,
2562 CXType_ULong = 10,
2563 CXType_ULongLong = 11,
2564 CXType_UInt128 = 12,
2565 CXType_Char_S = 13,
2566 CXType_SChar = 14,
2567 CXType_WChar = 15,
2568 CXType_Short = 16,
2569 CXType_Int = 17,
2570 CXType_Long = 18,
2571 CXType_LongLong = 19,
2572 CXType_Int128 = 20,
2573 CXType_Float = 21,
2574 CXType_Double = 22,
2575 CXType_LongDouble = 23,
2576 CXType_NullPtr = 24,
2577 CXType_Overload = 25,
2578 CXType_Dependent = 26,
2579 CXType_ObjCId = 27,
2580 CXType_ObjCClass = 28,
2581 CXType_ObjCSel = 29,
2582 CXType_FirstBuiltin = CXType_Void,
2583 CXType_LastBuiltin = CXType_ObjCSel,
2584
2585 CXType_Complex = 100,
2586 CXType_Pointer = 101,
2587 CXType_BlockPointer = 102,
2588 CXType_LValueReference = 103,
2589 CXType_RValueReference = 104,
2590 CXType_Record = 105,
2591 CXType_Enum = 106,
2592 CXType_Typedef = 107,
2593 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002594 CXType_ObjCObjectPointer = 109,
2595 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002596 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002597 CXType_ConstantArray = 112,
2598 CXType_Vector = 113
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002599};
2600
2601/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002602 * \brief Describes the calling convention of a function type
2603 */
2604enum CXCallingConv {
2605 CXCallingConv_Default = 0,
2606 CXCallingConv_C = 1,
2607 CXCallingConv_X86StdCall = 2,
2608 CXCallingConv_X86FastCall = 3,
2609 CXCallingConv_X86ThisCall = 4,
2610 CXCallingConv_X86Pascal = 5,
2611 CXCallingConv_AAPCS = 6,
2612 CXCallingConv_AAPCS_VFP = 7,
2613
2614 CXCallingConv_Invalid = 100,
2615 CXCallingConv_Unexposed = 200
2616};
2617
2618
2619/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002620 * \brief The type of an element in the abstract syntax tree.
2621 *
2622 */
2623typedef struct {
2624 enum CXTypeKind kind;
2625 void *data[2];
2626} CXType;
2627
2628/**
2629 * \brief Retrieve the type of a CXCursor (if any).
2630 */
2631CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2632
2633/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002634 * \brief Retrieve the underlying type of a typedef declaration.
2635 *
2636 * If the cursor does not reference a typedef declaration, an invalid type is
2637 * returned.
2638 */
2639CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2640
2641/**
2642 * \brief Retrieve the integer type of an enum declaration.
2643 *
2644 * If the cursor does not reference an enum declaration, an invalid type is
2645 * returned.
2646 */
2647CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2648
2649/**
2650 * \brief Retrieve the integer value of an enum constant declaration as a signed
2651 * long long.
2652 *
2653 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2654 * Since this is also potentially a valid constant value, the kind of the cursor
2655 * must be verified before calling this function.
2656 */
2657CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2658
2659/**
2660 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2661 * long long.
2662 *
2663 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2664 * Since this is also potentially a valid constant value, the kind of the cursor
2665 * must be verified before calling this function.
2666 */
2667CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2668
2669/**
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002670 * \brief Retrieve the number of non-variadic arguments associated with a given
2671 * cursor.
2672 *
2673 * If a cursor that is not a function or method is passed in, -1 is returned.
2674 */
2675CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2676
2677/**
2678 * \brief Retrieve the argument cursor of a function or method.
2679 *
2680 * If a cursor that is not a function or method is passed in or the index
2681 * exceeds the number of arguments, an invalid cursor is returned.
2682 */
2683CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2684
2685/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002686 * \determine Determine whether two CXTypes represent the same type.
2687 *
2688 * \returns non-zero if the CXTypes represent the same type and
2689 zero otherwise.
2690 */
2691CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2692
2693/**
2694 * \brief Return the canonical type for a CXType.
2695 *
2696 * Clang's type system explicitly models typedefs and all the ways
2697 * a specific type can be represented. The canonical type is the underlying
2698 * type with all the "sugar" removed. For example, if 'T' is a typedef
2699 * for 'int', the canonical type for 'T' would be 'int'.
2700 */
2701CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2702
2703/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002704 * \determine Determine whether a CXType has the "const" qualifier set,
2705 * without looking through typedefs that may have added "const" at a different level.
2706 */
2707CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2708
2709/**
2710 * \determine Determine whether a CXType has the "volatile" qualifier set,
2711 * without looking through typedefs that may have added "volatile" at a different level.
2712 */
2713CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2714
2715/**
2716 * \determine Determine whether a CXType has the "restrict" qualifier set,
2717 * without looking through typedefs that may have added "restrict" at a different level.
2718 */
2719CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2720
2721/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002722 * \brief For pointer types, returns the type of the pointee.
2723 *
2724 */
2725CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2726
2727/**
2728 * \brief Return the cursor for the declaration of the given type.
2729 */
2730CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2731
David Chisnall5389f482010-12-30 14:05:53 +00002732/**
2733 * Returns the Objective-C type encoding for the specified declaration.
2734 */
2735CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002736
2737/**
2738 * \brief Retrieve the spelling of a given CXTypeKind.
2739 */
2740CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2741
2742/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002743 * \brief Retrieve the calling convention associated with a function type.
2744 *
2745 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2746 */
2747CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2748
2749/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002750 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002751 *
2752 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002753 */
2754CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2755
2756/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002757 * \brief Retrieve the number of non-variadic arguments associated with a function type.
2758 *
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002759 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002760 */
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002761CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002762
2763/**
2764 * \brief Retrieve the type of an argument of a function type.
2765 *
2766 * If a non-function type is passed in or the function does not have enough parameters,
2767 * an invalid type is returned.
2768 */
2769CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2770
2771/**
2772 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2773 *
2774 */
2775CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2776
2777/**
2778 * \brief Retrieve the result type associated with a given cursor.
2779 *
2780 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002781 */
2782CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2783
2784/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002785 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2786 * otherwise.
2787 */
2788CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2789
2790/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002791 * \brief Return the element type of an array, complex, or vector type.
2792 *
2793 * If a type is passed in that is not an array, complex, or vector type,
2794 * an invalid type is returned.
2795 */
2796CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2797
2798/**
2799 * \brief Return the number of elements of an array or vector type.
2800 *
2801 * If a type is passed in that is not an array or vector type,
2802 * -1 is returned.
2803 */
2804CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2805
2806/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002807 * \brief Return the element type of an array type.
2808 *
2809 * If a non-array type is passed in, an invalid type is returned.
2810 */
2811CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2812
2813/**
2814 * \brief Return the the array size of a constant array.
2815 *
2816 * If a non-array type is passed in, -1 is returned.
2817 */
2818CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2819
2820/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002821 * \brief Returns 1 if the base class specified by the cursor with kind
2822 * CX_CXXBaseSpecifier is virtual.
2823 */
2824CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2825
2826/**
2827 * \brief Represents the C++ access control level to a base class for a
2828 * cursor with kind CX_CXXBaseSpecifier.
2829 */
2830enum CX_CXXAccessSpecifier {
2831 CX_CXXInvalidAccessSpecifier,
2832 CX_CXXPublic,
2833 CX_CXXProtected,
2834 CX_CXXPrivate
2835};
2836
2837/**
2838 * \brief Returns the access control level for the C++ base specifier
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00002839 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2840 * CXCursor_AccessSpecifier.
Ted Kremenek3064ef92010-08-27 21:34:58 +00002841 */
2842CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2843
2844/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002845 * \brief Determine the number of overloaded declarations referenced by a
2846 * \c CXCursor_OverloadedDeclRef cursor.
2847 *
2848 * \param cursor The cursor whose overloaded declarations are being queried.
2849 *
2850 * \returns The number of overloaded declarations referenced by \c cursor. If it
2851 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2852 */
2853CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2854
2855/**
2856 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2857 * by a \c CXCursor_OverloadedDeclRef cursor.
2858 *
2859 * \param cursor The cursor whose overloaded declarations are being queried.
2860 *
2861 * \param index The zero-based index into the set of overloaded declarations in
2862 * the cursor.
2863 *
2864 * \returns A cursor representing the declaration referenced by the given
2865 * \c cursor at the specified \c index. If the cursor does not have an
2866 * associated set of overloaded declarations, or if the index is out of bounds,
2867 * returns \c clang_getNullCursor();
2868 */
2869CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2870 unsigned index);
2871
2872/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002873 * @}
2874 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002875
2876/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002877 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002878 *
2879 * @{
2880 */
2881
2882
2883/**
2884 * \brief For cursors representing an iboutletcollection attribute,
2885 * this function returns the collection element type.
2886 *
2887 */
2888CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2889
2890/**
2891 * @}
2892 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002893
2894/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002895 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2896 *
2897 * These routines provide the ability to traverse the abstract syntax tree
2898 * using cursors.
2899 *
2900 * @{
2901 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002902
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002903/**
2904 * \brief Describes how the traversal of the children of a particular
2905 * cursor should proceed after visiting a particular child cursor.
2906 *
2907 * A value of this enumeration type should be returned by each
2908 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2909 */
2910enum CXChildVisitResult {
2911 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002912 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002913 */
2914 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002915 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002916 * \brief Continues the cursor traversal with the next sibling of
2917 * the cursor just visited, without visiting its children.
2918 */
2919 CXChildVisit_Continue,
2920 /**
2921 * \brief Recursively traverse the children of this cursor, using
2922 * the same visitor and client data.
2923 */
2924 CXChildVisit_Recurse
2925};
2926
2927/**
2928 * \brief Visitor invoked for each cursor found by a traversal.
2929 *
2930 * This visitor function will be invoked for each cursor found by
2931 * clang_visitCursorChildren(). Its first argument is the cursor being
2932 * visited, its second argument is the parent visitor for that cursor,
2933 * and its third argument is the client data provided to
2934 * clang_visitCursorChildren().
2935 *
2936 * The visitor should return one of the \c CXChildVisitResult values
2937 * to direct clang_visitCursorChildren().
2938 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002939typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2940 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002941 CXClientData client_data);
2942
2943/**
2944 * \brief Visit the children of a particular cursor.
2945 *
2946 * This function visits all the direct children of the given cursor,
2947 * invoking the given \p visitor function with the cursors of each
2948 * visited child. The traversal may be recursive, if the visitor returns
2949 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2950 * the visitor returns \c CXChildVisit_Break.
2951 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002952 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002953 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002954 * definition, have no children).
2955 *
2956 * \param visitor the visitor function that will be invoked for each
2957 * child of \p parent.
2958 *
2959 * \param client_data pointer data supplied by the client, which will
2960 * be passed to the visitor each time it is invoked.
2961 *
2962 * \returns a non-zero value if the traversal was terminated
2963 * prematurely by the visitor returning \c CXChildVisit_Break.
2964 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002965CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002966 CXCursorVisitor visitor,
2967 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002968#ifdef __has_feature
2969# if __has_feature(blocks)
2970/**
2971 * \brief Visitor invoked for each cursor found by a traversal.
2972 *
2973 * This visitor block will be invoked for each cursor found by
2974 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2975 * visited, its second argument is the parent visitor for that cursor.
2976 *
2977 * The visitor should return one of the \c CXChildVisitResult values
2978 * to direct clang_visitChildrenWithBlock().
2979 */
2980typedef enum CXChildVisitResult
2981 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2982
2983/**
2984 * Visits the children of a cursor using the specified block. Behaves
2985 * identically to clang_visitChildren() in all other respects.
2986 */
2987unsigned clang_visitChildrenWithBlock(CXCursor parent,
2988 CXCursorVisitorBlock block);
2989# endif
2990#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002991
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002992/**
2993 * @}
2994 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002995
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002996/**
2997 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2998 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002999 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003000 * across translation units, by providing the names of the entities referenced
3001 * by cursors, follow reference cursors to the declarations they reference,
3002 * and associate declarations with their definitions.
3003 *
3004 * @{
3005 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003006
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003007/**
3008 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3009 * by the given cursor.
3010 *
3011 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3012 * entity (function, class, variable, etc.) within a program. USRs can be
3013 * compared across translation units to determine, e.g., when references in
3014 * one translation refer to an entity defined in another translation unit.
3015 */
3016CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3017
3018/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003019 * \brief Construct a USR for a specified Objective-C class.
3020 */
3021CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3022
3023/**
3024 * \brief Construct a USR for a specified Objective-C category.
3025 */
3026CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00003027 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003028 const char *category_name);
3029
3030/**
3031 * \brief Construct a USR for a specified Objective-C protocol.
3032 */
3033CINDEX_LINKAGE CXString
3034 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3035
3036
3037/**
3038 * \brief Construct a USR for a specified Objective-C instance variable and
3039 * the USR for its containing class.
3040 */
3041CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3042 CXString classUSR);
3043
3044/**
3045 * \brief Construct a USR for a specified Objective-C method and
3046 * the USR for its containing class.
3047 */
3048CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3049 unsigned isInstanceMethod,
3050 CXString classUSR);
3051
3052/**
3053 * \brief Construct a USR for a specified Objective-C property and the USR
3054 * for its containing class.
3055 */
3056CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3057 CXString classUSR);
3058
3059/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003060 * \brief Retrieve a name for the entity referenced by this cursor.
3061 */
3062CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3063
Douglas Gregor358559d2010-10-02 22:49:11 +00003064/**
Argyrios Kyrtzidisba1da142012-03-30 20:58:35 +00003065 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3066 * Most of the times there is only one range for the complete spelling but for
3067 * objc methods and objc message expressions, there are multiple pieces for each
3068 * selector identifier.
3069 *
3070 * \param pieceIndex the index of the spelling name piece. If this is greater
3071 * than the actual number of pieces, it will return a NULL (invalid) range.
3072 *
3073 * \param options Reserved.
3074 */
3075CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3076 unsigned pieceIndex,
3077 unsigned options);
3078
3079/**
Douglas Gregor358559d2010-10-02 22:49:11 +00003080 * \brief Retrieve the display name for the entity referenced by this cursor.
3081 *
3082 * The display name contains extra information that helps identify the cursor,
3083 * such as the parameters of a function or template or the arguments of a
3084 * class template specialization.
3085 */
3086CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3087
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003088/** \brief For a cursor that is a reference, retrieve a cursor representing the
3089 * entity that it references.
3090 *
3091 * Reference cursors refer to other entities in the AST. For example, an
3092 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003093 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003094 * cursor for the superclass reference. If the input cursor is a declaration or
3095 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003096 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003097 */
3098CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00003099
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003100/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003101 * \brief For a cursor that is either a reference to or a declaration
3102 * of some entity, retrieve a cursor that describes the definition of
3103 * that entity.
3104 *
3105 * Some entities can be declared multiple times within a translation
3106 * unit, but only one of those declarations can also be a
3107 * definition. For example, given:
3108 *
3109 * \code
3110 * int f(int, int);
3111 * int g(int x, int y) { return f(x, y); }
3112 * int f(int a, int b) { return a + b; }
3113 * int f(int, int);
3114 * \endcode
3115 *
3116 * there are three declarations of the function "f", but only the
3117 * second one is a definition. The clang_getCursorDefinition()
3118 * function will take any cursor pointing to a declaration of "f"
3119 * (the first or fourth lines of the example) or a cursor referenced
3120 * that uses "f" (the call to "f' inside "g") and will return a
3121 * declaration cursor pointing to the definition (the second "f"
3122 * declaration).
3123 *
3124 * If given a cursor for which there is no corresponding definition,
3125 * e.g., because there is no definition of that entity within this
3126 * translation unit, returns a NULL cursor.
3127 */
3128CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3129
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003130/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003131 * \brief Determine whether the declaration pointed to by this cursor
3132 * is also a definition of that entity.
3133 */
3134CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3135
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003136/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003137 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3138 *
3139 * In the C family of languages, many kinds of entities can be declared several
3140 * times within a single translation unit. For example, a structure type can
3141 * be forward-declared (possibly multiple times) and later defined:
3142 *
3143 * \code
3144 * struct X;
3145 * struct X;
3146 * struct X {
3147 * int member;
3148 * };
3149 * \endcode
3150 *
3151 * The declarations and the definition of \c X are represented by three
3152 * different cursors, all of which are declarations of the same underlying
3153 * entity. One of these cursor is considered the "canonical" cursor, which
3154 * is effectively the representative for the underlying entity. One can
3155 * determine if two cursors are declarations of the same underlying entity by
3156 * comparing their canonical cursors.
3157 *
3158 * \returns The canonical cursor for the entity referred to by the given cursor.
3159 */
3160CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3161
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003162
3163/**
3164 * \brief If the cursor points to a selector identifier in a objc method or
3165 * message expression, this returns the selector index.
3166 *
3167 * After getting a cursor with \see clang_getCursor, this can be called to
3168 * determine if the location points to a selector identifier.
3169 *
3170 * \returns The selector index if the cursor is an objc method or message
3171 * expression and the cursor is pointing to a selector identifier, or -1
3172 * otherwise.
3173 */
3174CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3175
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003176/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003177 * @}
3178 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003179
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003180/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003181 * \defgroup CINDEX_CPP C++ AST introspection
3182 *
3183 * The routines in this group provide access information in the ASTs specific
3184 * to C++ language features.
3185 *
3186 * @{
3187 */
3188
3189/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003190 * \brief Determine if a C++ member function or member function template is
3191 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003192 */
3193CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3194
3195/**
Douglas Gregor211924b2011-05-12 15:17:24 +00003196 * \brief Determine if a C++ member function or member function template is
3197 * explicitly declared 'virtual' or if it overrides a virtual method from
3198 * one of the base classes.
3199 */
3200CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3201
3202/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003203 * \brief Given a cursor that represents a template, determine
3204 * the cursor kind of the specializations would be generated by instantiating
3205 * the template.
3206 *
3207 * This routine can be used to determine what flavor of function template,
3208 * class template, or class template partial specialization is stored in the
3209 * cursor. For example, it can describe whether a class template cursor is
3210 * declared with "struct", "class" or "union".
3211 *
3212 * \param C The cursor to query. This cursor should represent a template
3213 * declaration.
3214 *
3215 * \returns The cursor kind of the specializations that would be generated
3216 * by instantiating the template \p C. If \p C is not a template, returns
3217 * \c CXCursor_NoDeclFound.
3218 */
3219CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3220
3221/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00003222 * \brief Given a cursor that may represent a specialization or instantiation
3223 * of a template, retrieve the cursor that represents the template that it
3224 * specializes or from which it was instantiated.
3225 *
3226 * This routine determines the template involved both for explicit
3227 * specializations of templates and for implicit instantiations of the template,
3228 * both of which are referred to as "specializations". For a class template
3229 * specialization (e.g., \c std::vector<bool>), this routine will return
3230 * either the primary template (\c std::vector) or, if the specialization was
3231 * instantiated from a class template partial specialization, the class template
3232 * partial specialization. For a class template partial specialization and a
3233 * function template specialization (including instantiations), this
3234 * this routine will return the specialized template.
3235 *
3236 * For members of a class template (e.g., member functions, member classes, or
3237 * static data members), returns the specialized or instantiated member.
3238 * Although not strictly "templates" in the C++ language, members of class
3239 * templates have the same notions of specializations and instantiations that
3240 * templates do, so this routine treats them similarly.
3241 *
3242 * \param C A cursor that may be a specialization of a template or a member
3243 * of a template.
3244 *
3245 * \returns If the given cursor is a specialization or instantiation of a
3246 * template or a member thereof, the template or member that it specializes or
3247 * from which it was instantiated. Otherwise, returns a NULL cursor.
3248 */
3249CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00003250
3251/**
3252 * \brief Given a cursor that references something else, return the source range
3253 * covering that reference.
3254 *
3255 * \param C A cursor pointing to a member reference, a declaration reference, or
3256 * an operator call.
3257 * \param NameFlags A bitset with three independent flags:
3258 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3259 * CXNameRange_WantSinglePiece.
3260 * \param PieceIndex For contiguous names or when passing the flag
3261 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3262 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer48d798c2012-06-02 10:20:41 +00003263 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregor430d7a12011-07-25 17:48:11 +00003264 * pieces of the name. See also CXNameRange_WantSinglePiece.
3265 *
3266 * \returns The piece of the name pointed to by the given cursor. If there is no
3267 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3268 */
Francois Pichet48a8d142011-07-25 22:00:44 +00003269CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3270 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00003271 unsigned PieceIndex);
3272
3273enum CXNameRefFlags {
3274 /**
3275 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3276 * range.
3277 */
3278 CXNameRange_WantQualifier = 0x1,
3279
3280 /**
3281 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
3282 * the range.
3283 */
3284 CXNameRange_WantTemplateArgs = 0x2,
3285
3286 /**
3287 * \brief If the name is non-contiguous, return the full spanning range.
3288 *
3289 * Non-contiguous names occur in Objective-C when a selector with two or more
3290 * parameters is used, or in C++ when using an operator:
3291 * \code
3292 * [object doSomething:here withValue:there]; // ObjC
3293 * return some_vector[1]; // C++
3294 * \endcode
3295 */
3296 CXNameRange_WantSinglePiece = 0x4
3297};
Douglas Gregore0329ac2010-09-02 00:07:54 +00003298
3299/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003300 * @}
3301 */
3302
3303/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003304 * \defgroup CINDEX_LEX Token extraction and manipulation
3305 *
3306 * The routines in this group provide access to the tokens within a
3307 * translation unit, along with a semantic mapping of those tokens to
3308 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003309 *
3310 * @{
3311 */
3312
3313/**
3314 * \brief Describes a kind of token.
3315 */
3316typedef enum CXTokenKind {
3317 /**
3318 * \brief A token that contains some kind of punctuation.
3319 */
3320 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003321
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003322 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003323 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003324 */
3325 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003326
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003327 /**
3328 * \brief An identifier (that is not a keyword).
3329 */
3330 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003331
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003332 /**
3333 * \brief A numeric, string, or character literal.
3334 */
3335 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003336
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003337 /**
3338 * \brief A comment.
3339 */
3340 CXToken_Comment
3341} CXTokenKind;
3342
3343/**
3344 * \brief Describes a single preprocessing token.
3345 */
3346typedef struct {
3347 unsigned int_data[4];
3348 void *ptr_data;
3349} CXToken;
3350
3351/**
3352 * \brief Determine the kind of the given token.
3353 */
3354CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003355
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003356/**
3357 * \brief Determine the spelling of the given token.
3358 *
3359 * The spelling of a token is the textual representation of that token, e.g.,
3360 * the text of an identifier or keyword.
3361 */
3362CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003363
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003364/**
3365 * \brief Retrieve the source location of the given token.
3366 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003367CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003368 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003369
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003370/**
3371 * \brief Retrieve a source range that covers the given token.
3372 */
3373CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
3374
3375/**
3376 * \brief Tokenize the source code described by the given range into raw
3377 * lexical tokens.
3378 *
3379 * \param TU the translation unit whose text is being tokenized.
3380 *
3381 * \param Range the source range in which text should be tokenized. All of the
3382 * tokens produced by tokenization will fall within this source range,
3383 *
3384 * \param Tokens this pointer will be set to point to the array of tokens
3385 * that occur within the given source range. The returned pointer must be
3386 * freed with clang_disposeTokens() before the translation unit is destroyed.
3387 *
3388 * \param NumTokens will be set to the number of tokens in the \c *Tokens
3389 * array.
3390 *
3391 */
3392CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
3393 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003394
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003395/**
3396 * \brief Annotate the given set of tokens by providing cursors for each token
3397 * that can be mapped to a specific entity within the abstract syntax tree.
3398 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003399 * This token-annotation routine is equivalent to invoking
3400 * clang_getCursor() for the source locations of each of the
3401 * tokens. The cursors provided are filtered, so that only those
3402 * cursors that have a direct correspondence to the token are
3403 * accepted. For example, given a function call \c f(x),
3404 * clang_getCursor() would provide the following cursors:
3405 *
3406 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
3407 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
3408 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
3409 *
3410 * Only the first and last of these cursors will occur within the
3411 * annotate, since the tokens "f" and "x' directly refer to a function
3412 * and a variable, respectively, but the parentheses are just a small
3413 * part of the full syntax of the function call expression, which is
3414 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003415 *
3416 * \param TU the translation unit that owns the given tokens.
3417 *
3418 * \param Tokens the set of tokens to annotate.
3419 *
3420 * \param NumTokens the number of tokens in \p Tokens.
3421 *
3422 * \param Cursors an array of \p NumTokens cursors, whose contents will be
3423 * replaced with the cursors corresponding to each token.
3424 */
3425CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
3426 CXToken *Tokens, unsigned NumTokens,
3427 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003428
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003429/**
3430 * \brief Free the given set of tokens.
3431 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003432CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003433 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003434
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003435/**
3436 * @}
3437 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003438
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003439/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003440 * \defgroup CINDEX_DEBUG Debugging facilities
3441 *
3442 * These routines are used for testing and debugging, only, and should not
3443 * be relied upon.
3444 *
3445 * @{
3446 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003447
Steve Naroff4ade6d62009-09-23 17:52:52 +00003448/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00003449CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003450CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3451 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00003452 const char **endBuf,
3453 unsigned *startLine,
3454 unsigned *startColumn,
3455 unsigned *endLine,
3456 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00003457CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00003458CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
3459 unsigned stack_size);
3460
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003461/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003462 * @}
3463 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003464
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003465/**
3466 * \defgroup CINDEX_CODE_COMPLET Code completion
3467 *
3468 * Code completion involves taking an (incomplete) source file, along with
3469 * knowledge of where the user is actively editing that file, and suggesting
3470 * syntactically- and semantically-valid constructs that the user might want to
3471 * use at that particular point in the source code. These data structures and
3472 * routines provide support for code completion.
3473 *
3474 * @{
3475 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003476
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003477/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003478 * \brief A semantic string that describes a code-completion result.
3479 *
3480 * A semantic string that describes the formatting of a code-completion
3481 * result as a single "template" of text that should be inserted into the
3482 * source buffer when a particular code-completion result is selected.
3483 * Each semantic string is made up of some number of "chunks", each of which
3484 * contains some text along with a description of what that text means, e.g.,
3485 * the name of the entity being referenced, whether the text chunk is part of
3486 * the template, or whether it is a "placeholder" that the user should replace
3487 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003488 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003489 */
3490typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003491
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003492/**
3493 * \brief A single result of code completion.
3494 */
3495typedef struct {
3496 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003497 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003498 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003499 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003500 * *Decl cursor kinds), describing the entity that the completion is
3501 * referring to.
3502 *
3503 * \todo In the future, we would like to provide a full cursor, to allow
3504 * the client to extract additional information from declaration.
3505 */
3506 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003507
3508 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003509 * \brief The code-completion string that describes how to insert this
3510 * code-completion result into the editing buffer.
3511 */
3512 CXCompletionString CompletionString;
3513} CXCompletionResult;
3514
3515/**
3516 * \brief Describes a single piece of text within a code-completion string.
3517 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003518 * Each "chunk" within a code-completion string (\c CXCompletionString) is
3519 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003520 * should be interpreted by the client or is another completion string.
3521 */
3522enum CXCompletionChunkKind {
3523 /**
3524 * \brief A code-completion string that describes "optional" text that
3525 * could be a part of the template (but is not required).
3526 *
3527 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003528 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003529 * \c clang_getCompletionChunkCompletionString(). The code-completion string
3530 * describes an additional part of the template that is completely optional.
3531 * For example, optional chunks can be used to describe the placeholders for
3532 * arguments that match up with defaulted function parameters, e.g. given:
3533 *
3534 * \code
3535 * void f(int x, float y = 3.14, double z = 2.71828);
3536 * \endcode
3537 *
3538 * The code-completion string for this function would contain:
3539 * - a TypedText chunk for "f".
3540 * - a LeftParen chunk for "(".
3541 * - a Placeholder chunk for "int x"
3542 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
3543 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00003544 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003545 * - an Optional chunk containing the last defaulted argument:
3546 * - a Comma chunk for ","
3547 * - a Placeholder chunk for "double z"
3548 * - a RightParen chunk for ")"
3549 *
Daniel Dunbar71570182010-02-17 08:07:44 +00003550 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003551 * - Completely ignore optional chunks, in which case the template for the
3552 * function "f" would only include the first parameter ("int x").
3553 * - Fully expand all optional chunks, in which case the template for the
3554 * function "f" would have all of the parameters.
3555 */
3556 CXCompletionChunk_Optional,
3557 /**
3558 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003559 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003560 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003561 * There will be exactly one "typed text" chunk in a semantic string, which
3562 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003563 * declaration that could be used at the current code point. Clients are
3564 * expected to filter the code-completion results based on the text in this
3565 * chunk.
3566 */
3567 CXCompletionChunk_TypedText,
3568 /**
3569 * \brief Text that should be inserted as part of a code-completion result.
3570 *
3571 * A "text" chunk represents text that is part of the template to be
3572 * inserted into user code should this particular code-completion result
3573 * be selected.
3574 */
3575 CXCompletionChunk_Text,
3576 /**
3577 * \brief Placeholder text that should be replaced by the user.
3578 *
3579 * A "placeholder" chunk marks a place where the user should insert text
3580 * into the code-completion template. For example, placeholders might mark
3581 * the function parameters for a function declaration, to indicate that the
3582 * user should provide arguments for each of those parameters. The actual
3583 * text in a placeholder is a suggestion for the text to display before
3584 * the user replaces the placeholder with real code.
3585 */
3586 CXCompletionChunk_Placeholder,
3587 /**
3588 * \brief Informative text that should be displayed but never inserted as
3589 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003590 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003591 * An "informative" chunk contains annotations that can be displayed to
3592 * help the user decide whether a particular code-completion result is the
3593 * right option, but which is not part of the actual template to be inserted
3594 * by code completion.
3595 */
3596 CXCompletionChunk_Informative,
3597 /**
3598 * \brief Text that describes the current parameter when code-completion is
3599 * referring to function call, message send, or template specialization.
3600 *
3601 * A "current parameter" chunk occurs when code-completion is providing
3602 * information about a parameter corresponding to the argument at the
3603 * code-completion point. For example, given a function
3604 *
3605 * \code
3606 * int add(int x, int y);
3607 * \endcode
3608 *
3609 * and the source code \c add(, where the code-completion point is after the
3610 * "(", the code-completion string will contain a "current parameter" chunk
3611 * for "int x", indicating that the current argument will initialize that
3612 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003613 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003614 * "current paremeter" chunk to "int y".
3615 */
3616 CXCompletionChunk_CurrentParameter,
3617 /**
3618 * \brief A left parenthesis ('('), used to initiate a function call or
3619 * signal the beginning of a function parameter list.
3620 */
3621 CXCompletionChunk_LeftParen,
3622 /**
3623 * \brief A right parenthesis (')'), used to finish a function call or
3624 * signal the end of a function parameter list.
3625 */
3626 CXCompletionChunk_RightParen,
3627 /**
3628 * \brief A left bracket ('[').
3629 */
3630 CXCompletionChunk_LeftBracket,
3631 /**
3632 * \brief A right bracket (']').
3633 */
3634 CXCompletionChunk_RightBracket,
3635 /**
3636 * \brief A left brace ('{').
3637 */
3638 CXCompletionChunk_LeftBrace,
3639 /**
3640 * \brief A right brace ('}').
3641 */
3642 CXCompletionChunk_RightBrace,
3643 /**
3644 * \brief A left angle bracket ('<').
3645 */
3646 CXCompletionChunk_LeftAngle,
3647 /**
3648 * \brief A right angle bracket ('>').
3649 */
3650 CXCompletionChunk_RightAngle,
3651 /**
3652 * \brief A comma separator (',').
3653 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003654 CXCompletionChunk_Comma,
3655 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003656 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003657 *
3658 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003659 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003660 * expression using the given completion string would have.
3661 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00003662 CXCompletionChunk_ResultType,
3663 /**
3664 * \brief A colon (':').
3665 */
3666 CXCompletionChunk_Colon,
3667 /**
3668 * \brief A semicolon (';').
3669 */
3670 CXCompletionChunk_SemiColon,
3671 /**
3672 * \brief An '=' sign.
3673 */
3674 CXCompletionChunk_Equal,
3675 /**
3676 * Horizontal space (' ').
3677 */
3678 CXCompletionChunk_HorizontalSpace,
3679 /**
3680 * Vertical space ('\n'), after which it is generally a good idea to
3681 * perform indentation.
3682 */
3683 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003684};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003685
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003686/**
3687 * \brief Determine the kind of a particular chunk within a completion string.
3688 *
3689 * \param completion_string the completion string to query.
3690 *
3691 * \param chunk_number the 0-based index of the chunk in the completion string.
3692 *
3693 * \returns the kind of the chunk at the index \c chunk_number.
3694 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003695CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003696clang_getCompletionChunkKind(CXCompletionString completion_string,
3697 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003698
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003699/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003700 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003701 * completion string.
3702 *
3703 * \param completion_string the completion string to query.
3704 *
3705 * \param chunk_number the 0-based index of the chunk in the completion string.
3706 *
3707 * \returns the text associated with the chunk at index \c chunk_number.
3708 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00003709CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003710clang_getCompletionChunkText(CXCompletionString completion_string,
3711 unsigned chunk_number);
3712
3713/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003714 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003715 * within a completion string.
3716 *
3717 * \param completion_string the completion string to query.
3718 *
3719 * \param chunk_number the 0-based index of the chunk in the completion string.
3720 *
3721 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003722 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003723 */
3724CINDEX_LINKAGE CXCompletionString
3725clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
3726 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003727
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003728/**
3729 * \brief Retrieve the number of chunks in the given code-completion string.
3730 */
3731CINDEX_LINKAGE unsigned
3732clang_getNumCompletionChunks(CXCompletionString completion_string);
3733
3734/**
Douglas Gregor12e13132010-05-26 22:00:08 +00003735 * \brief Determine the priority of this code completion.
3736 *
3737 * The priority of a code completion indicates how likely it is that this
3738 * particular completion is the completion that the user will select. The
3739 * priority is selected by various internal heuristics.
3740 *
3741 * \param completion_string The completion string to query.
3742 *
3743 * \returns The priority of this completion string. Smaller values indicate
3744 * higher-priority (more likely) completions.
3745 */
3746CINDEX_LINKAGE unsigned
3747clang_getCompletionPriority(CXCompletionString completion_string);
3748
3749/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00003750 * \brief Determine the availability of the entity that this code-completion
3751 * string refers to.
3752 *
3753 * \param completion_string The completion string to query.
3754 *
3755 * \returns The availability of the completion string.
3756 */
3757CINDEX_LINKAGE enum CXAvailabilityKind
3758clang_getCompletionAvailability(CXCompletionString completion_string);
3759
3760/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003761 * \brief Retrieve the number of annotations associated with the given
3762 * completion string.
3763 *
3764 * \param completion_string the completion string to query.
3765 *
3766 * \returns the number of annotations associated with the given completion
3767 * string.
3768 */
3769CINDEX_LINKAGE unsigned
3770clang_getCompletionNumAnnotations(CXCompletionString completion_string);
3771
3772/**
3773 * \brief Retrieve the annotation associated with the given completion string.
3774 *
3775 * \param completion_string the completion string to query.
3776 *
3777 * \param annotation_number the 0-based index of the annotation of the
3778 * completion string.
3779 *
3780 * \returns annotation string associated with the completion at index
3781 * \c annotation_number, or a NULL string if that annotation is not available.
3782 */
3783CINDEX_LINKAGE CXString
3784clang_getCompletionAnnotation(CXCompletionString completion_string,
3785 unsigned annotation_number);
3786
3787/**
Douglas Gregorba103062012-03-27 23:34:16 +00003788 * \brief Retrieve the parent context of the given completion string.
3789 *
3790 * The parent context of a completion string is the semantic parent of
3791 * the declaration (if any) that the code completion represents. For example,
3792 * a code completion for an Objective-C method would have the method's class
3793 * or protocol as its context.
3794 *
3795 * \param completion_string The code completion string whose parent is
3796 * being queried.
3797 *
3798 * \param kind If non-NULL, will be set to the kind of the parent context,
3799 * or CXCursor_NotImplemented if there is no context.
3800 *
3801 * \param Returns the name of the completion parent, e.g., "NSObject" if
3802 * the completion string represents a method in the NSObject class.
3803 */
3804CINDEX_LINKAGE CXString
3805clang_getCompletionParent(CXCompletionString completion_string,
3806 enum CXCursorKind *kind);
3807/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00003808 * \brief Retrieve a completion string for an arbitrary declaration or macro
3809 * definition cursor.
3810 *
3811 * \param cursor The cursor to query.
3812 *
3813 * \returns A non-context-sensitive completion string for declaration and macro
3814 * definition cursors, or NULL for other kinds of cursors.
3815 */
3816CINDEX_LINKAGE CXCompletionString
3817clang_getCursorCompletionString(CXCursor cursor);
3818
3819/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003820 * \brief Contains the results of code-completion.
3821 *
3822 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00003823 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00003824 * \c clang_disposeCodeCompleteResults.
3825 */
3826typedef struct {
3827 /**
3828 * \brief The code-completion results.
3829 */
3830 CXCompletionResult *Results;
3831
3832 /**
3833 * \brief The number of code-completion results stored in the
3834 * \c Results array.
3835 */
3836 unsigned NumResults;
3837} CXCodeCompleteResults;
3838
3839/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003840 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3841 * modify its behavior.
3842 *
3843 * The enumerators in this enumeration can be bitwise-OR'd together to
3844 * provide multiple options to \c clang_codeCompleteAt().
3845 */
3846enum CXCodeComplete_Flags {
3847 /**
3848 * \brief Whether to include macros within the set of code
3849 * completions returned.
3850 */
3851 CXCodeComplete_IncludeMacros = 0x01,
3852
3853 /**
3854 * \brief Whether to include code patterns for language constructs
3855 * within the set of code completions, e.g., for loops.
3856 */
3857 CXCodeComplete_IncludeCodePatterns = 0x02
3858};
3859
3860/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003861 * \brief Bits that represent the context under which completion is occurring.
3862 *
3863 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3864 * contexts are occurring simultaneously.
3865 */
3866enum CXCompletionContext {
3867 /**
3868 * \brief The context for completions is unexposed, as only Clang results
3869 * should be included. (This is equivalent to having no context bits set.)
3870 */
3871 CXCompletionContext_Unexposed = 0,
3872
3873 /**
3874 * \brief Completions for any possible type should be included in the results.
3875 */
3876 CXCompletionContext_AnyType = 1 << 0,
3877
3878 /**
3879 * \brief Completions for any possible value (variables, function calls, etc.)
3880 * should be included in the results.
3881 */
3882 CXCompletionContext_AnyValue = 1 << 1,
3883 /**
3884 * \brief Completions for values that resolve to an Objective-C object should
3885 * be included in the results.
3886 */
3887 CXCompletionContext_ObjCObjectValue = 1 << 2,
3888 /**
3889 * \brief Completions for values that resolve to an Objective-C selector
3890 * should be included in the results.
3891 */
3892 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3893 /**
3894 * \brief Completions for values that resolve to a C++ class type should be
3895 * included in the results.
3896 */
3897 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3898
3899 /**
3900 * \brief Completions for fields of the member being accessed using the dot
3901 * operator should be included in the results.
3902 */
3903 CXCompletionContext_DotMemberAccess = 1 << 5,
3904 /**
3905 * \brief Completions for fields of the member being accessed using the arrow
3906 * operator should be included in the results.
3907 */
3908 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3909 /**
3910 * \brief Completions for properties of the Objective-C object being accessed
3911 * using the dot operator should be included in the results.
3912 */
3913 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3914
3915 /**
3916 * \brief Completions for enum tags should be included in the results.
3917 */
3918 CXCompletionContext_EnumTag = 1 << 8,
3919 /**
3920 * \brief Completions for union tags should be included in the results.
3921 */
3922 CXCompletionContext_UnionTag = 1 << 9,
3923 /**
3924 * \brief Completions for struct tags should be included in the results.
3925 */
3926 CXCompletionContext_StructTag = 1 << 10,
3927
3928 /**
3929 * \brief Completions for C++ class names should be included in the results.
3930 */
3931 CXCompletionContext_ClassTag = 1 << 11,
3932 /**
3933 * \brief Completions for C++ namespaces and namespace aliases should be
3934 * included in the results.
3935 */
3936 CXCompletionContext_Namespace = 1 << 12,
3937 /**
3938 * \brief Completions for C++ nested name specifiers should be included in
3939 * the results.
3940 */
3941 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3942
3943 /**
3944 * \brief Completions for Objective-C interfaces (classes) should be included
3945 * in the results.
3946 */
3947 CXCompletionContext_ObjCInterface = 1 << 14,
3948 /**
3949 * \brief Completions for Objective-C protocols should be included in
3950 * the results.
3951 */
3952 CXCompletionContext_ObjCProtocol = 1 << 15,
3953 /**
3954 * \brief Completions for Objective-C categories should be included in
3955 * the results.
3956 */
3957 CXCompletionContext_ObjCCategory = 1 << 16,
3958 /**
3959 * \brief Completions for Objective-C instance messages should be included
3960 * in the results.
3961 */
3962 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3963 /**
3964 * \brief Completions for Objective-C class messages should be included in
3965 * the results.
3966 */
3967 CXCompletionContext_ObjCClassMessage = 1 << 18,
3968 /**
3969 * \brief Completions for Objective-C selector names should be included in
3970 * the results.
3971 */
3972 CXCompletionContext_ObjCSelectorName = 1 << 19,
3973
3974 /**
3975 * \brief Completions for preprocessor macro names should be included in
3976 * the results.
3977 */
3978 CXCompletionContext_MacroName = 1 << 20,
3979
3980 /**
3981 * \brief Natural language completions should be included in the results.
3982 */
3983 CXCompletionContext_NaturalLanguage = 1 << 21,
3984
3985 /**
3986 * \brief The current context is unknown, so set all contexts.
3987 */
3988 CXCompletionContext_Unknown = ((1 << 22) - 1)
3989};
3990
3991/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003992 * \brief Returns a default set of code-completion options that can be
3993 * passed to\c clang_codeCompleteAt().
3994 */
3995CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3996
3997/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003998 * \brief Perform code completion at a given location in a translation unit.
3999 *
4000 * This function performs code completion at a particular file, line, and
4001 * column within source code, providing results that suggest potential
4002 * code snippets based on the context of the completion. The basic model
4003 * for code completion is that Clang will parse a complete source file,
4004 * performing syntax checking up to the location where code-completion has
4005 * been requested. At that point, a special code-completion token is passed
4006 * to the parser, which recognizes this token and determines, based on the
4007 * current location in the C/Objective-C/C++ grammar and the state of
4008 * semantic analysis, what completions to provide. These completions are
4009 * returned via a new \c CXCodeCompleteResults structure.
4010 *
4011 * Code completion itself is meant to be triggered by the client when the
4012 * user types punctuation characters or whitespace, at which point the
4013 * code-completion location will coincide with the cursor. For example, if \c p
4014 * is a pointer, code-completion might be triggered after the "-" and then
4015 * after the ">" in \c p->. When the code-completion location is afer the ">",
4016 * the completion results will provide, e.g., the members of the struct that
4017 * "p" points to. The client is responsible for placing the cursor at the
4018 * beginning of the token currently being typed, then filtering the results
4019 * based on the contents of the token. For example, when code-completing for
4020 * the expression \c p->get, the client should provide the location just after
4021 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4022 * client can filter the results based on the current token text ("get"), only
4023 * showing those results that start with "get". The intent of this interface
4024 * is to separate the relatively high-latency acquisition of code-completion
4025 * results from the filtering of results on a per-character basis, which must
4026 * have a lower latency.
4027 *
4028 * \param TU The translation unit in which code-completion should
4029 * occur. The source files for this translation unit need not be
4030 * completely up-to-date (and the contents of those source files may
4031 * be overridden via \p unsaved_files). Cursors referring into the
4032 * translation unit may be invalidated by this invocation.
4033 *
4034 * \param complete_filename The name of the source file where code
4035 * completion should be performed. This filename may be any file
4036 * included in the translation unit.
4037 *
4038 * \param complete_line The line at which code-completion should occur.
4039 *
4040 * \param complete_column The column at which code-completion should occur.
4041 * Note that the column should point just after the syntactic construct that
4042 * initiated code completion, and not in the middle of a lexical token.
4043 *
4044 * \param unsaved_files the Tiles that have not yet been saved to disk
4045 * but may be required for parsing or code completion, including the
4046 * contents of those files. The contents and name of these files (as
4047 * specified by CXUnsavedFile) are copied when necessary, so the
4048 * client only needs to guarantee their validity until the call to
4049 * this function returns.
4050 *
4051 * \param num_unsaved_files The number of unsaved file entries in \p
4052 * unsaved_files.
4053 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00004054 * \param options Extra options that control the behavior of code
4055 * completion, expressed as a bitwise OR of the enumerators of the
4056 * CXCodeComplete_Flags enumeration. The
4057 * \c clang_defaultCodeCompleteOptions() function returns a default set
4058 * of code-completion options.
4059 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004060 * \returns If successful, a new \c CXCodeCompleteResults structure
4061 * containing code-completion results, which should eventually be
4062 * freed with \c clang_disposeCodeCompleteResults(). If code
4063 * completion fails, returns NULL.
4064 */
4065CINDEX_LINKAGE
4066CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4067 const char *complete_filename,
4068 unsigned complete_line,
4069 unsigned complete_column,
4070 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00004071 unsigned num_unsaved_files,
4072 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004073
4074/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00004075 * \brief Sort the code-completion results in case-insensitive alphabetical
4076 * order.
4077 *
4078 * \param Results The set of results to sort.
4079 * \param NumResults The number of results in \p Results.
4080 */
4081CINDEX_LINKAGE
4082void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4083 unsigned NumResults);
4084
4085/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004086 * \brief Free the given set of code-completion results.
4087 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004088CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00004089void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00004090
Douglas Gregor20d416c2010-01-20 01:10:47 +00004091/**
Douglas Gregora88084b2010-02-18 18:08:43 +00004092 * \brief Determine the number of diagnostics produced prior to the
4093 * location where code completion was performed.
4094 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004095CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004096unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4097
4098/**
4099 * \brief Retrieve a diagnostic associated with the given code completion.
4100 *
4101 * \param Result the code completion results to query.
4102 * \param Index the zero-based diagnostic number to retrieve.
4103 *
4104 * \returns the requested diagnostic. This diagnostic must be freed
4105 * via a call to \c clang_disposeDiagnostic().
4106 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004107CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004108CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4109 unsigned Index);
4110
4111/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004112 * \brief Determines what compeltions are appropriate for the context
4113 * the given code completion.
4114 *
4115 * \param Results the code completion results to query
4116 *
4117 * \returns the kinds of completions that are appropriate for use
4118 * along with the given code completion results.
4119 */
4120CINDEX_LINKAGE
4121unsigned long long clang_codeCompleteGetContexts(
4122 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00004123
4124/**
4125 * \brief Returns the cursor kind for the container for the current code
4126 * completion context. The container is only guaranteed to be set for
4127 * contexts where a container exists (i.e. member accesses or Objective-C
4128 * message sends); if there is not a container, this function will return
4129 * CXCursor_InvalidCode.
4130 *
4131 * \param Results the code completion results to query
4132 *
4133 * \param IsIncomplete on return, this value will be false if Clang has complete
4134 * information about the container. If Clang does not have complete
4135 * information, this value will be true.
4136 *
4137 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4138 * container
4139 */
4140CINDEX_LINKAGE
4141enum CXCursorKind clang_codeCompleteGetContainerKind(
4142 CXCodeCompleteResults *Results,
4143 unsigned *IsIncomplete);
4144
4145/**
4146 * \brief Returns the USR for the container for the current code completion
4147 * context. If there is not a container for the current context, this
4148 * function will return the empty string.
4149 *
4150 * \param Results the code completion results to query
4151 *
4152 * \returns the USR for the container
4153 */
4154CINDEX_LINKAGE
4155CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00004156
Douglas Gregor0a47d692011-07-26 15:24:30 +00004157
4158/**
4159 * \brief Returns the currently-entered selector for an Objective-C message
4160 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4161 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4162 * CXCompletionContext_ObjCClassMessage.
4163 *
4164 * \param Results the code completion results to query
4165 *
4166 * \returns the selector (or partial selector) that has been entered thus far
4167 * for an Objective-C message send.
4168 */
4169CINDEX_LINKAGE
4170CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4171
Douglas Gregor3da626b2011-07-07 16:03:39 +00004172/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00004173 * @}
4174 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004175
4176
Ted Kremenek04bb7162010-01-22 22:44:15 +00004177/**
4178 * \defgroup CINDEX_MISC Miscellaneous utility functions
4179 *
4180 * @{
4181 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00004182
4183/**
4184 * \brief Return a version string, suitable for showing to a user, but not
4185 * intended to be parsed (the format is not guaranteed to be stable).
4186 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00004187CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00004188
Ted Kremenekd2427dd2011-03-18 23:05:39 +00004189
4190/**
4191 * \brief Enable/disable crash recovery.
4192 *
4193 * \param Flag to indicate if crash recovery is enabled. A non-zero value
4194 * enables crash recovery, while 0 disables it.
4195 */
4196CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4197
Ted Kremenek16b55a72010-01-26 19:31:51 +00004198 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00004199 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00004200 * (used with clang_getInclusions()).
4201 *
4202 * This visitor function will be invoked by clang_getInclusions() for each
4203 * file included (either at the top-level or by #include directives) within
4204 * a translation unit. The first argument is the file being included, and
4205 * the second and third arguments provide the inclusion stack. The
4206 * array is sorted in order of immediate inclusion. For example,
4207 * the first element refers to the location that included 'included_file'.
4208 */
4209typedef void (*CXInclusionVisitor)(CXFile included_file,
4210 CXSourceLocation* inclusion_stack,
4211 unsigned include_len,
4212 CXClientData client_data);
4213
4214/**
4215 * \brief Visit the set of preprocessor inclusions in a translation unit.
4216 * The visitor function is called with the provided data for every included
4217 * file. This does not include headers included by the PCH file (unless one
4218 * is inspecting the inclusions in the PCH file itself).
4219 */
4220CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4221 CXInclusionVisitor visitor,
4222 CXClientData client_data);
4223
4224/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00004225 * @}
4226 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004227
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004228/** \defgroup CINDEX_REMAPPING Remapping functions
4229 *
4230 * @{
4231 */
4232
4233/**
4234 * \brief A remapping of original source files and their translated files.
4235 */
4236typedef void *CXRemapping;
4237
4238/**
4239 * \brief Retrieve a remapping.
4240 *
4241 * \param path the path that contains metadata about remappings.
4242 *
4243 * \returns the requested remapping. This remapping must be freed
4244 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4245 */
4246CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4247
4248/**
Ted Kremenek30660a82012-03-06 20:06:33 +00004249 * \brief Retrieve a remapping.
4250 *
4251 * \param filePaths pointer to an array of file paths containing remapping info.
4252 *
4253 * \param numFiles number of file paths.
4254 *
4255 * \returns the requested remapping. This remapping must be freed
4256 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4257 */
4258CINDEX_LINKAGE
4259CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
4260 unsigned numFiles);
4261
4262/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004263 * \brief Determine the number of remappings.
4264 */
4265CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4266
4267/**
4268 * \brief Get the original and the associated filename from the remapping.
4269 *
4270 * \param original If non-NULL, will be set to the original filename.
4271 *
4272 * \param transformed If non-NULL, will be set to the filename that the original
4273 * is associated with.
4274 */
4275CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4276 CXString *original, CXString *transformed);
4277
4278/**
4279 * \brief Dispose the remapping.
4280 */
4281CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4282
4283/**
4284 * @}
4285 */
4286
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004287/** \defgroup CINDEX_HIGH Higher level API functions
4288 *
4289 * @{
4290 */
4291
4292enum CXVisitorResult {
4293 CXVisit_Break,
4294 CXVisit_Continue
4295};
4296
4297typedef struct {
4298 void *context;
4299 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4300} CXCursorAndRangeVisitor;
4301
4302/**
4303 * \brief Find references of a declaration in a specific file.
4304 *
4305 * \param cursor pointing to a declaration or a reference of one.
4306 *
4307 * \param file to search for references.
4308 *
4309 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4310 * each reference found.
4311 * The CXSourceRange will point inside the file; if the reference is inside
4312 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4313 */
4314CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4315 CXCursorAndRangeVisitor visitor);
4316
4317#ifdef __has_feature
4318# if __has_feature(blocks)
4319
4320typedef enum CXVisitorResult
4321 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4322
4323CINDEX_LINKAGE
4324void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4325 CXCursorAndRangeVisitorBlock);
4326
4327# endif
4328#endif
4329
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004330/**
4331 * \brief The client's data object that is associated with a CXFile.
4332 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004333typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004334
4335/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004336 * \brief The client's data object that is associated with a semantic entity.
4337 */
4338typedef void *CXIdxClientEntity;
4339
4340/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004341 * \brief The client's data object that is associated with a semantic container
4342 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004343 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004344typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004345
4346/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004347 * \brief The client's data object that is associated with an AST file (PCH
4348 * or module).
4349 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004350typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004351
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004352/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004353 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004354 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004355typedef struct {
4356 void *ptr_data[2];
4357 unsigned int_data;
4358} CXIdxLoc;
4359
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004360/**
4361 * \brief Data for \see ppIncludedFile callback.
4362 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004363typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004364 /**
4365 * \brief Location of '#' in the #include/#import directive.
4366 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004367 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004368 /**
4369 * \brief Filename as written in the #include/#import directive.
4370 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004371 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004372 /**
4373 * \brief The actual file that the #include/#import directive resolved to.
4374 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004375 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004376 int isImport;
4377 int isAngled;
4378} CXIdxIncludedFileInfo;
4379
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004380/**
4381 * \brief Data for \see importedASTFile callback.
4382 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004383typedef struct {
4384 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004385 /**
4386 * \brief Location where the file is imported. It is useful mostly for
4387 * modules.
4388 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004389 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004390 /**
4391 * \brief Non-zero if the AST file is a module otherwise it's a PCH.
4392 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004393 int isModule;
4394} CXIdxImportedASTFileInfo;
4395
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004396typedef enum {
4397 CXIdxEntity_Unexposed = 0,
4398 CXIdxEntity_Typedef = 1,
4399 CXIdxEntity_Function = 2,
4400 CXIdxEntity_Variable = 3,
4401 CXIdxEntity_Field = 4,
4402 CXIdxEntity_EnumConstant = 5,
4403
4404 CXIdxEntity_ObjCClass = 6,
4405 CXIdxEntity_ObjCProtocol = 7,
4406 CXIdxEntity_ObjCCategory = 8,
4407
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004408 CXIdxEntity_ObjCInstanceMethod = 9,
4409 CXIdxEntity_ObjCClassMethod = 10,
4410 CXIdxEntity_ObjCProperty = 11,
4411 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004412
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004413 CXIdxEntity_Enum = 13,
4414 CXIdxEntity_Struct = 14,
4415 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004416
4417 CXIdxEntity_CXXClass = 16,
4418 CXIdxEntity_CXXNamespace = 17,
4419 CXIdxEntity_CXXNamespaceAlias = 18,
4420 CXIdxEntity_CXXStaticVariable = 19,
4421 CXIdxEntity_CXXStaticMethod = 20,
4422 CXIdxEntity_CXXInstanceMethod = 21,
4423 CXIdxEntity_CXXConstructor = 22,
4424 CXIdxEntity_CXXDestructor = 23,
4425 CXIdxEntity_CXXConversionFunction = 24,
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004426 CXIdxEntity_CXXTypeAlias = 25
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004427
4428} CXIdxEntityKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004429
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004430typedef enum {
4431 CXIdxEntityLang_None = 0,
4432 CXIdxEntityLang_C = 1,
4433 CXIdxEntityLang_ObjC = 2,
4434 CXIdxEntityLang_CXX = 3
4435} CXIdxEntityLanguage;
4436
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004437/**
4438 * \brief Extra C++ template information for an entity. This can apply to:
4439 * CXIdxEntity_Function
4440 * CXIdxEntity_CXXClass
4441 * CXIdxEntity_CXXStaticMethod
4442 * CXIdxEntity_CXXInstanceMethod
4443 * CXIdxEntity_CXXConstructor
4444 * CXIdxEntity_CXXConversionFunction
4445 * CXIdxEntity_CXXTypeAlias
4446 */
4447typedef enum {
4448 CXIdxEntity_NonTemplate = 0,
4449 CXIdxEntity_Template = 1,
4450 CXIdxEntity_TemplatePartialSpecialization = 2,
4451 CXIdxEntity_TemplateSpecialization = 3
4452} CXIdxEntityCXXTemplateKind;
4453
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004454typedef enum {
4455 CXIdxAttr_Unexposed = 0,
4456 CXIdxAttr_IBAction = 1,
4457 CXIdxAttr_IBOutlet = 2,
4458 CXIdxAttr_IBOutletCollection = 3
4459} CXIdxAttrKind;
4460
4461typedef struct {
4462 CXIdxAttrKind kind;
4463 CXCursor cursor;
4464 CXIdxLoc loc;
4465} CXIdxAttrInfo;
4466
4467typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00004468 CXIdxEntityKind kind;
4469 CXIdxEntityCXXTemplateKind templateKind;
4470 CXIdxEntityLanguage lang;
4471 const char *name;
4472 const char *USR;
4473 CXCursor cursor;
4474 const CXIdxAttrInfo *const *attributes;
4475 unsigned numAttributes;
4476} CXIdxEntityInfo;
4477
4478typedef struct {
4479 CXCursor cursor;
4480} CXIdxContainerInfo;
4481
4482typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004483 const CXIdxAttrInfo *attrInfo;
4484 const CXIdxEntityInfo *objcClass;
4485 CXCursor classCursor;
4486 CXIdxLoc classLoc;
4487} CXIdxIBOutletCollectionAttrInfo;
4488
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004489typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004490 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004491 CXCursor cursor;
4492 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004493 const CXIdxContainerInfo *semanticContainer;
4494 /**
4495 * \brief Generally same as \see semanticContainer but can be different in
4496 * cases like out-of-line C++ member functions.
4497 */
4498 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004499 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004500 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004501 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004502 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004503 /**
4504 * \brief Whether the declaration exists in code or was created implicitly
4505 * by the compiler, e.g. implicit objc methods for properties.
4506 */
4507 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004508 const CXIdxAttrInfo *const *attributes;
4509 unsigned numAttributes;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004510} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004511
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004512typedef enum {
4513 CXIdxObjCContainer_ForwardRef = 0,
4514 CXIdxObjCContainer_Interface = 1,
4515 CXIdxObjCContainer_Implementation = 2
4516} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004517
4518typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004519 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004520 CXIdxObjCContainerKind kind;
4521} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004522
4523typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004524 const CXIdxEntityInfo *base;
4525 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004526 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004527} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004528
4529typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004530 const CXIdxEntityInfo *protocol;
4531 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004532 CXIdxLoc loc;
4533} CXIdxObjCProtocolRefInfo;
4534
4535typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004536 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004537 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004538} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004539
4540typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004541 const CXIdxObjCContainerDeclInfo *containerInfo;
4542 const CXIdxBaseClassInfo *superInfo;
4543 const CXIdxObjCProtocolRefListInfo *protocols;
4544} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004545
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004546typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00004547 const CXIdxObjCContainerDeclInfo *containerInfo;
4548 const CXIdxEntityInfo *objcClass;
4549 CXCursor classCursor;
4550 CXIdxLoc classLoc;
4551 const CXIdxObjCProtocolRefListInfo *protocols;
4552} CXIdxObjCCategoryDeclInfo;
4553
4554typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004555 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004556 const CXIdxEntityInfo *getter;
4557 const CXIdxEntityInfo *setter;
4558} CXIdxObjCPropertyDeclInfo;
4559
4560typedef struct {
4561 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004562 const CXIdxBaseClassInfo *const *bases;
4563 unsigned numBases;
4564} CXIdxCXXClassDeclInfo;
4565
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004566/**
4567 * \brief Data for \see indexEntityReference callback.
4568 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004569typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004570 /**
4571 * \brief The entity is referenced directly in user's code.
4572 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004573 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004574 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004575 * \brief An implicit reference, e.g. a reference of an ObjC method via the
4576 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004577 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004578 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004579} CXIdxEntityRefKind;
4580
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004581/**
4582 * \brief Data for \see indexEntityReference callback.
4583 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004584typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004585 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004586 /**
4587 * \brief Reference cursor.
4588 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004589 CXCursor cursor;
4590 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004591 /**
4592 * \brief The entity that gets referenced.
4593 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004594 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004595 /**
4596 * \brief Immediate "parent" of the reference. For example:
4597 *
4598 * \code
4599 * Foo *var;
4600 * \endcode
4601 *
4602 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004603 * For references inside statement bodies of functions/methods,
4604 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004605 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004606 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004607 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004608 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004609 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004610 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004611} CXIdxEntityRefInfo;
4612
4613typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004614 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004615 * \brief Called periodically to check whether indexing should be aborted.
4616 * Should return 0 to continue, and non-zero to abort.
4617 */
4618 int (*abortQuery)(CXClientData client_data, void *reserved);
4619
4620 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004621 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004622 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004623 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004624 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004625
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004626 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
4627 CXFile mainFile, void *reserved);
4628
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004629 /**
4630 * \brief Called when a file gets #included/#imported.
4631 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004632 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004633 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004634
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004635 /**
4636 * \brief Called when a AST file (PCH or module) gets imported.
4637 *
4638 * AST files will not get indexed (there will not be callbacks to index all
4639 * the entities in an AST file). The recommended action is that, if the AST
4640 * file is not already indexed, to block further indexing and initiate a new
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004641 * indexing job specific to the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004642 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004643 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004644 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004645
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004646 /**
4647 * \brief Called at the beginning of indexing a translation unit.
4648 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004649 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004650 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004651
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004652 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004653 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004654
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004655 /**
4656 * \brief Called to index a reference of an entity.
4657 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004658 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004659 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004660
4661} IndexerCallbacks;
4662
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004663CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004664CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
4665clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004666
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004667CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
4668clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
4669
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004670CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004671const CXIdxObjCCategoryDeclInfo *
4672clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
4673
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004674CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
4675clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004676
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004677CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
4678clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
4679
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004680CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
4681clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
4682
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004683CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
4684clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
4685
4686/**
4687 * \brief For retrieving a custom CXIdxClientContainer attached to a
4688 * container.
4689 */
4690CINDEX_LINKAGE CXIdxClientContainer
4691clang_index_getClientContainer(const CXIdxContainerInfo *);
4692
4693/**
4694 * \brief For setting a custom CXIdxClientContainer attached to a
4695 * container.
4696 */
4697CINDEX_LINKAGE void
4698clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
4699
4700/**
4701 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
4702 */
4703CINDEX_LINKAGE CXIdxClientEntity
4704clang_index_getClientEntity(const CXIdxEntityInfo *);
4705
4706/**
4707 * \brief For setting a custom CXIdxClientEntity attached to an entity.
4708 */
4709CINDEX_LINKAGE void
4710clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
4711
4712/**
4713 * \brief An indexing action, to be applied to one or multiple translation units
4714 * but not on concurrent threads. If there are threads doing indexing
4715 * concurrently, they should use different CXIndexAction objects.
4716 */
4717typedef void *CXIndexAction;
4718
4719/**
4720 * \brief An indexing action, to be applied to one or multiple translation units
4721 * but not on concurrent threads. If there are threads doing indexing
4722 * concurrently, they should use different CXIndexAction objects.
4723 *
4724 * \param CIdx The index object with which the index action will be associated.
4725 */
4726CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
4727
4728/**
4729 * \brief Destroy the given index action.
4730 *
4731 * The index action must not be destroyed until all of the translation units
4732 * created within that index action have been destroyed.
4733 */
4734CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
4735
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004736typedef enum {
4737 /**
4738 * \brief Used to indicate that no special indexing options are needed.
4739 */
4740 CXIndexOpt_None = 0x0,
4741
4742 /**
4743 * \brief Used to indicate that \see indexEntityReference should be invoked
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004744 * for only one reference of an entity per source file that does not also
4745 * include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004746 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00004747 CXIndexOpt_SuppressRedundantRefs = 0x1,
4748
4749 /**
4750 * \brief Function-local symbols should be indexed. If this is not set
4751 * function-local symbols will be ignored.
4752 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00004753 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
4754
4755 /**
4756 * \brief Implicit function/class template instantiations should be indexed.
4757 * If this is not set, implicit instantiations will be ignored.
4758 */
Argyrios Kyrtzidisb49a29f2012-03-27 21:38:03 +00004759 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
4760
4761 /**
4762 * \brief Suppress all compiler warnings when parsing for indexing.
4763 */
4764 CXIndexOpt_SuppressWarnings = 0x8
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004765} CXIndexOptFlags;
4766
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004767/**
4768 * \brief Index the given source file and the translation unit corresponding
4769 * to that file via callbacks implemented through \see IndexerCallbacks.
4770 *
4771 * \param client_data pointer data supplied by the client, which will
4772 * be passed to the invoked callbacks.
4773 *
4774 * \param index_callbacks Pointer to indexing callbacks that the client
4775 * implements.
4776 *
4777 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets
4778 * passed in index_callbacks.
4779 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004780 * \param index_options A bitmask of options that affects how indexing is
4781 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004782 *
4783 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
4784 * after indexing is finished. Set to NULL if you do not require it.
4785 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004786 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004787 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004788 *
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004789 * The rest of the parameters are the same as \see clang_parseTranslationUnit.
4790 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004791CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004792 CXClientData client_data,
4793 IndexerCallbacks *index_callbacks,
4794 unsigned index_callbacks_size,
4795 unsigned index_options,
4796 const char *source_filename,
4797 const char * const *command_line_args,
4798 int num_command_line_args,
4799 struct CXUnsavedFile *unsaved_files,
4800 unsigned num_unsaved_files,
4801 CXTranslationUnit *out_TU,
4802 unsigned TU_options);
4803
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004804/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004805 * \brief Index the given translation unit via callbacks implemented through
4806 * \see IndexerCallbacks.
4807 *
4808 * The order of callback invocations is not guaranteed to be the same as
4809 * when indexing a source file. The high level order will be:
4810 *
4811 * -Preprocessor callbacks invocations
4812 * -Declaration/reference callbacks invocations
4813 * -Diagnostic callback invocations
4814 *
4815 * The parameters are the same as \see clang_indexSourceFile.
4816 *
4817 * \returns If there is a failure from which the there is no recovery, returns
4818 * non-zero, otherwise returns 0.
4819 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004820CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004821 CXClientData client_data,
4822 IndexerCallbacks *index_callbacks,
4823 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004824 unsigned index_options,
4825 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004826
4827/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004828 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
4829 * the given CXIdxLoc.
4830 *
4831 * If the location refers into a macro expansion, retrieves the
4832 * location of the macro expansion and if it refers into a macro argument
4833 * retrieves the location of the argument.
4834 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004835CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004836 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004837 CXFile *file,
4838 unsigned *line,
4839 unsigned *column,
4840 unsigned *offset);
4841
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004842/**
4843 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
4844 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004845CINDEX_LINKAGE
4846CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
4847
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004848/**
4849 * @}
4850 */
4851
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004852/**
4853 * @}
4854 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004855
Ted Kremenekd2fa5662009-08-26 22:36:44 +00004856#ifdef __cplusplus
4857}
4858#endif
4859#endif
4860