blob: 94cfd685dc00498a4a59ef179c6d8e87e7055f40 [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
Chad Rosier8cd64b42012-06-11 20:47:18 +00001999 /** \brief A MS inline assembly statement extension.
2000 */
2001 CXCursor_MSAsmStmt = 229,
2002
Douglas Gregor42b29842011-10-05 19:00:14 +00002003 /** \brief The null satement ";": C99 6.8.3p3.
2004 *
2005 * This cursor kind is used to describe the null statement.
2006 */
2007 CXCursor_NullStmt = 230,
2008
2009 /** \brief Adaptor class for mixing declarations with statements and
2010 * expressions.
2011 */
2012 CXCursor_DeclStmt = 231,
2013
2014 CXCursor_LastStmt = CXCursor_DeclStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002015
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002016 /**
2017 * \brief Cursor that represents the translation unit itself.
2018 *
2019 * The translation unit cursor exists primarily to act as the root
2020 * cursor for traversing the contents of a translation unit.
2021 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002022 CXCursor_TranslationUnit = 300,
2023
2024 /* Attributes */
2025 CXCursor_FirstAttr = 400,
2026 /**
2027 * \brief An attribute whose specific kind is not exposed via this
2028 * interface.
2029 */
2030 CXCursor_UnexposedAttr = 400,
2031
2032 CXCursor_IBActionAttr = 401,
2033 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00002034 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00002035 CXCursor_CXXFinalAttr = 404,
2036 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002037 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002038 CXCursor_AsmLabelAttr = 407,
2039 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002040
2041 /* Preprocessing */
2042 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00002043 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00002044 CXCursor_MacroExpansion = 502,
2045 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002046 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002047 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002048 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002049};
2050
2051/**
2052 * \brief A cursor representing some element in the abstract syntax tree for
2053 * a translation unit.
2054 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002055 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002056 * program--declaration, statements, expressions, references to declarations,
2057 * etc.--under a single "cursor" abstraction with a common set of operations.
2058 * Common operation for a cursor include: getting the physical location in
2059 * a source file where the cursor points, getting the name associated with a
2060 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2061 *
2062 * Cursors can be produced in two specific ways.
2063 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2064 * from which one can use clang_visitChildren() to explore the rest of the
2065 * translation unit. clang_getCursor() maps from a physical source location
2066 * to the entity that resides at that location, allowing one to map from the
2067 * source code into the AST.
2068 */
2069typedef struct {
2070 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00002071 int xdata;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002072 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002073} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002074
2075/**
2076 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2077 *
2078 * @{
2079 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002080
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002081/**
2082 * \brief Retrieve the NULL cursor, which represents no entity.
2083 */
2084CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002085
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002086/**
2087 * \brief Retrieve the cursor that represents the given translation unit.
2088 *
2089 * The translation unit cursor can be used to start traversing the
2090 * various declarations within the given translation unit.
2091 */
2092CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2093
2094/**
2095 * \brief Determine whether two cursors are equivalent.
2096 */
2097CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002098
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002099/**
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002100 * \brief Returns non-zero if \arg cursor is null.
2101 */
Benjamin Kramer5b419362012-02-01 20:37:28 +00002102CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002103
2104/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00002105 * \brief Compute a hash value for the given cursor.
2106 */
2107CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2108
2109/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002110 * \brief Retrieve the kind of the given cursor.
2111 */
2112CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2113
2114/**
2115 * \brief Determine whether the given cursor kind represents a declaration.
2116 */
2117CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2118
2119/**
2120 * \brief Determine whether the given cursor kind represents a simple
2121 * reference.
2122 *
2123 * Note that other kinds of cursors (such as expressions) can also refer to
2124 * other cursors. Use clang_getCursorReferenced() to determine whether a
2125 * particular cursor refers to another entity.
2126 */
2127CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2128
2129/**
2130 * \brief Determine whether the given cursor kind represents an expression.
2131 */
2132CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2133
2134/**
2135 * \brief Determine whether the given cursor kind represents a statement.
2136 */
2137CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2138
2139/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002140 * \brief Determine whether the given cursor kind represents an attribute.
2141 */
2142CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2143
2144/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002145 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002146 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002147 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002148CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2149
2150/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002151 * \brief Determine whether the given cursor kind represents a translation
2152 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002153 */
2154CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002155
Ted Kremenekad6eff62010-03-08 21:17:29 +00002156/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002157 * \brief Determine whether the given cursor represents a preprocessing
2158 * element, such as a preprocessor directive or macro instantiation.
2159 */
2160CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2161
2162/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002163 * \brief Determine whether the given cursor represents a currently
2164 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2165 */
2166CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2167
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002168/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002169 * \brief Describe the linkage of the entity referred to by a cursor.
2170 */
2171enum CXLinkageKind {
2172 /** \brief This value indicates that no linkage information is available
2173 * for a provided CXCursor. */
2174 CXLinkage_Invalid,
2175 /**
2176 * \brief This is the linkage for variables, parameters, and so on that
2177 * have automatic storage. This covers normal (non-extern) local variables.
2178 */
2179 CXLinkage_NoLinkage,
2180 /** \brief This is the linkage for static variables and static functions. */
2181 CXLinkage_Internal,
2182 /** \brief This is the linkage for entities with external linkage that live
2183 * in C++ anonymous namespaces.*/
2184 CXLinkage_UniqueExternal,
2185 /** \brief This is the linkage for entities with true, external linkage. */
2186 CXLinkage_External
2187};
2188
2189/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002190 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002191 */
2192CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2193
2194/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002195 * \brief Determine the availability of the entity that this cursor refers to,
2196 * taking the current target platform into account.
Douglas Gregor58ddb602010-08-23 23:00:57 +00002197 *
2198 * \param cursor The cursor to query.
2199 *
2200 * \returns The availability of the cursor.
2201 */
2202CINDEX_LINKAGE enum CXAvailabilityKind
2203clang_getCursorAvailability(CXCursor cursor);
2204
2205/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002206 * Describes the availability of a given entity on a particular platform, e.g.,
2207 * a particular class might only be available on Mac OS 10.7 or newer.
2208 */
2209typedef struct CXPlatformAvailability {
2210 /**
2211 * \brief A string that describes the platform for which this structure
2212 * provides availability information.
2213 *
2214 * Possible values are "ios" or "macosx".
2215 */
2216 CXString Platform;
2217 /**
2218 * \brief The version number in which this entity was introduced.
2219 */
2220 CXVersion Introduced;
2221 /**
2222 * \brief The version number in which this entity was deprecated (but is
2223 * still available).
2224 */
2225 CXVersion Deprecated;
2226 /**
2227 * \brief The version number in which this entity was obsoleted, and therefore
2228 * is no longer available.
2229 */
2230 CXVersion Obsoleted;
2231 /**
2232 * \brief Whether the entity is unconditionally unavailable on this platform.
2233 */
2234 int Unavailable;
2235 /**
2236 * \brief An optional message to provide to a user of this API, e.g., to
2237 * suggest replacement APIs.
2238 */
2239 CXString Message;
2240} CXPlatformAvailability;
2241
2242/**
2243 * \brief Determine the availability of the entity that this cursor refers to
2244 * on any platforms for which availability information is known.
2245 *
2246 * \param cursor The cursor to query.
2247 *
2248 * \param always_deprecated If non-NULL, will be set to indicate whether the
2249 * entity is deprecated on all platforms.
2250 *
2251 * \param deprecated_message If non-NULL, will be set to the message text
2252 * provided along with the unconditional deprecation of this entity. The client
2253 * is responsible for deallocating this string.
2254 *
2255 * \param always_unavailabile If non-NULL, will be set to indicate whether the
2256 * entity is unavailable on all platforms.
2257 *
2258 * \param unavailable_message If non-NULL, will be set to the message text
2259 * provided along with the unconditional unavailability of this entity. The
2260 * client is responsible for deallocating this string.
2261 *
2262 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2263 * that will be populated with platform availability information, up to either
2264 * the number of platforms for which availability information is available (as
2265 * returned by this function) or \c availability_size, whichever is smaller.
2266 *
2267 * \param availability_size The number of elements available in the
2268 * \c availability array.
2269 *
2270 * \returns The number of platforms (N) for which availability information is
2271 * available (which is unrelated to \c availability_size).
2272 *
2273 * Note that the client is responsible for calling
2274 * \c clang_disposeCXPlatformAvailability to free each of the
2275 * platform-availability structures returned. There are
2276 * \c min(N, availability_size) such structures.
2277 */
2278CINDEX_LINKAGE int
2279clang_getCursorPlatformAvailability(CXCursor cursor,
2280 int *always_deprecated,
2281 CXString *deprecated_message,
2282 int *always_unavailable,
2283 CXString *unavailable_message,
2284 CXPlatformAvailability *availability,
2285 int availability_size);
2286
2287/**
2288 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2289 */
2290CINDEX_LINKAGE void
2291clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2292
2293/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002294 * \brief Describe the "language" of the entity referred to by a cursor.
2295 */
2296CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002297 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002298 CXLanguage_C,
2299 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002300 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002301};
2302
2303/**
2304 * \brief Determine the "language" of the entity referred to by a given cursor.
2305 */
2306CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2307
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002308/**
2309 * \brief Returns the translation unit that a cursor originated from.
2310 */
2311CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2312
Ted Kremenekeca099b2010-12-08 23:43:14 +00002313
2314/**
2315 * \brief A fast container representing a set of CXCursors.
2316 */
2317typedef struct CXCursorSetImpl *CXCursorSet;
2318
2319/**
2320 * \brief Creates an empty CXCursorSet.
2321 */
2322CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2323
2324/**
2325 * \brief Disposes a CXCursorSet and releases its associated memory.
2326 */
2327CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2328
2329/**
2330 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2331 *
2332 * \returns non-zero if the set contains the specified cursor.
2333*/
2334CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2335 CXCursor cursor);
2336
2337/**
2338 * \brief Inserts a CXCursor into a CXCursorSet.
2339 *
2340 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2341*/
2342CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2343 CXCursor cursor);
2344
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002345/**
2346 * \brief Determine the semantic parent of the given cursor.
2347 *
2348 * The semantic parent of a cursor is the cursor that semantically contains
2349 * the given \p cursor. For many declarations, the lexical and semantic parents
2350 * are equivalent (the lexical parent is returned by
2351 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2352 * definitions are provided out-of-line. For example:
2353 *
2354 * \code
2355 * class C {
2356 * void f();
2357 * };
2358 *
2359 * void C::f() { }
2360 * \endcode
2361 *
2362 * In the out-of-line definition of \c C::f, the semantic parent is the
2363 * the class \c C, of which this function is a member. The lexical parent is
2364 * the place where the declaration actually occurs in the source code; in this
2365 * case, the definition occurs in the translation unit. In general, the
2366 * lexical parent for a given entity can change without affecting the semantics
2367 * of the program, and the lexical parent of different declarations of the
2368 * same entity may be different. Changing the semantic parent of a declaration,
2369 * on the other hand, can have a major impact on semantics, and redeclarations
2370 * of a particular entity should all have the same semantic context.
2371 *
2372 * In the example above, both declarations of \c C::f have \c C as their
2373 * semantic context, while the lexical context of the first \c C::f is \c C
2374 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002375 *
2376 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002377 */
2378CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2379
2380/**
2381 * \brief Determine the lexical parent of the given cursor.
2382 *
2383 * The lexical parent of a cursor is the cursor in which the given \p cursor
2384 * was actually written. For many declarations, the lexical and semantic parents
2385 * are equivalent (the semantic parent is returned by
2386 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2387 * definitions are provided out-of-line. For example:
2388 *
2389 * \code
2390 * class C {
2391 * void f();
2392 * };
2393 *
2394 * void C::f() { }
2395 * \endcode
2396 *
2397 * In the out-of-line definition of \c C::f, the semantic parent is the
2398 * the class \c C, of which this function is a member. The lexical parent is
2399 * the place where the declaration actually occurs in the source code; in this
2400 * case, the definition occurs in the translation unit. In general, the
2401 * lexical parent for a given entity can change without affecting the semantics
2402 * of the program, and the lexical parent of different declarations of the
2403 * same entity may be different. Changing the semantic parent of a declaration,
2404 * on the other hand, can have a major impact on semantics, and redeclarations
2405 * of a particular entity should all have the same semantic context.
2406 *
2407 * In the example above, both declarations of \c C::f have \c C as their
2408 * semantic context, while the lexical context of the first \c C::f is \c C
2409 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002410 *
2411 * For declarations written in the global scope, the lexical parent is
2412 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002413 */
2414CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002415
2416/**
2417 * \brief Determine the set of methods that are overridden by the given
2418 * method.
2419 *
2420 * In both Objective-C and C++, a method (aka virtual member function,
2421 * in C++) can override a virtual method in a base class. For
2422 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002423 * base class, its protocols, or its categories' protocols, that has the same
2424 * selector and is of the same kind (class or instance).
2425 * If no such method exists, the search continues to the class's superclass,
2426 * its protocols, and its categories, and so on. A method from an Objective-C
2427 * implementation is considered to override the same methods as its
2428 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002429 *
2430 * For C++, a virtual member function overrides any virtual member
2431 * function with the same signature that occurs in its base
2432 * classes. With multiple inheritance, a virtual member function can
2433 * override several virtual member functions coming from different
2434 * base classes.
2435 *
2436 * In all cases, this function determines the immediate overridden
2437 * method, rather than all of the overridden methods. For example, if
2438 * a method is originally declared in a class A, then overridden in B
2439 * (which in inherits from A) and also in C (which inherited from B),
2440 * then the only overridden method returned from this function when
2441 * invoked on C's method will be B's method. The client may then
2442 * invoke this function again, given the previously-found overridden
2443 * methods, to map out the complete method-override set.
2444 *
2445 * \param cursor A cursor representing an Objective-C or C++
2446 * method. This routine will compute the set of methods that this
2447 * method overrides.
2448 *
2449 * \param overridden A pointer whose pointee will be replaced with a
2450 * pointer to an array of cursors, representing the set of overridden
2451 * methods. If there are no overridden methods, the pointee will be
2452 * set to NULL. The pointee must be freed via a call to
2453 * \c clang_disposeOverriddenCursors().
2454 *
2455 * \param num_overridden A pointer to the number of overridden
2456 * functions, will be set to the number of overridden functions in the
2457 * array pointed to by \p overridden.
2458 */
2459CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2460 CXCursor **overridden,
2461 unsigned *num_overridden);
2462
2463/**
2464 * \brief Free the set of overridden cursors returned by \c
2465 * clang_getOverriddenCursors().
2466 */
2467CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2468
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002469/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002470 * \brief Retrieve the file that is included by the given inclusion directive
2471 * cursor.
2472 */
2473CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2474
2475/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002476 * @}
2477 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002478
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002479/**
2480 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2481 *
2482 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2483 * routines help map between cursors and the physical locations where the
2484 * described entities occur in the source code. The mapping is provided in
2485 * both directions, so one can map from source code to the AST and back.
2486 *
2487 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002488 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002489
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002490/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002491 * \brief Map a source location to the cursor that describes the entity at that
2492 * location in the source code.
2493 *
2494 * clang_getCursor() maps an arbitrary source location within a translation
2495 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002496 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002497 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002498 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002499 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2500 * will return a cursor referring to the "+" expression.
2501 *
2502 * \returns a cursor representing the entity at the given source location, or
2503 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002504 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002505CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002506
Douglas Gregor98258af2010-01-18 22:46:11 +00002507/**
2508 * \brief Retrieve the physical location of the source constructor referenced
2509 * by the given cursor.
2510 *
2511 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002512 * declaration, where the name of that declaration would occur if it is
2513 * unnamed, or some keyword that introduces that particular declaration.
2514 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002515 * source code.
2516 */
2517CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002518
Douglas Gregorb6998662010-01-19 19:34:47 +00002519/**
2520 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002521 * the given cursor.
2522 *
2523 * The extent of a cursor starts with the file/line/column pointing at the
2524 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002525 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002526 * declaration, the extent covers the declaration itself. For a reference,
2527 * the extent covers the location of the reference (e.g., where the referenced
2528 * entity was actually used).
2529 */
2530CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002531
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002532/**
2533 * @}
2534 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002535
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002536/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002537 * \defgroup CINDEX_TYPES Type information for CXCursors
2538 *
2539 * @{
2540 */
2541
2542/**
2543 * \brief Describes the kind of type
2544 */
2545enum CXTypeKind {
2546 /**
2547 * \brief Reprents an invalid type (e.g., where no type is available).
2548 */
2549 CXType_Invalid = 0,
2550
2551 /**
2552 * \brief A type whose specific kind is not exposed via this
2553 * interface.
2554 */
2555 CXType_Unexposed = 1,
2556
2557 /* Builtin types */
2558 CXType_Void = 2,
2559 CXType_Bool = 3,
2560 CXType_Char_U = 4,
2561 CXType_UChar = 5,
2562 CXType_Char16 = 6,
2563 CXType_Char32 = 7,
2564 CXType_UShort = 8,
2565 CXType_UInt = 9,
2566 CXType_ULong = 10,
2567 CXType_ULongLong = 11,
2568 CXType_UInt128 = 12,
2569 CXType_Char_S = 13,
2570 CXType_SChar = 14,
2571 CXType_WChar = 15,
2572 CXType_Short = 16,
2573 CXType_Int = 17,
2574 CXType_Long = 18,
2575 CXType_LongLong = 19,
2576 CXType_Int128 = 20,
2577 CXType_Float = 21,
2578 CXType_Double = 22,
2579 CXType_LongDouble = 23,
2580 CXType_NullPtr = 24,
2581 CXType_Overload = 25,
2582 CXType_Dependent = 26,
2583 CXType_ObjCId = 27,
2584 CXType_ObjCClass = 28,
2585 CXType_ObjCSel = 29,
2586 CXType_FirstBuiltin = CXType_Void,
2587 CXType_LastBuiltin = CXType_ObjCSel,
2588
2589 CXType_Complex = 100,
2590 CXType_Pointer = 101,
2591 CXType_BlockPointer = 102,
2592 CXType_LValueReference = 103,
2593 CXType_RValueReference = 104,
2594 CXType_Record = 105,
2595 CXType_Enum = 106,
2596 CXType_Typedef = 107,
2597 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002598 CXType_ObjCObjectPointer = 109,
2599 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002600 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002601 CXType_ConstantArray = 112,
2602 CXType_Vector = 113
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002603};
2604
2605/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002606 * \brief Describes the calling convention of a function type
2607 */
2608enum CXCallingConv {
2609 CXCallingConv_Default = 0,
2610 CXCallingConv_C = 1,
2611 CXCallingConv_X86StdCall = 2,
2612 CXCallingConv_X86FastCall = 3,
2613 CXCallingConv_X86ThisCall = 4,
2614 CXCallingConv_X86Pascal = 5,
2615 CXCallingConv_AAPCS = 6,
2616 CXCallingConv_AAPCS_VFP = 7,
2617
2618 CXCallingConv_Invalid = 100,
2619 CXCallingConv_Unexposed = 200
2620};
2621
2622
2623/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002624 * \brief The type of an element in the abstract syntax tree.
2625 *
2626 */
2627typedef struct {
2628 enum CXTypeKind kind;
2629 void *data[2];
2630} CXType;
2631
2632/**
2633 * \brief Retrieve the type of a CXCursor (if any).
2634 */
2635CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2636
2637/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002638 * \brief Retrieve the underlying type of a typedef declaration.
2639 *
2640 * If the cursor does not reference a typedef declaration, an invalid type is
2641 * returned.
2642 */
2643CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2644
2645/**
2646 * \brief Retrieve the integer type of an enum declaration.
2647 *
2648 * If the cursor does not reference an enum declaration, an invalid type is
2649 * returned.
2650 */
2651CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2652
2653/**
2654 * \brief Retrieve the integer value of an enum constant declaration as a signed
2655 * long long.
2656 *
2657 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2658 * Since this is also potentially a valid constant value, the kind of the cursor
2659 * must be verified before calling this function.
2660 */
2661CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2662
2663/**
2664 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2665 * long long.
2666 *
2667 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2668 * Since this is also potentially a valid constant value, the kind of the cursor
2669 * must be verified before calling this function.
2670 */
2671CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2672
2673/**
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002674 * \brief Retrieve the number of non-variadic arguments associated with a given
2675 * cursor.
2676 *
2677 * If a cursor that is not a function or method is passed in, -1 is returned.
2678 */
2679CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2680
2681/**
2682 * \brief Retrieve the argument cursor of a function or method.
2683 *
2684 * If a cursor that is not a function or method is passed in or the index
2685 * exceeds the number of arguments, an invalid cursor is returned.
2686 */
2687CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2688
2689/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002690 * \determine Determine whether two CXTypes represent the same type.
2691 *
2692 * \returns non-zero if the CXTypes represent the same type and
2693 zero otherwise.
2694 */
2695CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2696
2697/**
2698 * \brief Return the canonical type for a CXType.
2699 *
2700 * Clang's type system explicitly models typedefs and all the ways
2701 * a specific type can be represented. The canonical type is the underlying
2702 * type with all the "sugar" removed. For example, if 'T' is a typedef
2703 * for 'int', the canonical type for 'T' would be 'int'.
2704 */
2705CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2706
2707/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002708 * \determine Determine whether a CXType has the "const" qualifier set,
2709 * without looking through typedefs that may have added "const" at a different level.
2710 */
2711CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2712
2713/**
2714 * \determine Determine whether a CXType has the "volatile" qualifier set,
2715 * without looking through typedefs that may have added "volatile" at a different level.
2716 */
2717CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2718
2719/**
2720 * \determine Determine whether a CXType has the "restrict" qualifier set,
2721 * without looking through typedefs that may have added "restrict" at a different level.
2722 */
2723CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2724
2725/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002726 * \brief For pointer types, returns the type of the pointee.
2727 *
2728 */
2729CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2730
2731/**
2732 * \brief Return the cursor for the declaration of the given type.
2733 */
2734CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2735
David Chisnall5389f482010-12-30 14:05:53 +00002736/**
2737 * Returns the Objective-C type encoding for the specified declaration.
2738 */
2739CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002740
2741/**
2742 * \brief Retrieve the spelling of a given CXTypeKind.
2743 */
2744CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2745
2746/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002747 * \brief Retrieve the calling convention associated with a function type.
2748 *
2749 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2750 */
2751CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2752
2753/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002754 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002755 *
2756 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002757 */
2758CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2759
2760/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002761 * \brief Retrieve the number of non-variadic arguments associated with a function type.
2762 *
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002763 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002764 */
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002765CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002766
2767/**
2768 * \brief Retrieve the type of an argument of a function type.
2769 *
2770 * If a non-function type is passed in or the function does not have enough parameters,
2771 * an invalid type is returned.
2772 */
2773CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2774
2775/**
2776 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2777 *
2778 */
2779CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2780
2781/**
2782 * \brief Retrieve the result type associated with a given cursor.
2783 *
2784 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002785 */
2786CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2787
2788/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002789 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2790 * otherwise.
2791 */
2792CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2793
2794/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002795 * \brief Return the element type of an array, complex, or vector type.
2796 *
2797 * If a type is passed in that is not an array, complex, or vector type,
2798 * an invalid type is returned.
2799 */
2800CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2801
2802/**
2803 * \brief Return the number of elements of an array or vector type.
2804 *
2805 * If a type is passed in that is not an array or vector type,
2806 * -1 is returned.
2807 */
2808CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2809
2810/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002811 * \brief Return the element type of an array type.
2812 *
2813 * If a non-array type is passed in, an invalid type is returned.
2814 */
2815CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2816
2817/**
2818 * \brief Return the the array size of a constant array.
2819 *
2820 * If a non-array type is passed in, -1 is returned.
2821 */
2822CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2823
2824/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002825 * \brief Returns 1 if the base class specified by the cursor with kind
2826 * CX_CXXBaseSpecifier is virtual.
2827 */
2828CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2829
2830/**
2831 * \brief Represents the C++ access control level to a base class for a
2832 * cursor with kind CX_CXXBaseSpecifier.
2833 */
2834enum CX_CXXAccessSpecifier {
2835 CX_CXXInvalidAccessSpecifier,
2836 CX_CXXPublic,
2837 CX_CXXProtected,
2838 CX_CXXPrivate
2839};
2840
2841/**
2842 * \brief Returns the access control level for the C++ base specifier
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00002843 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2844 * CXCursor_AccessSpecifier.
Ted Kremenek3064ef92010-08-27 21:34:58 +00002845 */
2846CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2847
2848/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002849 * \brief Determine the number of overloaded declarations referenced by a
2850 * \c CXCursor_OverloadedDeclRef cursor.
2851 *
2852 * \param cursor The cursor whose overloaded declarations are being queried.
2853 *
2854 * \returns The number of overloaded declarations referenced by \c cursor. If it
2855 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2856 */
2857CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2858
2859/**
2860 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2861 * by a \c CXCursor_OverloadedDeclRef cursor.
2862 *
2863 * \param cursor The cursor whose overloaded declarations are being queried.
2864 *
2865 * \param index The zero-based index into the set of overloaded declarations in
2866 * the cursor.
2867 *
2868 * \returns A cursor representing the declaration referenced by the given
2869 * \c cursor at the specified \c index. If the cursor does not have an
2870 * associated set of overloaded declarations, or if the index is out of bounds,
2871 * returns \c clang_getNullCursor();
2872 */
2873CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2874 unsigned index);
2875
2876/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002877 * @}
2878 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002879
2880/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002881 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002882 *
2883 * @{
2884 */
2885
2886
2887/**
2888 * \brief For cursors representing an iboutletcollection attribute,
2889 * this function returns the collection element type.
2890 *
2891 */
2892CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2893
2894/**
2895 * @}
2896 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002897
2898/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002899 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2900 *
2901 * These routines provide the ability to traverse the abstract syntax tree
2902 * using cursors.
2903 *
2904 * @{
2905 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002906
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002907/**
2908 * \brief Describes how the traversal of the children of a particular
2909 * cursor should proceed after visiting a particular child cursor.
2910 *
2911 * A value of this enumeration type should be returned by each
2912 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2913 */
2914enum CXChildVisitResult {
2915 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002916 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002917 */
2918 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002919 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002920 * \brief Continues the cursor traversal with the next sibling of
2921 * the cursor just visited, without visiting its children.
2922 */
2923 CXChildVisit_Continue,
2924 /**
2925 * \brief Recursively traverse the children of this cursor, using
2926 * the same visitor and client data.
2927 */
2928 CXChildVisit_Recurse
2929};
2930
2931/**
2932 * \brief Visitor invoked for each cursor found by a traversal.
2933 *
2934 * This visitor function will be invoked for each cursor found by
2935 * clang_visitCursorChildren(). Its first argument is the cursor being
2936 * visited, its second argument is the parent visitor for that cursor,
2937 * and its third argument is the client data provided to
2938 * clang_visitCursorChildren().
2939 *
2940 * The visitor should return one of the \c CXChildVisitResult values
2941 * to direct clang_visitCursorChildren().
2942 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002943typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2944 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002945 CXClientData client_data);
2946
2947/**
2948 * \brief Visit the children of a particular cursor.
2949 *
2950 * This function visits all the direct children of the given cursor,
2951 * invoking the given \p visitor function with the cursors of each
2952 * visited child. The traversal may be recursive, if the visitor returns
2953 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2954 * the visitor returns \c CXChildVisit_Break.
2955 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002956 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002957 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002958 * definition, have no children).
2959 *
2960 * \param visitor the visitor function that will be invoked for each
2961 * child of \p parent.
2962 *
2963 * \param client_data pointer data supplied by the client, which will
2964 * be passed to the visitor each time it is invoked.
2965 *
2966 * \returns a non-zero value if the traversal was terminated
2967 * prematurely by the visitor returning \c CXChildVisit_Break.
2968 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002969CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002970 CXCursorVisitor visitor,
2971 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002972#ifdef __has_feature
2973# if __has_feature(blocks)
2974/**
2975 * \brief Visitor invoked for each cursor found by a traversal.
2976 *
2977 * This visitor block will be invoked for each cursor found by
2978 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2979 * visited, its second argument is the parent visitor for that cursor.
2980 *
2981 * The visitor should return one of the \c CXChildVisitResult values
2982 * to direct clang_visitChildrenWithBlock().
2983 */
2984typedef enum CXChildVisitResult
2985 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2986
2987/**
2988 * Visits the children of a cursor using the specified block. Behaves
2989 * identically to clang_visitChildren() in all other respects.
2990 */
2991unsigned clang_visitChildrenWithBlock(CXCursor parent,
2992 CXCursorVisitorBlock block);
2993# endif
2994#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002995
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002996/**
2997 * @}
2998 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002999
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003000/**
3001 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3002 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003003 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003004 * across translation units, by providing the names of the entities referenced
3005 * by cursors, follow reference cursors to the declarations they reference,
3006 * and associate declarations with their definitions.
3007 *
3008 * @{
3009 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003010
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003011/**
3012 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3013 * by the given cursor.
3014 *
3015 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3016 * entity (function, class, variable, etc.) within a program. USRs can be
3017 * compared across translation units to determine, e.g., when references in
3018 * one translation refer to an entity defined in another translation unit.
3019 */
3020CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3021
3022/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003023 * \brief Construct a USR for a specified Objective-C class.
3024 */
3025CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3026
3027/**
3028 * \brief Construct a USR for a specified Objective-C category.
3029 */
3030CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00003031 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003032 const char *category_name);
3033
3034/**
3035 * \brief Construct a USR for a specified Objective-C protocol.
3036 */
3037CINDEX_LINKAGE CXString
3038 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3039
3040
3041/**
3042 * \brief Construct a USR for a specified Objective-C instance variable and
3043 * the USR for its containing class.
3044 */
3045CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3046 CXString classUSR);
3047
3048/**
3049 * \brief Construct a USR for a specified Objective-C method and
3050 * the USR for its containing class.
3051 */
3052CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3053 unsigned isInstanceMethod,
3054 CXString classUSR);
3055
3056/**
3057 * \brief Construct a USR for a specified Objective-C property and the USR
3058 * for its containing class.
3059 */
3060CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3061 CXString classUSR);
3062
3063/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003064 * \brief Retrieve a name for the entity referenced by this cursor.
3065 */
3066CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3067
Douglas Gregor358559d2010-10-02 22:49:11 +00003068/**
Argyrios Kyrtzidisba1da142012-03-30 20:58:35 +00003069 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3070 * Most of the times there is only one range for the complete spelling but for
3071 * objc methods and objc message expressions, there are multiple pieces for each
3072 * selector identifier.
3073 *
3074 * \param pieceIndex the index of the spelling name piece. If this is greater
3075 * than the actual number of pieces, it will return a NULL (invalid) range.
3076 *
3077 * \param options Reserved.
3078 */
3079CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3080 unsigned pieceIndex,
3081 unsigned options);
3082
3083/**
Douglas Gregor358559d2010-10-02 22:49:11 +00003084 * \brief Retrieve the display name for the entity referenced by this cursor.
3085 *
3086 * The display name contains extra information that helps identify the cursor,
3087 * such as the parameters of a function or template or the arguments of a
3088 * class template specialization.
3089 */
3090CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3091
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003092/** \brief For a cursor that is a reference, retrieve a cursor representing the
3093 * entity that it references.
3094 *
3095 * Reference cursors refer to other entities in the AST. For example, an
3096 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003097 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003098 * cursor for the superclass reference. If the input cursor is a declaration or
3099 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003100 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003101 */
3102CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00003103
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003104/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003105 * \brief For a cursor that is either a reference to or a declaration
3106 * of some entity, retrieve a cursor that describes the definition of
3107 * that entity.
3108 *
3109 * Some entities can be declared multiple times within a translation
3110 * unit, but only one of those declarations can also be a
3111 * definition. For example, given:
3112 *
3113 * \code
3114 * int f(int, int);
3115 * int g(int x, int y) { return f(x, y); }
3116 * int f(int a, int b) { return a + b; }
3117 * int f(int, int);
3118 * \endcode
3119 *
3120 * there are three declarations of the function "f", but only the
3121 * second one is a definition. The clang_getCursorDefinition()
3122 * function will take any cursor pointing to a declaration of "f"
3123 * (the first or fourth lines of the example) or a cursor referenced
3124 * that uses "f" (the call to "f' inside "g") and will return a
3125 * declaration cursor pointing to the definition (the second "f"
3126 * declaration).
3127 *
3128 * If given a cursor for which there is no corresponding definition,
3129 * e.g., because there is no definition of that entity within this
3130 * translation unit, returns a NULL cursor.
3131 */
3132CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3133
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003134/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003135 * \brief Determine whether the declaration pointed to by this cursor
3136 * is also a definition of that entity.
3137 */
3138CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3139
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003140/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003141 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3142 *
3143 * In the C family of languages, many kinds of entities can be declared several
3144 * times within a single translation unit. For example, a structure type can
3145 * be forward-declared (possibly multiple times) and later defined:
3146 *
3147 * \code
3148 * struct X;
3149 * struct X;
3150 * struct X {
3151 * int member;
3152 * };
3153 * \endcode
3154 *
3155 * The declarations and the definition of \c X are represented by three
3156 * different cursors, all of which are declarations of the same underlying
3157 * entity. One of these cursor is considered the "canonical" cursor, which
3158 * is effectively the representative for the underlying entity. One can
3159 * determine if two cursors are declarations of the same underlying entity by
3160 * comparing their canonical cursors.
3161 *
3162 * \returns The canonical cursor for the entity referred to by the given cursor.
3163 */
3164CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3165
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003166
3167/**
3168 * \brief If the cursor points to a selector identifier in a objc method or
3169 * message expression, this returns the selector index.
3170 *
3171 * After getting a cursor with \see clang_getCursor, this can be called to
3172 * determine if the location points to a selector identifier.
3173 *
3174 * \returns The selector index if the cursor is an objc method or message
3175 * expression and the cursor is pointing to a selector identifier, or -1
3176 * otherwise.
3177 */
3178CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3179
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003180/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003181 * @}
3182 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003183
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003184/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003185 * \defgroup CINDEX_CPP C++ AST introspection
3186 *
3187 * The routines in this group provide access information in the ASTs specific
3188 * to C++ language features.
3189 *
3190 * @{
3191 */
3192
3193/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003194 * \brief Determine if a C++ member function or member function template is
3195 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003196 */
3197CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3198
3199/**
Douglas Gregor211924b2011-05-12 15:17:24 +00003200 * \brief Determine if a C++ member function or member function template is
3201 * explicitly declared 'virtual' or if it overrides a virtual method from
3202 * one of the base classes.
3203 */
3204CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3205
3206/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003207 * \brief Given a cursor that represents a template, determine
3208 * the cursor kind of the specializations would be generated by instantiating
3209 * the template.
3210 *
3211 * This routine can be used to determine what flavor of function template,
3212 * class template, or class template partial specialization is stored in the
3213 * cursor. For example, it can describe whether a class template cursor is
3214 * declared with "struct", "class" or "union".
3215 *
3216 * \param C The cursor to query. This cursor should represent a template
3217 * declaration.
3218 *
3219 * \returns The cursor kind of the specializations that would be generated
3220 * by instantiating the template \p C. If \p C is not a template, returns
3221 * \c CXCursor_NoDeclFound.
3222 */
3223CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3224
3225/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00003226 * \brief Given a cursor that may represent a specialization or instantiation
3227 * of a template, retrieve the cursor that represents the template that it
3228 * specializes or from which it was instantiated.
3229 *
3230 * This routine determines the template involved both for explicit
3231 * specializations of templates and for implicit instantiations of the template,
3232 * both of which are referred to as "specializations". For a class template
3233 * specialization (e.g., \c std::vector<bool>), this routine will return
3234 * either the primary template (\c std::vector) or, if the specialization was
3235 * instantiated from a class template partial specialization, the class template
3236 * partial specialization. For a class template partial specialization and a
3237 * function template specialization (including instantiations), this
3238 * this routine will return the specialized template.
3239 *
3240 * For members of a class template (e.g., member functions, member classes, or
3241 * static data members), returns the specialized or instantiated member.
3242 * Although not strictly "templates" in the C++ language, members of class
3243 * templates have the same notions of specializations and instantiations that
3244 * templates do, so this routine treats them similarly.
3245 *
3246 * \param C A cursor that may be a specialization of a template or a member
3247 * of a template.
3248 *
3249 * \returns If the given cursor is a specialization or instantiation of a
3250 * template or a member thereof, the template or member that it specializes or
3251 * from which it was instantiated. Otherwise, returns a NULL cursor.
3252 */
3253CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00003254
3255/**
3256 * \brief Given a cursor that references something else, return the source range
3257 * covering that reference.
3258 *
3259 * \param C A cursor pointing to a member reference, a declaration reference, or
3260 * an operator call.
3261 * \param NameFlags A bitset with three independent flags:
3262 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3263 * CXNameRange_WantSinglePiece.
3264 * \param PieceIndex For contiguous names or when passing the flag
3265 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3266 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer48d798c2012-06-02 10:20:41 +00003267 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregor430d7a12011-07-25 17:48:11 +00003268 * pieces of the name. See also CXNameRange_WantSinglePiece.
3269 *
3270 * \returns The piece of the name pointed to by the given cursor. If there is no
3271 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3272 */
Francois Pichet48a8d142011-07-25 22:00:44 +00003273CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3274 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00003275 unsigned PieceIndex);
3276
3277enum CXNameRefFlags {
3278 /**
3279 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3280 * range.
3281 */
3282 CXNameRange_WantQualifier = 0x1,
3283
3284 /**
3285 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
3286 * the range.
3287 */
3288 CXNameRange_WantTemplateArgs = 0x2,
3289
3290 /**
3291 * \brief If the name is non-contiguous, return the full spanning range.
3292 *
3293 * Non-contiguous names occur in Objective-C when a selector with two or more
3294 * parameters is used, or in C++ when using an operator:
3295 * \code
3296 * [object doSomething:here withValue:there]; // ObjC
3297 * return some_vector[1]; // C++
3298 * \endcode
3299 */
3300 CXNameRange_WantSinglePiece = 0x4
3301};
Douglas Gregore0329ac2010-09-02 00:07:54 +00003302
3303/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003304 * @}
3305 */
3306
3307/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003308 * \defgroup CINDEX_LEX Token extraction and manipulation
3309 *
3310 * The routines in this group provide access to the tokens within a
3311 * translation unit, along with a semantic mapping of those tokens to
3312 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003313 *
3314 * @{
3315 */
3316
3317/**
3318 * \brief Describes a kind of token.
3319 */
3320typedef enum CXTokenKind {
3321 /**
3322 * \brief A token that contains some kind of punctuation.
3323 */
3324 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003325
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003326 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003327 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003328 */
3329 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003330
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003331 /**
3332 * \brief An identifier (that is not a keyword).
3333 */
3334 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003335
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003336 /**
3337 * \brief A numeric, string, or character literal.
3338 */
3339 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003340
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003341 /**
3342 * \brief A comment.
3343 */
3344 CXToken_Comment
3345} CXTokenKind;
3346
3347/**
3348 * \brief Describes a single preprocessing token.
3349 */
3350typedef struct {
3351 unsigned int_data[4];
3352 void *ptr_data;
3353} CXToken;
3354
3355/**
3356 * \brief Determine the kind of the given token.
3357 */
3358CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003359
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003360/**
3361 * \brief Determine the spelling of the given token.
3362 *
3363 * The spelling of a token is the textual representation of that token, e.g.,
3364 * the text of an identifier or keyword.
3365 */
3366CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003367
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003368/**
3369 * \brief Retrieve the source location of the given token.
3370 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003371CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003372 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003373
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003374/**
3375 * \brief Retrieve a source range that covers the given token.
3376 */
3377CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
3378
3379/**
3380 * \brief Tokenize the source code described by the given range into raw
3381 * lexical tokens.
3382 *
3383 * \param TU the translation unit whose text is being tokenized.
3384 *
3385 * \param Range the source range in which text should be tokenized. All of the
3386 * tokens produced by tokenization will fall within this source range,
3387 *
3388 * \param Tokens this pointer will be set to point to the array of tokens
3389 * that occur within the given source range. The returned pointer must be
3390 * freed with clang_disposeTokens() before the translation unit is destroyed.
3391 *
3392 * \param NumTokens will be set to the number of tokens in the \c *Tokens
3393 * array.
3394 *
3395 */
3396CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
3397 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003398
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003399/**
3400 * \brief Annotate the given set of tokens by providing cursors for each token
3401 * that can be mapped to a specific entity within the abstract syntax tree.
3402 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003403 * This token-annotation routine is equivalent to invoking
3404 * clang_getCursor() for the source locations of each of the
3405 * tokens. The cursors provided are filtered, so that only those
3406 * cursors that have a direct correspondence to the token are
3407 * accepted. For example, given a function call \c f(x),
3408 * clang_getCursor() would provide the following cursors:
3409 *
3410 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
3411 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
3412 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
3413 *
3414 * Only the first and last of these cursors will occur within the
3415 * annotate, since the tokens "f" and "x' directly refer to a function
3416 * and a variable, respectively, but the parentheses are just a small
3417 * part of the full syntax of the function call expression, which is
3418 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003419 *
3420 * \param TU the translation unit that owns the given tokens.
3421 *
3422 * \param Tokens the set of tokens to annotate.
3423 *
3424 * \param NumTokens the number of tokens in \p Tokens.
3425 *
3426 * \param Cursors an array of \p NumTokens cursors, whose contents will be
3427 * replaced with the cursors corresponding to each token.
3428 */
3429CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
3430 CXToken *Tokens, unsigned NumTokens,
3431 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003432
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003433/**
3434 * \brief Free the given set of tokens.
3435 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003436CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003437 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003438
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003439/**
3440 * @}
3441 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003442
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003443/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003444 * \defgroup CINDEX_DEBUG Debugging facilities
3445 *
3446 * These routines are used for testing and debugging, only, and should not
3447 * be relied upon.
3448 *
3449 * @{
3450 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003451
Steve Naroff4ade6d62009-09-23 17:52:52 +00003452/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00003453CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003454CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3455 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00003456 const char **endBuf,
3457 unsigned *startLine,
3458 unsigned *startColumn,
3459 unsigned *endLine,
3460 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00003461CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00003462CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
3463 unsigned stack_size);
3464
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003465/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003466 * @}
3467 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003468
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003469/**
3470 * \defgroup CINDEX_CODE_COMPLET Code completion
3471 *
3472 * Code completion involves taking an (incomplete) source file, along with
3473 * knowledge of where the user is actively editing that file, and suggesting
3474 * syntactically- and semantically-valid constructs that the user might want to
3475 * use at that particular point in the source code. These data structures and
3476 * routines provide support for code completion.
3477 *
3478 * @{
3479 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003480
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003481/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003482 * \brief A semantic string that describes a code-completion result.
3483 *
3484 * A semantic string that describes the formatting of a code-completion
3485 * result as a single "template" of text that should be inserted into the
3486 * source buffer when a particular code-completion result is selected.
3487 * Each semantic string is made up of some number of "chunks", each of which
3488 * contains some text along with a description of what that text means, e.g.,
3489 * the name of the entity being referenced, whether the text chunk is part of
3490 * the template, or whether it is a "placeholder" that the user should replace
3491 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003492 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003493 */
3494typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003495
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003496/**
3497 * \brief A single result of code completion.
3498 */
3499typedef struct {
3500 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003501 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003502 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003503 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003504 * *Decl cursor kinds), describing the entity that the completion is
3505 * referring to.
3506 *
3507 * \todo In the future, we would like to provide a full cursor, to allow
3508 * the client to extract additional information from declaration.
3509 */
3510 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003511
3512 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003513 * \brief The code-completion string that describes how to insert this
3514 * code-completion result into the editing buffer.
3515 */
3516 CXCompletionString CompletionString;
3517} CXCompletionResult;
3518
3519/**
3520 * \brief Describes a single piece of text within a code-completion string.
3521 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003522 * Each "chunk" within a code-completion string (\c CXCompletionString) is
3523 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003524 * should be interpreted by the client or is another completion string.
3525 */
3526enum CXCompletionChunkKind {
3527 /**
3528 * \brief A code-completion string that describes "optional" text that
3529 * could be a part of the template (but is not required).
3530 *
3531 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003532 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003533 * \c clang_getCompletionChunkCompletionString(). The code-completion string
3534 * describes an additional part of the template that is completely optional.
3535 * For example, optional chunks can be used to describe the placeholders for
3536 * arguments that match up with defaulted function parameters, e.g. given:
3537 *
3538 * \code
3539 * void f(int x, float y = 3.14, double z = 2.71828);
3540 * \endcode
3541 *
3542 * The code-completion string for this function would contain:
3543 * - a TypedText chunk for "f".
3544 * - a LeftParen chunk for "(".
3545 * - a Placeholder chunk for "int x"
3546 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
3547 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00003548 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003549 * - an Optional chunk containing the last defaulted argument:
3550 * - a Comma chunk for ","
3551 * - a Placeholder chunk for "double z"
3552 * - a RightParen chunk for ")"
3553 *
Daniel Dunbar71570182010-02-17 08:07:44 +00003554 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003555 * - Completely ignore optional chunks, in which case the template for the
3556 * function "f" would only include the first parameter ("int x").
3557 * - Fully expand all optional chunks, in which case the template for the
3558 * function "f" would have all of the parameters.
3559 */
3560 CXCompletionChunk_Optional,
3561 /**
3562 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003563 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003564 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003565 * There will be exactly one "typed text" chunk in a semantic string, which
3566 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003567 * declaration that could be used at the current code point. Clients are
3568 * expected to filter the code-completion results based on the text in this
3569 * chunk.
3570 */
3571 CXCompletionChunk_TypedText,
3572 /**
3573 * \brief Text that should be inserted as part of a code-completion result.
3574 *
3575 * A "text" chunk represents text that is part of the template to be
3576 * inserted into user code should this particular code-completion result
3577 * be selected.
3578 */
3579 CXCompletionChunk_Text,
3580 /**
3581 * \brief Placeholder text that should be replaced by the user.
3582 *
3583 * A "placeholder" chunk marks a place where the user should insert text
3584 * into the code-completion template. For example, placeholders might mark
3585 * the function parameters for a function declaration, to indicate that the
3586 * user should provide arguments for each of those parameters. The actual
3587 * text in a placeholder is a suggestion for the text to display before
3588 * the user replaces the placeholder with real code.
3589 */
3590 CXCompletionChunk_Placeholder,
3591 /**
3592 * \brief Informative text that should be displayed but never inserted as
3593 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003594 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003595 * An "informative" chunk contains annotations that can be displayed to
3596 * help the user decide whether a particular code-completion result is the
3597 * right option, but which is not part of the actual template to be inserted
3598 * by code completion.
3599 */
3600 CXCompletionChunk_Informative,
3601 /**
3602 * \brief Text that describes the current parameter when code-completion is
3603 * referring to function call, message send, or template specialization.
3604 *
3605 * A "current parameter" chunk occurs when code-completion is providing
3606 * information about a parameter corresponding to the argument at the
3607 * code-completion point. For example, given a function
3608 *
3609 * \code
3610 * int add(int x, int y);
3611 * \endcode
3612 *
3613 * and the source code \c add(, where the code-completion point is after the
3614 * "(", the code-completion string will contain a "current parameter" chunk
3615 * for "int x", indicating that the current argument will initialize that
3616 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003617 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003618 * "current paremeter" chunk to "int y".
3619 */
3620 CXCompletionChunk_CurrentParameter,
3621 /**
3622 * \brief A left parenthesis ('('), used to initiate a function call or
3623 * signal the beginning of a function parameter list.
3624 */
3625 CXCompletionChunk_LeftParen,
3626 /**
3627 * \brief A right parenthesis (')'), used to finish a function call or
3628 * signal the end of a function parameter list.
3629 */
3630 CXCompletionChunk_RightParen,
3631 /**
3632 * \brief A left bracket ('[').
3633 */
3634 CXCompletionChunk_LeftBracket,
3635 /**
3636 * \brief A right bracket (']').
3637 */
3638 CXCompletionChunk_RightBracket,
3639 /**
3640 * \brief A left brace ('{').
3641 */
3642 CXCompletionChunk_LeftBrace,
3643 /**
3644 * \brief A right brace ('}').
3645 */
3646 CXCompletionChunk_RightBrace,
3647 /**
3648 * \brief A left angle bracket ('<').
3649 */
3650 CXCompletionChunk_LeftAngle,
3651 /**
3652 * \brief A right angle bracket ('>').
3653 */
3654 CXCompletionChunk_RightAngle,
3655 /**
3656 * \brief A comma separator (',').
3657 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003658 CXCompletionChunk_Comma,
3659 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003660 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003661 *
3662 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003663 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003664 * expression using the given completion string would have.
3665 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00003666 CXCompletionChunk_ResultType,
3667 /**
3668 * \brief A colon (':').
3669 */
3670 CXCompletionChunk_Colon,
3671 /**
3672 * \brief A semicolon (';').
3673 */
3674 CXCompletionChunk_SemiColon,
3675 /**
3676 * \brief An '=' sign.
3677 */
3678 CXCompletionChunk_Equal,
3679 /**
3680 * Horizontal space (' ').
3681 */
3682 CXCompletionChunk_HorizontalSpace,
3683 /**
3684 * Vertical space ('\n'), after which it is generally a good idea to
3685 * perform indentation.
3686 */
3687 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003688};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003689
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003690/**
3691 * \brief Determine the kind of a particular chunk within a completion string.
3692 *
3693 * \param completion_string the completion string to query.
3694 *
3695 * \param chunk_number the 0-based index of the chunk in the completion string.
3696 *
3697 * \returns the kind of the chunk at the index \c chunk_number.
3698 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003699CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003700clang_getCompletionChunkKind(CXCompletionString completion_string,
3701 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003702
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003703/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003704 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003705 * completion string.
3706 *
3707 * \param completion_string the completion string to query.
3708 *
3709 * \param chunk_number the 0-based index of the chunk in the completion string.
3710 *
3711 * \returns the text associated with the chunk at index \c chunk_number.
3712 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00003713CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003714clang_getCompletionChunkText(CXCompletionString completion_string,
3715 unsigned chunk_number);
3716
3717/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003718 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003719 * within a completion string.
3720 *
3721 * \param completion_string the completion string to query.
3722 *
3723 * \param chunk_number the 0-based index of the chunk in the completion string.
3724 *
3725 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003726 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003727 */
3728CINDEX_LINKAGE CXCompletionString
3729clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
3730 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003731
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003732/**
3733 * \brief Retrieve the number of chunks in the given code-completion string.
3734 */
3735CINDEX_LINKAGE unsigned
3736clang_getNumCompletionChunks(CXCompletionString completion_string);
3737
3738/**
Douglas Gregor12e13132010-05-26 22:00:08 +00003739 * \brief Determine the priority of this code completion.
3740 *
3741 * The priority of a code completion indicates how likely it is that this
3742 * particular completion is the completion that the user will select. The
3743 * priority is selected by various internal heuristics.
3744 *
3745 * \param completion_string The completion string to query.
3746 *
3747 * \returns The priority of this completion string. Smaller values indicate
3748 * higher-priority (more likely) completions.
3749 */
3750CINDEX_LINKAGE unsigned
3751clang_getCompletionPriority(CXCompletionString completion_string);
3752
3753/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00003754 * \brief Determine the availability of the entity that this code-completion
3755 * string refers to.
3756 *
3757 * \param completion_string The completion string to query.
3758 *
3759 * \returns The availability of the completion string.
3760 */
3761CINDEX_LINKAGE enum CXAvailabilityKind
3762clang_getCompletionAvailability(CXCompletionString completion_string);
3763
3764/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003765 * \brief Retrieve the number of annotations associated with the given
3766 * completion string.
3767 *
3768 * \param completion_string the completion string to query.
3769 *
3770 * \returns the number of annotations associated with the given completion
3771 * string.
3772 */
3773CINDEX_LINKAGE unsigned
3774clang_getCompletionNumAnnotations(CXCompletionString completion_string);
3775
3776/**
3777 * \brief Retrieve the annotation associated with the given completion string.
3778 *
3779 * \param completion_string the completion string to query.
3780 *
3781 * \param annotation_number the 0-based index of the annotation of the
3782 * completion string.
3783 *
3784 * \returns annotation string associated with the completion at index
3785 * \c annotation_number, or a NULL string if that annotation is not available.
3786 */
3787CINDEX_LINKAGE CXString
3788clang_getCompletionAnnotation(CXCompletionString completion_string,
3789 unsigned annotation_number);
3790
3791/**
Douglas Gregorba103062012-03-27 23:34:16 +00003792 * \brief Retrieve the parent context of the given completion string.
3793 *
3794 * The parent context of a completion string is the semantic parent of
3795 * the declaration (if any) that the code completion represents. For example,
3796 * a code completion for an Objective-C method would have the method's class
3797 * or protocol as its context.
3798 *
3799 * \param completion_string The code completion string whose parent is
3800 * being queried.
3801 *
3802 * \param kind If non-NULL, will be set to the kind of the parent context,
3803 * or CXCursor_NotImplemented if there is no context.
3804 *
3805 * \param Returns the name of the completion parent, e.g., "NSObject" if
3806 * the completion string represents a method in the NSObject class.
3807 */
3808CINDEX_LINKAGE CXString
3809clang_getCompletionParent(CXCompletionString completion_string,
3810 enum CXCursorKind *kind);
3811/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00003812 * \brief Retrieve a completion string for an arbitrary declaration or macro
3813 * definition cursor.
3814 *
3815 * \param cursor The cursor to query.
3816 *
3817 * \returns A non-context-sensitive completion string for declaration and macro
3818 * definition cursors, or NULL for other kinds of cursors.
3819 */
3820CINDEX_LINKAGE CXCompletionString
3821clang_getCursorCompletionString(CXCursor cursor);
3822
3823/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003824 * \brief Contains the results of code-completion.
3825 *
3826 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00003827 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00003828 * \c clang_disposeCodeCompleteResults.
3829 */
3830typedef struct {
3831 /**
3832 * \brief The code-completion results.
3833 */
3834 CXCompletionResult *Results;
3835
3836 /**
3837 * \brief The number of code-completion results stored in the
3838 * \c Results array.
3839 */
3840 unsigned NumResults;
3841} CXCodeCompleteResults;
3842
3843/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003844 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3845 * modify its behavior.
3846 *
3847 * The enumerators in this enumeration can be bitwise-OR'd together to
3848 * provide multiple options to \c clang_codeCompleteAt().
3849 */
3850enum CXCodeComplete_Flags {
3851 /**
3852 * \brief Whether to include macros within the set of code
3853 * completions returned.
3854 */
3855 CXCodeComplete_IncludeMacros = 0x01,
3856
3857 /**
3858 * \brief Whether to include code patterns for language constructs
3859 * within the set of code completions, e.g., for loops.
3860 */
3861 CXCodeComplete_IncludeCodePatterns = 0x02
3862};
3863
3864/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003865 * \brief Bits that represent the context under which completion is occurring.
3866 *
3867 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3868 * contexts are occurring simultaneously.
3869 */
3870enum CXCompletionContext {
3871 /**
3872 * \brief The context for completions is unexposed, as only Clang results
3873 * should be included. (This is equivalent to having no context bits set.)
3874 */
3875 CXCompletionContext_Unexposed = 0,
3876
3877 /**
3878 * \brief Completions for any possible type should be included in the results.
3879 */
3880 CXCompletionContext_AnyType = 1 << 0,
3881
3882 /**
3883 * \brief Completions for any possible value (variables, function calls, etc.)
3884 * should be included in the results.
3885 */
3886 CXCompletionContext_AnyValue = 1 << 1,
3887 /**
3888 * \brief Completions for values that resolve to an Objective-C object should
3889 * be included in the results.
3890 */
3891 CXCompletionContext_ObjCObjectValue = 1 << 2,
3892 /**
3893 * \brief Completions for values that resolve to an Objective-C selector
3894 * should be included in the results.
3895 */
3896 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3897 /**
3898 * \brief Completions for values that resolve to a C++ class type should be
3899 * included in the results.
3900 */
3901 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3902
3903 /**
3904 * \brief Completions for fields of the member being accessed using the dot
3905 * operator should be included in the results.
3906 */
3907 CXCompletionContext_DotMemberAccess = 1 << 5,
3908 /**
3909 * \brief Completions for fields of the member being accessed using the arrow
3910 * operator should be included in the results.
3911 */
3912 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3913 /**
3914 * \brief Completions for properties of the Objective-C object being accessed
3915 * using the dot operator should be included in the results.
3916 */
3917 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3918
3919 /**
3920 * \brief Completions for enum tags should be included in the results.
3921 */
3922 CXCompletionContext_EnumTag = 1 << 8,
3923 /**
3924 * \brief Completions for union tags should be included in the results.
3925 */
3926 CXCompletionContext_UnionTag = 1 << 9,
3927 /**
3928 * \brief Completions for struct tags should be included in the results.
3929 */
3930 CXCompletionContext_StructTag = 1 << 10,
3931
3932 /**
3933 * \brief Completions for C++ class names should be included in the results.
3934 */
3935 CXCompletionContext_ClassTag = 1 << 11,
3936 /**
3937 * \brief Completions for C++ namespaces and namespace aliases should be
3938 * included in the results.
3939 */
3940 CXCompletionContext_Namespace = 1 << 12,
3941 /**
3942 * \brief Completions for C++ nested name specifiers should be included in
3943 * the results.
3944 */
3945 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3946
3947 /**
3948 * \brief Completions for Objective-C interfaces (classes) should be included
3949 * in the results.
3950 */
3951 CXCompletionContext_ObjCInterface = 1 << 14,
3952 /**
3953 * \brief Completions for Objective-C protocols should be included in
3954 * the results.
3955 */
3956 CXCompletionContext_ObjCProtocol = 1 << 15,
3957 /**
3958 * \brief Completions for Objective-C categories should be included in
3959 * the results.
3960 */
3961 CXCompletionContext_ObjCCategory = 1 << 16,
3962 /**
3963 * \brief Completions for Objective-C instance messages should be included
3964 * in the results.
3965 */
3966 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3967 /**
3968 * \brief Completions for Objective-C class messages should be included in
3969 * the results.
3970 */
3971 CXCompletionContext_ObjCClassMessage = 1 << 18,
3972 /**
3973 * \brief Completions for Objective-C selector names should be included in
3974 * the results.
3975 */
3976 CXCompletionContext_ObjCSelectorName = 1 << 19,
3977
3978 /**
3979 * \brief Completions for preprocessor macro names should be included in
3980 * the results.
3981 */
3982 CXCompletionContext_MacroName = 1 << 20,
3983
3984 /**
3985 * \brief Natural language completions should be included in the results.
3986 */
3987 CXCompletionContext_NaturalLanguage = 1 << 21,
3988
3989 /**
3990 * \brief The current context is unknown, so set all contexts.
3991 */
3992 CXCompletionContext_Unknown = ((1 << 22) - 1)
3993};
3994
3995/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003996 * \brief Returns a default set of code-completion options that can be
3997 * passed to\c clang_codeCompleteAt().
3998 */
3999CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4000
4001/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004002 * \brief Perform code completion at a given location in a translation unit.
4003 *
4004 * This function performs code completion at a particular file, line, and
4005 * column within source code, providing results that suggest potential
4006 * code snippets based on the context of the completion. The basic model
4007 * for code completion is that Clang will parse a complete source file,
4008 * performing syntax checking up to the location where code-completion has
4009 * been requested. At that point, a special code-completion token is passed
4010 * to the parser, which recognizes this token and determines, based on the
4011 * current location in the C/Objective-C/C++ grammar and the state of
4012 * semantic analysis, what completions to provide. These completions are
4013 * returned via a new \c CXCodeCompleteResults structure.
4014 *
4015 * Code completion itself is meant to be triggered by the client when the
4016 * user types punctuation characters or whitespace, at which point the
4017 * code-completion location will coincide with the cursor. For example, if \c p
4018 * is a pointer, code-completion might be triggered after the "-" and then
4019 * after the ">" in \c p->. When the code-completion location is afer the ">",
4020 * the completion results will provide, e.g., the members of the struct that
4021 * "p" points to. The client is responsible for placing the cursor at the
4022 * beginning of the token currently being typed, then filtering the results
4023 * based on the contents of the token. For example, when code-completing for
4024 * the expression \c p->get, the client should provide the location just after
4025 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4026 * client can filter the results based on the current token text ("get"), only
4027 * showing those results that start with "get". The intent of this interface
4028 * is to separate the relatively high-latency acquisition of code-completion
4029 * results from the filtering of results on a per-character basis, which must
4030 * have a lower latency.
4031 *
4032 * \param TU The translation unit in which code-completion should
4033 * occur. The source files for this translation unit need not be
4034 * completely up-to-date (and the contents of those source files may
4035 * be overridden via \p unsaved_files). Cursors referring into the
4036 * translation unit may be invalidated by this invocation.
4037 *
4038 * \param complete_filename The name of the source file where code
4039 * completion should be performed. This filename may be any file
4040 * included in the translation unit.
4041 *
4042 * \param complete_line The line at which code-completion should occur.
4043 *
4044 * \param complete_column The column at which code-completion should occur.
4045 * Note that the column should point just after the syntactic construct that
4046 * initiated code completion, and not in the middle of a lexical token.
4047 *
4048 * \param unsaved_files the Tiles that have not yet been saved to disk
4049 * but may be required for parsing or code completion, including the
4050 * contents of those files. The contents and name of these files (as
4051 * specified by CXUnsavedFile) are copied when necessary, so the
4052 * client only needs to guarantee their validity until the call to
4053 * this function returns.
4054 *
4055 * \param num_unsaved_files The number of unsaved file entries in \p
4056 * unsaved_files.
4057 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00004058 * \param options Extra options that control the behavior of code
4059 * completion, expressed as a bitwise OR of the enumerators of the
4060 * CXCodeComplete_Flags enumeration. The
4061 * \c clang_defaultCodeCompleteOptions() function returns a default set
4062 * of code-completion options.
4063 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004064 * \returns If successful, a new \c CXCodeCompleteResults structure
4065 * containing code-completion results, which should eventually be
4066 * freed with \c clang_disposeCodeCompleteResults(). If code
4067 * completion fails, returns NULL.
4068 */
4069CINDEX_LINKAGE
4070CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4071 const char *complete_filename,
4072 unsigned complete_line,
4073 unsigned complete_column,
4074 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00004075 unsigned num_unsaved_files,
4076 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004077
4078/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00004079 * \brief Sort the code-completion results in case-insensitive alphabetical
4080 * order.
4081 *
4082 * \param Results The set of results to sort.
4083 * \param NumResults The number of results in \p Results.
4084 */
4085CINDEX_LINKAGE
4086void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4087 unsigned NumResults);
4088
4089/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004090 * \brief Free the given set of code-completion results.
4091 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004092CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00004093void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00004094
Douglas Gregor20d416c2010-01-20 01:10:47 +00004095/**
Douglas Gregora88084b2010-02-18 18:08:43 +00004096 * \brief Determine the number of diagnostics produced prior to the
4097 * location where code completion was performed.
4098 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004099CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004100unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4101
4102/**
4103 * \brief Retrieve a diagnostic associated with the given code completion.
4104 *
4105 * \param Result the code completion results to query.
4106 * \param Index the zero-based diagnostic number to retrieve.
4107 *
4108 * \returns the requested diagnostic. This diagnostic must be freed
4109 * via a call to \c clang_disposeDiagnostic().
4110 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004111CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004112CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4113 unsigned Index);
4114
4115/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004116 * \brief Determines what compeltions are appropriate for the context
4117 * the given code completion.
4118 *
4119 * \param Results the code completion results to query
4120 *
4121 * \returns the kinds of completions that are appropriate for use
4122 * along with the given code completion results.
4123 */
4124CINDEX_LINKAGE
4125unsigned long long clang_codeCompleteGetContexts(
4126 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00004127
4128/**
4129 * \brief Returns the cursor kind for the container for the current code
4130 * completion context. The container is only guaranteed to be set for
4131 * contexts where a container exists (i.e. member accesses or Objective-C
4132 * message sends); if there is not a container, this function will return
4133 * CXCursor_InvalidCode.
4134 *
4135 * \param Results the code completion results to query
4136 *
4137 * \param IsIncomplete on return, this value will be false if Clang has complete
4138 * information about the container. If Clang does not have complete
4139 * information, this value will be true.
4140 *
4141 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4142 * container
4143 */
4144CINDEX_LINKAGE
4145enum CXCursorKind clang_codeCompleteGetContainerKind(
4146 CXCodeCompleteResults *Results,
4147 unsigned *IsIncomplete);
4148
4149/**
4150 * \brief Returns the USR for the container for the current code completion
4151 * context. If there is not a container for the current context, this
4152 * function will return the empty string.
4153 *
4154 * \param Results the code completion results to query
4155 *
4156 * \returns the USR for the container
4157 */
4158CINDEX_LINKAGE
4159CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00004160
Douglas Gregor0a47d692011-07-26 15:24:30 +00004161
4162/**
4163 * \brief Returns the currently-entered selector for an Objective-C message
4164 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4165 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4166 * CXCompletionContext_ObjCClassMessage.
4167 *
4168 * \param Results the code completion results to query
4169 *
4170 * \returns the selector (or partial selector) that has been entered thus far
4171 * for an Objective-C message send.
4172 */
4173CINDEX_LINKAGE
4174CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4175
Douglas Gregor3da626b2011-07-07 16:03:39 +00004176/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00004177 * @}
4178 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004179
4180
Ted Kremenek04bb7162010-01-22 22:44:15 +00004181/**
4182 * \defgroup CINDEX_MISC Miscellaneous utility functions
4183 *
4184 * @{
4185 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00004186
4187/**
4188 * \brief Return a version string, suitable for showing to a user, but not
4189 * intended to be parsed (the format is not guaranteed to be stable).
4190 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00004191CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00004192
Ted Kremenekd2427dd2011-03-18 23:05:39 +00004193
4194/**
4195 * \brief Enable/disable crash recovery.
4196 *
4197 * \param Flag to indicate if crash recovery is enabled. A non-zero value
4198 * enables crash recovery, while 0 disables it.
4199 */
4200CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4201
Ted Kremenek16b55a72010-01-26 19:31:51 +00004202 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00004203 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00004204 * (used with clang_getInclusions()).
4205 *
4206 * This visitor function will be invoked by clang_getInclusions() for each
4207 * file included (either at the top-level or by #include directives) within
4208 * a translation unit. The first argument is the file being included, and
4209 * the second and third arguments provide the inclusion stack. The
4210 * array is sorted in order of immediate inclusion. For example,
4211 * the first element refers to the location that included 'included_file'.
4212 */
4213typedef void (*CXInclusionVisitor)(CXFile included_file,
4214 CXSourceLocation* inclusion_stack,
4215 unsigned include_len,
4216 CXClientData client_data);
4217
4218/**
4219 * \brief Visit the set of preprocessor inclusions in a translation unit.
4220 * The visitor function is called with the provided data for every included
4221 * file. This does not include headers included by the PCH file (unless one
4222 * is inspecting the inclusions in the PCH file itself).
4223 */
4224CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4225 CXInclusionVisitor visitor,
4226 CXClientData client_data);
4227
4228/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00004229 * @}
4230 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004231
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004232/** \defgroup CINDEX_REMAPPING Remapping functions
4233 *
4234 * @{
4235 */
4236
4237/**
4238 * \brief A remapping of original source files and their translated files.
4239 */
4240typedef void *CXRemapping;
4241
4242/**
4243 * \brief Retrieve a remapping.
4244 *
4245 * \param path the path that contains metadata about remappings.
4246 *
4247 * \returns the requested remapping. This remapping must be freed
4248 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4249 */
4250CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4251
4252/**
Ted Kremenek30660a82012-03-06 20:06:33 +00004253 * \brief Retrieve a remapping.
4254 *
4255 * \param filePaths pointer to an array of file paths containing remapping info.
4256 *
4257 * \param numFiles number of file paths.
4258 *
4259 * \returns the requested remapping. This remapping must be freed
4260 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4261 */
4262CINDEX_LINKAGE
4263CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
4264 unsigned numFiles);
4265
4266/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004267 * \brief Determine the number of remappings.
4268 */
4269CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4270
4271/**
4272 * \brief Get the original and the associated filename from the remapping.
4273 *
4274 * \param original If non-NULL, will be set to the original filename.
4275 *
4276 * \param transformed If non-NULL, will be set to the filename that the original
4277 * is associated with.
4278 */
4279CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4280 CXString *original, CXString *transformed);
4281
4282/**
4283 * \brief Dispose the remapping.
4284 */
4285CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4286
4287/**
4288 * @}
4289 */
4290
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004291/** \defgroup CINDEX_HIGH Higher level API functions
4292 *
4293 * @{
4294 */
4295
4296enum CXVisitorResult {
4297 CXVisit_Break,
4298 CXVisit_Continue
4299};
4300
4301typedef struct {
4302 void *context;
4303 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4304} CXCursorAndRangeVisitor;
4305
4306/**
4307 * \brief Find references of a declaration in a specific file.
4308 *
4309 * \param cursor pointing to a declaration or a reference of one.
4310 *
4311 * \param file to search for references.
4312 *
4313 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4314 * each reference found.
4315 * The CXSourceRange will point inside the file; if the reference is inside
4316 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4317 */
4318CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4319 CXCursorAndRangeVisitor visitor);
4320
4321#ifdef __has_feature
4322# if __has_feature(blocks)
4323
4324typedef enum CXVisitorResult
4325 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4326
4327CINDEX_LINKAGE
4328void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4329 CXCursorAndRangeVisitorBlock);
4330
4331# endif
4332#endif
4333
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004334/**
4335 * \brief The client's data object that is associated with a CXFile.
4336 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004337typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004338
4339/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004340 * \brief The client's data object that is associated with a semantic entity.
4341 */
4342typedef void *CXIdxClientEntity;
4343
4344/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004345 * \brief The client's data object that is associated with a semantic container
4346 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004347 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004348typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004349
4350/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004351 * \brief The client's data object that is associated with an AST file (PCH
4352 * or module).
4353 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004354typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004355
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004356/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004357 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004358 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004359typedef struct {
4360 void *ptr_data[2];
4361 unsigned int_data;
4362} CXIdxLoc;
4363
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004364/**
4365 * \brief Data for \see ppIncludedFile callback.
4366 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004367typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004368 /**
4369 * \brief Location of '#' in the #include/#import directive.
4370 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004371 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004372 /**
4373 * \brief Filename as written in the #include/#import directive.
4374 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004375 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004376 /**
4377 * \brief The actual file that the #include/#import directive resolved to.
4378 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004379 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004380 int isImport;
4381 int isAngled;
4382} CXIdxIncludedFileInfo;
4383
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004384/**
4385 * \brief Data for \see importedASTFile callback.
4386 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004387typedef struct {
4388 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004389 /**
4390 * \brief Location where the file is imported. It is useful mostly for
4391 * modules.
4392 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004393 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004394 /**
4395 * \brief Non-zero if the AST file is a module otherwise it's a PCH.
4396 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004397 int isModule;
4398} CXIdxImportedASTFileInfo;
4399
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004400typedef enum {
4401 CXIdxEntity_Unexposed = 0,
4402 CXIdxEntity_Typedef = 1,
4403 CXIdxEntity_Function = 2,
4404 CXIdxEntity_Variable = 3,
4405 CXIdxEntity_Field = 4,
4406 CXIdxEntity_EnumConstant = 5,
4407
4408 CXIdxEntity_ObjCClass = 6,
4409 CXIdxEntity_ObjCProtocol = 7,
4410 CXIdxEntity_ObjCCategory = 8,
4411
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004412 CXIdxEntity_ObjCInstanceMethod = 9,
4413 CXIdxEntity_ObjCClassMethod = 10,
4414 CXIdxEntity_ObjCProperty = 11,
4415 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004416
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004417 CXIdxEntity_Enum = 13,
4418 CXIdxEntity_Struct = 14,
4419 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004420
4421 CXIdxEntity_CXXClass = 16,
4422 CXIdxEntity_CXXNamespace = 17,
4423 CXIdxEntity_CXXNamespaceAlias = 18,
4424 CXIdxEntity_CXXStaticVariable = 19,
4425 CXIdxEntity_CXXStaticMethod = 20,
4426 CXIdxEntity_CXXInstanceMethod = 21,
4427 CXIdxEntity_CXXConstructor = 22,
4428 CXIdxEntity_CXXDestructor = 23,
4429 CXIdxEntity_CXXConversionFunction = 24,
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004430 CXIdxEntity_CXXTypeAlias = 25
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004431
4432} CXIdxEntityKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004433
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004434typedef enum {
4435 CXIdxEntityLang_None = 0,
4436 CXIdxEntityLang_C = 1,
4437 CXIdxEntityLang_ObjC = 2,
4438 CXIdxEntityLang_CXX = 3
4439} CXIdxEntityLanguage;
4440
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004441/**
4442 * \brief Extra C++ template information for an entity. This can apply to:
4443 * CXIdxEntity_Function
4444 * CXIdxEntity_CXXClass
4445 * CXIdxEntity_CXXStaticMethod
4446 * CXIdxEntity_CXXInstanceMethod
4447 * CXIdxEntity_CXXConstructor
4448 * CXIdxEntity_CXXConversionFunction
4449 * CXIdxEntity_CXXTypeAlias
4450 */
4451typedef enum {
4452 CXIdxEntity_NonTemplate = 0,
4453 CXIdxEntity_Template = 1,
4454 CXIdxEntity_TemplatePartialSpecialization = 2,
4455 CXIdxEntity_TemplateSpecialization = 3
4456} CXIdxEntityCXXTemplateKind;
4457
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004458typedef enum {
4459 CXIdxAttr_Unexposed = 0,
4460 CXIdxAttr_IBAction = 1,
4461 CXIdxAttr_IBOutlet = 2,
4462 CXIdxAttr_IBOutletCollection = 3
4463} CXIdxAttrKind;
4464
4465typedef struct {
4466 CXIdxAttrKind kind;
4467 CXCursor cursor;
4468 CXIdxLoc loc;
4469} CXIdxAttrInfo;
4470
4471typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00004472 CXIdxEntityKind kind;
4473 CXIdxEntityCXXTemplateKind templateKind;
4474 CXIdxEntityLanguage lang;
4475 const char *name;
4476 const char *USR;
4477 CXCursor cursor;
4478 const CXIdxAttrInfo *const *attributes;
4479 unsigned numAttributes;
4480} CXIdxEntityInfo;
4481
4482typedef struct {
4483 CXCursor cursor;
4484} CXIdxContainerInfo;
4485
4486typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004487 const CXIdxAttrInfo *attrInfo;
4488 const CXIdxEntityInfo *objcClass;
4489 CXCursor classCursor;
4490 CXIdxLoc classLoc;
4491} CXIdxIBOutletCollectionAttrInfo;
4492
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004493typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004494 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004495 CXCursor cursor;
4496 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004497 const CXIdxContainerInfo *semanticContainer;
4498 /**
4499 * \brief Generally same as \see semanticContainer but can be different in
4500 * cases like out-of-line C++ member functions.
4501 */
4502 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004503 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004504 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004505 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004506 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004507 /**
4508 * \brief Whether the declaration exists in code or was created implicitly
4509 * by the compiler, e.g. implicit objc methods for properties.
4510 */
4511 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004512 const CXIdxAttrInfo *const *attributes;
4513 unsigned numAttributes;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004514} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004515
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004516typedef enum {
4517 CXIdxObjCContainer_ForwardRef = 0,
4518 CXIdxObjCContainer_Interface = 1,
4519 CXIdxObjCContainer_Implementation = 2
4520} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004521
4522typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004523 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004524 CXIdxObjCContainerKind kind;
4525} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004526
4527typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004528 const CXIdxEntityInfo *base;
4529 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004530 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004531} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004532
4533typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004534 const CXIdxEntityInfo *protocol;
4535 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004536 CXIdxLoc loc;
4537} CXIdxObjCProtocolRefInfo;
4538
4539typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004540 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004541 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004542} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004543
4544typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004545 const CXIdxObjCContainerDeclInfo *containerInfo;
4546 const CXIdxBaseClassInfo *superInfo;
4547 const CXIdxObjCProtocolRefListInfo *protocols;
4548} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004549
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004550typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00004551 const CXIdxObjCContainerDeclInfo *containerInfo;
4552 const CXIdxEntityInfo *objcClass;
4553 CXCursor classCursor;
4554 CXIdxLoc classLoc;
4555 const CXIdxObjCProtocolRefListInfo *protocols;
4556} CXIdxObjCCategoryDeclInfo;
4557
4558typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004559 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004560 const CXIdxEntityInfo *getter;
4561 const CXIdxEntityInfo *setter;
4562} CXIdxObjCPropertyDeclInfo;
4563
4564typedef struct {
4565 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004566 const CXIdxBaseClassInfo *const *bases;
4567 unsigned numBases;
4568} CXIdxCXXClassDeclInfo;
4569
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004570/**
4571 * \brief Data for \see indexEntityReference callback.
4572 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004573typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004574 /**
4575 * \brief The entity is referenced directly in user's code.
4576 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004577 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004578 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004579 * \brief An implicit reference, e.g. a reference of an ObjC method via the
4580 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004581 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004582 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004583} CXIdxEntityRefKind;
4584
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004585/**
4586 * \brief Data for \see indexEntityReference callback.
4587 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004588typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004589 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004590 /**
4591 * \brief Reference cursor.
4592 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004593 CXCursor cursor;
4594 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004595 /**
4596 * \brief The entity that gets referenced.
4597 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004598 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004599 /**
4600 * \brief Immediate "parent" of the reference. For example:
4601 *
4602 * \code
4603 * Foo *var;
4604 * \endcode
4605 *
4606 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004607 * For references inside statement bodies of functions/methods,
4608 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004609 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004610 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004611 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004612 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004613 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004614 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004615} CXIdxEntityRefInfo;
4616
4617typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004618 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004619 * \brief Called periodically to check whether indexing should be aborted.
4620 * Should return 0 to continue, and non-zero to abort.
4621 */
4622 int (*abortQuery)(CXClientData client_data, void *reserved);
4623
4624 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004625 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004626 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004627 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004628 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004629
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004630 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
4631 CXFile mainFile, void *reserved);
4632
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004633 /**
4634 * \brief Called when a file gets #included/#imported.
4635 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004636 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004637 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004638
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004639 /**
4640 * \brief Called when a AST file (PCH or module) gets imported.
4641 *
4642 * AST files will not get indexed (there will not be callbacks to index all
4643 * the entities in an AST file). The recommended action is that, if the AST
4644 * file is not already indexed, to block further indexing and initiate a new
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004645 * indexing job specific to the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004646 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004647 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004648 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004649
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004650 /**
4651 * \brief Called at the beginning of indexing a translation unit.
4652 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004653 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004654 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004655
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004656 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004657 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004658
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004659 /**
4660 * \brief Called to index a reference of an entity.
4661 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004662 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004663 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004664
4665} IndexerCallbacks;
4666
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004667CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004668CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
4669clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004670
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004671CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
4672clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
4673
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004674CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004675const CXIdxObjCCategoryDeclInfo *
4676clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
4677
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004678CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
4679clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004680
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004681CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
4682clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
4683
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004684CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
4685clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
4686
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004687CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
4688clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
4689
4690/**
4691 * \brief For retrieving a custom CXIdxClientContainer attached to a
4692 * container.
4693 */
4694CINDEX_LINKAGE CXIdxClientContainer
4695clang_index_getClientContainer(const CXIdxContainerInfo *);
4696
4697/**
4698 * \brief For setting a custom CXIdxClientContainer attached to a
4699 * container.
4700 */
4701CINDEX_LINKAGE void
4702clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
4703
4704/**
4705 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
4706 */
4707CINDEX_LINKAGE CXIdxClientEntity
4708clang_index_getClientEntity(const CXIdxEntityInfo *);
4709
4710/**
4711 * \brief For setting a custom CXIdxClientEntity attached to an entity.
4712 */
4713CINDEX_LINKAGE void
4714clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
4715
4716/**
4717 * \brief An indexing action, to be applied to one or multiple translation units
4718 * but not on concurrent threads. If there are threads doing indexing
4719 * concurrently, they should use different CXIndexAction objects.
4720 */
4721typedef void *CXIndexAction;
4722
4723/**
4724 * \brief An indexing action, to be applied to one or multiple translation units
4725 * but not on concurrent threads. If there are threads doing indexing
4726 * concurrently, they should use different CXIndexAction objects.
4727 *
4728 * \param CIdx The index object with which the index action will be associated.
4729 */
4730CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
4731
4732/**
4733 * \brief Destroy the given index action.
4734 *
4735 * The index action must not be destroyed until all of the translation units
4736 * created within that index action have been destroyed.
4737 */
4738CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
4739
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004740typedef enum {
4741 /**
4742 * \brief Used to indicate that no special indexing options are needed.
4743 */
4744 CXIndexOpt_None = 0x0,
4745
4746 /**
4747 * \brief Used to indicate that \see indexEntityReference should be invoked
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004748 * for only one reference of an entity per source file that does not also
4749 * include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004750 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00004751 CXIndexOpt_SuppressRedundantRefs = 0x1,
4752
4753 /**
4754 * \brief Function-local symbols should be indexed. If this is not set
4755 * function-local symbols will be ignored.
4756 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00004757 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
4758
4759 /**
4760 * \brief Implicit function/class template instantiations should be indexed.
4761 * If this is not set, implicit instantiations will be ignored.
4762 */
Argyrios Kyrtzidisb49a29f2012-03-27 21:38:03 +00004763 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
4764
4765 /**
4766 * \brief Suppress all compiler warnings when parsing for indexing.
4767 */
4768 CXIndexOpt_SuppressWarnings = 0x8
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004769} CXIndexOptFlags;
4770
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004771/**
4772 * \brief Index the given source file and the translation unit corresponding
4773 * to that file via callbacks implemented through \see IndexerCallbacks.
4774 *
4775 * \param client_data pointer data supplied by the client, which will
4776 * be passed to the invoked callbacks.
4777 *
4778 * \param index_callbacks Pointer to indexing callbacks that the client
4779 * implements.
4780 *
4781 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets
4782 * passed in index_callbacks.
4783 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004784 * \param index_options A bitmask of options that affects how indexing is
4785 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004786 *
4787 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
4788 * after indexing is finished. Set to NULL if you do not require it.
4789 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004790 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004791 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004792 *
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004793 * The rest of the parameters are the same as \see clang_parseTranslationUnit.
4794 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004795CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004796 CXClientData client_data,
4797 IndexerCallbacks *index_callbacks,
4798 unsigned index_callbacks_size,
4799 unsigned index_options,
4800 const char *source_filename,
4801 const char * const *command_line_args,
4802 int num_command_line_args,
4803 struct CXUnsavedFile *unsaved_files,
4804 unsigned num_unsaved_files,
4805 CXTranslationUnit *out_TU,
4806 unsigned TU_options);
4807
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004808/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004809 * \brief Index the given translation unit via callbacks implemented through
4810 * \see IndexerCallbacks.
4811 *
4812 * The order of callback invocations is not guaranteed to be the same as
4813 * when indexing a source file. The high level order will be:
4814 *
4815 * -Preprocessor callbacks invocations
4816 * -Declaration/reference callbacks invocations
4817 * -Diagnostic callback invocations
4818 *
4819 * The parameters are the same as \see clang_indexSourceFile.
4820 *
4821 * \returns If there is a failure from which the there is no recovery, returns
4822 * non-zero, otherwise returns 0.
4823 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004824CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004825 CXClientData client_data,
4826 IndexerCallbacks *index_callbacks,
4827 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004828 unsigned index_options,
4829 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004830
4831/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004832 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
4833 * the given CXIdxLoc.
4834 *
4835 * If the location refers into a macro expansion, retrieves the
4836 * location of the macro expansion and if it refers into a macro argument
4837 * retrieves the location of the argument.
4838 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004839CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004840 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004841 CXFile *file,
4842 unsigned *line,
4843 unsigned *column,
4844 unsigned *offset);
4845
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004846/**
4847 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
4848 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004849CINDEX_LINKAGE
4850CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
4851
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004852/**
4853 * @}
4854 */
4855
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004856/**
4857 * @}
4858 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004859
Ted Kremenekd2fa5662009-08-26 22:36:44 +00004860#ifdef __cplusplus
4861}
4862#endif
4863#endif
4864