blob: 787c44a2e4fa25ab5ad94c665990638b3f8bdefb [file] [log] [blame]
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
Steve Naroff88145032009-10-27 14:35:18 +000019#include <sys/stat.h>
Chandler Carruth3d315602009-12-17 09:27:29 +000020#include <time.h>
Douglas Gregor0a812cf2010-02-18 23:07:20 +000021#include <stdio.h>
Steve Naroff88145032009-10-27 14:35:18 +000022
Arnaud A. de Grandmaisondb2a6852012-06-28 22:01:06 +000023#include "clang-c/Platform.h"
24#include "clang-c/CXString.h"
25
Argyrios Kyrtzidis4d9eff52012-11-06 21:21:49 +000026/**
27 * \brief The version constants for the libclang API.
28 * CINDEX_VERSION_MINOR should increase when there are API additions.
29 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
30 *
31 * The policy about the libclang API was always to keep it source and ABI
32 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
33 */
Argyrios Kyrtzidisca9805a2012-10-29 23:24:44 +000034#define CINDEX_VERSION_MAJOR 0
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +000035#define CINDEX_VERSION_MINOR 15
Argyrios Kyrtzidisca9805a2012-10-29 23:24:44 +000036
37#define CINDEX_VERSION_ENCODE(major, minor) ( \
38 ((major) * 10000) \
39 + ((minor) * 1))
40
41#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
42 CINDEX_VERSION_MAJOR, \
43 CINDEX_VERSION_MINOR )
44
45#define CINDEX_VERSION_STRINGIZE_(major, minor) \
46 #major"."#minor
47#define CINDEX_VERSION_STRINGIZE(major, minor) \
48 CINDEX_VERSION_STRINGIZE_(major, minor)
49
50#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
51 CINDEX_VERSION_MAJOR, \
52 CINDEX_VERSION_MINOR)
53
Ted Kremenekd2fa5662009-08-26 22:36:44 +000054#ifdef __cplusplus
55extern "C" {
56#endif
57
Douglas Gregor87fb9402011-02-23 17:45:25 +000058/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000059 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000060 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000061 * facilities for parsing source code into an abstract syntax tree (AST),
62 * loading already-parsed ASTs, traversing the AST, associating
63 * physical source locations with elements within the AST, and other
64 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000065 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000066 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000067 * representation stored in Clang's C++ AST, nor should it: the intent is to
68 * maintain an API that is relatively stable from one release to the next,
69 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000070 *
71 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000072 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000073 *
74 * @{
75 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000076
Douglas Gregor7f173762010-01-20 22:28:27 +000077/**
78 * \brief An "index" that consists of a set of translation units that would
79 * typically be linked together into an executable or library.
80 */
81typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000082
Douglas Gregor7f173762010-01-20 22:28:27 +000083/**
84 * \brief A single translation unit, which resides in an index.
85 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000086typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000087
Douglas Gregor7f173762010-01-20 22:28:27 +000088/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000089 * \brief Opaque pointer representing client data that will be passed through
90 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000091 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000092typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000093
Douglas Gregor735df882009-12-02 09:21:34 +000094/**
95 * \brief Provides the contents of a file that has not yet been saved to disk.
96 *
97 * Each CXUnsavedFile instance provides the name of a file on the
98 * system along with the current contents of that file that have not
99 * yet been saved to disk.
100 */
101struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000102 /**
103 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +0000104 *
105 * This file must already exist in the file system.
106 */
107 const char *Filename;
108
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000109 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000110 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +0000111 */
112 const char *Contents;
113
114 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000115 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +0000116 */
117 unsigned long Length;
118};
119
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000120/**
121 * \brief Describes the availability of a particular entity, which indicates
122 * whether the use of this entity will result in a warning or error due to
123 * it being deprecated or unavailable.
124 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000125enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000126 /**
127 * \brief The entity is available.
128 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000129 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000130 /**
131 * \brief The entity is available, but has been deprecated (and its use is
132 * not recommended).
133 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000134 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000135 /**
136 * \brief The entity is not available; any use of it will be an error.
137 */
Erik Verbruggend1205962011-10-06 07:27:49 +0000138 CXAvailability_NotAvailable,
139 /**
140 * \brief The entity is available, but not accessible; any use of it will be
141 * an error.
142 */
143 CXAvailability_NotAccessible
Douglas Gregor58ddb602010-08-23 23:00:57 +0000144};
Douglas Gregorcc889662012-05-08 00:14:45 +0000145
146/**
147 * \brief Describes a version number of the form major.minor.subminor.
148 */
149typedef struct CXVersion {
150 /**
151 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
152 * value indicates that there is no version number at all.
153 */
154 int Major;
155 /**
156 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
157 * will be negative if no minor version number was provided, e.g., for
158 * version '10'.
159 */
160 int Minor;
161 /**
162 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
163 * will be negative if no minor or subminor version number was provided,
164 * e.g., in version '10' or '10.7'.
165 */
166 int Subminor;
167} CXVersion;
Douglas Gregor58ddb602010-08-23 23:00:57 +0000168
Douglas Gregor7f173762010-01-20 22:28:27 +0000169/**
James Dennett7eee0182012-06-15 05:41:51 +0000170 * \brief Provides a shared context for creating translation units.
171 *
172 * It provides two options:
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000173 *
174 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
175 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000176 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000177 * header that was used by the translation unit. If zero, all declarations
178 * will be enumerated.
179 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000180 * Here is an example:
181 *
James Dennett7eee0182012-06-15 05:41:51 +0000182 * \code
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000183 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
184 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000185 *
186 * // IndexTest.pch was produced with the following command:
187 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
188 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
189 *
190 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000191 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000192 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000193 * clang_disposeTranslationUnit(TU);
194 *
195 * // This will load all the symbols from 'IndexTest.c', excluding symbols
196 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000197 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
198 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
199 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000200 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
201 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000202 * clang_disposeTranslationUnit(TU);
James Dennett7eee0182012-06-15 05:41:51 +0000203 * \endcode
Steve Naroffb4ece632009-10-20 16:36:34 +0000204 *
205 * This process of creating the 'pch', loading it separately, and using it (via
206 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
207 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000208 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000209CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
210 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000211
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000212/**
213 * \brief Destroy the given index.
214 *
215 * The index must not be destroyed until all of the translation units created
216 * within that index have been destroyed.
217 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000218CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000219
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +0000220typedef enum {
221 /**
222 * \brief Used to indicate that no special CXIndex options are needed.
223 */
224 CXGlobalOpt_None = 0x0,
225
226 /**
227 * \brief Used to indicate that threads that libclang creates for indexing
228 * purposes should use background priority.
James Dennett7eee0182012-06-15 05:41:51 +0000229 *
230 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
231 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +0000232 */
233 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
234
235 /**
236 * \brief Used to indicate that threads that libclang creates for editing
237 * purposes should use background priority.
James Dennett7eee0182012-06-15 05:41:51 +0000238 *
239 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
240 * #clang_annotateTokens
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +0000241 */
242 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
243
244 /**
245 * \brief Used to indicate that all threads that libclang creates should use
246 * background priority.
247 */
248 CXGlobalOpt_ThreadBackgroundPriorityForAll =
249 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
250 CXGlobalOpt_ThreadBackgroundPriorityForEditing
251
252} CXGlobalOptFlags;
253
254/**
James Dennett7eee0182012-06-15 05:41:51 +0000255 * \brief Sets general options associated with a CXIndex.
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +0000256 *
257 * For example:
258 * \code
259 * CXIndex idx = ...;
260 * clang_CXIndex_setGlobalOptions(idx,
261 * clang_CXIndex_getGlobalOptions(idx) |
262 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
263 * \endcode
264 *
265 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
266 */
267CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
268
269/**
270 * \brief Gets the general options associated with a CXIndex.
271 *
272 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
273 * are associated with the given CXIndex object.
274 */
275CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
276
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000277/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000278 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000279 *
280 * @{
281 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000282
Douglas Gregorf5525442010-01-20 22:45:41 +0000283/**
284 * \brief A particular source file that is part of a translation unit.
285 */
286typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000287
Douglas Gregorf5525442010-01-20 22:45:41 +0000288
289/**
290 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000291 */
Ted Kremenek74844072010-02-17 00:41:20 +0000292CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000293
Douglas Gregorf5525442010-01-20 22:45:41 +0000294/**
295 * \brief Retrieve the last modification time of the given file.
296 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000297CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000298
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000299/**
Argyrios Kyrtzidisdb84e7a2013-01-26 04:52:52 +0000300 * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
301 * across an indexing session.
302 */
303typedef struct {
304 unsigned long long data[3];
305} CXFileUniqueID;
306
307/**
308 * \brief Retrieve the unique ID for the given \c file.
309 *
310 * \param file the file to get the ID for.
311 * \param outID stores the returned CXFileUniqueID.
312 * \returns If there was a failure getting the unique ID, returns non-zero,
313 * otherwise returns 0.
314*/
315CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
316
317/**
Douglas Gregordd3e5542011-05-04 00:14:37 +0000318 * \brief Determine whether the given header is guarded against
319 * multiple inclusions, either with the conventional
James Dennett7eee0182012-06-15 05:41:51 +0000320 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
Douglas Gregordd3e5542011-05-04 00:14:37 +0000321 */
322CINDEX_LINKAGE unsigned
323clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
324
325/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000326 * \brief Retrieve a file handle within the given translation unit.
327 *
328 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000329 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000330 * \param file_name the name of the file.
331 *
332 * \returns the file handle for the named file in the translation unit \p tu,
333 * or a NULL file handle if the file was not a part of this translation unit.
334 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000335CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000336 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000337
Douglas Gregorb9790342010-01-22 21:44:22 +0000338/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000339 * @}
340 */
341
342/**
343 * \defgroup CINDEX_LOCATIONS Physical source locations
344 *
345 * Clang represents physical source locations in its abstract syntax tree in
346 * great detail, with file, line, and column information for the majority of
347 * the tokens parsed in the source code. These data types and functions are
348 * used to represent source location information, either for a particular
349 * point in the program or for a range of points in the program, and extract
350 * specific location information from those data types.
351 *
352 * @{
353 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000354
Douglas Gregorf5525442010-01-20 22:45:41 +0000355/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000356 * \brief Identifies a specific source location within a translation
357 * unit.
358 *
Chandler Carruth20174222011-08-31 16:53:37 +0000359 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregora9b06d42010-11-09 06:24:54 +0000360 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000361 */
362typedef struct {
Argyrios Kyrtzidise2748282013-01-11 22:29:47 +0000363 const void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000364 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000365} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000366
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000367/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000368 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000369 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000370 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
371 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000372 */
373typedef struct {
Argyrios Kyrtzidise2748282013-01-11 22:29:47 +0000374 const void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000375 unsigned begin_int_data;
376 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000377} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000378
Douglas Gregor1db19de2010-01-19 21:36:55 +0000379/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000380 * \brief Retrieve a NULL (invalid) source location.
381 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +0000382CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000383
Douglas Gregorb9790342010-01-22 21:44:22 +0000384/**
James Dennett7eee0182012-06-15 05:41:51 +0000385 * \brief Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000386 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000387 * code.
388 *
389 * \returns non-zero if the source locations refer to the same location, zero
390 * if they refer to different locations.
391 */
392CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
393 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000394
Douglas Gregorb9790342010-01-22 21:44:22 +0000395/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000396 * \brief Retrieves the source location associated with a given file/line/column
397 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000398 */
399CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
400 CXFile file,
401 unsigned line,
402 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000403/**
404 * \brief Retrieves the source location associated with a given character offset
405 * in a particular translation unit.
406 */
407CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
408 CXFile file,
409 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000410
Douglas Gregorb9790342010-01-22 21:44:22 +0000411/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000412 * \brief Retrieve a NULL (invalid) source range.
413 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +0000414CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
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/**
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000432 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000433 */
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 *
James Dennett7eee0182012-06-15 05:41:51 +0000470 * \code
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000471 * #123 "dummy.c" 1
472 *
473 * static int func(void)
474 * {
475 * return 0;
476 * }
James Dennett7eee0182012-06-15 05:41:51 +0000477 * \endcode
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000478 *
479 * the location information returned by this function would be
480 *
481 * File: dummy.c Line: 124 Column: 12
482 *
483 * whereas clang_getExpansionLocation would have returned
484 *
485 * File: somefile.c Line: 3 Column: 12
486 *
487 * \param location the location within a source file that will be decomposed
488 * into its parts.
489 *
490 * \param filename [out] if non-NULL, will be set to the filename of the
491 * source location. Note that filenames returned will be for "virtual" files,
492 * which don't necessarily exist on the machine running clang - e.g. when
493 * parsing preprocessed output obtained from a different environment. If
494 * a non-NULL value is passed in, remember to dispose of the returned value
495 * using \c clang_disposeString() once you've finished with it. For an invalid
496 * source location, an empty string is returned.
497 *
498 * \param line [out] if non-NULL, will be set to the line number of the
499 * source location. For an invalid source location, zero is returned.
500 *
501 * \param column [out] if non-NULL, will be set to the column number of the
502 * source location. For an invalid source location, zero is returned.
503 */
504CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
505 CXString *filename,
506 unsigned *line,
507 unsigned *column);
508
509/**
Chandler Carruth20174222011-08-31 16:53:37 +0000510 * \brief Legacy API to retrieve the file, line, column, and offset represented
511 * by the given source location.
512 *
513 * This interface has been replaced by the newer interface
James Dennett7eee0182012-06-15 05:41:51 +0000514 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth20174222011-08-31 16:53:37 +0000515 * details.
516 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000517CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
518 CXFile *file,
519 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000520 unsigned *column,
521 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000522
523/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000524 * \brief Retrieve the file, line, column, and offset represented by
525 * the given source location.
526 *
527 * If the location refers into a macro instantiation, return where the
528 * location was originally spelled in the source file.
529 *
530 * \param location the location within a source file that will be decomposed
531 * into its parts.
532 *
533 * \param file [out] if non-NULL, will be set to the file to which the given
534 * source location points.
535 *
536 * \param line [out] if non-NULL, will be set to the line to which the given
537 * source location points.
538 *
539 * \param column [out] if non-NULL, will be set to the column to which the given
540 * source location points.
541 *
542 * \param offset [out] if non-NULL, will be set to the offset into the
543 * buffer to which the given source location points.
544 */
545CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
546 CXFile *file,
547 unsigned *line,
548 unsigned *column,
549 unsigned *offset);
550
551/**
Argyrios Kyrtzidis2d5c1332013-01-04 18:30:13 +0000552 * \brief Retrieve the file, line, column, and offset represented by
553 * the given source location.
554 *
555 * If the location refers into a macro expansion, return where the macro was
556 * expanded or where the macro argument was written, if the location points at
557 * a macro argument.
558 *
559 * \param location the location within a source file that will be decomposed
560 * into its parts.
561 *
562 * \param file [out] if non-NULL, will be set to the file to which the given
563 * source location points.
564 *
565 * \param line [out] if non-NULL, will be set to the line to which the given
566 * source location points.
567 *
568 * \param column [out] if non-NULL, will be set to the column to which the given
569 * source location points.
570 *
571 * \param offset [out] if non-NULL, will be set to the offset into the
572 * buffer to which the given source location points.
573 */
574CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
575 CXFile *file,
576 unsigned *line,
577 unsigned *column,
578 unsigned *offset);
579
580/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000581 * \brief Retrieve a source location representing the first character within a
582 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000583 */
584CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
585
586/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000587 * \brief Retrieve a source location representing the last character within a
588 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000589 */
590CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
591
Douglas Gregorf5525442010-01-20 22:45:41 +0000592/**
593 * @}
594 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000595
596/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000597 * \defgroup CINDEX_DIAG Diagnostic reporting
598 *
599 * @{
600 */
601
602/**
603 * \brief Describes the severity of a particular diagnostic.
604 */
605enum CXDiagnosticSeverity {
606 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000607 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000608 * option.
609 */
610 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000611
Douglas Gregor5352ac02010-01-28 00:27:43 +0000612 /**
613 * \brief This diagnostic is a note that should be attached to the
614 * previous (non-note) diagnostic.
615 */
616 CXDiagnostic_Note = 1,
617
618 /**
619 * \brief This diagnostic indicates suspicious code that may not be
620 * wrong.
621 */
622 CXDiagnostic_Warning = 2,
623
624 /**
625 * \brief This diagnostic indicates that the code is ill-formed.
626 */
627 CXDiagnostic_Error = 3,
628
629 /**
630 * \brief This diagnostic indicates that the code is ill-formed such
631 * that future parser recovery is unlikely to produce useful
632 * results.
633 */
634 CXDiagnostic_Fatal = 4
635};
636
637/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000638 * \brief A single diagnostic, containing the diagnostic's severity,
639 * location, text, source ranges, and fix-it hints.
640 */
641typedef void *CXDiagnostic;
642
643/**
Ted Kremenek15322172011-11-10 08:43:12 +0000644 * \brief A group of CXDiagnostics.
645 */
646typedef void *CXDiagnosticSet;
647
648/**
649 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
650 */
651CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
652
653/**
654 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
655 *
James Dennett7eee0182012-06-15 05:41:51 +0000656 * \param Diags the CXDiagnosticSet to query.
Ted Kremenek15322172011-11-10 08:43:12 +0000657 * \param Index the zero-based diagnostic number to retrieve.
658 *
659 * \returns the requested diagnostic. This diagnostic must be freed
660 * via a call to \c clang_disposeDiagnostic().
661 */
662CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
663 unsigned Index);
664
665
666/**
667 * \brief Describes the kind of error that occurred (if any) in a call to
668 * \c clang_loadDiagnostics.
669 */
670enum CXLoadDiag_Error {
671 /**
672 * \brief Indicates that no error occurred.
673 */
674 CXLoadDiag_None = 0,
675
676 /**
677 * \brief Indicates that an unknown error occurred while attempting to
678 * deserialize diagnostics.
679 */
680 CXLoadDiag_Unknown = 1,
681
682 /**
683 * \brief Indicates that the file containing the serialized diagnostics
684 * could not be opened.
685 */
686 CXLoadDiag_CannotLoad = 2,
687
688 /**
689 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett7eee0182012-06-15 05:41:51 +0000690 * corrupt.
Ted Kremenek15322172011-11-10 08:43:12 +0000691 */
692 CXLoadDiag_InvalidFile = 3
693};
694
695/**
696 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett7eee0182012-06-15 05:41:51 +0000697 * file.
Ted Kremenek15322172011-11-10 08:43:12 +0000698 *
James Dennett7eee0182012-06-15 05:41:51 +0000699 * \param file The name of the file to deserialize.
700 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenek15322172011-11-10 08:43:12 +0000701 * deserializing the diagnostics.
James Dennett7eee0182012-06-15 05:41:51 +0000702 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenek15322172011-11-10 08:43:12 +0000703 * if the file was not successfully loaded.
704 *
705 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett7eee0182012-06-15 05:41:51 +0000706 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenek15322172011-11-10 08:43:12 +0000707 */
708CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
709 enum CXLoadDiag_Error *error,
710 CXString *errorString);
711
712/**
713 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
714 */
715CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
716
717/**
James Dennett7eee0182012-06-15 05:41:51 +0000718 * \brief Retrieve the child diagnostics of a CXDiagnostic.
719 *
720 * This CXDiagnosticSet does not need to be released by
721 * clang_diposeDiagnosticSet.
Ted Kremenek15322172011-11-10 08:43:12 +0000722 */
723CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
724
725/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000726 * \brief Determine the number of diagnostics produced for the given
727 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000728 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000729CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
730
731/**
732 * \brief Retrieve a diagnostic associated with the given translation unit.
733 *
734 * \param Unit the translation unit to query.
735 * \param Index the zero-based diagnostic number to retrieve.
736 *
737 * \returns the requested diagnostic. This diagnostic must be freed
738 * via a call to \c clang_disposeDiagnostic().
739 */
740CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
741 unsigned Index);
742
743/**
Ted Kremenek0373fcc2011-12-09 22:28:32 +0000744 * \brief Retrieve the complete set of diagnostics associated with a
745 * translation unit.
746 *
747 * \param Unit the translation unit to query.
748 */
749CINDEX_LINKAGE CXDiagnosticSet
750 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
751
752/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000753 * \brief Destroy a diagnostic.
754 */
755CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000756
757/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000758 * \brief Options to control the display of diagnostics.
759 *
760 * The values in this enum are meant to be combined to customize the
761 * behavior of \c clang_displayDiagnostic().
762 */
763enum CXDiagnosticDisplayOptions {
764 /**
765 * \brief Display the source-location information where the
766 * diagnostic was located.
767 *
768 * When set, diagnostics will be prefixed by the file, line, and
769 * (optionally) column to which the diagnostic refers. For example,
770 *
771 * \code
772 * test.c:28: warning: extra tokens at end of #endif directive
773 * \endcode
774 *
775 * This option corresponds to the clang flag \c -fshow-source-location.
776 */
777 CXDiagnostic_DisplaySourceLocation = 0x01,
778
779 /**
780 * \brief If displaying the source-location information of the
781 * diagnostic, also include the column number.
782 *
783 * This option corresponds to the clang flag \c -fshow-column.
784 */
785 CXDiagnostic_DisplayColumn = 0x02,
786
787 /**
788 * \brief If displaying the source-location information of the
789 * diagnostic, also include information about source ranges in a
790 * machine-parsable format.
791 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000792 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000793 * \c -fdiagnostics-print-source-range-info.
794 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000795 CXDiagnostic_DisplaySourceRanges = 0x04,
796
797 /**
798 * \brief Display the option name associated with this diagnostic, if any.
799 *
800 * The option name displayed (e.g., -Wconversion) will be placed in brackets
801 * after the diagnostic text. This option corresponds to the clang flag
802 * \c -fdiagnostics-show-option.
803 */
804 CXDiagnostic_DisplayOption = 0x08,
805
806 /**
807 * \brief Display the category number associated with this diagnostic, if any.
808 *
809 * The category number is displayed within brackets after the diagnostic text.
810 * This option corresponds to the clang flag
811 * \c -fdiagnostics-show-category=id.
812 */
813 CXDiagnostic_DisplayCategoryId = 0x10,
814
815 /**
816 * \brief Display the category name associated with this diagnostic, if any.
817 *
818 * The category name is displayed within brackets after the diagnostic text.
819 * This option corresponds to the clang flag
820 * \c -fdiagnostics-show-category=name.
821 */
822 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000823};
824
825/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000826 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000827 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000828 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000829 * the diagnostic according to the various options given. The
830 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000831 * options that most closely mimics the behavior of the clang compiler.
832 *
833 * \param Diagnostic The diagnostic to print.
834 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000835 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000836 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000837 *
838 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000839 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000840CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
841 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000842
843/**
844 * \brief Retrieve the set of display options most similar to the
845 * default behavior of the clang compiler.
846 *
847 * \returns A set of display options suitable for use with \c
848 * clang_displayDiagnostic().
849 */
850CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
851
852/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000853 * \brief Determine the severity of the given diagnostic.
854 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000855CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000856clang_getDiagnosticSeverity(CXDiagnostic);
857
858/**
859 * \brief Retrieve the source location of the given diagnostic.
860 *
861 * This location is where Clang would print the caret ('^') when
862 * displaying the diagnostic on the command line.
863 */
864CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
865
866/**
867 * \brief Retrieve the text of the given diagnostic.
868 */
869CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000870
871/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000872 * \brief Retrieve the name of the command-line option that enabled this
873 * diagnostic.
874 *
875 * \param Diag The diagnostic to be queried.
876 *
877 * \param Disable If non-NULL, will be set to the option that disables this
878 * diagnostic (if any).
879 *
880 * \returns A string that contains the command-line option used to enable this
881 * warning, such as "-Wconversion" or "-pedantic".
882 */
883CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
884 CXString *Disable);
885
886/**
887 * \brief Retrieve the category number for this diagnostic.
888 *
889 * Diagnostics can be categorized into groups along with other, related
890 * diagnostics (e.g., diagnostics under the same warning flag). This routine
891 * retrieves the category number for the given diagnostic.
892 *
893 * \returns The number of the category that contains this diagnostic, or zero
894 * if this diagnostic is uncategorized.
895 */
896CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
897
898/**
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000899 * \brief Retrieve the name of a particular diagnostic category. This
900 * is now deprecated. Use clang_getDiagnosticCategoryText()
901 * instead.
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000902 *
903 * \param Category A diagnostic category number, as returned by
904 * \c clang_getDiagnosticCategory().
905 *
906 * \returns The name of the given diagnostic category.
907 */
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000908CINDEX_DEPRECATED CINDEX_LINKAGE
909CXString clang_getDiagnosticCategoryName(unsigned Category);
910
911/**
912 * \brief Retrieve the diagnostic category text for a given diagnostic.
913 *
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000914 * \returns The text of the given diagnostic category.
915 */
916CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000917
918/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000919 * \brief Determine the number of source ranges associated with the given
920 * diagnostic.
921 */
922CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000923
Douglas Gregor5352ac02010-01-28 00:27:43 +0000924/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000925 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000926 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000927 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000928 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000929 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000930 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000931 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000932 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000933 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000934 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000935 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000936 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000937CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000938 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000939
940/**
941 * \brief Determine the number of fix-it hints associated with the
942 * given diagnostic.
943 */
944CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
945
946/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000947 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000948 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000949 * Fix-its are described in terms of a source range whose contents
950 * should be replaced by a string. This approach generalizes over
951 * three kinds of operations: removal of source code (the range covers
952 * the code to be removed and the replacement string is empty),
953 * replacement of source code (the range covers the code to be
954 * replaced and the replacement string provides the new code), and
955 * insertion (both the start and end of the range point at the
956 * insertion location, and the replacement string provides the text to
957 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000958 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000959 * \param Diagnostic The diagnostic whose fix-its are being queried.
960 *
961 * \param FixIt The zero-based index of the fix-it.
962 *
963 * \param ReplacementRange The source range whose contents will be
964 * replaced with the returned replacement string. Note that source
965 * ranges are half-open ranges [a, b), so the source code should be
966 * replaced from a and up to (but not including) b.
967 *
968 * \returns A string containing text that should be replace the source
969 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000970 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000971CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000972 unsigned FixIt,
973 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000974
975/**
976 * @}
977 */
978
979/**
980 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
981 *
982 * The routines in this group provide the ability to create and destroy
983 * translation units from files, either by parsing the contents of the files or
984 * by reading in a serialized representation of a translation unit.
985 *
986 * @{
987 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000988
Douglas Gregor5352ac02010-01-28 00:27:43 +0000989/**
990 * \brief Get the original translation unit source file name.
991 */
992CINDEX_LINKAGE CXString
993clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
994
995/**
996 * \brief Return the CXTranslationUnit for a given source file and the provided
997 * command line arguments one would pass to the compiler.
998 *
999 * Note: The 'source_filename' argument is optional. If the caller provides a
1000 * NULL pointer, the name of the source file is expected to reside in the
1001 * specified command line arguments.
1002 *
1003 * Note: When encountered in 'clang_command_line_args', the following options
1004 * are ignored:
1005 *
1006 * '-c'
1007 * '-emit-ast'
1008 * '-fsyntax-only'
James Dennett7eee0182012-06-15 05:41:51 +00001009 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor5352ac02010-01-28 00:27:43 +00001010 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001011 * \param CIdx The index object with which the translation unit will be
1012 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001013 *
James Dennett7eee0182012-06-15 05:41:51 +00001014 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001015 * source file is included in \p clang_command_line_args.
1016 *
1017 * \param num_clang_command_line_args The number of command-line arguments in
1018 * \p clang_command_line_args.
1019 *
1020 * \param clang_command_line_args The command-line arguments that would be
1021 * passed to the \c clang executable if it were being invoked out-of-process.
1022 * These command-line options will be parsed and will affect how the translation
1023 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett7eee0182012-06-15 05:41:51 +00001024 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001025 *
1026 * \param num_unsaved_files the number of unsaved file entries in \p
1027 * unsaved_files.
1028 *
1029 * \param unsaved_files the files that have not yet been saved to disk
1030 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +00001031 * those files. The contents and name of these files (as specified by
1032 * CXUnsavedFile) are copied when necessary, so the client only needs to
1033 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +00001034 */
1035CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1036 CXIndex CIdx,
1037 const char *source_filename,
1038 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001039 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +00001040 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +00001041 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001042
Douglas Gregor5352ac02010-01-28 00:27:43 +00001043/**
1044 * \brief Create a translation unit from an AST file (-emit-ast).
1045 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001046CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +00001047 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +00001048
Douglas Gregor44c181a2010-07-23 00:33:23 +00001049/**
1050 * \brief Flags that control the creation of translation units.
1051 *
1052 * The enumerators in this enumeration type are meant to be bitwise
1053 * ORed together to specify which options should be used when
1054 * constructing the translation unit.
1055 */
Douglas Gregor5a430212010-07-21 18:52:53 +00001056enum CXTranslationUnit_Flags {
1057 /**
1058 * \brief Used to indicate that no special translation-unit options are
1059 * needed.
1060 */
1061 CXTranslationUnit_None = 0x0,
1062
1063 /**
1064 * \brief Used to indicate that the parser should construct a "detailed"
1065 * preprocessing record, including all macro definitions and instantiations.
1066 *
1067 * Constructing a detailed preprocessing record requires more memory
1068 * and time to parse, since the information contained in the record
1069 * is usually not retained. However, it can be useful for
1070 * applications that require more detailed information about the
1071 * behavior of the preprocessor.
1072 */
Douglas Gregor44c181a2010-07-23 00:33:23 +00001073 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1074
1075 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001076 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001077 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001078 * When a translation unit is considered "incomplete", semantic
1079 * analysis that is typically performed at the end of the
1080 * translation unit will be suppressed. For example, this suppresses
1081 * the completion of tentative declarations in C and of
1082 * instantiation of implicitly-instantiation function templates in
1083 * C++. This option is typically used when parsing a header with the
1084 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001085 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001086 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +00001087
1088 /**
1089 * \brief Used to indicate that the translation unit should be built with an
1090 * implicit precompiled header for the preamble.
1091 *
1092 * An implicit precompiled header is used as an optimization when a
1093 * particular translation unit is likely to be reparsed many times
1094 * when the sources aren't changing that often. In this case, an
1095 * implicit precompiled header will be built containing all of the
1096 * initial includes at the top of the main file (what we refer to as
1097 * the "preamble" of the file). In subsequent parses, if the
1098 * preamble or the files in it have not changed, \c
1099 * clang_reparseTranslationUnit() will re-use the implicit
1100 * precompiled header to improve parsing performance.
1101 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001102 CXTranslationUnit_PrecompiledPreamble = 0x04,
1103
1104 /**
1105 * \brief Used to indicate that the translation unit should cache some
1106 * code-completion results with each reparse of the source file.
1107 *
1108 * Caching of code-completion results is a performance optimization that
1109 * introduces some overhead to reparsing but improves the performance of
1110 * code-completion operations.
1111 */
Douglas Gregor99ba2022010-10-27 17:24:53 +00001112 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001113
Douglas Gregor99ba2022010-10-27 17:24:53 +00001114 /**
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001115 * \brief Used to indicate that the translation unit will be serialized with
1116 * \c clang_saveTranslationUnit.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001117 *
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001118 * This option is typically used when parsing a header with the intent of
1119 * producing a precompiled header.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001120 */
Argyrios Kyrtzidis900ab952012-10-11 16:05:00 +00001121 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregor99ba2022010-10-27 17:24:53 +00001122
1123 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001124 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001125 *
1126 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001127 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001128 */
Erik Verbruggen6a91d382012-04-12 10:11:59 +00001129 CXTranslationUnit_CXXChainedPCH = 0x20,
1130
1131 /**
1132 * \brief Used to indicate that function/method bodies should be skipped while
1133 * parsing.
1134 *
1135 * This option can be used to search for declarations/definitions while
1136 * ignoring the usages.
1137 */
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001138 CXTranslationUnit_SkipFunctionBodies = 0x40,
1139
1140 /**
1141 * \brief Used to indicate that brief documentation comments should be
1142 * included into the set of code completions returned from this translation
1143 * unit.
1144 */
1145 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor5a430212010-07-21 18:52:53 +00001146};
1147
1148/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001149 * \brief Returns the set of flags that is suitable for parsing a translation
1150 * unit that is being edited.
1151 *
1152 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1153 * to indicate that the translation unit is likely to be reparsed many times,
1154 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1155 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1156 * set contains an unspecified set of optimizations (e.g., the precompiled
1157 * preamble) geared toward improving the performance of these routines. The
1158 * set of optimizations enabled may change from one version to the next.
1159 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001160CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001161
1162/**
Douglas Gregor5a430212010-07-21 18:52:53 +00001163 * \brief Parse the given source file and the translation unit corresponding
1164 * to that file.
1165 *
1166 * This routine is the main entry point for the Clang C API, providing the
1167 * ability to parse a source file into a translation unit that can then be
1168 * queried by other functions in the API. This routine accepts a set of
1169 * command-line arguments so that the compilation can be configured in the same
1170 * way that the compiler is configured on the command line.
1171 *
1172 * \param CIdx The index object with which the translation unit will be
1173 * associated.
1174 *
1175 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001176 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +00001177 *
1178 * \param command_line_args The command-line arguments that would be
1179 * passed to the \c clang executable if it were being invoked out-of-process.
1180 * These command-line options will be parsed and will affect how the translation
1181 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett7eee0182012-06-15 05:41:51 +00001182 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor5a430212010-07-21 18:52:53 +00001183 *
1184 * \param num_command_line_args The number of command-line arguments in
1185 * \p command_line_args.
1186 *
1187 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00001188 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +00001189 * those files. The contents and name of these files (as specified by
1190 * CXUnsavedFile) are copied when necessary, so the client only needs to
1191 * guarantee their validity until the call to this function returns.
1192 *
1193 * \param num_unsaved_files the number of unsaved file entries in \p
1194 * unsaved_files.
1195 *
1196 * \param options A bitmask of options that affects how the translation unit
1197 * is managed but not its compilation. This should be a bitwise OR of the
1198 * CXTranslationUnit_XXX flags.
1199 *
1200 * \returns A new translation unit describing the parsed code and containing
1201 * any diagnostics produced by the compiler. If there is a failure from which
1202 * the compiler cannot recover, returns NULL.
1203 */
1204CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1205 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001206 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +00001207 int num_command_line_args,
1208 struct CXUnsavedFile *unsaved_files,
1209 unsigned num_unsaved_files,
1210 unsigned options);
1211
Douglas Gregor5352ac02010-01-28 00:27:43 +00001212/**
Douglas Gregor19998442010-08-13 15:35:05 +00001213 * \brief Flags that control how translation units are saved.
1214 *
1215 * The enumerators in this enumeration type are meant to be bitwise
1216 * ORed together to specify which options should be used when
1217 * saving the translation unit.
1218 */
1219enum CXSaveTranslationUnit_Flags {
1220 /**
1221 * \brief Used to indicate that no special saving options are needed.
1222 */
1223 CXSaveTranslationUnit_None = 0x0
1224};
1225
1226/**
1227 * \brief Returns the set of flags that is suitable for saving a translation
1228 * unit.
1229 *
1230 * The set of flags returned provide options for
1231 * \c clang_saveTranslationUnit() by default. The returned flag
1232 * set contains an unspecified set of options that save translation units with
1233 * the most commonly-requested data.
1234 */
1235CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1236
1237/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001238 * \brief Describes the kind of error that occurred (if any) in a call to
1239 * \c clang_saveTranslationUnit().
1240 */
1241enum CXSaveError {
1242 /**
1243 * \brief Indicates that no error occurred while saving a translation unit.
1244 */
1245 CXSaveError_None = 0,
1246
1247 /**
1248 * \brief Indicates that an unknown error occurred while attempting to save
1249 * the file.
1250 *
1251 * This error typically indicates that file I/O failed when attempting to
1252 * write the file.
1253 */
1254 CXSaveError_Unknown = 1,
1255
1256 /**
1257 * \brief Indicates that errors during translation prevented this attempt
1258 * to save the translation unit.
1259 *
1260 * Errors that prevent the translation unit from being saved can be
1261 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1262 */
1263 CXSaveError_TranslationErrors = 2,
1264
1265 /**
1266 * \brief Indicates that the translation unit to be saved was somehow
1267 * invalid (e.g., NULL).
1268 */
1269 CXSaveError_InvalidTU = 3
1270};
1271
1272/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001273 * \brief Saves a translation unit into a serialized representation of
1274 * that translation unit on disk.
1275 *
1276 * Any translation unit that was parsed without error can be saved
1277 * into a file. The translation unit can then be deserialized into a
1278 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1279 * if it is an incomplete translation unit that corresponds to a
1280 * header, used as a precompiled header when parsing other translation
1281 * units.
1282 *
1283 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001284 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001285 * \param FileName The file to which the translation unit will be saved.
1286 *
Douglas Gregor19998442010-08-13 15:35:05 +00001287 * \param options A bitmask of options that affects how the translation unit
1288 * is saved. This should be a bitwise OR of the
1289 * CXSaveTranslationUnit_XXX flags.
1290 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001291 * \returns A value that will match one of the enumerators of the CXSaveError
1292 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1293 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001294 */
1295CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001296 const char *FileName,
1297 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001298
1299/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001300 * \brief Destroy the specified CXTranslationUnit object.
1301 */
1302CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001303
Douglas Gregor5352ac02010-01-28 00:27:43 +00001304/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001305 * \brief Flags that control the reparsing of translation units.
1306 *
1307 * The enumerators in this enumeration type are meant to be bitwise
1308 * ORed together to specify which options should be used when
1309 * reparsing the translation unit.
1310 */
1311enum CXReparse_Flags {
1312 /**
1313 * \brief Used to indicate that no special reparsing options are needed.
1314 */
1315 CXReparse_None = 0x0
1316};
1317
1318/**
1319 * \brief Returns the set of flags that is suitable for reparsing a translation
1320 * unit.
1321 *
1322 * The set of flags returned provide options for
1323 * \c clang_reparseTranslationUnit() by default. The returned flag
1324 * set contains an unspecified set of optimizations geared toward common uses
1325 * of reparsing. The set of optimizations enabled may change from one version
1326 * to the next.
1327 */
1328CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1329
1330/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001331 * \brief Reparse the source files that produced this translation unit.
1332 *
1333 * This routine can be used to re-parse the source files that originally
1334 * created the given translation unit, for example because those source files
1335 * have changed (either on disk or as passed via \p unsaved_files). The
1336 * source code will be reparsed with the same command-line options as it
1337 * was originally parsed.
1338 *
1339 * Reparsing a translation unit invalidates all cursors and source locations
1340 * that refer into that translation unit. This makes reparsing a translation
1341 * unit semantically equivalent to destroying the translation unit and then
1342 * creating a new translation unit with the same command-line arguments.
1343 * However, it may be more efficient to reparse a translation
1344 * unit using this routine.
1345 *
1346 * \param TU The translation unit whose contents will be re-parsed. The
1347 * translation unit must originally have been built with
1348 * \c clang_createTranslationUnitFromSourceFile().
1349 *
1350 * \param num_unsaved_files The number of unsaved file entries in \p
1351 * unsaved_files.
1352 *
1353 * \param unsaved_files The files that have not yet been saved to disk
1354 * but may be required for parsing, including the contents of
1355 * those files. The contents and name of these files (as specified by
1356 * CXUnsavedFile) are copied when necessary, so the client only needs to
1357 * guarantee their validity until the call to this function returns.
1358 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001359 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1360 * The function \c clang_defaultReparseOptions() produces a default set of
1361 * options recommended for most uses, based on the translation unit.
1362 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001363 * \returns 0 if the sources could be reparsed. A non-zero value will be
1364 * returned if reparsing was impossible, such that the translation unit is
1365 * invalid. In such cases, the only valid call for \p TU is
1366 * \c clang_disposeTranslationUnit(TU).
1367 */
1368CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1369 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001370 struct CXUnsavedFile *unsaved_files,
1371 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001372
1373/**
1374 * \brief Categorizes how memory is being used by a translation unit.
1375 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001376enum CXTUResourceUsageKind {
1377 CXTUResourceUsage_AST = 1,
1378 CXTUResourceUsage_Identifiers = 2,
1379 CXTUResourceUsage_Selectors = 3,
1380 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001381 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001382 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001383 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001384 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1385 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1386 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001387 CXTUResourceUsage_Preprocessor = 11,
1388 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001389 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001390 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001391 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1392 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001393 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001394
1395 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001396 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001397};
1398
1399/**
1400 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001401 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001402 */
1403CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001404const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001405
Ted Kremenekf7870022011-04-20 16:41:07 +00001406typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001407 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001408 enum CXTUResourceUsageKind kind;
1409 /* \brief Amount of resources used.
1410 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001411 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001412} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001413
1414/**
1415 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1416 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001417typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001418 /* \brief Private data member, used for queries. */
1419 void *data;
1420
1421 /* \brief The number of entries in the 'entries' array. */
1422 unsigned numEntries;
1423
1424 /* \brief An array of key-value pairs, representing the breakdown of memory
1425 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001426 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001427
Ted Kremenekf7870022011-04-20 16:41:07 +00001428} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001429
1430/**
1431 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001432 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001433 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001434CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001435
Ted Kremenekf7870022011-04-20 16:41:07 +00001436CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001437
Douglas Gregorabc563f2010-07-19 21:46:24 +00001438/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001439 * @}
1440 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001441
Douglas Gregor5352ac02010-01-28 00:27:43 +00001442/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001443 * \brief Describes the kind of entity that a cursor refers to.
1444 */
1445enum CXCursorKind {
1446 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001447 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001448 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001449 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001450 *
1451 * Unexposed declarations have the same operations as any other kind
1452 * of declaration; one can extract their location information,
1453 * spelling, find their definitions, etc. However, the specific kind
1454 * of the declaration is not reported.
1455 */
1456 CXCursor_UnexposedDecl = 1,
1457 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001458 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001459 /** \brief A C or C++ union. */
1460 CXCursor_UnionDecl = 3,
1461 /** \brief A C++ class. */
1462 CXCursor_ClassDecl = 4,
1463 /** \brief An enumeration. */
1464 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001465 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001466 * \brief A field (in C) or non-static data member (in C++) in a
1467 * struct, union, or C++ class.
1468 */
1469 CXCursor_FieldDecl = 6,
1470 /** \brief An enumerator constant. */
1471 CXCursor_EnumConstantDecl = 7,
1472 /** \brief A function. */
1473 CXCursor_FunctionDecl = 8,
1474 /** \brief A variable. */
1475 CXCursor_VarDecl = 9,
1476 /** \brief A function or method parameter. */
1477 CXCursor_ParmDecl = 10,
James Dennett17d26a62012-06-11 06:19:40 +00001478 /** \brief An Objective-C \@interface. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001479 CXCursor_ObjCInterfaceDecl = 11,
James Dennett17d26a62012-06-11 06:19:40 +00001480 /** \brief An Objective-C \@interface for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001481 CXCursor_ObjCCategoryDecl = 12,
James Dennett17d26a62012-06-11 06:19:40 +00001482 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001483 CXCursor_ObjCProtocolDecl = 13,
James Dennett17d26a62012-06-11 06:19:40 +00001484 /** \brief An Objective-C \@property declaration. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001485 CXCursor_ObjCPropertyDecl = 14,
1486 /** \brief An Objective-C instance variable. */
1487 CXCursor_ObjCIvarDecl = 15,
1488 /** \brief An Objective-C instance method. */
1489 CXCursor_ObjCInstanceMethodDecl = 16,
1490 /** \brief An Objective-C class method. */
1491 CXCursor_ObjCClassMethodDecl = 17,
James Dennett17d26a62012-06-11 06:19:40 +00001492 /** \brief An Objective-C \@implementation. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001493 CXCursor_ObjCImplementationDecl = 18,
James Dennett17d26a62012-06-11 06:19:40 +00001494 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001495 CXCursor_ObjCCategoryImplDecl = 19,
1496 /** \brief A typedef */
1497 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001498 /** \brief A C++ class method. */
1499 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001500 /** \brief A C++ namespace. */
1501 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001502 /** \brief A linkage specification, e.g. 'extern "C"'. */
1503 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001504 /** \brief A C++ constructor. */
1505 CXCursor_Constructor = 24,
1506 /** \brief A C++ destructor. */
1507 CXCursor_Destructor = 25,
1508 /** \brief A C++ conversion function. */
1509 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001510 /** \brief A C++ template type parameter. */
1511 CXCursor_TemplateTypeParameter = 27,
1512 /** \brief A C++ non-type template parameter. */
1513 CXCursor_NonTypeTemplateParameter = 28,
1514 /** \brief A C++ template template parameter. */
1515 CXCursor_TemplateTemplateParameter = 29,
1516 /** \brief A C++ function template. */
1517 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001518 /** \brief A C++ class template. */
1519 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001520 /** \brief A C++ class template partial specialization. */
1521 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001522 /** \brief A C++ namespace alias declaration. */
1523 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001524 /** \brief A C++ using directive. */
1525 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001526 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001527 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001528 /** \brief A C++ alias declaration */
1529 CXCursor_TypeAliasDecl = 36,
James Dennett7eee0182012-06-15 05:41:51 +00001530 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor352697a2011-06-03 23:08:58 +00001531 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett7eee0182012-06-15 05:41:51 +00001532 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor352697a2011-06-03 23:08:58 +00001533 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001534 /** \brief An access specifier. */
1535 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor42b29842011-10-05 19:00:14 +00001536
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001537 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001538 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001539
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001540 /* References */
1541 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001542 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001543 CXCursor_ObjCProtocolRef = 41,
1544 CXCursor_ObjCClassRef = 42,
1545 /**
1546 * \brief A reference to a type declaration.
1547 *
1548 * A type reference occurs anywhere where a type is named but not
1549 * declared. For example, given:
1550 *
1551 * \code
1552 * typedef unsigned size_type;
1553 * size_type size;
1554 * \endcode
1555 *
1556 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1557 * while the type of the variable "size" is referenced. The cursor
1558 * referenced by the type of size is the typedef for size_type.
1559 */
1560 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001561 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001562 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001563 * \brief A reference to a class template, function template, template
1564 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001565 */
1566 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001567 /**
1568 * \brief A reference to a namespace or namespace alias.
1569 */
1570 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001571 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001572 * \brief A reference to a member of a struct, union, or class that occurs in
1573 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001574 */
1575 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001576 /**
1577 * \brief A reference to a labeled statement.
1578 *
1579 * This cursor kind is used to describe the jump to "start_over" in the
1580 * goto statement in the following example:
1581 *
1582 * \code
1583 * start_over:
1584 * ++counter;
1585 *
1586 * goto start_over;
1587 * \endcode
1588 *
1589 * A label reference cursor refers to a label statement.
1590 */
1591 CXCursor_LabelRef = 48,
1592
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001593 /**
1594 * \brief A reference to a set of overloaded functions or function templates
1595 * that has not yet been resolved to a specific function or function template.
1596 *
1597 * An overloaded declaration reference cursor occurs in C++ templates where
1598 * a dependent name refers to a function. For example:
1599 *
1600 * \code
1601 * template<typename T> void swap(T&, T&);
1602 *
1603 * struct X { ... };
1604 * void swap(X&, X&);
1605 *
1606 * template<typename T>
1607 * void reverse(T* first, T* last) {
1608 * while (first < last - 1) {
1609 * swap(*first, *--last);
1610 * ++first;
1611 * }
1612 * }
1613 *
1614 * struct Y { };
1615 * void swap(Y&, Y&);
1616 * \endcode
1617 *
1618 * Here, the identifier "swap" is associated with an overloaded declaration
1619 * reference. In the template definition, "swap" refers to either of the two
1620 * "swap" functions declared above, so both results will be available. At
1621 * instantiation time, "swap" may also refer to other functions found via
1622 * argument-dependent lookup (e.g., the "swap" function at the end of the
1623 * example).
1624 *
1625 * The functions \c clang_getNumOverloadedDecls() and
1626 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1627 * referenced by this cursor.
1628 */
1629 CXCursor_OverloadedDeclRef = 49,
1630
Douglas Gregor011d8b92012-02-15 00:54:55 +00001631 /**
1632 * \brief A reference to a variable that occurs in some non-expression
1633 * context, e.g., a C++ lambda capture list.
1634 */
1635 CXCursor_VariableRef = 50,
1636
1637 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001638
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001639 /* Error conditions */
1640 CXCursor_FirstInvalid = 70,
1641 CXCursor_InvalidFile = 70,
1642 CXCursor_NoDeclFound = 71,
1643 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001644 CXCursor_InvalidCode = 73,
1645 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001646
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001647 /* Expressions */
1648 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001649
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001650 /**
1651 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001652 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001653 *
1654 * Unexposed expressions have the same operations as any other kind
1655 * of expression; one can extract their location information,
1656 * spelling, children, etc. However, the specific kind of the
1657 * expression is not reported.
1658 */
1659 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001660
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001661 /**
1662 * \brief An expression that refers to some value declaration, such
1663 * as a function, varible, or enumerator.
1664 */
1665 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001666
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001667 /**
1668 * \brief An expression that refers to a member of a struct, union,
1669 * class, Objective-C class, etc.
1670 */
1671 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001672
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001673 /** \brief An expression that calls a function. */
1674 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001675
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001676 /** \brief An expression that sends a message to an Objective-C
1677 object or class. */
1678 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001679
1680 /** \brief An expression that represents a block literal. */
1681 CXCursor_BlockExpr = 105,
1682
Douglas Gregor42b29842011-10-05 19:00:14 +00001683 /** \brief An integer literal.
1684 */
1685 CXCursor_IntegerLiteral = 106,
1686
1687 /** \brief A floating point number literal.
1688 */
1689 CXCursor_FloatingLiteral = 107,
1690
1691 /** \brief An imaginary number literal.
1692 */
1693 CXCursor_ImaginaryLiteral = 108,
1694
1695 /** \brief A string literal.
1696 */
1697 CXCursor_StringLiteral = 109,
1698
1699 /** \brief A character literal.
1700 */
1701 CXCursor_CharacterLiteral = 110,
1702
1703 /** \brief A parenthesized expression, e.g. "(1)".
1704 *
1705 * This AST node is only formed if full location information is requested.
1706 */
1707 CXCursor_ParenExpr = 111,
1708
1709 /** \brief This represents the unary-expression's (except sizeof and
1710 * alignof).
1711 */
1712 CXCursor_UnaryOperator = 112,
1713
1714 /** \brief [C99 6.5.2.1] Array Subscripting.
1715 */
1716 CXCursor_ArraySubscriptExpr = 113,
1717
1718 /** \brief A builtin binary operation expression such as "x + y" or
1719 * "x <= y".
1720 */
1721 CXCursor_BinaryOperator = 114,
1722
1723 /** \brief Compound assignment such as "+=".
1724 */
1725 CXCursor_CompoundAssignOperator = 115,
1726
1727 /** \brief The ?: ternary operator.
1728 */
1729 CXCursor_ConditionalOperator = 116,
1730
1731 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1732 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1733 *
1734 * For example: (int)f.
1735 */
1736 CXCursor_CStyleCastExpr = 117,
1737
1738 /** \brief [C99 6.5.2.5]
1739 */
1740 CXCursor_CompoundLiteralExpr = 118,
1741
1742 /** \brief Describes an C or C++ initializer list.
1743 */
1744 CXCursor_InitListExpr = 119,
1745
1746 /** \brief The GNU address of label extension, representing &&label.
1747 */
1748 CXCursor_AddrLabelExpr = 120,
1749
1750 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1751 */
1752 CXCursor_StmtExpr = 121,
1753
Benjamin Kramerffbe9b92011-12-23 17:00:35 +00001754 /** \brief Represents a C11 generic selection.
Douglas Gregor42b29842011-10-05 19:00:14 +00001755 */
1756 CXCursor_GenericSelectionExpr = 122,
1757
1758 /** \brief Implements the GNU __null extension, which is a name for a null
1759 * pointer constant that has integral type (e.g., int or long) and is the same
1760 * size and alignment as a pointer.
1761 *
1762 * The __null extension is typically only used by system headers, which define
1763 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1764 * match the size of a pointer).
1765 */
1766 CXCursor_GNUNullExpr = 123,
1767
1768 /** \brief C++'s static_cast<> expression.
1769 */
1770 CXCursor_CXXStaticCastExpr = 124,
1771
1772 /** \brief C++'s dynamic_cast<> expression.
1773 */
1774 CXCursor_CXXDynamicCastExpr = 125,
1775
1776 /** \brief C++'s reinterpret_cast<> expression.
1777 */
1778 CXCursor_CXXReinterpretCastExpr = 126,
1779
1780 /** \brief C++'s const_cast<> expression.
1781 */
1782 CXCursor_CXXConstCastExpr = 127,
1783
1784 /** \brief Represents an explicit C++ type conversion that uses "functional"
1785 * notion (C++ [expr.type.conv]).
1786 *
1787 * Example:
1788 * \code
1789 * x = int(0.5);
1790 * \endcode
1791 */
1792 CXCursor_CXXFunctionalCastExpr = 128,
1793
1794 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1795 */
1796 CXCursor_CXXTypeidExpr = 129,
1797
1798 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1799 */
1800 CXCursor_CXXBoolLiteralExpr = 130,
1801
1802 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1803 */
1804 CXCursor_CXXNullPtrLiteralExpr = 131,
1805
1806 /** \brief Represents the "this" expression in C++
1807 */
1808 CXCursor_CXXThisExpr = 132,
1809
1810 /** \brief [C++ 15] C++ Throw Expression.
1811 *
1812 * This handles 'throw' and 'throw' assignment-expression. When
1813 * assignment-expression isn't present, Op will be null.
1814 */
1815 CXCursor_CXXThrowExpr = 133,
1816
1817 /** \brief A new expression for memory allocation and constructor calls, e.g:
1818 * "new CXXNewExpr(foo)".
1819 */
1820 CXCursor_CXXNewExpr = 134,
1821
1822 /** \brief A delete expression for memory deallocation and destructor calls,
1823 * e.g. "delete[] pArray".
1824 */
1825 CXCursor_CXXDeleteExpr = 135,
1826
1827 /** \brief A unary expression.
1828 */
1829 CXCursor_UnaryExpr = 136,
1830
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001831 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor42b29842011-10-05 19:00:14 +00001832 */
1833 CXCursor_ObjCStringLiteral = 137,
1834
James Dennett7eee0182012-06-15 05:41:51 +00001835 /** \brief An Objective-C \@encode expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001836 */
1837 CXCursor_ObjCEncodeExpr = 138,
1838
James Dennett7eee0182012-06-15 05:41:51 +00001839 /** \brief An Objective-C \@selector expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001840 */
1841 CXCursor_ObjCSelectorExpr = 139,
1842
James Dennett17d26a62012-06-11 06:19:40 +00001843 /** \brief An Objective-C \@protocol expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001844 */
1845 CXCursor_ObjCProtocolExpr = 140,
1846
1847 /** \brief An Objective-C "bridged" cast expression, which casts between
1848 * Objective-C pointers and C pointers, transferring ownership in the process.
1849 *
1850 * \code
1851 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1852 * \endcode
1853 */
1854 CXCursor_ObjCBridgedCastExpr = 141,
1855
1856 /** \brief Represents a C++0x pack expansion that produces a sequence of
1857 * expressions.
1858 *
1859 * A pack expansion expression contains a pattern (which itself is an
1860 * expression) followed by an ellipsis. For example:
1861 *
1862 * \code
1863 * template<typename F, typename ...Types>
1864 * void forward(F f, Types &&...args) {
1865 * f(static_cast<Types&&>(args)...);
1866 * }
1867 * \endcode
1868 */
1869 CXCursor_PackExpansionExpr = 142,
1870
1871 /** \brief Represents an expression that computes the length of a parameter
1872 * pack.
1873 *
1874 * \code
1875 * template<typename ...Types>
1876 * struct count {
1877 * static const unsigned value = sizeof...(Types);
1878 * };
1879 * \endcode
1880 */
1881 CXCursor_SizeOfPackExpr = 143,
1882
Douglas Gregor011d8b92012-02-15 00:54:55 +00001883 /* \brief Represents a C++ lambda expression that produces a local function
1884 * object.
1885 *
1886 * \code
1887 * void abssort(float *x, unsigned N) {
1888 * std::sort(x, x + N,
1889 * [](float a, float b) {
1890 * return std::abs(a) < std::abs(b);
1891 * });
1892 * }
1893 * \endcode
1894 */
1895 CXCursor_LambdaExpr = 144,
1896
Ted Kremenekb3f75422012-03-06 20:06:06 +00001897 /** \brief Objective-c Boolean Literal.
1898 */
1899 CXCursor_ObjCBoolLiteralExpr = 145,
1900
1901 CXCursor_LastExpr = CXCursor_ObjCBoolLiteralExpr,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001902
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001903 /* Statements */
1904 CXCursor_FirstStmt = 200,
1905 /**
1906 * \brief A statement whose specific kind is not exposed via this
1907 * interface.
1908 *
1909 * Unexposed statements have the same operations as any other kind of
1910 * statement; one can extract their location information, spelling,
1911 * children, etc. However, the specific kind of the statement is not
1912 * reported.
1913 */
1914 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001915
1916 /** \brief A labelled statement in a function.
1917 *
1918 * This cursor kind is used to describe the "start_over:" label statement in
1919 * the following example:
1920 *
1921 * \code
1922 * start_over:
1923 * ++counter;
1924 * \endcode
1925 *
1926 */
1927 CXCursor_LabelStmt = 201,
Douglas Gregor42b29842011-10-05 19:00:14 +00001928
1929 /** \brief A group of statements like { stmt stmt }.
1930 *
1931 * This cursor kind is used to describe compound statements, e.g. function
1932 * bodies.
1933 */
1934 CXCursor_CompoundStmt = 202,
1935
1936 /** \brief A case statment.
1937 */
1938 CXCursor_CaseStmt = 203,
1939
1940 /** \brief A default statement.
1941 */
1942 CXCursor_DefaultStmt = 204,
1943
1944 /** \brief An if statement
1945 */
1946 CXCursor_IfStmt = 205,
1947
1948 /** \brief A switch statement.
1949 */
1950 CXCursor_SwitchStmt = 206,
1951
1952 /** \brief A while statement.
1953 */
1954 CXCursor_WhileStmt = 207,
1955
1956 /** \brief A do statement.
1957 */
1958 CXCursor_DoStmt = 208,
1959
1960 /** \brief A for statement.
1961 */
1962 CXCursor_ForStmt = 209,
1963
1964 /** \brief A goto statement.
1965 */
1966 CXCursor_GotoStmt = 210,
1967
1968 /** \brief An indirect goto statement.
1969 */
1970 CXCursor_IndirectGotoStmt = 211,
1971
1972 /** \brief A continue statement.
1973 */
1974 CXCursor_ContinueStmt = 212,
1975
1976 /** \brief A break statement.
1977 */
1978 CXCursor_BreakStmt = 213,
1979
1980 /** \brief A return statement.
1981 */
1982 CXCursor_ReturnStmt = 214,
1983
Chad Rosierdf5faf52012-08-25 00:11:56 +00001984 /** \brief A GCC inline assembly statement extension.
Douglas Gregor42b29842011-10-05 19:00:14 +00001985 */
Chad Rosierdf5faf52012-08-25 00:11:56 +00001986 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5e02f652012-09-24 19:27:20 +00001987 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor42b29842011-10-05 19:00:14 +00001988
James Dennett7eee0182012-06-15 05:41:51 +00001989 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001990 */
1991 CXCursor_ObjCAtTryStmt = 216,
1992
James Dennett7eee0182012-06-15 05:41:51 +00001993 /** \brief Objective-C's \@catch statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001994 */
1995 CXCursor_ObjCAtCatchStmt = 217,
1996
James Dennett7eee0182012-06-15 05:41:51 +00001997 /** \brief Objective-C's \@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001998 */
1999 CXCursor_ObjCAtFinallyStmt = 218,
2000
James Dennett7eee0182012-06-15 05:41:51 +00002001 /** \brief Objective-C's \@throw statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002002 */
2003 CXCursor_ObjCAtThrowStmt = 219,
2004
James Dennett7eee0182012-06-15 05:41:51 +00002005 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00002006 */
2007 CXCursor_ObjCAtSynchronizedStmt = 220,
2008
2009 /** \brief Objective-C's autorelease pool statement.
2010 */
2011 CXCursor_ObjCAutoreleasePoolStmt = 221,
2012
2013 /** \brief Objective-C's collection statement.
2014 */
2015 CXCursor_ObjCForCollectionStmt = 222,
2016
2017 /** \brief C++'s catch statement.
2018 */
2019 CXCursor_CXXCatchStmt = 223,
2020
2021 /** \brief C++'s try statement.
2022 */
2023 CXCursor_CXXTryStmt = 224,
2024
2025 /** \brief C++'s for (* : *) statement.
2026 */
2027 CXCursor_CXXForRangeStmt = 225,
2028
2029 /** \brief Windows Structured Exception Handling's try statement.
2030 */
2031 CXCursor_SEHTryStmt = 226,
2032
2033 /** \brief Windows Structured Exception Handling's except statement.
2034 */
2035 CXCursor_SEHExceptStmt = 227,
2036
2037 /** \brief Windows Structured Exception Handling's finally statement.
2038 */
2039 CXCursor_SEHFinallyStmt = 228,
2040
Chad Rosier8cd64b42012-06-11 20:47:18 +00002041 /** \brief A MS inline assembly statement extension.
2042 */
2043 CXCursor_MSAsmStmt = 229,
2044
Douglas Gregor42b29842011-10-05 19:00:14 +00002045 /** \brief The null satement ";": C99 6.8.3p3.
2046 *
2047 * This cursor kind is used to describe the null statement.
2048 */
2049 CXCursor_NullStmt = 230,
2050
2051 /** \brief Adaptor class for mixing declarations with statements and
2052 * expressions.
2053 */
2054 CXCursor_DeclStmt = 231,
2055
Joao Matos4c5fa422012-09-04 17:33:09 +00002056 CXCursor_LastStmt = CXCursor_DeclStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002057
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002058 /**
2059 * \brief Cursor that represents the translation unit itself.
2060 *
2061 * The translation unit cursor exists primarily to act as the root
2062 * cursor for traversing the contents of a translation unit.
2063 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002064 CXCursor_TranslationUnit = 300,
2065
Bill Wendlingad017fa2012-12-20 19:22:21 +00002066 /* Attributes */
Ted Kremeneke77f4432010-02-18 03:09:07 +00002067 CXCursor_FirstAttr = 400,
2068 /**
2069 * \brief An attribute whose specific kind is not exposed via this
2070 * interface.
2071 */
2072 CXCursor_UnexposedAttr = 400,
2073
2074 CXCursor_IBActionAttr = 401,
2075 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00002076 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00002077 CXCursor_CXXFinalAttr = 404,
2078 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002079 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002080 CXCursor_AsmLabelAttr = 407,
2081 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002082
2083 /* Preprocessing */
2084 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00002085 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00002086 CXCursor_MacroExpansion = 502,
2087 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002088 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002089 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis6a010122012-10-05 00:22:24 +00002090 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2091
2092 /* Extra Declarations */
2093 /**
2094 * \brief A module import declaration.
2095 */
2096 CXCursor_ModuleImportDecl = 600,
2097 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2098 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002099};
2100
2101/**
2102 * \brief A cursor representing some element in the abstract syntax tree for
2103 * a translation unit.
2104 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002105 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002106 * program--declaration, statements, expressions, references to declarations,
2107 * etc.--under a single "cursor" abstraction with a common set of operations.
2108 * Common operation for a cursor include: getting the physical location in
2109 * a source file where the cursor points, getting the name associated with a
2110 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2111 *
2112 * Cursors can be produced in two specific ways.
2113 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2114 * from which one can use clang_visitChildren() to explore the rest of the
2115 * translation unit. clang_getCursor() maps from a physical source location
2116 * to the entity that resides at that location, allowing one to map from the
2117 * source code into the AST.
2118 */
2119typedef struct {
2120 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00002121 int xdata;
Dmitri Gribenko67812b22013-01-11 21:01:49 +00002122 const void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002123} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002124
2125/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00002126 * \brief A comment AST node.
2127 */
2128typedef struct {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00002129 const void *ASTNode;
2130 CXTranslationUnit TranslationUnit;
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00002131} CXComment;
2132
2133/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002134 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2135 *
2136 * @{
2137 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002138
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002139/**
2140 * \brief Retrieve the NULL cursor, which represents no entity.
2141 */
2142CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002143
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002144/**
2145 * \brief Retrieve the cursor that represents the given translation unit.
2146 *
2147 * The translation unit cursor can be used to start traversing the
2148 * various declarations within the given translation unit.
2149 */
2150CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2151
2152/**
2153 * \brief Determine whether two cursors are equivalent.
2154 */
2155CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002156
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002157/**
Dmitri Gribenko1824d542012-09-13 13:11:20 +00002158 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002159 */
Dmitri Gribenko1824d542012-09-13 13:11:20 +00002160CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002161
2162/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00002163 * \brief Compute a hash value for the given cursor.
2164 */
2165CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2166
2167/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002168 * \brief Retrieve the kind of the given cursor.
2169 */
2170CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2171
2172/**
2173 * \brief Determine whether the given cursor kind represents a declaration.
2174 */
2175CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2176
2177/**
2178 * \brief Determine whether the given cursor kind represents a simple
2179 * reference.
2180 *
2181 * Note that other kinds of cursors (such as expressions) can also refer to
2182 * other cursors. Use clang_getCursorReferenced() to determine whether a
2183 * particular cursor refers to another entity.
2184 */
2185CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2186
2187/**
2188 * \brief Determine whether the given cursor kind represents an expression.
2189 */
2190CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2191
2192/**
2193 * \brief Determine whether the given cursor kind represents a statement.
2194 */
2195CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2196
2197/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002198 * \brief Determine whether the given cursor kind represents an attribute.
2199 */
2200CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2201
2202/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002203 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002204 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002205 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002206CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2207
2208/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002209 * \brief Determine whether the given cursor kind represents a translation
2210 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002211 */
2212CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002213
Ted Kremenekad6eff62010-03-08 21:17:29 +00002214/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002215 * \brief Determine whether the given cursor represents a preprocessing
2216 * element, such as a preprocessor directive or macro instantiation.
2217 */
2218CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2219
2220/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002221 * \brief Determine whether the given cursor represents a currently
2222 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2223 */
2224CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2225
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002226/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002227 * \brief Describe the linkage of the entity referred to by a cursor.
2228 */
2229enum CXLinkageKind {
2230 /** \brief This value indicates that no linkage information is available
2231 * for a provided CXCursor. */
2232 CXLinkage_Invalid,
2233 /**
2234 * \brief This is the linkage for variables, parameters, and so on that
2235 * have automatic storage. This covers normal (non-extern) local variables.
2236 */
2237 CXLinkage_NoLinkage,
2238 /** \brief This is the linkage for static variables and static functions. */
2239 CXLinkage_Internal,
2240 /** \brief This is the linkage for entities with external linkage that live
2241 * in C++ anonymous namespaces.*/
2242 CXLinkage_UniqueExternal,
2243 /** \brief This is the linkage for entities with true, external linkage. */
2244 CXLinkage_External
2245};
2246
2247/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002248 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002249 */
2250CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2251
2252/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002253 * \brief Determine the availability of the entity that this cursor refers to,
2254 * taking the current target platform into account.
Douglas Gregor58ddb602010-08-23 23:00:57 +00002255 *
2256 * \param cursor The cursor to query.
2257 *
2258 * \returns The availability of the cursor.
2259 */
2260CINDEX_LINKAGE enum CXAvailabilityKind
2261clang_getCursorAvailability(CXCursor cursor);
2262
2263/**
Douglas Gregorcc889662012-05-08 00:14:45 +00002264 * Describes the availability of a given entity on a particular platform, e.g.,
2265 * a particular class might only be available on Mac OS 10.7 or newer.
2266 */
2267typedef struct CXPlatformAvailability {
2268 /**
2269 * \brief A string that describes the platform for which this structure
2270 * provides availability information.
2271 *
2272 * Possible values are "ios" or "macosx".
2273 */
2274 CXString Platform;
2275 /**
2276 * \brief The version number in which this entity was introduced.
2277 */
2278 CXVersion Introduced;
2279 /**
2280 * \brief The version number in which this entity was deprecated (but is
2281 * still available).
2282 */
2283 CXVersion Deprecated;
2284 /**
2285 * \brief The version number in which this entity was obsoleted, and therefore
2286 * is no longer available.
2287 */
2288 CXVersion Obsoleted;
2289 /**
2290 * \brief Whether the entity is unconditionally unavailable on this platform.
2291 */
2292 int Unavailable;
2293 /**
2294 * \brief An optional message to provide to a user of this API, e.g., to
2295 * suggest replacement APIs.
2296 */
2297 CXString Message;
2298} CXPlatformAvailability;
2299
2300/**
2301 * \brief Determine the availability of the entity that this cursor refers to
2302 * on any platforms for which availability information is known.
2303 *
2304 * \param cursor The cursor to query.
2305 *
2306 * \param always_deprecated If non-NULL, will be set to indicate whether the
2307 * entity is deprecated on all platforms.
2308 *
2309 * \param deprecated_message If non-NULL, will be set to the message text
2310 * provided along with the unconditional deprecation of this entity. The client
2311 * is responsible for deallocating this string.
2312 *
James Dennett7eee0182012-06-15 05:41:51 +00002313 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregorcc889662012-05-08 00:14:45 +00002314 * entity is unavailable on all platforms.
2315 *
2316 * \param unavailable_message If non-NULL, will be set to the message text
2317 * provided along with the unconditional unavailability of this entity. The
2318 * client is responsible for deallocating this string.
2319 *
2320 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2321 * that will be populated with platform availability information, up to either
2322 * the number of platforms for which availability information is available (as
2323 * returned by this function) or \c availability_size, whichever is smaller.
2324 *
2325 * \param availability_size The number of elements available in the
2326 * \c availability array.
2327 *
2328 * \returns The number of platforms (N) for which availability information is
2329 * available (which is unrelated to \c availability_size).
2330 *
2331 * Note that the client is responsible for calling
2332 * \c clang_disposeCXPlatformAvailability to free each of the
2333 * platform-availability structures returned. There are
2334 * \c min(N, availability_size) such structures.
2335 */
2336CINDEX_LINKAGE int
2337clang_getCursorPlatformAvailability(CXCursor cursor,
2338 int *always_deprecated,
2339 CXString *deprecated_message,
2340 int *always_unavailable,
2341 CXString *unavailable_message,
2342 CXPlatformAvailability *availability,
2343 int availability_size);
2344
2345/**
2346 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2347 */
2348CINDEX_LINKAGE void
2349clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2350
2351/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002352 * \brief Describe the "language" of the entity referred to by a cursor.
2353 */
2354CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002355 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002356 CXLanguage_C,
2357 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002358 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002359};
2360
2361/**
2362 * \brief Determine the "language" of the entity referred to by a given cursor.
2363 */
2364CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2365
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002366/**
2367 * \brief Returns the translation unit that a cursor originated from.
2368 */
2369CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2370
Ted Kremenekeca099b2010-12-08 23:43:14 +00002371
2372/**
2373 * \brief A fast container representing a set of CXCursors.
2374 */
2375typedef struct CXCursorSetImpl *CXCursorSet;
2376
2377/**
2378 * \brief Creates an empty CXCursorSet.
2379 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +00002380CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
Ted Kremenekeca099b2010-12-08 23:43:14 +00002381
2382/**
2383 * \brief Disposes a CXCursorSet and releases its associated memory.
2384 */
2385CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2386
2387/**
2388 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2389 *
2390 * \returns non-zero if the set contains the specified cursor.
2391*/
2392CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2393 CXCursor cursor);
2394
2395/**
2396 * \brief Inserts a CXCursor into a CXCursorSet.
2397 *
2398 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2399*/
2400CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2401 CXCursor cursor);
2402
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002403/**
2404 * \brief Determine the semantic parent of the given cursor.
2405 *
2406 * The semantic parent of a cursor is the cursor that semantically contains
2407 * the given \p cursor. For many declarations, the lexical and semantic parents
2408 * are equivalent (the lexical parent is returned by
2409 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2410 * definitions are provided out-of-line. For example:
2411 *
2412 * \code
2413 * class C {
2414 * void f();
2415 * };
2416 *
2417 * void C::f() { }
2418 * \endcode
2419 *
2420 * In the out-of-line definition of \c C::f, the semantic parent is the
2421 * the class \c C, of which this function is a member. The lexical parent is
2422 * the place where the declaration actually occurs in the source code; in this
2423 * case, the definition occurs in the translation unit. In general, the
2424 * lexical parent for a given entity can change without affecting the semantics
2425 * of the program, and the lexical parent of different declarations of the
2426 * same entity may be different. Changing the semantic parent of a declaration,
2427 * on the other hand, can have a major impact on semantics, and redeclarations
2428 * of a particular entity should all have the same semantic context.
2429 *
2430 * In the example above, both declarations of \c C::f have \c C as their
2431 * semantic context, while the lexical context of the first \c C::f is \c C
2432 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002433 *
2434 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002435 */
2436CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2437
2438/**
2439 * \brief Determine the lexical parent of the given cursor.
2440 *
2441 * The lexical parent of a cursor is the cursor in which the given \p cursor
2442 * was actually written. For many declarations, the lexical and semantic parents
2443 * are equivalent (the semantic parent is returned by
2444 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2445 * definitions are provided out-of-line. For example:
2446 *
2447 * \code
2448 * class C {
2449 * void f();
2450 * };
2451 *
2452 * void C::f() { }
2453 * \endcode
2454 *
2455 * In the out-of-line definition of \c C::f, the semantic parent is the
2456 * the class \c C, of which this function is a member. The lexical parent is
2457 * the place where the declaration actually occurs in the source code; in this
2458 * case, the definition occurs in the translation unit. In general, the
2459 * lexical parent for a given entity can change without affecting the semantics
2460 * of the program, and the lexical parent of different declarations of the
2461 * same entity may be different. Changing the semantic parent of a declaration,
2462 * on the other hand, can have a major impact on semantics, and redeclarations
2463 * of a particular entity should all have the same semantic context.
2464 *
2465 * In the example above, both declarations of \c C::f have \c C as their
2466 * semantic context, while the lexical context of the first \c C::f is \c C
2467 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002468 *
2469 * For declarations written in the global scope, the lexical parent is
2470 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002471 */
2472CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002473
2474/**
2475 * \brief Determine the set of methods that are overridden by the given
2476 * method.
2477 *
2478 * In both Objective-C and C++, a method (aka virtual member function,
2479 * in C++) can override a virtual method in a base class. For
2480 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002481 * base class, its protocols, or its categories' protocols, that has the same
2482 * selector and is of the same kind (class or instance).
2483 * If no such method exists, the search continues to the class's superclass,
2484 * its protocols, and its categories, and so on. A method from an Objective-C
2485 * implementation is considered to override the same methods as its
2486 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002487 *
2488 * For C++, a virtual member function overrides any virtual member
2489 * function with the same signature that occurs in its base
2490 * classes. With multiple inheritance, a virtual member function can
2491 * override several virtual member functions coming from different
2492 * base classes.
2493 *
2494 * In all cases, this function determines the immediate overridden
2495 * method, rather than all of the overridden methods. For example, if
2496 * a method is originally declared in a class A, then overridden in B
2497 * (which in inherits from A) and also in C (which inherited from B),
2498 * then the only overridden method returned from this function when
2499 * invoked on C's method will be B's method. The client may then
2500 * invoke this function again, given the previously-found overridden
2501 * methods, to map out the complete method-override set.
2502 *
2503 * \param cursor A cursor representing an Objective-C or C++
2504 * method. This routine will compute the set of methods that this
2505 * method overrides.
2506 *
2507 * \param overridden A pointer whose pointee will be replaced with a
2508 * pointer to an array of cursors, representing the set of overridden
2509 * methods. If there are no overridden methods, the pointee will be
2510 * set to NULL. The pointee must be freed via a call to
2511 * \c clang_disposeOverriddenCursors().
2512 *
2513 * \param num_overridden A pointer to the number of overridden
2514 * functions, will be set to the number of overridden functions in the
2515 * array pointed to by \p overridden.
2516 */
2517CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2518 CXCursor **overridden,
2519 unsigned *num_overridden);
2520
2521/**
2522 * \brief Free the set of overridden cursors returned by \c
2523 * clang_getOverriddenCursors().
2524 */
2525CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2526
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002527/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002528 * \brief Retrieve the file that is included by the given inclusion directive
2529 * cursor.
2530 */
2531CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2532
2533/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002534 * @}
2535 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002536
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002537/**
2538 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2539 *
2540 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2541 * routines help map between cursors and the physical locations where the
2542 * described entities occur in the source code. The mapping is provided in
2543 * both directions, so one can map from source code to the AST and back.
2544 *
2545 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002546 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002547
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002548/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002549 * \brief Map a source location to the cursor that describes the entity at that
2550 * location in the source code.
2551 *
2552 * clang_getCursor() maps an arbitrary source location within a translation
2553 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002554 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002555 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002556 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002557 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2558 * will return a cursor referring to the "+" expression.
2559 *
2560 * \returns a cursor representing the entity at the given source location, or
2561 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002562 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002563CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002564
Douglas Gregor98258af2010-01-18 22:46:11 +00002565/**
2566 * \brief Retrieve the physical location of the source constructor referenced
2567 * by the given cursor.
2568 *
2569 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002570 * declaration, where the name of that declaration would occur if it is
2571 * unnamed, or some keyword that introduces that particular declaration.
2572 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002573 * source code.
2574 */
2575CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002576
Douglas Gregorb6998662010-01-19 19:34:47 +00002577/**
2578 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002579 * the given cursor.
2580 *
2581 * The extent of a cursor starts with the file/line/column pointing at the
2582 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002583 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002584 * declaration, the extent covers the declaration itself. For a reference,
2585 * the extent covers the location of the reference (e.g., where the referenced
2586 * entity was actually used).
2587 */
2588CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002589
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002590/**
2591 * @}
2592 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002593
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002594/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002595 * \defgroup CINDEX_TYPES Type information for CXCursors
2596 *
2597 * @{
2598 */
2599
2600/**
2601 * \brief Describes the kind of type
2602 */
2603enum CXTypeKind {
2604 /**
2605 * \brief Reprents an invalid type (e.g., where no type is available).
2606 */
2607 CXType_Invalid = 0,
2608
2609 /**
2610 * \brief A type whose specific kind is not exposed via this
2611 * interface.
2612 */
2613 CXType_Unexposed = 1,
2614
2615 /* Builtin types */
2616 CXType_Void = 2,
2617 CXType_Bool = 3,
2618 CXType_Char_U = 4,
2619 CXType_UChar = 5,
2620 CXType_Char16 = 6,
2621 CXType_Char32 = 7,
2622 CXType_UShort = 8,
2623 CXType_UInt = 9,
2624 CXType_ULong = 10,
2625 CXType_ULongLong = 11,
2626 CXType_UInt128 = 12,
2627 CXType_Char_S = 13,
2628 CXType_SChar = 14,
2629 CXType_WChar = 15,
2630 CXType_Short = 16,
2631 CXType_Int = 17,
2632 CXType_Long = 18,
2633 CXType_LongLong = 19,
2634 CXType_Int128 = 20,
2635 CXType_Float = 21,
2636 CXType_Double = 22,
2637 CXType_LongDouble = 23,
2638 CXType_NullPtr = 24,
2639 CXType_Overload = 25,
2640 CXType_Dependent = 26,
2641 CXType_ObjCId = 27,
2642 CXType_ObjCClass = 28,
2643 CXType_ObjCSel = 29,
2644 CXType_FirstBuiltin = CXType_Void,
2645 CXType_LastBuiltin = CXType_ObjCSel,
2646
2647 CXType_Complex = 100,
2648 CXType_Pointer = 101,
2649 CXType_BlockPointer = 102,
2650 CXType_LValueReference = 103,
2651 CXType_RValueReference = 104,
2652 CXType_Record = 105,
2653 CXType_Enum = 106,
2654 CXType_Typedef = 107,
2655 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002656 CXType_ObjCObjectPointer = 109,
2657 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002658 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002659 CXType_ConstantArray = 112,
2660 CXType_Vector = 113
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002661};
2662
2663/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002664 * \brief Describes the calling convention of a function type
2665 */
2666enum CXCallingConv {
2667 CXCallingConv_Default = 0,
2668 CXCallingConv_C = 1,
2669 CXCallingConv_X86StdCall = 2,
2670 CXCallingConv_X86FastCall = 3,
2671 CXCallingConv_X86ThisCall = 4,
2672 CXCallingConv_X86Pascal = 5,
2673 CXCallingConv_AAPCS = 6,
2674 CXCallingConv_AAPCS_VFP = 7,
Derek Schuff263366f2012-10-16 22:30:41 +00002675 CXCallingConv_PnaclCall = 8,
Guy Benyei38980082012-12-25 08:53:55 +00002676 CXCallingConv_IntelOclBicc = 9,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002677
2678 CXCallingConv_Invalid = 100,
2679 CXCallingConv_Unexposed = 200
2680};
2681
2682
2683/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002684 * \brief The type of an element in the abstract syntax tree.
2685 *
2686 */
2687typedef struct {
2688 enum CXTypeKind kind;
2689 void *data[2];
2690} CXType;
2691
2692/**
2693 * \brief Retrieve the type of a CXCursor (if any).
2694 */
2695CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2696
2697/**
Dmitri Gribenkoae03d8e2013-02-15 21:15:49 +00002698 * \brief Pretty-print the underlying type using the rules of the
2699 * language of the translation unit from which it came.
2700 *
2701 * If the type is invalid, an empty string is returned.
2702 */
2703CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2704
2705/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002706 * \brief Retrieve the underlying type of a typedef declaration.
2707 *
2708 * If the cursor does not reference a typedef declaration, an invalid type is
2709 * returned.
2710 */
2711CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2712
2713/**
2714 * \brief Retrieve the integer type of an enum declaration.
2715 *
2716 * If the cursor does not reference an enum declaration, an invalid type is
2717 * returned.
2718 */
2719CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2720
2721/**
2722 * \brief Retrieve the integer value of an enum constant declaration as a signed
2723 * long long.
2724 *
2725 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2726 * Since this is also potentially a valid constant value, the kind of the cursor
2727 * must be verified before calling this function.
2728 */
2729CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2730
2731/**
2732 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2733 * long long.
2734 *
2735 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2736 * Since this is also potentially a valid constant value, the kind of the cursor
2737 * must be verified before calling this function.
2738 */
2739CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2740
2741/**
Dmitri Gribenko1eb60822012-12-04 15:13:46 +00002742 * \brief Retrieve the bit width of a bit field declaration as an integer.
2743 *
2744 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2745 */
2746CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2747
2748/**
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002749 * \brief Retrieve the number of non-variadic arguments associated with a given
2750 * cursor.
2751 *
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +00002752 * The number of arguments can be determined for calls as well as for
2753 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002754 */
2755CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2756
2757/**
2758 * \brief Retrieve the argument cursor of a function or method.
2759 *
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +00002760 * The argument cursor can be determined for calls as well as for declarations
2761 * of functions or methods. For other cursors and for invalid indices, an
2762 * invalid cursor is returned.
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002763 */
2764CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2765
2766/**
James Dennett7eee0182012-06-15 05:41:51 +00002767 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002768 *
James Dennett7eee0182012-06-15 05:41:51 +00002769 * \returns non-zero if the CXTypes represent the same type and
2770 * zero otherwise.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002771 */
2772CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2773
2774/**
2775 * \brief Return the canonical type for a CXType.
2776 *
2777 * Clang's type system explicitly models typedefs and all the ways
2778 * a specific type can be represented. The canonical type is the underlying
2779 * type with all the "sugar" removed. For example, if 'T' is a typedef
2780 * for 'int', the canonical type for 'T' would be 'int'.
2781 */
2782CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2783
2784/**
James Dennett7eee0182012-06-15 05:41:51 +00002785 * \brief Determine whether a CXType has the "const" qualifier set,
2786 * without looking through typedefs that may have added "const" at a
2787 * different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002788 */
2789CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2790
2791/**
James Dennett7eee0182012-06-15 05:41:51 +00002792 * \brief Determine whether a CXType has the "volatile" qualifier set,
2793 * without looking through typedefs that may have added "volatile" at
2794 * a different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002795 */
2796CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2797
2798/**
James Dennett7eee0182012-06-15 05:41:51 +00002799 * \brief Determine whether a CXType has the "restrict" qualifier set,
2800 * without looking through typedefs that may have added "restrict" at a
2801 * different level.
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002802 */
2803CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2804
2805/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002806 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002807 */
2808CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2809
2810/**
2811 * \brief Return the cursor for the declaration of the given type.
2812 */
2813CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2814
David Chisnall5389f482010-12-30 14:05:53 +00002815/**
2816 * Returns the Objective-C type encoding for the specified declaration.
2817 */
2818CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002819
2820/**
2821 * \brief Retrieve the spelling of a given CXTypeKind.
2822 */
2823CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2824
2825/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002826 * \brief Retrieve the calling convention associated with a function type.
2827 *
2828 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2829 */
2830CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2831
2832/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002833 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002834 *
2835 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002836 */
2837CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2838
2839/**
James Dennett7eee0182012-06-15 05:41:51 +00002840 * \brief Retrieve the number of non-variadic arguments associated with a
2841 * function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002842 *
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002843 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002844 */
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002845CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002846
2847/**
2848 * \brief Retrieve the type of an argument of a function type.
2849 *
James Dennett7eee0182012-06-15 05:41:51 +00002850 * If a non-function type is passed in or the function does not have enough
2851 * parameters, an invalid type is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002852 */
2853CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2854
2855/**
2856 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002857 */
2858CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2859
2860/**
2861 * \brief Retrieve the result type associated with a given cursor.
2862 *
2863 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002864 */
2865CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2866
2867/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002868 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2869 * otherwise.
2870 */
2871CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2872
2873/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002874 * \brief Return the element type of an array, complex, or vector type.
2875 *
2876 * If a type is passed in that is not an array, complex, or vector type,
2877 * an invalid type is returned.
2878 */
2879CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2880
2881/**
2882 * \brief Return the number of elements of an array or vector type.
2883 *
2884 * If a type is passed in that is not an array or vector type,
2885 * -1 is returned.
2886 */
2887CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2888
2889/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002890 * \brief Return the element type of an array type.
2891 *
2892 * If a non-array type is passed in, an invalid type is returned.
2893 */
2894CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2895
2896/**
Sylvestre Ledrubed28ac2012-07-23 08:59:39 +00002897 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002898 *
2899 * If a non-array type is passed in, -1 is returned.
2900 */
2901CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2902
2903/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002904 * \brief Returns 1 if the base class specified by the cursor with kind
2905 * CX_CXXBaseSpecifier is virtual.
2906 */
2907CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2908
2909/**
2910 * \brief Represents the C++ access control level to a base class for a
2911 * cursor with kind CX_CXXBaseSpecifier.
2912 */
2913enum CX_CXXAccessSpecifier {
2914 CX_CXXInvalidAccessSpecifier,
2915 CX_CXXPublic,
2916 CX_CXXProtected,
2917 CX_CXXPrivate
2918};
2919
2920/**
2921 * \brief Returns the access control level for the C++ base specifier
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00002922 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2923 * CXCursor_AccessSpecifier.
Ted Kremenek3064ef92010-08-27 21:34:58 +00002924 */
2925CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2926
2927/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002928 * \brief Determine the number of overloaded declarations referenced by a
2929 * \c CXCursor_OverloadedDeclRef cursor.
2930 *
2931 * \param cursor The cursor whose overloaded declarations are being queried.
2932 *
2933 * \returns The number of overloaded declarations referenced by \c cursor. If it
2934 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2935 */
2936CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2937
2938/**
2939 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2940 * by a \c CXCursor_OverloadedDeclRef cursor.
2941 *
2942 * \param cursor The cursor whose overloaded declarations are being queried.
2943 *
2944 * \param index The zero-based index into the set of overloaded declarations in
2945 * the cursor.
2946 *
2947 * \returns A cursor representing the declaration referenced by the given
2948 * \c cursor at the specified \c index. If the cursor does not have an
2949 * associated set of overloaded declarations, or if the index is out of bounds,
2950 * returns \c clang_getNullCursor();
2951 */
2952CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2953 unsigned index);
2954
2955/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002956 * @}
2957 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002958
2959/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002960 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002961 *
2962 * @{
2963 */
2964
2965
2966/**
2967 * \brief For cursors representing an iboutletcollection attribute,
2968 * this function returns the collection element type.
2969 *
2970 */
2971CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2972
2973/**
2974 * @}
2975 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002976
2977/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002978 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2979 *
2980 * These routines provide the ability to traverse the abstract syntax tree
2981 * using cursors.
2982 *
2983 * @{
2984 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002985
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002986/**
2987 * \brief Describes how the traversal of the children of a particular
2988 * cursor should proceed after visiting a particular child cursor.
2989 *
2990 * A value of this enumeration type should be returned by each
2991 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2992 */
2993enum CXChildVisitResult {
2994 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002995 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002996 */
2997 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002998 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002999 * \brief Continues the cursor traversal with the next sibling of
3000 * the cursor just visited, without visiting its children.
3001 */
3002 CXChildVisit_Continue,
3003 /**
3004 * \brief Recursively traverse the children of this cursor, using
3005 * the same visitor and client data.
3006 */
3007 CXChildVisit_Recurse
3008};
3009
3010/**
3011 * \brief Visitor invoked for each cursor found by a traversal.
3012 *
3013 * This visitor function will be invoked for each cursor found by
3014 * clang_visitCursorChildren(). Its first argument is the cursor being
3015 * visited, its second argument is the parent visitor for that cursor,
3016 * and its third argument is the client data provided to
3017 * clang_visitCursorChildren().
3018 *
3019 * The visitor should return one of the \c CXChildVisitResult values
3020 * to direct clang_visitCursorChildren().
3021 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003022typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3023 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003024 CXClientData client_data);
3025
3026/**
3027 * \brief Visit the children of a particular cursor.
3028 *
3029 * This function visits all the direct children of the given cursor,
3030 * invoking the given \p visitor function with the cursors of each
3031 * visited child. The traversal may be recursive, if the visitor returns
3032 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3033 * the visitor returns \c CXChildVisit_Break.
3034 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003035 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00003036 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003037 * definition, have no children).
3038 *
3039 * \param visitor the visitor function that will be invoked for each
3040 * child of \p parent.
3041 *
3042 * \param client_data pointer data supplied by the client, which will
3043 * be passed to the visitor each time it is invoked.
3044 *
3045 * \returns a non-zero value if the traversal was terminated
3046 * prematurely by the visitor returning \c CXChildVisit_Break.
3047 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003048CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003049 CXCursorVisitor visitor,
3050 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00003051#ifdef __has_feature
3052# if __has_feature(blocks)
3053/**
3054 * \brief Visitor invoked for each cursor found by a traversal.
3055 *
3056 * This visitor block will be invoked for each cursor found by
3057 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3058 * visited, its second argument is the parent visitor for that cursor.
3059 *
3060 * The visitor should return one of the \c CXChildVisitResult values
3061 * to direct clang_visitChildrenWithBlock().
3062 */
3063typedef enum CXChildVisitResult
3064 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3065
3066/**
3067 * Visits the children of a cursor using the specified block. Behaves
3068 * identically to clang_visitChildren() in all other respects.
3069 */
3070unsigned clang_visitChildrenWithBlock(CXCursor parent,
3071 CXCursorVisitorBlock block);
3072# endif
3073#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003074
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003075/**
3076 * @}
3077 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003078
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003079/**
3080 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3081 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003082 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003083 * across translation units, by providing the names of the entities referenced
3084 * by cursors, follow reference cursors to the declarations they reference,
3085 * and associate declarations with their definitions.
3086 *
3087 * @{
3088 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003089
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003090/**
3091 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3092 * by the given cursor.
3093 *
3094 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3095 * entity (function, class, variable, etc.) within a program. USRs can be
3096 * compared across translation units to determine, e.g., when references in
3097 * one translation refer to an entity defined in another translation unit.
3098 */
3099CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3100
3101/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003102 * \brief Construct a USR for a specified Objective-C class.
3103 */
3104CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3105
3106/**
3107 * \brief Construct a USR for a specified Objective-C category.
3108 */
3109CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00003110 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003111 const char *category_name);
3112
3113/**
3114 * \brief Construct a USR for a specified Objective-C protocol.
3115 */
3116CINDEX_LINKAGE CXString
3117 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3118
3119
3120/**
3121 * \brief Construct a USR for a specified Objective-C instance variable and
3122 * the USR for its containing class.
3123 */
3124CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3125 CXString classUSR);
3126
3127/**
3128 * \brief Construct a USR for a specified Objective-C method and
3129 * the USR for its containing class.
3130 */
3131CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3132 unsigned isInstanceMethod,
3133 CXString classUSR);
3134
3135/**
3136 * \brief Construct a USR for a specified Objective-C property and the USR
3137 * for its containing class.
3138 */
3139CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3140 CXString classUSR);
3141
3142/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003143 * \brief Retrieve a name for the entity referenced by this cursor.
3144 */
3145CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3146
Douglas Gregor358559d2010-10-02 22:49:11 +00003147/**
Argyrios Kyrtzidisba1da142012-03-30 20:58:35 +00003148 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3149 * Most of the times there is only one range for the complete spelling but for
3150 * objc methods and objc message expressions, there are multiple pieces for each
3151 * selector identifier.
3152 *
3153 * \param pieceIndex the index of the spelling name piece. If this is greater
3154 * than the actual number of pieces, it will return a NULL (invalid) range.
3155 *
3156 * \param options Reserved.
3157 */
3158CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3159 unsigned pieceIndex,
3160 unsigned options);
3161
3162/**
Douglas Gregor358559d2010-10-02 22:49:11 +00003163 * \brief Retrieve the display name for the entity referenced by this cursor.
3164 *
3165 * The display name contains extra information that helps identify the cursor,
3166 * such as the parameters of a function or template or the arguments of a
3167 * class template specialization.
3168 */
3169CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3170
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003171/** \brief For a cursor that is a reference, retrieve a cursor representing the
3172 * entity that it references.
3173 *
3174 * Reference cursors refer to other entities in the AST. For example, an
3175 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003176 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003177 * cursor for the superclass reference. If the input cursor is a declaration or
3178 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003179 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00003180 */
3181CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00003182
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003183/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003184 * \brief For a cursor that is either a reference to or a declaration
3185 * of some entity, retrieve a cursor that describes the definition of
3186 * that entity.
3187 *
3188 * Some entities can be declared multiple times within a translation
3189 * unit, but only one of those declarations can also be a
3190 * definition. For example, given:
3191 *
3192 * \code
3193 * int f(int, int);
3194 * int g(int x, int y) { return f(x, y); }
3195 * int f(int a, int b) { return a + b; }
3196 * int f(int, int);
3197 * \endcode
3198 *
3199 * there are three declarations of the function "f", but only the
3200 * second one is a definition. The clang_getCursorDefinition()
3201 * function will take any cursor pointing to a declaration of "f"
3202 * (the first or fourth lines of the example) or a cursor referenced
3203 * that uses "f" (the call to "f' inside "g") and will return a
3204 * declaration cursor pointing to the definition (the second "f"
3205 * declaration).
3206 *
3207 * If given a cursor for which there is no corresponding definition,
3208 * e.g., because there is no definition of that entity within this
3209 * translation unit, returns a NULL cursor.
3210 */
3211CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3212
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003213/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003214 * \brief Determine whether the declaration pointed to by this cursor
3215 * is also a definition of that entity.
3216 */
3217CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3218
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003219/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003220 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3221 *
3222 * In the C family of languages, many kinds of entities can be declared several
3223 * times within a single translation unit. For example, a structure type can
3224 * be forward-declared (possibly multiple times) and later defined:
3225 *
3226 * \code
3227 * struct X;
3228 * struct X;
3229 * struct X {
3230 * int member;
3231 * };
3232 * \endcode
3233 *
3234 * The declarations and the definition of \c X are represented by three
3235 * different cursors, all of which are declarations of the same underlying
3236 * entity. One of these cursor is considered the "canonical" cursor, which
3237 * is effectively the representative for the underlying entity. One can
3238 * determine if two cursors are declarations of the same underlying entity by
3239 * comparing their canonical cursors.
3240 *
3241 * \returns The canonical cursor for the entity referred to by the given cursor.
3242 */
3243CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3244
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003245
3246/**
3247 * \brief If the cursor points to a selector identifier in a objc method or
3248 * message expression, this returns the selector index.
3249 *
James Dennett7eee0182012-06-15 05:41:51 +00003250 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003251 * determine if the location points to a selector identifier.
3252 *
3253 * \returns The selector index if the cursor is an objc method or message
3254 * expression and the cursor is pointing to a selector identifier, or -1
3255 * otherwise.
3256 */
3257CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3258
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003259/**
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00003260 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3261 * returns non-zero if the method/message is "dynamic", meaning:
3262 *
3263 * For a C++ method: the call is virtual.
3264 * For an ObjC message: the receiver is an object instance, not 'super' or a
3265 * specific class.
3266 *
3267 * If the method/message is "static" or the cursor does not point to a
3268 * method/message, it will return zero.
3269 */
3270CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3271
3272/**
Argyrios Kyrtzidise4a990f2012-11-01 02:01:34 +00003273 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3274 * receiver.
3275 */
3276CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3277
3278/**
Dmitri Gribenkoaa0cd852012-06-20 00:34:58 +00003279 * \brief Given a cursor that represents a declaration, return the associated
3280 * comment's source range. The range may include multiple consecutive comments
3281 * with whitespace in between.
3282 */
3283CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3284
3285/**
3286 * \brief Given a cursor that represents a declaration, return the associated
3287 * comment text, including comment markers.
3288 */
3289CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3290
3291/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003292 * \brief Given a cursor that represents a documentable entity (e.g.,
3293 * declaration), return the associated \\brief paragraph; otherwise return the
3294 * first paragraph.
Dmitri Gribenko2d44d772012-06-26 20:39:18 +00003295 */
3296CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3297
3298/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003299 * \brief Given a cursor that represents a documentable entity (e.g.,
3300 * declaration), return the associated parsed comment as a
3301 * \c CXComment_FullComment AST node.
3302 */
3303CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3304
3305/**
3306 * @}
3307 */
3308
3309/**
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003310 * \defgroup CINDEX_MODULE Module introspection
3311 *
3312 * The functions in this group provide access to information about modules.
3313 *
3314 * @{
3315 */
3316
3317typedef void *CXModule;
3318
3319/**
3320 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3321 */
3322CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3323
3324/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003325 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003326 *
3327 * \returns the parent of a sub-module or NULL if the given module is top-level,
3328 * e.g. for 'std.vector' it will return the 'std' module.
3329 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003330CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003331
3332/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003333 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003334 *
3335 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3336 * will return "vector".
3337 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003338CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003339
3340/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003341 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003342 *
3343 * \returns the full name of the module, e.g. "std.vector".
3344 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003345CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003346
3347/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003348 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003349 *
3350 * \returns the number of top level headers associated with this module.
3351 */
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +00003352CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3353 CXModule Module);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003354
3355/**
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003356 * \param Module a module object.
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003357 *
3358 * \param Index top level header index (zero-based).
3359 *
3360 * \returns the specified top level header associated with the module.
3361 */
Argyrios Kyrtzidisd29245c2012-10-06 01:18:38 +00003362CINDEX_LINKAGE
Argyrios Kyrtzidisc1d22392013-03-13 21:13:43 +00003363CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3364 CXModule Module, unsigned Index);
Argyrios Kyrtzidis5d04b1a2012-10-05 00:22:37 +00003365
3366/**
3367 * @}
3368 */
3369
3370/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003371 * \defgroup CINDEX_COMMENT Comment AST introspection
3372 *
3373 * The routines in this group provide access to information in the
3374 * documentation comment ASTs.
3375 *
3376 * @{
3377 */
3378
3379/**
3380 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3381 * node can be considered block content (e. g., paragraph), inline content
3382 * (plain text) or neither (the root AST node).
3383 */
3384enum CXCommentKind {
3385 /**
3386 * \brief Null comment. No AST node is constructed at the requested location
3387 * because there is no text or a syntax error.
3388 */
3389 CXComment_Null = 0,
3390
3391 /**
3392 * \brief Plain text. Inline content.
3393 */
3394 CXComment_Text = 1,
3395
3396 /**
3397 * \brief A command with word-like arguments that is considered inline content.
3398 *
3399 * For example: \\c command.
3400 */
3401 CXComment_InlineCommand = 2,
3402
3403 /**
3404 * \brief HTML start tag with attributes (name-value pairs). Considered
3405 * inline content.
3406 *
3407 * For example:
3408 * \verbatim
3409 * <br> <br /> <a href="http://example.org/">
3410 * \endverbatim
3411 */
3412 CXComment_HTMLStartTag = 3,
3413
3414 /**
3415 * \brief HTML end tag. Considered inline content.
3416 *
3417 * For example:
3418 * \verbatim
3419 * </a>
3420 * \endverbatim
3421 */
3422 CXComment_HTMLEndTag = 4,
3423
3424 /**
3425 * \brief A paragraph, contains inline comment. The paragraph itself is
3426 * block content.
3427 */
3428 CXComment_Paragraph = 5,
3429
3430 /**
3431 * \brief A command that has zero or more word-like arguments (number of
3432 * word-like arguments depends on command name) and a paragraph as an
3433 * argument. Block command is block content.
3434 *
3435 * Paragraph argument is also a child of the block command.
3436 *
3437 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3438 *
3439 * AST nodes of special kinds that parser knows about (e. g., \\param
3440 * command) have their own node kinds.
3441 */
3442 CXComment_BlockCommand = 6,
3443
3444 /**
3445 * \brief A \\param or \\arg command that describes the function parameter
3446 * (name, passing direction, description).
3447 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003448 * For example: \\param [in] ParamName description.
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003449 */
3450 CXComment_ParamCommand = 7,
3451
3452 /**
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003453 * \brief A \\tparam command that describes a template parameter (name and
3454 * description).
3455 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003456 * For example: \\tparam T description.
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003457 */
3458 CXComment_TParamCommand = 8,
3459
3460 /**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003461 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3462 * block has an opening and a closing command and contains multiple lines of
3463 * text (\c CXComment_VerbatimBlockLine child nodes).
3464 *
3465 * For example:
3466 * \\verbatim
3467 * aaa
3468 * \\endverbatim
3469 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003470 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003471
3472 /**
3473 * \brief A line of text that is contained within a
3474 * CXComment_VerbatimBlockCommand node.
3475 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003476 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003477
3478 /**
3479 * \brief A verbatim line command. Verbatim line has an opening command,
3480 * a single line of text (up to the newline after the opening command) and
3481 * has no closing command.
3482 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003483 CXComment_VerbatimLine = 11,
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003484
3485 /**
3486 * \brief A full comment attached to a declaration, contains block content.
3487 */
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003488 CXComment_FullComment = 12
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003489};
3490
3491/**
Dmitri Gribenko2d66a502012-07-23 16:43:01 +00003492 * \brief The most appropriate rendering mode for an inline command, chosen on
3493 * command semantics in Doxygen.
3494 */
3495enum CXCommentInlineCommandRenderKind {
3496 /**
3497 * \brief Command argument should be rendered in a normal font.
3498 */
3499 CXCommentInlineCommandRenderKind_Normal,
3500
3501 /**
3502 * \brief Command argument should be rendered in a bold font.
3503 */
3504 CXCommentInlineCommandRenderKind_Bold,
3505
3506 /**
3507 * \brief Command argument should be rendered in a monospaced font.
3508 */
3509 CXCommentInlineCommandRenderKind_Monospaced,
3510
3511 /**
3512 * \brief Command argument should be rendered emphasized (typically italic
3513 * font).
3514 */
3515 CXCommentInlineCommandRenderKind_Emphasized
3516};
3517
3518/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003519 * \brief Describes parameter passing direction for \\param or \\arg command.
3520 */
3521enum CXCommentParamPassDirection {
3522 /**
3523 * \brief The parameter is an input parameter.
3524 */
3525 CXCommentParamPassDirection_In,
3526
3527 /**
3528 * \brief The parameter is an output parameter.
3529 */
3530 CXCommentParamPassDirection_Out,
3531
3532 /**
3533 * \brief The parameter is an input and output parameter.
3534 */
3535 CXCommentParamPassDirection_InOut
3536};
3537
3538/**
3539 * \param Comment AST node of any kind.
3540 *
3541 * \returns the type of the AST node.
3542 */
3543CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3544
3545/**
3546 * \param Comment AST node of any kind.
3547 *
3548 * \returns number of children of the AST node.
3549 */
3550CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3551
3552/**
3553 * \param Comment AST node of any kind.
3554 *
Dmitri Gribenko70517ca2012-08-23 17:58:28 +00003555 * \param ChildIdx child index (zero-based).
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003556 *
3557 * \returns the specified child of the AST node.
3558 */
3559CINDEX_LINKAGE
3560CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3561
3562/**
3563 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3564 * only \c CXComment_Text nodes that are empty or whitespace.
3565 *
3566 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3567 * never considered whitespace.
3568 *
3569 * \returns non-zero if \c Comment is whitespace.
3570 */
3571CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3572
3573/**
3574 * \returns non-zero if \c Comment is inline content and has a newline
3575 * immediately following it in the comment text. Newlines between paragraphs
3576 * do not count.
3577 */
3578CINDEX_LINKAGE
3579unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3580
3581/**
3582 * \param Comment a \c CXComment_Text AST node.
3583 *
3584 * \returns text contained in the AST node.
3585 */
3586CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3587
3588/**
3589 * \param Comment a \c CXComment_InlineCommand AST node.
3590 *
3591 * \returns name of the inline command.
3592 */
3593CINDEX_LINKAGE
3594CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3595
3596/**
3597 * \param Comment a \c CXComment_InlineCommand AST node.
3598 *
Dmitri Gribenko2d66a502012-07-23 16:43:01 +00003599 * \returns the most appropriate rendering mode, chosen on command
3600 * semantics in Doxygen.
3601 */
3602CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3603clang_InlineCommandComment_getRenderKind(CXComment Comment);
3604
3605/**
3606 * \param Comment a \c CXComment_InlineCommand AST node.
3607 *
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003608 * \returns number of command arguments.
3609 */
3610CINDEX_LINKAGE
3611unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3612
3613/**
3614 * \param Comment a \c CXComment_InlineCommand AST node.
3615 *
3616 * \param ArgIdx argument index (zero-based).
3617 *
3618 * \returns text of the specified argument.
3619 */
3620CINDEX_LINKAGE
3621CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3622 unsigned ArgIdx);
3623
3624/**
3625 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3626 * node.
3627 *
3628 * \returns HTML tag name.
3629 */
3630CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3631
3632/**
3633 * \param Comment a \c CXComment_HTMLStartTag AST node.
3634 *
3635 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3636 */
3637CINDEX_LINKAGE
3638unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3639
3640/**
3641 * \param Comment a \c CXComment_HTMLStartTag AST node.
3642 *
3643 * \returns number of attributes (name-value pairs) attached to the start tag.
3644 */
3645CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3646
3647/**
3648 * \param Comment a \c CXComment_HTMLStartTag AST node.
3649 *
3650 * \param AttrIdx attribute index (zero-based).
3651 *
3652 * \returns name of the specified attribute.
3653 */
3654CINDEX_LINKAGE
3655CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3656
3657/**
3658 * \param Comment a \c CXComment_HTMLStartTag AST node.
3659 *
3660 * \param AttrIdx attribute index (zero-based).
3661 *
3662 * \returns value of the specified attribute.
3663 */
3664CINDEX_LINKAGE
3665CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3666
3667/**
3668 * \param Comment a \c CXComment_BlockCommand AST node.
3669 *
3670 * \returns name of the block command.
3671 */
3672CINDEX_LINKAGE
3673CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3674
3675/**
3676 * \param Comment a \c CXComment_BlockCommand AST node.
3677 *
3678 * \returns number of word-like arguments.
3679 */
3680CINDEX_LINKAGE
3681unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3682
3683/**
3684 * \param Comment a \c CXComment_BlockCommand AST node.
3685 *
3686 * \param ArgIdx argument index (zero-based).
3687 *
3688 * \returns text of the specified word-like argument.
3689 */
3690CINDEX_LINKAGE
3691CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3692 unsigned ArgIdx);
3693
3694/**
3695 * \param Comment a \c CXComment_BlockCommand or
3696 * \c CXComment_VerbatimBlockCommand AST node.
3697 *
3698 * \returns paragraph argument of the block command.
3699 */
3700CINDEX_LINKAGE
3701CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3702
3703/**
3704 * \param Comment a \c CXComment_ParamCommand AST node.
3705 *
3706 * \returns parameter name.
3707 */
3708CINDEX_LINKAGE
3709CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3710
3711/**
3712 * \param Comment a \c CXComment_ParamCommand AST node.
3713 *
3714 * \returns non-zero if the parameter that this AST node represents was found
3715 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3716 * function will return a meaningful value.
3717 */
3718CINDEX_LINKAGE
3719unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3720
3721/**
3722 * \param Comment a \c CXComment_ParamCommand AST node.
3723 *
3724 * \returns zero-based parameter index in function prototype.
3725 */
3726CINDEX_LINKAGE
3727unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3728
3729/**
3730 * \param Comment a \c CXComment_ParamCommand AST node.
3731 *
3732 * \returns non-zero if parameter passing direction was specified explicitly in
3733 * the comment.
3734 */
3735CINDEX_LINKAGE
3736unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3737
3738/**
3739 * \param Comment a \c CXComment_ParamCommand AST node.
3740 *
3741 * \returns parameter passing direction.
3742 */
3743CINDEX_LINKAGE
3744enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
3745 CXComment Comment);
3746
3747/**
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003748 * \param Comment a \c CXComment_TParamCommand AST node.
3749 *
3750 * \returns template parameter name.
3751 */
3752CINDEX_LINKAGE
3753CXString clang_TParamCommandComment_getParamName(CXComment Comment);
3754
3755/**
3756 * \param Comment a \c CXComment_TParamCommand AST node.
3757 *
3758 * \returns non-zero if the parameter that this AST node represents was found
3759 * in the template parameter list and
3760 * \c clang_TParamCommandComment_getDepth and
3761 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
3762 * value.
3763 */
3764CINDEX_LINKAGE
3765unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
3766
3767/**
3768 * \param Comment a \c CXComment_TParamCommand AST node.
3769 *
3770 * \returns zero-based nesting depth of this parameter in the template parameter list.
3771 *
3772 * For example,
3773 * \verbatim
3774 * template<typename C, template<typename T> class TT>
3775 * void test(TT<int> aaa);
3776 * \endverbatim
3777 * for C and TT nesting depth is 0,
3778 * for T nesting depth is 1.
3779 */
3780CINDEX_LINKAGE
3781unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
3782
3783/**
3784 * \param Comment a \c CXComment_TParamCommand AST node.
3785 *
3786 * \returns zero-based parameter index in the template parameter list at a
3787 * given nesting depth.
3788 *
3789 * For example,
3790 * \verbatim
3791 * template<typename C, template<typename T> class TT>
3792 * void test(TT<int> aaa);
3793 * \endverbatim
3794 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
3795 * at depth 0 C's index is 0, TT's index is 1.
3796 *
3797 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
3798 * at depth 0 T's index is 1 (same as TT's),
3799 * at depth 1 T's index is 0.
3800 */
3801CINDEX_LINKAGE
3802unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
3803
3804/**
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003805 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
3806 *
3807 * \returns text contained in the AST node.
3808 */
3809CINDEX_LINKAGE
3810CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
3811
3812/**
3813 * \param Comment a \c CXComment_VerbatimLine AST node.
3814 *
3815 * \returns text contained in the AST node.
3816 */
3817CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
3818
3819/**
3820 * \brief Convert an HTML tag AST node to string.
3821 *
3822 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3823 * node.
3824 *
3825 * \returns string containing an HTML tag.
3826 */
3827CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
3828
3829/**
3830 * \brief Convert a given full parsed comment to an HTML fragment.
3831 *
3832 * Specific details of HTML layout are subject to change. Don't try to parse
3833 * this HTML back into an AST, use other APIs instead.
3834 *
3835 * Currently the following CSS classes are used:
3836 * \li "para-brief" for \\brief paragraph and equivalent commands;
3837 * \li "para-returns" for \\returns paragraph and equivalent commands;
3838 * \li "word-returns" for the "Returns" word in \\returns paragraph.
3839 *
Dmitri Gribenko3e63d332012-07-21 01:47:43 +00003840 * Function argument documentation is rendered as a \<dl\> list with arguments
3841 * sorted in function prototype order. CSS classes used:
3842 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
3843 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
3844 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
3845 * parameter index is invalid.
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003846 *
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003847 * Template parameter documentation is rendered as a \<dl\> list with
3848 * parameters sorted in template parameter list order. CSS classes used:
3849 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
3850 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko6a425522012-08-01 23:47:30 +00003851 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko96b09862012-07-31 22:37:06 +00003852 * names inside template template parameters;
3853 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
3854 * parameter position is invalid.
3855 *
Dmitri Gribenkoae99b752012-07-20 21:34:34 +00003856 * \param Comment a \c CXComment_FullComment AST node.
3857 *
3858 * \returns string containing an HTML fragment.
3859 */
3860CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
3861
3862/**
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00003863 * \brief Convert a given full parsed comment to an XML document.
3864 *
3865 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
3866 * inside clang source tree.
3867 *
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00003868 * \param Comment a \c CXComment_FullComment AST node.
3869 *
3870 * \returns string containing an XML document.
3871 */
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00003872CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenkof303d4c2012-08-07 17:54:38 +00003873
3874/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003875 * @}
3876 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003877
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003878/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003879 * \defgroup CINDEX_CPP C++ AST introspection
3880 *
3881 * The routines in this group provide access information in the ASTs specific
3882 * to C++ language features.
3883 *
3884 * @{
3885 */
3886
3887/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003888 * \brief Determine if a C++ member function or member function template is
3889 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003890 */
3891CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3892
3893/**
Douglas Gregor211924b2011-05-12 15:17:24 +00003894 * \brief Determine if a C++ member function or member function template is
3895 * explicitly declared 'virtual' or if it overrides a virtual method from
3896 * one of the base classes.
3897 */
3898CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3899
3900/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003901 * \brief Given a cursor that represents a template, determine
3902 * the cursor kind of the specializations would be generated by instantiating
3903 * the template.
3904 *
3905 * This routine can be used to determine what flavor of function template,
3906 * class template, or class template partial specialization is stored in the
3907 * cursor. For example, it can describe whether a class template cursor is
3908 * declared with "struct", "class" or "union".
3909 *
3910 * \param C The cursor to query. This cursor should represent a template
3911 * declaration.
3912 *
3913 * \returns The cursor kind of the specializations that would be generated
3914 * by instantiating the template \p C. If \p C is not a template, returns
3915 * \c CXCursor_NoDeclFound.
3916 */
3917CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3918
3919/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00003920 * \brief Given a cursor that may represent a specialization or instantiation
3921 * of a template, retrieve the cursor that represents the template that it
3922 * specializes or from which it was instantiated.
3923 *
3924 * This routine determines the template involved both for explicit
3925 * specializations of templates and for implicit instantiations of the template,
3926 * both of which are referred to as "specializations". For a class template
3927 * specialization (e.g., \c std::vector<bool>), this routine will return
3928 * either the primary template (\c std::vector) or, if the specialization was
3929 * instantiated from a class template partial specialization, the class template
3930 * partial specialization. For a class template partial specialization and a
3931 * function template specialization (including instantiations), this
3932 * this routine will return the specialized template.
3933 *
3934 * For members of a class template (e.g., member functions, member classes, or
3935 * static data members), returns the specialized or instantiated member.
3936 * Although not strictly "templates" in the C++ language, members of class
3937 * templates have the same notions of specializations and instantiations that
3938 * templates do, so this routine treats them similarly.
3939 *
3940 * \param C A cursor that may be a specialization of a template or a member
3941 * of a template.
3942 *
3943 * \returns If the given cursor is a specialization or instantiation of a
3944 * template or a member thereof, the template or member that it specializes or
3945 * from which it was instantiated. Otherwise, returns a NULL cursor.
3946 */
3947CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00003948
3949/**
3950 * \brief Given a cursor that references something else, return the source range
3951 * covering that reference.
3952 *
3953 * \param C A cursor pointing to a member reference, a declaration reference, or
3954 * an operator call.
3955 * \param NameFlags A bitset with three independent flags:
3956 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3957 * CXNameRange_WantSinglePiece.
3958 * \param PieceIndex For contiguous names or when passing the flag
3959 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3960 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer48d798c2012-06-02 10:20:41 +00003961 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregor430d7a12011-07-25 17:48:11 +00003962 * pieces of the name. See also CXNameRange_WantSinglePiece.
3963 *
3964 * \returns The piece of the name pointed to by the given cursor. If there is no
3965 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3966 */
Francois Pichet48a8d142011-07-25 22:00:44 +00003967CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3968 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00003969 unsigned PieceIndex);
3970
3971enum CXNameRefFlags {
3972 /**
3973 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3974 * range.
3975 */
3976 CXNameRange_WantQualifier = 0x1,
3977
3978 /**
James Dennett7eee0182012-06-15 05:41:51 +00003979 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
3980 * in the range.
Douglas Gregor430d7a12011-07-25 17:48:11 +00003981 */
3982 CXNameRange_WantTemplateArgs = 0x2,
3983
3984 /**
3985 * \brief If the name is non-contiguous, return the full spanning range.
3986 *
3987 * Non-contiguous names occur in Objective-C when a selector with two or more
3988 * parameters is used, or in C++ when using an operator:
3989 * \code
3990 * [object doSomething:here withValue:there]; // ObjC
3991 * return some_vector[1]; // C++
3992 * \endcode
3993 */
3994 CXNameRange_WantSinglePiece = 0x4
3995};
Douglas Gregore0329ac2010-09-02 00:07:54 +00003996
3997/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003998 * @}
3999 */
4000
4001/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004002 * \defgroup CINDEX_LEX Token extraction and manipulation
4003 *
4004 * The routines in this group provide access to the tokens within a
4005 * translation unit, along with a semantic mapping of those tokens to
4006 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004007 *
4008 * @{
4009 */
4010
4011/**
4012 * \brief Describes a kind of token.
4013 */
4014typedef enum CXTokenKind {
4015 /**
4016 * \brief A token that contains some kind of punctuation.
4017 */
4018 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004019
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004020 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004021 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004022 */
4023 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004024
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004025 /**
4026 * \brief An identifier (that is not a keyword).
4027 */
4028 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004029
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004030 /**
4031 * \brief A numeric, string, or character literal.
4032 */
4033 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00004034
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004035 /**
4036 * \brief A comment.
4037 */
4038 CXToken_Comment
4039} CXTokenKind;
4040
4041/**
4042 * \brief Describes a single preprocessing token.
4043 */
4044typedef struct {
4045 unsigned int_data[4];
4046 void *ptr_data;
4047} CXToken;
4048
4049/**
4050 * \brief Determine the kind of the given token.
4051 */
4052CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004053
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004054/**
4055 * \brief Determine the spelling of the given token.
4056 *
4057 * The spelling of a token is the textual representation of that token, e.g.,
4058 * the text of an identifier or keyword.
4059 */
4060CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004061
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004062/**
4063 * \brief Retrieve the source location of the given token.
4064 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004065CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004066 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004067
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004068/**
4069 * \brief Retrieve a source range that covers the given token.
4070 */
4071CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4072
4073/**
4074 * \brief Tokenize the source code described by the given range into raw
4075 * lexical tokens.
4076 *
4077 * \param TU the translation unit whose text is being tokenized.
4078 *
4079 * \param Range the source range in which text should be tokenized. All of the
4080 * tokens produced by tokenization will fall within this source range,
4081 *
4082 * \param Tokens this pointer will be set to point to the array of tokens
4083 * that occur within the given source range. The returned pointer must be
4084 * freed with clang_disposeTokens() before the translation unit is destroyed.
4085 *
4086 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4087 * array.
4088 *
4089 */
4090CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4091 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004092
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004093/**
4094 * \brief Annotate the given set of tokens by providing cursors for each token
4095 * that can be mapped to a specific entity within the abstract syntax tree.
4096 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00004097 * This token-annotation routine is equivalent to invoking
4098 * clang_getCursor() for the source locations of each of the
4099 * tokens. The cursors provided are filtered, so that only those
4100 * cursors that have a direct correspondence to the token are
4101 * accepted. For example, given a function call \c f(x),
4102 * clang_getCursor() would provide the following cursors:
4103 *
4104 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4105 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4106 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4107 *
4108 * Only the first and last of these cursors will occur within the
4109 * annotate, since the tokens "f" and "x' directly refer to a function
4110 * and a variable, respectively, but the parentheses are just a small
4111 * part of the full syntax of the function call expression, which is
4112 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004113 *
4114 * \param TU the translation unit that owns the given tokens.
4115 *
4116 * \param Tokens the set of tokens to annotate.
4117 *
4118 * \param NumTokens the number of tokens in \p Tokens.
4119 *
4120 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4121 * replaced with the cursors corresponding to each token.
4122 */
4123CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4124 CXToken *Tokens, unsigned NumTokens,
4125 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004126
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004127/**
4128 * \brief Free the given set of tokens.
4129 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004130CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004131 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00004132
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004133/**
4134 * @}
4135 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004136
Douglas Gregorfc8ea232010-01-26 17:06:03 +00004137/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004138 * \defgroup CINDEX_DEBUG Debugging facilities
4139 *
4140 * These routines are used for testing and debugging, only, and should not
4141 * be relied upon.
4142 *
4143 * @{
4144 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004145
Steve Naroff4ade6d62009-09-23 17:52:52 +00004146/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00004147CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004148CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4149 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00004150 const char **endBuf,
4151 unsigned *startLine,
4152 unsigned *startColumn,
4153 unsigned *endLine,
4154 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00004155CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00004156CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4157 unsigned stack_size);
4158
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004159/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004160 * @}
4161 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004162
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004163/**
4164 * \defgroup CINDEX_CODE_COMPLET Code completion
4165 *
4166 * Code completion involves taking an (incomplete) source file, along with
4167 * knowledge of where the user is actively editing that file, and suggesting
4168 * syntactically- and semantically-valid constructs that the user might want to
4169 * use at that particular point in the source code. These data structures and
4170 * routines provide support for code completion.
4171 *
4172 * @{
4173 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004174
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004175/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004176 * \brief A semantic string that describes a code-completion result.
4177 *
4178 * A semantic string that describes the formatting of a code-completion
4179 * result as a single "template" of text that should be inserted into the
4180 * source buffer when a particular code-completion result is selected.
4181 * Each semantic string is made up of some number of "chunks", each of which
4182 * contains some text along with a description of what that text means, e.g.,
4183 * the name of the entity being referenced, whether the text chunk is part of
4184 * the template, or whether it is a "placeholder" that the user should replace
4185 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004186 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004187 */
4188typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004189
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004190/**
4191 * \brief A single result of code completion.
4192 */
4193typedef struct {
4194 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004195 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004196 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004197 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004198 * *Decl cursor kinds), describing the entity that the completion is
4199 * referring to.
4200 *
4201 * \todo In the future, we would like to provide a full cursor, to allow
4202 * the client to extract additional information from declaration.
4203 */
4204 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004205
4206 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004207 * \brief The code-completion string that describes how to insert this
4208 * code-completion result into the editing buffer.
4209 */
4210 CXCompletionString CompletionString;
4211} CXCompletionResult;
4212
4213/**
4214 * \brief Describes a single piece of text within a code-completion string.
4215 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004216 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4217 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004218 * should be interpreted by the client or is another completion string.
4219 */
4220enum CXCompletionChunkKind {
4221 /**
4222 * \brief A code-completion string that describes "optional" text that
4223 * could be a part of the template (but is not required).
4224 *
4225 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004226 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004227 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4228 * describes an additional part of the template that is completely optional.
4229 * For example, optional chunks can be used to describe the placeholders for
4230 * arguments that match up with defaulted function parameters, e.g. given:
4231 *
4232 * \code
4233 * void f(int x, float y = 3.14, double z = 2.71828);
4234 * \endcode
4235 *
4236 * The code-completion string for this function would contain:
4237 * - a TypedText chunk for "f".
4238 * - a LeftParen chunk for "(".
4239 * - a Placeholder chunk for "int x"
4240 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4241 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00004242 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004243 * - an Optional chunk containing the last defaulted argument:
4244 * - a Comma chunk for ","
4245 * - a Placeholder chunk for "double z"
4246 * - a RightParen chunk for ")"
4247 *
Daniel Dunbar71570182010-02-17 08:07:44 +00004248 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004249 * - Completely ignore optional chunks, in which case the template for the
4250 * function "f" would only include the first parameter ("int x").
4251 * - Fully expand all optional chunks, in which case the template for the
4252 * function "f" would have all of the parameters.
4253 */
4254 CXCompletionChunk_Optional,
4255 /**
4256 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004257 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004258 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004259 * There will be exactly one "typed text" chunk in a semantic string, which
4260 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004261 * declaration that could be used at the current code point. Clients are
4262 * expected to filter the code-completion results based on the text in this
4263 * chunk.
4264 */
4265 CXCompletionChunk_TypedText,
4266 /**
4267 * \brief Text that should be inserted as part of a code-completion result.
4268 *
4269 * A "text" chunk represents text that is part of the template to be
4270 * inserted into user code should this particular code-completion result
4271 * be selected.
4272 */
4273 CXCompletionChunk_Text,
4274 /**
4275 * \brief Placeholder text that should be replaced by the user.
4276 *
4277 * A "placeholder" chunk marks a place where the user should insert text
4278 * into the code-completion template. For example, placeholders might mark
4279 * the function parameters for a function declaration, to indicate that the
4280 * user should provide arguments for each of those parameters. The actual
4281 * text in a placeholder is a suggestion for the text to display before
4282 * the user replaces the placeholder with real code.
4283 */
4284 CXCompletionChunk_Placeholder,
4285 /**
4286 * \brief Informative text that should be displayed but never inserted as
4287 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004288 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004289 * An "informative" chunk contains annotations that can be displayed to
4290 * help the user decide whether a particular code-completion result is the
4291 * right option, but which is not part of the actual template to be inserted
4292 * by code completion.
4293 */
4294 CXCompletionChunk_Informative,
4295 /**
4296 * \brief Text that describes the current parameter when code-completion is
4297 * referring to function call, message send, or template specialization.
4298 *
4299 * A "current parameter" chunk occurs when code-completion is providing
4300 * information about a parameter corresponding to the argument at the
4301 * code-completion point. For example, given a function
4302 *
4303 * \code
4304 * int add(int x, int y);
4305 * \endcode
4306 *
4307 * and the source code \c add(, where the code-completion point is after the
4308 * "(", the code-completion string will contain a "current parameter" chunk
4309 * for "int x", indicating that the current argument will initialize that
4310 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004311 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004312 * "current paremeter" chunk to "int y".
4313 */
4314 CXCompletionChunk_CurrentParameter,
4315 /**
4316 * \brief A left parenthesis ('('), used to initiate a function call or
4317 * signal the beginning of a function parameter list.
4318 */
4319 CXCompletionChunk_LeftParen,
4320 /**
4321 * \brief A right parenthesis (')'), used to finish a function call or
4322 * signal the end of a function parameter list.
4323 */
4324 CXCompletionChunk_RightParen,
4325 /**
4326 * \brief A left bracket ('[').
4327 */
4328 CXCompletionChunk_LeftBracket,
4329 /**
4330 * \brief A right bracket (']').
4331 */
4332 CXCompletionChunk_RightBracket,
4333 /**
4334 * \brief A left brace ('{').
4335 */
4336 CXCompletionChunk_LeftBrace,
4337 /**
4338 * \brief A right brace ('}').
4339 */
4340 CXCompletionChunk_RightBrace,
4341 /**
4342 * \brief A left angle bracket ('<').
4343 */
4344 CXCompletionChunk_LeftAngle,
4345 /**
4346 * \brief A right angle bracket ('>').
4347 */
4348 CXCompletionChunk_RightAngle,
4349 /**
4350 * \brief A comma separator (',').
4351 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004352 CXCompletionChunk_Comma,
4353 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004354 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004355 *
4356 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004357 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00004358 * expression using the given completion string would have.
4359 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00004360 CXCompletionChunk_ResultType,
4361 /**
4362 * \brief A colon (':').
4363 */
4364 CXCompletionChunk_Colon,
4365 /**
4366 * \brief A semicolon (';').
4367 */
4368 CXCompletionChunk_SemiColon,
4369 /**
4370 * \brief An '=' sign.
4371 */
4372 CXCompletionChunk_Equal,
4373 /**
4374 * Horizontal space (' ').
4375 */
4376 CXCompletionChunk_HorizontalSpace,
4377 /**
4378 * Vertical space ('\n'), after which it is generally a good idea to
4379 * perform indentation.
4380 */
4381 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004382};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004383
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004384/**
4385 * \brief Determine the kind of a particular chunk within a completion string.
4386 *
4387 * \param completion_string the completion string to query.
4388 *
4389 * \param chunk_number the 0-based index of the chunk in the completion string.
4390 *
4391 * \returns the kind of the chunk at the index \c chunk_number.
4392 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004393CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004394clang_getCompletionChunkKind(CXCompletionString completion_string,
4395 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004396
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004397/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004398 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004399 * completion string.
4400 *
4401 * \param completion_string the completion string to query.
4402 *
4403 * \param chunk_number the 0-based index of the chunk in the completion string.
4404 *
4405 * \returns the text associated with the chunk at index \c chunk_number.
4406 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00004407CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004408clang_getCompletionChunkText(CXCompletionString completion_string,
4409 unsigned chunk_number);
4410
4411/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004412 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004413 * within a completion string.
4414 *
4415 * \param completion_string the completion string to query.
4416 *
4417 * \param chunk_number the 0-based index of the chunk in the completion string.
4418 *
4419 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00004420 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004421 */
4422CINDEX_LINKAGE CXCompletionString
4423clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4424 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004425
Douglas Gregor0c8296d2009-11-07 00:00:49 +00004426/**
4427 * \brief Retrieve the number of chunks in the given code-completion string.
4428 */
4429CINDEX_LINKAGE unsigned
4430clang_getNumCompletionChunks(CXCompletionString completion_string);
4431
4432/**
Douglas Gregor12e13132010-05-26 22:00:08 +00004433 * \brief Determine the priority of this code completion.
4434 *
4435 * The priority of a code completion indicates how likely it is that this
4436 * particular completion is the completion that the user will select. The
4437 * priority is selected by various internal heuristics.
4438 *
4439 * \param completion_string The completion string to query.
4440 *
4441 * \returns The priority of this completion string. Smaller values indicate
4442 * higher-priority (more likely) completions.
4443 */
4444CINDEX_LINKAGE unsigned
4445clang_getCompletionPriority(CXCompletionString completion_string);
4446
4447/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00004448 * \brief Determine the availability of the entity that this code-completion
4449 * string refers to.
4450 *
4451 * \param completion_string The completion string to query.
4452 *
4453 * \returns The availability of the completion string.
4454 */
4455CINDEX_LINKAGE enum CXAvailabilityKind
4456clang_getCompletionAvailability(CXCompletionString completion_string);
4457
4458/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00004459 * \brief Retrieve the number of annotations associated with the given
4460 * completion string.
4461 *
4462 * \param completion_string the completion string to query.
4463 *
4464 * \returns the number of annotations associated with the given completion
4465 * string.
4466 */
4467CINDEX_LINKAGE unsigned
4468clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4469
4470/**
4471 * \brief Retrieve the annotation associated with the given completion string.
4472 *
4473 * \param completion_string the completion string to query.
4474 *
4475 * \param annotation_number the 0-based index of the annotation of the
4476 * completion string.
4477 *
4478 * \returns annotation string associated with the completion at index
4479 * \c annotation_number, or a NULL string if that annotation is not available.
4480 */
4481CINDEX_LINKAGE CXString
4482clang_getCompletionAnnotation(CXCompletionString completion_string,
4483 unsigned annotation_number);
4484
4485/**
Douglas Gregorba103062012-03-27 23:34:16 +00004486 * \brief Retrieve the parent context of the given completion string.
4487 *
4488 * The parent context of a completion string is the semantic parent of
4489 * the declaration (if any) that the code completion represents. For example,
4490 * a code completion for an Objective-C method would have the method's class
4491 * or protocol as its context.
4492 *
4493 * \param completion_string The code completion string whose parent is
4494 * being queried.
4495 *
Argyrios Kyrtzidis526d2442012-09-26 16:39:56 +00004496 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregorba103062012-03-27 23:34:16 +00004497 *
James Dennett7eee0182012-06-15 05:41:51 +00004498 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregorba103062012-03-27 23:34:16 +00004499 * the completion string represents a method in the NSObject class.
4500 */
4501CINDEX_LINKAGE CXString
4502clang_getCompletionParent(CXCompletionString completion_string,
4503 enum CXCursorKind *kind);
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00004504
4505/**
4506 * \brief Retrieve the brief documentation comment attached to the declaration
4507 * that corresponds to the given completion string.
4508 */
4509CINDEX_LINKAGE CXString
4510clang_getCompletionBriefComment(CXCompletionString completion_string);
4511
Douglas Gregorba103062012-03-27 23:34:16 +00004512/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00004513 * \brief Retrieve a completion string for an arbitrary declaration or macro
4514 * definition cursor.
4515 *
4516 * \param cursor The cursor to query.
4517 *
4518 * \returns A non-context-sensitive completion string for declaration and macro
4519 * definition cursors, or NULL for other kinds of cursors.
4520 */
4521CINDEX_LINKAGE CXCompletionString
4522clang_getCursorCompletionString(CXCursor cursor);
4523
4524/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004525 * \brief Contains the results of code-completion.
4526 *
4527 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00004528 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00004529 * \c clang_disposeCodeCompleteResults.
4530 */
4531typedef struct {
4532 /**
4533 * \brief The code-completion results.
4534 */
4535 CXCompletionResult *Results;
4536
4537 /**
4538 * \brief The number of code-completion results stored in the
4539 * \c Results array.
4540 */
4541 unsigned NumResults;
4542} CXCodeCompleteResults;
4543
4544/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00004545 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4546 * modify its behavior.
4547 *
4548 * The enumerators in this enumeration can be bitwise-OR'd together to
4549 * provide multiple options to \c clang_codeCompleteAt().
4550 */
4551enum CXCodeComplete_Flags {
4552 /**
4553 * \brief Whether to include macros within the set of code
4554 * completions returned.
4555 */
4556 CXCodeComplete_IncludeMacros = 0x01,
4557
4558 /**
4559 * \brief Whether to include code patterns for language constructs
4560 * within the set of code completions, e.g., for loops.
4561 */
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00004562 CXCodeComplete_IncludeCodePatterns = 0x02,
4563
4564 /**
4565 * \brief Whether to include brief documentation within the set of code
4566 * completions returned.
4567 */
4568 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorcee235c2010-08-05 09:09:23 +00004569};
4570
4571/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004572 * \brief Bits that represent the context under which completion is occurring.
4573 *
4574 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4575 * contexts are occurring simultaneously.
4576 */
4577enum CXCompletionContext {
4578 /**
4579 * \brief The context for completions is unexposed, as only Clang results
4580 * should be included. (This is equivalent to having no context bits set.)
4581 */
4582 CXCompletionContext_Unexposed = 0,
4583
4584 /**
4585 * \brief Completions for any possible type should be included in the results.
4586 */
4587 CXCompletionContext_AnyType = 1 << 0,
4588
4589 /**
4590 * \brief Completions for any possible value (variables, function calls, etc.)
4591 * should be included in the results.
4592 */
4593 CXCompletionContext_AnyValue = 1 << 1,
4594 /**
4595 * \brief Completions for values that resolve to an Objective-C object should
4596 * be included in the results.
4597 */
4598 CXCompletionContext_ObjCObjectValue = 1 << 2,
4599 /**
4600 * \brief Completions for values that resolve to an Objective-C selector
4601 * should be included in the results.
4602 */
4603 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4604 /**
4605 * \brief Completions for values that resolve to a C++ class type should be
4606 * included in the results.
4607 */
4608 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4609
4610 /**
4611 * \brief Completions for fields of the member being accessed using the dot
4612 * operator should be included in the results.
4613 */
4614 CXCompletionContext_DotMemberAccess = 1 << 5,
4615 /**
4616 * \brief Completions for fields of the member being accessed using the arrow
4617 * operator should be included in the results.
4618 */
4619 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4620 /**
4621 * \brief Completions for properties of the Objective-C object being accessed
4622 * using the dot operator should be included in the results.
4623 */
4624 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4625
4626 /**
4627 * \brief Completions for enum tags should be included in the results.
4628 */
4629 CXCompletionContext_EnumTag = 1 << 8,
4630 /**
4631 * \brief Completions for union tags should be included in the results.
4632 */
4633 CXCompletionContext_UnionTag = 1 << 9,
4634 /**
4635 * \brief Completions for struct tags should be included in the results.
4636 */
4637 CXCompletionContext_StructTag = 1 << 10,
4638
4639 /**
4640 * \brief Completions for C++ class names should be included in the results.
4641 */
4642 CXCompletionContext_ClassTag = 1 << 11,
4643 /**
4644 * \brief Completions for C++ namespaces and namespace aliases should be
4645 * included in the results.
4646 */
4647 CXCompletionContext_Namespace = 1 << 12,
4648 /**
4649 * \brief Completions for C++ nested name specifiers should be included in
4650 * the results.
4651 */
4652 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4653
4654 /**
4655 * \brief Completions for Objective-C interfaces (classes) should be included
4656 * in the results.
4657 */
4658 CXCompletionContext_ObjCInterface = 1 << 14,
4659 /**
4660 * \brief Completions for Objective-C protocols should be included in
4661 * the results.
4662 */
4663 CXCompletionContext_ObjCProtocol = 1 << 15,
4664 /**
4665 * \brief Completions for Objective-C categories should be included in
4666 * the results.
4667 */
4668 CXCompletionContext_ObjCCategory = 1 << 16,
4669 /**
4670 * \brief Completions for Objective-C instance messages should be included
4671 * in the results.
4672 */
4673 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4674 /**
4675 * \brief Completions for Objective-C class messages should be included in
4676 * the results.
4677 */
4678 CXCompletionContext_ObjCClassMessage = 1 << 18,
4679 /**
4680 * \brief Completions for Objective-C selector names should be included in
4681 * the results.
4682 */
4683 CXCompletionContext_ObjCSelectorName = 1 << 19,
4684
4685 /**
4686 * \brief Completions for preprocessor macro names should be included in
4687 * the results.
4688 */
4689 CXCompletionContext_MacroName = 1 << 20,
4690
4691 /**
4692 * \brief Natural language completions should be included in the results.
4693 */
4694 CXCompletionContext_NaturalLanguage = 1 << 21,
4695
4696 /**
4697 * \brief The current context is unknown, so set all contexts.
4698 */
4699 CXCompletionContext_Unknown = ((1 << 22) - 1)
4700};
4701
4702/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00004703 * \brief Returns a default set of code-completion options that can be
4704 * passed to\c clang_codeCompleteAt().
4705 */
4706CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4707
4708/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004709 * \brief Perform code completion at a given location in a translation unit.
4710 *
4711 * This function performs code completion at a particular file, line, and
4712 * column within source code, providing results that suggest potential
4713 * code snippets based on the context of the completion. The basic model
4714 * for code completion is that Clang will parse a complete source file,
4715 * performing syntax checking up to the location where code-completion has
4716 * been requested. At that point, a special code-completion token is passed
4717 * to the parser, which recognizes this token and determines, based on the
4718 * current location in the C/Objective-C/C++ grammar and the state of
4719 * semantic analysis, what completions to provide. These completions are
4720 * returned via a new \c CXCodeCompleteResults structure.
4721 *
4722 * Code completion itself is meant to be triggered by the client when the
4723 * user types punctuation characters or whitespace, at which point the
4724 * code-completion location will coincide with the cursor. For example, if \c p
4725 * is a pointer, code-completion might be triggered after the "-" and then
4726 * after the ">" in \c p->. When the code-completion location is afer the ">",
4727 * the completion results will provide, e.g., the members of the struct that
4728 * "p" points to. The client is responsible for placing the cursor at the
4729 * beginning of the token currently being typed, then filtering the results
4730 * based on the contents of the token. For example, when code-completing for
4731 * the expression \c p->get, the client should provide the location just after
4732 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4733 * client can filter the results based on the current token text ("get"), only
4734 * showing those results that start with "get". The intent of this interface
4735 * is to separate the relatively high-latency acquisition of code-completion
4736 * results from the filtering of results on a per-character basis, which must
4737 * have a lower latency.
4738 *
4739 * \param TU The translation unit in which code-completion should
4740 * occur. The source files for this translation unit need not be
4741 * completely up-to-date (and the contents of those source files may
4742 * be overridden via \p unsaved_files). Cursors referring into the
4743 * translation unit may be invalidated by this invocation.
4744 *
4745 * \param complete_filename The name of the source file where code
4746 * completion should be performed. This filename may be any file
4747 * included in the translation unit.
4748 *
4749 * \param complete_line The line at which code-completion should occur.
4750 *
4751 * \param complete_column The column at which code-completion should occur.
4752 * Note that the column should point just after the syntactic construct that
4753 * initiated code completion, and not in the middle of a lexical token.
4754 *
4755 * \param unsaved_files the Tiles that have not yet been saved to disk
4756 * but may be required for parsing or code completion, including the
4757 * contents of those files. The contents and name of these files (as
4758 * specified by CXUnsavedFile) are copied when necessary, so the
4759 * client only needs to guarantee their validity until the call to
4760 * this function returns.
4761 *
4762 * \param num_unsaved_files The number of unsaved file entries in \p
4763 * unsaved_files.
4764 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00004765 * \param options Extra options that control the behavior of code
4766 * completion, expressed as a bitwise OR of the enumerators of the
4767 * CXCodeComplete_Flags enumeration. The
4768 * \c clang_defaultCodeCompleteOptions() function returns a default set
4769 * of code-completion options.
4770 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004771 * \returns If successful, a new \c CXCodeCompleteResults structure
4772 * containing code-completion results, which should eventually be
4773 * freed with \c clang_disposeCodeCompleteResults(). If code
4774 * completion fails, returns NULL.
4775 */
4776CINDEX_LINKAGE
4777CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4778 const char *complete_filename,
4779 unsigned complete_line,
4780 unsigned complete_column,
4781 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00004782 unsigned num_unsaved_files,
4783 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00004784
4785/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00004786 * \brief Sort the code-completion results in case-insensitive alphabetical
4787 * order.
4788 *
4789 * \param Results The set of results to sort.
4790 * \param NumResults The number of results in \p Results.
4791 */
4792CINDEX_LINKAGE
4793void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4794 unsigned NumResults);
4795
4796/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00004797 * \brief Free the given set of code-completion results.
4798 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004799CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00004800void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00004801
Douglas Gregor20d416c2010-01-20 01:10:47 +00004802/**
Douglas Gregora88084b2010-02-18 18:08:43 +00004803 * \brief Determine the number of diagnostics produced prior to the
4804 * location where code completion was performed.
4805 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004806CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004807unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4808
4809/**
4810 * \brief Retrieve a diagnostic associated with the given code completion.
4811 *
James Dennett7eee0182012-06-15 05:41:51 +00004812 * \param Results the code completion results to query.
Douglas Gregora88084b2010-02-18 18:08:43 +00004813 * \param Index the zero-based diagnostic number to retrieve.
4814 *
4815 * \returns the requested diagnostic. This diagnostic must be freed
4816 * via a call to \c clang_disposeDiagnostic().
4817 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00004818CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00004819CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4820 unsigned Index);
4821
4822/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004823 * \brief Determines what compeltions are appropriate for the context
4824 * the given code completion.
4825 *
4826 * \param Results the code completion results to query
4827 *
4828 * \returns the kinds of completions that are appropriate for use
4829 * along with the given code completion results.
4830 */
4831CINDEX_LINKAGE
4832unsigned long long clang_codeCompleteGetContexts(
4833 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00004834
4835/**
4836 * \brief Returns the cursor kind for the container for the current code
4837 * completion context. The container is only guaranteed to be set for
4838 * contexts where a container exists (i.e. member accesses or Objective-C
4839 * message sends); if there is not a container, this function will return
4840 * CXCursor_InvalidCode.
4841 *
4842 * \param Results the code completion results to query
4843 *
4844 * \param IsIncomplete on return, this value will be false if Clang has complete
4845 * information about the container. If Clang does not have complete
4846 * information, this value will be true.
4847 *
4848 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4849 * container
4850 */
4851CINDEX_LINKAGE
4852enum CXCursorKind clang_codeCompleteGetContainerKind(
4853 CXCodeCompleteResults *Results,
4854 unsigned *IsIncomplete);
4855
4856/**
4857 * \brief Returns the USR for the container for the current code completion
4858 * context. If there is not a container for the current context, this
4859 * function will return the empty string.
4860 *
4861 * \param Results the code completion results to query
4862 *
4863 * \returns the USR for the container
4864 */
4865CINDEX_LINKAGE
4866CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00004867
Douglas Gregor0a47d692011-07-26 15:24:30 +00004868
4869/**
4870 * \brief Returns the currently-entered selector for an Objective-C message
4871 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4872 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4873 * CXCompletionContext_ObjCClassMessage.
4874 *
4875 * \param Results the code completion results to query
4876 *
4877 * \returns the selector (or partial selector) that has been entered thus far
4878 * for an Objective-C message send.
4879 */
4880CINDEX_LINKAGE
4881CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4882
Douglas Gregor3da626b2011-07-07 16:03:39 +00004883/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00004884 * @}
4885 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004886
4887
Ted Kremenek04bb7162010-01-22 22:44:15 +00004888/**
4889 * \defgroup CINDEX_MISC Miscellaneous utility functions
4890 *
4891 * @{
4892 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00004893
4894/**
4895 * \brief Return a version string, suitable for showing to a user, but not
4896 * intended to be parsed (the format is not guaranteed to be stable).
4897 */
NAKAMURA Takumif9c21662013-01-10 02:12:38 +00004898CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenek04bb7162010-01-22 22:44:15 +00004899
Ted Kremenekd2427dd2011-03-18 23:05:39 +00004900
4901/**
4902 * \brief Enable/disable crash recovery.
4903 *
James Dennett7eee0182012-06-15 05:41:51 +00004904 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
4905 * value enables crash recovery, while 0 disables it.
Ted Kremenekd2427dd2011-03-18 23:05:39 +00004906 */
4907CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4908
Ted Kremenek16b55a72010-01-26 19:31:51 +00004909 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00004910 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00004911 * (used with clang_getInclusions()).
4912 *
4913 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett7eee0182012-06-15 05:41:51 +00004914 * file included (either at the top-level or by \#include directives) within
Ted Kremenek16b55a72010-01-26 19:31:51 +00004915 * a translation unit. The first argument is the file being included, and
4916 * the second and third arguments provide the inclusion stack. The
4917 * array is sorted in order of immediate inclusion. For example,
4918 * the first element refers to the location that included 'included_file'.
4919 */
4920typedef void (*CXInclusionVisitor)(CXFile included_file,
4921 CXSourceLocation* inclusion_stack,
4922 unsigned include_len,
4923 CXClientData client_data);
4924
4925/**
4926 * \brief Visit the set of preprocessor inclusions in a translation unit.
4927 * The visitor function is called with the provided data for every included
4928 * file. This does not include headers included by the PCH file (unless one
4929 * is inspecting the inclusions in the PCH file itself).
4930 */
4931CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4932 CXInclusionVisitor visitor,
4933 CXClientData client_data);
4934
4935/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00004936 * @}
4937 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004938
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004939/** \defgroup CINDEX_REMAPPING Remapping functions
4940 *
4941 * @{
4942 */
4943
4944/**
4945 * \brief A remapping of original source files and their translated files.
4946 */
4947typedef void *CXRemapping;
4948
4949/**
4950 * \brief Retrieve a remapping.
4951 *
4952 * \param path the path that contains metadata about remappings.
4953 *
4954 * \returns the requested remapping. This remapping must be freed
4955 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4956 */
4957CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4958
4959/**
Ted Kremenek30660a82012-03-06 20:06:33 +00004960 * \brief Retrieve a remapping.
4961 *
4962 * \param filePaths pointer to an array of file paths containing remapping info.
4963 *
4964 * \param numFiles number of file paths.
4965 *
4966 * \returns the requested remapping. This remapping must be freed
4967 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4968 */
4969CINDEX_LINKAGE
4970CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
4971 unsigned numFiles);
4972
4973/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004974 * \brief Determine the number of remappings.
4975 */
4976CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4977
4978/**
4979 * \brief Get the original and the associated filename from the remapping.
4980 *
4981 * \param original If non-NULL, will be set to the original filename.
4982 *
4983 * \param transformed If non-NULL, will be set to the filename that the original
4984 * is associated with.
4985 */
4986CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4987 CXString *original, CXString *transformed);
4988
4989/**
4990 * \brief Dispose the remapping.
4991 */
4992CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4993
4994/**
4995 * @}
4996 */
4997
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004998/** \defgroup CINDEX_HIGH Higher level API functions
4999 *
5000 * @{
5001 */
5002
5003enum CXVisitorResult {
5004 CXVisit_Break,
5005 CXVisit_Continue
5006};
5007
5008typedef struct {
5009 void *context;
5010 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5011} CXCursorAndRangeVisitor;
5012
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005013typedef enum {
5014 /**
5015 * \brief Function returned successfully.
5016 */
5017 CXResult_Success = 0,
5018 /**
5019 * \brief One of the parameters was invalid for the function.
5020 */
5021 CXResult_Invalid = 1,
5022 /**
5023 * \brief The function was terminated by a callback (e.g. it returned
5024 * CXVisit_Break)
5025 */
5026 CXResult_VisitBreak = 2
5027
5028} CXResult;
5029
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005030/**
5031 * \brief Find references of a declaration in a specific file.
5032 *
5033 * \param cursor pointing to a declaration or a reference of one.
5034 *
5035 * \param file to search for references.
5036 *
5037 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5038 * each reference found.
5039 * The CXSourceRange will point inside the file; if the reference is inside
5040 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis389dc562013-03-08 20:42:33 +00005041 *
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005042 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005043 */
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005044CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5045 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005046
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005047/**
5048 * \brief Find #import/#include directives in a specific file.
5049 *
5050 * \param TU translation unit containing the file to query.
5051 *
5052 * \param file to search for #import/#include directives.
5053 *
5054 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5055 * each directive found.
Argyrios Kyrtzidis389dc562013-03-08 20:42:33 +00005056 *
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005057 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005058 */
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005059CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5060 CXFile file,
5061 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005062
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005063#ifdef __has_feature
5064# if __has_feature(blocks)
5065
5066typedef enum CXVisitorResult
5067 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5068
5069CINDEX_LINKAGE
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005070CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5071 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005072
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005073CINDEX_LINKAGE
Argyrios Kyrtzidis6f09c3d2013-03-08 22:47:41 +00005074CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5075 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidisee2d5fd2013-03-08 02:32:34 +00005076
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005077# endif
5078#endif
5079
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005080/**
5081 * \brief The client's data object that is associated with a CXFile.
5082 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005083typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005084
5085/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005086 * \brief The client's data object that is associated with a semantic entity.
5087 */
5088typedef void *CXIdxClientEntity;
5089
5090/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005091 * \brief The client's data object that is associated with a semantic container
5092 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005093 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005094typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005095
5096/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005097 * \brief The client's data object that is associated with an AST file (PCH
5098 * or module).
5099 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005100typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005101
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005102/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005103 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005104 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005105typedef struct {
5106 void *ptr_data[2];
5107 unsigned int_data;
5108} CXIdxLoc;
5109
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005110/**
James Dennett7eee0182012-06-15 05:41:51 +00005111 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005112 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005113typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005114 /**
James Dennett7eee0182012-06-15 05:41:51 +00005115 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005116 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005117 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005118 /**
James Dennett7eee0182012-06-15 05:41:51 +00005119 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005120 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005121 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005122 /**
James Dennett7eee0182012-06-15 05:41:51 +00005123 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005124 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005125 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005126 int isImport;
5127 int isAngled;
Argyrios Kyrtzidis8d7a24e2012-10-18 00:17:05 +00005128 /**
5129 * \brief Non-zero if the directive was automatically turned into a module
5130 * import.
5131 */
5132 int isModuleImport;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005133} CXIdxIncludedFileInfo;
5134
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005135/**
James Dennett7eee0182012-06-15 05:41:51 +00005136 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005137 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005138typedef struct {
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005139 /**
5140 * \brief Top level AST file containing the imported PCH, module or submodule.
5141 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005142 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005143 /**
Argyrios Kyrtzidis134d1e8a2012-10-05 00:22:40 +00005144 * \brief The imported module or NULL if the AST file is a PCH.
5145 */
5146 CXModule module;
5147 /**
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005148 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005149 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005150 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005151 /**
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005152 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidis134d1e8a2012-10-05 00:22:40 +00005153 * a module import. Applicable only for modules.
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005154 */
Argyrios Kyrtzidis37f2f522012-10-03 21:05:44 +00005155 int isImplicit;
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005156
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005157} CXIdxImportedASTFileInfo;
5158
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005159typedef enum {
5160 CXIdxEntity_Unexposed = 0,
5161 CXIdxEntity_Typedef = 1,
5162 CXIdxEntity_Function = 2,
5163 CXIdxEntity_Variable = 3,
5164 CXIdxEntity_Field = 4,
5165 CXIdxEntity_EnumConstant = 5,
5166
5167 CXIdxEntity_ObjCClass = 6,
5168 CXIdxEntity_ObjCProtocol = 7,
5169 CXIdxEntity_ObjCCategory = 8,
5170
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005171 CXIdxEntity_ObjCInstanceMethod = 9,
5172 CXIdxEntity_ObjCClassMethod = 10,
5173 CXIdxEntity_ObjCProperty = 11,
5174 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005175
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005176 CXIdxEntity_Enum = 13,
5177 CXIdxEntity_Struct = 14,
5178 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005179
5180 CXIdxEntity_CXXClass = 16,
5181 CXIdxEntity_CXXNamespace = 17,
5182 CXIdxEntity_CXXNamespaceAlias = 18,
5183 CXIdxEntity_CXXStaticVariable = 19,
5184 CXIdxEntity_CXXStaticMethod = 20,
5185 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matos17d35c32012-08-31 22:18:20 +00005186 CXIdxEntity_CXXConstructor = 22,
5187 CXIdxEntity_CXXDestructor = 23,
5188 CXIdxEntity_CXXConversionFunction = 24,
5189 CXIdxEntity_CXXTypeAlias = 25,
5190 CXIdxEntity_CXXInterface = 26
5191
5192} CXIdxEntityKind;
5193
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00005194typedef enum {
5195 CXIdxEntityLang_None = 0,
5196 CXIdxEntityLang_C = 1,
5197 CXIdxEntityLang_ObjC = 2,
5198 CXIdxEntityLang_CXX = 3
5199} CXIdxEntityLanguage;
5200
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005201/**
5202 * \brief Extra C++ template information for an entity. This can apply to:
5203 * CXIdxEntity_Function
5204 * CXIdxEntity_CXXClass
5205 * CXIdxEntity_CXXStaticMethod
5206 * CXIdxEntity_CXXInstanceMethod
5207 * CXIdxEntity_CXXConstructor
5208 * CXIdxEntity_CXXConversionFunction
5209 * CXIdxEntity_CXXTypeAlias
5210 */
5211typedef enum {
5212 CXIdxEntity_NonTemplate = 0,
5213 CXIdxEntity_Template = 1,
5214 CXIdxEntity_TemplatePartialSpecialization = 2,
5215 CXIdxEntity_TemplateSpecialization = 3
5216} CXIdxEntityCXXTemplateKind;
5217
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005218typedef enum {
5219 CXIdxAttr_Unexposed = 0,
5220 CXIdxAttr_IBAction = 1,
5221 CXIdxAttr_IBOutlet = 2,
5222 CXIdxAttr_IBOutletCollection = 3
5223} CXIdxAttrKind;
5224
5225typedef struct {
5226 CXIdxAttrKind kind;
5227 CXCursor cursor;
5228 CXIdxLoc loc;
5229} CXIdxAttrInfo;
5230
5231typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00005232 CXIdxEntityKind kind;
5233 CXIdxEntityCXXTemplateKind templateKind;
5234 CXIdxEntityLanguage lang;
5235 const char *name;
5236 const char *USR;
5237 CXCursor cursor;
5238 const CXIdxAttrInfo *const *attributes;
5239 unsigned numAttributes;
5240} CXIdxEntityInfo;
5241
5242typedef struct {
5243 CXCursor cursor;
5244} CXIdxContainerInfo;
5245
5246typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005247 const CXIdxAttrInfo *attrInfo;
5248 const CXIdxEntityInfo *objcClass;
5249 CXCursor classCursor;
5250 CXIdxLoc classLoc;
5251} CXIdxIBOutletCollectionAttrInfo;
5252
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005253typedef enum {
5254 CXIdxDeclFlag_Skipped = 0x1
5255} CXIdxDeclInfoFlags;
5256
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005257typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005258 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005259 CXCursor cursor;
5260 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005261 const CXIdxContainerInfo *semanticContainer;
5262 /**
James Dennett7eee0182012-06-15 05:41:51 +00005263 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005264 * cases like out-of-line C++ member functions.
5265 */
5266 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005267 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005268 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005269 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005270 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005271 /**
5272 * \brief Whether the declaration exists in code or was created implicitly
5273 * by the compiler, e.g. implicit objc methods for properties.
5274 */
5275 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005276 const CXIdxAttrInfo *const *attributes;
5277 unsigned numAttributes;
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005278
5279 unsigned flags;
5280
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005281} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005282
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005283typedef enum {
5284 CXIdxObjCContainer_ForwardRef = 0,
5285 CXIdxObjCContainer_Interface = 1,
5286 CXIdxObjCContainer_Implementation = 2
5287} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005288
5289typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005290 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005291 CXIdxObjCContainerKind kind;
5292} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005293
5294typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005295 const CXIdxEntityInfo *base;
5296 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005297 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005298} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005299
5300typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005301 const CXIdxEntityInfo *protocol;
5302 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005303 CXIdxLoc loc;
5304} CXIdxObjCProtocolRefInfo;
5305
5306typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005307 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005308 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005309} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005310
5311typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005312 const CXIdxObjCContainerDeclInfo *containerInfo;
5313 const CXIdxBaseClassInfo *superInfo;
5314 const CXIdxObjCProtocolRefListInfo *protocols;
5315} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005316
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005317typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00005318 const CXIdxObjCContainerDeclInfo *containerInfo;
5319 const CXIdxEntityInfo *objcClass;
5320 CXCursor classCursor;
5321 CXIdxLoc classLoc;
5322 const CXIdxObjCProtocolRefListInfo *protocols;
5323} CXIdxObjCCategoryDeclInfo;
5324
5325typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005326 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00005327 const CXIdxEntityInfo *getter;
5328 const CXIdxEntityInfo *setter;
5329} CXIdxObjCPropertyDeclInfo;
5330
5331typedef struct {
5332 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005333 const CXIdxBaseClassInfo *const *bases;
5334 unsigned numBases;
5335} CXIdxCXXClassDeclInfo;
5336
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005337/**
James Dennett7eee0182012-06-15 05:41:51 +00005338 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005339 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005340typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005341 /**
5342 * \brief The entity is referenced directly in user's code.
5343 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005344 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005345 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005346 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5347 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005348 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005349 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00005350} CXIdxEntityRefKind;
5351
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005352/**
James Dennett7eee0182012-06-15 05:41:51 +00005353 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005354 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005355typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00005356 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005357 /**
5358 * \brief Reference cursor.
5359 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005360 CXCursor cursor;
5361 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005362 /**
5363 * \brief The entity that gets referenced.
5364 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005365 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005366 /**
5367 * \brief Immediate "parent" of the reference. For example:
5368 *
5369 * \code
5370 * Foo *var;
5371 * \endcode
5372 *
5373 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00005374 * For references inside statement bodies of functions/methods,
5375 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005376 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005377 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005378 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00005379 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005380 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005381 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005382} CXIdxEntityRefInfo;
5383
James Dennett7eee0182012-06-15 05:41:51 +00005384/**
5385 * \brief A group of callbacks used by #clang_indexSourceFile and
5386 * #clang_indexTranslationUnit.
5387 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005388typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005389 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005390 * \brief Called periodically to check whether indexing should be aborted.
5391 * Should return 0 to continue, and non-zero to abort.
5392 */
5393 int (*abortQuery)(CXClientData client_data, void *reserved);
5394
5395 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005396 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005397 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005398 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005399 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005400
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005401 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett7eee0182012-06-15 05:41:51 +00005402 CXFile mainFile, void *reserved);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005403
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005404 /**
James Dennett7eee0182012-06-15 05:41:51 +00005405 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005406 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005407 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005408 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005409
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005410 /**
5411 * \brief Called when a AST file (PCH or module) gets imported.
5412 *
5413 * AST files will not get indexed (there will not be callbacks to index all
5414 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis2c3e05c2012-10-02 16:10:38 +00005415 * file is not already indexed, to initiate a new indexing job specific to
5416 * the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005417 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005418 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005419 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005420
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005421 /**
5422 * \brief Called at the beginning of indexing a translation unit.
5423 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005424 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005425 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005426
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005427 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005428 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005429
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005430 /**
5431 * \brief Called to index a reference of an entity.
5432 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005433 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005434 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005435
5436} IndexerCallbacks;
5437
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00005438CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005439CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5440clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005441
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005442CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5443clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5444
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00005445CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00005446const CXIdxObjCCategoryDeclInfo *
5447clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5448
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00005449CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5450clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005451
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00005452CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5453clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5454
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00005455CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5456clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5457
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005458CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5459clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5460
5461/**
5462 * \brief For retrieving a custom CXIdxClientContainer attached to a
5463 * container.
5464 */
5465CINDEX_LINKAGE CXIdxClientContainer
5466clang_index_getClientContainer(const CXIdxContainerInfo *);
5467
5468/**
5469 * \brief For setting a custom CXIdxClientContainer attached to a
5470 * container.
5471 */
5472CINDEX_LINKAGE void
5473clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5474
5475/**
5476 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5477 */
5478CINDEX_LINKAGE CXIdxClientEntity
5479clang_index_getClientEntity(const CXIdxEntityInfo *);
5480
5481/**
5482 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5483 */
5484CINDEX_LINKAGE void
5485clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5486
5487/**
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005488 * \brief An indexing action/session, to be applied to one or multiple
5489 * translation units.
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005490 */
5491typedef void *CXIndexAction;
5492
5493/**
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005494 * \brief An indexing action/session, to be applied to one or multiple
5495 * translation units.
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005496 *
5497 * \param CIdx The index object with which the index action will be associated.
5498 */
5499CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5500
5501/**
5502 * \brief Destroy the given index action.
5503 *
5504 * The index action must not be destroyed until all of the translation units
5505 * created within that index action have been destroyed.
5506 */
5507CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5508
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005509typedef enum {
5510 /**
5511 * \brief Used to indicate that no special indexing options are needed.
5512 */
5513 CXIndexOpt_None = 0x0,
5514
5515 /**
James Dennett7eee0182012-06-15 05:41:51 +00005516 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5517 * be invoked for only one reference of an entity per source file that does
5518 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005519 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00005520 CXIndexOpt_SuppressRedundantRefs = 0x1,
5521
5522 /**
5523 * \brief Function-local symbols should be indexed. If this is not set
5524 * function-local symbols will be ignored.
5525 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00005526 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5527
5528 /**
5529 * \brief Implicit function/class template instantiations should be indexed.
5530 * If this is not set, implicit instantiations will be ignored.
5531 */
Argyrios Kyrtzidisb49a29f2012-03-27 21:38:03 +00005532 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5533
5534 /**
5535 * \brief Suppress all compiler warnings when parsing for indexing.
5536 */
Argyrios Kyrtzidis838eb7e2012-12-06 19:41:16 +00005537 CXIndexOpt_SuppressWarnings = 0x8,
5538
5539 /**
5540 * \brief Skip a function/method body that was already parsed during an
5541 * indexing session assosiated with a \c CXIndexAction object.
5542 * Bodies in system headers are always skipped.
5543 */
5544 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5545
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005546} CXIndexOptFlags;
5547
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005548/**
5549 * \brief Index the given source file and the translation unit corresponding
James Dennett7eee0182012-06-15 05:41:51 +00005550 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005551 *
5552 * \param client_data pointer data supplied by the client, which will
5553 * be passed to the invoked callbacks.
5554 *
5555 * \param index_callbacks Pointer to indexing callbacks that the client
5556 * implements.
5557 *
James Dennett7eee0182012-06-15 05:41:51 +00005558 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005559 * passed in index_callbacks.
5560 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005561 * \param index_options A bitmask of options that affects how indexing is
5562 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005563 *
5564 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
5565 * after indexing is finished. Set to NULL if you do not require it.
5566 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005567 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005568 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005569 *
James Dennett7eee0182012-06-15 05:41:51 +00005570 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005571 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005572CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005573 CXClientData client_data,
5574 IndexerCallbacks *index_callbacks,
5575 unsigned index_callbacks_size,
5576 unsigned index_options,
5577 const char *source_filename,
5578 const char * const *command_line_args,
5579 int num_command_line_args,
5580 struct CXUnsavedFile *unsaved_files,
5581 unsigned num_unsaved_files,
5582 CXTranslationUnit *out_TU,
5583 unsigned TU_options);
5584
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005585/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005586 * \brief Index the given translation unit via callbacks implemented through
James Dennett7eee0182012-06-15 05:41:51 +00005587 * #IndexerCallbacks.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005588 *
5589 * The order of callback invocations is not guaranteed to be the same as
5590 * when indexing a source file. The high level order will be:
5591 *
5592 * -Preprocessor callbacks invocations
5593 * -Declaration/reference callbacks invocations
5594 * -Diagnostic callback invocations
5595 *
James Dennett7eee0182012-06-15 05:41:51 +00005596 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005597 *
5598 * \returns If there is a failure from which the there is no recovery, returns
5599 * non-zero, otherwise returns 0.
5600 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005601CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005602 CXClientData client_data,
5603 IndexerCallbacks *index_callbacks,
5604 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00005605 unsigned index_options,
5606 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00005607
5608/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005609 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5610 * the given CXIdxLoc.
5611 *
5612 * If the location refers into a macro expansion, retrieves the
5613 * location of the macro expansion and if it refers into a macro argument
5614 * retrieves the location of the argument.
5615 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005616CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00005617 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005618 CXFile *file,
5619 unsigned *line,
5620 unsigned *column,
5621 unsigned *offset);
5622
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00005623/**
5624 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5625 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00005626CINDEX_LINKAGE
5627CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5628
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00005629/**
5630 * @}
5631 */
5632
Douglas Gregorc42fefa2010-01-22 22:29:16 +00005633/**
5634 * @}
5635 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00005636
Ted Kremenekd2fa5662009-08-26 22:36:44 +00005637#ifdef __cplusplus
5638}
5639#endif
5640#endif
5641