blob: d43c2d619aac63dfac05f81d8c0faea09f08576a [file] [log] [blame]
Ted Kremenekb60d87c2009-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
Chandler Carruthaacafe52009-12-17 09:27:29 +000019#include <time.h>
Steve Naroff6231f182009-10-27 14:35:18 +000020
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000021#include "clang-c/Platform.h"
22#include "clang-c/CXString.h"
23
Argyrios Kyrtzidis1c4db8d2012-11-06 21:21:49 +000024/**
25 * \brief The version constants for the libclang API.
26 * CINDEX_VERSION_MINOR should increase when there are API additions.
27 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
28 *
29 * The policy about the libclang API was always to keep it source and ABI
30 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
31 */
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000032#define CINDEX_VERSION_MAJOR 0
Stefanus Du Toitdb51c632013-08-08 17:48:14 +000033#define CINDEX_VERSION_MINOR 20
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000034
35#define CINDEX_VERSION_ENCODE(major, minor) ( \
36 ((major) * 10000) \
37 + ((minor) * 1))
38
39#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
40 CINDEX_VERSION_MAJOR, \
41 CINDEX_VERSION_MINOR )
42
43#define CINDEX_VERSION_STRINGIZE_(major, minor) \
44 #major"."#minor
45#define CINDEX_VERSION_STRINGIZE(major, minor) \
46 CINDEX_VERSION_STRINGIZE_(major, minor)
47
48#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
49 CINDEX_VERSION_MAJOR, \
50 CINDEX_VERSION_MINOR)
51
Ted Kremenekb60d87c2009-08-26 22:36:44 +000052#ifdef __cplusplus
53extern "C" {
54#endif
55
Douglas Gregor4a4e0eb2011-02-23 17:45:25 +000056/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor52606ff2010-01-20 01:10:47 +000057 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000058 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorc8e390c2010-01-20 22:45:41 +000059 * facilities for parsing source code into an abstract syntax tree (AST),
60 * loading already-parsed ASTs, traversing the AST, associating
61 * physical source locations with elements within the AST, and other
62 * facilities that support Clang-based development tools.
Douglas Gregor52606ff2010-01-20 01:10:47 +000063 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000064 * This C interface to Clang will never provide all of the information
Douglas Gregorc8e390c2010-01-20 22:45:41 +000065 * representation stored in Clang's C++ AST, nor should it: the intent is to
66 * maintain an API that is relatively stable from one release to the next,
67 * providing only the basic functionality needed to support development tools.
Daniel Dunbar62ebf252010-01-24 02:54:26 +000068 *
69 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorc8e390c2010-01-20 22:45:41 +000070 * functions are prefixed with "clang_".
Douglas Gregor52606ff2010-01-20 01:10:47 +000071 *
72 * @{
73 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +000074
Douglas Gregor802f12f2010-01-20 22:28:27 +000075/**
76 * \brief An "index" that consists of a set of translation units that would
77 * typically be linked together into an executable or library.
78 */
79typedef void *CXIndex;
Steve Naroffd5e8e862009-08-27 19:51:58 +000080
Douglas Gregor802f12f2010-01-20 22:28:27 +000081/**
82 * \brief A single translation unit, which resides in an index.
83 */
Ted Kremenek7df92ae2010-11-17 23:24:11 +000084typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroffd5e8e862009-08-27 19:51:58 +000085
Douglas Gregor802f12f2010-01-20 22:28:27 +000086/**
Douglas Gregor6007cf22010-01-22 22:29:16 +000087 * \brief Opaque pointer representing client data that will be passed through
88 * to various callbacks and visitors.
Douglas Gregor802f12f2010-01-20 22:28:27 +000089 */
Douglas Gregor6007cf22010-01-22 22:29:16 +000090typedef void *CXClientData;
Daniel Dunbar62ebf252010-01-24 02:54:26 +000091
Douglas Gregor9485bf92009-12-02 09:21:34 +000092/**
93 * \brief Provides the contents of a file that has not yet been saved to disk.
94 *
95 * Each CXUnsavedFile instance provides the name of a file on the
96 * system along with the current contents of that file that have not
97 * yet been saved to disk.
98 */
99struct CXUnsavedFile {
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000100 /**
101 * \brief The file whose contents have not yet been saved.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000102 *
103 * This file must already exist in the file system.
104 */
105 const char *Filename;
106
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000107 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000108 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000109 */
110 const char *Contents;
111
112 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000113 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000114 */
115 unsigned long Length;
116};
117
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000118/**
119 * \brief Describes the availability of a particular entity, which indicates
120 * whether the use of this entity will result in a warning or error due to
121 * it being deprecated or unavailable.
122 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000123enum CXAvailabilityKind {
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000124 /**
125 * \brief The entity is available.
126 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000127 CXAvailability_Available,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000128 /**
129 * \brief The entity is available, but has been deprecated (and its use is
130 * not recommended).
131 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000132 CXAvailability_Deprecated,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000133 /**
134 * \brief The entity is not available; any use of it will be an error.
135 */
Erik Verbruggen2e657ff2011-10-06 07:27:49 +0000136 CXAvailability_NotAvailable,
137 /**
138 * \brief The entity is available, but not accessible; any use of it will be
139 * an error.
140 */
141 CXAvailability_NotAccessible
Douglas Gregorf757a122010-08-23 23:00:57 +0000142};
Douglas Gregord6225d32012-05-08 00:14:45 +0000143
144/**
145 * \brief Describes a version number of the form major.minor.subminor.
146 */
147typedef struct CXVersion {
148 /**
149 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
150 * value indicates that there is no version number at all.
151 */
152 int Major;
153 /**
154 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
155 * will be negative if no minor version number was provided, e.g., for
156 * version '10'.
157 */
158 int Minor;
159 /**
160 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
161 * will be negative if no minor or subminor version number was provided,
162 * e.g., in version '10' or '10.7'.
163 */
164 int Subminor;
165} CXVersion;
Douglas Gregorf757a122010-08-23 23:00:57 +0000166
Douglas Gregor802f12f2010-01-20 22:28:27 +0000167/**
James Dennett574cb4c2012-06-15 05:41:51 +0000168 * \brief Provides a shared context for creating translation units.
169 *
170 * It provides two options:
Steve Naroff531e2842009-10-20 14:46:24 +0000171 *
172 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
173 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000174 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroff531e2842009-10-20 14:46:24 +0000175 * header that was used by the translation unit. If zero, all declarations
176 * will be enumerated.
177 *
Steve Naroffbb4568a2009-10-20 16:36:34 +0000178 * Here is an example:
179 *
James Dennett574cb4c2012-06-15 05:41:51 +0000180 * \code
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000181 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
182 * Idx = clang_createIndex(1, 1);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000183 *
184 * // IndexTest.pch was produced with the following command:
185 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
186 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
187 *
188 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000189 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor990b5762010-01-20 21:37:00 +0000190 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000191 * clang_disposeTranslationUnit(TU);
192 *
193 * // This will load all the symbols from 'IndexTest.c', excluding symbols
194 * // from 'IndexTest.pch'.
Daniel Dunbard0159262010-01-25 00:43:14 +0000195 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
196 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
197 * 0, 0);
Douglas Gregorfed36b12010-01-20 23:57:43 +0000198 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
199 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000200 * clang_disposeTranslationUnit(TU);
James Dennett574cb4c2012-06-15 05:41:51 +0000201 * \endcode
Steve Naroffbb4568a2009-10-20 16:36:34 +0000202 *
203 * This process of creating the 'pch', loading it separately, and using it (via
204 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
205 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroff531e2842009-10-20 14:46:24 +0000206 */
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000207CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
208 int displayDiagnostics);
Ted Kremenekd071c602010-03-13 02:50:34 +0000209
Douglas Gregor408bb742010-02-08 23:03:06 +0000210/**
211 * \brief Destroy the given index.
212 *
213 * The index must not be destroyed until all of the translation units created
214 * within that index have been destroyed.
215 */
Daniel Dunbar11089662009-12-03 01:54:28 +0000216CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000217
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000218typedef enum {
219 /**
220 * \brief Used to indicate that no special CXIndex options are needed.
221 */
222 CXGlobalOpt_None = 0x0,
223
224 /**
225 * \brief Used to indicate that threads that libclang creates for indexing
226 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000227 *
228 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
229 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000230 */
231 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
232
233 /**
234 * \brief Used to indicate that threads that libclang creates for editing
235 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000236 *
237 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
238 * #clang_annotateTokens
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000239 */
240 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
241
242 /**
243 * \brief Used to indicate that all threads that libclang creates should use
244 * background priority.
245 */
246 CXGlobalOpt_ThreadBackgroundPriorityForAll =
247 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
248 CXGlobalOpt_ThreadBackgroundPriorityForEditing
249
250} CXGlobalOptFlags;
251
252/**
James Dennett574cb4c2012-06-15 05:41:51 +0000253 * \brief Sets general options associated with a CXIndex.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000254 *
255 * For example:
256 * \code
257 * CXIndex idx = ...;
258 * clang_CXIndex_setGlobalOptions(idx,
259 * clang_CXIndex_getGlobalOptions(idx) |
260 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
261 * \endcode
262 *
263 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
264 */
265CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
266
267/**
268 * \brief Gets the general options associated with a CXIndex.
269 *
270 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
271 * are associated with the given CXIndex object.
272 */
273CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
274
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000275/**
Douglas Gregor6007cf22010-01-22 22:29:16 +0000276 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000277 *
278 * @{
279 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000280
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000281/**
282 * \brief A particular source file that is part of a translation unit.
283 */
284typedef void *CXFile;
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000285
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000286
287/**
288 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff6231f182009-10-27 14:35:18 +0000289 */
Ted Kremenekc560b682010-02-17 00:41:20 +0000290CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000291
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000292/**
293 * \brief Retrieve the last modification time of the given file.
294 */
Douglas Gregor249c1212009-10-31 15:48:08 +0000295CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff6231f182009-10-27 14:35:18 +0000296
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000297/**
Argyrios Kyrtzidisac08b262013-01-26 04:52:52 +0000298 * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
299 * across an indexing session.
300 */
301typedef struct {
302 unsigned long long data[3];
303} CXFileUniqueID;
304
305/**
306 * \brief Retrieve the unique ID for the given \c file.
307 *
308 * \param file the file to get the ID for.
309 * \param outID stores the returned CXFileUniqueID.
310 * \returns If there was a failure getting the unique ID, returns non-zero,
311 * otherwise returns 0.
312*/
313CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
314
315/**
Douglas Gregor37aa4932011-05-04 00:14:37 +0000316 * \brief Determine whether the given header is guarded against
317 * multiple inclusions, either with the conventional
James Dennett574cb4c2012-06-15 05:41:51 +0000318 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
Douglas Gregor37aa4932011-05-04 00:14:37 +0000319 */
320CINDEX_LINKAGE unsigned
321clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
322
323/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000324 * \brief Retrieve a file handle within the given translation unit.
325 *
326 * \param tu the translation unit
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000327 *
Douglas Gregor816fd362010-01-22 21:44:22 +0000328 * \param file_name the name of the file.
329 *
330 * \returns the file handle for the named file in the translation unit \p tu,
331 * or a NULL file handle if the file was not a part of this translation unit.
332 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000333CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregor816fd362010-01-22 21:44:22 +0000334 const char *file_name);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000335
Douglas Gregor816fd362010-01-22 21:44:22 +0000336/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000337 * @}
338 */
339
340/**
341 * \defgroup CINDEX_LOCATIONS Physical source locations
342 *
343 * Clang represents physical source locations in its abstract syntax tree in
344 * great detail, with file, line, and column information for the majority of
345 * the tokens parsed in the source code. These data types and functions are
346 * used to represent source location information, either for a particular
347 * point in the program or for a range of points in the program, and extract
348 * specific location information from those data types.
349 *
350 * @{
351 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000352
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000353/**
Douglas Gregor4f46e782010-01-19 21:36:55 +0000354 * \brief Identifies a specific source location within a translation
355 * unit.
356 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000357 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregor229bebd2010-11-09 06:24:54 +0000358 * to map a source location to a particular file, line, and column.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000359 */
360typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000361 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000362 unsigned int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000363} CXSourceLocation;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000364
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000365/**
Daniel Dunbar02968e52010-02-14 10:02:57 +0000366 * \brief Identifies a half-open character range in the source code.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000367 *
Douglas Gregor4f46e782010-01-19 21:36:55 +0000368 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
369 * starting and end locations from a source range, respectively.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000370 */
371typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000372 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000373 unsigned begin_int_data;
374 unsigned end_int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000375} CXSourceRange;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000376
Douglas Gregor4f46e782010-01-19 21:36:55 +0000377/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000378 * \brief Retrieve a NULL (invalid) source location.
379 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000380CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000381
Douglas Gregor816fd362010-01-22 21:44:22 +0000382/**
James Dennett574cb4c2012-06-15 05:41:51 +0000383 * \brief Determine whether two source locations, which must refer into
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000384 * the same translation unit, refer to exactly the same point in the source
Douglas Gregor816fd362010-01-22 21:44:22 +0000385 * code.
386 *
387 * \returns non-zero if the source locations refer to the same location, zero
388 * if they refer to different locations.
389 */
390CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
391 CXSourceLocation loc2);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000392
Douglas Gregor816fd362010-01-22 21:44:22 +0000393/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000394 * \brief Retrieves the source location associated with a given file/line/column
395 * in a particular translation unit.
Douglas Gregor816fd362010-01-22 21:44:22 +0000396 */
397CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
398 CXFile file,
399 unsigned line,
400 unsigned column);
David Chisnall2e16ac52010-10-15 17:07:39 +0000401/**
402 * \brief Retrieves the source location associated with a given character offset
403 * in a particular translation unit.
404 */
405CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
406 CXFile file,
407 unsigned offset);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000408
Douglas Gregor816fd362010-01-22 21:44:22 +0000409/**
Argyrios Kyrtzidis25f7af12013-04-12 17:06:51 +0000410 * \brief Returns non-zero if the given source location is in a system header.
411 */
412CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
413
414/**
Stefanus Du Toitdb51c632013-08-08 17:48:14 +0000415 * \brief Returns non-zero if the given source location is in the main file of
416 * the corresponding translation unit.
417 */
418CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
419
420/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000421 * \brief Retrieve a NULL (invalid) source range.
422 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000423CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
Ted Kremenekd071c602010-03-13 02:50:34 +0000424
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000425/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000426 * \brief Retrieve a source range given the beginning and ending source
427 * locations.
428 */
429CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
430 CXSourceLocation end);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000431
Douglas Gregor816fd362010-01-22 21:44:22 +0000432/**
Douglas Gregor757e38b2011-07-23 19:35:14 +0000433 * \brief Determine whether two ranges are equivalent.
434 *
435 * \returns non-zero if the ranges are the same, zero if they differ.
436 */
437CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
438 CXSourceRange range2);
439
440/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +0000441 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000442 */
Erik Verbruggend610b0f2011-10-06 12:11:57 +0000443CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000444
445/**
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000446 * \brief Retrieve the file, line, column, and offset represented by
447 * the given source location.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000448 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000449 * If the location refers into a macro expansion, retrieves the
450 * location of the macro expansion.
Douglas Gregor229bebd2010-11-09 06:24:54 +0000451 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000452 * \param location the location within a source file that will be decomposed
453 * into its parts.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000454 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000455 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000456 * source location points.
457 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000458 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000459 * source location points.
460 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000461 * \param column [out] if non-NULL, will be set to the column to which the given
462 * source location points.
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000463 *
464 * \param offset [out] if non-NULL, will be set to the offset into the
465 * buffer to which the given source location points.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000466 */
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000467CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
468 CXFile *file,
469 unsigned *line,
470 unsigned *column,
471 unsigned *offset);
472
473/**
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000474 * \brief Retrieve the file, line, column, and offset represented by
475 * the given source location, as specified in a # line directive.
476 *
477 * Example: given the following source code in a file somefile.c
478 *
James Dennett574cb4c2012-06-15 05:41:51 +0000479 * \code
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000480 * #123 "dummy.c" 1
481 *
482 * static int func(void)
483 * {
484 * return 0;
485 * }
James Dennett574cb4c2012-06-15 05:41:51 +0000486 * \endcode
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000487 *
488 * the location information returned by this function would be
489 *
490 * File: dummy.c Line: 124 Column: 12
491 *
492 * whereas clang_getExpansionLocation would have returned
493 *
494 * File: somefile.c Line: 3 Column: 12
495 *
496 * \param location the location within a source file that will be decomposed
497 * into its parts.
498 *
499 * \param filename [out] if non-NULL, will be set to the filename of the
500 * source location. Note that filenames returned will be for "virtual" files,
501 * which don't necessarily exist on the machine running clang - e.g. when
502 * parsing preprocessed output obtained from a different environment. If
503 * a non-NULL value is passed in, remember to dispose of the returned value
504 * using \c clang_disposeString() once you've finished with it. For an invalid
505 * source location, an empty string is returned.
506 *
507 * \param line [out] if non-NULL, will be set to the line number of the
508 * source location. For an invalid source location, zero is returned.
509 *
510 * \param column [out] if non-NULL, will be set to the column number of the
511 * source location. For an invalid source location, zero is returned.
512 */
513CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
514 CXString *filename,
515 unsigned *line,
516 unsigned *column);
517
518/**
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000519 * \brief Legacy API to retrieve the file, line, column, and offset represented
520 * by the given source location.
521 *
522 * This interface has been replaced by the newer interface
James Dennett574cb4c2012-06-15 05:41:51 +0000523 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000524 * details.
525 */
Douglas Gregor4f46e782010-01-19 21:36:55 +0000526CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
527 CXFile *file,
528 unsigned *line,
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000529 unsigned *column,
530 unsigned *offset);
Douglas Gregor47751d62010-01-26 03:07:15 +0000531
532/**
Douglas Gregor229bebd2010-11-09 06:24:54 +0000533 * \brief Retrieve the file, line, column, and offset represented by
534 * the given source location.
535 *
536 * If the location refers into a macro instantiation, return where the
537 * location was originally spelled in the source file.
538 *
539 * \param location the location within a source file that will be decomposed
540 * into its parts.
541 *
542 * \param file [out] if non-NULL, will be set to the file to which the given
543 * source location points.
544 *
545 * \param line [out] if non-NULL, will be set to the line to which the given
546 * source location points.
547 *
548 * \param column [out] if non-NULL, will be set to the column to which the given
549 * source location points.
550 *
551 * \param offset [out] if non-NULL, will be set to the offset into the
552 * buffer to which the given source location points.
553 */
554CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
555 CXFile *file,
556 unsigned *line,
557 unsigned *column,
558 unsigned *offset);
559
560/**
Argyrios Kyrtzidis56be7162013-01-04 18:30:13 +0000561 * \brief Retrieve the file, line, column, and offset represented by
562 * the given source location.
563 *
564 * If the location refers into a macro expansion, return where the macro was
565 * expanded or where the macro argument was written, if the location points at
566 * a macro argument.
567 *
568 * \param location the location within a source file that will be decomposed
569 * into its parts.
570 *
571 * \param file [out] if non-NULL, will be set to the file to which the given
572 * source location points.
573 *
574 * \param line [out] if non-NULL, will be set to the line to which the given
575 * source location points.
576 *
577 * \param column [out] if non-NULL, will be set to the column to which the given
578 * source location points.
579 *
580 * \param offset [out] if non-NULL, will be set to the offset into the
581 * buffer to which the given source location points.
582 */
583CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
584 CXFile *file,
585 unsigned *line,
586 unsigned *column,
587 unsigned *offset);
588
589/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000590 * \brief Retrieve a source location representing the first character within a
591 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000592 */
593CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
594
595/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000596 * \brief Retrieve a source location representing the last character within a
597 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000598 */
599CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
600
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000601/**
602 * @}
603 */
Douglas Gregor6007cf22010-01-22 22:29:16 +0000604
605/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000606 * \defgroup CINDEX_DIAG Diagnostic reporting
607 *
608 * @{
609 */
610
611/**
612 * \brief Describes the severity of a particular diagnostic.
613 */
614enum CXDiagnosticSeverity {
615 /**
Ted Kremenekd071c602010-03-13 02:50:34 +0000616 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000617 * option.
618 */
619 CXDiagnostic_Ignored = 0,
Ted Kremenekd071c602010-03-13 02:50:34 +0000620
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000621 /**
622 * \brief This diagnostic is a note that should be attached to the
623 * previous (non-note) diagnostic.
624 */
625 CXDiagnostic_Note = 1,
626
627 /**
628 * \brief This diagnostic indicates suspicious code that may not be
629 * wrong.
630 */
631 CXDiagnostic_Warning = 2,
632
633 /**
634 * \brief This diagnostic indicates that the code is ill-formed.
635 */
636 CXDiagnostic_Error = 3,
637
638 /**
639 * \brief This diagnostic indicates that the code is ill-formed such
640 * that future parser recovery is unlikely to produce useful
641 * results.
642 */
643 CXDiagnostic_Fatal = 4
644};
645
646/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000647 * \brief A single diagnostic, containing the diagnostic's severity,
648 * location, text, source ranges, and fix-it hints.
649 */
650typedef void *CXDiagnostic;
651
652/**
Ted Kremenekd010ba42011-11-10 08:43:12 +0000653 * \brief A group of CXDiagnostics.
654 */
655typedef void *CXDiagnosticSet;
656
657/**
658 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
659 */
660CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
661
662/**
663 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
664 *
James Dennett574cb4c2012-06-15 05:41:51 +0000665 * \param Diags the CXDiagnosticSet to query.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000666 * \param Index the zero-based diagnostic number to retrieve.
667 *
668 * \returns the requested diagnostic. This diagnostic must be freed
669 * via a call to \c clang_disposeDiagnostic().
670 */
671CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
672 unsigned Index);
673
674
675/**
676 * \brief Describes the kind of error that occurred (if any) in a call to
677 * \c clang_loadDiagnostics.
678 */
679enum CXLoadDiag_Error {
680 /**
681 * \brief Indicates that no error occurred.
682 */
683 CXLoadDiag_None = 0,
684
685 /**
686 * \brief Indicates that an unknown error occurred while attempting to
687 * deserialize diagnostics.
688 */
689 CXLoadDiag_Unknown = 1,
690
691 /**
692 * \brief Indicates that the file containing the serialized diagnostics
693 * could not be opened.
694 */
695 CXLoadDiag_CannotLoad = 2,
696
697 /**
698 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett574cb4c2012-06-15 05:41:51 +0000699 * corrupt.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000700 */
701 CXLoadDiag_InvalidFile = 3
702};
703
704/**
705 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett574cb4c2012-06-15 05:41:51 +0000706 * file.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000707 *
James Dennett574cb4c2012-06-15 05:41:51 +0000708 * \param file The name of the file to deserialize.
709 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenekd010ba42011-11-10 08:43:12 +0000710 * deserializing the diagnostics.
James Dennett574cb4c2012-06-15 05:41:51 +0000711 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenekd010ba42011-11-10 08:43:12 +0000712 * if the file was not successfully loaded.
713 *
714 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett574cb4c2012-06-15 05:41:51 +0000715 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenekd010ba42011-11-10 08:43:12 +0000716 */
717CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
718 enum CXLoadDiag_Error *error,
719 CXString *errorString);
720
721/**
722 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
723 */
724CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
725
726/**
James Dennett574cb4c2012-06-15 05:41:51 +0000727 * \brief Retrieve the child diagnostics of a CXDiagnostic.
728 *
729 * This CXDiagnosticSet does not need to be released by
730 * clang_diposeDiagnosticSet.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000731 */
732CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
733
734/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000735 * \brief Determine the number of diagnostics produced for the given
736 * translation unit.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000737 */
Douglas Gregor33cdd812010-02-18 18:08:43 +0000738CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
739
740/**
741 * \brief Retrieve a diagnostic associated with the given translation unit.
742 *
743 * \param Unit the translation unit to query.
744 * \param Index the zero-based diagnostic number to retrieve.
745 *
746 * \returns the requested diagnostic. This diagnostic must be freed
747 * via a call to \c clang_disposeDiagnostic().
748 */
749CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
750 unsigned Index);
751
752/**
Ted Kremenekb4a8b052011-12-09 22:28:32 +0000753 * \brief Retrieve the complete set of diagnostics associated with a
754 * translation unit.
755 *
756 * \param Unit the translation unit to query.
757 */
758CINDEX_LINKAGE CXDiagnosticSet
759 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
760
761/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000762 * \brief Destroy a diagnostic.
763 */
764CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000765
766/**
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000767 * \brief Options to control the display of diagnostics.
768 *
769 * The values in this enum are meant to be combined to customize the
770 * behavior of \c clang_displayDiagnostic().
771 */
772enum CXDiagnosticDisplayOptions {
773 /**
774 * \brief Display the source-location information where the
775 * diagnostic was located.
776 *
777 * When set, diagnostics will be prefixed by the file, line, and
778 * (optionally) column to which the diagnostic refers. For example,
779 *
780 * \code
781 * test.c:28: warning: extra tokens at end of #endif directive
782 * \endcode
783 *
784 * This option corresponds to the clang flag \c -fshow-source-location.
785 */
786 CXDiagnostic_DisplaySourceLocation = 0x01,
787
788 /**
789 * \brief If displaying the source-location information of the
790 * diagnostic, also include the column number.
791 *
792 * This option corresponds to the clang flag \c -fshow-column.
793 */
794 CXDiagnostic_DisplayColumn = 0x02,
795
796 /**
797 * \brief If displaying the source-location information of the
798 * diagnostic, also include information about source ranges in a
799 * machine-parsable format.
800 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000801 * This option corresponds to the clang flag
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000802 * \c -fdiagnostics-print-source-range-info.
803 */
Douglas Gregora750e8e2010-11-19 16:18:16 +0000804 CXDiagnostic_DisplaySourceRanges = 0x04,
805
806 /**
807 * \brief Display the option name associated with this diagnostic, if any.
808 *
809 * The option name displayed (e.g., -Wconversion) will be placed in brackets
810 * after the diagnostic text. This option corresponds to the clang flag
811 * \c -fdiagnostics-show-option.
812 */
813 CXDiagnostic_DisplayOption = 0x08,
814
815 /**
816 * \brief Display the category number associated with this diagnostic, if any.
817 *
818 * The category number is displayed within brackets after the diagnostic text.
819 * This option corresponds to the clang flag
820 * \c -fdiagnostics-show-category=id.
821 */
822 CXDiagnostic_DisplayCategoryId = 0x10,
823
824 /**
825 * \brief Display the category name associated with this diagnostic, if any.
826 *
827 * The category name is displayed within brackets after the diagnostic text.
828 * This option corresponds to the clang flag
829 * \c -fdiagnostics-show-category=name.
830 */
831 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000832};
833
834/**
Douglas Gregord770f732010-02-22 23:17:23 +0000835 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000836 *
Douglas Gregord770f732010-02-22 23:17:23 +0000837 * This routine will format the given diagnostic to a string, rendering
Ted Kremenekd071c602010-03-13 02:50:34 +0000838 * the diagnostic according to the various options given. The
839 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000840 * options that most closely mimics the behavior of the clang compiler.
841 *
842 * \param Diagnostic The diagnostic to print.
843 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000844 * \param Options A set of options that control the diagnostic display,
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000845 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregord770f732010-02-22 23:17:23 +0000846 *
847 * \returns A new string containing for formatted diagnostic.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000848 */
Douglas Gregord770f732010-02-22 23:17:23 +0000849CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
850 unsigned Options);
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000851
852/**
853 * \brief Retrieve the set of display options most similar to the
854 * default behavior of the clang compiler.
855 *
856 * \returns A set of display options suitable for use with \c
857 * clang_displayDiagnostic().
858 */
859CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
860
861/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000862 * \brief Determine the severity of the given diagnostic.
863 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000864CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000865clang_getDiagnosticSeverity(CXDiagnostic);
866
867/**
868 * \brief Retrieve the source location of the given diagnostic.
869 *
870 * This location is where Clang would print the caret ('^') when
871 * displaying the diagnostic on the command line.
872 */
873CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
874
875/**
876 * \brief Retrieve the text of the given diagnostic.
877 */
878CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000879
880/**
Douglas Gregora750e8e2010-11-19 16:18:16 +0000881 * \brief Retrieve the name of the command-line option that enabled this
882 * diagnostic.
883 *
884 * \param Diag The diagnostic to be queried.
885 *
886 * \param Disable If non-NULL, will be set to the option that disables this
887 * diagnostic (if any).
888 *
889 * \returns A string that contains the command-line option used to enable this
890 * warning, such as "-Wconversion" or "-pedantic".
891 */
892CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
893 CXString *Disable);
894
895/**
896 * \brief Retrieve the category number for this diagnostic.
897 *
898 * Diagnostics can be categorized into groups along with other, related
899 * diagnostics (e.g., diagnostics under the same warning flag). This routine
900 * retrieves the category number for the given diagnostic.
901 *
902 * \returns The number of the category that contains this diagnostic, or zero
903 * if this diagnostic is uncategorized.
904 */
905CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
906
907/**
Ted Kremenek26a6d492012-04-12 00:03:31 +0000908 * \brief Retrieve the name of a particular diagnostic category. This
909 * is now deprecated. Use clang_getDiagnosticCategoryText()
910 * instead.
Douglas Gregora750e8e2010-11-19 16:18:16 +0000911 *
912 * \param Category A diagnostic category number, as returned by
913 * \c clang_getDiagnosticCategory().
914 *
915 * \returns The name of the given diagnostic category.
916 */
Ted Kremenek26a6d492012-04-12 00:03:31 +0000917CINDEX_DEPRECATED CINDEX_LINKAGE
918CXString clang_getDiagnosticCategoryName(unsigned Category);
919
920/**
921 * \brief Retrieve the diagnostic category text for a given diagnostic.
922 *
Ted Kremenek26a6d492012-04-12 00:03:31 +0000923 * \returns The text of the given diagnostic category.
924 */
925CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregora750e8e2010-11-19 16:18:16 +0000926
927/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000928 * \brief Determine the number of source ranges associated with the given
929 * diagnostic.
930 */
931CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenekd071c602010-03-13 02:50:34 +0000932
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000933/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000934 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000935 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000936 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000937 * code. On the command line, Clang displays source ranges by
Ted Kremenekd071c602010-03-13 02:50:34 +0000938 * underlining them with '~' characters.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000939 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000940 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000941 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000942 * \param Range the zero-based index specifying which range to
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000943 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000944 * \returns the requested source range.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000945 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000946CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000947 unsigned Range);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000948
949/**
950 * \brief Determine the number of fix-it hints associated with the
951 * given diagnostic.
952 */
953CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
954
955/**
Douglas Gregor836ec942010-02-19 18:16:06 +0000956 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000957 *
Douglas Gregor836ec942010-02-19 18:16:06 +0000958 * Fix-its are described in terms of a source range whose contents
959 * should be replaced by a string. This approach generalizes over
960 * three kinds of operations: removal of source code (the range covers
961 * the code to be removed and the replacement string is empty),
962 * replacement of source code (the range covers the code to be
963 * replaced and the replacement string provides the new code), and
964 * insertion (both the start and end of the range point at the
965 * insertion location, and the replacement string provides the text to
966 * insert).
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000967 *
Douglas Gregor836ec942010-02-19 18:16:06 +0000968 * \param Diagnostic The diagnostic whose fix-its are being queried.
969 *
970 * \param FixIt The zero-based index of the fix-it.
971 *
972 * \param ReplacementRange The source range whose contents will be
973 * replaced with the returned replacement string. Note that source
974 * ranges are half-open ranges [a, b), so the source code should be
975 * replaced from a and up to (but not including) b.
976 *
977 * \returns A string containing text that should be replace the source
978 * code indicated by the \c ReplacementRange.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000979 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000980CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor836ec942010-02-19 18:16:06 +0000981 unsigned FixIt,
982 CXSourceRange *ReplacementRange);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000983
984/**
985 * @}
986 */
987
988/**
989 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
990 *
991 * The routines in this group provide the ability to create and destroy
992 * translation units from files, either by parsing the contents of the files or
993 * by reading in a serialized representation of a translation unit.
994 *
995 * @{
996 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000997
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000998/**
999 * \brief Get the original translation unit source file name.
1000 */
1001CINDEX_LINKAGE CXString
1002clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1003
1004/**
1005 * \brief Return the CXTranslationUnit for a given source file and the provided
1006 * command line arguments one would pass to the compiler.
1007 *
1008 * Note: The 'source_filename' argument is optional. If the caller provides a
1009 * NULL pointer, the name of the source file is expected to reside in the
1010 * specified command line arguments.
1011 *
1012 * Note: When encountered in 'clang_command_line_args', the following options
1013 * are ignored:
1014 *
1015 * '-c'
1016 * '-emit-ast'
1017 * '-fsyntax-only'
James Dennett574cb4c2012-06-15 05:41:51 +00001018 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001019 *
Ted Kremenekbd4972442010-11-08 04:28:51 +00001020 * \param CIdx The index object with which the translation unit will be
1021 * associated.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001022 *
James Dennett574cb4c2012-06-15 05:41:51 +00001023 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenekbd4972442010-11-08 04:28:51 +00001024 * source file is included in \p clang_command_line_args.
1025 *
1026 * \param num_clang_command_line_args The number of command-line arguments in
1027 * \p clang_command_line_args.
1028 *
1029 * \param clang_command_line_args The command-line arguments that would be
1030 * passed to the \c clang executable if it were being invoked out-of-process.
1031 * These command-line options will be parsed and will affect how the translation
1032 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001033 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001034 *
1035 * \param num_unsaved_files the number of unsaved file entries in \p
1036 * unsaved_files.
1037 *
1038 * \param unsaved_files the files that have not yet been saved to disk
1039 * but may be required for code completion, including the contents of
Ted Kremenekde24a942010-04-12 18:47:26 +00001040 * those files. The contents and name of these files (as specified by
1041 * CXUnsavedFile) are copied when necessary, so the client only needs to
1042 * guarantee their validity until the call to this function returns.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001043 */
1044CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1045 CXIndex CIdx,
1046 const char *source_filename,
1047 int num_clang_command_line_args,
Douglas Gregor57879fa2010-09-01 16:43:19 +00001048 const char * const *clang_command_line_args,
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001049 unsigned num_unsaved_files,
Douglas Gregor33cdd812010-02-18 18:08:43 +00001050 struct CXUnsavedFile *unsaved_files);
Ted Kremenekd071c602010-03-13 02:50:34 +00001051
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001052/**
1053 * \brief Create a translation unit from an AST file (-emit-ast).
1054 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001055CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregor33cdd812010-02-18 18:08:43 +00001056 const char *ast_filename);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001057
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001058/**
1059 * \brief Flags that control the creation of translation units.
1060 *
1061 * The enumerators in this enumeration type are meant to be bitwise
1062 * ORed together to specify which options should be used when
1063 * constructing the translation unit.
1064 */
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001065enum CXTranslationUnit_Flags {
1066 /**
1067 * \brief Used to indicate that no special translation-unit options are
1068 * needed.
1069 */
1070 CXTranslationUnit_None = 0x0,
1071
1072 /**
1073 * \brief Used to indicate that the parser should construct a "detailed"
1074 * preprocessing record, including all macro definitions and instantiations.
1075 *
1076 * Constructing a detailed preprocessing record requires more memory
1077 * and time to parse, since the information contained in the record
1078 * is usually not retained. However, it can be useful for
1079 * applications that require more detailed information about the
1080 * behavior of the preprocessor.
1081 */
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001082 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1083
1084 /**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001085 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001086 *
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001087 * When a translation unit is considered "incomplete", semantic
1088 * analysis that is typically performed at the end of the
1089 * translation unit will be suppressed. For example, this suppresses
1090 * the completion of tentative declarations in C and of
1091 * instantiation of implicitly-instantiation function templates in
1092 * C++. This option is typically used when parsing a header with the
1093 * intent of producing a precompiled header.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001094 */
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001095 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001096
1097 /**
1098 * \brief Used to indicate that the translation unit should be built with an
1099 * implicit precompiled header for the preamble.
1100 *
1101 * An implicit precompiled header is used as an optimization when a
1102 * particular translation unit is likely to be reparsed many times
1103 * when the sources aren't changing that often. In this case, an
1104 * implicit precompiled header will be built containing all of the
1105 * initial includes at the top of the main file (what we refer to as
1106 * the "preamble" of the file). In subsequent parses, if the
1107 * preamble or the files in it have not changed, \c
1108 * clang_reparseTranslationUnit() will re-use the implicit
1109 * precompiled header to improve parsing performance.
1110 */
Douglas Gregorde051182010-08-11 15:58:42 +00001111 CXTranslationUnit_PrecompiledPreamble = 0x04,
1112
1113 /**
1114 * \brief Used to indicate that the translation unit should cache some
1115 * code-completion results with each reparse of the source file.
1116 *
1117 * Caching of code-completion results is a performance optimization that
1118 * introduces some overhead to reparsing but improves the performance of
1119 * code-completion operations.
1120 */
Douglas Gregorf5a18542010-10-27 17:24:53 +00001121 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001122
Douglas Gregorf5a18542010-10-27 17:24:53 +00001123 /**
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001124 * \brief Used to indicate that the translation unit will be serialized with
1125 * \c clang_saveTranslationUnit.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001126 *
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001127 * This option is typically used when parsing a header with the intent of
1128 * producing a precompiled header.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001129 */
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001130 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregorf5a18542010-10-27 17:24:53 +00001131
1132 /**
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001133 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001134 *
1135 * Note: this is a *temporary* option that is available only while
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001136 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001137 */
Erik Verbruggen6e922512012-04-12 10:11:59 +00001138 CXTranslationUnit_CXXChainedPCH = 0x20,
1139
1140 /**
1141 * \brief Used to indicate that function/method bodies should be skipped while
1142 * parsing.
1143 *
1144 * This option can be used to search for declarations/definitions while
1145 * ignoring the usages.
1146 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00001147 CXTranslationUnit_SkipFunctionBodies = 0x40,
1148
1149 /**
1150 * \brief Used to indicate that brief documentation comments should be
1151 * included into the set of code completions returned from this translation
1152 * unit.
1153 */
1154 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001155};
1156
1157/**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001158 * \brief Returns the set of flags that is suitable for parsing a translation
1159 * unit that is being edited.
1160 *
1161 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1162 * to indicate that the translation unit is likely to be reparsed many times,
1163 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1164 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1165 * set contains an unspecified set of optimizations (e.g., the precompiled
1166 * preamble) geared toward improving the performance of these routines. The
1167 * set of optimizations enabled may change from one version to the next.
1168 */
Douglas Gregorde051182010-08-11 15:58:42 +00001169CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001170
1171/**
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001172 * \brief Parse the given source file and the translation unit corresponding
1173 * to that file.
1174 *
1175 * This routine is the main entry point for the Clang C API, providing the
1176 * ability to parse a source file into a translation unit that can then be
1177 * queried by other functions in the API. This routine accepts a set of
1178 * command-line arguments so that the compilation can be configured in the same
1179 * way that the compiler is configured on the command line.
1180 *
1181 * \param CIdx The index object with which the translation unit will be
1182 * associated.
1183 *
1184 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenekbd4972442010-11-08 04:28:51 +00001185 * source file is included in \p command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001186 *
1187 * \param command_line_args The command-line arguments that would be
1188 * passed to the \c clang executable if it were being invoked out-of-process.
1189 * These command-line options will be parsed and will affect how the translation
1190 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001191 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001192 *
1193 * \param num_command_line_args The number of command-line arguments in
1194 * \p command_line_args.
1195 *
1196 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor8e984da2010-08-04 16:47:14 +00001197 * but may be required for parsing, including the contents of
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001198 * those files. The contents and name of these files (as specified by
1199 * CXUnsavedFile) are copied when necessary, so the client only needs to
1200 * guarantee their validity until the call to this function returns.
1201 *
1202 * \param num_unsaved_files the number of unsaved file entries in \p
1203 * unsaved_files.
1204 *
1205 * \param options A bitmask of options that affects how the translation unit
1206 * is managed but not its compilation. This should be a bitwise OR of the
1207 * CXTranslationUnit_XXX flags.
1208 *
1209 * \returns A new translation unit describing the parsed code and containing
1210 * any diagnostics produced by the compiler. If there is a failure from which
1211 * the compiler cannot recover, returns NULL.
1212 */
1213CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1214 const char *source_filename,
Douglas Gregor57879fa2010-09-01 16:43:19 +00001215 const char * const *command_line_args,
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001216 int num_command_line_args,
1217 struct CXUnsavedFile *unsaved_files,
1218 unsigned num_unsaved_files,
1219 unsigned options);
1220
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001221/**
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001222 * \brief Flags that control how translation units are saved.
1223 *
1224 * The enumerators in this enumeration type are meant to be bitwise
1225 * ORed together to specify which options should be used when
1226 * saving the translation unit.
1227 */
1228enum CXSaveTranslationUnit_Flags {
1229 /**
1230 * \brief Used to indicate that no special saving options are needed.
1231 */
1232 CXSaveTranslationUnit_None = 0x0
1233};
1234
1235/**
1236 * \brief Returns the set of flags that is suitable for saving a translation
1237 * unit.
1238 *
1239 * The set of flags returned provide options for
1240 * \c clang_saveTranslationUnit() by default. The returned flag
1241 * set contains an unspecified set of options that save translation units with
1242 * the most commonly-requested data.
1243 */
1244CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1245
1246/**
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001247 * \brief Describes the kind of error that occurred (if any) in a call to
1248 * \c clang_saveTranslationUnit().
1249 */
1250enum CXSaveError {
1251 /**
1252 * \brief Indicates that no error occurred while saving a translation unit.
1253 */
1254 CXSaveError_None = 0,
1255
1256 /**
1257 * \brief Indicates that an unknown error occurred while attempting to save
1258 * the file.
1259 *
1260 * This error typically indicates that file I/O failed when attempting to
1261 * write the file.
1262 */
1263 CXSaveError_Unknown = 1,
1264
1265 /**
1266 * \brief Indicates that errors during translation prevented this attempt
1267 * to save the translation unit.
1268 *
1269 * Errors that prevent the translation unit from being saved can be
1270 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1271 */
1272 CXSaveError_TranslationErrors = 2,
1273
1274 /**
1275 * \brief Indicates that the translation unit to be saved was somehow
1276 * invalid (e.g., NULL).
1277 */
1278 CXSaveError_InvalidTU = 3
1279};
1280
1281/**
Douglas Gregore9386682010-08-13 05:36:37 +00001282 * \brief Saves a translation unit into a serialized representation of
1283 * that translation unit on disk.
1284 *
1285 * Any translation unit that was parsed without error can be saved
1286 * into a file. The translation unit can then be deserialized into a
1287 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1288 * if it is an incomplete translation unit that corresponds to a
1289 * header, used as a precompiled header when parsing other translation
1290 * units.
1291 *
1292 * \param TU The translation unit to save.
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001293 *
Douglas Gregore9386682010-08-13 05:36:37 +00001294 * \param FileName The file to which the translation unit will be saved.
1295 *
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001296 * \param options A bitmask of options that affects how the translation unit
1297 * is saved. This should be a bitwise OR of the
1298 * CXSaveTranslationUnit_XXX flags.
1299 *
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001300 * \returns A value that will match one of the enumerators of the CXSaveError
1301 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1302 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregore9386682010-08-13 05:36:37 +00001303 */
1304CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001305 const char *FileName,
1306 unsigned options);
Douglas Gregore9386682010-08-13 05:36:37 +00001307
1308/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001309 * \brief Destroy the specified CXTranslationUnit object.
1310 */
1311CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenekd071c602010-03-13 02:50:34 +00001312
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001313/**
Douglas Gregorde051182010-08-11 15:58:42 +00001314 * \brief Flags that control the reparsing of translation units.
1315 *
1316 * The enumerators in this enumeration type are meant to be bitwise
1317 * ORed together to specify which options should be used when
1318 * reparsing the translation unit.
1319 */
1320enum CXReparse_Flags {
1321 /**
1322 * \brief Used to indicate that no special reparsing options are needed.
1323 */
1324 CXReparse_None = 0x0
1325};
1326
1327/**
1328 * \brief Returns the set of flags that is suitable for reparsing a translation
1329 * unit.
1330 *
1331 * The set of flags returned provide options for
1332 * \c clang_reparseTranslationUnit() by default. The returned flag
1333 * set contains an unspecified set of optimizations geared toward common uses
1334 * of reparsing. The set of optimizations enabled may change from one version
1335 * to the next.
1336 */
1337CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1338
1339/**
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001340 * \brief Reparse the source files that produced this translation unit.
1341 *
1342 * This routine can be used to re-parse the source files that originally
1343 * created the given translation unit, for example because those source files
1344 * have changed (either on disk or as passed via \p unsaved_files). The
1345 * source code will be reparsed with the same command-line options as it
1346 * was originally parsed.
1347 *
1348 * Reparsing a translation unit invalidates all cursors and source locations
1349 * that refer into that translation unit. This makes reparsing a translation
1350 * unit semantically equivalent to destroying the translation unit and then
1351 * creating a new translation unit with the same command-line arguments.
1352 * However, it may be more efficient to reparse a translation
1353 * unit using this routine.
1354 *
1355 * \param TU The translation unit whose contents will be re-parsed. The
1356 * translation unit must originally have been built with
1357 * \c clang_createTranslationUnitFromSourceFile().
1358 *
1359 * \param num_unsaved_files The number of unsaved file entries in \p
1360 * unsaved_files.
1361 *
1362 * \param unsaved_files The files that have not yet been saved to disk
1363 * but may be required for parsing, including the contents of
1364 * those files. The contents and name of these files (as specified by
1365 * CXUnsavedFile) are copied when necessary, so the client only needs to
1366 * guarantee their validity until the call to this function returns.
1367 *
Douglas Gregorde051182010-08-11 15:58:42 +00001368 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1369 * The function \c clang_defaultReparseOptions() produces a default set of
1370 * options recommended for most uses, based on the translation unit.
1371 *
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001372 * \returns 0 if the sources could be reparsed. A non-zero value will be
1373 * returned if reparsing was impossible, such that the translation unit is
1374 * invalid. In such cases, the only valid call for \p TU is
1375 * \c clang_disposeTranslationUnit(TU).
1376 */
1377CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1378 unsigned num_unsaved_files,
Douglas Gregorde051182010-08-11 15:58:42 +00001379 struct CXUnsavedFile *unsaved_files,
1380 unsigned options);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001381
1382/**
1383 * \brief Categorizes how memory is being used by a translation unit.
1384 */
Ted Kremenek23324122011-04-20 16:41:07 +00001385enum CXTUResourceUsageKind {
1386 CXTUResourceUsage_AST = 1,
1387 CXTUResourceUsage_Identifiers = 2,
1388 CXTUResourceUsage_Selectors = 3,
1389 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek21735e62011-04-28 04:10:31 +00001390 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekf5df0ce2011-04-28 04:53:38 +00001391 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenek8d587902011-04-28 20:36:42 +00001392 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremenek5e1ed7b2011-04-28 23:46:20 +00001393 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1394 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1395 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek2160a0d2011-05-04 01:38:46 +00001396 CXTUResourceUsage_Preprocessor = 11,
1397 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenek120992a2011-07-26 23:46:06 +00001398 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001399 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenek23324122011-04-20 16:41:07 +00001400 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1401 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001402 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenek23324122011-04-20 16:41:07 +00001403
1404 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001405 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek83f642e2011-04-18 22:47:10 +00001406};
1407
1408/**
1409 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenek23324122011-04-20 16:41:07 +00001410 * the name of the memory category. This string should never be freed.
Ted Kremenek83f642e2011-04-18 22:47:10 +00001411 */
1412CINDEX_LINKAGE
Ted Kremenek23324122011-04-20 16:41:07 +00001413const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001414
Ted Kremenek23324122011-04-20 16:41:07 +00001415typedef struct CXTUResourceUsageEntry {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001416 /* \brief The memory usage category. */
Ted Kremenek23324122011-04-20 16:41:07 +00001417 enum CXTUResourceUsageKind kind;
1418 /* \brief Amount of resources used.
1419 The units will depend on the resource kind. */
Ted Kremenek83f642e2011-04-18 22:47:10 +00001420 unsigned long amount;
Ted Kremenek23324122011-04-20 16:41:07 +00001421} CXTUResourceUsageEntry;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001422
1423/**
1424 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1425 */
Ted Kremenek23324122011-04-20 16:41:07 +00001426typedef struct CXTUResourceUsage {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001427 /* \brief Private data member, used for queries. */
1428 void *data;
1429
1430 /* \brief The number of entries in the 'entries' array. */
1431 unsigned numEntries;
1432
1433 /* \brief An array of key-value pairs, representing the breakdown of memory
1434 usage. */
Ted Kremenek23324122011-04-20 16:41:07 +00001435 CXTUResourceUsageEntry *entries;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001436
Ted Kremenek23324122011-04-20 16:41:07 +00001437} CXTUResourceUsage;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001438
1439/**
1440 * \brief Return the memory usage of a translation unit. This object
Ted Kremenek23324122011-04-20 16:41:07 +00001441 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek83f642e2011-04-18 22:47:10 +00001442 */
Ted Kremenek23324122011-04-20 16:41:07 +00001443CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001444
Ted Kremenek23324122011-04-20 16:41:07 +00001445CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001446
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001447/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001448 * @}
1449 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001450
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001451/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001452 * \brief Describes the kind of entity that a cursor refers to.
1453 */
1454enum CXCursorKind {
1455 /* Declarations */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001456 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001457 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001458 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001459 *
1460 * Unexposed declarations have the same operations as any other kind
1461 * of declaration; one can extract their location information,
1462 * spelling, find their definitions, etc. However, the specific kind
1463 * of the declaration is not reported.
1464 */
1465 CXCursor_UnexposedDecl = 1,
1466 /** \brief A C or C++ struct. */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001467 CXCursor_StructDecl = 2,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001468 /** \brief A C or C++ union. */
1469 CXCursor_UnionDecl = 3,
1470 /** \brief A C++ class. */
1471 CXCursor_ClassDecl = 4,
1472 /** \brief An enumeration. */
1473 CXCursor_EnumDecl = 5,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001474 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001475 * \brief A field (in C) or non-static data member (in C++) in a
1476 * struct, union, or C++ class.
1477 */
1478 CXCursor_FieldDecl = 6,
1479 /** \brief An enumerator constant. */
1480 CXCursor_EnumConstantDecl = 7,
1481 /** \brief A function. */
1482 CXCursor_FunctionDecl = 8,
1483 /** \brief A variable. */
1484 CXCursor_VarDecl = 9,
1485 /** \brief A function or method parameter. */
1486 CXCursor_ParmDecl = 10,
James Dennett1355bd12012-06-11 06:19:40 +00001487 /** \brief An Objective-C \@interface. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001488 CXCursor_ObjCInterfaceDecl = 11,
James Dennett1355bd12012-06-11 06:19:40 +00001489 /** \brief An Objective-C \@interface for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001490 CXCursor_ObjCCategoryDecl = 12,
James Dennett1355bd12012-06-11 06:19:40 +00001491 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001492 CXCursor_ObjCProtocolDecl = 13,
James Dennett1355bd12012-06-11 06:19:40 +00001493 /** \brief An Objective-C \@property declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001494 CXCursor_ObjCPropertyDecl = 14,
1495 /** \brief An Objective-C instance variable. */
1496 CXCursor_ObjCIvarDecl = 15,
1497 /** \brief An Objective-C instance method. */
1498 CXCursor_ObjCInstanceMethodDecl = 16,
1499 /** \brief An Objective-C class method. */
1500 CXCursor_ObjCClassMethodDecl = 17,
James Dennett1355bd12012-06-11 06:19:40 +00001501 /** \brief An Objective-C \@implementation. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001502 CXCursor_ObjCImplementationDecl = 18,
James Dennett1355bd12012-06-11 06:19:40 +00001503 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001504 CXCursor_ObjCCategoryImplDecl = 19,
1505 /** \brief A typedef */
1506 CXCursor_TypedefDecl = 20,
Ted Kremenek225b8e32010-04-13 23:39:06 +00001507 /** \brief A C++ class method. */
1508 CXCursor_CXXMethod = 21,
Ted Kremenekbd67fb22010-05-06 23:38:21 +00001509 /** \brief A C++ namespace. */
1510 CXCursor_Namespace = 22,
Ted Kremenekb80cba52010-05-07 01:04:29 +00001511 /** \brief A linkage specification, e.g. 'extern "C"'. */
1512 CXCursor_LinkageSpec = 23,
Douglas Gregor12bca222010-08-31 14:41:23 +00001513 /** \brief A C++ constructor. */
1514 CXCursor_Constructor = 24,
1515 /** \brief A C++ destructor. */
1516 CXCursor_Destructor = 25,
1517 /** \brief A C++ conversion function. */
1518 CXCursor_ConversionFunction = 26,
Douglas Gregor713602b2010-08-31 17:01:39 +00001519 /** \brief A C++ template type parameter. */
1520 CXCursor_TemplateTypeParameter = 27,
1521 /** \brief A C++ non-type template parameter. */
1522 CXCursor_NonTypeTemplateParameter = 28,
1523 /** \brief A C++ template template parameter. */
1524 CXCursor_TemplateTemplateParameter = 29,
1525 /** \brief A C++ function template. */
1526 CXCursor_FunctionTemplate = 30,
Douglas Gregor1fbaeb12010-08-31 19:02:00 +00001527 /** \brief A C++ class template. */
1528 CXCursor_ClassTemplate = 31,
Douglas Gregorf96abb22010-08-31 19:31:58 +00001529 /** \brief A C++ class template partial specialization. */
1530 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregora89314e2010-08-31 23:48:11 +00001531 /** \brief A C++ namespace alias declaration. */
1532 CXCursor_NamespaceAlias = 33,
Douglas Gregor01a430132010-09-01 03:07:18 +00001533 /** \brief A C++ using directive. */
1534 CXCursor_UsingDirective = 34,
Richard Smithdda56e42011-04-15 14:24:37 +00001535 /** \brief A C++ using declaration. */
Douglas Gregora9aa29c2010-09-01 19:52:22 +00001536 CXCursor_UsingDeclaration = 35,
Richard Smithdda56e42011-04-15 14:24:37 +00001537 /** \brief A C++ alias declaration */
1538 CXCursor_TypeAliasDecl = 36,
James Dennett574cb4c2012-06-15 05:41:51 +00001539 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001540 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett574cb4c2012-06-15 05:41:51 +00001541 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001542 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001543 /** \brief An access specifier. */
1544 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor4c362d52011-10-05 19:00:14 +00001545
Ted Kremenek08de5c12010-05-19 21:51:10 +00001546 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001547 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001548
Douglas Gregor6007cf22010-01-22 22:29:16 +00001549 /* References */
1550 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001551 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001552 CXCursor_ObjCProtocolRef = 41,
1553 CXCursor_ObjCClassRef = 42,
1554 /**
1555 * \brief A reference to a type declaration.
1556 *
1557 * A type reference occurs anywhere where a type is named but not
1558 * declared. For example, given:
1559 *
1560 * \code
1561 * typedef unsigned size_type;
1562 * size_type size;
1563 * \endcode
1564 *
1565 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1566 * while the type of the variable "size" is referenced. The cursor
1567 * referenced by the type of size is the typedef for size_type.
1568 */
1569 CXCursor_TypeRef = 43,
Ted Kremenekae9e2212010-08-27 21:34:58 +00001570 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregora23e8f72010-08-31 20:37:03 +00001571 /**
Douglas Gregorf3af3112010-09-09 21:42:20 +00001572 * \brief A reference to a class template, function template, template
1573 * template parameter, or class template partial specialization.
Douglas Gregora23e8f72010-08-31 20:37:03 +00001574 */
1575 CXCursor_TemplateRef = 45,
Douglas Gregora89314e2010-08-31 23:48:11 +00001576 /**
1577 * \brief A reference to a namespace or namespace alias.
1578 */
1579 CXCursor_NamespaceRef = 46,
Douglas Gregorf3af3112010-09-09 21:42:20 +00001580 /**
Douglas Gregora93ab662010-09-10 00:22:18 +00001581 * \brief A reference to a member of a struct, union, or class that occurs in
1582 * some non-expression context, e.g., a designated initializer.
Douglas Gregorf3af3112010-09-09 21:42:20 +00001583 */
1584 CXCursor_MemberRef = 47,
Douglas Gregora93ab662010-09-10 00:22:18 +00001585 /**
1586 * \brief A reference to a labeled statement.
1587 *
1588 * This cursor kind is used to describe the jump to "start_over" in the
1589 * goto statement in the following example:
1590 *
1591 * \code
1592 * start_over:
1593 * ++counter;
1594 *
1595 * goto start_over;
1596 * \endcode
1597 *
1598 * A label reference cursor refers to a label statement.
1599 */
1600 CXCursor_LabelRef = 48,
1601
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00001602 /**
1603 * \brief A reference to a set of overloaded functions or function templates
1604 * that has not yet been resolved to a specific function or function template.
1605 *
1606 * An overloaded declaration reference cursor occurs in C++ templates where
1607 * a dependent name refers to a function. For example:
1608 *
1609 * \code
1610 * template<typename T> void swap(T&, T&);
1611 *
1612 * struct X { ... };
1613 * void swap(X&, X&);
1614 *
1615 * template<typename T>
1616 * void reverse(T* first, T* last) {
1617 * while (first < last - 1) {
1618 * swap(*first, *--last);
1619 * ++first;
1620 * }
1621 * }
1622 *
1623 * struct Y { };
1624 * void swap(Y&, Y&);
1625 * \endcode
1626 *
1627 * Here, the identifier "swap" is associated with an overloaded declaration
1628 * reference. In the template definition, "swap" refers to either of the two
1629 * "swap" functions declared above, so both results will be available. At
1630 * instantiation time, "swap" may also refer to other functions found via
1631 * argument-dependent lookup (e.g., the "swap" function at the end of the
1632 * example).
1633 *
1634 * The functions \c clang_getNumOverloadedDecls() and
1635 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1636 * referenced by this cursor.
1637 */
1638 CXCursor_OverloadedDeclRef = 49,
1639
Douglas Gregor30093832012-02-15 00:54:55 +00001640 /**
1641 * \brief A reference to a variable that occurs in some non-expression
1642 * context, e.g., a C++ lambda capture list.
1643 */
1644 CXCursor_VariableRef = 50,
1645
1646 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001647
Douglas Gregor6007cf22010-01-22 22:29:16 +00001648 /* Error conditions */
1649 CXCursor_FirstInvalid = 70,
1650 CXCursor_InvalidFile = 70,
1651 CXCursor_NoDeclFound = 71,
1652 CXCursor_NotImplemented = 72,
Ted Kremeneke184ac52010-03-19 20:39:03 +00001653 CXCursor_InvalidCode = 73,
1654 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001655
Douglas Gregor6007cf22010-01-22 22:29:16 +00001656 /* Expressions */
1657 CXCursor_FirstExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001658
Douglas Gregor6007cf22010-01-22 22:29:16 +00001659 /**
1660 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001661 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001662 *
1663 * Unexposed expressions have the same operations as any other kind
1664 * of expression; one can extract their location information,
1665 * spelling, children, etc. However, the specific kind of the
1666 * expression is not reported.
1667 */
1668 CXCursor_UnexposedExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001669
Douglas Gregor6007cf22010-01-22 22:29:16 +00001670 /**
1671 * \brief An expression that refers to some value declaration, such
1672 * as a function, varible, or enumerator.
1673 */
1674 CXCursor_DeclRefExpr = 101,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001675
Douglas Gregor6007cf22010-01-22 22:29:16 +00001676 /**
1677 * \brief An expression that refers to a member of a struct, union,
1678 * class, Objective-C class, etc.
1679 */
1680 CXCursor_MemberRefExpr = 102,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001681
Douglas Gregor6007cf22010-01-22 22:29:16 +00001682 /** \brief An expression that calls a function. */
1683 CXCursor_CallExpr = 103,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001684
Douglas Gregor6007cf22010-01-22 22:29:16 +00001685 /** \brief An expression that sends a message to an Objective-C
1686 object or class. */
1687 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek33b9a422010-04-11 21:47:37 +00001688
1689 /** \brief An expression that represents a block literal. */
1690 CXCursor_BlockExpr = 105,
1691
Douglas Gregor4c362d52011-10-05 19:00:14 +00001692 /** \brief An integer literal.
1693 */
1694 CXCursor_IntegerLiteral = 106,
1695
1696 /** \brief A floating point number literal.
1697 */
1698 CXCursor_FloatingLiteral = 107,
1699
1700 /** \brief An imaginary number literal.
1701 */
1702 CXCursor_ImaginaryLiteral = 108,
1703
1704 /** \brief A string literal.
1705 */
1706 CXCursor_StringLiteral = 109,
1707
1708 /** \brief A character literal.
1709 */
1710 CXCursor_CharacterLiteral = 110,
1711
1712 /** \brief A parenthesized expression, e.g. "(1)".
1713 *
1714 * This AST node is only formed if full location information is requested.
1715 */
1716 CXCursor_ParenExpr = 111,
1717
1718 /** \brief This represents the unary-expression's (except sizeof and
1719 * alignof).
1720 */
1721 CXCursor_UnaryOperator = 112,
1722
1723 /** \brief [C99 6.5.2.1] Array Subscripting.
1724 */
1725 CXCursor_ArraySubscriptExpr = 113,
1726
1727 /** \brief A builtin binary operation expression such as "x + y" or
1728 * "x <= y".
1729 */
1730 CXCursor_BinaryOperator = 114,
1731
1732 /** \brief Compound assignment such as "+=".
1733 */
1734 CXCursor_CompoundAssignOperator = 115,
1735
1736 /** \brief The ?: ternary operator.
1737 */
1738 CXCursor_ConditionalOperator = 116,
1739
1740 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1741 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1742 *
1743 * For example: (int)f.
1744 */
1745 CXCursor_CStyleCastExpr = 117,
1746
1747 /** \brief [C99 6.5.2.5]
1748 */
1749 CXCursor_CompoundLiteralExpr = 118,
1750
1751 /** \brief Describes an C or C++ initializer list.
1752 */
1753 CXCursor_InitListExpr = 119,
1754
1755 /** \brief The GNU address of label extension, representing &&label.
1756 */
1757 CXCursor_AddrLabelExpr = 120,
1758
1759 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1760 */
1761 CXCursor_StmtExpr = 121,
1762
Benjamin Kramere56f3932011-12-23 17:00:35 +00001763 /** \brief Represents a C11 generic selection.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001764 */
1765 CXCursor_GenericSelectionExpr = 122,
1766
1767 /** \brief Implements the GNU __null extension, which is a name for a null
1768 * pointer constant that has integral type (e.g., int or long) and is the same
1769 * size and alignment as a pointer.
1770 *
1771 * The __null extension is typically only used by system headers, which define
1772 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1773 * match the size of a pointer).
1774 */
1775 CXCursor_GNUNullExpr = 123,
1776
1777 /** \brief C++'s static_cast<> expression.
1778 */
1779 CXCursor_CXXStaticCastExpr = 124,
1780
1781 /** \brief C++'s dynamic_cast<> expression.
1782 */
1783 CXCursor_CXXDynamicCastExpr = 125,
1784
1785 /** \brief C++'s reinterpret_cast<> expression.
1786 */
1787 CXCursor_CXXReinterpretCastExpr = 126,
1788
1789 /** \brief C++'s const_cast<> expression.
1790 */
1791 CXCursor_CXXConstCastExpr = 127,
1792
1793 /** \brief Represents an explicit C++ type conversion that uses "functional"
1794 * notion (C++ [expr.type.conv]).
1795 *
1796 * Example:
1797 * \code
1798 * x = int(0.5);
1799 * \endcode
1800 */
1801 CXCursor_CXXFunctionalCastExpr = 128,
1802
1803 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1804 */
1805 CXCursor_CXXTypeidExpr = 129,
1806
1807 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1808 */
1809 CXCursor_CXXBoolLiteralExpr = 130,
1810
1811 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1812 */
1813 CXCursor_CXXNullPtrLiteralExpr = 131,
1814
1815 /** \brief Represents the "this" expression in C++
1816 */
1817 CXCursor_CXXThisExpr = 132,
1818
1819 /** \brief [C++ 15] C++ Throw Expression.
1820 *
1821 * This handles 'throw' and 'throw' assignment-expression. When
1822 * assignment-expression isn't present, Op will be null.
1823 */
1824 CXCursor_CXXThrowExpr = 133,
1825
1826 /** \brief A new expression for memory allocation and constructor calls, e.g:
1827 * "new CXXNewExpr(foo)".
1828 */
1829 CXCursor_CXXNewExpr = 134,
1830
1831 /** \brief A delete expression for memory deallocation and destructor calls,
1832 * e.g. "delete[] pArray".
1833 */
1834 CXCursor_CXXDeleteExpr = 135,
1835
1836 /** \brief A unary expression.
1837 */
1838 CXCursor_UnaryExpr = 136,
1839
Douglas Gregor910c37c2011-11-11 22:35:18 +00001840 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor4c362d52011-10-05 19:00:14 +00001841 */
1842 CXCursor_ObjCStringLiteral = 137,
1843
James Dennett574cb4c2012-06-15 05:41:51 +00001844 /** \brief An Objective-C \@encode expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001845 */
1846 CXCursor_ObjCEncodeExpr = 138,
1847
James Dennett574cb4c2012-06-15 05:41:51 +00001848 /** \brief An Objective-C \@selector expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001849 */
1850 CXCursor_ObjCSelectorExpr = 139,
1851
James Dennett1355bd12012-06-11 06:19:40 +00001852 /** \brief An Objective-C \@protocol expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001853 */
1854 CXCursor_ObjCProtocolExpr = 140,
1855
1856 /** \brief An Objective-C "bridged" cast expression, which casts between
1857 * Objective-C pointers and C pointers, transferring ownership in the process.
1858 *
1859 * \code
1860 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1861 * \endcode
1862 */
1863 CXCursor_ObjCBridgedCastExpr = 141,
1864
1865 /** \brief Represents a C++0x pack expansion that produces a sequence of
1866 * expressions.
1867 *
1868 * A pack expansion expression contains a pattern (which itself is an
1869 * expression) followed by an ellipsis. For example:
1870 *
1871 * \code
1872 * template<typename F, typename ...Types>
1873 * void forward(F f, Types &&...args) {
1874 * f(static_cast<Types&&>(args)...);
1875 * }
1876 * \endcode
1877 */
1878 CXCursor_PackExpansionExpr = 142,
1879
1880 /** \brief Represents an expression that computes the length of a parameter
1881 * pack.
1882 *
1883 * \code
1884 * template<typename ...Types>
1885 * struct count {
1886 * static const unsigned value = sizeof...(Types);
1887 * };
1888 * \endcode
1889 */
1890 CXCursor_SizeOfPackExpr = 143,
1891
Douglas Gregor30093832012-02-15 00:54:55 +00001892 /* \brief Represents a C++ lambda expression that produces a local function
1893 * object.
1894 *
1895 * \code
1896 * void abssort(float *x, unsigned N) {
1897 * std::sort(x, x + N,
1898 * [](float a, float b) {
1899 * return std::abs(a) < std::abs(b);
1900 * });
1901 * }
1902 * \endcode
1903 */
1904 CXCursor_LambdaExpr = 144,
1905
Ted Kremenek77006f62012-03-06 20:06:06 +00001906 /** \brief Objective-c Boolean Literal.
1907 */
1908 CXCursor_ObjCBoolLiteralExpr = 145,
1909
Argyrios Kyrtzidisc2233be2013-04-23 17:57:17 +00001910 /** \brief Represents the "self" expression in a ObjC method.
1911 */
1912 CXCursor_ObjCSelfExpr = 146,
1913
1914 CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001915
Douglas Gregor6007cf22010-01-22 22:29:16 +00001916 /* Statements */
1917 CXCursor_FirstStmt = 200,
1918 /**
1919 * \brief A statement whose specific kind is not exposed via this
1920 * interface.
1921 *
1922 * Unexposed statements have the same operations as any other kind of
1923 * statement; one can extract their location information, spelling,
1924 * children, etc. However, the specific kind of the statement is not
1925 * reported.
1926 */
1927 CXCursor_UnexposedStmt = 200,
Douglas Gregora93ab662010-09-10 00:22:18 +00001928
1929 /** \brief A labelled statement in a function.
1930 *
1931 * This cursor kind is used to describe the "start_over:" label statement in
1932 * the following example:
1933 *
1934 * \code
1935 * start_over:
1936 * ++counter;
1937 * \endcode
1938 *
1939 */
1940 CXCursor_LabelStmt = 201,
Douglas Gregor4c362d52011-10-05 19:00:14 +00001941
1942 /** \brief A group of statements like { stmt stmt }.
1943 *
1944 * This cursor kind is used to describe compound statements, e.g. function
1945 * bodies.
1946 */
1947 CXCursor_CompoundStmt = 202,
1948
1949 /** \brief A case statment.
1950 */
1951 CXCursor_CaseStmt = 203,
1952
1953 /** \brief A default statement.
1954 */
1955 CXCursor_DefaultStmt = 204,
1956
1957 /** \brief An if statement
1958 */
1959 CXCursor_IfStmt = 205,
1960
1961 /** \brief A switch statement.
1962 */
1963 CXCursor_SwitchStmt = 206,
1964
1965 /** \brief A while statement.
1966 */
1967 CXCursor_WhileStmt = 207,
1968
1969 /** \brief A do statement.
1970 */
1971 CXCursor_DoStmt = 208,
1972
1973 /** \brief A for statement.
1974 */
1975 CXCursor_ForStmt = 209,
1976
1977 /** \brief A goto statement.
1978 */
1979 CXCursor_GotoStmt = 210,
1980
1981 /** \brief An indirect goto statement.
1982 */
1983 CXCursor_IndirectGotoStmt = 211,
1984
1985 /** \brief A continue statement.
1986 */
1987 CXCursor_ContinueStmt = 212,
1988
1989 /** \brief A break statement.
1990 */
1991 CXCursor_BreakStmt = 213,
1992
1993 /** \brief A return statement.
1994 */
1995 CXCursor_ReturnStmt = 214,
1996
Chad Rosierde70e0e2012-08-25 00:11:56 +00001997 /** \brief A GCC inline assembly statement extension.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001998 */
Chad Rosierde70e0e2012-08-25 00:11:56 +00001999 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5eae0732012-09-24 19:27:20 +00002000 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002001
James Dennett574cb4c2012-06-15 05:41:51 +00002002 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002003 */
2004 CXCursor_ObjCAtTryStmt = 216,
2005
James Dennett574cb4c2012-06-15 05:41:51 +00002006 /** \brief Objective-C's \@catch statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002007 */
2008 CXCursor_ObjCAtCatchStmt = 217,
2009
James Dennett574cb4c2012-06-15 05:41:51 +00002010 /** \brief Objective-C's \@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002011 */
2012 CXCursor_ObjCAtFinallyStmt = 218,
2013
James Dennett574cb4c2012-06-15 05:41:51 +00002014 /** \brief Objective-C's \@throw statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002015 */
2016 CXCursor_ObjCAtThrowStmt = 219,
2017
James Dennett574cb4c2012-06-15 05:41:51 +00002018 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002019 */
2020 CXCursor_ObjCAtSynchronizedStmt = 220,
2021
2022 /** \brief Objective-C's autorelease pool statement.
2023 */
2024 CXCursor_ObjCAutoreleasePoolStmt = 221,
2025
2026 /** \brief Objective-C's collection statement.
2027 */
2028 CXCursor_ObjCForCollectionStmt = 222,
2029
2030 /** \brief C++'s catch statement.
2031 */
2032 CXCursor_CXXCatchStmt = 223,
2033
2034 /** \brief C++'s try statement.
2035 */
2036 CXCursor_CXXTryStmt = 224,
2037
2038 /** \brief C++'s for (* : *) statement.
2039 */
2040 CXCursor_CXXForRangeStmt = 225,
2041
2042 /** \brief Windows Structured Exception Handling's try statement.
2043 */
2044 CXCursor_SEHTryStmt = 226,
2045
2046 /** \brief Windows Structured Exception Handling's except statement.
2047 */
2048 CXCursor_SEHExceptStmt = 227,
2049
2050 /** \brief Windows Structured Exception Handling's finally statement.
2051 */
2052 CXCursor_SEHFinallyStmt = 228,
2053
Chad Rosier32503022012-06-11 20:47:18 +00002054 /** \brief A MS inline assembly statement extension.
2055 */
2056 CXCursor_MSAsmStmt = 229,
2057
Douglas Gregor4c362d52011-10-05 19:00:14 +00002058 /** \brief The null satement ";": C99 6.8.3p3.
2059 *
2060 * This cursor kind is used to describe the null statement.
2061 */
2062 CXCursor_NullStmt = 230,
2063
2064 /** \brief Adaptor class for mixing declarations with statements and
2065 * expressions.
2066 */
2067 CXCursor_DeclStmt = 231,
2068
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002069 /** \brief OpenMP parallel directive.
2070 */
2071 CXCursor_OMPParallelDirective = 232,
2072
2073 CXCursor_LastStmt = CXCursor_OMPParallelDirective,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002074
Douglas Gregor6007cf22010-01-22 22:29:16 +00002075 /**
2076 * \brief Cursor that represents the translation unit itself.
2077 *
2078 * The translation unit cursor exists primarily to act as the root
2079 * cursor for traversing the contents of a translation unit.
2080 */
Ted Kremenekbff31432010-02-18 03:09:07 +00002081 CXCursor_TranslationUnit = 300,
2082
Bill Wendling44426052012-12-20 19:22:21 +00002083 /* Attributes */
Ted Kremenekbff31432010-02-18 03:09:07 +00002084 CXCursor_FirstAttr = 400,
2085 /**
2086 * \brief An attribute whose specific kind is not exposed via this
2087 * interface.
2088 */
2089 CXCursor_UnexposedAttr = 400,
2090
2091 CXCursor_IBActionAttr = 401,
2092 CXCursor_IBOutletAttr = 402,
Ted Kremenek26bde772010-05-19 17:38:06 +00002093 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis2cb4e3c2011-09-13 17:39:31 +00002094 CXCursor_CXXFinalAttr = 404,
2095 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggenca98f2a2011-10-13 09:41:32 +00002096 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002097 CXCursor_AsmLabelAttr = 407,
2098 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002099
2100 /* Preprocessing */
2101 CXCursor_PreprocessingDirective = 500,
Douglas Gregor06d6d322010-03-18 18:04:21 +00002102 CXCursor_MacroDefinition = 501,
Chandler Carruth9e4704a2011-07-14 08:41:15 +00002103 CXCursor_MacroExpansion = 502,
2104 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregor796d76a2010-10-20 22:00:55 +00002105 CXCursor_InclusionDirective = 503,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002106 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis50e5b1d2012-10-05 00:22:24 +00002107 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2108
2109 /* Extra Declarations */
2110 /**
2111 * \brief A module import declaration.
2112 */
2113 CXCursor_ModuleImportDecl = 600,
2114 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2115 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregor6007cf22010-01-22 22:29:16 +00002116};
2117
2118/**
2119 * \brief A cursor representing some element in the abstract syntax tree for
2120 * a translation unit.
2121 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002122 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregor6007cf22010-01-22 22:29:16 +00002123 * program--declaration, statements, expressions, references to declarations,
2124 * etc.--under a single "cursor" abstraction with a common set of operations.
2125 * Common operation for a cursor include: getting the physical location in
2126 * a source file where the cursor points, getting the name associated with a
2127 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2128 *
2129 * Cursors can be produced in two specific ways.
2130 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2131 * from which one can use clang_visitChildren() to explore the rest of the
2132 * translation unit. clang_getCursor() maps from a physical source location
2133 * to the entity that resides at that location, allowing one to map from the
2134 * source code into the AST.
2135 */
2136typedef struct {
2137 enum CXCursorKind kind;
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00002138 int xdata;
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +00002139 const void *data[3];
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002140} CXCursor;
Douglas Gregor6007cf22010-01-22 22:29:16 +00002141
2142/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002143 * \brief A comment AST node.
2144 */
2145typedef struct {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00002146 const void *ASTNode;
2147 CXTranslationUnit TranslationUnit;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002148} CXComment;
2149
2150/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002151 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2152 *
2153 * @{
2154 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002155
Douglas Gregor6007cf22010-01-22 22:29:16 +00002156/**
2157 * \brief Retrieve the NULL cursor, which represents no entity.
2158 */
2159CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002160
Douglas Gregor6007cf22010-01-22 22:29:16 +00002161/**
2162 * \brief Retrieve the cursor that represents the given translation unit.
2163 *
2164 * The translation unit cursor can be used to start traversing the
2165 * various declarations within the given translation unit.
2166 */
2167CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2168
2169/**
2170 * \brief Determine whether two cursors are equivalent.
2171 */
2172CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002173
Douglas Gregor6007cf22010-01-22 22:29:16 +00002174/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002175 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002176 */
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002177CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002178
2179/**
Douglas Gregor06a3f302010-11-20 00:09:34 +00002180 * \brief Compute a hash value for the given cursor.
2181 */
2182CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2183
2184/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002185 * \brief Retrieve the kind of the given cursor.
2186 */
2187CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2188
2189/**
2190 * \brief Determine whether the given cursor kind represents a declaration.
2191 */
2192CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2193
2194/**
2195 * \brief Determine whether the given cursor kind represents a simple
2196 * reference.
2197 *
2198 * Note that other kinds of cursors (such as expressions) can also refer to
2199 * other cursors. Use clang_getCursorReferenced() to determine whether a
2200 * particular cursor refers to another entity.
2201 */
2202CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2203
2204/**
2205 * \brief Determine whether the given cursor kind represents an expression.
2206 */
2207CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2208
2209/**
2210 * \brief Determine whether the given cursor kind represents a statement.
2211 */
2212CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2213
2214/**
Douglas Gregora98034a2011-07-06 03:00:34 +00002215 * \brief Determine whether the given cursor kind represents an attribute.
2216 */
2217CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2218
2219/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002220 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregor6007cf22010-01-22 22:29:16 +00002221 * cursor.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002222 */
Douglas Gregor6007cf22010-01-22 22:29:16 +00002223CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2224
2225/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002226 * \brief Determine whether the given cursor kind represents a translation
2227 * unit.
Douglas Gregor6007cf22010-01-22 22:29:16 +00002228 */
2229CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002230
Ted Kremenekff9021b2010-03-08 21:17:29 +00002231/***
Douglas Gregor92a524f2010-03-18 00:42:48 +00002232 * \brief Determine whether the given cursor represents a preprocessing
2233 * element, such as a preprocessor directive or macro instantiation.
2234 */
2235CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2236
2237/***
Ted Kremenekff9021b2010-03-08 21:17:29 +00002238 * \brief Determine whether the given cursor represents a currently
2239 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2240 */
2241CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2242
Douglas Gregor6007cf22010-01-22 22:29:16 +00002243/**
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002244 * \brief Describe the linkage of the entity referred to by a cursor.
2245 */
2246enum CXLinkageKind {
2247 /** \brief This value indicates that no linkage information is available
2248 * for a provided CXCursor. */
2249 CXLinkage_Invalid,
2250 /**
2251 * \brief This is the linkage for variables, parameters, and so on that
2252 * have automatic storage. This covers normal (non-extern) local variables.
2253 */
2254 CXLinkage_NoLinkage,
2255 /** \brief This is the linkage for static variables and static functions. */
2256 CXLinkage_Internal,
2257 /** \brief This is the linkage for entities with external linkage that live
2258 * in C++ anonymous namespaces.*/
2259 CXLinkage_UniqueExternal,
2260 /** \brief This is the linkage for entities with true, external linkage. */
2261 CXLinkage_External
2262};
2263
2264/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002265 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002266 */
2267CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2268
2269/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002270 * \brief Determine the availability of the entity that this cursor refers to,
2271 * taking the current target platform into account.
Douglas Gregorf757a122010-08-23 23:00:57 +00002272 *
2273 * \param cursor The cursor to query.
2274 *
2275 * \returns The availability of the cursor.
2276 */
2277CINDEX_LINKAGE enum CXAvailabilityKind
2278clang_getCursorAvailability(CXCursor cursor);
2279
2280/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002281 * Describes the availability of a given entity on a particular platform, e.g.,
2282 * a particular class might only be available on Mac OS 10.7 or newer.
2283 */
2284typedef struct CXPlatformAvailability {
2285 /**
2286 * \brief A string that describes the platform for which this structure
2287 * provides availability information.
2288 *
2289 * Possible values are "ios" or "macosx".
2290 */
2291 CXString Platform;
2292 /**
2293 * \brief The version number in which this entity was introduced.
2294 */
2295 CXVersion Introduced;
2296 /**
2297 * \brief The version number in which this entity was deprecated (but is
2298 * still available).
2299 */
2300 CXVersion Deprecated;
2301 /**
2302 * \brief The version number in which this entity was obsoleted, and therefore
2303 * is no longer available.
2304 */
2305 CXVersion Obsoleted;
2306 /**
2307 * \brief Whether the entity is unconditionally unavailable on this platform.
2308 */
2309 int Unavailable;
2310 /**
2311 * \brief An optional message to provide to a user of this API, e.g., to
2312 * suggest replacement APIs.
2313 */
2314 CXString Message;
2315} CXPlatformAvailability;
2316
2317/**
2318 * \brief Determine the availability of the entity that this cursor refers to
2319 * on any platforms for which availability information is known.
2320 *
2321 * \param cursor The cursor to query.
2322 *
2323 * \param always_deprecated If non-NULL, will be set to indicate whether the
2324 * entity is deprecated on all platforms.
2325 *
2326 * \param deprecated_message If non-NULL, will be set to the message text
2327 * provided along with the unconditional deprecation of this entity. The client
2328 * is responsible for deallocating this string.
2329 *
James Dennett574cb4c2012-06-15 05:41:51 +00002330 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregord6225d32012-05-08 00:14:45 +00002331 * entity is unavailable on all platforms.
2332 *
2333 * \param unavailable_message If non-NULL, will be set to the message text
2334 * provided along with the unconditional unavailability of this entity. The
2335 * client is responsible for deallocating this string.
2336 *
2337 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2338 * that will be populated with platform availability information, up to either
2339 * the number of platforms for which availability information is available (as
2340 * returned by this function) or \c availability_size, whichever is smaller.
2341 *
2342 * \param availability_size The number of elements available in the
2343 * \c availability array.
2344 *
2345 * \returns The number of platforms (N) for which availability information is
2346 * available (which is unrelated to \c availability_size).
2347 *
2348 * Note that the client is responsible for calling
2349 * \c clang_disposeCXPlatformAvailability to free each of the
2350 * platform-availability structures returned. There are
2351 * \c min(N, availability_size) such structures.
2352 */
2353CINDEX_LINKAGE int
2354clang_getCursorPlatformAvailability(CXCursor cursor,
2355 int *always_deprecated,
2356 CXString *deprecated_message,
2357 int *always_unavailable,
2358 CXString *unavailable_message,
2359 CXPlatformAvailability *availability,
2360 int availability_size);
2361
2362/**
2363 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2364 */
2365CINDEX_LINKAGE void
2366clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2367
2368/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002369 * \brief Describe the "language" of the entity referred to by a cursor.
2370 */
2371CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenekee457512010-04-14 20:58:32 +00002372 CXLanguage_Invalid = 0,
Ted Kremenek4ed29252010-04-12 21:22:16 +00002373 CXLanguage_C,
2374 CXLanguage_ObjC,
Ted Kremenekee457512010-04-14 20:58:32 +00002375 CXLanguage_CPlusPlus
Ted Kremenek4ed29252010-04-12 21:22:16 +00002376};
2377
2378/**
2379 * \brief Determine the "language" of the entity referred to by a given cursor.
2380 */
2381CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2382
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002383/**
2384 * \brief Returns the translation unit that a cursor originated from.
2385 */
2386CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2387
Ted Kremenekc0b98662013-04-24 07:17:12 +00002388
2389/**
2390 * \brief A fast container representing a set of CXCursors.
2391 */
2392typedef struct CXCursorSetImpl *CXCursorSet;
2393
2394/**
2395 * \brief Creates an empty CXCursorSet.
2396 */
2397CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2398
2399/**
2400 * \brief Disposes a CXCursorSet and releases its associated memory.
2401 */
2402CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2403
2404/**
2405 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2406 *
2407 * \returns non-zero if the set contains the specified cursor.
2408*/
2409CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2410 CXCursor cursor);
2411
2412/**
2413 * \brief Inserts a CXCursor into a CXCursorSet.
2414 *
2415 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2416*/
2417CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2418 CXCursor cursor);
2419
Douglas Gregor0576ce72010-09-22 21:22:29 +00002420/**
2421 * \brief Determine the semantic parent of the given cursor.
2422 *
2423 * The semantic parent of a cursor is the cursor that semantically contains
2424 * the given \p cursor. For many declarations, the lexical and semantic parents
2425 * are equivalent (the lexical parent is returned by
2426 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2427 * definitions are provided out-of-line. For example:
2428 *
2429 * \code
2430 * class C {
2431 * void f();
2432 * };
2433 *
2434 * void C::f() { }
2435 * \endcode
2436 *
2437 * In the out-of-line definition of \c C::f, the semantic parent is the
2438 * the class \c C, of which this function is a member. The lexical parent is
2439 * the place where the declaration actually occurs in the source code; in this
2440 * case, the definition occurs in the translation unit. In general, the
2441 * lexical parent for a given entity can change without affecting the semantics
2442 * of the program, and the lexical parent of different declarations of the
2443 * same entity may be different. Changing the semantic parent of a declaration,
2444 * on the other hand, can have a major impact on semantics, and redeclarations
2445 * of a particular entity should all have the same semantic context.
2446 *
2447 * In the example above, both declarations of \c C::f have \c C as their
2448 * semantic context, while the lexical context of the first \c C::f is \c C
2449 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002450 *
2451 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002452 */
2453CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2454
2455/**
2456 * \brief Determine the lexical parent of the given cursor.
2457 *
2458 * The lexical parent of a cursor is the cursor in which the given \p cursor
2459 * was actually written. For many declarations, the lexical and semantic parents
2460 * are equivalent (the semantic parent is returned by
2461 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2462 * definitions are provided out-of-line. For example:
2463 *
2464 * \code
2465 * class C {
2466 * void f();
2467 * };
2468 *
2469 * void C::f() { }
2470 * \endcode
2471 *
2472 * In the out-of-line definition of \c C::f, the semantic parent is the
2473 * the class \c C, of which this function is a member. The lexical parent is
2474 * the place where the declaration actually occurs in the source code; in this
2475 * case, the definition occurs in the translation unit. In general, the
2476 * lexical parent for a given entity can change without affecting the semantics
2477 * of the program, and the lexical parent of different declarations of the
2478 * same entity may be different. Changing the semantic parent of a declaration,
2479 * on the other hand, can have a major impact on semantics, and redeclarations
2480 * of a particular entity should all have the same semantic context.
2481 *
2482 * In the example above, both declarations of \c C::f have \c C as their
2483 * semantic context, while the lexical context of the first \c C::f is \c C
2484 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002485 *
2486 * For declarations written in the global scope, the lexical parent is
2487 * the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002488 */
2489CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor99a26af2010-10-01 20:25:15 +00002490
2491/**
2492 * \brief Determine the set of methods that are overridden by the given
2493 * method.
2494 *
2495 * In both Objective-C and C++, a method (aka virtual member function,
2496 * in C++) can override a virtual method in a base class. For
2497 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidisbfb24252012-03-08 00:20:03 +00002498 * base class, its protocols, or its categories' protocols, that has the same
2499 * selector and is of the same kind (class or instance).
2500 * If no such method exists, the search continues to the class's superclass,
2501 * its protocols, and its categories, and so on. A method from an Objective-C
2502 * implementation is considered to override the same methods as its
2503 * corresponding method in the interface.
Douglas Gregor99a26af2010-10-01 20:25:15 +00002504 *
2505 * For C++, a virtual member function overrides any virtual member
2506 * function with the same signature that occurs in its base
2507 * classes. With multiple inheritance, a virtual member function can
2508 * override several virtual member functions coming from different
2509 * base classes.
2510 *
2511 * In all cases, this function determines the immediate overridden
2512 * method, rather than all of the overridden methods. For example, if
2513 * a method is originally declared in a class A, then overridden in B
2514 * (which in inherits from A) and also in C (which inherited from B),
2515 * then the only overridden method returned from this function when
2516 * invoked on C's method will be B's method. The client may then
2517 * invoke this function again, given the previously-found overridden
2518 * methods, to map out the complete method-override set.
2519 *
2520 * \param cursor A cursor representing an Objective-C or C++
2521 * method. This routine will compute the set of methods that this
2522 * method overrides.
2523 *
2524 * \param overridden A pointer whose pointee will be replaced with a
2525 * pointer to an array of cursors, representing the set of overridden
2526 * methods. If there are no overridden methods, the pointee will be
2527 * set to NULL. The pointee must be freed via a call to
2528 * \c clang_disposeOverriddenCursors().
2529 *
2530 * \param num_overridden A pointer to the number of overridden
2531 * functions, will be set to the number of overridden functions in the
2532 * array pointed to by \p overridden.
2533 */
2534CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2535 CXCursor **overridden,
2536 unsigned *num_overridden);
2537
2538/**
2539 * \brief Free the set of overridden cursors returned by \c
2540 * clang_getOverriddenCursors().
2541 */
2542CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2543
Ted Kremenek4ed29252010-04-12 21:22:16 +00002544/**
Douglas Gregor796d76a2010-10-20 22:00:55 +00002545 * \brief Retrieve the file that is included by the given inclusion directive
2546 * cursor.
2547 */
2548CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2549
2550/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002551 * @}
2552 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002553
Douglas Gregor6007cf22010-01-22 22:29:16 +00002554/**
2555 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2556 *
2557 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2558 * routines help map between cursors and the physical locations where the
2559 * described entities occur in the source code. The mapping is provided in
2560 * both directions, so one can map from source code to the AST and back.
2561 *
2562 * @{
Steve Naroffa1c72842009-08-28 15:28:48 +00002563 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002564
Steve Naroff20bad0b2009-10-21 13:56:23 +00002565/**
Douglas Gregor816fd362010-01-22 21:44:22 +00002566 * \brief Map a source location to the cursor that describes the entity at that
2567 * location in the source code.
2568 *
2569 * clang_getCursor() maps an arbitrary source location within a translation
2570 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002571 * location. For example, given an expression \c x + y, invoking
Douglas Gregor816fd362010-01-22 21:44:22 +00002572 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002573 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregor816fd362010-01-22 21:44:22 +00002574 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2575 * will return a cursor referring to the "+" expression.
2576 *
2577 * \returns a cursor representing the entity at the given source location, or
2578 * a NULL cursor if no such entity can be found.
Steve Naroff20bad0b2009-10-21 13:56:23 +00002579 */
Douglas Gregor816fd362010-01-22 21:44:22 +00002580CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002581
Douglas Gregor66a58812010-01-18 22:46:11 +00002582/**
2583 * \brief Retrieve the physical location of the source constructor referenced
2584 * by the given cursor.
2585 *
2586 * The location of a declaration is typically the location of the name of that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002587 * declaration, where the name of that declaration would occur if it is
2588 * unnamed, or some keyword that introduces that particular declaration.
2589 * The location of a reference is where that reference occurs within the
Douglas Gregor66a58812010-01-18 22:46:11 +00002590 * source code.
2591 */
2592CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregor6007cf22010-01-22 22:29:16 +00002593
Douglas Gregor6b8232f2010-01-19 19:34:47 +00002594/**
2595 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002596 * the given cursor.
2597 *
2598 * The extent of a cursor starts with the file/line/column pointing at the
2599 * first character within the source construct that the cursor refers to and
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002600 * ends with the last character withinin that source construct. For a
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002601 * declaration, the extent covers the declaration itself. For a reference,
2602 * the extent covers the location of the reference (e.g., where the referenced
2603 * entity was actually used).
2604 */
2605CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorad27e8b2010-01-19 01:20:04 +00002606
Douglas Gregor6007cf22010-01-22 22:29:16 +00002607/**
2608 * @}
2609 */
Ted Kremeneka5940822010-08-26 01:42:22 +00002610
Douglas Gregor6007cf22010-01-22 22:29:16 +00002611/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002612 * \defgroup CINDEX_TYPES Type information for CXCursors
2613 *
2614 * @{
2615 */
2616
2617/**
2618 * \brief Describes the kind of type
2619 */
2620enum CXTypeKind {
2621 /**
2622 * \brief Reprents an invalid type (e.g., where no type is available).
2623 */
2624 CXType_Invalid = 0,
2625
2626 /**
2627 * \brief A type whose specific kind is not exposed via this
2628 * interface.
2629 */
2630 CXType_Unexposed = 1,
2631
2632 /* Builtin types */
2633 CXType_Void = 2,
2634 CXType_Bool = 3,
2635 CXType_Char_U = 4,
2636 CXType_UChar = 5,
2637 CXType_Char16 = 6,
2638 CXType_Char32 = 7,
2639 CXType_UShort = 8,
2640 CXType_UInt = 9,
2641 CXType_ULong = 10,
2642 CXType_ULongLong = 11,
2643 CXType_UInt128 = 12,
2644 CXType_Char_S = 13,
2645 CXType_SChar = 14,
2646 CXType_WChar = 15,
2647 CXType_Short = 16,
2648 CXType_Int = 17,
2649 CXType_Long = 18,
2650 CXType_LongLong = 19,
2651 CXType_Int128 = 20,
2652 CXType_Float = 21,
2653 CXType_Double = 22,
2654 CXType_LongDouble = 23,
2655 CXType_NullPtr = 24,
2656 CXType_Overload = 25,
2657 CXType_Dependent = 26,
2658 CXType_ObjCId = 27,
2659 CXType_ObjCClass = 28,
2660 CXType_ObjCSel = 29,
2661 CXType_FirstBuiltin = CXType_Void,
2662 CXType_LastBuiltin = CXType_ObjCSel,
2663
2664 CXType_Complex = 100,
2665 CXType_Pointer = 101,
2666 CXType_BlockPointer = 102,
2667 CXType_LValueReference = 103,
2668 CXType_RValueReference = 104,
2669 CXType_Record = 105,
2670 CXType_Enum = 106,
2671 CXType_Typedef = 107,
2672 CXType_ObjCInterface = 108,
Ted Kremenekc1508872010-06-21 20:15:39 +00002673 CXType_ObjCObjectPointer = 109,
2674 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002675 CXType_FunctionProto = 111,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002676 CXType_ConstantArray = 112,
Argyrios Kyrtzidis0661a712013-07-23 17:36:21 +00002677 CXType_Vector = 113,
2678 CXType_IncompleteArray = 114,
2679 CXType_VariableArray = 115,
2680 CXType_DependentSizedArray = 116
Ted Kremenek6bca9842010-05-14 21:29:26 +00002681};
2682
2683/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002684 * \brief Describes the calling convention of a function type
2685 */
2686enum CXCallingConv {
2687 CXCallingConv_Default = 0,
2688 CXCallingConv_C = 1,
2689 CXCallingConv_X86StdCall = 2,
2690 CXCallingConv_X86FastCall = 3,
2691 CXCallingConv_X86ThisCall = 4,
2692 CXCallingConv_X86Pascal = 5,
2693 CXCallingConv_AAPCS = 6,
2694 CXCallingConv_AAPCS_VFP = 7,
Derek Schuffa2020962012-10-16 22:30:41 +00002695 CXCallingConv_PnaclCall = 8,
Guy Benyeif0a014b2012-12-25 08:53:55 +00002696 CXCallingConv_IntelOclBicc = 9,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002697
2698 CXCallingConv_Invalid = 100,
2699 CXCallingConv_Unexposed = 200
2700};
2701
2702
2703/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002704 * \brief The type of an element in the abstract syntax tree.
2705 *
2706 */
2707typedef struct {
2708 enum CXTypeKind kind;
2709 void *data[2];
2710} CXType;
2711
2712/**
2713 * \brief Retrieve the type of a CXCursor (if any).
2714 */
2715CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2716
2717/**
Dmitri Gribenko00353722013-02-15 21:15:49 +00002718 * \brief Pretty-print the underlying type using the rules of the
2719 * language of the translation unit from which it came.
2720 *
2721 * If the type is invalid, an empty string is returned.
2722 */
2723CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2724
2725/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002726 * \brief Retrieve the underlying type of a typedef declaration.
2727 *
2728 * If the cursor does not reference a typedef declaration, an invalid type is
2729 * returned.
2730 */
2731CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2732
2733/**
2734 * \brief Retrieve the integer type of an enum declaration.
2735 *
2736 * If the cursor does not reference an enum declaration, an invalid type is
2737 * returned.
2738 */
2739CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2740
2741/**
2742 * \brief Retrieve the integer value of an enum constant declaration as a signed
2743 * long long.
2744 *
2745 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2746 * Since this is also potentially a valid constant value, the kind of the cursor
2747 * must be verified before calling this function.
2748 */
2749CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2750
2751/**
2752 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2753 * long long.
2754 *
2755 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2756 * Since this is also potentially a valid constant value, the kind of the cursor
2757 * must be verified before calling this function.
2758 */
2759CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2760
2761/**
Dmitri Gribenkob506ba12012-12-04 15:13:46 +00002762 * \brief Retrieve the bit width of a bit field declaration as an integer.
2763 *
2764 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2765 */
2766CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2767
2768/**
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002769 * \brief Retrieve the number of non-variadic arguments associated with a given
2770 * cursor.
2771 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002772 * The number of arguments can be determined for calls as well as for
2773 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002774 */
2775CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2776
2777/**
2778 * \brief Retrieve the argument cursor of a function or method.
2779 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002780 * The argument cursor can be determined for calls as well as for declarations
2781 * of functions or methods. For other cursors and for invalid indices, an
2782 * invalid cursor is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002783 */
2784CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2785
2786/**
James Dennett574cb4c2012-06-15 05:41:51 +00002787 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002788 *
James Dennett574cb4c2012-06-15 05:41:51 +00002789 * \returns non-zero if the CXTypes represent the same type and
2790 * zero otherwise.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002791 */
2792CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2793
2794/**
2795 * \brief Return the canonical type for a CXType.
2796 *
2797 * Clang's type system explicitly models typedefs and all the ways
2798 * a specific type can be represented. The canonical type is the underlying
2799 * type with all the "sugar" removed. For example, if 'T' is a typedef
2800 * for 'int', the canonical type for 'T' would be 'int'.
2801 */
2802CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2803
2804/**
James Dennett574cb4c2012-06-15 05:41:51 +00002805 * \brief Determine whether a CXType has the "const" qualifier set,
2806 * without looking through typedefs that may have added "const" at a
2807 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002808 */
2809CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2810
2811/**
James Dennett574cb4c2012-06-15 05:41:51 +00002812 * \brief Determine whether a CXType has the "volatile" qualifier set,
2813 * without looking through typedefs that may have added "volatile" at
2814 * a different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002815 */
2816CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2817
2818/**
James Dennett574cb4c2012-06-15 05:41:51 +00002819 * \brief Determine whether a CXType has the "restrict" qualifier set,
2820 * without looking through typedefs that may have added "restrict" at a
2821 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002822 */
2823CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2824
2825/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002826 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002827 */
2828CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2829
2830/**
2831 * \brief Return the cursor for the declaration of the given type.
2832 */
2833CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2834
David Chisnall50e4eba2010-12-30 14:05:53 +00002835/**
2836 * Returns the Objective-C type encoding for the specified declaration.
2837 */
2838CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek6bca9842010-05-14 21:29:26 +00002839
2840/**
2841 * \brief Retrieve the spelling of a given CXTypeKind.
2842 */
2843CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2844
2845/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002846 * \brief Retrieve the calling convention associated with a function type.
2847 *
2848 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2849 */
2850CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2851
2852/**
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00002853 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002854 *
2855 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenekc1508872010-06-21 20:15:39 +00002856 */
2857CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2858
2859/**
James Dennett574cb4c2012-06-15 05:41:51 +00002860 * \brief Retrieve the number of non-variadic arguments associated with a
2861 * function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002862 *
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002863 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002864 */
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002865CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002866
2867/**
2868 * \brief Retrieve the type of an argument of a function type.
2869 *
James Dennett574cb4c2012-06-15 05:41:51 +00002870 * If a non-function type is passed in or the function does not have enough
2871 * parameters, an invalid type is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002872 */
2873CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2874
2875/**
2876 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002877 */
2878CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2879
2880/**
2881 * \brief Retrieve the result type associated with a given cursor.
2882 *
2883 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00002884 */
2885CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2886
2887/**
Ted Kremenek0c7476a2010-07-30 00:14:11 +00002888 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2889 * otherwise.
2890 */
2891CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2892
2893/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002894 * \brief Return the element type of an array, complex, or vector type.
2895 *
2896 * If a type is passed in that is not an array, complex, or vector type,
2897 * an invalid type is returned.
2898 */
2899CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2900
2901/**
2902 * \brief Return the number of elements of an array or vector type.
2903 *
2904 * If a type is passed in that is not an array or vector type,
2905 * -1 is returned.
2906 */
2907CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2908
2909/**
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002910 * \brief Return the element type of an array type.
2911 *
2912 * If a non-array type is passed in, an invalid type is returned.
2913 */
2914CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2915
2916/**
Sylvestre Ledru830885c2012-07-23 08:59:39 +00002917 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002918 *
2919 * If a non-array type is passed in, -1 is returned.
2920 */
2921CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2922
2923/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00002924 * \brief List the possible error codes for \c clang_Type_getSizeOf,
2925 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
2926 * \c clang_Cursor_getOffsetOf.
2927 *
2928 * A value of this enumeration type can be returned if the target type is not
2929 * a valid argument to sizeof, alignof or offsetof.
2930 */
2931enum CXTypeLayoutError {
2932 /**
2933 * \brief Type is of kind CXType_Invalid.
2934 */
2935 CXTypeLayoutError_Invalid = -1,
2936 /**
2937 * \brief The type is an incomplete Type.
2938 */
2939 CXTypeLayoutError_Incomplete = -2,
2940 /**
2941 * \brief The type is a dependent Type.
2942 */
2943 CXTypeLayoutError_Dependent = -3,
2944 /**
2945 * \brief The type is not a constant size type.
2946 */
2947 CXTypeLayoutError_NotConstantSize = -4,
2948 /**
2949 * \brief The Field name is not valid for this record.
2950 */
2951 CXTypeLayoutError_InvalidFieldName = -5
2952};
2953
2954/**
2955 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
2956 * standard.
2957 *
2958 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2959 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2960 * is returned.
2961 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2962 * returned.
2963 * If the type declaration is not a constant size type,
2964 * CXTypeLayoutError_NotConstantSize is returned.
2965 */
2966CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
2967
2968/**
2969 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
2970 *
2971 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2972 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2973 * is returned.
2974 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2975 * returned.
2976 */
2977CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
2978
2979/**
2980 * \brief Return the offset of a field named S in a record of type T in bits
2981 * as it would be returned by __offsetof__ as per C++11[18.2p4]
2982 *
2983 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
2984 * is returned.
2985 * If the field's type declaration is an incomplete type,
2986 * CXTypeLayoutError_Incomplete is returned.
2987 * If the field's type declaration is a dependent type,
2988 * CXTypeLayoutError_Dependent is returned.
2989 * If the field's name S is not found,
2990 * CXTypeLayoutError_InvalidFieldName is returned.
2991 */
2992CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
2993
2994/**
2995 * \brief Returns non-zero if the cursor specifies a Record member that is a
2996 * bitfield.
2997 */
2998CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
2999
3000/**
Ted Kremenekae9e2212010-08-27 21:34:58 +00003001 * \brief Returns 1 if the base class specified by the cursor with kind
3002 * CX_CXXBaseSpecifier is virtual.
3003 */
3004CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3005
3006/**
3007 * \brief Represents the C++ access control level to a base class for a
3008 * cursor with kind CX_CXXBaseSpecifier.
3009 */
3010enum CX_CXXAccessSpecifier {
3011 CX_CXXInvalidAccessSpecifier,
3012 CX_CXXPublic,
3013 CX_CXXProtected,
3014 CX_CXXPrivate
3015};
3016
3017/**
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003018 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidisf6464082013-04-11 17:31:13 +00003019 *
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003020 * If the cursor refers to a C++ declaration, its access control level within its
3021 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3022 * access specifier, the specifier itself is returned.
Ted Kremenekae9e2212010-08-27 21:34:58 +00003023 */
3024CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3025
3026/**
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00003027 * \brief Determine the number of overloaded declarations referenced by a
3028 * \c CXCursor_OverloadedDeclRef cursor.
3029 *
3030 * \param cursor The cursor whose overloaded declarations are being queried.
3031 *
3032 * \returns The number of overloaded declarations referenced by \c cursor. If it
3033 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3034 */
3035CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3036
3037/**
3038 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3039 * by a \c CXCursor_OverloadedDeclRef cursor.
3040 *
3041 * \param cursor The cursor whose overloaded declarations are being queried.
3042 *
3043 * \param index The zero-based index into the set of overloaded declarations in
3044 * the cursor.
3045 *
3046 * \returns A cursor representing the declaration referenced by the given
3047 * \c cursor at the specified \c index. If the cursor does not have an
3048 * associated set of overloaded declarations, or if the index is out of bounds,
3049 * returns \c clang_getNullCursor();
3050 */
3051CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3052 unsigned index);
3053
3054/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00003055 * @}
3056 */
Ted Kremeneka5940822010-08-26 01:42:22 +00003057
3058/**
Ted Kremenek2c2c5f32010-08-27 21:34:51 +00003059 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremeneka5940822010-08-26 01:42:22 +00003060 *
3061 * @{
3062 */
3063
3064
3065/**
3066 * \brief For cursors representing an iboutletcollection attribute,
3067 * this function returns the collection element type.
3068 *
3069 */
3070CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3071
3072/**
3073 * @}
3074 */
Ted Kremenek6bca9842010-05-14 21:29:26 +00003075
3076/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003077 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3078 *
3079 * These routines provide the ability to traverse the abstract syntax tree
3080 * using cursors.
3081 *
3082 * @{
3083 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003084
Douglas Gregor6007cf22010-01-22 22:29:16 +00003085/**
3086 * \brief Describes how the traversal of the children of a particular
3087 * cursor should proceed after visiting a particular child cursor.
3088 *
3089 * A value of this enumeration type should be returned by each
3090 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3091 */
3092enum CXChildVisitResult {
3093 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003094 * \brief Terminates the cursor traversal.
Douglas Gregor6007cf22010-01-22 22:29:16 +00003095 */
3096 CXChildVisit_Break,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003097 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003098 * \brief Continues the cursor traversal with the next sibling of
3099 * the cursor just visited, without visiting its children.
3100 */
3101 CXChildVisit_Continue,
3102 /**
3103 * \brief Recursively traverse the children of this cursor, using
3104 * the same visitor and client data.
3105 */
3106 CXChildVisit_Recurse
3107};
3108
3109/**
3110 * \brief Visitor invoked for each cursor found by a traversal.
3111 *
3112 * This visitor function will be invoked for each cursor found by
3113 * clang_visitCursorChildren(). Its first argument is the cursor being
3114 * visited, its second argument is the parent visitor for that cursor,
3115 * and its third argument is the client data provided to
3116 * clang_visitCursorChildren().
3117 *
3118 * The visitor should return one of the \c CXChildVisitResult values
3119 * to direct clang_visitCursorChildren().
3120 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003121typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3122 CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003123 CXClientData client_data);
3124
3125/**
3126 * \brief Visit the children of a particular cursor.
3127 *
3128 * This function visits all the direct children of the given cursor,
3129 * invoking the given \p visitor function with the cursors of each
3130 * visited child. The traversal may be recursive, if the visitor returns
3131 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3132 * the visitor returns \c CXChildVisit_Break.
3133 *
Douglas Gregor6007cf22010-01-22 22:29:16 +00003134 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbarb9999fd2010-01-24 04:10:31 +00003135 * cursors can be visited, including invalid cursors (which, by
Douglas Gregor6007cf22010-01-22 22:29:16 +00003136 * definition, have no children).
3137 *
3138 * \param visitor the visitor function that will be invoked for each
3139 * child of \p parent.
3140 *
3141 * \param client_data pointer data supplied by the client, which will
3142 * be passed to the visitor each time it is invoked.
3143 *
3144 * \returns a non-zero value if the traversal was terminated
3145 * prematurely by the visitor returning \c CXChildVisit_Break.
3146 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003147CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003148 CXCursorVisitor visitor,
3149 CXClientData client_data);
David Chisnallb2aa0ef2010-11-03 14:12:26 +00003150#ifdef __has_feature
3151# if __has_feature(blocks)
3152/**
3153 * \brief Visitor invoked for each cursor found by a traversal.
3154 *
3155 * This visitor block will be invoked for each cursor found by
3156 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3157 * visited, its second argument is the parent visitor for that cursor.
3158 *
3159 * The visitor should return one of the \c CXChildVisitResult values
3160 * to direct clang_visitChildrenWithBlock().
3161 */
3162typedef enum CXChildVisitResult
3163 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3164
3165/**
3166 * Visits the children of a cursor using the specified block. Behaves
3167 * identically to clang_visitChildren() in all other respects.
3168 */
3169unsigned clang_visitChildrenWithBlock(CXCursor parent,
3170 CXCursorVisitorBlock block);
3171# endif
3172#endif
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003173
Douglas Gregor6007cf22010-01-22 22:29:16 +00003174/**
3175 * @}
3176 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003177
Douglas Gregor6007cf22010-01-22 22:29:16 +00003178/**
3179 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3180 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003181 * These routines provide the ability to determine references within and
Douglas Gregor6007cf22010-01-22 22:29:16 +00003182 * across translation units, by providing the names of the entities referenced
3183 * by cursors, follow reference cursors to the declarations they reference,
3184 * and associate declarations with their definitions.
3185 *
3186 * @{
3187 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003188
Douglas Gregor6007cf22010-01-22 22:29:16 +00003189/**
3190 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3191 * by the given cursor.
3192 *
3193 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3194 * entity (function, class, variable, etc.) within a program. USRs can be
3195 * compared across translation units to determine, e.g., when references in
3196 * one translation refer to an entity defined in another translation unit.
3197 */
3198CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3199
3200/**
Ted Kremenekd071c602010-03-13 02:50:34 +00003201 * \brief Construct a USR for a specified Objective-C class.
3202 */
3203CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3204
3205/**
3206 * \brief Construct a USR for a specified Objective-C category.
3207 */
3208CINDEX_LINKAGE CXString
Ted Kremenekbc1a67b2010-03-15 17:38:58 +00003209 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenekd071c602010-03-13 02:50:34 +00003210 const char *category_name);
3211
3212/**
3213 * \brief Construct a USR for a specified Objective-C protocol.
3214 */
3215CINDEX_LINKAGE CXString
3216 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3217
3218
3219/**
3220 * \brief Construct a USR for a specified Objective-C instance variable and
3221 * the USR for its containing class.
3222 */
3223CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3224 CXString classUSR);
3225
3226/**
3227 * \brief Construct a USR for a specified Objective-C method and
3228 * the USR for its containing class.
3229 */
3230CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3231 unsigned isInstanceMethod,
3232 CXString classUSR);
3233
3234/**
3235 * \brief Construct a USR for a specified Objective-C property and the USR
3236 * for its containing class.
3237 */
3238CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3239 CXString classUSR);
3240
3241/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003242 * \brief Retrieve a name for the entity referenced by this cursor.
3243 */
3244CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3245
Douglas Gregor97c75712010-10-02 22:49:11 +00003246/**
Argyrios Kyrtzidis191a6a82012-03-30 20:58:35 +00003247 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3248 * Most of the times there is only one range for the complete spelling but for
3249 * objc methods and objc message expressions, there are multiple pieces for each
3250 * selector identifier.
3251 *
3252 * \param pieceIndex the index of the spelling name piece. If this is greater
3253 * than the actual number of pieces, it will return a NULL (invalid) range.
3254 *
3255 * \param options Reserved.
3256 */
3257CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3258 unsigned pieceIndex,
3259 unsigned options);
3260
3261/**
Douglas Gregor97c75712010-10-02 22:49:11 +00003262 * \brief Retrieve the display name for the entity referenced by this cursor.
3263 *
3264 * The display name contains extra information that helps identify the cursor,
3265 * such as the parameters of a function or template or the arguments of a
3266 * class template specialization.
3267 */
3268CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3269
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003270/** \brief For a cursor that is a reference, retrieve a cursor representing the
3271 * entity that it references.
3272 *
3273 * Reference cursors refer to other entities in the AST. For example, an
3274 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003275 * This function produces the cursor for the Objective-C class from the
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003276 * cursor for the superclass reference. If the input cursor is a declaration or
3277 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003278 * Otherwise, returns the NULL cursor.
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003279 */
3280CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003281
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003282/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003283 * \brief For a cursor that is either a reference to or a declaration
3284 * of some entity, retrieve a cursor that describes the definition of
3285 * that entity.
3286 *
3287 * Some entities can be declared multiple times within a translation
3288 * unit, but only one of those declarations can also be a
3289 * definition. For example, given:
3290 *
3291 * \code
3292 * int f(int, int);
3293 * int g(int x, int y) { return f(x, y); }
3294 * int f(int a, int b) { return a + b; }
3295 * int f(int, int);
3296 * \endcode
3297 *
3298 * there are three declarations of the function "f", but only the
3299 * second one is a definition. The clang_getCursorDefinition()
3300 * function will take any cursor pointing to a declaration of "f"
3301 * (the first or fourth lines of the example) or a cursor referenced
3302 * that uses "f" (the call to "f' inside "g") and will return a
3303 * declaration cursor pointing to the definition (the second "f"
3304 * declaration).
3305 *
3306 * If given a cursor for which there is no corresponding definition,
3307 * e.g., because there is no definition of that entity within this
3308 * translation unit, returns a NULL cursor.
3309 */
3310CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3311
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003312/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003313 * \brief Determine whether the declaration pointed to by this cursor
3314 * is also a definition of that entity.
3315 */
3316CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3317
Douglas Gregor6007cf22010-01-22 22:29:16 +00003318/**
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003319 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3320 *
3321 * In the C family of languages, many kinds of entities can be declared several
3322 * times within a single translation unit. For example, a structure type can
3323 * be forward-declared (possibly multiple times) and later defined:
3324 *
3325 * \code
3326 * struct X;
3327 * struct X;
3328 * struct X {
3329 * int member;
3330 * };
3331 * \endcode
3332 *
3333 * The declarations and the definition of \c X are represented by three
3334 * different cursors, all of which are declarations of the same underlying
3335 * entity. One of these cursor is considered the "canonical" cursor, which
3336 * is effectively the representative for the underlying entity. One can
3337 * determine if two cursors are declarations of the same underlying entity by
3338 * comparing their canonical cursors.
3339 *
3340 * \returns The canonical cursor for the entity referred to by the given cursor.
3341 */
3342CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3343
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003344
3345/**
3346 * \brief If the cursor points to a selector identifier in a objc method or
3347 * message expression, this returns the selector index.
3348 *
James Dennett574cb4c2012-06-15 05:41:51 +00003349 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003350 * determine if the location points to a selector identifier.
3351 *
3352 * \returns The selector index if the cursor is an objc method or message
3353 * expression and the cursor is pointing to a selector identifier, or -1
3354 * otherwise.
3355 */
3356CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3357
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003358/**
Argyrios Kyrtzidisb6df68212012-07-02 23:54:36 +00003359 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3360 * returns non-zero if the method/message is "dynamic", meaning:
3361 *
3362 * For a C++ method: the call is virtual.
3363 * For an ObjC message: the receiver is an object instance, not 'super' or a
3364 * specific class.
3365 *
3366 * If the method/message is "static" or the cursor does not point to a
3367 * method/message, it will return zero.
3368 */
3369CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3370
3371/**
Argyrios Kyrtzidisb26a24c2012-11-01 02:01:34 +00003372 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3373 * receiver.
3374 */
3375CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3376
3377/**
Argyrios Kyrtzidis9adfd8a2013-04-18 22:15:49 +00003378 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3379 */
3380typedef enum {
3381 CXObjCPropertyAttr_noattr = 0x00,
3382 CXObjCPropertyAttr_readonly = 0x01,
3383 CXObjCPropertyAttr_getter = 0x02,
3384 CXObjCPropertyAttr_assign = 0x04,
3385 CXObjCPropertyAttr_readwrite = 0x08,
3386 CXObjCPropertyAttr_retain = 0x10,
3387 CXObjCPropertyAttr_copy = 0x20,
3388 CXObjCPropertyAttr_nonatomic = 0x40,
3389 CXObjCPropertyAttr_setter = 0x80,
3390 CXObjCPropertyAttr_atomic = 0x100,
3391 CXObjCPropertyAttr_weak = 0x200,
3392 CXObjCPropertyAttr_strong = 0x400,
3393 CXObjCPropertyAttr_unsafe_unretained = 0x800
3394} CXObjCPropertyAttrKind;
3395
3396/**
3397 * \brief Given a cursor that represents a property declaration, return the
3398 * associated property attributes. The bits are formed from
3399 * \c CXObjCPropertyAttrKind.
3400 *
3401 * \param reserved Reserved for future use, pass 0.
3402 */
3403CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3404 unsigned reserved);
3405
3406/**
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003407 * \brief 'Qualifiers' written next to the return and parameter types in
3408 * ObjC method declarations.
3409 */
3410typedef enum {
3411 CXObjCDeclQualifier_None = 0x0,
3412 CXObjCDeclQualifier_In = 0x1,
3413 CXObjCDeclQualifier_Inout = 0x2,
3414 CXObjCDeclQualifier_Out = 0x4,
3415 CXObjCDeclQualifier_Bycopy = 0x8,
3416 CXObjCDeclQualifier_Byref = 0x10,
3417 CXObjCDeclQualifier_Oneway = 0x20
3418} CXObjCDeclQualifierKind;
3419
3420/**
3421 * \brief Given a cursor that represents an ObjC method or parameter
3422 * declaration, return the associated ObjC qualifiers for the return type or the
Argyrios Kyrtzidis982934e2013-04-19 00:51:52 +00003423 * parameter respectively. The bits are formed from CXObjCDeclQualifierKind.
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003424 */
3425CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3426
3427/**
Argyrios Kyrtzidis7b50fc52013-07-05 20:44:37 +00003428 * \brief Given a cursor that represents an ObjC method or property declaration,
3429 * return non-zero if the declaration was affected by "@optional".
3430 * Returns zero if the cursor is not such a declaration or it is "@required".
3431 */
3432CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
3433
3434/**
Argyrios Kyrtzidis23814e42013-04-18 23:53:05 +00003435 * \brief Returns non-zero if the given cursor is a variadic function or method.
3436 */
3437CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3438
3439/**
Dmitri Gribenkoaab83832012-06-20 00:34:58 +00003440 * \brief Given a cursor that represents a declaration, return the associated
3441 * comment's source range. The range may include multiple consecutive comments
3442 * with whitespace in between.
3443 */
3444CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3445
3446/**
3447 * \brief Given a cursor that represents a declaration, return the associated
3448 * comment text, including comment markers.
3449 */
3450CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3451
3452/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003453 * \brief Given a cursor that represents a documentable entity (e.g.,
3454 * declaration), return the associated \\brief paragraph; otherwise return the
3455 * first paragraph.
Dmitri Gribenko5188c4b2012-06-26 20:39:18 +00003456 */
3457CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3458
3459/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003460 * \brief Given a cursor that represents a documentable entity (e.g.,
3461 * declaration), return the associated parsed comment as a
3462 * \c CXComment_FullComment AST node.
3463 */
3464CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3465
3466/**
3467 * @}
3468 */
3469
3470/**
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003471 * \defgroup CINDEX_MODULE Module introspection
3472 *
3473 * The functions in this group provide access to information about modules.
3474 *
3475 * @{
3476 */
3477
3478typedef void *CXModule;
3479
3480/**
3481 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3482 */
3483CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3484
3485/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003486 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003487 *
Argyrios Kyrtzidis12fdb9e2013-04-26 22:47:49 +00003488 * \returns the module file where the provided module object came from.
3489 */
3490CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3491
3492/**
3493 * \param Module a module object.
3494 *
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003495 * \returns the parent of a sub-module or NULL if the given module is top-level,
3496 * e.g. for 'std.vector' it will return the 'std' module.
3497 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003498CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003499
3500/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003501 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003502 *
3503 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3504 * will return "vector".
3505 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003506CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003507
3508/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003509 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003510 *
3511 * \returns the full name of the module, e.g. "std.vector".
3512 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003513CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003514
3515/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003516 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003517 *
3518 * \returns the number of top level headers associated with this module.
3519 */
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003520CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3521 CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003522
3523/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003524 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003525 *
3526 * \param Index top level header index (zero-based).
3527 *
3528 * \returns the specified top level header associated with the module.
3529 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003530CINDEX_LINKAGE
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003531CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3532 CXModule Module, unsigned Index);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003533
3534/**
3535 * @}
3536 */
3537
3538/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003539 * \defgroup CINDEX_COMMENT Comment AST introspection
3540 *
3541 * The routines in this group provide access to information in the
3542 * documentation comment ASTs.
3543 *
3544 * @{
3545 */
3546
3547/**
3548 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3549 * node can be considered block content (e. g., paragraph), inline content
3550 * (plain text) or neither (the root AST node).
3551 */
3552enum CXCommentKind {
3553 /**
3554 * \brief Null comment. No AST node is constructed at the requested location
3555 * because there is no text or a syntax error.
3556 */
3557 CXComment_Null = 0,
3558
3559 /**
3560 * \brief Plain text. Inline content.
3561 */
3562 CXComment_Text = 1,
3563
3564 /**
3565 * \brief A command with word-like arguments that is considered inline content.
3566 *
3567 * For example: \\c command.
3568 */
3569 CXComment_InlineCommand = 2,
3570
3571 /**
3572 * \brief HTML start tag with attributes (name-value pairs). Considered
3573 * inline content.
3574 *
3575 * For example:
3576 * \verbatim
3577 * <br> <br /> <a href="http://example.org/">
3578 * \endverbatim
3579 */
3580 CXComment_HTMLStartTag = 3,
3581
3582 /**
3583 * \brief HTML end tag. Considered inline content.
3584 *
3585 * For example:
3586 * \verbatim
3587 * </a>
3588 * \endverbatim
3589 */
3590 CXComment_HTMLEndTag = 4,
3591
3592 /**
3593 * \brief A paragraph, contains inline comment. The paragraph itself is
3594 * block content.
3595 */
3596 CXComment_Paragraph = 5,
3597
3598 /**
3599 * \brief A command that has zero or more word-like arguments (number of
3600 * word-like arguments depends on command name) and a paragraph as an
3601 * argument. Block command is block content.
3602 *
3603 * Paragraph argument is also a child of the block command.
3604 *
3605 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3606 *
3607 * AST nodes of special kinds that parser knows about (e. g., \\param
3608 * command) have their own node kinds.
3609 */
3610 CXComment_BlockCommand = 6,
3611
3612 /**
3613 * \brief A \\param or \\arg command that describes the function parameter
3614 * (name, passing direction, description).
3615 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003616 * For example: \\param [in] ParamName description.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003617 */
3618 CXComment_ParamCommand = 7,
3619
3620 /**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003621 * \brief A \\tparam command that describes a template parameter (name and
3622 * description).
3623 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003624 * For example: \\tparam T description.
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003625 */
3626 CXComment_TParamCommand = 8,
3627
3628 /**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003629 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3630 * block has an opening and a closing command and contains multiple lines of
3631 * text (\c CXComment_VerbatimBlockLine child nodes).
3632 *
3633 * For example:
3634 * \\verbatim
3635 * aaa
3636 * \\endverbatim
3637 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003638 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003639
3640 /**
3641 * \brief A line of text that is contained within a
3642 * CXComment_VerbatimBlockCommand node.
3643 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003644 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003645
3646 /**
3647 * \brief A verbatim line command. Verbatim line has an opening command,
3648 * a single line of text (up to the newline after the opening command) and
3649 * has no closing command.
3650 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003651 CXComment_VerbatimLine = 11,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003652
3653 /**
3654 * \brief A full comment attached to a declaration, contains block content.
3655 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003656 CXComment_FullComment = 12
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003657};
3658
3659/**
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003660 * \brief The most appropriate rendering mode for an inline command, chosen on
3661 * command semantics in Doxygen.
3662 */
3663enum CXCommentInlineCommandRenderKind {
3664 /**
3665 * \brief Command argument should be rendered in a normal font.
3666 */
3667 CXCommentInlineCommandRenderKind_Normal,
3668
3669 /**
3670 * \brief Command argument should be rendered in a bold font.
3671 */
3672 CXCommentInlineCommandRenderKind_Bold,
3673
3674 /**
3675 * \brief Command argument should be rendered in a monospaced font.
3676 */
3677 CXCommentInlineCommandRenderKind_Monospaced,
3678
3679 /**
3680 * \brief Command argument should be rendered emphasized (typically italic
3681 * font).
3682 */
3683 CXCommentInlineCommandRenderKind_Emphasized
3684};
3685
3686/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003687 * \brief Describes parameter passing direction for \\param or \\arg command.
3688 */
3689enum CXCommentParamPassDirection {
3690 /**
3691 * \brief The parameter is an input parameter.
3692 */
3693 CXCommentParamPassDirection_In,
3694
3695 /**
3696 * \brief The parameter is an output parameter.
3697 */
3698 CXCommentParamPassDirection_Out,
3699
3700 /**
3701 * \brief The parameter is an input and output parameter.
3702 */
3703 CXCommentParamPassDirection_InOut
3704};
3705
3706/**
3707 * \param Comment AST node of any kind.
3708 *
3709 * \returns the type of the AST node.
3710 */
3711CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3712
3713/**
3714 * \param Comment AST node of any kind.
3715 *
3716 * \returns number of children of the AST node.
3717 */
3718CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3719
3720/**
3721 * \param Comment AST node of any kind.
3722 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003723 * \param ChildIdx child index (zero-based).
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003724 *
3725 * \returns the specified child of the AST node.
3726 */
3727CINDEX_LINKAGE
3728CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3729
3730/**
3731 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3732 * only \c CXComment_Text nodes that are empty or whitespace.
3733 *
3734 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3735 * never considered whitespace.
3736 *
3737 * \returns non-zero if \c Comment is whitespace.
3738 */
3739CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3740
3741/**
3742 * \returns non-zero if \c Comment is inline content and has a newline
3743 * immediately following it in the comment text. Newlines between paragraphs
3744 * do not count.
3745 */
3746CINDEX_LINKAGE
3747unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3748
3749/**
3750 * \param Comment a \c CXComment_Text AST node.
3751 *
3752 * \returns text contained in the AST node.
3753 */
3754CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3755
3756/**
3757 * \param Comment a \c CXComment_InlineCommand AST node.
3758 *
3759 * \returns name of the inline command.
3760 */
3761CINDEX_LINKAGE
3762CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3763
3764/**
3765 * \param Comment a \c CXComment_InlineCommand AST node.
3766 *
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003767 * \returns the most appropriate rendering mode, chosen on command
3768 * semantics in Doxygen.
3769 */
3770CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3771clang_InlineCommandComment_getRenderKind(CXComment Comment);
3772
3773/**
3774 * \param Comment a \c CXComment_InlineCommand AST node.
3775 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003776 * \returns number of command arguments.
3777 */
3778CINDEX_LINKAGE
3779unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3780
3781/**
3782 * \param Comment a \c CXComment_InlineCommand AST node.
3783 *
3784 * \param ArgIdx argument index (zero-based).
3785 *
3786 * \returns text of the specified argument.
3787 */
3788CINDEX_LINKAGE
3789CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3790 unsigned ArgIdx);
3791
3792/**
3793 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3794 * node.
3795 *
3796 * \returns HTML tag name.
3797 */
3798CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3799
3800/**
3801 * \param Comment a \c CXComment_HTMLStartTag AST node.
3802 *
3803 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3804 */
3805CINDEX_LINKAGE
3806unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3807
3808/**
3809 * \param Comment a \c CXComment_HTMLStartTag AST node.
3810 *
3811 * \returns number of attributes (name-value pairs) attached to the start tag.
3812 */
3813CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3814
3815/**
3816 * \param Comment a \c CXComment_HTMLStartTag AST node.
3817 *
3818 * \param AttrIdx attribute index (zero-based).
3819 *
3820 * \returns name of the specified attribute.
3821 */
3822CINDEX_LINKAGE
3823CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3824
3825/**
3826 * \param Comment a \c CXComment_HTMLStartTag AST node.
3827 *
3828 * \param AttrIdx attribute index (zero-based).
3829 *
3830 * \returns value of the specified attribute.
3831 */
3832CINDEX_LINKAGE
3833CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3834
3835/**
3836 * \param Comment a \c CXComment_BlockCommand AST node.
3837 *
3838 * \returns name of the block command.
3839 */
3840CINDEX_LINKAGE
3841CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3842
3843/**
3844 * \param Comment a \c CXComment_BlockCommand AST node.
3845 *
3846 * \returns number of word-like arguments.
3847 */
3848CINDEX_LINKAGE
3849unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3850
3851/**
3852 * \param Comment a \c CXComment_BlockCommand AST node.
3853 *
3854 * \param ArgIdx argument index (zero-based).
3855 *
3856 * \returns text of the specified word-like argument.
3857 */
3858CINDEX_LINKAGE
3859CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3860 unsigned ArgIdx);
3861
3862/**
3863 * \param Comment a \c CXComment_BlockCommand or
3864 * \c CXComment_VerbatimBlockCommand AST node.
3865 *
3866 * \returns paragraph argument of the block command.
3867 */
3868CINDEX_LINKAGE
3869CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3870
3871/**
3872 * \param Comment a \c CXComment_ParamCommand AST node.
3873 *
3874 * \returns parameter name.
3875 */
3876CINDEX_LINKAGE
3877CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3878
3879/**
3880 * \param Comment a \c CXComment_ParamCommand AST node.
3881 *
3882 * \returns non-zero if the parameter that this AST node represents was found
3883 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3884 * function will return a meaningful value.
3885 */
3886CINDEX_LINKAGE
3887unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3888
3889/**
3890 * \param Comment a \c CXComment_ParamCommand AST node.
3891 *
3892 * \returns zero-based parameter index in function prototype.
3893 */
3894CINDEX_LINKAGE
3895unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3896
3897/**
3898 * \param Comment a \c CXComment_ParamCommand AST node.
3899 *
3900 * \returns non-zero if parameter passing direction was specified explicitly in
3901 * the comment.
3902 */
3903CINDEX_LINKAGE
3904unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3905
3906/**
3907 * \param Comment a \c CXComment_ParamCommand AST node.
3908 *
3909 * \returns parameter passing direction.
3910 */
3911CINDEX_LINKAGE
3912enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
3913 CXComment Comment);
3914
3915/**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003916 * \param Comment a \c CXComment_TParamCommand AST node.
3917 *
3918 * \returns template parameter name.
3919 */
3920CINDEX_LINKAGE
3921CXString clang_TParamCommandComment_getParamName(CXComment Comment);
3922
3923/**
3924 * \param Comment a \c CXComment_TParamCommand AST node.
3925 *
3926 * \returns non-zero if the parameter that this AST node represents was found
3927 * in the template parameter list and
3928 * \c clang_TParamCommandComment_getDepth and
3929 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
3930 * value.
3931 */
3932CINDEX_LINKAGE
3933unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
3934
3935/**
3936 * \param Comment a \c CXComment_TParamCommand AST node.
3937 *
3938 * \returns zero-based nesting depth of this parameter in the template parameter list.
3939 *
3940 * For example,
3941 * \verbatim
3942 * template<typename C, template<typename T> class TT>
3943 * void test(TT<int> aaa);
3944 * \endverbatim
3945 * for C and TT nesting depth is 0,
3946 * for T nesting depth is 1.
3947 */
3948CINDEX_LINKAGE
3949unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
3950
3951/**
3952 * \param Comment a \c CXComment_TParamCommand AST node.
3953 *
3954 * \returns zero-based parameter index in the template parameter list at a
3955 * given nesting depth.
3956 *
3957 * For example,
3958 * \verbatim
3959 * template<typename C, template<typename T> class TT>
3960 * void test(TT<int> aaa);
3961 * \endverbatim
3962 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
3963 * at depth 0 C's index is 0, TT's index is 1.
3964 *
3965 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
3966 * at depth 0 T's index is 1 (same as TT's),
3967 * at depth 1 T's index is 0.
3968 */
3969CINDEX_LINKAGE
3970unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
3971
3972/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003973 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
3974 *
3975 * \returns text contained in the AST node.
3976 */
3977CINDEX_LINKAGE
3978CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
3979
3980/**
3981 * \param Comment a \c CXComment_VerbatimLine AST node.
3982 *
3983 * \returns text contained in the AST node.
3984 */
3985CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
3986
3987/**
3988 * \brief Convert an HTML tag AST node to string.
3989 *
3990 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3991 * node.
3992 *
3993 * \returns string containing an HTML tag.
3994 */
3995CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
3996
3997/**
3998 * \brief Convert a given full parsed comment to an HTML fragment.
3999 *
4000 * Specific details of HTML layout are subject to change. Don't try to parse
4001 * this HTML back into an AST, use other APIs instead.
4002 *
4003 * Currently the following CSS classes are used:
4004 * \li "para-brief" for \\brief paragraph and equivalent commands;
4005 * \li "para-returns" for \\returns paragraph and equivalent commands;
4006 * \li "word-returns" for the "Returns" word in \\returns paragraph.
4007 *
Dmitri Gribenko4c6d7a22012-07-21 01:47:43 +00004008 * Function argument documentation is rendered as a \<dl\> list with arguments
4009 * sorted in function prototype order. CSS classes used:
4010 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
4011 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
4012 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
4013 * parameter index is invalid.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004014 *
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004015 * Template parameter documentation is rendered as a \<dl\> list with
4016 * parameters sorted in template parameter list order. CSS classes used:
4017 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
4018 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko58e41312012-08-01 23:47:30 +00004019 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004020 * names inside template template parameters;
4021 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
4022 * parameter position is invalid.
4023 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004024 * \param Comment a \c CXComment_FullComment AST node.
4025 *
4026 * \returns string containing an HTML fragment.
4027 */
4028CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
4029
4030/**
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004031 * \brief Convert a given full parsed comment to an XML document.
4032 *
4033 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
4034 * inside clang source tree.
4035 *
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004036 * \param Comment a \c CXComment_FullComment AST node.
4037 *
4038 * \returns string containing an XML document.
4039 */
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00004040CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004041
4042/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004043 * @}
4044 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004045
Douglas Gregor6007cf22010-01-22 22:29:16 +00004046/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004047 * \defgroup CINDEX_CPP C++ AST introspection
4048 *
4049 * The routines in this group provide access information in the ASTs specific
4050 * to C++ language features.
4051 *
4052 * @{
4053 */
4054
4055/**
Dmitri Gribenko62770be2013-05-17 18:38:35 +00004056 * \brief Determine if a C++ member function or member function template is
4057 * pure virtual.
4058 */
4059CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4060
4061/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004062 * \brief Determine if a C++ member function or member function template is
4063 * declared 'static'.
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004064 */
4065CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4066
4067/**
Douglas Gregor9519d922011-05-12 15:17:24 +00004068 * \brief Determine if a C++ member function or member function template is
4069 * explicitly declared 'virtual' or if it overrides a virtual method from
4070 * one of the base classes.
4071 */
4072CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4073
4074/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004075 * \brief Given a cursor that represents a template, determine
4076 * the cursor kind of the specializations would be generated by instantiating
4077 * the template.
4078 *
4079 * This routine can be used to determine what flavor of function template,
4080 * class template, or class template partial specialization is stored in the
4081 * cursor. For example, it can describe whether a class template cursor is
4082 * declared with "struct", "class" or "union".
4083 *
4084 * \param C The cursor to query. This cursor should represent a template
4085 * declaration.
4086 *
4087 * \returns The cursor kind of the specializations that would be generated
4088 * by instantiating the template \p C. If \p C is not a template, returns
4089 * \c CXCursor_NoDeclFound.
4090 */
4091CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4092
4093/**
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004094 * \brief Given a cursor that may represent a specialization or instantiation
4095 * of a template, retrieve the cursor that represents the template that it
4096 * specializes or from which it was instantiated.
4097 *
4098 * This routine determines the template involved both for explicit
4099 * specializations of templates and for implicit instantiations of the template,
4100 * both of which are referred to as "specializations". For a class template
4101 * specialization (e.g., \c std::vector<bool>), this routine will return
4102 * either the primary template (\c std::vector) or, if the specialization was
4103 * instantiated from a class template partial specialization, the class template
4104 * partial specialization. For a class template partial specialization and a
4105 * function template specialization (including instantiations), this
4106 * this routine will return the specialized template.
4107 *
4108 * For members of a class template (e.g., member functions, member classes, or
4109 * static data members), returns the specialized or instantiated member.
4110 * Although not strictly "templates" in the C++ language, members of class
4111 * templates have the same notions of specializations and instantiations that
4112 * templates do, so this routine treats them similarly.
4113 *
4114 * \param C A cursor that may be a specialization of a template or a member
4115 * of a template.
4116 *
4117 * \returns If the given cursor is a specialization or instantiation of a
4118 * template or a member thereof, the template or member that it specializes or
4119 * from which it was instantiated. Otherwise, returns a NULL cursor.
4120 */
4121CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004122
4123/**
4124 * \brief Given a cursor that references something else, return the source range
4125 * covering that reference.
4126 *
4127 * \param C A cursor pointing to a member reference, a declaration reference, or
4128 * an operator call.
4129 * \param NameFlags A bitset with three independent flags:
4130 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4131 * CXNameRange_WantSinglePiece.
4132 * \param PieceIndex For contiguous names or when passing the flag
4133 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4134 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer474261a2012-06-02 10:20:41 +00004135 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004136 * pieces of the name. See also CXNameRange_WantSinglePiece.
4137 *
4138 * \returns The piece of the name pointed to by the given cursor. If there is no
4139 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4140 */
Francois Pichetece689f2011-07-25 22:00:44 +00004141CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4142 unsigned NameFlags,
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004143 unsigned PieceIndex);
4144
4145enum CXNameRefFlags {
4146 /**
4147 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4148 * range.
4149 */
4150 CXNameRange_WantQualifier = 0x1,
4151
4152 /**
James Dennett574cb4c2012-06-15 05:41:51 +00004153 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4154 * in the range.
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004155 */
4156 CXNameRange_WantTemplateArgs = 0x2,
4157
4158 /**
4159 * \brief If the name is non-contiguous, return the full spanning range.
4160 *
4161 * Non-contiguous names occur in Objective-C when a selector with two or more
4162 * parameters is used, or in C++ when using an operator:
4163 * \code
4164 * [object doSomething:here withValue:there]; // ObjC
4165 * return some_vector[1]; // C++
4166 * \endcode
4167 */
4168 CXNameRange_WantSinglePiece = 0x4
4169};
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004170
4171/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004172 * @}
4173 */
4174
4175/**
Douglas Gregor61656112010-01-26 18:31:56 +00004176 * \defgroup CINDEX_LEX Token extraction and manipulation
4177 *
4178 * The routines in this group provide access to the tokens within a
4179 * translation unit, along with a semantic mapping of those tokens to
4180 * their corresponding cursors.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004181 *
4182 * @{
4183 */
4184
4185/**
4186 * \brief Describes a kind of token.
4187 */
4188typedef enum CXTokenKind {
4189 /**
4190 * \brief A token that contains some kind of punctuation.
4191 */
4192 CXToken_Punctuation,
Ted Kremenekd071c602010-03-13 02:50:34 +00004193
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004194 /**
Douglas Gregor61656112010-01-26 18:31:56 +00004195 * \brief A language keyword.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004196 */
4197 CXToken_Keyword,
Ted Kremenekd071c602010-03-13 02:50:34 +00004198
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004199 /**
4200 * \brief An identifier (that is not a keyword).
4201 */
4202 CXToken_Identifier,
Ted Kremenekd071c602010-03-13 02:50:34 +00004203
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004204 /**
4205 * \brief A numeric, string, or character literal.
4206 */
4207 CXToken_Literal,
Ted Kremenekd071c602010-03-13 02:50:34 +00004208
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004209 /**
4210 * \brief A comment.
4211 */
4212 CXToken_Comment
4213} CXTokenKind;
4214
4215/**
4216 * \brief Describes a single preprocessing token.
4217 */
4218typedef struct {
4219 unsigned int_data[4];
4220 void *ptr_data;
4221} CXToken;
4222
4223/**
4224 * \brief Determine the kind of the given token.
4225 */
4226CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004227
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004228/**
4229 * \brief Determine the spelling of the given token.
4230 *
4231 * The spelling of a token is the textual representation of that token, e.g.,
4232 * the text of an identifier or keyword.
4233 */
4234CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004235
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004236/**
4237 * \brief Retrieve the source location of the given token.
4238 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004239CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004240 CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004241
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004242/**
4243 * \brief Retrieve a source range that covers the given token.
4244 */
4245CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4246
4247/**
4248 * \brief Tokenize the source code described by the given range into raw
4249 * lexical tokens.
4250 *
4251 * \param TU the translation unit whose text is being tokenized.
4252 *
4253 * \param Range the source range in which text should be tokenized. All of the
4254 * tokens produced by tokenization will fall within this source range,
4255 *
4256 * \param Tokens this pointer will be set to point to the array of tokens
4257 * that occur within the given source range. The returned pointer must be
4258 * freed with clang_disposeTokens() before the translation unit is destroyed.
4259 *
4260 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4261 * array.
4262 *
4263 */
4264CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4265 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004266
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004267/**
4268 * \brief Annotate the given set of tokens by providing cursors for each token
4269 * that can be mapped to a specific entity within the abstract syntax tree.
4270 *
Douglas Gregor61656112010-01-26 18:31:56 +00004271 * This token-annotation routine is equivalent to invoking
4272 * clang_getCursor() for the source locations of each of the
4273 * tokens. The cursors provided are filtered, so that only those
4274 * cursors that have a direct correspondence to the token are
4275 * accepted. For example, given a function call \c f(x),
4276 * clang_getCursor() would provide the following cursors:
4277 *
4278 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4279 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4280 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4281 *
4282 * Only the first and last of these cursors will occur within the
4283 * annotate, since the tokens "f" and "x' directly refer to a function
4284 * and a variable, respectively, but the parentheses are just a small
4285 * part of the full syntax of the function call expression, which is
4286 * not provided as an annotation.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004287 *
4288 * \param TU the translation unit that owns the given tokens.
4289 *
4290 * \param Tokens the set of tokens to annotate.
4291 *
4292 * \param NumTokens the number of tokens in \p Tokens.
4293 *
4294 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4295 * replaced with the cursors corresponding to each token.
4296 */
4297CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4298 CXToken *Tokens, unsigned NumTokens,
4299 CXCursor *Cursors);
Ted Kremenekd071c602010-03-13 02:50:34 +00004300
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004301/**
4302 * \brief Free the given set of tokens.
4303 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004304CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004305 CXToken *Tokens, unsigned NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004306
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004307/**
4308 * @}
4309 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004310
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004311/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004312 * \defgroup CINDEX_DEBUG Debugging facilities
4313 *
4314 * These routines are used for testing and debugging, only, and should not
4315 * be relied upon.
4316 *
4317 * @{
4318 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004319
Steve Naroff76b8f132009-09-23 17:52:52 +00004320/* for debug/testing */
Ted Kremenek29004672010-02-17 00:41:32 +00004321CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004322CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4323 const char **startBuf,
Steve Naroff76b8f132009-09-23 17:52:52 +00004324 const char **endBuf,
4325 unsigned *startLine,
4326 unsigned *startColumn,
4327 unsigned *endLine,
4328 unsigned *endColumn);
Douglas Gregor1e21cc72010-02-18 23:07:20 +00004329CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar23420652010-11-04 01:26:29 +00004330CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4331 unsigned stack_size);
4332
Douglas Gregor9eb77012009-11-07 00:00:49 +00004333/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004334 * @}
4335 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004336
Douglas Gregor6007cf22010-01-22 22:29:16 +00004337/**
4338 * \defgroup CINDEX_CODE_COMPLET Code completion
4339 *
4340 * Code completion involves taking an (incomplete) source file, along with
4341 * knowledge of where the user is actively editing that file, and suggesting
4342 * syntactically- and semantically-valid constructs that the user might want to
4343 * use at that particular point in the source code. These data structures and
4344 * routines provide support for code completion.
4345 *
4346 * @{
4347 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004348
Douglas Gregor6007cf22010-01-22 22:29:16 +00004349/**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004350 * \brief A semantic string that describes a code-completion result.
4351 *
4352 * A semantic string that describes the formatting of a code-completion
4353 * result as a single "template" of text that should be inserted into the
4354 * source buffer when a particular code-completion result is selected.
4355 * Each semantic string is made up of some number of "chunks", each of which
4356 * contains some text along with a description of what that text means, e.g.,
4357 * the name of the entity being referenced, whether the text chunk is part of
4358 * the template, or whether it is a "placeholder" that the user should replace
4359 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004360 * description of the different kinds of chunks.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004361 */
4362typedef void *CXCompletionString;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004363
Douglas Gregor9eb77012009-11-07 00:00:49 +00004364/**
4365 * \brief A single result of code completion.
4366 */
4367typedef struct {
4368 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004369 * \brief The kind of entity that this completion refers to.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004370 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004371 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor9eb77012009-11-07 00:00:49 +00004372 * *Decl cursor kinds), describing the entity that the completion is
4373 * referring to.
4374 *
4375 * \todo In the future, we would like to provide a full cursor, to allow
4376 * the client to extract additional information from declaration.
4377 */
4378 enum CXCursorKind CursorKind;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004379
4380 /**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004381 * \brief The code-completion string that describes how to insert this
4382 * code-completion result into the editing buffer.
4383 */
4384 CXCompletionString CompletionString;
4385} CXCompletionResult;
4386
4387/**
4388 * \brief Describes a single piece of text within a code-completion string.
4389 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004390 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4391 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor9eb77012009-11-07 00:00:49 +00004392 * should be interpreted by the client or is another completion string.
4393 */
4394enum CXCompletionChunkKind {
4395 /**
4396 * \brief A code-completion string that describes "optional" text that
4397 * could be a part of the template (but is not required).
4398 *
4399 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004400 * string for its representation, which is accessible via
Douglas Gregor9eb77012009-11-07 00:00:49 +00004401 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4402 * describes an additional part of the template that is completely optional.
4403 * For example, optional chunks can be used to describe the placeholders for
4404 * arguments that match up with defaulted function parameters, e.g. given:
4405 *
4406 * \code
4407 * void f(int x, float y = 3.14, double z = 2.71828);
4408 * \endcode
4409 *
4410 * The code-completion string for this function would contain:
4411 * - a TypedText chunk for "f".
4412 * - a LeftParen chunk for "(".
4413 * - a Placeholder chunk for "int x"
4414 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4415 * - a Comma chunk for ","
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004416 * - a Placeholder chunk for "float y"
Douglas Gregor9eb77012009-11-07 00:00:49 +00004417 * - an Optional chunk containing the last defaulted argument:
4418 * - a Comma chunk for ","
4419 * - a Placeholder chunk for "double z"
4420 * - a RightParen chunk for ")"
4421 *
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004422 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor9eb77012009-11-07 00:00:49 +00004423 * - Completely ignore optional chunks, in which case the template for the
4424 * function "f" would only include the first parameter ("int x").
4425 * - Fully expand all optional chunks, in which case the template for the
4426 * function "f" would have all of the parameters.
4427 */
4428 CXCompletionChunk_Optional,
4429 /**
4430 * \brief Text that a user would be expected to type to get this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004431 * code-completion result.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004432 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004433 * There will be exactly one "typed text" chunk in a semantic string, which
4434 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004435 * declaration that could be used at the current code point. Clients are
4436 * expected to filter the code-completion results based on the text in this
4437 * chunk.
4438 */
4439 CXCompletionChunk_TypedText,
4440 /**
4441 * \brief Text that should be inserted as part of a code-completion result.
4442 *
4443 * A "text" chunk represents text that is part of the template to be
4444 * inserted into user code should this particular code-completion result
4445 * be selected.
4446 */
4447 CXCompletionChunk_Text,
4448 /**
4449 * \brief Placeholder text that should be replaced by the user.
4450 *
4451 * A "placeholder" chunk marks a place where the user should insert text
4452 * into the code-completion template. For example, placeholders might mark
4453 * the function parameters for a function declaration, to indicate that the
4454 * user should provide arguments for each of those parameters. The actual
4455 * text in a placeholder is a suggestion for the text to display before
4456 * the user replaces the placeholder with real code.
4457 */
4458 CXCompletionChunk_Placeholder,
4459 /**
4460 * \brief Informative text that should be displayed but never inserted as
4461 * part of the template.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004462 *
Douglas Gregor9eb77012009-11-07 00:00:49 +00004463 * An "informative" chunk contains annotations that can be displayed to
4464 * help the user decide whether a particular code-completion result is the
4465 * right option, but which is not part of the actual template to be inserted
4466 * by code completion.
4467 */
4468 CXCompletionChunk_Informative,
4469 /**
4470 * \brief Text that describes the current parameter when code-completion is
4471 * referring to function call, message send, or template specialization.
4472 *
4473 * A "current parameter" chunk occurs when code-completion is providing
4474 * information about a parameter corresponding to the argument at the
4475 * code-completion point. For example, given a function
4476 *
4477 * \code
4478 * int add(int x, int y);
4479 * \endcode
4480 *
4481 * and the source code \c add(, where the code-completion point is after the
4482 * "(", the code-completion string will contain a "current parameter" chunk
4483 * for "int x", indicating that the current argument will initialize that
4484 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004485 * point is after the ","), the code-completion string will contain a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004486 * "current paremeter" chunk to "int y".
4487 */
4488 CXCompletionChunk_CurrentParameter,
4489 /**
4490 * \brief A left parenthesis ('('), used to initiate a function call or
4491 * signal the beginning of a function parameter list.
4492 */
4493 CXCompletionChunk_LeftParen,
4494 /**
4495 * \brief A right parenthesis (')'), used to finish a function call or
4496 * signal the end of a function parameter list.
4497 */
4498 CXCompletionChunk_RightParen,
4499 /**
4500 * \brief A left bracket ('[').
4501 */
4502 CXCompletionChunk_LeftBracket,
4503 /**
4504 * \brief A right bracket (']').
4505 */
4506 CXCompletionChunk_RightBracket,
4507 /**
4508 * \brief A left brace ('{').
4509 */
4510 CXCompletionChunk_LeftBrace,
4511 /**
4512 * \brief A right brace ('}').
4513 */
4514 CXCompletionChunk_RightBrace,
4515 /**
4516 * \brief A left angle bracket ('<').
4517 */
4518 CXCompletionChunk_LeftAngle,
4519 /**
4520 * \brief A right angle bracket ('>').
4521 */
4522 CXCompletionChunk_RightAngle,
4523 /**
4524 * \brief A comma separator (',').
4525 */
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004526 CXCompletionChunk_Comma,
4527 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004528 * \brief Text that specifies the result type of a given result.
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004529 *
4530 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004531 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004532 * expression using the given completion string would have.
4533 */
Douglas Gregor504a6ae2010-01-10 23:08:15 +00004534 CXCompletionChunk_ResultType,
4535 /**
4536 * \brief A colon (':').
4537 */
4538 CXCompletionChunk_Colon,
4539 /**
4540 * \brief A semicolon (';').
4541 */
4542 CXCompletionChunk_SemiColon,
4543 /**
4544 * \brief An '=' sign.
4545 */
4546 CXCompletionChunk_Equal,
4547 /**
4548 * Horizontal space (' ').
4549 */
4550 CXCompletionChunk_HorizontalSpace,
4551 /**
4552 * Vertical space ('\n'), after which it is generally a good idea to
4553 * perform indentation.
4554 */
4555 CXCompletionChunk_VerticalSpace
Douglas Gregor9eb77012009-11-07 00:00:49 +00004556};
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004557
Douglas Gregor9eb77012009-11-07 00:00:49 +00004558/**
4559 * \brief Determine the kind of a particular chunk within a completion string.
4560 *
4561 * \param completion_string the completion string to query.
4562 *
4563 * \param chunk_number the 0-based index of the chunk in the completion string.
4564 *
4565 * \returns the kind of the chunk at the index \c chunk_number.
4566 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004567CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor9eb77012009-11-07 00:00:49 +00004568clang_getCompletionChunkKind(CXCompletionString completion_string,
4569 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004570
Douglas Gregor9eb77012009-11-07 00:00:49 +00004571/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004572 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004573 * completion string.
4574 *
4575 * \param completion_string the completion string to query.
4576 *
4577 * \param chunk_number the 0-based index of the chunk in the completion string.
4578 *
4579 * \returns the text associated with the chunk at index \c chunk_number.
4580 */
Ted Kremenekf602f962010-02-17 01:42:24 +00004581CINDEX_LINKAGE CXString
Douglas Gregor9eb77012009-11-07 00:00:49 +00004582clang_getCompletionChunkText(CXCompletionString completion_string,
4583 unsigned chunk_number);
4584
4585/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004586 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor9eb77012009-11-07 00:00:49 +00004587 * within a completion string.
4588 *
4589 * \param completion_string the completion string to query.
4590 *
4591 * \param chunk_number the 0-based index of the chunk in the completion string.
4592 *
4593 * \returns the completion string associated with the chunk at index
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004594 * \c chunk_number.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004595 */
4596CINDEX_LINKAGE CXCompletionString
4597clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4598 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004599
Douglas Gregor9eb77012009-11-07 00:00:49 +00004600/**
4601 * \brief Retrieve the number of chunks in the given code-completion string.
4602 */
4603CINDEX_LINKAGE unsigned
4604clang_getNumCompletionChunks(CXCompletionString completion_string);
4605
4606/**
Douglas Gregora2db7932010-05-26 22:00:08 +00004607 * \brief Determine the priority of this code completion.
4608 *
4609 * The priority of a code completion indicates how likely it is that this
4610 * particular completion is the completion that the user will select. The
4611 * priority is selected by various internal heuristics.
4612 *
4613 * \param completion_string The completion string to query.
4614 *
4615 * \returns The priority of this completion string. Smaller values indicate
4616 * higher-priority (more likely) completions.
4617 */
4618CINDEX_LINKAGE unsigned
4619clang_getCompletionPriority(CXCompletionString completion_string);
4620
4621/**
Douglas Gregorf757a122010-08-23 23:00:57 +00004622 * \brief Determine the availability of the entity that this code-completion
4623 * string refers to.
4624 *
4625 * \param completion_string The completion string to query.
4626 *
4627 * \returns The availability of the completion string.
4628 */
4629CINDEX_LINKAGE enum CXAvailabilityKind
4630clang_getCompletionAvailability(CXCompletionString completion_string);
4631
4632/**
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004633 * \brief Retrieve the number of annotations associated with the given
4634 * completion string.
4635 *
4636 * \param completion_string the completion string to query.
4637 *
4638 * \returns the number of annotations associated with the given completion
4639 * string.
4640 */
4641CINDEX_LINKAGE unsigned
4642clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4643
4644/**
4645 * \brief Retrieve the annotation associated with the given completion string.
4646 *
4647 * \param completion_string the completion string to query.
4648 *
4649 * \param annotation_number the 0-based index of the annotation of the
4650 * completion string.
4651 *
4652 * \returns annotation string associated with the completion at index
4653 * \c annotation_number, or a NULL string if that annotation is not available.
4654 */
4655CINDEX_LINKAGE CXString
4656clang_getCompletionAnnotation(CXCompletionString completion_string,
4657 unsigned annotation_number);
4658
4659/**
Douglas Gregor78254c82012-03-27 23:34:16 +00004660 * \brief Retrieve the parent context of the given completion string.
4661 *
4662 * The parent context of a completion string is the semantic parent of
4663 * the declaration (if any) that the code completion represents. For example,
4664 * a code completion for an Objective-C method would have the method's class
4665 * or protocol as its context.
4666 *
4667 * \param completion_string The code completion string whose parent is
4668 * being queried.
4669 *
Argyrios Kyrtzidis9ae39562012-09-26 16:39:56 +00004670 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregor78254c82012-03-27 23:34:16 +00004671 *
James Dennett574cb4c2012-06-15 05:41:51 +00004672 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregor78254c82012-03-27 23:34:16 +00004673 * the completion string represents a method in the NSObject class.
4674 */
4675CINDEX_LINKAGE CXString
4676clang_getCompletionParent(CXCompletionString completion_string,
4677 enum CXCursorKind *kind);
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004678
4679/**
4680 * \brief Retrieve the brief documentation comment attached to the declaration
4681 * that corresponds to the given completion string.
4682 */
4683CINDEX_LINKAGE CXString
4684clang_getCompletionBriefComment(CXCompletionString completion_string);
4685
Douglas Gregor78254c82012-03-27 23:34:16 +00004686/**
Douglas Gregor3f35bb22011-08-04 20:04:59 +00004687 * \brief Retrieve a completion string for an arbitrary declaration or macro
4688 * definition cursor.
4689 *
4690 * \param cursor The cursor to query.
4691 *
4692 * \returns A non-context-sensitive completion string for declaration and macro
4693 * definition cursors, or NULL for other kinds of cursors.
4694 */
4695CINDEX_LINKAGE CXCompletionString
4696clang_getCursorCompletionString(CXCursor cursor);
4697
4698/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004699 * \brief Contains the results of code-completion.
4700 *
4701 * This data structure contains the results of code completion, as
Douglas Gregor6a9580282010-10-11 21:51:20 +00004702 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004703 * \c clang_disposeCodeCompleteResults.
4704 */
4705typedef struct {
4706 /**
4707 * \brief The code-completion results.
4708 */
4709 CXCompletionResult *Results;
4710
4711 /**
4712 * \brief The number of code-completion results stored in the
4713 * \c Results array.
4714 */
4715 unsigned NumResults;
4716} CXCodeCompleteResults;
4717
4718/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004719 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4720 * modify its behavior.
4721 *
4722 * The enumerators in this enumeration can be bitwise-OR'd together to
4723 * provide multiple options to \c clang_codeCompleteAt().
4724 */
4725enum CXCodeComplete_Flags {
4726 /**
4727 * \brief Whether to include macros within the set of code
4728 * completions returned.
4729 */
4730 CXCodeComplete_IncludeMacros = 0x01,
4731
4732 /**
4733 * \brief Whether to include code patterns for language constructs
4734 * within the set of code completions, e.g., for loops.
4735 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004736 CXCodeComplete_IncludeCodePatterns = 0x02,
4737
4738 /**
4739 * \brief Whether to include brief documentation within the set of code
4740 * completions returned.
4741 */
4742 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorb68bc592010-08-05 09:09:23 +00004743};
4744
4745/**
Douglas Gregor21325842011-07-07 16:03:39 +00004746 * \brief Bits that represent the context under which completion is occurring.
4747 *
4748 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4749 * contexts are occurring simultaneously.
4750 */
4751enum CXCompletionContext {
4752 /**
4753 * \brief The context for completions is unexposed, as only Clang results
4754 * should be included. (This is equivalent to having no context bits set.)
4755 */
4756 CXCompletionContext_Unexposed = 0,
4757
4758 /**
4759 * \brief Completions for any possible type should be included in the results.
4760 */
4761 CXCompletionContext_AnyType = 1 << 0,
4762
4763 /**
4764 * \brief Completions for any possible value (variables, function calls, etc.)
4765 * should be included in the results.
4766 */
4767 CXCompletionContext_AnyValue = 1 << 1,
4768 /**
4769 * \brief Completions for values that resolve to an Objective-C object should
4770 * be included in the results.
4771 */
4772 CXCompletionContext_ObjCObjectValue = 1 << 2,
4773 /**
4774 * \brief Completions for values that resolve to an Objective-C selector
4775 * should be included in the results.
4776 */
4777 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4778 /**
4779 * \brief Completions for values that resolve to a C++ class type should be
4780 * included in the results.
4781 */
4782 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4783
4784 /**
4785 * \brief Completions for fields of the member being accessed using the dot
4786 * operator should be included in the results.
4787 */
4788 CXCompletionContext_DotMemberAccess = 1 << 5,
4789 /**
4790 * \brief Completions for fields of the member being accessed using the arrow
4791 * operator should be included in the results.
4792 */
4793 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4794 /**
4795 * \brief Completions for properties of the Objective-C object being accessed
4796 * using the dot operator should be included in the results.
4797 */
4798 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4799
4800 /**
4801 * \brief Completions for enum tags should be included in the results.
4802 */
4803 CXCompletionContext_EnumTag = 1 << 8,
4804 /**
4805 * \brief Completions for union tags should be included in the results.
4806 */
4807 CXCompletionContext_UnionTag = 1 << 9,
4808 /**
4809 * \brief Completions for struct tags should be included in the results.
4810 */
4811 CXCompletionContext_StructTag = 1 << 10,
4812
4813 /**
4814 * \brief Completions for C++ class names should be included in the results.
4815 */
4816 CXCompletionContext_ClassTag = 1 << 11,
4817 /**
4818 * \brief Completions for C++ namespaces and namespace aliases should be
4819 * included in the results.
4820 */
4821 CXCompletionContext_Namespace = 1 << 12,
4822 /**
4823 * \brief Completions for C++ nested name specifiers should be included in
4824 * the results.
4825 */
4826 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4827
4828 /**
4829 * \brief Completions for Objective-C interfaces (classes) should be included
4830 * in the results.
4831 */
4832 CXCompletionContext_ObjCInterface = 1 << 14,
4833 /**
4834 * \brief Completions for Objective-C protocols should be included in
4835 * the results.
4836 */
4837 CXCompletionContext_ObjCProtocol = 1 << 15,
4838 /**
4839 * \brief Completions for Objective-C categories should be included in
4840 * the results.
4841 */
4842 CXCompletionContext_ObjCCategory = 1 << 16,
4843 /**
4844 * \brief Completions for Objective-C instance messages should be included
4845 * in the results.
4846 */
4847 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4848 /**
4849 * \brief Completions for Objective-C class messages should be included in
4850 * the results.
4851 */
4852 CXCompletionContext_ObjCClassMessage = 1 << 18,
4853 /**
4854 * \brief Completions for Objective-C selector names should be included in
4855 * the results.
4856 */
4857 CXCompletionContext_ObjCSelectorName = 1 << 19,
4858
4859 /**
4860 * \brief Completions for preprocessor macro names should be included in
4861 * the results.
4862 */
4863 CXCompletionContext_MacroName = 1 << 20,
4864
4865 /**
4866 * \brief Natural language completions should be included in the results.
4867 */
4868 CXCompletionContext_NaturalLanguage = 1 << 21,
4869
4870 /**
4871 * \brief The current context is unknown, so set all contexts.
4872 */
4873 CXCompletionContext_Unknown = ((1 << 22) - 1)
4874};
4875
4876/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004877 * \brief Returns a default set of code-completion options that can be
4878 * passed to\c clang_codeCompleteAt().
4879 */
4880CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4881
4882/**
Douglas Gregor8e984da2010-08-04 16:47:14 +00004883 * \brief Perform code completion at a given location in a translation unit.
4884 *
4885 * This function performs code completion at a particular file, line, and
4886 * column within source code, providing results that suggest potential
4887 * code snippets based on the context of the completion. The basic model
4888 * for code completion is that Clang will parse a complete source file,
4889 * performing syntax checking up to the location where code-completion has
4890 * been requested. At that point, a special code-completion token is passed
4891 * to the parser, which recognizes this token and determines, based on the
4892 * current location in the C/Objective-C/C++ grammar and the state of
4893 * semantic analysis, what completions to provide. These completions are
4894 * returned via a new \c CXCodeCompleteResults structure.
4895 *
4896 * Code completion itself is meant to be triggered by the client when the
4897 * user types punctuation characters or whitespace, at which point the
4898 * code-completion location will coincide with the cursor. For example, if \c p
4899 * is a pointer, code-completion might be triggered after the "-" and then
4900 * after the ">" in \c p->. When the code-completion location is afer the ">",
4901 * the completion results will provide, e.g., the members of the struct that
4902 * "p" points to. The client is responsible for placing the cursor at the
4903 * beginning of the token currently being typed, then filtering the results
4904 * based on the contents of the token. For example, when code-completing for
4905 * the expression \c p->get, the client should provide the location just after
4906 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4907 * client can filter the results based on the current token text ("get"), only
4908 * showing those results that start with "get". The intent of this interface
4909 * is to separate the relatively high-latency acquisition of code-completion
4910 * results from the filtering of results on a per-character basis, which must
4911 * have a lower latency.
4912 *
4913 * \param TU The translation unit in which code-completion should
4914 * occur. The source files for this translation unit need not be
4915 * completely up-to-date (and the contents of those source files may
4916 * be overridden via \p unsaved_files). Cursors referring into the
4917 * translation unit may be invalidated by this invocation.
4918 *
4919 * \param complete_filename The name of the source file where code
4920 * completion should be performed. This filename may be any file
4921 * included in the translation unit.
4922 *
4923 * \param complete_line The line at which code-completion should occur.
4924 *
4925 * \param complete_column The column at which code-completion should occur.
4926 * Note that the column should point just after the syntactic construct that
4927 * initiated code completion, and not in the middle of a lexical token.
4928 *
4929 * \param unsaved_files the Tiles that have not yet been saved to disk
4930 * but may be required for parsing or code completion, including the
4931 * contents of those files. The contents and name of these files (as
4932 * specified by CXUnsavedFile) are copied when necessary, so the
4933 * client only needs to guarantee their validity until the call to
4934 * this function returns.
4935 *
4936 * \param num_unsaved_files The number of unsaved file entries in \p
4937 * unsaved_files.
4938 *
Douglas Gregorb68bc592010-08-05 09:09:23 +00004939 * \param options Extra options that control the behavior of code
4940 * completion, expressed as a bitwise OR of the enumerators of the
4941 * CXCodeComplete_Flags enumeration. The
4942 * \c clang_defaultCodeCompleteOptions() function returns a default set
4943 * of code-completion options.
4944 *
Douglas Gregor8e984da2010-08-04 16:47:14 +00004945 * \returns If successful, a new \c CXCodeCompleteResults structure
4946 * containing code-completion results, which should eventually be
4947 * freed with \c clang_disposeCodeCompleteResults(). If code
4948 * completion fails, returns NULL.
4949 */
4950CINDEX_LINKAGE
4951CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4952 const char *complete_filename,
4953 unsigned complete_line,
4954 unsigned complete_column,
4955 struct CXUnsavedFile *unsaved_files,
Douglas Gregorb68bc592010-08-05 09:09:23 +00004956 unsigned num_unsaved_files,
4957 unsigned options);
Douglas Gregor8e984da2010-08-04 16:47:14 +00004958
4959/**
Douglas Gregor49f67ce2010-08-26 13:48:20 +00004960 * \brief Sort the code-completion results in case-insensitive alphabetical
4961 * order.
4962 *
4963 * \param Results The set of results to sort.
4964 * \param NumResults The number of results in \p Results.
4965 */
4966CINDEX_LINKAGE
4967void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4968 unsigned NumResults);
4969
4970/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004971 * \brief Free the given set of code-completion results.
4972 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004973CINDEX_LINKAGE
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004974void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregorf757a122010-08-23 23:00:57 +00004975
Douglas Gregor52606ff2010-01-20 01:10:47 +00004976/**
Douglas Gregor33cdd812010-02-18 18:08:43 +00004977 * \brief Determine the number of diagnostics produced prior to the
4978 * location where code completion was performed.
4979 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004980CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00004981unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4982
4983/**
4984 * \brief Retrieve a diagnostic associated with the given code completion.
4985 *
James Dennett574cb4c2012-06-15 05:41:51 +00004986 * \param Results the code completion results to query.
Douglas Gregor33cdd812010-02-18 18:08:43 +00004987 * \param Index the zero-based diagnostic number to retrieve.
4988 *
4989 * \returns the requested diagnostic. This diagnostic must be freed
4990 * via a call to \c clang_disposeDiagnostic().
4991 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004992CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00004993CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4994 unsigned Index);
4995
4996/**
Douglas Gregor21325842011-07-07 16:03:39 +00004997 * \brief Determines what compeltions are appropriate for the context
4998 * the given code completion.
4999 *
5000 * \param Results the code completion results to query
5001 *
5002 * \returns the kinds of completions that are appropriate for use
5003 * along with the given code completion results.
5004 */
5005CINDEX_LINKAGE
5006unsigned long long clang_codeCompleteGetContexts(
5007 CXCodeCompleteResults *Results);
Douglas Gregor63745d52011-07-21 01:05:26 +00005008
5009/**
5010 * \brief Returns the cursor kind for the container for the current code
5011 * completion context. The container is only guaranteed to be set for
5012 * contexts where a container exists (i.e. member accesses or Objective-C
5013 * message sends); if there is not a container, this function will return
5014 * CXCursor_InvalidCode.
5015 *
5016 * \param Results the code completion results to query
5017 *
5018 * \param IsIncomplete on return, this value will be false if Clang has complete
5019 * information about the container. If Clang does not have complete
5020 * information, this value will be true.
5021 *
5022 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5023 * container
5024 */
5025CINDEX_LINKAGE
5026enum CXCursorKind clang_codeCompleteGetContainerKind(
5027 CXCodeCompleteResults *Results,
5028 unsigned *IsIncomplete);
5029
5030/**
5031 * \brief Returns the USR for the container for the current code completion
5032 * context. If there is not a container for the current context, this
5033 * function will return the empty string.
5034 *
5035 * \param Results the code completion results to query
5036 *
5037 * \returns the USR for the container
5038 */
5039CINDEX_LINKAGE
5040CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor21325842011-07-07 16:03:39 +00005041
Douglas Gregorea777402011-07-26 15:24:30 +00005042
5043/**
5044 * \brief Returns the currently-entered selector for an Objective-C message
5045 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5046 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5047 * CXCompletionContext_ObjCClassMessage.
5048 *
5049 * \param Results the code completion results to query
5050 *
5051 * \returns the selector (or partial selector) that has been entered thus far
5052 * for an Objective-C message send.
5053 */
5054CINDEX_LINKAGE
5055CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5056
Douglas Gregor21325842011-07-07 16:03:39 +00005057/**
Douglas Gregor52606ff2010-01-20 01:10:47 +00005058 * @}
5059 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005060
5061
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005062/**
5063 * \defgroup CINDEX_MISC Miscellaneous utility functions
5064 *
5065 * @{
5066 */
Ted Kremenek3e315a22010-01-23 17:51:23 +00005067
5068/**
5069 * \brief Return a version string, suitable for showing to a user, but not
5070 * intended to be parsed (the format is not guaranteed to be stable).
5071 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +00005072CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005073
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005074
5075/**
5076 * \brief Enable/disable crash recovery.
5077 *
James Dennett574cb4c2012-06-15 05:41:51 +00005078 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5079 * value enables crash recovery, while 0 disables it.
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005080 */
5081CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5082
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005083 /**
Ted Kremenekd071c602010-03-13 02:50:34 +00005084 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005085 * (used with clang_getInclusions()).
5086 *
5087 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett574cb4c2012-06-15 05:41:51 +00005088 * file included (either at the top-level or by \#include directives) within
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005089 * a translation unit. The first argument is the file being included, and
5090 * the second and third arguments provide the inclusion stack. The
5091 * array is sorted in order of immediate inclusion. For example,
5092 * the first element refers to the location that included 'included_file'.
5093 */
5094typedef void (*CXInclusionVisitor)(CXFile included_file,
5095 CXSourceLocation* inclusion_stack,
5096 unsigned include_len,
5097 CXClientData client_data);
5098
5099/**
5100 * \brief Visit the set of preprocessor inclusions in a translation unit.
5101 * The visitor function is called with the provided data for every included
5102 * file. This does not include headers included by the PCH file (unless one
5103 * is inspecting the inclusions in the PCH file itself).
5104 */
5105CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5106 CXInclusionVisitor visitor,
5107 CXClientData client_data);
5108
5109/**
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005110 * @}
5111 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005112
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005113/** \defgroup CINDEX_REMAPPING Remapping functions
5114 *
5115 * @{
5116 */
5117
5118/**
5119 * \brief A remapping of original source files and their translated files.
5120 */
5121typedef void *CXRemapping;
5122
5123/**
5124 * \brief Retrieve a remapping.
5125 *
5126 * \param path the path that contains metadata about remappings.
5127 *
5128 * \returns the requested remapping. This remapping must be freed
5129 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5130 */
5131CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5132
5133/**
Ted Kremenekf7639e12012-03-06 20:06:33 +00005134 * \brief Retrieve a remapping.
5135 *
5136 * \param filePaths pointer to an array of file paths containing remapping info.
5137 *
5138 * \param numFiles number of file paths.
5139 *
5140 * \returns the requested remapping. This remapping must be freed
5141 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5142 */
5143CINDEX_LINKAGE
5144CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5145 unsigned numFiles);
5146
5147/**
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005148 * \brief Determine the number of remappings.
5149 */
5150CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5151
5152/**
5153 * \brief Get the original and the associated filename from the remapping.
5154 *
5155 * \param original If non-NULL, will be set to the original filename.
5156 *
5157 * \param transformed If non-NULL, will be set to the filename that the original
5158 * is associated with.
5159 */
5160CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5161 CXString *original, CXString *transformed);
5162
5163/**
5164 * \brief Dispose the remapping.
5165 */
5166CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5167
5168/**
5169 * @}
5170 */
5171
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005172/** \defgroup CINDEX_HIGH Higher level API functions
5173 *
5174 * @{
5175 */
5176
5177enum CXVisitorResult {
5178 CXVisit_Break,
5179 CXVisit_Continue
5180};
5181
5182typedef struct {
5183 void *context;
5184 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5185} CXCursorAndRangeVisitor;
5186
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005187typedef enum {
5188 /**
5189 * \brief Function returned successfully.
5190 */
5191 CXResult_Success = 0,
5192 /**
5193 * \brief One of the parameters was invalid for the function.
5194 */
5195 CXResult_Invalid = 1,
5196 /**
5197 * \brief The function was terminated by a callback (e.g. it returned
5198 * CXVisit_Break)
5199 */
5200 CXResult_VisitBreak = 2
5201
5202} CXResult;
5203
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005204/**
5205 * \brief Find references of a declaration in a specific file.
5206 *
5207 * \param cursor pointing to a declaration or a reference of one.
5208 *
5209 * \param file to search for references.
5210 *
5211 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5212 * each reference found.
5213 * The CXSourceRange will point inside the file; if the reference is inside
5214 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005215 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005216 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005217 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005218CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5219 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005220
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005221/**
5222 * \brief Find #import/#include directives in a specific file.
5223 *
5224 * \param TU translation unit containing the file to query.
5225 *
5226 * \param file to search for #import/#include directives.
5227 *
5228 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5229 * each directive found.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005230 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005231 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005232 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005233CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5234 CXFile file,
5235 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005236
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005237#ifdef __has_feature
5238# if __has_feature(blocks)
5239
5240typedef enum CXVisitorResult
5241 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5242
5243CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005244CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5245 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005246
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005247CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005248CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5249 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005250
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005251# endif
5252#endif
5253
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005254/**
5255 * \brief The client's data object that is associated with a CXFile.
5256 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005257typedef void *CXIdxClientFile;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005258
5259/**
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005260 * \brief The client's data object that is associated with a semantic entity.
5261 */
5262typedef void *CXIdxClientEntity;
5263
5264/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005265 * \brief The client's data object that is associated with a semantic container
5266 * of entities.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005267 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005268typedef void *CXIdxClientContainer;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005269
5270/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005271 * \brief The client's data object that is associated with an AST file (PCH
5272 * or module).
5273 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005274typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005275
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005276/**
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005277 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005278 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005279typedef struct {
5280 void *ptr_data[2];
5281 unsigned int_data;
5282} CXIdxLoc;
5283
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005284/**
James Dennett574cb4c2012-06-15 05:41:51 +00005285 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005286 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005287typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005288 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005289 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005290 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005291 CXIdxLoc hashLoc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005292 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005293 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005294 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005295 const char *filename;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005296 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005297 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005298 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005299 CXFile file;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005300 int isImport;
5301 int isAngled;
Argyrios Kyrtzidis5e2ec482012-10-18 00:17:05 +00005302 /**
5303 * \brief Non-zero if the directive was automatically turned into a module
5304 * import.
5305 */
5306 int isModuleImport;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005307} CXIdxIncludedFileInfo;
5308
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005309/**
James Dennett574cb4c2012-06-15 05:41:51 +00005310 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005311 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005312typedef struct {
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005313 /**
5314 * \brief Top level AST file containing the imported PCH, module or submodule.
5315 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005316 CXFile file;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005317 /**
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005318 * \brief The imported module or NULL if the AST file is a PCH.
5319 */
5320 CXModule module;
5321 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005322 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005323 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005324 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005325 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005326 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005327 * a module import. Applicable only for modules.
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005328 */
Argyrios Kyrtzidis184b1442012-10-03 21:05:44 +00005329 int isImplicit;
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005330
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005331} CXIdxImportedASTFileInfo;
5332
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005333typedef enum {
5334 CXIdxEntity_Unexposed = 0,
5335 CXIdxEntity_Typedef = 1,
5336 CXIdxEntity_Function = 2,
5337 CXIdxEntity_Variable = 3,
5338 CXIdxEntity_Field = 4,
5339 CXIdxEntity_EnumConstant = 5,
5340
5341 CXIdxEntity_ObjCClass = 6,
5342 CXIdxEntity_ObjCProtocol = 7,
5343 CXIdxEntity_ObjCCategory = 8,
5344
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005345 CXIdxEntity_ObjCInstanceMethod = 9,
5346 CXIdxEntity_ObjCClassMethod = 10,
5347 CXIdxEntity_ObjCProperty = 11,
5348 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005349
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005350 CXIdxEntity_Enum = 13,
5351 CXIdxEntity_Struct = 14,
5352 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005353
5354 CXIdxEntity_CXXClass = 16,
5355 CXIdxEntity_CXXNamespace = 17,
5356 CXIdxEntity_CXXNamespaceAlias = 18,
5357 CXIdxEntity_CXXStaticVariable = 19,
5358 CXIdxEntity_CXXStaticMethod = 20,
5359 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matose9a3ed42012-08-31 22:18:20 +00005360 CXIdxEntity_CXXConstructor = 22,
5361 CXIdxEntity_CXXDestructor = 23,
5362 CXIdxEntity_CXXConversionFunction = 24,
5363 CXIdxEntity_CXXTypeAlias = 25,
5364 CXIdxEntity_CXXInterface = 26
5365
5366} CXIdxEntityKind;
5367
Argyrios Kyrtzidis52002882011-12-07 20:44:12 +00005368typedef enum {
5369 CXIdxEntityLang_None = 0,
5370 CXIdxEntityLang_C = 1,
5371 CXIdxEntityLang_ObjC = 2,
5372 CXIdxEntityLang_CXX = 3
5373} CXIdxEntityLanguage;
5374
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005375/**
5376 * \brief Extra C++ template information for an entity. This can apply to:
5377 * CXIdxEntity_Function
5378 * CXIdxEntity_CXXClass
5379 * CXIdxEntity_CXXStaticMethod
5380 * CXIdxEntity_CXXInstanceMethod
5381 * CXIdxEntity_CXXConstructor
5382 * CXIdxEntity_CXXConversionFunction
5383 * CXIdxEntity_CXXTypeAlias
5384 */
5385typedef enum {
5386 CXIdxEntity_NonTemplate = 0,
5387 CXIdxEntity_Template = 1,
5388 CXIdxEntity_TemplatePartialSpecialization = 2,
5389 CXIdxEntity_TemplateSpecialization = 3
5390} CXIdxEntityCXXTemplateKind;
5391
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005392typedef enum {
5393 CXIdxAttr_Unexposed = 0,
5394 CXIdxAttr_IBAction = 1,
5395 CXIdxAttr_IBOutlet = 2,
5396 CXIdxAttr_IBOutletCollection = 3
5397} CXIdxAttrKind;
5398
5399typedef struct {
5400 CXIdxAttrKind kind;
5401 CXCursor cursor;
5402 CXIdxLoc loc;
5403} CXIdxAttrInfo;
5404
5405typedef struct {
Argyrios Kyrtzidis4d873b72011-12-15 00:05:00 +00005406 CXIdxEntityKind kind;
5407 CXIdxEntityCXXTemplateKind templateKind;
5408 CXIdxEntityLanguage lang;
5409 const char *name;
5410 const char *USR;
5411 CXCursor cursor;
5412 const CXIdxAttrInfo *const *attributes;
5413 unsigned numAttributes;
5414} CXIdxEntityInfo;
5415
5416typedef struct {
5417 CXCursor cursor;
5418} CXIdxContainerInfo;
5419
5420typedef struct {
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005421 const CXIdxAttrInfo *attrInfo;
5422 const CXIdxEntityInfo *objcClass;
5423 CXCursor classCursor;
5424 CXIdxLoc classLoc;
5425} CXIdxIBOutletCollectionAttrInfo;
5426
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005427typedef enum {
5428 CXIdxDeclFlag_Skipped = 0x1
5429} CXIdxDeclInfoFlags;
5430
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005431typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005432 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005433 CXCursor cursor;
5434 CXIdxLoc loc;
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005435 const CXIdxContainerInfo *semanticContainer;
5436 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005437 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005438 * cases like out-of-line C++ member functions.
5439 */
5440 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005441 int isRedeclaration;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005442 int isDefinition;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005443 int isContainer;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005444 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005445 /**
5446 * \brief Whether the declaration exists in code or was created implicitly
5447 * by the compiler, e.g. implicit objc methods for properties.
5448 */
5449 int isImplicit;
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005450 const CXIdxAttrInfo *const *attributes;
5451 unsigned numAttributes;
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005452
5453 unsigned flags;
5454
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005455} CXIdxDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005456
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005457typedef enum {
5458 CXIdxObjCContainer_ForwardRef = 0,
5459 CXIdxObjCContainer_Interface = 1,
5460 CXIdxObjCContainer_Implementation = 2
5461} CXIdxObjCContainerKind;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005462
5463typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005464 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005465 CXIdxObjCContainerKind kind;
5466} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005467
5468typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005469 const CXIdxEntityInfo *base;
5470 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005471 CXIdxLoc loc;
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005472} CXIdxBaseClassInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005473
5474typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005475 const CXIdxEntityInfo *protocol;
5476 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005477 CXIdxLoc loc;
5478} CXIdxObjCProtocolRefInfo;
5479
5480typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005481 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005482 unsigned numProtocols;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005483} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005484
5485typedef struct {
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005486 const CXIdxObjCContainerDeclInfo *containerInfo;
5487 const CXIdxBaseClassInfo *superInfo;
5488 const CXIdxObjCProtocolRefListInfo *protocols;
5489} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005490
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005491typedef struct {
Argyrios Kyrtzidis9b9f7a92011-12-13 18:47:45 +00005492 const CXIdxObjCContainerDeclInfo *containerInfo;
5493 const CXIdxEntityInfo *objcClass;
5494 CXCursor classCursor;
5495 CXIdxLoc classLoc;
5496 const CXIdxObjCProtocolRefListInfo *protocols;
5497} CXIdxObjCCategoryDeclInfo;
5498
5499typedef struct {
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005500 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005501 const CXIdxEntityInfo *getter;
5502 const CXIdxEntityInfo *setter;
5503} CXIdxObjCPropertyDeclInfo;
5504
5505typedef struct {
5506 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005507 const CXIdxBaseClassInfo *const *bases;
5508 unsigned numBases;
5509} CXIdxCXXClassDeclInfo;
5510
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005511/**
James Dennett574cb4c2012-06-15 05:41:51 +00005512 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005513 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005514typedef enum {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005515 /**
5516 * \brief The entity is referenced directly in user's code.
5517 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005518 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005519 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005520 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5521 * dot syntax.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005522 */
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005523 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005524} CXIdxEntityRefKind;
5525
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005526/**
James Dennett574cb4c2012-06-15 05:41:51 +00005527 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005528 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005529typedef struct {
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005530 CXIdxEntityRefKind kind;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005531 /**
5532 * \brief Reference cursor.
5533 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005534 CXCursor cursor;
5535 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005536 /**
5537 * \brief The entity that gets referenced.
5538 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005539 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005540 /**
5541 * \brief Immediate "parent" of the reference. For example:
5542 *
5543 * \code
5544 * Foo *var;
5545 * \endcode
5546 *
5547 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005548 * For references inside statement bodies of functions/methods,
5549 * the parentEntity will be the function/method.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005550 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005551 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005552 /**
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005553 * \brief Lexical container context of the reference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005554 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005555 const CXIdxContainerInfo *container;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005556} CXIdxEntityRefInfo;
5557
James Dennett574cb4c2012-06-15 05:41:51 +00005558/**
5559 * \brief A group of callbacks used by #clang_indexSourceFile and
5560 * #clang_indexTranslationUnit.
5561 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005562typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005563 /**
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005564 * \brief Called periodically to check whether indexing should be aborted.
5565 * Should return 0 to continue, and non-zero to abort.
5566 */
5567 int (*abortQuery)(CXClientData client_data, void *reserved);
5568
5569 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005570 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005571 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005572 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005573 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005574
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005575 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett574cb4c2012-06-15 05:41:51 +00005576 CXFile mainFile, void *reserved);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005577
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005578 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005579 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005580 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005581 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005582 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005583
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005584 /**
5585 * \brief Called when a AST file (PCH or module) gets imported.
5586 *
5587 * AST files will not get indexed (there will not be callbacks to index all
5588 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005589 * file is not already indexed, to initiate a new indexing job specific to
5590 * the AST file.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005591 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005592 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005593 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005594
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005595 /**
5596 * \brief Called at the beginning of indexing a translation unit.
5597 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005598 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005599 void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005600
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005601 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005602 const CXIdxDeclInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005603
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005604 /**
5605 * \brief Called to index a reference of an entity.
5606 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005607 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005608 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005609
5610} IndexerCallbacks;
5611
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005612CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005613CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5614clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005615
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005616CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5617clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5618
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005619CINDEX_LINKAGE
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005620const CXIdxObjCCategoryDeclInfo *
5621clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5622
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005623CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5624clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005625
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005626CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5627clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5628
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005629CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5630clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5631
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005632CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5633clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5634
5635/**
5636 * \brief For retrieving a custom CXIdxClientContainer attached to a
5637 * container.
5638 */
5639CINDEX_LINKAGE CXIdxClientContainer
5640clang_index_getClientContainer(const CXIdxContainerInfo *);
5641
5642/**
5643 * \brief For setting a custom CXIdxClientContainer attached to a
5644 * container.
5645 */
5646CINDEX_LINKAGE void
5647clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5648
5649/**
5650 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5651 */
5652CINDEX_LINKAGE CXIdxClientEntity
5653clang_index_getClientEntity(const CXIdxEntityInfo *);
5654
5655/**
5656 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5657 */
5658CINDEX_LINKAGE void
5659clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5660
5661/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005662 * \brief An indexing action/session, to be applied to one or multiple
5663 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005664 */
5665typedef void *CXIndexAction;
5666
5667/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005668 * \brief An indexing action/session, to be applied to one or multiple
5669 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005670 *
5671 * \param CIdx The index object with which the index action will be associated.
5672 */
5673CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5674
5675/**
5676 * \brief Destroy the given index action.
5677 *
5678 * The index action must not be destroyed until all of the translation units
5679 * created within that index action have been destroyed.
5680 */
5681CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5682
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005683typedef enum {
5684 /**
5685 * \brief Used to indicate that no special indexing options are needed.
5686 */
5687 CXIndexOpt_None = 0x0,
5688
5689 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005690 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5691 * be invoked for only one reference of an entity per source file that does
5692 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005693 */
Argyrios Kyrtzidisfb7d1452012-01-14 00:11:49 +00005694 CXIndexOpt_SuppressRedundantRefs = 0x1,
5695
5696 /**
5697 * \brief Function-local symbols should be indexed. If this is not set
5698 * function-local symbols will be ignored.
5699 */
Argyrios Kyrtzidis7e747952012-02-14 22:23:11 +00005700 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5701
5702 /**
5703 * \brief Implicit function/class template instantiations should be indexed.
5704 * If this is not set, implicit instantiations will be ignored.
5705 */
Argyrios Kyrtzidis6c9ed7d2012-03-27 21:38:03 +00005706 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5707
5708 /**
5709 * \brief Suppress all compiler warnings when parsing for indexing.
5710 */
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005711 CXIndexOpt_SuppressWarnings = 0x8,
5712
5713 /**
5714 * \brief Skip a function/method body that was already parsed during an
5715 * indexing session assosiated with a \c CXIndexAction object.
5716 * Bodies in system headers are always skipped.
5717 */
5718 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5719
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005720} CXIndexOptFlags;
5721
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005722/**
5723 * \brief Index the given source file and the translation unit corresponding
James Dennett574cb4c2012-06-15 05:41:51 +00005724 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005725 *
5726 * \param client_data pointer data supplied by the client, which will
5727 * be passed to the invoked callbacks.
5728 *
5729 * \param index_callbacks Pointer to indexing callbacks that the client
5730 * implements.
5731 *
James Dennett574cb4c2012-06-15 05:41:51 +00005732 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005733 * passed in index_callbacks.
5734 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005735 * \param index_options A bitmask of options that affects how indexing is
5736 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005737 *
5738 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
5739 * after indexing is finished. Set to NULL if you do not require it.
5740 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005741 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005742 * non-zero, otherwise returns 0.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005743 *
James Dennett574cb4c2012-06-15 05:41:51 +00005744 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005745 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005746CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005747 CXClientData client_data,
5748 IndexerCallbacks *index_callbacks,
5749 unsigned index_callbacks_size,
5750 unsigned index_options,
5751 const char *source_filename,
5752 const char * const *command_line_args,
5753 int num_command_line_args,
5754 struct CXUnsavedFile *unsaved_files,
5755 unsigned num_unsaved_files,
5756 CXTranslationUnit *out_TU,
5757 unsigned TU_options);
5758
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005759/**
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005760 * \brief Index the given translation unit via callbacks implemented through
James Dennett574cb4c2012-06-15 05:41:51 +00005761 * #IndexerCallbacks.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005762 *
5763 * The order of callback invocations is not guaranteed to be the same as
5764 * when indexing a source file. The high level order will be:
5765 *
5766 * -Preprocessor callbacks invocations
5767 * -Declaration/reference callbacks invocations
5768 * -Diagnostic callback invocations
5769 *
James Dennett574cb4c2012-06-15 05:41:51 +00005770 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005771 *
5772 * \returns If there is a failure from which the there is no recovery, returns
5773 * non-zero, otherwise returns 0.
5774 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005775CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005776 CXClientData client_data,
5777 IndexerCallbacks *index_callbacks,
5778 unsigned index_callbacks_size,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005779 unsigned index_options,
5780 CXTranslationUnit);
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005781
5782/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005783 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5784 * the given CXIdxLoc.
5785 *
5786 * If the location refers into a macro expansion, retrieves the
5787 * location of the macro expansion and if it refers into a macro argument
5788 * retrieves the location of the argument.
5789 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005790CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005791 CXIdxClientFile *indexFile,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005792 CXFile *file,
5793 unsigned *line,
5794 unsigned *column,
5795 unsigned *offset);
5796
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005797/**
5798 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5799 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005800CINDEX_LINKAGE
5801CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5802
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005803/**
5804 * @}
5805 */
5806
Douglas Gregor6007cf22010-01-22 22:29:16 +00005807/**
5808 * @}
5809 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005810
Ted Kremenekb60d87c2009-08-26 22:36:44 +00005811#ifdef __cplusplus
5812}
5813#endif
5814#endif
5815