blob: cd130e3746e6174ea51422cb0b6da823f8b2de4b [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
Benjamin Kramer2501f142013-10-20 11:47:15 +00001949 /** \brief A case statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001950 */
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,
Argyrios Kyrtzidis16834f12013-09-25 00:14:38 +00002098 CXCursor_PackedAttr = 408,
2099 CXCursor_LastAttr = CXCursor_PackedAttr,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002100
2101 /* Preprocessing */
2102 CXCursor_PreprocessingDirective = 500,
Douglas Gregor06d6d322010-03-18 18:04:21 +00002103 CXCursor_MacroDefinition = 501,
Chandler Carruth9e4704a2011-07-14 08:41:15 +00002104 CXCursor_MacroExpansion = 502,
2105 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregor796d76a2010-10-20 22:00:55 +00002106 CXCursor_InclusionDirective = 503,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002107 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis50e5b1d2012-10-05 00:22:24 +00002108 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2109
2110 /* Extra Declarations */
2111 /**
2112 * \brief A module import declaration.
2113 */
2114 CXCursor_ModuleImportDecl = 600,
2115 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2116 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregor6007cf22010-01-22 22:29:16 +00002117};
2118
2119/**
2120 * \brief A cursor representing some element in the abstract syntax tree for
2121 * a translation unit.
2122 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002123 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregor6007cf22010-01-22 22:29:16 +00002124 * program--declaration, statements, expressions, references to declarations,
2125 * etc.--under a single "cursor" abstraction with a common set of operations.
2126 * Common operation for a cursor include: getting the physical location in
2127 * a source file where the cursor points, getting the name associated with a
2128 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2129 *
2130 * Cursors can be produced in two specific ways.
2131 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2132 * from which one can use clang_visitChildren() to explore the rest of the
2133 * translation unit. clang_getCursor() maps from a physical source location
2134 * to the entity that resides at that location, allowing one to map from the
2135 * source code into the AST.
2136 */
2137typedef struct {
2138 enum CXCursorKind kind;
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00002139 int xdata;
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +00002140 const void *data[3];
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002141} CXCursor;
Douglas Gregor6007cf22010-01-22 22:29:16 +00002142
2143/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002144 * \brief A comment AST node.
2145 */
2146typedef struct {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00002147 const void *ASTNode;
2148 CXTranslationUnit TranslationUnit;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00002149} CXComment;
2150
2151/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002152 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2153 *
2154 * @{
2155 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002156
Douglas Gregor6007cf22010-01-22 22:29:16 +00002157/**
2158 * \brief Retrieve the NULL cursor, which represents no entity.
2159 */
2160CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002161
Douglas Gregor6007cf22010-01-22 22:29:16 +00002162/**
2163 * \brief Retrieve the cursor that represents the given translation unit.
2164 *
2165 * The translation unit cursor can be used to start traversing the
2166 * various declarations within the given translation unit.
2167 */
2168CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2169
2170/**
2171 * \brief Determine whether two cursors are equivalent.
2172 */
2173CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002174
Douglas Gregor6007cf22010-01-22 22:29:16 +00002175/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002176 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002177 */
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002178CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002179
2180/**
Douglas Gregor06a3f302010-11-20 00:09:34 +00002181 * \brief Compute a hash value for the given cursor.
2182 */
2183CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2184
2185/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002186 * \brief Retrieve the kind of the given cursor.
2187 */
2188CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2189
2190/**
2191 * \brief Determine whether the given cursor kind represents a declaration.
2192 */
2193CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2194
2195/**
2196 * \brief Determine whether the given cursor kind represents a simple
2197 * reference.
2198 *
2199 * Note that other kinds of cursors (such as expressions) can also refer to
2200 * other cursors. Use clang_getCursorReferenced() to determine whether a
2201 * particular cursor refers to another entity.
2202 */
2203CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2204
2205/**
2206 * \brief Determine whether the given cursor kind represents an expression.
2207 */
2208CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2209
2210/**
2211 * \brief Determine whether the given cursor kind represents a statement.
2212 */
2213CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2214
2215/**
Douglas Gregora98034a2011-07-06 03:00:34 +00002216 * \brief Determine whether the given cursor kind represents an attribute.
2217 */
2218CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2219
2220/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002221 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregor6007cf22010-01-22 22:29:16 +00002222 * cursor.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002223 */
Douglas Gregor6007cf22010-01-22 22:29:16 +00002224CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2225
2226/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002227 * \brief Determine whether the given cursor kind represents a translation
2228 * unit.
Douglas Gregor6007cf22010-01-22 22:29:16 +00002229 */
2230CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002231
Ted Kremenekff9021b2010-03-08 21:17:29 +00002232/***
Douglas Gregor92a524f2010-03-18 00:42:48 +00002233 * \brief Determine whether the given cursor represents a preprocessing
2234 * element, such as a preprocessor directive or macro instantiation.
2235 */
2236CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2237
2238/***
Ted Kremenekff9021b2010-03-08 21:17:29 +00002239 * \brief Determine whether the given cursor represents a currently
2240 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2241 */
2242CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2243
Douglas Gregor6007cf22010-01-22 22:29:16 +00002244/**
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002245 * \brief Describe the linkage of the entity referred to by a cursor.
2246 */
2247enum CXLinkageKind {
2248 /** \brief This value indicates that no linkage information is available
2249 * for a provided CXCursor. */
2250 CXLinkage_Invalid,
2251 /**
2252 * \brief This is the linkage for variables, parameters, and so on that
2253 * have automatic storage. This covers normal (non-extern) local variables.
2254 */
2255 CXLinkage_NoLinkage,
2256 /** \brief This is the linkage for static variables and static functions. */
2257 CXLinkage_Internal,
2258 /** \brief This is the linkage for entities with external linkage that live
2259 * in C++ anonymous namespaces.*/
2260 CXLinkage_UniqueExternal,
2261 /** \brief This is the linkage for entities with true, external linkage. */
2262 CXLinkage_External
2263};
2264
2265/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002266 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002267 */
2268CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2269
2270/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002271 * \brief Determine the availability of the entity that this cursor refers to,
2272 * taking the current target platform into account.
Douglas Gregorf757a122010-08-23 23:00:57 +00002273 *
2274 * \param cursor The cursor to query.
2275 *
2276 * \returns The availability of the cursor.
2277 */
2278CINDEX_LINKAGE enum CXAvailabilityKind
2279clang_getCursorAvailability(CXCursor cursor);
2280
2281/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002282 * Describes the availability of a given entity on a particular platform, e.g.,
2283 * a particular class might only be available on Mac OS 10.7 or newer.
2284 */
2285typedef struct CXPlatformAvailability {
2286 /**
2287 * \brief A string that describes the platform for which this structure
2288 * provides availability information.
2289 *
2290 * Possible values are "ios" or "macosx".
2291 */
2292 CXString Platform;
2293 /**
2294 * \brief The version number in which this entity was introduced.
2295 */
2296 CXVersion Introduced;
2297 /**
2298 * \brief The version number in which this entity was deprecated (but is
2299 * still available).
2300 */
2301 CXVersion Deprecated;
2302 /**
2303 * \brief The version number in which this entity was obsoleted, and therefore
2304 * is no longer available.
2305 */
2306 CXVersion Obsoleted;
2307 /**
2308 * \brief Whether the entity is unconditionally unavailable on this platform.
2309 */
2310 int Unavailable;
2311 /**
2312 * \brief An optional message to provide to a user of this API, e.g., to
2313 * suggest replacement APIs.
2314 */
2315 CXString Message;
2316} CXPlatformAvailability;
2317
2318/**
2319 * \brief Determine the availability of the entity that this cursor refers to
2320 * on any platforms for which availability information is known.
2321 *
2322 * \param cursor The cursor to query.
2323 *
2324 * \param always_deprecated If non-NULL, will be set to indicate whether the
2325 * entity is deprecated on all platforms.
2326 *
2327 * \param deprecated_message If non-NULL, will be set to the message text
2328 * provided along with the unconditional deprecation of this entity. The client
2329 * is responsible for deallocating this string.
2330 *
James Dennett574cb4c2012-06-15 05:41:51 +00002331 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregord6225d32012-05-08 00:14:45 +00002332 * entity is unavailable on all platforms.
2333 *
2334 * \param unavailable_message If non-NULL, will be set to the message text
2335 * provided along with the unconditional unavailability of this entity. The
2336 * client is responsible for deallocating this string.
2337 *
2338 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2339 * that will be populated with platform availability information, up to either
2340 * the number of platforms for which availability information is available (as
2341 * returned by this function) or \c availability_size, whichever is smaller.
2342 *
2343 * \param availability_size The number of elements available in the
2344 * \c availability array.
2345 *
2346 * \returns The number of platforms (N) for which availability information is
2347 * available (which is unrelated to \c availability_size).
2348 *
2349 * Note that the client is responsible for calling
2350 * \c clang_disposeCXPlatformAvailability to free each of the
2351 * platform-availability structures returned. There are
2352 * \c min(N, availability_size) such structures.
2353 */
2354CINDEX_LINKAGE int
2355clang_getCursorPlatformAvailability(CXCursor cursor,
2356 int *always_deprecated,
2357 CXString *deprecated_message,
2358 int *always_unavailable,
2359 CXString *unavailable_message,
2360 CXPlatformAvailability *availability,
2361 int availability_size);
2362
2363/**
2364 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2365 */
2366CINDEX_LINKAGE void
2367clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2368
2369/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002370 * \brief Describe the "language" of the entity referred to by a cursor.
2371 */
2372CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenekee457512010-04-14 20:58:32 +00002373 CXLanguage_Invalid = 0,
Ted Kremenek4ed29252010-04-12 21:22:16 +00002374 CXLanguage_C,
2375 CXLanguage_ObjC,
Ted Kremenekee457512010-04-14 20:58:32 +00002376 CXLanguage_CPlusPlus
Ted Kremenek4ed29252010-04-12 21:22:16 +00002377};
2378
2379/**
2380 * \brief Determine the "language" of the entity referred to by a given cursor.
2381 */
2382CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2383
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002384/**
2385 * \brief Returns the translation unit that a cursor originated from.
2386 */
2387CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2388
Ted Kremenekc0b98662013-04-24 07:17:12 +00002389
2390/**
2391 * \brief A fast container representing a set of CXCursors.
2392 */
2393typedef struct CXCursorSetImpl *CXCursorSet;
2394
2395/**
2396 * \brief Creates an empty CXCursorSet.
2397 */
2398CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2399
2400/**
2401 * \brief Disposes a CXCursorSet and releases its associated memory.
2402 */
2403CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2404
2405/**
2406 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2407 *
2408 * \returns non-zero if the set contains the specified cursor.
2409*/
2410CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2411 CXCursor cursor);
2412
2413/**
2414 * \brief Inserts a CXCursor into a CXCursorSet.
2415 *
2416 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2417*/
2418CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2419 CXCursor cursor);
2420
Douglas Gregor0576ce72010-09-22 21:22:29 +00002421/**
2422 * \brief Determine the semantic parent of the given cursor.
2423 *
2424 * The semantic parent of a cursor is the cursor that semantically contains
2425 * the given \p cursor. For many declarations, the lexical and semantic parents
2426 * are equivalent (the lexical parent is returned by
2427 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2428 * definitions are provided out-of-line. For example:
2429 *
2430 * \code
2431 * class C {
2432 * void f();
2433 * };
2434 *
2435 * void C::f() { }
2436 * \endcode
2437 *
2438 * In the out-of-line definition of \c C::f, the semantic parent is the
2439 * the class \c C, of which this function is a member. The lexical parent is
2440 * the place where the declaration actually occurs in the source code; in this
2441 * case, the definition occurs in the translation unit. In general, the
2442 * lexical parent for a given entity can change without affecting the semantics
2443 * of the program, and the lexical parent of different declarations of the
2444 * same entity may be different. Changing the semantic parent of a declaration,
2445 * on the other hand, can have a major impact on semantics, and redeclarations
2446 * of a particular entity should all have the same semantic context.
2447 *
2448 * In the example above, both declarations of \c C::f have \c C as their
2449 * semantic context, while the lexical context of the first \c C::f is \c C
2450 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002451 *
2452 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002453 */
2454CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2455
2456/**
2457 * \brief Determine the lexical parent of the given cursor.
2458 *
2459 * The lexical parent of a cursor is the cursor in which the given \p cursor
2460 * was actually written. For many declarations, the lexical and semantic parents
2461 * are equivalent (the semantic parent is returned by
2462 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2463 * definitions are provided out-of-line. For example:
2464 *
2465 * \code
2466 * class C {
2467 * void f();
2468 * };
2469 *
2470 * void C::f() { }
2471 * \endcode
2472 *
2473 * In the out-of-line definition of \c C::f, the semantic parent is the
2474 * the class \c C, of which this function is a member. The lexical parent is
2475 * the place where the declaration actually occurs in the source code; in this
2476 * case, the definition occurs in the translation unit. In general, the
2477 * lexical parent for a given entity can change without affecting the semantics
2478 * of the program, and the lexical parent of different declarations of the
2479 * same entity may be different. Changing the semantic parent of a declaration,
2480 * on the other hand, can have a major impact on semantics, and redeclarations
2481 * of a particular entity should all have the same semantic context.
2482 *
2483 * In the example above, both declarations of \c C::f have \c C as their
2484 * semantic context, while the lexical context of the first \c C::f is \c C
2485 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002486 *
2487 * For declarations written in the global scope, the lexical parent is
2488 * the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002489 */
2490CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor99a26af2010-10-01 20:25:15 +00002491
2492/**
2493 * \brief Determine the set of methods that are overridden by the given
2494 * method.
2495 *
2496 * In both Objective-C and C++, a method (aka virtual member function,
2497 * in C++) can override a virtual method in a base class. For
2498 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidisbfb24252012-03-08 00:20:03 +00002499 * base class, its protocols, or its categories' protocols, that has the same
2500 * selector and is of the same kind (class or instance).
2501 * If no such method exists, the search continues to the class's superclass,
2502 * its protocols, and its categories, and so on. A method from an Objective-C
2503 * implementation is considered to override the same methods as its
2504 * corresponding method in the interface.
Douglas Gregor99a26af2010-10-01 20:25:15 +00002505 *
2506 * For C++, a virtual member function overrides any virtual member
2507 * function with the same signature that occurs in its base
2508 * classes. With multiple inheritance, a virtual member function can
2509 * override several virtual member functions coming from different
2510 * base classes.
2511 *
2512 * In all cases, this function determines the immediate overridden
2513 * method, rather than all of the overridden methods. For example, if
2514 * a method is originally declared in a class A, then overridden in B
2515 * (which in inherits from A) and also in C (which inherited from B),
2516 * then the only overridden method returned from this function when
2517 * invoked on C's method will be B's method. The client may then
2518 * invoke this function again, given the previously-found overridden
2519 * methods, to map out the complete method-override set.
2520 *
2521 * \param cursor A cursor representing an Objective-C or C++
2522 * method. This routine will compute the set of methods that this
2523 * method overrides.
2524 *
2525 * \param overridden A pointer whose pointee will be replaced with a
2526 * pointer to an array of cursors, representing the set of overridden
2527 * methods. If there are no overridden methods, the pointee will be
2528 * set to NULL. The pointee must be freed via a call to
2529 * \c clang_disposeOverriddenCursors().
2530 *
2531 * \param num_overridden A pointer to the number of overridden
2532 * functions, will be set to the number of overridden functions in the
2533 * array pointed to by \p overridden.
2534 */
2535CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2536 CXCursor **overridden,
2537 unsigned *num_overridden);
2538
2539/**
2540 * \brief Free the set of overridden cursors returned by \c
2541 * clang_getOverriddenCursors().
2542 */
2543CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2544
Ted Kremenek4ed29252010-04-12 21:22:16 +00002545/**
Douglas Gregor796d76a2010-10-20 22:00:55 +00002546 * \brief Retrieve the file that is included by the given inclusion directive
2547 * cursor.
2548 */
2549CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2550
2551/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002552 * @}
2553 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002554
Douglas Gregor6007cf22010-01-22 22:29:16 +00002555/**
2556 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2557 *
2558 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2559 * routines help map between cursors and the physical locations where the
2560 * described entities occur in the source code. The mapping is provided in
2561 * both directions, so one can map from source code to the AST and back.
2562 *
2563 * @{
Steve Naroffa1c72842009-08-28 15:28:48 +00002564 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002565
Steve Naroff20bad0b2009-10-21 13:56:23 +00002566/**
Douglas Gregor816fd362010-01-22 21:44:22 +00002567 * \brief Map a source location to the cursor that describes the entity at that
2568 * location in the source code.
2569 *
2570 * clang_getCursor() maps an arbitrary source location within a translation
2571 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002572 * location. For example, given an expression \c x + y, invoking
Douglas Gregor816fd362010-01-22 21:44:22 +00002573 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002574 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregor816fd362010-01-22 21:44:22 +00002575 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2576 * will return a cursor referring to the "+" expression.
2577 *
2578 * \returns a cursor representing the entity at the given source location, or
2579 * a NULL cursor if no such entity can be found.
Steve Naroff20bad0b2009-10-21 13:56:23 +00002580 */
Douglas Gregor816fd362010-01-22 21:44:22 +00002581CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002582
Douglas Gregor66a58812010-01-18 22:46:11 +00002583/**
2584 * \brief Retrieve the physical location of the source constructor referenced
2585 * by the given cursor.
2586 *
2587 * The location of a declaration is typically the location of the name of that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002588 * declaration, where the name of that declaration would occur if it is
2589 * unnamed, or some keyword that introduces that particular declaration.
2590 * The location of a reference is where that reference occurs within the
Douglas Gregor66a58812010-01-18 22:46:11 +00002591 * source code.
2592 */
2593CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregor6007cf22010-01-22 22:29:16 +00002594
Douglas Gregor6b8232f2010-01-19 19:34:47 +00002595/**
2596 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002597 * the given cursor.
2598 *
2599 * The extent of a cursor starts with the file/line/column pointing at the
2600 * first character within the source construct that the cursor refers to and
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002601 * ends with the last character withinin that source construct. For a
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002602 * declaration, the extent covers the declaration itself. For a reference,
2603 * the extent covers the location of the reference (e.g., where the referenced
2604 * entity was actually used).
2605 */
2606CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorad27e8b2010-01-19 01:20:04 +00002607
Douglas Gregor6007cf22010-01-22 22:29:16 +00002608/**
2609 * @}
2610 */
Ted Kremeneka5940822010-08-26 01:42:22 +00002611
Douglas Gregor6007cf22010-01-22 22:29:16 +00002612/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002613 * \defgroup CINDEX_TYPES Type information for CXCursors
2614 *
2615 * @{
2616 */
2617
2618/**
2619 * \brief Describes the kind of type
2620 */
2621enum CXTypeKind {
2622 /**
2623 * \brief Reprents an invalid type (e.g., where no type is available).
2624 */
2625 CXType_Invalid = 0,
2626
2627 /**
2628 * \brief A type whose specific kind is not exposed via this
2629 * interface.
2630 */
2631 CXType_Unexposed = 1,
2632
2633 /* Builtin types */
2634 CXType_Void = 2,
2635 CXType_Bool = 3,
2636 CXType_Char_U = 4,
2637 CXType_UChar = 5,
2638 CXType_Char16 = 6,
2639 CXType_Char32 = 7,
2640 CXType_UShort = 8,
2641 CXType_UInt = 9,
2642 CXType_ULong = 10,
2643 CXType_ULongLong = 11,
2644 CXType_UInt128 = 12,
2645 CXType_Char_S = 13,
2646 CXType_SChar = 14,
2647 CXType_WChar = 15,
2648 CXType_Short = 16,
2649 CXType_Int = 17,
2650 CXType_Long = 18,
2651 CXType_LongLong = 19,
2652 CXType_Int128 = 20,
2653 CXType_Float = 21,
2654 CXType_Double = 22,
2655 CXType_LongDouble = 23,
2656 CXType_NullPtr = 24,
2657 CXType_Overload = 25,
2658 CXType_Dependent = 26,
2659 CXType_ObjCId = 27,
2660 CXType_ObjCClass = 28,
2661 CXType_ObjCSel = 29,
2662 CXType_FirstBuiltin = CXType_Void,
2663 CXType_LastBuiltin = CXType_ObjCSel,
2664
2665 CXType_Complex = 100,
2666 CXType_Pointer = 101,
2667 CXType_BlockPointer = 102,
2668 CXType_LValueReference = 103,
2669 CXType_RValueReference = 104,
2670 CXType_Record = 105,
2671 CXType_Enum = 106,
2672 CXType_Typedef = 107,
2673 CXType_ObjCInterface = 108,
Ted Kremenekc1508872010-06-21 20:15:39 +00002674 CXType_ObjCObjectPointer = 109,
2675 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002676 CXType_FunctionProto = 111,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002677 CXType_ConstantArray = 112,
Argyrios Kyrtzidis0661a712013-07-23 17:36:21 +00002678 CXType_Vector = 113,
2679 CXType_IncompleteArray = 114,
2680 CXType_VariableArray = 115,
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00002681 CXType_DependentSizedArray = 116,
2682 CXType_MemberPointer = 117
Ted Kremenek6bca9842010-05-14 21:29:26 +00002683};
2684
2685/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002686 * \brief Describes the calling convention of a function type
2687 */
2688enum CXCallingConv {
2689 CXCallingConv_Default = 0,
2690 CXCallingConv_C = 1,
2691 CXCallingConv_X86StdCall = 2,
2692 CXCallingConv_X86FastCall = 3,
2693 CXCallingConv_X86ThisCall = 4,
2694 CXCallingConv_X86Pascal = 5,
2695 CXCallingConv_AAPCS = 6,
2696 CXCallingConv_AAPCS_VFP = 7,
Derek Schuffa2020962012-10-16 22:30:41 +00002697 CXCallingConv_PnaclCall = 8,
Guy Benyeif0a014b2012-12-25 08:53:55 +00002698 CXCallingConv_IntelOclBicc = 9,
Charles Davisb5a214e2013-08-30 04:39:01 +00002699 CXCallingConv_X86_64Win64 = 10,
2700 CXCallingConv_X86_64SysV = 11,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002701
2702 CXCallingConv_Invalid = 100,
2703 CXCallingConv_Unexposed = 200
2704};
2705
2706
2707/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002708 * \brief The type of an element in the abstract syntax tree.
2709 *
2710 */
2711typedef struct {
2712 enum CXTypeKind kind;
2713 void *data[2];
2714} CXType;
2715
2716/**
2717 * \brief Retrieve the type of a CXCursor (if any).
2718 */
2719CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2720
2721/**
Dmitri Gribenko00353722013-02-15 21:15:49 +00002722 * \brief Pretty-print the underlying type using the rules of the
2723 * language of the translation unit from which it came.
2724 *
2725 * If the type is invalid, an empty string is returned.
2726 */
2727CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2728
2729/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002730 * \brief Retrieve the underlying type of a typedef declaration.
2731 *
2732 * If the cursor does not reference a typedef declaration, an invalid type is
2733 * returned.
2734 */
2735CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2736
2737/**
2738 * \brief Retrieve the integer type of an enum declaration.
2739 *
2740 * If the cursor does not reference an enum declaration, an invalid type is
2741 * returned.
2742 */
2743CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2744
2745/**
2746 * \brief Retrieve the integer value of an enum constant declaration as a signed
2747 * long long.
2748 *
2749 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2750 * Since this is also potentially a valid constant value, the kind of the cursor
2751 * must be verified before calling this function.
2752 */
2753CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2754
2755/**
2756 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2757 * long long.
2758 *
2759 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2760 * Since this is also potentially a valid constant value, the kind of the cursor
2761 * must be verified before calling this function.
2762 */
2763CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2764
2765/**
Dmitri Gribenkob506ba12012-12-04 15:13:46 +00002766 * \brief Retrieve the bit width of a bit field declaration as an integer.
2767 *
2768 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2769 */
2770CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2771
2772/**
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002773 * \brief Retrieve the number of non-variadic arguments associated with a given
2774 * cursor.
2775 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002776 * The number of arguments can be determined for calls as well as for
2777 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002778 */
2779CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2780
2781/**
2782 * \brief Retrieve the argument cursor of a function or method.
2783 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002784 * The argument cursor can be determined for calls as well as for declarations
2785 * of functions or methods. For other cursors and for invalid indices, an
2786 * invalid cursor is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002787 */
2788CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2789
2790/**
James Dennett574cb4c2012-06-15 05:41:51 +00002791 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002792 *
James Dennett574cb4c2012-06-15 05:41:51 +00002793 * \returns non-zero if the CXTypes represent the same type and
2794 * zero otherwise.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002795 */
2796CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2797
2798/**
2799 * \brief Return the canonical type for a CXType.
2800 *
2801 * Clang's type system explicitly models typedefs and all the ways
2802 * a specific type can be represented. The canonical type is the underlying
2803 * type with all the "sugar" removed. For example, if 'T' is a typedef
2804 * for 'int', the canonical type for 'T' would be 'int'.
2805 */
2806CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2807
2808/**
James Dennett574cb4c2012-06-15 05:41:51 +00002809 * \brief Determine whether a CXType has the "const" qualifier set,
2810 * without looking through typedefs that may have added "const" at a
2811 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002812 */
2813CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2814
2815/**
James Dennett574cb4c2012-06-15 05:41:51 +00002816 * \brief Determine whether a CXType has the "volatile" qualifier set,
2817 * without looking through typedefs that may have added "volatile" at
2818 * a different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002819 */
2820CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2821
2822/**
James Dennett574cb4c2012-06-15 05:41:51 +00002823 * \brief Determine whether a CXType has the "restrict" qualifier set,
2824 * without looking through typedefs that may have added "restrict" at a
2825 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00002826 */
2827CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2828
2829/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002830 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek6bca9842010-05-14 21:29:26 +00002831 */
2832CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2833
2834/**
2835 * \brief Return the cursor for the declaration of the given type.
2836 */
2837CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2838
David Chisnall50e4eba2010-12-30 14:05:53 +00002839/**
2840 * Returns the Objective-C type encoding for the specified declaration.
2841 */
2842CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek6bca9842010-05-14 21:29:26 +00002843
2844/**
2845 * \brief Retrieve the spelling of a given CXTypeKind.
2846 */
2847CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2848
2849/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002850 * \brief Retrieve the calling convention associated with a function type.
2851 *
2852 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2853 */
2854CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2855
2856/**
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00002857 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002858 *
2859 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenekc1508872010-06-21 20:15:39 +00002860 */
2861CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2862
2863/**
James Dennett574cb4c2012-06-15 05:41:51 +00002864 * \brief Retrieve the number of non-variadic arguments associated with a
2865 * function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002866 *
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002867 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002868 */
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002869CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002870
2871/**
2872 * \brief Retrieve the type of an argument of a function type.
2873 *
James Dennett574cb4c2012-06-15 05:41:51 +00002874 * If a non-function type is passed in or the function does not have enough
2875 * parameters, an invalid type is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002876 */
2877CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2878
2879/**
2880 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002881 */
2882CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2883
2884/**
2885 * \brief Retrieve the result type associated with a given cursor.
2886 *
2887 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00002888 */
2889CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2890
2891/**
Ted Kremenek0c7476a2010-07-30 00:14:11 +00002892 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2893 * otherwise.
2894 */
2895CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2896
2897/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002898 * \brief Return the element type of an array, complex, or vector type.
2899 *
2900 * If a type is passed in that is not an array, complex, or vector type,
2901 * an invalid type is returned.
2902 */
2903CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2904
2905/**
2906 * \brief Return the number of elements of an array or vector type.
2907 *
2908 * If a type is passed in that is not an array or vector type,
2909 * -1 is returned.
2910 */
2911CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2912
2913/**
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002914 * \brief Return the element type of an array type.
2915 *
2916 * If a non-array type is passed in, an invalid type is returned.
2917 */
2918CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2919
2920/**
Sylvestre Ledru830885c2012-07-23 08:59:39 +00002921 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002922 *
2923 * If a non-array type is passed in, -1 is returned.
2924 */
2925CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2926
2927/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00002928 * \brief List the possible error codes for \c clang_Type_getSizeOf,
2929 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
2930 * \c clang_Cursor_getOffsetOf.
2931 *
2932 * A value of this enumeration type can be returned if the target type is not
2933 * a valid argument to sizeof, alignof or offsetof.
2934 */
2935enum CXTypeLayoutError {
2936 /**
2937 * \brief Type is of kind CXType_Invalid.
2938 */
2939 CXTypeLayoutError_Invalid = -1,
2940 /**
2941 * \brief The type is an incomplete Type.
2942 */
2943 CXTypeLayoutError_Incomplete = -2,
2944 /**
2945 * \brief The type is a dependent Type.
2946 */
2947 CXTypeLayoutError_Dependent = -3,
2948 /**
2949 * \brief The type is not a constant size type.
2950 */
2951 CXTypeLayoutError_NotConstantSize = -4,
2952 /**
2953 * \brief The Field name is not valid for this record.
2954 */
2955 CXTypeLayoutError_InvalidFieldName = -5
2956};
2957
2958/**
2959 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
2960 * standard.
2961 *
2962 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2963 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2964 * is returned.
2965 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2966 * returned.
2967 * If the type declaration is not a constant size type,
2968 * CXTypeLayoutError_NotConstantSize is returned.
2969 */
2970CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
2971
2972/**
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00002973 * \brief Return the class type of an member pointer type.
2974 *
2975 * If a non-member-pointer type is passed in, an invalid type is returned.
2976 */
2977CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T);
2978
2979/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00002980 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
2981 *
2982 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
2983 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
2984 * is returned.
2985 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
2986 * returned.
2987 */
2988CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
2989
2990/**
2991 * \brief Return the offset of a field named S in a record of type T in bits
2992 * as it would be returned by __offsetof__ as per C++11[18.2p4]
2993 *
2994 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
2995 * is returned.
2996 * If the field's type declaration is an incomplete type,
2997 * CXTypeLayoutError_Incomplete is returned.
2998 * If the field's type declaration is a dependent type,
2999 * CXTypeLayoutError_Dependent is returned.
3000 * If the field's name S is not found,
3001 * CXTypeLayoutError_InvalidFieldName is returned.
3002 */
3003CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
3004
Argyrios Kyrtzidisadff3ae2013-10-11 19:58:38 +00003005enum CXRefQualifierKind {
3006 /** \brief No ref-qualifier was provided. */
3007 CXRefQualifier_None = 0,
3008 /** \brief An lvalue ref-qualifier was provided (\c &). */
3009 CXRefQualifier_LValue,
3010 /** \brief An rvalue ref-qualifier was provided (\c &&). */
3011 CXRefQualifier_RValue
3012};
3013
3014/**
3015 * \brief Retrieve the ref-qualifier kind of a function or method.
3016 *
3017 * The ref-qualifier is returned for C++ functions or methods. For other types
3018 * or non-C++ declarations, CXRefQualifier_None is returned.
3019 */
3020CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
3021
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003022/**
3023 * \brief Returns non-zero if the cursor specifies a Record member that is a
3024 * bitfield.
3025 */
3026CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
3027
3028/**
Ted Kremenekae9e2212010-08-27 21:34:58 +00003029 * \brief Returns 1 if the base class specified by the cursor with kind
3030 * CX_CXXBaseSpecifier is virtual.
3031 */
3032CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3033
3034/**
3035 * \brief Represents the C++ access control level to a base class for a
3036 * cursor with kind CX_CXXBaseSpecifier.
3037 */
3038enum CX_CXXAccessSpecifier {
3039 CX_CXXInvalidAccessSpecifier,
3040 CX_CXXPublic,
3041 CX_CXXProtected,
3042 CX_CXXPrivate
3043};
3044
3045/**
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003046 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidisf6464082013-04-11 17:31:13 +00003047 *
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003048 * If the cursor refers to a C++ declaration, its access control level within its
3049 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3050 * access specifier, the specifier itself is returned.
Ted Kremenekae9e2212010-08-27 21:34:58 +00003051 */
3052CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3053
3054/**
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00003055 * \brief Determine the number of overloaded declarations referenced by a
3056 * \c CXCursor_OverloadedDeclRef cursor.
3057 *
3058 * \param cursor The cursor whose overloaded declarations are being queried.
3059 *
3060 * \returns The number of overloaded declarations referenced by \c cursor. If it
3061 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3062 */
3063CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3064
3065/**
3066 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3067 * by a \c CXCursor_OverloadedDeclRef cursor.
3068 *
3069 * \param cursor The cursor whose overloaded declarations are being queried.
3070 *
3071 * \param index The zero-based index into the set of overloaded declarations in
3072 * the cursor.
3073 *
3074 * \returns A cursor representing the declaration referenced by the given
3075 * \c cursor at the specified \c index. If the cursor does not have an
3076 * associated set of overloaded declarations, or if the index is out of bounds,
3077 * returns \c clang_getNullCursor();
3078 */
3079CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3080 unsigned index);
3081
3082/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00003083 * @}
3084 */
Ted Kremeneka5940822010-08-26 01:42:22 +00003085
3086/**
Ted Kremenek2c2c5f32010-08-27 21:34:51 +00003087 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremeneka5940822010-08-26 01:42:22 +00003088 *
3089 * @{
3090 */
3091
3092
3093/**
3094 * \brief For cursors representing an iboutletcollection attribute,
3095 * this function returns the collection element type.
3096 *
3097 */
3098CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3099
3100/**
3101 * @}
3102 */
Ted Kremenek6bca9842010-05-14 21:29:26 +00003103
3104/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003105 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3106 *
3107 * These routines provide the ability to traverse the abstract syntax tree
3108 * using cursors.
3109 *
3110 * @{
3111 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003112
Douglas Gregor6007cf22010-01-22 22:29:16 +00003113/**
3114 * \brief Describes how the traversal of the children of a particular
3115 * cursor should proceed after visiting a particular child cursor.
3116 *
3117 * A value of this enumeration type should be returned by each
3118 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3119 */
3120enum CXChildVisitResult {
3121 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003122 * \brief Terminates the cursor traversal.
Douglas Gregor6007cf22010-01-22 22:29:16 +00003123 */
3124 CXChildVisit_Break,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003125 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003126 * \brief Continues the cursor traversal with the next sibling of
3127 * the cursor just visited, without visiting its children.
3128 */
3129 CXChildVisit_Continue,
3130 /**
3131 * \brief Recursively traverse the children of this cursor, using
3132 * the same visitor and client data.
3133 */
3134 CXChildVisit_Recurse
3135};
3136
3137/**
3138 * \brief Visitor invoked for each cursor found by a traversal.
3139 *
3140 * This visitor function will be invoked for each cursor found by
3141 * clang_visitCursorChildren(). Its first argument is the cursor being
3142 * visited, its second argument is the parent visitor for that cursor,
3143 * and its third argument is the client data provided to
3144 * clang_visitCursorChildren().
3145 *
3146 * The visitor should return one of the \c CXChildVisitResult values
3147 * to direct clang_visitCursorChildren().
3148 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003149typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3150 CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003151 CXClientData client_data);
3152
3153/**
3154 * \brief Visit the children of a particular cursor.
3155 *
3156 * This function visits all the direct children of the given cursor,
3157 * invoking the given \p visitor function with the cursors of each
3158 * visited child. The traversal may be recursive, if the visitor returns
3159 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3160 * the visitor returns \c CXChildVisit_Break.
3161 *
Douglas Gregor6007cf22010-01-22 22:29:16 +00003162 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbarb9999fd2010-01-24 04:10:31 +00003163 * cursors can be visited, including invalid cursors (which, by
Douglas Gregor6007cf22010-01-22 22:29:16 +00003164 * definition, have no children).
3165 *
3166 * \param visitor the visitor function that will be invoked for each
3167 * child of \p parent.
3168 *
3169 * \param client_data pointer data supplied by the client, which will
3170 * be passed to the visitor each time it is invoked.
3171 *
3172 * \returns a non-zero value if the traversal was terminated
3173 * prematurely by the visitor returning \c CXChildVisit_Break.
3174 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003175CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003176 CXCursorVisitor visitor,
3177 CXClientData client_data);
David Chisnallb2aa0ef2010-11-03 14:12:26 +00003178#ifdef __has_feature
3179# if __has_feature(blocks)
3180/**
3181 * \brief Visitor invoked for each cursor found by a traversal.
3182 *
3183 * This visitor block will be invoked for each cursor found by
3184 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3185 * visited, its second argument is the parent visitor for that cursor.
3186 *
3187 * The visitor should return one of the \c CXChildVisitResult values
3188 * to direct clang_visitChildrenWithBlock().
3189 */
3190typedef enum CXChildVisitResult
3191 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3192
3193/**
3194 * Visits the children of a cursor using the specified block. Behaves
3195 * identically to clang_visitChildren() in all other respects.
3196 */
3197unsigned clang_visitChildrenWithBlock(CXCursor parent,
3198 CXCursorVisitorBlock block);
3199# endif
3200#endif
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003201
Douglas Gregor6007cf22010-01-22 22:29:16 +00003202/**
3203 * @}
3204 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003205
Douglas Gregor6007cf22010-01-22 22:29:16 +00003206/**
3207 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3208 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003209 * These routines provide the ability to determine references within and
Douglas Gregor6007cf22010-01-22 22:29:16 +00003210 * across translation units, by providing the names of the entities referenced
3211 * by cursors, follow reference cursors to the declarations they reference,
3212 * and associate declarations with their definitions.
3213 *
3214 * @{
3215 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003216
Douglas Gregor6007cf22010-01-22 22:29:16 +00003217/**
3218 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3219 * by the given cursor.
3220 *
3221 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3222 * entity (function, class, variable, etc.) within a program. USRs can be
3223 * compared across translation units to determine, e.g., when references in
3224 * one translation refer to an entity defined in another translation unit.
3225 */
3226CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3227
3228/**
Ted Kremenekd071c602010-03-13 02:50:34 +00003229 * \brief Construct a USR for a specified Objective-C class.
3230 */
3231CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3232
3233/**
3234 * \brief Construct a USR for a specified Objective-C category.
3235 */
3236CINDEX_LINKAGE CXString
Ted Kremenekbc1a67b2010-03-15 17:38:58 +00003237 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenekd071c602010-03-13 02:50:34 +00003238 const char *category_name);
3239
3240/**
3241 * \brief Construct a USR for a specified Objective-C protocol.
3242 */
3243CINDEX_LINKAGE CXString
3244 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3245
3246
3247/**
3248 * \brief Construct a USR for a specified Objective-C instance variable and
3249 * the USR for its containing class.
3250 */
3251CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3252 CXString classUSR);
3253
3254/**
3255 * \brief Construct a USR for a specified Objective-C method and
3256 * the USR for its containing class.
3257 */
3258CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3259 unsigned isInstanceMethod,
3260 CXString classUSR);
3261
3262/**
3263 * \brief Construct a USR for a specified Objective-C property and the USR
3264 * for its containing class.
3265 */
3266CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3267 CXString classUSR);
3268
3269/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003270 * \brief Retrieve a name for the entity referenced by this cursor.
3271 */
3272CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3273
Douglas Gregor97c75712010-10-02 22:49:11 +00003274/**
Argyrios Kyrtzidis191a6a82012-03-30 20:58:35 +00003275 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3276 * Most of the times there is only one range for the complete spelling but for
3277 * objc methods and objc message expressions, there are multiple pieces for each
3278 * selector identifier.
3279 *
3280 * \param pieceIndex the index of the spelling name piece. If this is greater
3281 * than the actual number of pieces, it will return a NULL (invalid) range.
3282 *
3283 * \param options Reserved.
3284 */
3285CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3286 unsigned pieceIndex,
3287 unsigned options);
3288
3289/**
Douglas Gregor97c75712010-10-02 22:49:11 +00003290 * \brief Retrieve the display name for the entity referenced by this cursor.
3291 *
3292 * The display name contains extra information that helps identify the cursor,
3293 * such as the parameters of a function or template or the arguments of a
3294 * class template specialization.
3295 */
3296CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3297
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003298/** \brief For a cursor that is a reference, retrieve a cursor representing the
3299 * entity that it references.
3300 *
3301 * Reference cursors refer to other entities in the AST. For example, an
3302 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003303 * This function produces the cursor for the Objective-C class from the
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003304 * cursor for the superclass reference. If the input cursor is a declaration or
3305 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003306 * Otherwise, returns the NULL cursor.
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003307 */
3308CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003309
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003310/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003311 * \brief For a cursor that is either a reference to or a declaration
3312 * of some entity, retrieve a cursor that describes the definition of
3313 * that entity.
3314 *
3315 * Some entities can be declared multiple times within a translation
3316 * unit, but only one of those declarations can also be a
3317 * definition. For example, given:
3318 *
3319 * \code
3320 * int f(int, int);
3321 * int g(int x, int y) { return f(x, y); }
3322 * int f(int a, int b) { return a + b; }
3323 * int f(int, int);
3324 * \endcode
3325 *
3326 * there are three declarations of the function "f", but only the
3327 * second one is a definition. The clang_getCursorDefinition()
3328 * function will take any cursor pointing to a declaration of "f"
3329 * (the first or fourth lines of the example) or a cursor referenced
3330 * that uses "f" (the call to "f' inside "g") and will return a
3331 * declaration cursor pointing to the definition (the second "f"
3332 * declaration).
3333 *
3334 * If given a cursor for which there is no corresponding definition,
3335 * e.g., because there is no definition of that entity within this
3336 * translation unit, returns a NULL cursor.
3337 */
3338CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3339
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003340/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003341 * \brief Determine whether the declaration pointed to by this cursor
3342 * is also a definition of that entity.
3343 */
3344CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3345
Douglas Gregor6007cf22010-01-22 22:29:16 +00003346/**
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003347 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3348 *
3349 * In the C family of languages, many kinds of entities can be declared several
3350 * times within a single translation unit. For example, a structure type can
3351 * be forward-declared (possibly multiple times) and later defined:
3352 *
3353 * \code
3354 * struct X;
3355 * struct X;
3356 * struct X {
3357 * int member;
3358 * };
3359 * \endcode
3360 *
3361 * The declarations and the definition of \c X are represented by three
3362 * different cursors, all of which are declarations of the same underlying
3363 * entity. One of these cursor is considered the "canonical" cursor, which
3364 * is effectively the representative for the underlying entity. One can
3365 * determine if two cursors are declarations of the same underlying entity by
3366 * comparing their canonical cursors.
3367 *
3368 * \returns The canonical cursor for the entity referred to by the given cursor.
3369 */
3370CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3371
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003372
3373/**
3374 * \brief If the cursor points to a selector identifier in a objc method or
3375 * message expression, this returns the selector index.
3376 *
James Dennett574cb4c2012-06-15 05:41:51 +00003377 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003378 * determine if the location points to a selector identifier.
3379 *
3380 * \returns The selector index if the cursor is an objc method or message
3381 * expression and the cursor is pointing to a selector identifier, or -1
3382 * otherwise.
3383 */
3384CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3385
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003386/**
Argyrios Kyrtzidisb6df68212012-07-02 23:54:36 +00003387 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3388 * returns non-zero if the method/message is "dynamic", meaning:
3389 *
3390 * For a C++ method: the call is virtual.
3391 * For an ObjC message: the receiver is an object instance, not 'super' or a
3392 * specific class.
3393 *
3394 * If the method/message is "static" or the cursor does not point to a
3395 * method/message, it will return zero.
3396 */
3397CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3398
3399/**
Argyrios Kyrtzidisb26a24c2012-11-01 02:01:34 +00003400 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3401 * receiver.
3402 */
3403CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3404
3405/**
Argyrios Kyrtzidis9adfd8a2013-04-18 22:15:49 +00003406 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3407 */
3408typedef enum {
3409 CXObjCPropertyAttr_noattr = 0x00,
3410 CXObjCPropertyAttr_readonly = 0x01,
3411 CXObjCPropertyAttr_getter = 0x02,
3412 CXObjCPropertyAttr_assign = 0x04,
3413 CXObjCPropertyAttr_readwrite = 0x08,
3414 CXObjCPropertyAttr_retain = 0x10,
3415 CXObjCPropertyAttr_copy = 0x20,
3416 CXObjCPropertyAttr_nonatomic = 0x40,
3417 CXObjCPropertyAttr_setter = 0x80,
3418 CXObjCPropertyAttr_atomic = 0x100,
3419 CXObjCPropertyAttr_weak = 0x200,
3420 CXObjCPropertyAttr_strong = 0x400,
3421 CXObjCPropertyAttr_unsafe_unretained = 0x800
3422} CXObjCPropertyAttrKind;
3423
3424/**
3425 * \brief Given a cursor that represents a property declaration, return the
3426 * associated property attributes. The bits are formed from
3427 * \c CXObjCPropertyAttrKind.
3428 *
3429 * \param reserved Reserved for future use, pass 0.
3430 */
3431CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3432 unsigned reserved);
3433
3434/**
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003435 * \brief 'Qualifiers' written next to the return and parameter types in
3436 * ObjC method declarations.
3437 */
3438typedef enum {
3439 CXObjCDeclQualifier_None = 0x0,
3440 CXObjCDeclQualifier_In = 0x1,
3441 CXObjCDeclQualifier_Inout = 0x2,
3442 CXObjCDeclQualifier_Out = 0x4,
3443 CXObjCDeclQualifier_Bycopy = 0x8,
3444 CXObjCDeclQualifier_Byref = 0x10,
3445 CXObjCDeclQualifier_Oneway = 0x20
3446} CXObjCDeclQualifierKind;
3447
3448/**
3449 * \brief Given a cursor that represents an ObjC method or parameter
3450 * declaration, return the associated ObjC qualifiers for the return type or the
Argyrios Kyrtzidis982934e2013-04-19 00:51:52 +00003451 * parameter respectively. The bits are formed from CXObjCDeclQualifierKind.
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003452 */
3453CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3454
3455/**
Argyrios Kyrtzidis7b50fc52013-07-05 20:44:37 +00003456 * \brief Given a cursor that represents an ObjC method or property declaration,
3457 * return non-zero if the declaration was affected by "@optional".
3458 * Returns zero if the cursor is not such a declaration or it is "@required".
3459 */
3460CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
3461
3462/**
Argyrios Kyrtzidis23814e42013-04-18 23:53:05 +00003463 * \brief Returns non-zero if the given cursor is a variadic function or method.
3464 */
3465CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3466
3467/**
Dmitri Gribenkoaab83832012-06-20 00:34:58 +00003468 * \brief Given a cursor that represents a declaration, return the associated
3469 * comment's source range. The range may include multiple consecutive comments
3470 * with whitespace in between.
3471 */
3472CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3473
3474/**
3475 * \brief Given a cursor that represents a declaration, return the associated
3476 * comment text, including comment markers.
3477 */
3478CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3479
3480/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003481 * \brief Given a cursor that represents a documentable entity (e.g.,
3482 * declaration), return the associated \\brief paragraph; otherwise return the
3483 * first paragraph.
Dmitri Gribenko5188c4b2012-06-26 20:39:18 +00003484 */
3485CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3486
3487/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003488 * \brief Given a cursor that represents a documentable entity (e.g.,
3489 * declaration), return the associated parsed comment as a
3490 * \c CXComment_FullComment AST node.
3491 */
3492CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3493
3494/**
3495 * @}
3496 */
3497
3498/**
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003499 * \defgroup CINDEX_MODULE Module introspection
3500 *
3501 * The functions in this group provide access to information about modules.
3502 *
3503 * @{
3504 */
3505
3506typedef void *CXModule;
3507
3508/**
3509 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3510 */
3511CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3512
3513/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003514 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003515 *
Argyrios Kyrtzidis12fdb9e2013-04-26 22:47:49 +00003516 * \returns the module file where the provided module object came from.
3517 */
3518CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3519
3520/**
3521 * \param Module a module object.
3522 *
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003523 * \returns the parent of a sub-module or NULL if the given module is top-level,
3524 * e.g. for 'std.vector' it will return the 'std' module.
3525 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003526CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003527
3528/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003529 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003530 *
3531 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3532 * will return "vector".
3533 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003534CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003535
3536/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003537 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003538 *
3539 * \returns the full name of the module, e.g. "std.vector".
3540 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003541CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003542
3543/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003544 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003545 *
3546 * \returns the number of top level headers associated with this module.
3547 */
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003548CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3549 CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003550
3551/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003552 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003553 *
3554 * \param Index top level header index (zero-based).
3555 *
3556 * \returns the specified top level header associated with the module.
3557 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003558CINDEX_LINKAGE
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003559CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3560 CXModule Module, unsigned Index);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003561
3562/**
3563 * @}
3564 */
3565
3566/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003567 * \defgroup CINDEX_COMMENT Comment AST introspection
3568 *
3569 * The routines in this group provide access to information in the
3570 * documentation comment ASTs.
3571 *
3572 * @{
3573 */
3574
3575/**
3576 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3577 * node can be considered block content (e. g., paragraph), inline content
3578 * (plain text) or neither (the root AST node).
3579 */
3580enum CXCommentKind {
3581 /**
3582 * \brief Null comment. No AST node is constructed at the requested location
3583 * because there is no text or a syntax error.
3584 */
3585 CXComment_Null = 0,
3586
3587 /**
3588 * \brief Plain text. Inline content.
3589 */
3590 CXComment_Text = 1,
3591
3592 /**
3593 * \brief A command with word-like arguments that is considered inline content.
3594 *
3595 * For example: \\c command.
3596 */
3597 CXComment_InlineCommand = 2,
3598
3599 /**
3600 * \brief HTML start tag with attributes (name-value pairs). Considered
3601 * inline content.
3602 *
3603 * For example:
3604 * \verbatim
3605 * <br> <br /> <a href="http://example.org/">
3606 * \endverbatim
3607 */
3608 CXComment_HTMLStartTag = 3,
3609
3610 /**
3611 * \brief HTML end tag. Considered inline content.
3612 *
3613 * For example:
3614 * \verbatim
3615 * </a>
3616 * \endverbatim
3617 */
3618 CXComment_HTMLEndTag = 4,
3619
3620 /**
3621 * \brief A paragraph, contains inline comment. The paragraph itself is
3622 * block content.
3623 */
3624 CXComment_Paragraph = 5,
3625
3626 /**
3627 * \brief A command that has zero or more word-like arguments (number of
3628 * word-like arguments depends on command name) and a paragraph as an
3629 * argument. Block command is block content.
3630 *
3631 * Paragraph argument is also a child of the block command.
3632 *
3633 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3634 *
3635 * AST nodes of special kinds that parser knows about (e. g., \\param
3636 * command) have their own node kinds.
3637 */
3638 CXComment_BlockCommand = 6,
3639
3640 /**
3641 * \brief A \\param or \\arg command that describes the function parameter
3642 * (name, passing direction, description).
3643 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003644 * For example: \\param [in] ParamName description.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003645 */
3646 CXComment_ParamCommand = 7,
3647
3648 /**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003649 * \brief A \\tparam command that describes a template parameter (name and
3650 * description).
3651 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003652 * For example: \\tparam T description.
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003653 */
3654 CXComment_TParamCommand = 8,
3655
3656 /**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003657 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3658 * block has an opening and a closing command and contains multiple lines of
3659 * text (\c CXComment_VerbatimBlockLine child nodes).
3660 *
3661 * For example:
3662 * \\verbatim
3663 * aaa
3664 * \\endverbatim
3665 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003666 CXComment_VerbatimBlockCommand = 9,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003667
3668 /**
3669 * \brief A line of text that is contained within a
3670 * CXComment_VerbatimBlockCommand node.
3671 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003672 CXComment_VerbatimBlockLine = 10,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003673
3674 /**
3675 * \brief A verbatim line command. Verbatim line has an opening command,
3676 * a single line of text (up to the newline after the opening command) and
3677 * has no closing command.
3678 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003679 CXComment_VerbatimLine = 11,
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003680
3681 /**
3682 * \brief A full comment attached to a declaration, contains block content.
3683 */
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003684 CXComment_FullComment = 12
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003685};
3686
3687/**
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003688 * \brief The most appropriate rendering mode for an inline command, chosen on
3689 * command semantics in Doxygen.
3690 */
3691enum CXCommentInlineCommandRenderKind {
3692 /**
3693 * \brief Command argument should be rendered in a normal font.
3694 */
3695 CXCommentInlineCommandRenderKind_Normal,
3696
3697 /**
3698 * \brief Command argument should be rendered in a bold font.
3699 */
3700 CXCommentInlineCommandRenderKind_Bold,
3701
3702 /**
3703 * \brief Command argument should be rendered in a monospaced font.
3704 */
3705 CXCommentInlineCommandRenderKind_Monospaced,
3706
3707 /**
3708 * \brief Command argument should be rendered emphasized (typically italic
3709 * font).
3710 */
3711 CXCommentInlineCommandRenderKind_Emphasized
3712};
3713
3714/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003715 * \brief Describes parameter passing direction for \\param or \\arg command.
3716 */
3717enum CXCommentParamPassDirection {
3718 /**
3719 * \brief The parameter is an input parameter.
3720 */
3721 CXCommentParamPassDirection_In,
3722
3723 /**
3724 * \brief The parameter is an output parameter.
3725 */
3726 CXCommentParamPassDirection_Out,
3727
3728 /**
3729 * \brief The parameter is an input and output parameter.
3730 */
3731 CXCommentParamPassDirection_InOut
3732};
3733
3734/**
3735 * \param Comment AST node of any kind.
3736 *
3737 * \returns the type of the AST node.
3738 */
3739CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3740
3741/**
3742 * \param Comment AST node of any kind.
3743 *
3744 * \returns number of children of the AST node.
3745 */
3746CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3747
3748/**
3749 * \param Comment AST node of any kind.
3750 *
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00003751 * \param ChildIdx child index (zero-based).
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003752 *
3753 * \returns the specified child of the AST node.
3754 */
3755CINDEX_LINKAGE
3756CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3757
3758/**
3759 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3760 * only \c CXComment_Text nodes that are empty or whitespace.
3761 *
3762 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3763 * never considered whitespace.
3764 *
3765 * \returns non-zero if \c Comment is whitespace.
3766 */
3767CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3768
3769/**
3770 * \returns non-zero if \c Comment is inline content and has a newline
3771 * immediately following it in the comment text. Newlines between paragraphs
3772 * do not count.
3773 */
3774CINDEX_LINKAGE
3775unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3776
3777/**
3778 * \param Comment a \c CXComment_Text AST node.
3779 *
3780 * \returns text contained in the AST node.
3781 */
3782CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3783
3784/**
3785 * \param Comment a \c CXComment_InlineCommand AST node.
3786 *
3787 * \returns name of the inline command.
3788 */
3789CINDEX_LINKAGE
3790CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3791
3792/**
3793 * \param Comment a \c CXComment_InlineCommand AST node.
3794 *
Dmitri Gribenkod73e4ce2012-07-23 16:43:01 +00003795 * \returns the most appropriate rendering mode, chosen on command
3796 * semantics in Doxygen.
3797 */
3798CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3799clang_InlineCommandComment_getRenderKind(CXComment Comment);
3800
3801/**
3802 * \param Comment a \c CXComment_InlineCommand AST node.
3803 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003804 * \returns number of command arguments.
3805 */
3806CINDEX_LINKAGE
3807unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3808
3809/**
3810 * \param Comment a \c CXComment_InlineCommand AST node.
3811 *
3812 * \param ArgIdx argument index (zero-based).
3813 *
3814 * \returns text of the specified argument.
3815 */
3816CINDEX_LINKAGE
3817CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3818 unsigned ArgIdx);
3819
3820/**
3821 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3822 * node.
3823 *
3824 * \returns HTML tag name.
3825 */
3826CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3827
3828/**
3829 * \param Comment a \c CXComment_HTMLStartTag AST node.
3830 *
3831 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
3832 */
3833CINDEX_LINKAGE
3834unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3835
3836/**
3837 * \param Comment a \c CXComment_HTMLStartTag AST node.
3838 *
3839 * \returns number of attributes (name-value pairs) attached to the start tag.
3840 */
3841CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3842
3843/**
3844 * \param Comment a \c CXComment_HTMLStartTag AST node.
3845 *
3846 * \param AttrIdx attribute index (zero-based).
3847 *
3848 * \returns name of the specified attribute.
3849 */
3850CINDEX_LINKAGE
3851CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3852
3853/**
3854 * \param Comment a \c CXComment_HTMLStartTag AST node.
3855 *
3856 * \param AttrIdx attribute index (zero-based).
3857 *
3858 * \returns value of the specified attribute.
3859 */
3860CINDEX_LINKAGE
3861CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3862
3863/**
3864 * \param Comment a \c CXComment_BlockCommand AST node.
3865 *
3866 * \returns name of the block command.
3867 */
3868CINDEX_LINKAGE
3869CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3870
3871/**
3872 * \param Comment a \c CXComment_BlockCommand AST node.
3873 *
3874 * \returns number of word-like arguments.
3875 */
3876CINDEX_LINKAGE
3877unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3878
3879/**
3880 * \param Comment a \c CXComment_BlockCommand AST node.
3881 *
3882 * \param ArgIdx argument index (zero-based).
3883 *
3884 * \returns text of the specified word-like argument.
3885 */
3886CINDEX_LINKAGE
3887CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3888 unsigned ArgIdx);
3889
3890/**
3891 * \param Comment a \c CXComment_BlockCommand or
3892 * \c CXComment_VerbatimBlockCommand AST node.
3893 *
3894 * \returns paragraph argument of the block command.
3895 */
3896CINDEX_LINKAGE
3897CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3898
3899/**
3900 * \param Comment a \c CXComment_ParamCommand AST node.
3901 *
3902 * \returns parameter name.
3903 */
3904CINDEX_LINKAGE
3905CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3906
3907/**
3908 * \param Comment a \c CXComment_ParamCommand AST node.
3909 *
3910 * \returns non-zero if the parameter that this AST node represents was found
3911 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3912 * function will return a meaningful value.
3913 */
3914CINDEX_LINKAGE
3915unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3916
3917/**
3918 * \param Comment a \c CXComment_ParamCommand AST node.
3919 *
3920 * \returns zero-based parameter index in function prototype.
3921 */
3922CINDEX_LINKAGE
3923unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3924
3925/**
3926 * \param Comment a \c CXComment_ParamCommand AST node.
3927 *
3928 * \returns non-zero if parameter passing direction was specified explicitly in
3929 * the comment.
3930 */
3931CINDEX_LINKAGE
3932unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3933
3934/**
3935 * \param Comment a \c CXComment_ParamCommand AST node.
3936 *
3937 * \returns parameter passing direction.
3938 */
3939CINDEX_LINKAGE
3940enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
3941 CXComment Comment);
3942
3943/**
Dmitri Gribenko34df2202012-07-31 22:37:06 +00003944 * \param Comment a \c CXComment_TParamCommand AST node.
3945 *
3946 * \returns template parameter name.
3947 */
3948CINDEX_LINKAGE
3949CXString clang_TParamCommandComment_getParamName(CXComment Comment);
3950
3951/**
3952 * \param Comment a \c CXComment_TParamCommand AST node.
3953 *
3954 * \returns non-zero if the parameter that this AST node represents was found
3955 * in the template parameter list and
3956 * \c clang_TParamCommandComment_getDepth and
3957 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
3958 * value.
3959 */
3960CINDEX_LINKAGE
3961unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
3962
3963/**
3964 * \param Comment a \c CXComment_TParamCommand AST node.
3965 *
3966 * \returns zero-based nesting depth of this parameter in the template parameter list.
3967 *
3968 * For example,
3969 * \verbatim
3970 * template<typename C, template<typename T> class TT>
3971 * void test(TT<int> aaa);
3972 * \endverbatim
3973 * for C and TT nesting depth is 0,
3974 * for T nesting depth is 1.
3975 */
3976CINDEX_LINKAGE
3977unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
3978
3979/**
3980 * \param Comment a \c CXComment_TParamCommand AST node.
3981 *
3982 * \returns zero-based parameter index in the template parameter list at a
3983 * given nesting depth.
3984 *
3985 * For example,
3986 * \verbatim
3987 * template<typename C, template<typename T> class TT>
3988 * void test(TT<int> aaa);
3989 * \endverbatim
3990 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
3991 * at depth 0 C's index is 0, TT's index is 1.
3992 *
3993 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
3994 * at depth 0 T's index is 1 (same as TT's),
3995 * at depth 1 T's index is 0.
3996 */
3997CINDEX_LINKAGE
3998unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
3999
4000/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004001 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
4002 *
4003 * \returns text contained in the AST node.
4004 */
4005CINDEX_LINKAGE
4006CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
4007
4008/**
4009 * \param Comment a \c CXComment_VerbatimLine AST node.
4010 *
4011 * \returns text contained in the AST node.
4012 */
4013CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
4014
4015/**
4016 * \brief Convert an HTML tag AST node to string.
4017 *
4018 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
4019 * node.
4020 *
4021 * \returns string containing an HTML tag.
4022 */
4023CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
4024
4025/**
4026 * \brief Convert a given full parsed comment to an HTML fragment.
4027 *
4028 * Specific details of HTML layout are subject to change. Don't try to parse
4029 * this HTML back into an AST, use other APIs instead.
4030 *
4031 * Currently the following CSS classes are used:
4032 * \li "para-brief" for \\brief paragraph and equivalent commands;
4033 * \li "para-returns" for \\returns paragraph and equivalent commands;
4034 * \li "word-returns" for the "Returns" word in \\returns paragraph.
4035 *
Dmitri Gribenko4c6d7a22012-07-21 01:47:43 +00004036 * Function argument documentation is rendered as a \<dl\> list with arguments
4037 * sorted in function prototype order. CSS classes used:
4038 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
4039 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
4040 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
4041 * parameter index is invalid.
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004042 *
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004043 * Template parameter documentation is rendered as a \<dl\> list with
4044 * parameters sorted in template parameter list order. CSS classes used:
4045 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
4046 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
Dmitri Gribenko58e41312012-08-01 23:47:30 +00004047 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
Dmitri Gribenko34df2202012-07-31 22:37:06 +00004048 * names inside template template parameters;
4049 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
4050 * parameter position is invalid.
4051 *
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00004052 * \param Comment a \c CXComment_FullComment AST node.
4053 *
4054 * \returns string containing an HTML fragment.
4055 */
4056CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
4057
4058/**
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004059 * \brief Convert a given full parsed comment to an XML document.
4060 *
4061 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
4062 * inside clang source tree.
4063 *
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004064 * \param Comment a \c CXComment_FullComment AST node.
4065 *
4066 * \returns string containing an XML document.
4067 */
Dmitri Gribenko7acbf002012-09-10 20:32:42 +00004068CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +00004069
4070/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004071 * @}
4072 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004073
Douglas Gregor6007cf22010-01-22 22:29:16 +00004074/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004075 * \defgroup CINDEX_CPP C++ AST introspection
4076 *
4077 * The routines in this group provide access information in the ASTs specific
4078 * to C++ language features.
4079 *
4080 * @{
4081 */
4082
4083/**
Dmitri Gribenko62770be2013-05-17 18:38:35 +00004084 * \brief Determine if a C++ member function or member function template is
4085 * pure virtual.
4086 */
4087CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4088
4089/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004090 * \brief Determine if a C++ member function or member function template is
4091 * declared 'static'.
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004092 */
4093CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4094
4095/**
Douglas Gregor9519d922011-05-12 15:17:24 +00004096 * \brief Determine if a C++ member function or member function template is
4097 * explicitly declared 'virtual' or if it overrides a virtual method from
4098 * one of the base classes.
4099 */
4100CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4101
4102/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00004103 * \brief Given a cursor that represents a template, determine
4104 * the cursor kind of the specializations would be generated by instantiating
4105 * the template.
4106 *
4107 * This routine can be used to determine what flavor of function template,
4108 * class template, or class template partial specialization is stored in the
4109 * cursor. For example, it can describe whether a class template cursor is
4110 * declared with "struct", "class" or "union".
4111 *
4112 * \param C The cursor to query. This cursor should represent a template
4113 * declaration.
4114 *
4115 * \returns The cursor kind of the specializations that would be generated
4116 * by instantiating the template \p C. If \p C is not a template, returns
4117 * \c CXCursor_NoDeclFound.
4118 */
4119CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4120
4121/**
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004122 * \brief Given a cursor that may represent a specialization or instantiation
4123 * of a template, retrieve the cursor that represents the template that it
4124 * specializes or from which it was instantiated.
4125 *
4126 * This routine determines the template involved both for explicit
4127 * specializations of templates and for implicit instantiations of the template,
4128 * both of which are referred to as "specializations". For a class template
4129 * specialization (e.g., \c std::vector<bool>), this routine will return
4130 * either the primary template (\c std::vector) or, if the specialization was
4131 * instantiated from a class template partial specialization, the class template
4132 * partial specialization. For a class template partial specialization and a
4133 * function template specialization (including instantiations), this
4134 * this routine will return the specialized template.
4135 *
4136 * For members of a class template (e.g., member functions, member classes, or
4137 * static data members), returns the specialized or instantiated member.
4138 * Although not strictly "templates" in the C++ language, members of class
4139 * templates have the same notions of specializations and instantiations that
4140 * templates do, so this routine treats them similarly.
4141 *
4142 * \param C A cursor that may be a specialization of a template or a member
4143 * of a template.
4144 *
4145 * \returns If the given cursor is a specialization or instantiation of a
4146 * template or a member thereof, the template or member that it specializes or
4147 * from which it was instantiated. Otherwise, returns a NULL cursor.
4148 */
4149CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004150
4151/**
4152 * \brief Given a cursor that references something else, return the source range
4153 * covering that reference.
4154 *
4155 * \param C A cursor pointing to a member reference, a declaration reference, or
4156 * an operator call.
4157 * \param NameFlags A bitset with three independent flags:
4158 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4159 * CXNameRange_WantSinglePiece.
4160 * \param PieceIndex For contiguous names or when passing the flag
4161 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4162 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer474261a2012-06-02 10:20:41 +00004163 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004164 * pieces of the name. See also CXNameRange_WantSinglePiece.
4165 *
4166 * \returns The piece of the name pointed to by the given cursor. If there is no
4167 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4168 */
Francois Pichetece689f2011-07-25 22:00:44 +00004169CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4170 unsigned NameFlags,
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004171 unsigned PieceIndex);
4172
4173enum CXNameRefFlags {
4174 /**
4175 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4176 * range.
4177 */
4178 CXNameRange_WantQualifier = 0x1,
4179
4180 /**
James Dennett574cb4c2012-06-15 05:41:51 +00004181 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4182 * in the range.
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004183 */
4184 CXNameRange_WantTemplateArgs = 0x2,
4185
4186 /**
4187 * \brief If the name is non-contiguous, return the full spanning range.
4188 *
4189 * Non-contiguous names occur in Objective-C when a selector with two or more
4190 * parameters is used, or in C++ when using an operator:
4191 * \code
4192 * [object doSomething:here withValue:there]; // ObjC
4193 * return some_vector[1]; // C++
4194 * \endcode
4195 */
4196 CXNameRange_WantSinglePiece = 0x4
4197};
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004198
4199/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004200 * @}
4201 */
4202
4203/**
Douglas Gregor61656112010-01-26 18:31:56 +00004204 * \defgroup CINDEX_LEX Token extraction and manipulation
4205 *
4206 * The routines in this group provide access to the tokens within a
4207 * translation unit, along with a semantic mapping of those tokens to
4208 * their corresponding cursors.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004209 *
4210 * @{
4211 */
4212
4213/**
4214 * \brief Describes a kind of token.
4215 */
4216typedef enum CXTokenKind {
4217 /**
4218 * \brief A token that contains some kind of punctuation.
4219 */
4220 CXToken_Punctuation,
Ted Kremenekd071c602010-03-13 02:50:34 +00004221
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004222 /**
Douglas Gregor61656112010-01-26 18:31:56 +00004223 * \brief A language keyword.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004224 */
4225 CXToken_Keyword,
Ted Kremenekd071c602010-03-13 02:50:34 +00004226
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004227 /**
4228 * \brief An identifier (that is not a keyword).
4229 */
4230 CXToken_Identifier,
Ted Kremenekd071c602010-03-13 02:50:34 +00004231
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004232 /**
4233 * \brief A numeric, string, or character literal.
4234 */
4235 CXToken_Literal,
Ted Kremenekd071c602010-03-13 02:50:34 +00004236
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004237 /**
4238 * \brief A comment.
4239 */
4240 CXToken_Comment
4241} CXTokenKind;
4242
4243/**
4244 * \brief Describes a single preprocessing token.
4245 */
4246typedef struct {
4247 unsigned int_data[4];
4248 void *ptr_data;
4249} CXToken;
4250
4251/**
4252 * \brief Determine the kind of the given token.
4253 */
4254CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004255
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004256/**
4257 * \brief Determine the spelling of the given token.
4258 *
4259 * The spelling of a token is the textual representation of that token, e.g.,
4260 * the text of an identifier or keyword.
4261 */
4262CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004263
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004264/**
4265 * \brief Retrieve the source location of the given token.
4266 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004267CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004268 CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004269
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004270/**
4271 * \brief Retrieve a source range that covers the given token.
4272 */
4273CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4274
4275/**
4276 * \brief Tokenize the source code described by the given range into raw
4277 * lexical tokens.
4278 *
4279 * \param TU the translation unit whose text is being tokenized.
4280 *
4281 * \param Range the source range in which text should be tokenized. All of the
4282 * tokens produced by tokenization will fall within this source range,
4283 *
4284 * \param Tokens this pointer will be set to point to the array of tokens
4285 * that occur within the given source range. The returned pointer must be
4286 * freed with clang_disposeTokens() before the translation unit is destroyed.
4287 *
4288 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4289 * array.
4290 *
4291 */
4292CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4293 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004294
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004295/**
4296 * \brief Annotate the given set of tokens by providing cursors for each token
4297 * that can be mapped to a specific entity within the abstract syntax tree.
4298 *
Douglas Gregor61656112010-01-26 18:31:56 +00004299 * This token-annotation routine is equivalent to invoking
4300 * clang_getCursor() for the source locations of each of the
4301 * tokens. The cursors provided are filtered, so that only those
4302 * cursors that have a direct correspondence to the token are
4303 * accepted. For example, given a function call \c f(x),
4304 * clang_getCursor() would provide the following cursors:
4305 *
4306 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4307 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4308 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4309 *
4310 * Only the first and last of these cursors will occur within the
4311 * annotate, since the tokens "f" and "x' directly refer to a function
4312 * and a variable, respectively, but the parentheses are just a small
4313 * part of the full syntax of the function call expression, which is
4314 * not provided as an annotation.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004315 *
4316 * \param TU the translation unit that owns the given tokens.
4317 *
4318 * \param Tokens the set of tokens to annotate.
4319 *
4320 * \param NumTokens the number of tokens in \p Tokens.
4321 *
4322 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4323 * replaced with the cursors corresponding to each token.
4324 */
4325CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4326 CXToken *Tokens, unsigned NumTokens,
4327 CXCursor *Cursors);
Ted Kremenekd071c602010-03-13 02:50:34 +00004328
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004329/**
4330 * \brief Free the given set of tokens.
4331 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004332CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004333 CXToken *Tokens, unsigned NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004334
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004335/**
4336 * @}
4337 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004338
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004339/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004340 * \defgroup CINDEX_DEBUG Debugging facilities
4341 *
4342 * These routines are used for testing and debugging, only, and should not
4343 * be relied upon.
4344 *
4345 * @{
4346 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004347
Steve Naroff76b8f132009-09-23 17:52:52 +00004348/* for debug/testing */
Ted Kremenek29004672010-02-17 00:41:32 +00004349CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004350CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4351 const char **startBuf,
Steve Naroff76b8f132009-09-23 17:52:52 +00004352 const char **endBuf,
4353 unsigned *startLine,
4354 unsigned *startColumn,
4355 unsigned *endLine,
4356 unsigned *endColumn);
Douglas Gregor1e21cc72010-02-18 23:07:20 +00004357CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar23420652010-11-04 01:26:29 +00004358CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4359 unsigned stack_size);
4360
Douglas Gregor9eb77012009-11-07 00:00:49 +00004361/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004362 * @}
4363 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004364
Douglas Gregor6007cf22010-01-22 22:29:16 +00004365/**
4366 * \defgroup CINDEX_CODE_COMPLET Code completion
4367 *
4368 * Code completion involves taking an (incomplete) source file, along with
4369 * knowledge of where the user is actively editing that file, and suggesting
4370 * syntactically- and semantically-valid constructs that the user might want to
4371 * use at that particular point in the source code. These data structures and
4372 * routines provide support for code completion.
4373 *
4374 * @{
4375 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004376
Douglas Gregor6007cf22010-01-22 22:29:16 +00004377/**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004378 * \brief A semantic string that describes a code-completion result.
4379 *
4380 * A semantic string that describes the formatting of a code-completion
4381 * result as a single "template" of text that should be inserted into the
4382 * source buffer when a particular code-completion result is selected.
4383 * Each semantic string is made up of some number of "chunks", each of which
4384 * contains some text along with a description of what that text means, e.g.,
4385 * the name of the entity being referenced, whether the text chunk is part of
4386 * the template, or whether it is a "placeholder" that the user should replace
4387 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004388 * description of the different kinds of chunks.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004389 */
4390typedef void *CXCompletionString;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004391
Douglas Gregor9eb77012009-11-07 00:00:49 +00004392/**
4393 * \brief A single result of code completion.
4394 */
4395typedef struct {
4396 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004397 * \brief The kind of entity that this completion refers to.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004398 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004399 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor9eb77012009-11-07 00:00:49 +00004400 * *Decl cursor kinds), describing the entity that the completion is
4401 * referring to.
4402 *
4403 * \todo In the future, we would like to provide a full cursor, to allow
4404 * the client to extract additional information from declaration.
4405 */
4406 enum CXCursorKind CursorKind;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004407
4408 /**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004409 * \brief The code-completion string that describes how to insert this
4410 * code-completion result into the editing buffer.
4411 */
4412 CXCompletionString CompletionString;
4413} CXCompletionResult;
4414
4415/**
4416 * \brief Describes a single piece of text within a code-completion string.
4417 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004418 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4419 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor9eb77012009-11-07 00:00:49 +00004420 * should be interpreted by the client or is another completion string.
4421 */
4422enum CXCompletionChunkKind {
4423 /**
4424 * \brief A code-completion string that describes "optional" text that
4425 * could be a part of the template (but is not required).
4426 *
4427 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004428 * string for its representation, which is accessible via
Douglas Gregor9eb77012009-11-07 00:00:49 +00004429 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4430 * describes an additional part of the template that is completely optional.
4431 * For example, optional chunks can be used to describe the placeholders for
4432 * arguments that match up with defaulted function parameters, e.g. given:
4433 *
4434 * \code
4435 * void f(int x, float y = 3.14, double z = 2.71828);
4436 * \endcode
4437 *
4438 * The code-completion string for this function would contain:
4439 * - a TypedText chunk for "f".
4440 * - a LeftParen chunk for "(".
4441 * - a Placeholder chunk for "int x"
4442 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4443 * - a Comma chunk for ","
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004444 * - a Placeholder chunk for "float y"
Douglas Gregor9eb77012009-11-07 00:00:49 +00004445 * - an Optional chunk containing the last defaulted argument:
4446 * - a Comma chunk for ","
4447 * - a Placeholder chunk for "double z"
4448 * - a RightParen chunk for ")"
4449 *
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004450 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor9eb77012009-11-07 00:00:49 +00004451 * - Completely ignore optional chunks, in which case the template for the
4452 * function "f" would only include the first parameter ("int x").
4453 * - Fully expand all optional chunks, in which case the template for the
4454 * function "f" would have all of the parameters.
4455 */
4456 CXCompletionChunk_Optional,
4457 /**
4458 * \brief Text that a user would be expected to type to get this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004459 * code-completion result.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004460 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004461 * There will be exactly one "typed text" chunk in a semantic string, which
4462 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004463 * declaration that could be used at the current code point. Clients are
4464 * expected to filter the code-completion results based on the text in this
4465 * chunk.
4466 */
4467 CXCompletionChunk_TypedText,
4468 /**
4469 * \brief Text that should be inserted as part of a code-completion result.
4470 *
4471 * A "text" chunk represents text that is part of the template to be
4472 * inserted into user code should this particular code-completion result
4473 * be selected.
4474 */
4475 CXCompletionChunk_Text,
4476 /**
4477 * \brief Placeholder text that should be replaced by the user.
4478 *
4479 * A "placeholder" chunk marks a place where the user should insert text
4480 * into the code-completion template. For example, placeholders might mark
4481 * the function parameters for a function declaration, to indicate that the
4482 * user should provide arguments for each of those parameters. The actual
4483 * text in a placeholder is a suggestion for the text to display before
4484 * the user replaces the placeholder with real code.
4485 */
4486 CXCompletionChunk_Placeholder,
4487 /**
4488 * \brief Informative text that should be displayed but never inserted as
4489 * part of the template.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004490 *
Douglas Gregor9eb77012009-11-07 00:00:49 +00004491 * An "informative" chunk contains annotations that can be displayed to
4492 * help the user decide whether a particular code-completion result is the
4493 * right option, but which is not part of the actual template to be inserted
4494 * by code completion.
4495 */
4496 CXCompletionChunk_Informative,
4497 /**
4498 * \brief Text that describes the current parameter when code-completion is
4499 * referring to function call, message send, or template specialization.
4500 *
4501 * A "current parameter" chunk occurs when code-completion is providing
4502 * information about a parameter corresponding to the argument at the
4503 * code-completion point. For example, given a function
4504 *
4505 * \code
4506 * int add(int x, int y);
4507 * \endcode
4508 *
4509 * and the source code \c add(, where the code-completion point is after the
4510 * "(", the code-completion string will contain a "current parameter" chunk
4511 * for "int x", indicating that the current argument will initialize that
4512 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004513 * point is after the ","), the code-completion string will contain a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004514 * "current paremeter" chunk to "int y".
4515 */
4516 CXCompletionChunk_CurrentParameter,
4517 /**
4518 * \brief A left parenthesis ('('), used to initiate a function call or
4519 * signal the beginning of a function parameter list.
4520 */
4521 CXCompletionChunk_LeftParen,
4522 /**
4523 * \brief A right parenthesis (')'), used to finish a function call or
4524 * signal the end of a function parameter list.
4525 */
4526 CXCompletionChunk_RightParen,
4527 /**
4528 * \brief A left bracket ('[').
4529 */
4530 CXCompletionChunk_LeftBracket,
4531 /**
4532 * \brief A right bracket (']').
4533 */
4534 CXCompletionChunk_RightBracket,
4535 /**
4536 * \brief A left brace ('{').
4537 */
4538 CXCompletionChunk_LeftBrace,
4539 /**
4540 * \brief A right brace ('}').
4541 */
4542 CXCompletionChunk_RightBrace,
4543 /**
4544 * \brief A left angle bracket ('<').
4545 */
4546 CXCompletionChunk_LeftAngle,
4547 /**
4548 * \brief A right angle bracket ('>').
4549 */
4550 CXCompletionChunk_RightAngle,
4551 /**
4552 * \brief A comma separator (',').
4553 */
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004554 CXCompletionChunk_Comma,
4555 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004556 * \brief Text that specifies the result type of a given result.
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004557 *
4558 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004559 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004560 * expression using the given completion string would have.
4561 */
Douglas Gregor504a6ae2010-01-10 23:08:15 +00004562 CXCompletionChunk_ResultType,
4563 /**
4564 * \brief A colon (':').
4565 */
4566 CXCompletionChunk_Colon,
4567 /**
4568 * \brief A semicolon (';').
4569 */
4570 CXCompletionChunk_SemiColon,
4571 /**
4572 * \brief An '=' sign.
4573 */
4574 CXCompletionChunk_Equal,
4575 /**
4576 * Horizontal space (' ').
4577 */
4578 CXCompletionChunk_HorizontalSpace,
4579 /**
4580 * Vertical space ('\n'), after which it is generally a good idea to
4581 * perform indentation.
4582 */
4583 CXCompletionChunk_VerticalSpace
Douglas Gregor9eb77012009-11-07 00:00:49 +00004584};
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004585
Douglas Gregor9eb77012009-11-07 00:00:49 +00004586/**
4587 * \brief Determine the kind of a particular chunk 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 kind of the chunk at the index \c chunk_number.
4594 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004595CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor9eb77012009-11-07 00:00:49 +00004596clang_getCompletionChunkKind(CXCompletionString completion_string,
4597 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004598
Douglas Gregor9eb77012009-11-07 00:00:49 +00004599/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004600 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004601 * completion string.
4602 *
4603 * \param completion_string the completion string to query.
4604 *
4605 * \param chunk_number the 0-based index of the chunk in the completion string.
4606 *
4607 * \returns the text associated with the chunk at index \c chunk_number.
4608 */
Ted Kremenekf602f962010-02-17 01:42:24 +00004609CINDEX_LINKAGE CXString
Douglas Gregor9eb77012009-11-07 00:00:49 +00004610clang_getCompletionChunkText(CXCompletionString completion_string,
4611 unsigned chunk_number);
4612
4613/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004614 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor9eb77012009-11-07 00:00:49 +00004615 * within a completion string.
4616 *
4617 * \param completion_string the completion string to query.
4618 *
4619 * \param chunk_number the 0-based index of the chunk in the completion string.
4620 *
4621 * \returns the completion string associated with the chunk at index
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004622 * \c chunk_number.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004623 */
4624CINDEX_LINKAGE CXCompletionString
4625clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4626 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004627
Douglas Gregor9eb77012009-11-07 00:00:49 +00004628/**
4629 * \brief Retrieve the number of chunks in the given code-completion string.
4630 */
4631CINDEX_LINKAGE unsigned
4632clang_getNumCompletionChunks(CXCompletionString completion_string);
4633
4634/**
Douglas Gregora2db7932010-05-26 22:00:08 +00004635 * \brief Determine the priority of this code completion.
4636 *
4637 * The priority of a code completion indicates how likely it is that this
4638 * particular completion is the completion that the user will select. The
4639 * priority is selected by various internal heuristics.
4640 *
4641 * \param completion_string The completion string to query.
4642 *
4643 * \returns The priority of this completion string. Smaller values indicate
4644 * higher-priority (more likely) completions.
4645 */
4646CINDEX_LINKAGE unsigned
4647clang_getCompletionPriority(CXCompletionString completion_string);
4648
4649/**
Douglas Gregorf757a122010-08-23 23:00:57 +00004650 * \brief Determine the availability of the entity that this code-completion
4651 * string refers to.
4652 *
4653 * \param completion_string The completion string to query.
4654 *
4655 * \returns The availability of the completion string.
4656 */
4657CINDEX_LINKAGE enum CXAvailabilityKind
4658clang_getCompletionAvailability(CXCompletionString completion_string);
4659
4660/**
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004661 * \brief Retrieve the number of annotations associated with the given
4662 * completion string.
4663 *
4664 * \param completion_string the completion string to query.
4665 *
4666 * \returns the number of annotations associated with the given completion
4667 * string.
4668 */
4669CINDEX_LINKAGE unsigned
4670clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4671
4672/**
4673 * \brief Retrieve the annotation associated with the given completion string.
4674 *
4675 * \param completion_string the completion string to query.
4676 *
4677 * \param annotation_number the 0-based index of the annotation of the
4678 * completion string.
4679 *
4680 * \returns annotation string associated with the completion at index
4681 * \c annotation_number, or a NULL string if that annotation is not available.
4682 */
4683CINDEX_LINKAGE CXString
4684clang_getCompletionAnnotation(CXCompletionString completion_string,
4685 unsigned annotation_number);
4686
4687/**
Douglas Gregor78254c82012-03-27 23:34:16 +00004688 * \brief Retrieve the parent context of the given completion string.
4689 *
4690 * The parent context of a completion string is the semantic parent of
4691 * the declaration (if any) that the code completion represents. For example,
4692 * a code completion for an Objective-C method would have the method's class
4693 * or protocol as its context.
4694 *
4695 * \param completion_string The code completion string whose parent is
4696 * being queried.
4697 *
Argyrios Kyrtzidis9ae39562012-09-26 16:39:56 +00004698 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregor78254c82012-03-27 23:34:16 +00004699 *
James Dennett574cb4c2012-06-15 05:41:51 +00004700 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregor78254c82012-03-27 23:34:16 +00004701 * the completion string represents a method in the NSObject class.
4702 */
4703CINDEX_LINKAGE CXString
4704clang_getCompletionParent(CXCompletionString completion_string,
4705 enum CXCursorKind *kind);
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004706
4707/**
4708 * \brief Retrieve the brief documentation comment attached to the declaration
4709 * that corresponds to the given completion string.
4710 */
4711CINDEX_LINKAGE CXString
4712clang_getCompletionBriefComment(CXCompletionString completion_string);
4713
Douglas Gregor78254c82012-03-27 23:34:16 +00004714/**
Douglas Gregor3f35bb22011-08-04 20:04:59 +00004715 * \brief Retrieve a completion string for an arbitrary declaration or macro
4716 * definition cursor.
4717 *
4718 * \param cursor The cursor to query.
4719 *
4720 * \returns A non-context-sensitive completion string for declaration and macro
4721 * definition cursors, or NULL for other kinds of cursors.
4722 */
4723CINDEX_LINKAGE CXCompletionString
4724clang_getCursorCompletionString(CXCursor cursor);
4725
4726/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004727 * \brief Contains the results of code-completion.
4728 *
4729 * This data structure contains the results of code completion, as
Douglas Gregor6a9580282010-10-11 21:51:20 +00004730 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004731 * \c clang_disposeCodeCompleteResults.
4732 */
4733typedef struct {
4734 /**
4735 * \brief The code-completion results.
4736 */
4737 CXCompletionResult *Results;
4738
4739 /**
4740 * \brief The number of code-completion results stored in the
4741 * \c Results array.
4742 */
4743 unsigned NumResults;
4744} CXCodeCompleteResults;
4745
4746/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004747 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4748 * modify its behavior.
4749 *
4750 * The enumerators in this enumeration can be bitwise-OR'd together to
4751 * provide multiple options to \c clang_codeCompleteAt().
4752 */
4753enum CXCodeComplete_Flags {
4754 /**
4755 * \brief Whether to include macros within the set of code
4756 * completions returned.
4757 */
4758 CXCodeComplete_IncludeMacros = 0x01,
4759
4760 /**
4761 * \brief Whether to include code patterns for language constructs
4762 * within the set of code completions, e.g., for loops.
4763 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004764 CXCodeComplete_IncludeCodePatterns = 0x02,
4765
4766 /**
4767 * \brief Whether to include brief documentation within the set of code
4768 * completions returned.
4769 */
4770 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorb68bc592010-08-05 09:09:23 +00004771};
4772
4773/**
Douglas Gregor21325842011-07-07 16:03:39 +00004774 * \brief Bits that represent the context under which completion is occurring.
4775 *
4776 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4777 * contexts are occurring simultaneously.
4778 */
4779enum CXCompletionContext {
4780 /**
4781 * \brief The context for completions is unexposed, as only Clang results
4782 * should be included. (This is equivalent to having no context bits set.)
4783 */
4784 CXCompletionContext_Unexposed = 0,
4785
4786 /**
4787 * \brief Completions for any possible type should be included in the results.
4788 */
4789 CXCompletionContext_AnyType = 1 << 0,
4790
4791 /**
4792 * \brief Completions for any possible value (variables, function calls, etc.)
4793 * should be included in the results.
4794 */
4795 CXCompletionContext_AnyValue = 1 << 1,
4796 /**
4797 * \brief Completions for values that resolve to an Objective-C object should
4798 * be included in the results.
4799 */
4800 CXCompletionContext_ObjCObjectValue = 1 << 2,
4801 /**
4802 * \brief Completions for values that resolve to an Objective-C selector
4803 * should be included in the results.
4804 */
4805 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4806 /**
4807 * \brief Completions for values that resolve to a C++ class type should be
4808 * included in the results.
4809 */
4810 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4811
4812 /**
4813 * \brief Completions for fields of the member being accessed using the dot
4814 * operator should be included in the results.
4815 */
4816 CXCompletionContext_DotMemberAccess = 1 << 5,
4817 /**
4818 * \brief Completions for fields of the member being accessed using the arrow
4819 * operator should be included in the results.
4820 */
4821 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4822 /**
4823 * \brief Completions for properties of the Objective-C object being accessed
4824 * using the dot operator should be included in the results.
4825 */
4826 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4827
4828 /**
4829 * \brief Completions for enum tags should be included in the results.
4830 */
4831 CXCompletionContext_EnumTag = 1 << 8,
4832 /**
4833 * \brief Completions for union tags should be included in the results.
4834 */
4835 CXCompletionContext_UnionTag = 1 << 9,
4836 /**
4837 * \brief Completions for struct tags should be included in the results.
4838 */
4839 CXCompletionContext_StructTag = 1 << 10,
4840
4841 /**
4842 * \brief Completions for C++ class names should be included in the results.
4843 */
4844 CXCompletionContext_ClassTag = 1 << 11,
4845 /**
4846 * \brief Completions for C++ namespaces and namespace aliases should be
4847 * included in the results.
4848 */
4849 CXCompletionContext_Namespace = 1 << 12,
4850 /**
4851 * \brief Completions for C++ nested name specifiers should be included in
4852 * the results.
4853 */
4854 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4855
4856 /**
4857 * \brief Completions for Objective-C interfaces (classes) should be included
4858 * in the results.
4859 */
4860 CXCompletionContext_ObjCInterface = 1 << 14,
4861 /**
4862 * \brief Completions for Objective-C protocols should be included in
4863 * the results.
4864 */
4865 CXCompletionContext_ObjCProtocol = 1 << 15,
4866 /**
4867 * \brief Completions for Objective-C categories should be included in
4868 * the results.
4869 */
4870 CXCompletionContext_ObjCCategory = 1 << 16,
4871 /**
4872 * \brief Completions for Objective-C instance messages should be included
4873 * in the results.
4874 */
4875 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4876 /**
4877 * \brief Completions for Objective-C class messages should be included in
4878 * the results.
4879 */
4880 CXCompletionContext_ObjCClassMessage = 1 << 18,
4881 /**
4882 * \brief Completions for Objective-C selector names should be included in
4883 * the results.
4884 */
4885 CXCompletionContext_ObjCSelectorName = 1 << 19,
4886
4887 /**
4888 * \brief Completions for preprocessor macro names should be included in
4889 * the results.
4890 */
4891 CXCompletionContext_MacroName = 1 << 20,
4892
4893 /**
4894 * \brief Natural language completions should be included in the results.
4895 */
4896 CXCompletionContext_NaturalLanguage = 1 << 21,
4897
4898 /**
4899 * \brief The current context is unknown, so set all contexts.
4900 */
4901 CXCompletionContext_Unknown = ((1 << 22) - 1)
4902};
4903
4904/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004905 * \brief Returns a default set of code-completion options that can be
4906 * passed to\c clang_codeCompleteAt().
4907 */
4908CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4909
4910/**
Douglas Gregor8e984da2010-08-04 16:47:14 +00004911 * \brief Perform code completion at a given location in a translation unit.
4912 *
4913 * This function performs code completion at a particular file, line, and
4914 * column within source code, providing results that suggest potential
4915 * code snippets based on the context of the completion. The basic model
4916 * for code completion is that Clang will parse a complete source file,
4917 * performing syntax checking up to the location where code-completion has
4918 * been requested. At that point, a special code-completion token is passed
4919 * to the parser, which recognizes this token and determines, based on the
4920 * current location in the C/Objective-C/C++ grammar and the state of
4921 * semantic analysis, what completions to provide. These completions are
4922 * returned via a new \c CXCodeCompleteResults structure.
4923 *
4924 * Code completion itself is meant to be triggered by the client when the
4925 * user types punctuation characters or whitespace, at which point the
4926 * code-completion location will coincide with the cursor. For example, if \c p
4927 * is a pointer, code-completion might be triggered after the "-" and then
4928 * after the ">" in \c p->. When the code-completion location is afer the ">",
4929 * the completion results will provide, e.g., the members of the struct that
4930 * "p" points to. The client is responsible for placing the cursor at the
4931 * beginning of the token currently being typed, then filtering the results
4932 * based on the contents of the token. For example, when code-completing for
4933 * the expression \c p->get, the client should provide the location just after
4934 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4935 * client can filter the results based on the current token text ("get"), only
4936 * showing those results that start with "get". The intent of this interface
4937 * is to separate the relatively high-latency acquisition of code-completion
4938 * results from the filtering of results on a per-character basis, which must
4939 * have a lower latency.
4940 *
4941 * \param TU The translation unit in which code-completion should
4942 * occur. The source files for this translation unit need not be
4943 * completely up-to-date (and the contents of those source files may
4944 * be overridden via \p unsaved_files). Cursors referring into the
4945 * translation unit may be invalidated by this invocation.
4946 *
4947 * \param complete_filename The name of the source file where code
4948 * completion should be performed. This filename may be any file
4949 * included in the translation unit.
4950 *
4951 * \param complete_line The line at which code-completion should occur.
4952 *
4953 * \param complete_column The column at which code-completion should occur.
4954 * Note that the column should point just after the syntactic construct that
4955 * initiated code completion, and not in the middle of a lexical token.
4956 *
4957 * \param unsaved_files the Tiles that have not yet been saved to disk
4958 * but may be required for parsing or code completion, including the
4959 * contents of those files. The contents and name of these files (as
4960 * specified by CXUnsavedFile) are copied when necessary, so the
4961 * client only needs to guarantee their validity until the call to
4962 * this function returns.
4963 *
4964 * \param num_unsaved_files The number of unsaved file entries in \p
4965 * unsaved_files.
4966 *
Douglas Gregorb68bc592010-08-05 09:09:23 +00004967 * \param options Extra options that control the behavior of code
4968 * completion, expressed as a bitwise OR of the enumerators of the
4969 * CXCodeComplete_Flags enumeration. The
4970 * \c clang_defaultCodeCompleteOptions() function returns a default set
4971 * of code-completion options.
4972 *
Douglas Gregor8e984da2010-08-04 16:47:14 +00004973 * \returns If successful, a new \c CXCodeCompleteResults structure
4974 * containing code-completion results, which should eventually be
4975 * freed with \c clang_disposeCodeCompleteResults(). If code
4976 * completion fails, returns NULL.
4977 */
4978CINDEX_LINKAGE
4979CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4980 const char *complete_filename,
4981 unsigned complete_line,
4982 unsigned complete_column,
4983 struct CXUnsavedFile *unsaved_files,
Douglas Gregorb68bc592010-08-05 09:09:23 +00004984 unsigned num_unsaved_files,
4985 unsigned options);
Douglas Gregor8e984da2010-08-04 16:47:14 +00004986
4987/**
Douglas Gregor49f67ce2010-08-26 13:48:20 +00004988 * \brief Sort the code-completion results in case-insensitive alphabetical
4989 * order.
4990 *
4991 * \param Results The set of results to sort.
4992 * \param NumResults The number of results in \p Results.
4993 */
4994CINDEX_LINKAGE
4995void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4996 unsigned NumResults);
4997
4998/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004999 * \brief Free the given set of code-completion results.
5000 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005001CINDEX_LINKAGE
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00005002void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregorf757a122010-08-23 23:00:57 +00005003
Douglas Gregor52606ff2010-01-20 01:10:47 +00005004/**
Douglas Gregor33cdd812010-02-18 18:08:43 +00005005 * \brief Determine the number of diagnostics produced prior to the
5006 * location where code completion was performed.
5007 */
Ted Kremenekd071c602010-03-13 02:50:34 +00005008CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00005009unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
5010
5011/**
5012 * \brief Retrieve a diagnostic associated with the given code completion.
5013 *
James Dennett574cb4c2012-06-15 05:41:51 +00005014 * \param Results the code completion results to query.
Douglas Gregor33cdd812010-02-18 18:08:43 +00005015 * \param Index the zero-based diagnostic number to retrieve.
5016 *
5017 * \returns the requested diagnostic. This diagnostic must be freed
5018 * via a call to \c clang_disposeDiagnostic().
5019 */
Ted Kremenekd071c602010-03-13 02:50:34 +00005020CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00005021CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
5022 unsigned Index);
5023
5024/**
Douglas Gregor21325842011-07-07 16:03:39 +00005025 * \brief Determines what compeltions are appropriate for the context
5026 * the given code completion.
5027 *
5028 * \param Results the code completion results to query
5029 *
5030 * \returns the kinds of completions that are appropriate for use
5031 * along with the given code completion results.
5032 */
5033CINDEX_LINKAGE
5034unsigned long long clang_codeCompleteGetContexts(
5035 CXCodeCompleteResults *Results);
Douglas Gregor63745d52011-07-21 01:05:26 +00005036
5037/**
5038 * \brief Returns the cursor kind for the container for the current code
5039 * completion context. The container is only guaranteed to be set for
5040 * contexts where a container exists (i.e. member accesses or Objective-C
5041 * message sends); if there is not a container, this function will return
5042 * CXCursor_InvalidCode.
5043 *
5044 * \param Results the code completion results to query
5045 *
5046 * \param IsIncomplete on return, this value will be false if Clang has complete
5047 * information about the container. If Clang does not have complete
5048 * information, this value will be true.
5049 *
5050 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5051 * container
5052 */
5053CINDEX_LINKAGE
5054enum CXCursorKind clang_codeCompleteGetContainerKind(
5055 CXCodeCompleteResults *Results,
5056 unsigned *IsIncomplete);
5057
5058/**
5059 * \brief Returns the USR for the container for the current code completion
5060 * context. If there is not a container for the current context, this
5061 * function will return the empty string.
5062 *
5063 * \param Results the code completion results to query
5064 *
5065 * \returns the USR for the container
5066 */
5067CINDEX_LINKAGE
5068CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor21325842011-07-07 16:03:39 +00005069
Douglas Gregorea777402011-07-26 15:24:30 +00005070
5071/**
5072 * \brief Returns the currently-entered selector for an Objective-C message
5073 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5074 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5075 * CXCompletionContext_ObjCClassMessage.
5076 *
5077 * \param Results the code completion results to query
5078 *
5079 * \returns the selector (or partial selector) that has been entered thus far
5080 * for an Objective-C message send.
5081 */
5082CINDEX_LINKAGE
5083CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5084
Douglas Gregor21325842011-07-07 16:03:39 +00005085/**
Douglas Gregor52606ff2010-01-20 01:10:47 +00005086 * @}
5087 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005088
5089
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005090/**
5091 * \defgroup CINDEX_MISC Miscellaneous utility functions
5092 *
5093 * @{
5094 */
Ted Kremenek3e315a22010-01-23 17:51:23 +00005095
5096/**
5097 * \brief Return a version string, suitable for showing to a user, but not
5098 * intended to be parsed (the format is not guaranteed to be stable).
5099 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +00005100CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005101
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005102
5103/**
5104 * \brief Enable/disable crash recovery.
5105 *
James Dennett574cb4c2012-06-15 05:41:51 +00005106 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5107 * value enables crash recovery, while 0 disables it.
Ted Kremenek1ec7b332011-03-18 23:05:39 +00005108 */
5109CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5110
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005111 /**
Ted Kremenekd071c602010-03-13 02:50:34 +00005112 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005113 * (used with clang_getInclusions()).
5114 *
5115 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett574cb4c2012-06-15 05:41:51 +00005116 * file included (either at the top-level or by \#include directives) within
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00005117 * a translation unit. The first argument is the file being included, and
5118 * the second and third arguments provide the inclusion stack. The
5119 * array is sorted in order of immediate inclusion. For example,
5120 * the first element refers to the location that included 'included_file'.
5121 */
5122typedef void (*CXInclusionVisitor)(CXFile included_file,
5123 CXSourceLocation* inclusion_stack,
5124 unsigned include_len,
5125 CXClientData client_data);
5126
5127/**
5128 * \brief Visit the set of preprocessor inclusions in a translation unit.
5129 * The visitor function is called with the provided data for every included
5130 * file. This does not include headers included by the PCH file (unless one
5131 * is inspecting the inclusions in the PCH file itself).
5132 */
5133CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5134 CXInclusionVisitor visitor,
5135 CXClientData client_data);
5136
5137/**
Ted Kremenekc0f3f722010-01-22 22:44:15 +00005138 * @}
5139 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005140
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005141/** \defgroup CINDEX_REMAPPING Remapping functions
5142 *
5143 * @{
5144 */
5145
5146/**
5147 * \brief A remapping of original source files and their translated files.
5148 */
5149typedef void *CXRemapping;
5150
5151/**
5152 * \brief Retrieve a remapping.
5153 *
5154 * \param path the path that contains metadata about remappings.
5155 *
5156 * \returns the requested remapping. This remapping must be freed
5157 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5158 */
5159CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5160
5161/**
Ted Kremenekf7639e12012-03-06 20:06:33 +00005162 * \brief Retrieve a remapping.
5163 *
5164 * \param filePaths pointer to an array of file paths containing remapping info.
5165 *
5166 * \param numFiles number of file paths.
5167 *
5168 * \returns the requested remapping. This remapping must be freed
5169 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5170 */
5171CINDEX_LINKAGE
5172CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5173 unsigned numFiles);
5174
5175/**
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005176 * \brief Determine the number of remappings.
5177 */
5178CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5179
5180/**
5181 * \brief Get the original and the associated filename from the remapping.
5182 *
5183 * \param original If non-NULL, will be set to the original filename.
5184 *
5185 * \param transformed If non-NULL, will be set to the filename that the original
5186 * is associated with.
5187 */
5188CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5189 CXString *original, CXString *transformed);
5190
5191/**
5192 * \brief Dispose the remapping.
5193 */
5194CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5195
5196/**
5197 * @}
5198 */
5199
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005200/** \defgroup CINDEX_HIGH Higher level API functions
5201 *
5202 * @{
5203 */
5204
5205enum CXVisitorResult {
5206 CXVisit_Break,
5207 CXVisit_Continue
5208};
5209
5210typedef struct {
5211 void *context;
5212 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5213} CXCursorAndRangeVisitor;
5214
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005215typedef enum {
5216 /**
5217 * \brief Function returned successfully.
5218 */
5219 CXResult_Success = 0,
5220 /**
5221 * \brief One of the parameters was invalid for the function.
5222 */
5223 CXResult_Invalid = 1,
5224 /**
5225 * \brief The function was terminated by a callback (e.g. it returned
5226 * CXVisit_Break)
5227 */
5228 CXResult_VisitBreak = 2
5229
5230} CXResult;
5231
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005232/**
5233 * \brief Find references of a declaration in a specific file.
5234 *
5235 * \param cursor pointing to a declaration or a reference of one.
5236 *
5237 * \param file to search for references.
5238 *
5239 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5240 * each reference found.
5241 * The CXSourceRange will point inside the file; if the reference is inside
5242 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005243 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005244 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005245 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005246CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5247 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005248
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005249/**
5250 * \brief Find #import/#include directives in a specific file.
5251 *
5252 * \param TU translation unit containing the file to query.
5253 *
5254 * \param file to search for #import/#include directives.
5255 *
5256 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5257 * each directive found.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005258 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005259 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005260 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005261CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5262 CXFile file,
5263 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005264
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005265#ifdef __has_feature
5266# if __has_feature(blocks)
5267
5268typedef enum CXVisitorResult
5269 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5270
5271CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005272CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5273 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005274
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005275CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005276CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5277 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005278
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005279# endif
5280#endif
5281
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005282/**
5283 * \brief The client's data object that is associated with a CXFile.
5284 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005285typedef void *CXIdxClientFile;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005286
5287/**
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005288 * \brief The client's data object that is associated with a semantic entity.
5289 */
5290typedef void *CXIdxClientEntity;
5291
5292/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005293 * \brief The client's data object that is associated with a semantic container
5294 * of entities.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005295 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005296typedef void *CXIdxClientContainer;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005297
5298/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005299 * \brief The client's data object that is associated with an AST file (PCH
5300 * or module).
5301 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005302typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005303
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005304/**
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005305 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005306 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005307typedef struct {
5308 void *ptr_data[2];
5309 unsigned int_data;
5310} CXIdxLoc;
5311
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005312/**
James Dennett574cb4c2012-06-15 05:41:51 +00005313 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005314 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005315typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005316 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005317 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005318 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005319 CXIdxLoc hashLoc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005320 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005321 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005322 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005323 const char *filename;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005324 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005325 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005326 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005327 CXFile file;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005328 int isImport;
5329 int isAngled;
Argyrios Kyrtzidis5e2ec482012-10-18 00:17:05 +00005330 /**
5331 * \brief Non-zero if the directive was automatically turned into a module
5332 * import.
5333 */
5334 int isModuleImport;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005335} CXIdxIncludedFileInfo;
5336
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005337/**
James Dennett574cb4c2012-06-15 05:41:51 +00005338 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005339 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005340typedef struct {
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005341 /**
5342 * \brief Top level AST file containing the imported PCH, module or submodule.
5343 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005344 CXFile file;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005345 /**
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005346 * \brief The imported module or NULL if the AST file is a PCH.
5347 */
5348 CXModule module;
5349 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005350 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005351 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005352 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005353 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005354 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005355 * a module import. Applicable only for modules.
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005356 */
Argyrios Kyrtzidis184b1442012-10-03 21:05:44 +00005357 int isImplicit;
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005358
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005359} CXIdxImportedASTFileInfo;
5360
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005361typedef enum {
5362 CXIdxEntity_Unexposed = 0,
5363 CXIdxEntity_Typedef = 1,
5364 CXIdxEntity_Function = 2,
5365 CXIdxEntity_Variable = 3,
5366 CXIdxEntity_Field = 4,
5367 CXIdxEntity_EnumConstant = 5,
5368
5369 CXIdxEntity_ObjCClass = 6,
5370 CXIdxEntity_ObjCProtocol = 7,
5371 CXIdxEntity_ObjCCategory = 8,
5372
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005373 CXIdxEntity_ObjCInstanceMethod = 9,
5374 CXIdxEntity_ObjCClassMethod = 10,
5375 CXIdxEntity_ObjCProperty = 11,
5376 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005377
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005378 CXIdxEntity_Enum = 13,
5379 CXIdxEntity_Struct = 14,
5380 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005381
5382 CXIdxEntity_CXXClass = 16,
5383 CXIdxEntity_CXXNamespace = 17,
5384 CXIdxEntity_CXXNamespaceAlias = 18,
5385 CXIdxEntity_CXXStaticVariable = 19,
5386 CXIdxEntity_CXXStaticMethod = 20,
5387 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matose9a3ed42012-08-31 22:18:20 +00005388 CXIdxEntity_CXXConstructor = 22,
5389 CXIdxEntity_CXXDestructor = 23,
5390 CXIdxEntity_CXXConversionFunction = 24,
5391 CXIdxEntity_CXXTypeAlias = 25,
5392 CXIdxEntity_CXXInterface = 26
5393
5394} CXIdxEntityKind;
5395
Argyrios Kyrtzidis52002882011-12-07 20:44:12 +00005396typedef enum {
5397 CXIdxEntityLang_None = 0,
5398 CXIdxEntityLang_C = 1,
5399 CXIdxEntityLang_ObjC = 2,
5400 CXIdxEntityLang_CXX = 3
5401} CXIdxEntityLanguage;
5402
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005403/**
5404 * \brief Extra C++ template information for an entity. This can apply to:
5405 * CXIdxEntity_Function
5406 * CXIdxEntity_CXXClass
5407 * CXIdxEntity_CXXStaticMethod
5408 * CXIdxEntity_CXXInstanceMethod
5409 * CXIdxEntity_CXXConstructor
5410 * CXIdxEntity_CXXConversionFunction
5411 * CXIdxEntity_CXXTypeAlias
5412 */
5413typedef enum {
5414 CXIdxEntity_NonTemplate = 0,
5415 CXIdxEntity_Template = 1,
5416 CXIdxEntity_TemplatePartialSpecialization = 2,
5417 CXIdxEntity_TemplateSpecialization = 3
5418} CXIdxEntityCXXTemplateKind;
5419
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005420typedef enum {
5421 CXIdxAttr_Unexposed = 0,
5422 CXIdxAttr_IBAction = 1,
5423 CXIdxAttr_IBOutlet = 2,
5424 CXIdxAttr_IBOutletCollection = 3
5425} CXIdxAttrKind;
5426
5427typedef struct {
5428 CXIdxAttrKind kind;
5429 CXCursor cursor;
5430 CXIdxLoc loc;
5431} CXIdxAttrInfo;
5432
5433typedef struct {
Argyrios Kyrtzidis4d873b72011-12-15 00:05:00 +00005434 CXIdxEntityKind kind;
5435 CXIdxEntityCXXTemplateKind templateKind;
5436 CXIdxEntityLanguage lang;
5437 const char *name;
5438 const char *USR;
5439 CXCursor cursor;
5440 const CXIdxAttrInfo *const *attributes;
5441 unsigned numAttributes;
5442} CXIdxEntityInfo;
5443
5444typedef struct {
5445 CXCursor cursor;
5446} CXIdxContainerInfo;
5447
5448typedef struct {
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005449 const CXIdxAttrInfo *attrInfo;
5450 const CXIdxEntityInfo *objcClass;
5451 CXCursor classCursor;
5452 CXIdxLoc classLoc;
5453} CXIdxIBOutletCollectionAttrInfo;
5454
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005455typedef enum {
5456 CXIdxDeclFlag_Skipped = 0x1
5457} CXIdxDeclInfoFlags;
5458
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005459typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005460 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005461 CXCursor cursor;
5462 CXIdxLoc loc;
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005463 const CXIdxContainerInfo *semanticContainer;
5464 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005465 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005466 * cases like out-of-line C++ member functions.
5467 */
5468 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005469 int isRedeclaration;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005470 int isDefinition;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005471 int isContainer;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005472 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005473 /**
5474 * \brief Whether the declaration exists in code or was created implicitly
5475 * by the compiler, e.g. implicit objc methods for properties.
5476 */
5477 int isImplicit;
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005478 const CXIdxAttrInfo *const *attributes;
5479 unsigned numAttributes;
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005480
5481 unsigned flags;
5482
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005483} CXIdxDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005484
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005485typedef enum {
5486 CXIdxObjCContainer_ForwardRef = 0,
5487 CXIdxObjCContainer_Interface = 1,
5488 CXIdxObjCContainer_Implementation = 2
5489} CXIdxObjCContainerKind;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005490
5491typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005492 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005493 CXIdxObjCContainerKind kind;
5494} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005495
5496typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005497 const CXIdxEntityInfo *base;
5498 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005499 CXIdxLoc loc;
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005500} CXIdxBaseClassInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005501
5502typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005503 const CXIdxEntityInfo *protocol;
5504 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005505 CXIdxLoc loc;
5506} CXIdxObjCProtocolRefInfo;
5507
5508typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005509 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005510 unsigned numProtocols;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005511} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005512
5513typedef struct {
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005514 const CXIdxObjCContainerDeclInfo *containerInfo;
5515 const CXIdxBaseClassInfo *superInfo;
5516 const CXIdxObjCProtocolRefListInfo *protocols;
5517} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005518
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005519typedef struct {
Argyrios Kyrtzidis9b9f7a92011-12-13 18:47:45 +00005520 const CXIdxObjCContainerDeclInfo *containerInfo;
5521 const CXIdxEntityInfo *objcClass;
5522 CXCursor classCursor;
5523 CXIdxLoc classLoc;
5524 const CXIdxObjCProtocolRefListInfo *protocols;
5525} CXIdxObjCCategoryDeclInfo;
5526
5527typedef struct {
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005528 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005529 const CXIdxEntityInfo *getter;
5530 const CXIdxEntityInfo *setter;
5531} CXIdxObjCPropertyDeclInfo;
5532
5533typedef struct {
5534 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005535 const CXIdxBaseClassInfo *const *bases;
5536 unsigned numBases;
5537} CXIdxCXXClassDeclInfo;
5538
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005539/**
James Dennett574cb4c2012-06-15 05:41:51 +00005540 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005541 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005542typedef enum {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005543 /**
5544 * \brief The entity is referenced directly in user's code.
5545 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005546 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005547 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005548 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5549 * dot syntax.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005550 */
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005551 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005552} CXIdxEntityRefKind;
5553
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005554/**
James Dennett574cb4c2012-06-15 05:41:51 +00005555 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005556 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005557typedef struct {
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005558 CXIdxEntityRefKind kind;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005559 /**
5560 * \brief Reference cursor.
5561 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005562 CXCursor cursor;
5563 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005564 /**
5565 * \brief The entity that gets referenced.
5566 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005567 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005568 /**
5569 * \brief Immediate "parent" of the reference. For example:
5570 *
5571 * \code
5572 * Foo *var;
5573 * \endcode
5574 *
5575 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005576 * For references inside statement bodies of functions/methods,
5577 * the parentEntity will be the function/method.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005578 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005579 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005580 /**
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005581 * \brief Lexical container context of the reference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005582 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005583 const CXIdxContainerInfo *container;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005584} CXIdxEntityRefInfo;
5585
James Dennett574cb4c2012-06-15 05:41:51 +00005586/**
5587 * \brief A group of callbacks used by #clang_indexSourceFile and
5588 * #clang_indexTranslationUnit.
5589 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005590typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005591 /**
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005592 * \brief Called periodically to check whether indexing should be aborted.
5593 * Should return 0 to continue, and non-zero to abort.
5594 */
5595 int (*abortQuery)(CXClientData client_data, void *reserved);
5596
5597 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005598 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005599 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005600 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005601 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005602
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005603 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett574cb4c2012-06-15 05:41:51 +00005604 CXFile mainFile, void *reserved);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005605
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005606 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005607 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005608 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005609 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005610 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005611
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005612 /**
5613 * \brief Called when a AST file (PCH or module) gets imported.
5614 *
5615 * AST files will not get indexed (there will not be callbacks to index all
5616 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005617 * file is not already indexed, to initiate a new indexing job specific to
5618 * the AST file.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005619 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005620 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005621 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005622
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005623 /**
5624 * \brief Called at the beginning of indexing a translation unit.
5625 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005626 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005627 void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005628
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005629 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005630 const CXIdxDeclInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005631
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005632 /**
5633 * \brief Called to index a reference of an entity.
5634 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005635 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005636 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005637
5638} IndexerCallbacks;
5639
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005640CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005641CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5642clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005643
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005644CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5645clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5646
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005647CINDEX_LINKAGE
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005648const CXIdxObjCCategoryDeclInfo *
5649clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5650
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005651CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5652clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005653
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005654CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5655clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5656
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005657CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5658clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5659
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005660CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5661clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5662
5663/**
5664 * \brief For retrieving a custom CXIdxClientContainer attached to a
5665 * container.
5666 */
5667CINDEX_LINKAGE CXIdxClientContainer
5668clang_index_getClientContainer(const CXIdxContainerInfo *);
5669
5670/**
5671 * \brief For setting a custom CXIdxClientContainer attached to a
5672 * container.
5673 */
5674CINDEX_LINKAGE void
5675clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5676
5677/**
5678 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5679 */
5680CINDEX_LINKAGE CXIdxClientEntity
5681clang_index_getClientEntity(const CXIdxEntityInfo *);
5682
5683/**
5684 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5685 */
5686CINDEX_LINKAGE void
5687clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5688
5689/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005690 * \brief An indexing action/session, to be applied to one or multiple
5691 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005692 */
5693typedef void *CXIndexAction;
5694
5695/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005696 * \brief An indexing action/session, to be applied to one or multiple
5697 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005698 *
5699 * \param CIdx The index object with which the index action will be associated.
5700 */
5701CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5702
5703/**
5704 * \brief Destroy the given index action.
5705 *
5706 * The index action must not be destroyed until all of the translation units
5707 * created within that index action have been destroyed.
5708 */
5709CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5710
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005711typedef enum {
5712 /**
5713 * \brief Used to indicate that no special indexing options are needed.
5714 */
5715 CXIndexOpt_None = 0x0,
5716
5717 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005718 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5719 * be invoked for only one reference of an entity per source file that does
5720 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005721 */
Argyrios Kyrtzidisfb7d1452012-01-14 00:11:49 +00005722 CXIndexOpt_SuppressRedundantRefs = 0x1,
5723
5724 /**
5725 * \brief Function-local symbols should be indexed. If this is not set
5726 * function-local symbols will be ignored.
5727 */
Argyrios Kyrtzidis7e747952012-02-14 22:23:11 +00005728 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5729
5730 /**
5731 * \brief Implicit function/class template instantiations should be indexed.
5732 * If this is not set, implicit instantiations will be ignored.
5733 */
Argyrios Kyrtzidis6c9ed7d2012-03-27 21:38:03 +00005734 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5735
5736 /**
5737 * \brief Suppress all compiler warnings when parsing for indexing.
5738 */
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005739 CXIndexOpt_SuppressWarnings = 0x8,
5740
5741 /**
5742 * \brief Skip a function/method body that was already parsed during an
5743 * indexing session assosiated with a \c CXIndexAction object.
5744 * Bodies in system headers are always skipped.
5745 */
5746 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5747
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005748} CXIndexOptFlags;
5749
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005750/**
5751 * \brief Index the given source file and the translation unit corresponding
James Dennett574cb4c2012-06-15 05:41:51 +00005752 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005753 *
5754 * \param client_data pointer data supplied by the client, which will
5755 * be passed to the invoked callbacks.
5756 *
5757 * \param index_callbacks Pointer to indexing callbacks that the client
5758 * implements.
5759 *
James Dennett574cb4c2012-06-15 05:41:51 +00005760 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005761 * passed in index_callbacks.
5762 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005763 * \param index_options A bitmask of options that affects how indexing is
5764 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005765 *
5766 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
5767 * after indexing is finished. Set to NULL if you do not require it.
5768 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005769 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005770 * non-zero, otherwise returns 0.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005771 *
James Dennett574cb4c2012-06-15 05:41:51 +00005772 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005773 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005774CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005775 CXClientData client_data,
5776 IndexerCallbacks *index_callbacks,
5777 unsigned index_callbacks_size,
5778 unsigned index_options,
5779 const char *source_filename,
5780 const char * const *command_line_args,
5781 int num_command_line_args,
5782 struct CXUnsavedFile *unsaved_files,
5783 unsigned num_unsaved_files,
5784 CXTranslationUnit *out_TU,
5785 unsigned TU_options);
5786
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005787/**
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005788 * \brief Index the given translation unit via callbacks implemented through
James Dennett574cb4c2012-06-15 05:41:51 +00005789 * #IndexerCallbacks.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005790 *
5791 * The order of callback invocations is not guaranteed to be the same as
5792 * when indexing a source file. The high level order will be:
5793 *
5794 * -Preprocessor callbacks invocations
5795 * -Declaration/reference callbacks invocations
5796 * -Diagnostic callback invocations
5797 *
James Dennett574cb4c2012-06-15 05:41:51 +00005798 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005799 *
5800 * \returns If there is a failure from which the there is no recovery, returns
5801 * non-zero, otherwise returns 0.
5802 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005803CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005804 CXClientData client_data,
5805 IndexerCallbacks *index_callbacks,
5806 unsigned index_callbacks_size,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005807 unsigned index_options,
5808 CXTranslationUnit);
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005809
5810/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005811 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5812 * the given CXIdxLoc.
5813 *
5814 * If the location refers into a macro expansion, retrieves the
5815 * location of the macro expansion and if it refers into a macro argument
5816 * retrieves the location of the argument.
5817 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005818CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005819 CXIdxClientFile *indexFile,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005820 CXFile *file,
5821 unsigned *line,
5822 unsigned *column,
5823 unsigned *offset);
5824
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005825/**
5826 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5827 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005828CINDEX_LINKAGE
5829CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5830
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005831/**
5832 * @}
5833 */
5834
Douglas Gregor6007cf22010-01-22 22:29:16 +00005835/**
5836 * @}
5837 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005838
Ted Kremenekb60d87c2009-08-26 22:36:44 +00005839#ifdef __cplusplus
5840}
5841#endif
5842#endif
5843