blob: 3892949046204cb195acf7dda7729398d3931056 [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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000016#ifndef LLVM_CLANG_C_INDEX_H
17#define LLVM_CLANG_C_INDEX_H
Ted Kremenekb60d87c2009-08-26 22:36:44 +000018
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"
Argyrios Kyrtzidis0b9682e2014-02-25 03:59:23 +000022#include "clang-c/CXErrorCode.h"
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000023#include "clang-c/CXString.h"
Argyrios Kyrtzidis09a439d2014-02-25 03:59:16 +000024#include "clang-c/BuildSystem.h"
Arnaud A. de Grandmaison0271b322012-06-28 22:01:06 +000025
Argyrios Kyrtzidis1c4db8d2012-11-06 21:21:49 +000026/**
27 * \brief The version constants for the libclang API.
28 * CINDEX_VERSION_MINOR should increase when there are API additions.
29 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
30 *
31 * The policy about the libclang API was always to keep it source and ABI
32 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
33 */
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000034#define CINDEX_VERSION_MAJOR 0
Argyrios Kyrtzidis4e0854f2014-10-15 17:05:31 +000035#define CINDEX_VERSION_MINOR 29
Argyrios Kyrtzidis5b216ed2012-10-29 23:24:44 +000036
37#define CINDEX_VERSION_ENCODE(major, minor) ( \
38 ((major) * 10000) \
39 + ((minor) * 1))
40
41#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
42 CINDEX_VERSION_MAJOR, \
43 CINDEX_VERSION_MINOR )
44
45#define CINDEX_VERSION_STRINGIZE_(major, minor) \
46 #major"."#minor
47#define CINDEX_VERSION_STRINGIZE(major, minor) \
48 CINDEX_VERSION_STRINGIZE_(major, minor)
49
50#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
51 CINDEX_VERSION_MAJOR, \
52 CINDEX_VERSION_MINOR)
53
Ted Kremenekb60d87c2009-08-26 22:36:44 +000054#ifdef __cplusplus
55extern "C" {
56#endif
57
Douglas Gregor4a4e0eb2011-02-23 17:45:25 +000058/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor52606ff2010-01-20 01:10:47 +000059 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000060 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorc8e390c2010-01-20 22:45:41 +000061 * facilities for parsing source code into an abstract syntax tree (AST),
62 * loading already-parsed ASTs, traversing the AST, associating
63 * physical source locations with elements within the AST, and other
64 * facilities that support Clang-based development tools.
Douglas Gregor52606ff2010-01-20 01:10:47 +000065 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +000066 * This C interface to Clang will never provide all of the information
Douglas Gregorc8e390c2010-01-20 22:45:41 +000067 * representation stored in Clang's C++ AST, nor should it: the intent is to
68 * maintain an API that is relatively stable from one release to the next,
69 * providing only the basic functionality needed to support development tools.
Daniel Dunbar62ebf252010-01-24 02:54:26 +000070 *
71 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorc8e390c2010-01-20 22:45:41 +000072 * functions are prefixed with "clang_".
Douglas Gregor52606ff2010-01-20 01:10:47 +000073 *
74 * @{
75 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +000076
Douglas Gregor802f12f2010-01-20 22:28:27 +000077/**
78 * \brief An "index" that consists of a set of translation units that would
79 * typically be linked together into an executable or library.
80 */
81typedef void *CXIndex;
Steve Naroffd5e8e862009-08-27 19:51:58 +000082
Douglas Gregor802f12f2010-01-20 22:28:27 +000083/**
84 * \brief A single translation unit, which resides in an index.
85 */
Ted Kremenek7df92ae2010-11-17 23:24:11 +000086typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroffd5e8e862009-08-27 19:51:58 +000087
Douglas Gregor802f12f2010-01-20 22:28:27 +000088/**
Douglas Gregor6007cf22010-01-22 22:29:16 +000089 * \brief Opaque pointer representing client data that will be passed through
90 * to various callbacks and visitors.
Douglas Gregor802f12f2010-01-20 22:28:27 +000091 */
Douglas Gregor6007cf22010-01-22 22:29:16 +000092typedef void *CXClientData;
Daniel Dunbar62ebf252010-01-24 02:54:26 +000093
Douglas Gregor9485bf92009-12-02 09:21:34 +000094/**
95 * \brief Provides the contents of a file that has not yet been saved to disk.
96 *
97 * Each CXUnsavedFile instance provides the name of a file on the
98 * system along with the current contents of that file that have not
99 * yet been saved to disk.
100 */
101struct CXUnsavedFile {
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000102 /**
103 * \brief The file whose contents have not yet been saved.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000104 *
105 * This file must already exist in the file system.
106 */
107 const char *Filename;
108
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000109 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000110 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000111 */
112 const char *Contents;
113
114 /**
Douglas Gregor89a56c52010-02-27 01:32:48 +0000115 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor9485bf92009-12-02 09:21:34 +0000116 */
117 unsigned long Length;
118};
119
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000120/**
121 * \brief Describes the availability of a particular entity, which indicates
122 * whether the use of this entity will result in a warning or error due to
123 * it being deprecated or unavailable.
124 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000125enum CXAvailabilityKind {
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000126 /**
127 * \brief The entity is available.
128 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000129 CXAvailability_Available,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000130 /**
131 * \brief The entity is available, but has been deprecated (and its use is
132 * not recommended).
133 */
Douglas Gregorf757a122010-08-23 23:00:57 +0000134 CXAvailability_Deprecated,
Peter Collingbourne5caf5af2010-08-24 00:31:37 +0000135 /**
136 * \brief The entity is not available; any use of it will be an error.
137 */
Erik Verbruggen2e657ff2011-10-06 07:27:49 +0000138 CXAvailability_NotAvailable,
139 /**
140 * \brief The entity is available, but not accessible; any use of it will be
141 * an error.
142 */
143 CXAvailability_NotAccessible
Douglas Gregorf757a122010-08-23 23:00:57 +0000144};
Douglas Gregord6225d32012-05-08 00:14:45 +0000145
146/**
147 * \brief Describes a version number of the form major.minor.subminor.
148 */
149typedef struct CXVersion {
150 /**
151 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
152 * value indicates that there is no version number at all.
153 */
154 int Major;
155 /**
156 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
157 * will be negative if no minor version number was provided, e.g., for
158 * version '10'.
159 */
160 int Minor;
161 /**
162 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
163 * will be negative if no minor or subminor version number was provided,
164 * e.g., in version '10' or '10.7'.
165 */
166 int Subminor;
167} CXVersion;
Douglas Gregorf757a122010-08-23 23:00:57 +0000168
Douglas Gregor802f12f2010-01-20 22:28:27 +0000169/**
James Dennett574cb4c2012-06-15 05:41:51 +0000170 * \brief Provides a shared context for creating translation units.
171 *
172 * It provides two options:
Steve Naroff531e2842009-10-20 14:46:24 +0000173 *
174 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
175 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000176 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroff531e2842009-10-20 14:46:24 +0000177 * header that was used by the translation unit. If zero, all declarations
178 * will be enumerated.
179 *
Steve Naroffbb4568a2009-10-20 16:36:34 +0000180 * Here is an example:
181 *
James Dennett574cb4c2012-06-15 05:41:51 +0000182 * \code
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000183 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
184 * Idx = clang_createIndex(1, 1);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000185 *
186 * // IndexTest.pch was produced with the following command:
187 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
188 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
189 *
190 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000191 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor990b5762010-01-20 21:37:00 +0000192 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000193 * clang_disposeTranslationUnit(TU);
194 *
195 * // This will load all the symbols from 'IndexTest.c', excluding symbols
196 * // from 'IndexTest.pch'.
Daniel Dunbard0159262010-01-25 00:43:14 +0000197 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
198 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
199 * 0, 0);
Douglas Gregorfed36b12010-01-20 23:57:43 +0000200 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
201 * TranslationUnitVisitor, 0);
Steve Naroffbb4568a2009-10-20 16:36:34 +0000202 * clang_disposeTranslationUnit(TU);
James Dennett574cb4c2012-06-15 05:41:51 +0000203 * \endcode
Steve Naroffbb4568a2009-10-20 16:36:34 +0000204 *
205 * This process of creating the 'pch', loading it separately, and using it (via
206 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
207 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroff531e2842009-10-20 14:46:24 +0000208 */
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000209CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
210 int displayDiagnostics);
Ted Kremenekd071c602010-03-13 02:50:34 +0000211
Douglas Gregor408bb742010-02-08 23:03:06 +0000212/**
213 * \brief Destroy the given index.
214 *
215 * The index must not be destroyed until all of the translation units created
216 * within that index have been destroyed.
217 */
Daniel Dunbar11089662009-12-03 01:54:28 +0000218CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000219
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000220typedef enum {
221 /**
222 * \brief Used to indicate that no special CXIndex options are needed.
223 */
224 CXGlobalOpt_None = 0x0,
225
226 /**
227 * \brief Used to indicate that threads that libclang creates for indexing
228 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000229 *
230 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
231 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000232 */
233 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
234
235 /**
236 * \brief Used to indicate that threads that libclang creates for editing
237 * purposes should use background priority.
James Dennett574cb4c2012-06-15 05:41:51 +0000238 *
239 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
240 * #clang_annotateTokens
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000241 */
242 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
243
244 /**
245 * \brief Used to indicate that all threads that libclang creates should use
246 * background priority.
247 */
248 CXGlobalOpt_ThreadBackgroundPriorityForAll =
249 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
250 CXGlobalOpt_ThreadBackgroundPriorityForEditing
251
252} CXGlobalOptFlags;
253
254/**
James Dennett574cb4c2012-06-15 05:41:51 +0000255 * \brief Sets general options associated with a CXIndex.
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +0000256 *
257 * For example:
258 * \code
259 * CXIndex idx = ...;
260 * clang_CXIndex_setGlobalOptions(idx,
261 * clang_CXIndex_getGlobalOptions(idx) |
262 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
263 * \endcode
264 *
265 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
266 */
267CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
268
269/**
270 * \brief Gets the general options associated with a CXIndex.
271 *
272 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
273 * are associated with the given CXIndex object.
274 */
275CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
276
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000277/**
Douglas Gregor6007cf22010-01-22 22:29:16 +0000278 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000279 *
280 * @{
281 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000282
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000283/**
284 * \brief A particular source file that is part of a translation unit.
285 */
286typedef void *CXFile;
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000287
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000288
289/**
290 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff6231f182009-10-27 14:35:18 +0000291 */
Ted Kremenekc560b682010-02-17 00:41:20 +0000292CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000293
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000294/**
295 * \brief Retrieve the last modification time of the given file.
296 */
Douglas Gregor249c1212009-10-31 15:48:08 +0000297CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff6231f182009-10-27 14:35:18 +0000298
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000299/**
Argyrios Kyrtzidisac08b262013-01-26 04:52:52 +0000300 * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
301 * across an indexing session.
302 */
303typedef struct {
304 unsigned long long data[3];
305} CXFileUniqueID;
306
307/**
308 * \brief Retrieve the unique ID for the given \c file.
309 *
310 * \param file the file to get the ID for.
311 * \param outID stores the returned CXFileUniqueID.
312 * \returns If there was a failure getting the unique ID, returns non-zero,
313 * otherwise returns 0.
314*/
315CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
316
317/**
Douglas Gregor37aa4932011-05-04 00:14:37 +0000318 * \brief Determine whether the given header is guarded against
319 * multiple inclusions, either with the conventional
James Dennett574cb4c2012-06-15 05:41:51 +0000320 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
Douglas Gregor37aa4932011-05-04 00:14:37 +0000321 */
322CINDEX_LINKAGE unsigned
323clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
324
325/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000326 * \brief Retrieve a file handle within the given translation unit.
327 *
328 * \param tu the translation unit
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000329 *
Douglas Gregor816fd362010-01-22 21:44:22 +0000330 * \param file_name the name of the file.
331 *
332 * \returns the file handle for the named file in the translation unit \p tu,
333 * or a NULL file handle if the file was not a part of this translation unit.
334 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000335CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregor816fd362010-01-22 21:44:22 +0000336 const char *file_name);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000337
Douglas Gregor816fd362010-01-22 21:44:22 +0000338/**
Argyrios Kyrtzidisac3997e2014-08-16 00:26:19 +0000339 * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
340 * or they are both NULL.
341 */
342CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
343
344/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000345 * @}
346 */
347
348/**
349 * \defgroup CINDEX_LOCATIONS Physical source locations
350 *
351 * Clang represents physical source locations in its abstract syntax tree in
352 * great detail, with file, line, and column information for the majority of
353 * the tokens parsed in the source code. These data types and functions are
354 * used to represent source location information, either for a particular
355 * point in the program or for a range of points in the program, and extract
356 * specific location information from those data types.
357 *
358 * @{
359 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000360
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000361/**
Douglas Gregor4f46e782010-01-19 21:36:55 +0000362 * \brief Identifies a specific source location within a translation
363 * unit.
364 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000365 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregor229bebd2010-11-09 06:24:54 +0000366 * to map a source location to a particular file, line, and column.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000367 */
368typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000369 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000370 unsigned int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000371} CXSourceLocation;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000372
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000373/**
Daniel Dunbar02968e52010-02-14 10:02:57 +0000374 * \brief Identifies a half-open character range in the source code.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000375 *
Douglas Gregor4f46e782010-01-19 21:36:55 +0000376 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
377 * starting and end locations from a source range, respectively.
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000378 */
379typedef struct {
Argyrios Kyrtzidis49d9d0292013-01-11 22:29:47 +0000380 const void *ptr_data[2];
Douglas Gregor4f46e782010-01-19 21:36:55 +0000381 unsigned begin_int_data;
382 unsigned end_int_data;
Douglas Gregor49c4baf2010-01-18 22:13:09 +0000383} CXSourceRange;
Ted Kremeneka44d99c2010-01-05 23:18:49 +0000384
Douglas Gregor4f46e782010-01-19 21:36:55 +0000385/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000386 * \brief Retrieve a NULL (invalid) source location.
387 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000388CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000389
Douglas Gregor816fd362010-01-22 21:44:22 +0000390/**
James Dennett574cb4c2012-06-15 05:41:51 +0000391 * \brief Determine whether two source locations, which must refer into
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000392 * the same translation unit, refer to exactly the same point in the source
Douglas Gregor816fd362010-01-22 21:44:22 +0000393 * code.
394 *
395 * \returns non-zero if the source locations refer to the same location, zero
396 * if they refer to different locations.
397 */
398CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
399 CXSourceLocation loc2);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000400
Douglas Gregor816fd362010-01-22 21:44:22 +0000401/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000402 * \brief Retrieves the source location associated with a given file/line/column
403 * in a particular translation unit.
Douglas Gregor816fd362010-01-22 21:44:22 +0000404 */
405CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
406 CXFile file,
407 unsigned line,
408 unsigned column);
David Chisnall2e16ac52010-10-15 17:07:39 +0000409/**
410 * \brief Retrieves the source location associated with a given character offset
411 * in a particular translation unit.
412 */
413CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
414 CXFile file,
415 unsigned offset);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000416
Douglas Gregor816fd362010-01-22 21:44:22 +0000417/**
Argyrios Kyrtzidis25f7af12013-04-12 17:06:51 +0000418 * \brief Returns non-zero if the given source location is in a system header.
419 */
420CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
421
422/**
Stefanus Du Toitdb51c632013-08-08 17:48:14 +0000423 * \brief Returns non-zero if the given source location is in the main file of
424 * the corresponding translation unit.
425 */
426CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
427
428/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000429 * \brief Retrieve a NULL (invalid) source range.
430 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +0000431CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
Ted Kremenekd071c602010-03-13 02:50:34 +0000432
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000433/**
Douglas Gregor816fd362010-01-22 21:44:22 +0000434 * \brief Retrieve a source range given the beginning and ending source
435 * locations.
436 */
437CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
438 CXSourceLocation end);
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000439
Douglas Gregor816fd362010-01-22 21:44:22 +0000440/**
Douglas Gregor757e38b2011-07-23 19:35:14 +0000441 * \brief Determine whether two ranges are equivalent.
442 *
443 * \returns non-zero if the ranges are the same, zero if they differ.
444 */
445CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
446 CXSourceRange range2);
447
448/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +0000449 * \brief Returns non-zero if \p range is null.
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000450 */
Erik Verbruggend610b0f2011-10-06 12:11:57 +0000451CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidise7e42912011-09-28 18:14:21 +0000452
453/**
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000454 * \brief Retrieve the file, line, column, and offset represented by
455 * the given source location.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000456 *
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000457 * If the location refers into a macro expansion, retrieves the
458 * location of the macro expansion.
Douglas Gregor229bebd2010-11-09 06:24:54 +0000459 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000460 * \param location the location within a source file that will be decomposed
461 * into its parts.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000462 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000463 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000464 * source location points.
465 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000466 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor4f46e782010-01-19 21:36:55 +0000467 * source location points.
468 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000469 * \param column [out] if non-NULL, will be set to the column to which the given
470 * source location points.
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000471 *
472 * \param offset [out] if non-NULL, will be set to the offset into the
473 * buffer to which the given source location points.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000474 */
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000475CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
476 CXFile *file,
477 unsigned *line,
478 unsigned *column,
479 unsigned *offset);
480
481/**
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000482 * \brief Retrieve the file, line, column, and offset represented by
483 * the given source location, as specified in a # line directive.
484 *
485 * Example: given the following source code in a file somefile.c
486 *
James Dennett574cb4c2012-06-15 05:41:51 +0000487 * \code
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000488 * #123 "dummy.c" 1
489 *
490 * static int func(void)
491 * {
492 * return 0;
493 * }
James Dennett574cb4c2012-06-15 05:41:51 +0000494 * \endcode
Argyrios Kyrtzidis91672b32011-09-13 21:49:08 +0000495 *
496 * the location information returned by this function would be
497 *
498 * File: dummy.c Line: 124 Column: 12
499 *
500 * whereas clang_getExpansionLocation would have returned
501 *
502 * File: somefile.c Line: 3 Column: 12
503 *
504 * \param location the location within a source file that will be decomposed
505 * into its parts.
506 *
507 * \param filename [out] if non-NULL, will be set to the filename of the
508 * source location. Note that filenames returned will be for "virtual" files,
509 * which don't necessarily exist on the machine running clang - e.g. when
510 * parsing preprocessed output obtained from a different environment. If
511 * a non-NULL value is passed in, remember to dispose of the returned value
512 * using \c clang_disposeString() once you've finished with it. For an invalid
513 * source location, an empty string is returned.
514 *
515 * \param line [out] if non-NULL, will be set to the line number of the
516 * source location. For an invalid source location, zero is returned.
517 *
518 * \param column [out] if non-NULL, will be set to the column number of the
519 * source location. For an invalid source location, zero is returned.
520 */
521CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
522 CXString *filename,
523 unsigned *line,
524 unsigned *column);
525
526/**
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000527 * \brief Legacy API to retrieve the file, line, column, and offset represented
528 * by the given source location.
529 *
530 * This interface has been replaced by the newer interface
James Dennett574cb4c2012-06-15 05:41:51 +0000531 * #clang_getExpansionLocation(). See that interface's documentation for
Chandler Carruth4aa01ef2011-08-31 16:53:37 +0000532 * details.
533 */
Douglas Gregor4f46e782010-01-19 21:36:55 +0000534CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
535 CXFile *file,
536 unsigned *line,
Douglas Gregor9bd6db52010-01-26 19:19:08 +0000537 unsigned *column,
538 unsigned *offset);
Douglas Gregor47751d62010-01-26 03:07:15 +0000539
540/**
Douglas Gregor229bebd2010-11-09 06:24:54 +0000541 * \brief Retrieve the file, line, column, and offset represented by
542 * the given source location.
543 *
544 * If the location refers into a macro instantiation, return where the
545 * location was originally spelled in the source file.
546 *
547 * \param location the location within a source file that will be decomposed
548 * into its parts.
549 *
550 * \param file [out] if non-NULL, will be set to the file to which the given
551 * source location points.
552 *
553 * \param line [out] if non-NULL, will be set to the line to which the given
554 * source location points.
555 *
556 * \param column [out] if non-NULL, will be set to the column to which the given
557 * source location points.
558 *
559 * \param offset [out] if non-NULL, will be set to the offset into the
560 * buffer to which the given source location points.
561 */
562CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
563 CXFile *file,
564 unsigned *line,
565 unsigned *column,
566 unsigned *offset);
567
568/**
Argyrios Kyrtzidis56be7162013-01-04 18:30:13 +0000569 * \brief Retrieve the file, line, column, and offset represented by
570 * the given source location.
571 *
572 * If the location refers into a macro expansion, return where the macro was
573 * expanded or where the macro argument was written, if the location points at
574 * a macro argument.
575 *
576 * \param location the location within a source file that will be decomposed
577 * into its parts.
578 *
579 * \param file [out] if non-NULL, will be set to the file to which the given
580 * source location points.
581 *
582 * \param line [out] if non-NULL, will be set to the line to which the given
583 * source location points.
584 *
585 * \param column [out] if non-NULL, will be set to the column to which the given
586 * source location points.
587 *
588 * \param offset [out] if non-NULL, will be set to the offset into the
589 * buffer to which the given source location points.
590 */
591CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
592 CXFile *file,
593 unsigned *line,
594 unsigned *column,
595 unsigned *offset);
596
597/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000598 * \brief Retrieve a source location representing the first character within a
599 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000600 */
601CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
602
603/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +0000604 * \brief Retrieve a source location representing the last character within a
605 * source range.
Douglas Gregor4f46e782010-01-19 21:36:55 +0000606 */
607CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
608
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000609/**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000610 * \brief Identifies an array of ranges.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000611 */
612typedef struct {
613 /** \brief The number of ranges in the \c ranges array. */
614 unsigned count;
615 /**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000616 * \brief An array of \c CXSourceRanges.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000617 */
618 CXSourceRange *ranges;
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000619} CXSourceRangeList;
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000620
621/**
622 * \brief Retrieve all ranges that were skipped by the preprocessor.
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000623 *
624 * The preprocessor will skip lines when they are surrounded by an
625 * if/ifdef/ifndef directive whose condition does not evaluate to true.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000626 */
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000627CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
628 CXFile file);
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000629
630/**
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000631 * \brief Destroy the given \c CXSourceRangeList.
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000632 */
Argyrios Kyrtzidis0e282ef2013-12-06 18:55:45 +0000633CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
Argyrios Kyrtzidis9ef57752013-12-05 08:19:32 +0000634
635/**
Douglas Gregorc8e390c2010-01-20 22:45:41 +0000636 * @}
637 */
Douglas Gregor6007cf22010-01-22 22:29:16 +0000638
639/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000640 * \defgroup CINDEX_DIAG Diagnostic reporting
641 *
642 * @{
643 */
644
645/**
646 * \brief Describes the severity of a particular diagnostic.
647 */
648enum CXDiagnosticSeverity {
649 /**
Ted Kremenekd071c602010-03-13 02:50:34 +0000650 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000651 * option.
652 */
653 CXDiagnostic_Ignored = 0,
Ted Kremenekd071c602010-03-13 02:50:34 +0000654
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000655 /**
656 * \brief This diagnostic is a note that should be attached to the
657 * previous (non-note) diagnostic.
658 */
659 CXDiagnostic_Note = 1,
660
661 /**
662 * \brief This diagnostic indicates suspicious code that may not be
663 * wrong.
664 */
665 CXDiagnostic_Warning = 2,
666
667 /**
668 * \brief This diagnostic indicates that the code is ill-formed.
669 */
670 CXDiagnostic_Error = 3,
671
672 /**
673 * \brief This diagnostic indicates that the code is ill-formed such
674 * that future parser recovery is unlikely to produce useful
675 * results.
676 */
677 CXDiagnostic_Fatal = 4
678};
679
680/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000681 * \brief A single diagnostic, containing the diagnostic's severity,
682 * location, text, source ranges, and fix-it hints.
683 */
684typedef void *CXDiagnostic;
685
686/**
Ted Kremenekd010ba42011-11-10 08:43:12 +0000687 * \brief A group of CXDiagnostics.
688 */
689typedef void *CXDiagnosticSet;
690
691/**
692 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
693 */
694CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
695
696/**
697 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
698 *
James Dennett574cb4c2012-06-15 05:41:51 +0000699 * \param Diags the CXDiagnosticSet to query.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000700 * \param Index the zero-based diagnostic number to retrieve.
701 *
702 * \returns the requested diagnostic. This diagnostic must be freed
703 * via a call to \c clang_disposeDiagnostic().
704 */
705CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
706 unsigned Index);
707
708
709/**
710 * \brief Describes the kind of error that occurred (if any) in a call to
711 * \c clang_loadDiagnostics.
712 */
713enum CXLoadDiag_Error {
714 /**
715 * \brief Indicates that no error occurred.
716 */
717 CXLoadDiag_None = 0,
718
719 /**
720 * \brief Indicates that an unknown error occurred while attempting to
721 * deserialize diagnostics.
722 */
723 CXLoadDiag_Unknown = 1,
724
725 /**
726 * \brief Indicates that the file containing the serialized diagnostics
727 * could not be opened.
728 */
729 CXLoadDiag_CannotLoad = 2,
730
731 /**
732 * \brief Indicates that the serialized diagnostics file is invalid or
James Dennett574cb4c2012-06-15 05:41:51 +0000733 * corrupt.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000734 */
735 CXLoadDiag_InvalidFile = 3
736};
737
738/**
739 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
James Dennett574cb4c2012-06-15 05:41:51 +0000740 * file.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000741 *
James Dennett574cb4c2012-06-15 05:41:51 +0000742 * \param file The name of the file to deserialize.
743 * \param error A pointer to a enum value recording if there was a problem
Ted Kremenekd010ba42011-11-10 08:43:12 +0000744 * deserializing the diagnostics.
James Dennett574cb4c2012-06-15 05:41:51 +0000745 * \param errorString A pointer to a CXString for recording the error string
Ted Kremenekd010ba42011-11-10 08:43:12 +0000746 * if the file was not successfully loaded.
747 *
748 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
James Dennett574cb4c2012-06-15 05:41:51 +0000749 * diagnostics should be released using clang_disposeDiagnosticSet().
Ted Kremenekd010ba42011-11-10 08:43:12 +0000750 */
751CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
752 enum CXLoadDiag_Error *error,
753 CXString *errorString);
754
755/**
756 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
757 */
758CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
759
760/**
James Dennett574cb4c2012-06-15 05:41:51 +0000761 * \brief Retrieve the child diagnostics of a CXDiagnostic.
762 *
763 * This CXDiagnosticSet does not need to be released by
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000764 * clang_disposeDiagnosticSet.
Ted Kremenekd010ba42011-11-10 08:43:12 +0000765 */
766CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
767
768/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000769 * \brief Determine the number of diagnostics produced for the given
770 * translation unit.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000771 */
Douglas Gregor33cdd812010-02-18 18:08:43 +0000772CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
773
774/**
775 * \brief Retrieve a diagnostic associated with the given translation unit.
776 *
777 * \param Unit the translation unit to query.
778 * \param Index the zero-based diagnostic number to retrieve.
779 *
780 * \returns the requested diagnostic. This diagnostic must be freed
781 * via a call to \c clang_disposeDiagnostic().
782 */
783CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
784 unsigned Index);
785
786/**
Ted Kremenekb4a8b052011-12-09 22:28:32 +0000787 * \brief Retrieve the complete set of diagnostics associated with a
788 * translation unit.
789 *
790 * \param Unit the translation unit to query.
791 */
792CINDEX_LINKAGE CXDiagnosticSet
793 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
794
795/**
Douglas Gregor33cdd812010-02-18 18:08:43 +0000796 * \brief Destroy a diagnostic.
797 */
798CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000799
800/**
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000801 * \brief Options to control the display of diagnostics.
802 *
803 * The values in this enum are meant to be combined to customize the
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000804 * behavior of \c clang_formatDiagnostic().
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000805 */
806enum CXDiagnosticDisplayOptions {
807 /**
808 * \brief Display the source-location information where the
809 * diagnostic was located.
810 *
811 * When set, diagnostics will be prefixed by the file, line, and
812 * (optionally) column to which the diagnostic refers. For example,
813 *
814 * \code
815 * test.c:28: warning: extra tokens at end of #endif directive
816 * \endcode
817 *
818 * This option corresponds to the clang flag \c -fshow-source-location.
819 */
820 CXDiagnostic_DisplaySourceLocation = 0x01,
821
822 /**
823 * \brief If displaying the source-location information of the
824 * diagnostic, also include the column number.
825 *
826 * This option corresponds to the clang flag \c -fshow-column.
827 */
828 CXDiagnostic_DisplayColumn = 0x02,
829
830 /**
831 * \brief If displaying the source-location information of the
832 * diagnostic, also include information about source ranges in a
833 * machine-parsable format.
834 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000835 * This option corresponds to the clang flag
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000836 * \c -fdiagnostics-print-source-range-info.
837 */
Douglas Gregora750e8e2010-11-19 16:18:16 +0000838 CXDiagnostic_DisplaySourceRanges = 0x04,
839
840 /**
841 * \brief Display the option name associated with this diagnostic, if any.
842 *
843 * The option name displayed (e.g., -Wconversion) will be placed in brackets
844 * after the diagnostic text. This option corresponds to the clang flag
845 * \c -fdiagnostics-show-option.
846 */
847 CXDiagnostic_DisplayOption = 0x08,
848
849 /**
850 * \brief Display the category number associated with this diagnostic, if any.
851 *
852 * The category number is displayed within brackets after the diagnostic text.
853 * This option corresponds to the clang flag
854 * \c -fdiagnostics-show-category=id.
855 */
856 CXDiagnostic_DisplayCategoryId = 0x10,
857
858 /**
859 * \brief Display the category name associated with this diagnostic, if any.
860 *
861 * The category name is displayed within brackets after the diagnostic text.
862 * This option corresponds to the clang flag
863 * \c -fdiagnostics-show-category=name.
864 */
865 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000866};
867
868/**
Douglas Gregord770f732010-02-22 23:17:23 +0000869 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000870 *
Douglas Gregord770f732010-02-22 23:17:23 +0000871 * This routine will format the given diagnostic to a string, rendering
Ted Kremenekd071c602010-03-13 02:50:34 +0000872 * the diagnostic according to the various options given. The
873 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000874 * options that most closely mimics the behavior of the clang compiler.
875 *
876 * \param Diagnostic The diagnostic to print.
877 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000878 * \param Options A set of options that control the diagnostic display,
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000879 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregord770f732010-02-22 23:17:23 +0000880 *
881 * \returns A new string containing for formatted diagnostic.
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000882 */
Douglas Gregord770f732010-02-22 23:17:23 +0000883CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
884 unsigned Options);
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000885
886/**
887 * \brief Retrieve the set of display options most similar to the
888 * default behavior of the clang compiler.
889 *
890 * \returns A set of display options suitable for use with \c
Sylvestre Ledrud29d97c2013-11-17 09:46:45 +0000891 * clang_formatDiagnostic().
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000892 */
893CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
894
895/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000896 * \brief Determine the severity of the given diagnostic.
897 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000898CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000899clang_getDiagnosticSeverity(CXDiagnostic);
900
901/**
902 * \brief Retrieve the source location of the given diagnostic.
903 *
904 * This location is where Clang would print the caret ('^') when
905 * displaying the diagnostic on the command line.
906 */
907CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
908
909/**
910 * \brief Retrieve the text of the given diagnostic.
911 */
912CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000913
914/**
Douglas Gregora750e8e2010-11-19 16:18:16 +0000915 * \brief Retrieve the name of the command-line option that enabled this
916 * diagnostic.
917 *
918 * \param Diag The diagnostic to be queried.
919 *
920 * \param Disable If non-NULL, will be set to the option that disables this
921 * diagnostic (if any).
922 *
923 * \returns A string that contains the command-line option used to enable this
924 * warning, such as "-Wconversion" or "-pedantic".
925 */
926CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
927 CXString *Disable);
928
929/**
930 * \brief Retrieve the category number for this diagnostic.
931 *
932 * Diagnostics can be categorized into groups along with other, related
933 * diagnostics (e.g., diagnostics under the same warning flag). This routine
934 * retrieves the category number for the given diagnostic.
935 *
936 * \returns The number of the category that contains this diagnostic, or zero
937 * if this diagnostic is uncategorized.
938 */
939CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
940
941/**
Ted Kremenek26a6d492012-04-12 00:03:31 +0000942 * \brief Retrieve the name of a particular diagnostic category. This
943 * is now deprecated. Use clang_getDiagnosticCategoryText()
944 * instead.
Douglas Gregora750e8e2010-11-19 16:18:16 +0000945 *
946 * \param Category A diagnostic category number, as returned by
947 * \c clang_getDiagnosticCategory().
948 *
949 * \returns The name of the given diagnostic category.
950 */
Ted Kremenek26a6d492012-04-12 00:03:31 +0000951CINDEX_DEPRECATED CINDEX_LINKAGE
952CXString clang_getDiagnosticCategoryName(unsigned Category);
953
954/**
955 * \brief Retrieve the diagnostic category text for a given diagnostic.
956 *
Ted Kremenek26a6d492012-04-12 00:03:31 +0000957 * \returns The text of the given diagnostic category.
958 */
959CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregora750e8e2010-11-19 16:18:16 +0000960
961/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000962 * \brief Determine the number of source ranges associated with the given
963 * diagnostic.
964 */
965CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenekd071c602010-03-13 02:50:34 +0000966
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000967/**
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000968 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000969 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000970 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000971 * code. On the command line, Clang displays source ranges by
Ted Kremenekd071c602010-03-13 02:50:34 +0000972 * underlining them with '~' characters.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000973 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000974 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000975 *
Ted Kremenekd071c602010-03-13 02:50:34 +0000976 * \param Range the zero-based index specifying which range to
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000977 *
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000978 * \returns the requested source range.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000979 */
Ted Kremenekd071c602010-03-13 02:50:34 +0000980CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregor4b8fd6d2010-02-08 23:11:56 +0000981 unsigned Range);
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000982
983/**
984 * \brief Determine the number of fix-it hints associated with the
985 * given diagnostic.
986 */
987CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
988
989/**
Douglas Gregor836ec942010-02-19 18:16:06 +0000990 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor4f9c3762010-01-28 00:27:43 +0000991 *
Douglas Gregor836ec942010-02-19 18:16:06 +0000992 * Fix-its are described in terms of a source range whose contents
993 * should be replaced by a string. This approach generalizes over
994 * three kinds of operations: removal of source code (the range covers
995 * the code to be removed and the replacement string is empty),
996 * replacement of source code (the range covers the code to be
997 * replaced and the replacement string provides the new code), and
998 * insertion (both the start and end of the range point at the
999 * insertion location, and the replacement string provides the text to
1000 * insert).
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001001 *
Douglas Gregor836ec942010-02-19 18:16:06 +00001002 * \param Diagnostic The diagnostic whose fix-its are being queried.
1003 *
1004 * \param FixIt The zero-based index of the fix-it.
1005 *
1006 * \param ReplacementRange The source range whose contents will be
1007 * replaced with the returned replacement string. Note that source
1008 * ranges are half-open ranges [a, b), so the source code should be
1009 * replaced from a and up to (but not including) b.
1010 *
1011 * \returns A string containing text that should be replace the source
1012 * code indicated by the \c ReplacementRange.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001013 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001014CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor836ec942010-02-19 18:16:06 +00001015 unsigned FixIt,
1016 CXSourceRange *ReplacementRange);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001017
1018/**
1019 * @}
1020 */
1021
1022/**
1023 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
1024 *
1025 * The routines in this group provide the ability to create and destroy
1026 * translation units from files, either by parsing the contents of the files or
1027 * by reading in a serialized representation of a translation unit.
1028 *
1029 * @{
1030 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001031
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001032/**
1033 * \brief Get the original translation unit source file name.
1034 */
1035CINDEX_LINKAGE CXString
1036clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1037
1038/**
1039 * \brief Return the CXTranslationUnit for a given source file and the provided
1040 * command line arguments one would pass to the compiler.
1041 *
1042 * Note: The 'source_filename' argument is optional. If the caller provides a
1043 * NULL pointer, the name of the source file is expected to reside in the
1044 * specified command line arguments.
1045 *
1046 * Note: When encountered in 'clang_command_line_args', the following options
1047 * are ignored:
1048 *
1049 * '-c'
1050 * '-emit-ast'
1051 * '-fsyntax-only'
James Dennett574cb4c2012-06-15 05:41:51 +00001052 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001053 *
Ted Kremenekbd4972442010-11-08 04:28:51 +00001054 * \param CIdx The index object with which the translation unit will be
1055 * associated.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001056 *
James Dennett574cb4c2012-06-15 05:41:51 +00001057 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenekbd4972442010-11-08 04:28:51 +00001058 * source file is included in \p clang_command_line_args.
1059 *
1060 * \param num_clang_command_line_args The number of command-line arguments in
1061 * \p clang_command_line_args.
1062 *
1063 * \param clang_command_line_args The command-line arguments that would be
1064 * passed to the \c clang executable if it were being invoked out-of-process.
1065 * These command-line options will be parsed and will affect how the translation
1066 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001067 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001068 *
1069 * \param num_unsaved_files the number of unsaved file entries in \p
1070 * unsaved_files.
1071 *
1072 * \param unsaved_files the files that have not yet been saved to disk
1073 * but may be required for code completion, including the contents of
Ted Kremenekde24a942010-04-12 18:47:26 +00001074 * those files. The contents and name of these files (as specified by
1075 * CXUnsavedFile) are copied when necessary, so the client only needs to
1076 * guarantee their validity until the call to this function returns.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001077 */
1078CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1079 CXIndex CIdx,
1080 const char *source_filename,
1081 int num_clang_command_line_args,
Douglas Gregor57879fa2010-09-01 16:43:19 +00001082 const char * const *clang_command_line_args,
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001083 unsigned num_unsaved_files,
Douglas Gregor33cdd812010-02-18 18:08:43 +00001084 struct CXUnsavedFile *unsaved_files);
Ted Kremenekd071c602010-03-13 02:50:34 +00001085
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001086/**
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001087 * \brief Same as \c clang_createTranslationUnit2, but returns
1088 * the \c CXTranslationUnit instead of an error code. In case of an error this
1089 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1090 * error codes.
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001091 */
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001092CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
1093 CXIndex CIdx,
1094 const char *ast_filename);
1095
1096/**
1097 * \brief Create a translation unit from an AST file (\c -emit-ast).
1098 *
1099 * \param[out] out_TU A non-NULL pointer to store the created
1100 * \c CXTranslationUnit.
1101 *
1102 * \returns Zero on success, otherwise returns an error code.
1103 */
1104CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2(
1105 CXIndex CIdx,
1106 const char *ast_filename,
1107 CXTranslationUnit *out_TU);
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001108
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001109/**
1110 * \brief Flags that control the creation of translation units.
1111 *
1112 * The enumerators in this enumeration type are meant to be bitwise
1113 * ORed together to specify which options should be used when
1114 * constructing the translation unit.
1115 */
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001116enum CXTranslationUnit_Flags {
1117 /**
1118 * \brief Used to indicate that no special translation-unit options are
1119 * needed.
1120 */
1121 CXTranslationUnit_None = 0x0,
1122
1123 /**
1124 * \brief Used to indicate that the parser should construct a "detailed"
1125 * preprocessing record, including all macro definitions and instantiations.
1126 *
1127 * Constructing a detailed preprocessing record requires more memory
1128 * and time to parse, since the information contained in the record
1129 * is usually not retained. However, it can be useful for
1130 * applications that require more detailed information about the
1131 * behavior of the preprocessor.
1132 */
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001133 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1134
1135 /**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001136 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001137 *
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001138 * When a translation unit is considered "incomplete", semantic
1139 * analysis that is typically performed at the end of the
1140 * translation unit will be suppressed. For example, this suppresses
1141 * the completion of tentative declarations in C and of
1142 * instantiation of implicitly-instantiation function templates in
1143 * C++. This option is typically used when parsing a header with the
1144 * intent of producing a precompiled header.
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001145 */
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001146 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregorbe2d8c62010-07-23 00:33:23 +00001147
1148 /**
1149 * \brief Used to indicate that the translation unit should be built with an
1150 * implicit precompiled header for the preamble.
1151 *
1152 * An implicit precompiled header is used as an optimization when a
1153 * particular translation unit is likely to be reparsed many times
1154 * when the sources aren't changing that often. In this case, an
1155 * implicit precompiled header will be built containing all of the
1156 * initial includes at the top of the main file (what we refer to as
1157 * the "preamble" of the file). In subsequent parses, if the
1158 * preamble or the files in it have not changed, \c
1159 * clang_reparseTranslationUnit() will re-use the implicit
1160 * precompiled header to improve parsing performance.
1161 */
Douglas Gregorde051182010-08-11 15:58:42 +00001162 CXTranslationUnit_PrecompiledPreamble = 0x04,
1163
1164 /**
1165 * \brief Used to indicate that the translation unit should cache some
1166 * code-completion results with each reparse of the source file.
1167 *
1168 * Caching of code-completion results is a performance optimization that
1169 * introduces some overhead to reparsing but improves the performance of
1170 * code-completion operations.
1171 */
Douglas Gregorf5a18542010-10-27 17:24:53 +00001172 CXTranslationUnit_CacheCompletionResults = 0x08,
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001173
Douglas Gregorf5a18542010-10-27 17:24:53 +00001174 /**
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001175 * \brief Used to indicate that the translation unit will be serialized with
1176 * \c clang_saveTranslationUnit.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001177 *
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001178 * This option is typically used when parsing a header with the intent of
1179 * producing a precompiled header.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001180 */
Argyrios Kyrtzidis0db720f2012-10-11 16:05:00 +00001181 CXTranslationUnit_ForSerialization = 0x10,
Douglas Gregorf5a18542010-10-27 17:24:53 +00001182
1183 /**
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001184 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001185 *
1186 * Note: this is a *temporary* option that is available only while
Douglas Gregor2ed0ee12011-08-25 22:54:01 +00001187 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregorf5a18542010-10-27 17:24:53 +00001188 */
Erik Verbruggen6e922512012-04-12 10:11:59 +00001189 CXTranslationUnit_CXXChainedPCH = 0x20,
1190
1191 /**
1192 * \brief Used to indicate that function/method bodies should be skipped while
1193 * parsing.
1194 *
1195 * This option can be used to search for declarations/definitions while
1196 * ignoring the usages.
1197 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00001198 CXTranslationUnit_SkipFunctionBodies = 0x40,
1199
1200 /**
1201 * \brief Used to indicate that brief documentation comments should be
1202 * included into the set of code completions returned from this translation
1203 * unit.
1204 */
1205 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001206};
1207
1208/**
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001209 * \brief Returns the set of flags that is suitable for parsing a translation
1210 * unit that is being edited.
1211 *
1212 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1213 * to indicate that the translation unit is likely to be reparsed many times,
1214 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1215 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1216 * set contains an unspecified set of optimizations (e.g., the precompiled
1217 * preamble) geared toward improving the performance of these routines. The
1218 * set of optimizations enabled may change from one version to the next.
1219 */
Douglas Gregorde051182010-08-11 15:58:42 +00001220CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001221
1222/**
1223 * \brief Same as \c clang_parseTranslationUnit2, but returns
1224 * the \c CXTranslationUnit instead of an error code. In case of an error this
1225 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1226 * error codes.
1227 */
1228CINDEX_LINKAGE CXTranslationUnit
1229clang_parseTranslationUnit(CXIndex CIdx,
1230 const char *source_filename,
1231 const char *const *command_line_args,
1232 int num_command_line_args,
1233 struct CXUnsavedFile *unsaved_files,
1234 unsigned num_unsaved_files,
1235 unsigned options);
1236
Douglas Gregor4a47bca2010-08-09 22:28:58 +00001237/**
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001238 * \brief Parse the given source file and the translation unit corresponding
1239 * to that file.
1240 *
1241 * This routine is the main entry point for the Clang C API, providing the
1242 * ability to parse a source file into a translation unit that can then be
1243 * queried by other functions in the API. This routine accepts a set of
1244 * command-line arguments so that the compilation can be configured in the same
1245 * way that the compiler is configured on the command line.
1246 *
1247 * \param CIdx The index object with which the translation unit will be
1248 * associated.
1249 *
1250 * \param source_filename The name of the source file to load, or NULL if the
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001251 * source file is included in \c command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001252 *
1253 * \param command_line_args The command-line arguments that would be
1254 * passed to the \c clang executable if it were being invoked out-of-process.
1255 * These command-line options will be parsed and will affect how the translation
1256 * unit is parsed. Note that the following options are ignored: '-c',
James Dennett574cb4c2012-06-15 05:41:51 +00001257 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001258 *
1259 * \param num_command_line_args The number of command-line arguments in
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001260 * \c command_line_args.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001261 *
1262 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor8e984da2010-08-04 16:47:14 +00001263 * but may be required for parsing, including the contents of
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001264 * those files. The contents and name of these files (as specified by
1265 * CXUnsavedFile) are copied when necessary, so the client only needs to
1266 * guarantee their validity until the call to this function returns.
1267 *
1268 * \param num_unsaved_files the number of unsaved file entries in \p
1269 * unsaved_files.
1270 *
1271 * \param options A bitmask of options that affects how the translation unit
1272 * is managed but not its compilation. This should be a bitwise OR of the
1273 * CXTranslationUnit_XXX flags.
1274 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001275 * \param[out] out_TU A non-NULL pointer to store the created
1276 * \c CXTranslationUnit, describing the parsed code and containing any
1277 * diagnostics produced by the compiler.
1278 *
1279 * \returns Zero on success, otherwise returns an error code.
Douglas Gregor99d2cf42010-07-21 18:52:53 +00001280 */
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001281CINDEX_LINKAGE enum CXErrorCode
1282clang_parseTranslationUnit2(CXIndex CIdx,
1283 const char *source_filename,
1284 const char *const *command_line_args,
1285 int num_command_line_args,
1286 struct CXUnsavedFile *unsaved_files,
1287 unsigned num_unsaved_files,
1288 unsigned options,
1289 CXTranslationUnit *out_TU);
1290
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001291/**
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001292 * \brief Flags that control how translation units are saved.
1293 *
1294 * The enumerators in this enumeration type are meant to be bitwise
1295 * ORed together to specify which options should be used when
1296 * saving the translation unit.
1297 */
1298enum CXSaveTranslationUnit_Flags {
1299 /**
1300 * \brief Used to indicate that no special saving options are needed.
1301 */
1302 CXSaveTranslationUnit_None = 0x0
1303};
1304
1305/**
1306 * \brief Returns the set of flags that is suitable for saving a translation
1307 * unit.
1308 *
1309 * The set of flags returned provide options for
1310 * \c clang_saveTranslationUnit() by default. The returned flag
1311 * set contains an unspecified set of options that save translation units with
1312 * the most commonly-requested data.
1313 */
1314CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1315
1316/**
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001317 * \brief Describes the kind of error that occurred (if any) in a call to
1318 * \c clang_saveTranslationUnit().
1319 */
1320enum CXSaveError {
1321 /**
1322 * \brief Indicates that no error occurred while saving a translation unit.
1323 */
1324 CXSaveError_None = 0,
1325
1326 /**
1327 * \brief Indicates that an unknown error occurred while attempting to save
1328 * the file.
1329 *
1330 * This error typically indicates that file I/O failed when attempting to
1331 * write the file.
1332 */
1333 CXSaveError_Unknown = 1,
1334
1335 /**
1336 * \brief Indicates that errors during translation prevented this attempt
1337 * to save the translation unit.
1338 *
1339 * Errors that prevent the translation unit from being saved can be
1340 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1341 */
1342 CXSaveError_TranslationErrors = 2,
1343
1344 /**
1345 * \brief Indicates that the translation unit to be saved was somehow
1346 * invalid (e.g., NULL).
1347 */
1348 CXSaveError_InvalidTU = 3
1349};
1350
1351/**
Douglas Gregore9386682010-08-13 05:36:37 +00001352 * \brief Saves a translation unit into a serialized representation of
1353 * that translation unit on disk.
1354 *
1355 * Any translation unit that was parsed without error can be saved
1356 * into a file. The translation unit can then be deserialized into a
1357 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1358 * if it is an incomplete translation unit that corresponds to a
1359 * header, used as a precompiled header when parsing other translation
1360 * units.
1361 *
1362 * \param TU The translation unit to save.
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001363 *
Douglas Gregore9386682010-08-13 05:36:37 +00001364 * \param FileName The file to which the translation unit will be saved.
1365 *
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001366 * \param options A bitmask of options that affects how the translation unit
1367 * is saved. This should be a bitwise OR of the
1368 * CXSaveTranslationUnit_XXX flags.
1369 *
Douglas Gregor30c80fa2011-07-06 16:43:36 +00001370 * \returns A value that will match one of the enumerators of the CXSaveError
1371 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1372 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregore9386682010-08-13 05:36:37 +00001373 */
1374CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor6bb92ec2010-08-13 15:35:05 +00001375 const char *FileName,
1376 unsigned options);
Douglas Gregore9386682010-08-13 05:36:37 +00001377
1378/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001379 * \brief Destroy the specified CXTranslationUnit object.
1380 */
1381CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenekd071c602010-03-13 02:50:34 +00001382
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001383/**
Douglas Gregorde051182010-08-11 15:58:42 +00001384 * \brief Flags that control the reparsing of translation units.
1385 *
1386 * The enumerators in this enumeration type are meant to be bitwise
1387 * ORed together to specify which options should be used when
1388 * reparsing the translation unit.
1389 */
1390enum CXReparse_Flags {
1391 /**
1392 * \brief Used to indicate that no special reparsing options are needed.
1393 */
1394 CXReparse_None = 0x0
1395};
1396
1397/**
1398 * \brief Returns the set of flags that is suitable for reparsing a translation
1399 * unit.
1400 *
1401 * The set of flags returned provide options for
1402 * \c clang_reparseTranslationUnit() by default. The returned flag
1403 * set contains an unspecified set of optimizations geared toward common uses
1404 * of reparsing. The set of optimizations enabled may change from one version
1405 * to the next.
1406 */
1407CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1408
1409/**
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001410 * \brief Reparse the source files that produced this translation unit.
1411 *
1412 * This routine can be used to re-parse the source files that originally
1413 * created the given translation unit, for example because those source files
1414 * have changed (either on disk or as passed via \p unsaved_files). The
1415 * source code will be reparsed with the same command-line options as it
1416 * was originally parsed.
1417 *
1418 * Reparsing a translation unit invalidates all cursors and source locations
1419 * that refer into that translation unit. This makes reparsing a translation
1420 * unit semantically equivalent to destroying the translation unit and then
1421 * creating a new translation unit with the same command-line arguments.
1422 * However, it may be more efficient to reparse a translation
1423 * unit using this routine.
1424 *
1425 * \param TU The translation unit whose contents will be re-parsed. The
1426 * translation unit must originally have been built with
1427 * \c clang_createTranslationUnitFromSourceFile().
1428 *
1429 * \param num_unsaved_files The number of unsaved file entries in \p
1430 * unsaved_files.
1431 *
1432 * \param unsaved_files The files that have not yet been saved to disk
1433 * but may be required for parsing, including the contents of
1434 * those files. The contents and name of these files (as specified by
1435 * CXUnsavedFile) are copied when necessary, so the client only needs to
1436 * guarantee their validity until the call to this function returns.
1437 *
Douglas Gregorde051182010-08-11 15:58:42 +00001438 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1439 * The function \c clang_defaultReparseOptions() produces a default set of
1440 * options recommended for most uses, based on the translation unit.
1441 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001442 * \returns 0 if the sources could be reparsed. A non-zero error code will be
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001443 * returned if reparsing was impossible, such that the translation unit is
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00001444 * invalid. In such cases, the only valid call for \c TU is
1445 * \c clang_disposeTranslationUnit(TU). The error codes returned by this
1446 * routine are described by the \c CXErrorCode enum.
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001447 */
1448CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1449 unsigned num_unsaved_files,
Douglas Gregorde051182010-08-11 15:58:42 +00001450 struct CXUnsavedFile *unsaved_files,
1451 unsigned options);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001452
1453/**
1454 * \brief Categorizes how memory is being used by a translation unit.
1455 */
Ted Kremenek23324122011-04-20 16:41:07 +00001456enum CXTUResourceUsageKind {
1457 CXTUResourceUsage_AST = 1,
1458 CXTUResourceUsage_Identifiers = 2,
1459 CXTUResourceUsage_Selectors = 3,
1460 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek21735e62011-04-28 04:10:31 +00001461 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekf5df0ce2011-04-28 04:53:38 +00001462 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenek8d587902011-04-28 20:36:42 +00001463 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremenek5e1ed7b2011-04-28 23:46:20 +00001464 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1465 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1466 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek2160a0d2011-05-04 01:38:46 +00001467 CXTUResourceUsage_Preprocessor = 11,
1468 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenek120992a2011-07-26 23:46:06 +00001469 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001470 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenek23324122011-04-20 16:41:07 +00001471 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1472 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001473 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenek23324122011-04-20 16:41:07 +00001474
1475 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekfbcce6f2011-07-26 23:46:11 +00001476 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek83f642e2011-04-18 22:47:10 +00001477};
1478
1479/**
1480 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenek23324122011-04-20 16:41:07 +00001481 * the name of the memory category. This string should never be freed.
Ted Kremenek83f642e2011-04-18 22:47:10 +00001482 */
1483CINDEX_LINKAGE
Ted Kremenek23324122011-04-20 16:41:07 +00001484const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001485
Ted Kremenek23324122011-04-20 16:41:07 +00001486typedef struct CXTUResourceUsageEntry {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001487 /* \brief The memory usage category. */
Ted Kremenek23324122011-04-20 16:41:07 +00001488 enum CXTUResourceUsageKind kind;
1489 /* \brief Amount of resources used.
1490 The units will depend on the resource kind. */
Ted Kremenek83f642e2011-04-18 22:47:10 +00001491 unsigned long amount;
Ted Kremenek23324122011-04-20 16:41:07 +00001492} CXTUResourceUsageEntry;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001493
1494/**
1495 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1496 */
Ted Kremenek23324122011-04-20 16:41:07 +00001497typedef struct CXTUResourceUsage {
Ted Kremenek83f642e2011-04-18 22:47:10 +00001498 /* \brief Private data member, used for queries. */
1499 void *data;
1500
1501 /* \brief The number of entries in the 'entries' array. */
1502 unsigned numEntries;
1503
1504 /* \brief An array of key-value pairs, representing the breakdown of memory
1505 usage. */
Ted Kremenek23324122011-04-20 16:41:07 +00001506 CXTUResourceUsageEntry *entries;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001507
Ted Kremenek23324122011-04-20 16:41:07 +00001508} CXTUResourceUsage;
Ted Kremenek83f642e2011-04-18 22:47:10 +00001509
1510/**
1511 * \brief Return the memory usage of a translation unit. This object
Ted Kremenek23324122011-04-20 16:41:07 +00001512 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek83f642e2011-04-18 22:47:10 +00001513 */
Ted Kremenek23324122011-04-20 16:41:07 +00001514CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001515
Ted Kremenek23324122011-04-20 16:41:07 +00001516CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek83f642e2011-04-18 22:47:10 +00001517
Douglas Gregoraa21cc42010-07-19 21:46:24 +00001518/**
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001519 * @}
1520 */
Ted Kremenekd071c602010-03-13 02:50:34 +00001521
Douglas Gregor4f9c3762010-01-28 00:27:43 +00001522/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001523 * \brief Describes the kind of entity that a cursor refers to.
1524 */
1525enum CXCursorKind {
1526 /* Declarations */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001527 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001528 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001529 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001530 *
1531 * Unexposed declarations have the same operations as any other kind
1532 * of declaration; one can extract their location information,
1533 * spelling, find their definitions, etc. However, the specific kind
1534 * of the declaration is not reported.
1535 */
1536 CXCursor_UnexposedDecl = 1,
1537 /** \brief A C or C++ struct. */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001538 CXCursor_StructDecl = 2,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001539 /** \brief A C or C++ union. */
1540 CXCursor_UnionDecl = 3,
1541 /** \brief A C++ class. */
1542 CXCursor_ClassDecl = 4,
1543 /** \brief An enumeration. */
1544 CXCursor_EnumDecl = 5,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001545 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00001546 * \brief A field (in C) or non-static data member (in C++) in a
1547 * struct, union, or C++ class.
1548 */
1549 CXCursor_FieldDecl = 6,
1550 /** \brief An enumerator constant. */
1551 CXCursor_EnumConstantDecl = 7,
1552 /** \brief A function. */
1553 CXCursor_FunctionDecl = 8,
1554 /** \brief A variable. */
1555 CXCursor_VarDecl = 9,
1556 /** \brief A function or method parameter. */
1557 CXCursor_ParmDecl = 10,
James Dennett1355bd12012-06-11 06:19:40 +00001558 /** \brief An Objective-C \@interface. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001559 CXCursor_ObjCInterfaceDecl = 11,
James Dennett1355bd12012-06-11 06:19:40 +00001560 /** \brief An Objective-C \@interface for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001561 CXCursor_ObjCCategoryDecl = 12,
James Dennett1355bd12012-06-11 06:19:40 +00001562 /** \brief An Objective-C \@protocol declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001563 CXCursor_ObjCProtocolDecl = 13,
James Dennett1355bd12012-06-11 06:19:40 +00001564 /** \brief An Objective-C \@property declaration. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001565 CXCursor_ObjCPropertyDecl = 14,
1566 /** \brief An Objective-C instance variable. */
1567 CXCursor_ObjCIvarDecl = 15,
1568 /** \brief An Objective-C instance method. */
1569 CXCursor_ObjCInstanceMethodDecl = 16,
1570 /** \brief An Objective-C class method. */
1571 CXCursor_ObjCClassMethodDecl = 17,
James Dennett1355bd12012-06-11 06:19:40 +00001572 /** \brief An Objective-C \@implementation. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001573 CXCursor_ObjCImplementationDecl = 18,
James Dennett1355bd12012-06-11 06:19:40 +00001574 /** \brief An Objective-C \@implementation for a category. */
Douglas Gregor6007cf22010-01-22 22:29:16 +00001575 CXCursor_ObjCCategoryImplDecl = 19,
1576 /** \brief A typedef */
1577 CXCursor_TypedefDecl = 20,
Ted Kremenek225b8e32010-04-13 23:39:06 +00001578 /** \brief A C++ class method. */
1579 CXCursor_CXXMethod = 21,
Ted Kremenekbd67fb22010-05-06 23:38:21 +00001580 /** \brief A C++ namespace. */
1581 CXCursor_Namespace = 22,
Ted Kremenekb80cba52010-05-07 01:04:29 +00001582 /** \brief A linkage specification, e.g. 'extern "C"'. */
1583 CXCursor_LinkageSpec = 23,
Douglas Gregor12bca222010-08-31 14:41:23 +00001584 /** \brief A C++ constructor. */
1585 CXCursor_Constructor = 24,
1586 /** \brief A C++ destructor. */
1587 CXCursor_Destructor = 25,
1588 /** \brief A C++ conversion function. */
1589 CXCursor_ConversionFunction = 26,
Douglas Gregor713602b2010-08-31 17:01:39 +00001590 /** \brief A C++ template type parameter. */
1591 CXCursor_TemplateTypeParameter = 27,
1592 /** \brief A C++ non-type template parameter. */
1593 CXCursor_NonTypeTemplateParameter = 28,
1594 /** \brief A C++ template template parameter. */
1595 CXCursor_TemplateTemplateParameter = 29,
1596 /** \brief A C++ function template. */
1597 CXCursor_FunctionTemplate = 30,
Douglas Gregor1fbaeb12010-08-31 19:02:00 +00001598 /** \brief A C++ class template. */
1599 CXCursor_ClassTemplate = 31,
Douglas Gregorf96abb22010-08-31 19:31:58 +00001600 /** \brief A C++ class template partial specialization. */
1601 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregora89314e2010-08-31 23:48:11 +00001602 /** \brief A C++ namespace alias declaration. */
1603 CXCursor_NamespaceAlias = 33,
Douglas Gregor01a430132010-09-01 03:07:18 +00001604 /** \brief A C++ using directive. */
1605 CXCursor_UsingDirective = 34,
Richard Smithdda56e42011-04-15 14:24:37 +00001606 /** \brief A C++ using declaration. */
Douglas Gregora9aa29c2010-09-01 19:52:22 +00001607 CXCursor_UsingDeclaration = 35,
Richard Smithdda56e42011-04-15 14:24:37 +00001608 /** \brief A C++ alias declaration */
1609 CXCursor_TypeAliasDecl = 36,
James Dennett574cb4c2012-06-15 05:41:51 +00001610 /** \brief An Objective-C \@synthesize definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001611 CXCursor_ObjCSynthesizeDecl = 37,
James Dennett574cb4c2012-06-15 05:41:51 +00001612 /** \brief An Objective-C \@dynamic definition. */
Douglas Gregor4cd65962011-06-03 23:08:58 +00001613 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001614 /** \brief An access specifier. */
1615 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor4c362d52011-10-05 19:00:14 +00001616
Ted Kremenek08de5c12010-05-19 21:51:10 +00001617 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis12afd702011-09-30 17:58:23 +00001618 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001619
Douglas Gregor6007cf22010-01-22 22:29:16 +00001620 /* References */
1621 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001622 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregor6007cf22010-01-22 22:29:16 +00001623 CXCursor_ObjCProtocolRef = 41,
1624 CXCursor_ObjCClassRef = 42,
1625 /**
1626 * \brief A reference to a type declaration.
1627 *
1628 * A type reference occurs anywhere where a type is named but not
1629 * declared. For example, given:
1630 *
1631 * \code
1632 * typedef unsigned size_type;
1633 * size_type size;
1634 * \endcode
1635 *
1636 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1637 * while the type of the variable "size" is referenced. The cursor
1638 * referenced by the type of size is the typedef for size_type.
1639 */
1640 CXCursor_TypeRef = 43,
Ted Kremenekae9e2212010-08-27 21:34:58 +00001641 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregora23e8f72010-08-31 20:37:03 +00001642 /**
Douglas Gregorf3af3112010-09-09 21:42:20 +00001643 * \brief A reference to a class template, function template, template
1644 * template parameter, or class template partial specialization.
Douglas Gregora23e8f72010-08-31 20:37:03 +00001645 */
1646 CXCursor_TemplateRef = 45,
Douglas Gregora89314e2010-08-31 23:48:11 +00001647 /**
1648 * \brief A reference to a namespace or namespace alias.
1649 */
1650 CXCursor_NamespaceRef = 46,
Douglas Gregorf3af3112010-09-09 21:42:20 +00001651 /**
Douglas Gregora93ab662010-09-10 00:22:18 +00001652 * \brief A reference to a member of a struct, union, or class that occurs in
1653 * some non-expression context, e.g., a designated initializer.
Douglas Gregorf3af3112010-09-09 21:42:20 +00001654 */
1655 CXCursor_MemberRef = 47,
Douglas Gregora93ab662010-09-10 00:22:18 +00001656 /**
1657 * \brief A reference to a labeled statement.
1658 *
1659 * This cursor kind is used to describe the jump to "start_over" in the
1660 * goto statement in the following example:
1661 *
1662 * \code
1663 * start_over:
1664 * ++counter;
1665 *
1666 * goto start_over;
1667 * \endcode
1668 *
1669 * A label reference cursor refers to a label statement.
1670 */
1671 CXCursor_LabelRef = 48,
1672
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00001673 /**
1674 * \brief A reference to a set of overloaded functions or function templates
1675 * that has not yet been resolved to a specific function or function template.
1676 *
1677 * An overloaded declaration reference cursor occurs in C++ templates where
1678 * a dependent name refers to a function. For example:
1679 *
1680 * \code
1681 * template<typename T> void swap(T&, T&);
1682 *
1683 * struct X { ... };
1684 * void swap(X&, X&);
1685 *
1686 * template<typename T>
1687 * void reverse(T* first, T* last) {
1688 * while (first < last - 1) {
1689 * swap(*first, *--last);
1690 * ++first;
1691 * }
1692 * }
1693 *
1694 * struct Y { };
1695 * void swap(Y&, Y&);
1696 * \endcode
1697 *
1698 * Here, the identifier "swap" is associated with an overloaded declaration
1699 * reference. In the template definition, "swap" refers to either of the two
1700 * "swap" functions declared above, so both results will be available. At
1701 * instantiation time, "swap" may also refer to other functions found via
1702 * argument-dependent lookup (e.g., the "swap" function at the end of the
1703 * example).
1704 *
1705 * The functions \c clang_getNumOverloadedDecls() and
1706 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1707 * referenced by this cursor.
1708 */
1709 CXCursor_OverloadedDeclRef = 49,
1710
Douglas Gregor30093832012-02-15 00:54:55 +00001711 /**
1712 * \brief A reference to a variable that occurs in some non-expression
1713 * context, e.g., a C++ lambda capture list.
1714 */
1715 CXCursor_VariableRef = 50,
1716
1717 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001718
Douglas Gregor6007cf22010-01-22 22:29:16 +00001719 /* Error conditions */
1720 CXCursor_FirstInvalid = 70,
1721 CXCursor_InvalidFile = 70,
1722 CXCursor_NoDeclFound = 71,
1723 CXCursor_NotImplemented = 72,
Ted Kremeneke184ac52010-03-19 20:39:03 +00001724 CXCursor_InvalidCode = 73,
1725 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001726
Douglas Gregor6007cf22010-01-22 22:29:16 +00001727 /* Expressions */
1728 CXCursor_FirstExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001729
Douglas Gregor6007cf22010-01-22 22:29:16 +00001730 /**
1731 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001732 * interface.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001733 *
1734 * Unexposed expressions have the same operations as any other kind
1735 * of expression; one can extract their location information,
1736 * spelling, children, etc. However, the specific kind of the
1737 * expression is not reported.
1738 */
1739 CXCursor_UnexposedExpr = 100,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001740
Douglas Gregor6007cf22010-01-22 22:29:16 +00001741 /**
1742 * \brief An expression that refers to some value declaration, such
Nico Weber7deebef2014-04-24 03:17:47 +00001743 * as a function, variable, or enumerator.
Douglas Gregor6007cf22010-01-22 22:29:16 +00001744 */
1745 CXCursor_DeclRefExpr = 101,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001746
Douglas Gregor6007cf22010-01-22 22:29:16 +00001747 /**
1748 * \brief An expression that refers to a member of a struct, union,
1749 * class, Objective-C class, etc.
1750 */
1751 CXCursor_MemberRefExpr = 102,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001752
Douglas Gregor6007cf22010-01-22 22:29:16 +00001753 /** \brief An expression that calls a function. */
1754 CXCursor_CallExpr = 103,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001755
Douglas Gregor6007cf22010-01-22 22:29:16 +00001756 /** \brief An expression that sends a message to an Objective-C
1757 object or class. */
1758 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek33b9a422010-04-11 21:47:37 +00001759
1760 /** \brief An expression that represents a block literal. */
1761 CXCursor_BlockExpr = 105,
1762
Douglas Gregor4c362d52011-10-05 19:00:14 +00001763 /** \brief An integer literal.
1764 */
1765 CXCursor_IntegerLiteral = 106,
1766
1767 /** \brief A floating point number literal.
1768 */
1769 CXCursor_FloatingLiteral = 107,
1770
1771 /** \brief An imaginary number literal.
1772 */
1773 CXCursor_ImaginaryLiteral = 108,
1774
1775 /** \brief A string literal.
1776 */
1777 CXCursor_StringLiteral = 109,
1778
1779 /** \brief A character literal.
1780 */
1781 CXCursor_CharacterLiteral = 110,
1782
1783 /** \brief A parenthesized expression, e.g. "(1)".
1784 *
1785 * This AST node is only formed if full location information is requested.
1786 */
1787 CXCursor_ParenExpr = 111,
1788
1789 /** \brief This represents the unary-expression's (except sizeof and
1790 * alignof).
1791 */
1792 CXCursor_UnaryOperator = 112,
1793
1794 /** \brief [C99 6.5.2.1] Array Subscripting.
1795 */
1796 CXCursor_ArraySubscriptExpr = 113,
1797
1798 /** \brief A builtin binary operation expression such as "x + y" or
1799 * "x <= y".
1800 */
1801 CXCursor_BinaryOperator = 114,
1802
1803 /** \brief Compound assignment such as "+=".
1804 */
1805 CXCursor_CompoundAssignOperator = 115,
1806
1807 /** \brief The ?: ternary operator.
1808 */
1809 CXCursor_ConditionalOperator = 116,
1810
1811 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1812 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1813 *
1814 * For example: (int)f.
1815 */
1816 CXCursor_CStyleCastExpr = 117,
1817
1818 /** \brief [C99 6.5.2.5]
1819 */
1820 CXCursor_CompoundLiteralExpr = 118,
1821
1822 /** \brief Describes an C or C++ initializer list.
1823 */
1824 CXCursor_InitListExpr = 119,
1825
1826 /** \brief The GNU address of label extension, representing &&label.
1827 */
1828 CXCursor_AddrLabelExpr = 120,
1829
1830 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1831 */
1832 CXCursor_StmtExpr = 121,
1833
Benjamin Kramere56f3932011-12-23 17:00:35 +00001834 /** \brief Represents a C11 generic selection.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001835 */
1836 CXCursor_GenericSelectionExpr = 122,
1837
1838 /** \brief Implements the GNU __null extension, which is a name for a null
1839 * pointer constant that has integral type (e.g., int or long) and is the same
1840 * size and alignment as a pointer.
1841 *
1842 * The __null extension is typically only used by system headers, which define
1843 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1844 * match the size of a pointer).
1845 */
1846 CXCursor_GNUNullExpr = 123,
1847
1848 /** \brief C++'s static_cast<> expression.
1849 */
1850 CXCursor_CXXStaticCastExpr = 124,
1851
1852 /** \brief C++'s dynamic_cast<> expression.
1853 */
1854 CXCursor_CXXDynamicCastExpr = 125,
1855
1856 /** \brief C++'s reinterpret_cast<> expression.
1857 */
1858 CXCursor_CXXReinterpretCastExpr = 126,
1859
1860 /** \brief C++'s const_cast<> expression.
1861 */
1862 CXCursor_CXXConstCastExpr = 127,
1863
1864 /** \brief Represents an explicit C++ type conversion that uses "functional"
1865 * notion (C++ [expr.type.conv]).
1866 *
1867 * Example:
1868 * \code
1869 * x = int(0.5);
1870 * \endcode
1871 */
1872 CXCursor_CXXFunctionalCastExpr = 128,
1873
1874 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1875 */
1876 CXCursor_CXXTypeidExpr = 129,
1877
1878 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1879 */
1880 CXCursor_CXXBoolLiteralExpr = 130,
1881
1882 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1883 */
1884 CXCursor_CXXNullPtrLiteralExpr = 131,
1885
1886 /** \brief Represents the "this" expression in C++
1887 */
1888 CXCursor_CXXThisExpr = 132,
1889
1890 /** \brief [C++ 15] C++ Throw Expression.
1891 *
1892 * This handles 'throw' and 'throw' assignment-expression. When
1893 * assignment-expression isn't present, Op will be null.
1894 */
1895 CXCursor_CXXThrowExpr = 133,
1896
1897 /** \brief A new expression for memory allocation and constructor calls, e.g:
1898 * "new CXXNewExpr(foo)".
1899 */
1900 CXCursor_CXXNewExpr = 134,
1901
1902 /** \brief A delete expression for memory deallocation and destructor calls,
1903 * e.g. "delete[] pArray".
1904 */
1905 CXCursor_CXXDeleteExpr = 135,
1906
1907 /** \brief A unary expression.
1908 */
1909 CXCursor_UnaryExpr = 136,
1910
Douglas Gregor910c37c2011-11-11 22:35:18 +00001911 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor4c362d52011-10-05 19:00:14 +00001912 */
1913 CXCursor_ObjCStringLiteral = 137,
1914
James Dennett574cb4c2012-06-15 05:41:51 +00001915 /** \brief An Objective-C \@encode expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001916 */
1917 CXCursor_ObjCEncodeExpr = 138,
1918
James Dennett574cb4c2012-06-15 05:41:51 +00001919 /** \brief An Objective-C \@selector expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001920 */
1921 CXCursor_ObjCSelectorExpr = 139,
1922
James Dennett1355bd12012-06-11 06:19:40 +00001923 /** \brief An Objective-C \@protocol expression.
Douglas Gregor4c362d52011-10-05 19:00:14 +00001924 */
1925 CXCursor_ObjCProtocolExpr = 140,
1926
1927 /** \brief An Objective-C "bridged" cast expression, which casts between
1928 * Objective-C pointers and C pointers, transferring ownership in the process.
1929 *
1930 * \code
1931 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1932 * \endcode
1933 */
1934 CXCursor_ObjCBridgedCastExpr = 141,
1935
1936 /** \brief Represents a C++0x pack expansion that produces a sequence of
1937 * expressions.
1938 *
1939 * A pack expansion expression contains a pattern (which itself is an
1940 * expression) followed by an ellipsis. For example:
1941 *
1942 * \code
1943 * template<typename F, typename ...Types>
1944 * void forward(F f, Types &&...args) {
1945 * f(static_cast<Types&&>(args)...);
1946 * }
1947 * \endcode
1948 */
1949 CXCursor_PackExpansionExpr = 142,
1950
1951 /** \brief Represents an expression that computes the length of a parameter
1952 * pack.
1953 *
1954 * \code
1955 * template<typename ...Types>
1956 * struct count {
1957 * static const unsigned value = sizeof...(Types);
1958 * };
1959 * \endcode
1960 */
1961 CXCursor_SizeOfPackExpr = 143,
1962
Douglas Gregor30093832012-02-15 00:54:55 +00001963 /* \brief Represents a C++ lambda expression that produces a local function
1964 * object.
1965 *
1966 * \code
1967 * void abssort(float *x, unsigned N) {
1968 * std::sort(x, x + N,
1969 * [](float a, float b) {
1970 * return std::abs(a) < std::abs(b);
1971 * });
1972 * }
1973 * \endcode
1974 */
1975 CXCursor_LambdaExpr = 144,
1976
Ted Kremenek77006f62012-03-06 20:06:06 +00001977 /** \brief Objective-c Boolean Literal.
1978 */
1979 CXCursor_ObjCBoolLiteralExpr = 145,
1980
Nico Weber7deebef2014-04-24 03:17:47 +00001981 /** \brief Represents the "self" expression in an Objective-C method.
Argyrios Kyrtzidisc2233be2013-04-23 17:57:17 +00001982 */
1983 CXCursor_ObjCSelfExpr = 146,
1984
1985 CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00001986
Douglas Gregor6007cf22010-01-22 22:29:16 +00001987 /* Statements */
1988 CXCursor_FirstStmt = 200,
1989 /**
1990 * \brief A statement whose specific kind is not exposed via this
1991 * interface.
1992 *
1993 * Unexposed statements have the same operations as any other kind of
1994 * statement; one can extract their location information, spelling,
1995 * children, etc. However, the specific kind of the statement is not
1996 * reported.
1997 */
1998 CXCursor_UnexposedStmt = 200,
Douglas Gregora93ab662010-09-10 00:22:18 +00001999
2000 /** \brief A labelled statement in a function.
2001 *
2002 * This cursor kind is used to describe the "start_over:" label statement in
2003 * the following example:
2004 *
2005 * \code
2006 * start_over:
2007 * ++counter;
2008 * \endcode
2009 *
2010 */
2011 CXCursor_LabelStmt = 201,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002012
2013 /** \brief A group of statements like { stmt stmt }.
2014 *
2015 * This cursor kind is used to describe compound statements, e.g. function
2016 * bodies.
2017 */
2018 CXCursor_CompoundStmt = 202,
2019
Benjamin Kramer2501f142013-10-20 11:47:15 +00002020 /** \brief A case statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002021 */
2022 CXCursor_CaseStmt = 203,
2023
2024 /** \brief A default statement.
2025 */
2026 CXCursor_DefaultStmt = 204,
2027
2028 /** \brief An if statement
2029 */
2030 CXCursor_IfStmt = 205,
2031
2032 /** \brief A switch statement.
2033 */
2034 CXCursor_SwitchStmt = 206,
2035
2036 /** \brief A while statement.
2037 */
2038 CXCursor_WhileStmt = 207,
2039
2040 /** \brief A do statement.
2041 */
2042 CXCursor_DoStmt = 208,
2043
2044 /** \brief A for statement.
2045 */
2046 CXCursor_ForStmt = 209,
2047
2048 /** \brief A goto statement.
2049 */
2050 CXCursor_GotoStmt = 210,
2051
2052 /** \brief An indirect goto statement.
2053 */
2054 CXCursor_IndirectGotoStmt = 211,
2055
2056 /** \brief A continue statement.
2057 */
2058 CXCursor_ContinueStmt = 212,
2059
2060 /** \brief A break statement.
2061 */
2062 CXCursor_BreakStmt = 213,
2063
2064 /** \brief A return statement.
2065 */
2066 CXCursor_ReturnStmt = 214,
2067
Chad Rosierde70e0e2012-08-25 00:11:56 +00002068 /** \brief A GCC inline assembly statement extension.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002069 */
Chad Rosierde70e0e2012-08-25 00:11:56 +00002070 CXCursor_GCCAsmStmt = 215,
Argyrios Kyrtzidis5eae0732012-09-24 19:27:20 +00002071 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
Douglas Gregor4c362d52011-10-05 19:00:14 +00002072
James Dennett574cb4c2012-06-15 05:41:51 +00002073 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002074 */
2075 CXCursor_ObjCAtTryStmt = 216,
2076
James Dennett574cb4c2012-06-15 05:41:51 +00002077 /** \brief Objective-C's \@catch statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002078 */
2079 CXCursor_ObjCAtCatchStmt = 217,
2080
James Dennett574cb4c2012-06-15 05:41:51 +00002081 /** \brief Objective-C's \@finally statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002082 */
2083 CXCursor_ObjCAtFinallyStmt = 218,
2084
James Dennett574cb4c2012-06-15 05:41:51 +00002085 /** \brief Objective-C's \@throw statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002086 */
2087 CXCursor_ObjCAtThrowStmt = 219,
2088
James Dennett574cb4c2012-06-15 05:41:51 +00002089 /** \brief Objective-C's \@synchronized statement.
Douglas Gregor4c362d52011-10-05 19:00:14 +00002090 */
2091 CXCursor_ObjCAtSynchronizedStmt = 220,
2092
2093 /** \brief Objective-C's autorelease pool statement.
2094 */
2095 CXCursor_ObjCAutoreleasePoolStmt = 221,
2096
2097 /** \brief Objective-C's collection statement.
2098 */
2099 CXCursor_ObjCForCollectionStmt = 222,
2100
2101 /** \brief C++'s catch statement.
2102 */
2103 CXCursor_CXXCatchStmt = 223,
2104
2105 /** \brief C++'s try statement.
2106 */
2107 CXCursor_CXXTryStmt = 224,
2108
2109 /** \brief C++'s for (* : *) statement.
2110 */
2111 CXCursor_CXXForRangeStmt = 225,
2112
2113 /** \brief Windows Structured Exception Handling's try statement.
2114 */
2115 CXCursor_SEHTryStmt = 226,
2116
2117 /** \brief Windows Structured Exception Handling's except statement.
2118 */
2119 CXCursor_SEHExceptStmt = 227,
2120
2121 /** \brief Windows Structured Exception Handling's finally statement.
2122 */
2123 CXCursor_SEHFinallyStmt = 228,
2124
Chad Rosier32503022012-06-11 20:47:18 +00002125 /** \brief A MS inline assembly statement extension.
2126 */
2127 CXCursor_MSAsmStmt = 229,
2128
Douglas Gregor4c362d52011-10-05 19:00:14 +00002129 /** \brief The null satement ";": C99 6.8.3p3.
2130 *
2131 * This cursor kind is used to describe the null statement.
2132 */
2133 CXCursor_NullStmt = 230,
2134
2135 /** \brief Adaptor class for mixing declarations with statements and
2136 * expressions.
2137 */
2138 CXCursor_DeclStmt = 231,
2139
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002140 /** \brief OpenMP parallel directive.
2141 */
2142 CXCursor_OMPParallelDirective = 232,
2143
Alexey Bataev1b59ab52014-02-27 08:29:12 +00002144 /** \brief OpenMP simd directive.
2145 */
2146 CXCursor_OMPSimdDirective = 233,
2147
Alexey Bataevf29276e2014-06-18 04:14:57 +00002148 /** \brief OpenMP for directive.
2149 */
2150 CXCursor_OMPForDirective = 234,
2151
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002152 /** \brief OpenMP sections directive.
2153 */
2154 CXCursor_OMPSectionsDirective = 235,
2155
Alexey Bataev1e0498a2014-06-26 08:21:58 +00002156 /** \brief OpenMP section directive.
2157 */
2158 CXCursor_OMPSectionDirective = 236,
2159
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00002160 /** \brief OpenMP single directive.
2161 */
2162 CXCursor_OMPSingleDirective = 237,
2163
Alexey Bataev4acb8592014-07-07 13:01:15 +00002164 /** \brief OpenMP parallel for directive.
2165 */
2166 CXCursor_OMPParallelForDirective = 238,
2167
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002168 /** \brief OpenMP parallel sections directive.
2169 */
2170 CXCursor_OMPParallelSectionsDirective = 239,
2171
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002172 /** \brief OpenMP task directive.
2173 */
2174 CXCursor_OMPTaskDirective = 240,
2175
Alexander Musman80c22892014-07-17 08:54:58 +00002176 /** \brief OpenMP master directive.
2177 */
2178 CXCursor_OMPMasterDirective = 241,
2179
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002180 /** \brief OpenMP critical directive.
2181 */
2182 CXCursor_OMPCriticalDirective = 242,
2183
Alexey Bataev68446b72014-07-18 07:47:19 +00002184 /** \brief OpenMP taskyield directive.
2185 */
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002186 CXCursor_OMPTaskyieldDirective = 243,
Alexey Bataev68446b72014-07-18 07:47:19 +00002187
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002188 /** \brief OpenMP barrier directive.
2189 */
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002190 CXCursor_OMPBarrierDirective = 244,
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002191
Alexey Bataev2df347a2014-07-18 10:17:07 +00002192 /** \brief OpenMP taskwait directive.
2193 */
Alexander Musmand9ed09f2014-07-21 09:42:05 +00002194 CXCursor_OMPTaskwaitDirective = 245,
Alexey Bataev2df347a2014-07-18 10:17:07 +00002195
Alexey Bataev6125da92014-07-21 11:26:11 +00002196 /** \brief OpenMP flush directive.
2197 */
2198 CXCursor_OMPFlushDirective = 246,
Alexey Bataev0162e452014-07-22 10:10:35 +00002199
Reid Klecknerba764482014-07-24 18:22:15 +00002200 /** \brief Windows Structured Exception Handling's leave statement.
2201 */
2202 CXCursor_SEHLeaveStmt = 247,
2203
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002204 /** \brief OpenMP ordered directive.
2205 */
Reid Klecknerba764482014-07-24 18:22:15 +00002206 CXCursor_OMPOrderedDirective = 248,
Alexey Bataev6125da92014-07-21 11:26:11 +00002207
Alexey Bataev0162e452014-07-22 10:10:35 +00002208 /** \brief OpenMP atomic directive.
2209 */
Reid Klecknerba764482014-07-24 18:22:15 +00002210 CXCursor_OMPAtomicDirective = 249,
Alexey Bataev0162e452014-07-22 10:10:35 +00002211
Alexander Musmanf82886e2014-09-18 05:12:34 +00002212 /** \brief OpenMP for simd directive.
2213 */
2214 CXCursor_OMPForSimdDirective = 250,
2215
Alexander Musmane4e893b2014-09-23 09:33:00 +00002216 /** \brief OpenMP parallel for simd directive.
2217 */
2218 CXCursor_OMPParallelForSimdDirective = 251,
2219
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002220 /** \brief OpenMP target directive.
2221 */
Alexander Musmane4e893b2014-09-23 09:33:00 +00002222 CXCursor_OMPTargetDirective = 252,
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002223
Alexey Bataev13314bf2014-10-09 04:18:56 +00002224 /** \brief OpenMP teams directive.
2225 */
2226 CXCursor_OMPTeamsDirective = 253,
2227
2228 CXCursor_LastStmt = CXCursor_OMPTeamsDirective,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002229
Douglas Gregor6007cf22010-01-22 22:29:16 +00002230 /**
2231 * \brief Cursor that represents the translation unit itself.
2232 *
2233 * The translation unit cursor exists primarily to act as the root
2234 * cursor for traversing the contents of a translation unit.
2235 */
Ted Kremenekbff31432010-02-18 03:09:07 +00002236 CXCursor_TranslationUnit = 300,
2237
Bill Wendling44426052012-12-20 19:22:21 +00002238 /* Attributes */
Ted Kremenekbff31432010-02-18 03:09:07 +00002239 CXCursor_FirstAttr = 400,
2240 /**
2241 * \brief An attribute whose specific kind is not exposed via this
2242 * interface.
2243 */
2244 CXCursor_UnexposedAttr = 400,
2245
2246 CXCursor_IBActionAttr = 401,
2247 CXCursor_IBOutletAttr = 402,
Ted Kremenek26bde772010-05-19 17:38:06 +00002248 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis2cb4e3c2011-09-13 17:39:31 +00002249 CXCursor_CXXFinalAttr = 404,
2250 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggenca98f2a2011-10-13 09:41:32 +00002251 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002252 CXCursor_AsmLabelAttr = 407,
Argyrios Kyrtzidis16834f12013-09-25 00:14:38 +00002253 CXCursor_PackedAttr = 408,
Joey Gouly81228382014-05-01 15:41:58 +00002254 CXCursor_PureAttr = 409,
2255 CXCursor_ConstAttr = 410,
2256 CXCursor_NoDuplicateAttr = 411,
Eli Bendersky2581e662014-05-28 19:29:58 +00002257 CXCursor_CUDAConstantAttr = 412,
2258 CXCursor_CUDADeviceAttr = 413,
2259 CXCursor_CUDAGlobalAttr = 414,
2260 CXCursor_CUDAHostAttr = 415,
Eli Bendersky9b071472014-08-08 14:59:00 +00002261 CXCursor_CUDASharedAttr = 416,
2262 CXCursor_LastAttr = CXCursor_CUDASharedAttr,
Eli Bendersky2581e662014-05-28 19:29:58 +00002263
Douglas Gregor92a524f2010-03-18 00:42:48 +00002264 /* Preprocessing */
2265 CXCursor_PreprocessingDirective = 500,
Douglas Gregor06d6d322010-03-18 18:04:21 +00002266 CXCursor_MacroDefinition = 501,
Chandler Carruth9e4704a2011-07-14 08:41:15 +00002267 CXCursor_MacroExpansion = 502,
2268 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregor796d76a2010-10-20 22:00:55 +00002269 CXCursor_InclusionDirective = 503,
Douglas Gregor92a524f2010-03-18 00:42:48 +00002270 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Argyrios Kyrtzidis50e5b1d2012-10-05 00:22:24 +00002271 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2272
2273 /* Extra Declarations */
2274 /**
2275 * \brief A module import declaration.
2276 */
2277 CXCursor_ModuleImportDecl = 600,
2278 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2279 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
Douglas Gregor6007cf22010-01-22 22:29:16 +00002280};
2281
2282/**
2283 * \brief A cursor representing some element in the abstract syntax tree for
2284 * a translation unit.
2285 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002286 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregor6007cf22010-01-22 22:29:16 +00002287 * program--declaration, statements, expressions, references to declarations,
2288 * etc.--under a single "cursor" abstraction with a common set of operations.
2289 * Common operation for a cursor include: getting the physical location in
2290 * a source file where the cursor points, getting the name associated with a
2291 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2292 *
2293 * Cursors can be produced in two specific ways.
2294 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2295 * from which one can use clang_visitChildren() to explore the rest of the
2296 * translation unit. clang_getCursor() maps from a physical source location
2297 * to the entity that resides at that location, allowing one to map from the
2298 * source code into the AST.
2299 */
2300typedef struct {
2301 enum CXCursorKind kind;
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00002302 int xdata;
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +00002303 const void *data[3];
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002304} CXCursor;
Douglas Gregor6007cf22010-01-22 22:29:16 +00002305
2306/**
2307 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2308 *
2309 * @{
2310 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002311
Douglas Gregor6007cf22010-01-22 22:29:16 +00002312/**
2313 * \brief Retrieve the NULL cursor, which represents no entity.
2314 */
2315CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002316
Douglas Gregor6007cf22010-01-22 22:29:16 +00002317/**
2318 * \brief Retrieve the cursor that represents the given translation unit.
2319 *
2320 * The translation unit cursor can be used to start traversing the
2321 * various declarations within the given translation unit.
2322 */
2323CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2324
2325/**
2326 * \brief Determine whether two cursors are equivalent.
2327 */
2328CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002329
Douglas Gregor6007cf22010-01-22 22:29:16 +00002330/**
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002331 * \brief Returns non-zero if \p cursor is null.
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002332 */
Dmitri Gribenko8994e0c2012-09-13 13:11:20 +00002333CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002334
2335/**
Douglas Gregor06a3f302010-11-20 00:09:34 +00002336 * \brief Compute a hash value for the given cursor.
2337 */
2338CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2339
2340/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002341 * \brief Retrieve the kind of the given cursor.
2342 */
2343CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2344
2345/**
2346 * \brief Determine whether the given cursor kind represents a declaration.
2347 */
2348CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2349
2350/**
2351 * \brief Determine whether the given cursor kind represents a simple
2352 * reference.
2353 *
2354 * Note that other kinds of cursors (such as expressions) can also refer to
2355 * other cursors. Use clang_getCursorReferenced() to determine whether a
2356 * particular cursor refers to another entity.
2357 */
2358CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2359
2360/**
2361 * \brief Determine whether the given cursor kind represents an expression.
2362 */
2363CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2364
2365/**
2366 * \brief Determine whether the given cursor kind represents a statement.
2367 */
2368CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2369
2370/**
Douglas Gregora98034a2011-07-06 03:00:34 +00002371 * \brief Determine whether the given cursor kind represents an attribute.
2372 */
2373CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2374
2375/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002376 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregor6007cf22010-01-22 22:29:16 +00002377 * cursor.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002378 */
Douglas Gregor6007cf22010-01-22 22:29:16 +00002379CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2380
2381/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002382 * \brief Determine whether the given cursor kind represents a translation
2383 * unit.
Douglas Gregor6007cf22010-01-22 22:29:16 +00002384 */
2385CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002386
Ted Kremenekff9021b2010-03-08 21:17:29 +00002387/***
Douglas Gregor92a524f2010-03-18 00:42:48 +00002388 * \brief Determine whether the given cursor represents a preprocessing
2389 * element, such as a preprocessor directive or macro instantiation.
2390 */
2391CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2392
2393/***
Ted Kremenekff9021b2010-03-08 21:17:29 +00002394 * \brief Determine whether the given cursor represents a currently
2395 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2396 */
2397CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2398
Douglas Gregor6007cf22010-01-22 22:29:16 +00002399/**
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002400 * \brief Describe the linkage of the entity referred to by a cursor.
2401 */
2402enum CXLinkageKind {
2403 /** \brief This value indicates that no linkage information is available
2404 * for a provided CXCursor. */
2405 CXLinkage_Invalid,
2406 /**
2407 * \brief This is the linkage for variables, parameters, and so on that
2408 * have automatic storage. This covers normal (non-extern) local variables.
2409 */
2410 CXLinkage_NoLinkage,
2411 /** \brief This is the linkage for static variables and static functions. */
2412 CXLinkage_Internal,
2413 /** \brief This is the linkage for entities with external linkage that live
2414 * in C++ anonymous namespaces.*/
2415 CXLinkage_UniqueExternal,
2416 /** \brief This is the linkage for entities with true, external linkage. */
2417 CXLinkage_External
2418};
2419
2420/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002421 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenekfb4961d2010-03-03 06:36:57 +00002422 */
2423CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2424
2425/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002426 * \brief Determine the availability of the entity that this cursor refers to,
2427 * taking the current target platform into account.
Douglas Gregorf757a122010-08-23 23:00:57 +00002428 *
2429 * \param cursor The cursor to query.
2430 *
2431 * \returns The availability of the cursor.
2432 */
2433CINDEX_LINKAGE enum CXAvailabilityKind
2434clang_getCursorAvailability(CXCursor cursor);
2435
2436/**
Douglas Gregord6225d32012-05-08 00:14:45 +00002437 * Describes the availability of a given entity on a particular platform, e.g.,
2438 * a particular class might only be available on Mac OS 10.7 or newer.
2439 */
2440typedef struct CXPlatformAvailability {
2441 /**
2442 * \brief A string that describes the platform for which this structure
2443 * provides availability information.
2444 *
2445 * Possible values are "ios" or "macosx".
2446 */
2447 CXString Platform;
2448 /**
2449 * \brief The version number in which this entity was introduced.
2450 */
2451 CXVersion Introduced;
2452 /**
2453 * \brief The version number in which this entity was deprecated (but is
2454 * still available).
2455 */
2456 CXVersion Deprecated;
2457 /**
2458 * \brief The version number in which this entity was obsoleted, and therefore
2459 * is no longer available.
2460 */
2461 CXVersion Obsoleted;
2462 /**
2463 * \brief Whether the entity is unconditionally unavailable on this platform.
2464 */
2465 int Unavailable;
2466 /**
2467 * \brief An optional message to provide to a user of this API, e.g., to
2468 * suggest replacement APIs.
2469 */
2470 CXString Message;
2471} CXPlatformAvailability;
2472
2473/**
2474 * \brief Determine the availability of the entity that this cursor refers to
2475 * on any platforms for which availability information is known.
2476 *
2477 * \param cursor The cursor to query.
2478 *
2479 * \param always_deprecated If non-NULL, will be set to indicate whether the
2480 * entity is deprecated on all platforms.
2481 *
2482 * \param deprecated_message If non-NULL, will be set to the message text
2483 * provided along with the unconditional deprecation of this entity. The client
2484 * is responsible for deallocating this string.
2485 *
James Dennett574cb4c2012-06-15 05:41:51 +00002486 * \param always_unavailable If non-NULL, will be set to indicate whether the
Douglas Gregord6225d32012-05-08 00:14:45 +00002487 * entity is unavailable on all platforms.
2488 *
2489 * \param unavailable_message If non-NULL, will be set to the message text
2490 * provided along with the unconditional unavailability of this entity. The
2491 * client is responsible for deallocating this string.
2492 *
2493 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2494 * that will be populated with platform availability information, up to either
2495 * the number of platforms for which availability information is available (as
2496 * returned by this function) or \c availability_size, whichever is smaller.
2497 *
2498 * \param availability_size The number of elements available in the
2499 * \c availability array.
2500 *
2501 * \returns The number of platforms (N) for which availability information is
2502 * available (which is unrelated to \c availability_size).
2503 *
2504 * Note that the client is responsible for calling
2505 * \c clang_disposeCXPlatformAvailability to free each of the
2506 * platform-availability structures returned. There are
2507 * \c min(N, availability_size) such structures.
2508 */
2509CINDEX_LINKAGE int
2510clang_getCursorPlatformAvailability(CXCursor cursor,
2511 int *always_deprecated,
2512 CXString *deprecated_message,
2513 int *always_unavailable,
2514 CXString *unavailable_message,
2515 CXPlatformAvailability *availability,
2516 int availability_size);
2517
2518/**
2519 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2520 */
2521CINDEX_LINKAGE void
2522clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2523
2524/**
Ted Kremenek4ed29252010-04-12 21:22:16 +00002525 * \brief Describe the "language" of the entity referred to by a cursor.
2526 */
Reid Kleckner9e3bc722013-12-30 17:48:49 +00002527enum CXLanguageKind {
Ted Kremenekee457512010-04-14 20:58:32 +00002528 CXLanguage_Invalid = 0,
Ted Kremenek4ed29252010-04-12 21:22:16 +00002529 CXLanguage_C,
2530 CXLanguage_ObjC,
Ted Kremenekee457512010-04-14 20:58:32 +00002531 CXLanguage_CPlusPlus
Ted Kremenek4ed29252010-04-12 21:22:16 +00002532};
2533
2534/**
2535 * \brief Determine the "language" of the entity referred to by a given cursor.
2536 */
2537CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2538
Argyrios Kyrtzidisd6e9fa52011-09-27 00:30:30 +00002539/**
2540 * \brief Returns the translation unit that a cursor originated from.
2541 */
2542CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2543
Ted Kremenekc0b98662013-04-24 07:17:12 +00002544
2545/**
2546 * \brief A fast container representing a set of CXCursors.
2547 */
2548typedef struct CXCursorSetImpl *CXCursorSet;
2549
2550/**
2551 * \brief Creates an empty CXCursorSet.
2552 */
2553CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2554
2555/**
2556 * \brief Disposes a CXCursorSet and releases its associated memory.
2557 */
2558CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2559
2560/**
2561 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2562 *
2563 * \returns non-zero if the set contains the specified cursor.
2564*/
2565CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2566 CXCursor cursor);
2567
2568/**
2569 * \brief Inserts a CXCursor into a CXCursorSet.
2570 *
2571 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2572*/
2573CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2574 CXCursor cursor);
2575
Douglas Gregor0576ce72010-09-22 21:22:29 +00002576/**
2577 * \brief Determine the semantic parent of the given cursor.
2578 *
2579 * The semantic parent of a cursor is the cursor that semantically contains
2580 * the given \p cursor. For many declarations, the lexical and semantic parents
2581 * are equivalent (the lexical parent is returned by
2582 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2583 * definitions are provided out-of-line. For example:
2584 *
2585 * \code
2586 * class C {
2587 * void f();
2588 * };
2589 *
2590 * void C::f() { }
2591 * \endcode
2592 *
Nico Weber7deebef2014-04-24 03:17:47 +00002593 * In the out-of-line definition of \c C::f, the semantic parent is
Douglas Gregor0576ce72010-09-22 21:22:29 +00002594 * the class \c C, of which this function is a member. The lexical parent is
2595 * the place where the declaration actually occurs in the source code; in this
Nico Weber7deebef2014-04-24 03:17:47 +00002596 * case, the definition occurs in the translation unit. In general, the
Douglas Gregor0576ce72010-09-22 21:22:29 +00002597 * lexical parent for a given entity can change without affecting the semantics
2598 * of the program, and the lexical parent of different declarations of the
2599 * same entity may be different. Changing the semantic parent of a declaration,
2600 * on the other hand, can have a major impact on semantics, and redeclarations
2601 * of a particular entity should all have the same semantic context.
2602 *
2603 * In the example above, both declarations of \c C::f have \c C as their
2604 * semantic context, while the lexical context of the first \c C::f is \c C
2605 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002606 *
2607 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002608 */
2609CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2610
2611/**
2612 * \brief Determine the lexical parent of the given cursor.
2613 *
2614 * The lexical parent of a cursor is the cursor in which the given \p cursor
2615 * was actually written. For many declarations, the lexical and semantic parents
2616 * are equivalent (the semantic parent is returned by
2617 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2618 * definitions are provided out-of-line. For example:
2619 *
2620 * \code
2621 * class C {
2622 * void f();
2623 * };
2624 *
2625 * void C::f() { }
2626 * \endcode
2627 *
Nico Weber7deebef2014-04-24 03:17:47 +00002628 * In the out-of-line definition of \c C::f, the semantic parent is
Douglas Gregor0576ce72010-09-22 21:22:29 +00002629 * the class \c C, of which this function is a member. The lexical parent is
2630 * the place where the declaration actually occurs in the source code; in this
Nico Weber7deebef2014-04-24 03:17:47 +00002631 * case, the definition occurs in the translation unit. In general, the
Douglas Gregor0576ce72010-09-22 21:22:29 +00002632 * lexical parent for a given entity can change without affecting the semantics
2633 * of the program, and the lexical parent of different declarations of the
2634 * same entity may be different. Changing the semantic parent of a declaration,
2635 * on the other hand, can have a major impact on semantics, and redeclarations
2636 * of a particular entity should all have the same semantic context.
2637 *
2638 * In the example above, both declarations of \c C::f have \c C as their
2639 * semantic context, while the lexical context of the first \c C::f is \c C
2640 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor7ecd19e2010-12-21 07:55:45 +00002641 *
2642 * For declarations written in the global scope, the lexical parent is
2643 * the translation unit.
Douglas Gregor0576ce72010-09-22 21:22:29 +00002644 */
2645CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor99a26af2010-10-01 20:25:15 +00002646
2647/**
2648 * \brief Determine the set of methods that are overridden by the given
2649 * method.
2650 *
2651 * In both Objective-C and C++, a method (aka virtual member function,
2652 * in C++) can override a virtual method in a base class. For
2653 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidisbfb24252012-03-08 00:20:03 +00002654 * base class, its protocols, or its categories' protocols, that has the same
2655 * selector and is of the same kind (class or instance).
2656 * If no such method exists, the search continues to the class's superclass,
2657 * its protocols, and its categories, and so on. A method from an Objective-C
2658 * implementation is considered to override the same methods as its
2659 * corresponding method in the interface.
Douglas Gregor99a26af2010-10-01 20:25:15 +00002660 *
2661 * For C++, a virtual member function overrides any virtual member
2662 * function with the same signature that occurs in its base
2663 * classes. With multiple inheritance, a virtual member function can
2664 * override several virtual member functions coming from different
2665 * base classes.
2666 *
2667 * In all cases, this function determines the immediate overridden
2668 * method, rather than all of the overridden methods. For example, if
2669 * a method is originally declared in a class A, then overridden in B
2670 * (which in inherits from A) and also in C (which inherited from B),
2671 * then the only overridden method returned from this function when
2672 * invoked on C's method will be B's method. The client may then
2673 * invoke this function again, given the previously-found overridden
2674 * methods, to map out the complete method-override set.
2675 *
2676 * \param cursor A cursor representing an Objective-C or C++
2677 * method. This routine will compute the set of methods that this
2678 * method overrides.
2679 *
2680 * \param overridden A pointer whose pointee will be replaced with a
2681 * pointer to an array of cursors, representing the set of overridden
2682 * methods. If there are no overridden methods, the pointee will be
2683 * set to NULL. The pointee must be freed via a call to
2684 * \c clang_disposeOverriddenCursors().
2685 *
2686 * \param num_overridden A pointer to the number of overridden
2687 * functions, will be set to the number of overridden functions in the
2688 * array pointed to by \p overridden.
2689 */
2690CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2691 CXCursor **overridden,
2692 unsigned *num_overridden);
2693
2694/**
2695 * \brief Free the set of overridden cursors returned by \c
2696 * clang_getOverriddenCursors().
2697 */
2698CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2699
Ted Kremenek4ed29252010-04-12 21:22:16 +00002700/**
Douglas Gregor796d76a2010-10-20 22:00:55 +00002701 * \brief Retrieve the file that is included by the given inclusion directive
2702 * cursor.
2703 */
2704CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2705
2706/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00002707 * @}
2708 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002709
Douglas Gregor6007cf22010-01-22 22:29:16 +00002710/**
2711 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2712 *
2713 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2714 * routines help map between cursors and the physical locations where the
2715 * described entities occur in the source code. The mapping is provided in
2716 * both directions, so one can map from source code to the AST and back.
2717 *
2718 * @{
Steve Naroffa1c72842009-08-28 15:28:48 +00002719 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002720
Steve Naroff20bad0b2009-10-21 13:56:23 +00002721/**
Douglas Gregor816fd362010-01-22 21:44:22 +00002722 * \brief Map a source location to the cursor that describes the entity at that
2723 * location in the source code.
2724 *
2725 * clang_getCursor() maps an arbitrary source location within a translation
2726 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002727 * location. For example, given an expression \c x + y, invoking
Douglas Gregor816fd362010-01-22 21:44:22 +00002728 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002729 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregor816fd362010-01-22 21:44:22 +00002730 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2731 * will return a cursor referring to the "+" expression.
2732 *
2733 * \returns a cursor representing the entity at the given source location, or
2734 * a NULL cursor if no such entity can be found.
Steve Naroff20bad0b2009-10-21 13:56:23 +00002735 */
Douglas Gregor816fd362010-01-22 21:44:22 +00002736CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002737
Douglas Gregor66a58812010-01-18 22:46:11 +00002738/**
2739 * \brief Retrieve the physical location of the source constructor referenced
2740 * by the given cursor.
2741 *
2742 * The location of a declaration is typically the location of the name of that
Daniel Dunbar62ebf252010-01-24 02:54:26 +00002743 * declaration, where the name of that declaration would occur if it is
2744 * unnamed, or some keyword that introduces that particular declaration.
2745 * The location of a reference is where that reference occurs within the
Douglas Gregor66a58812010-01-18 22:46:11 +00002746 * source code.
2747 */
2748CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregor6007cf22010-01-22 22:29:16 +00002749
Douglas Gregor6b8232f2010-01-19 19:34:47 +00002750/**
2751 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002752 * the given cursor.
2753 *
2754 * The extent of a cursor starts with the file/line/column pointing at the
2755 * first character within the source construct that the cursor refers to and
Nico Weber7deebef2014-04-24 03:17:47 +00002756 * ends with the last character within that source construct. For a
Douglas Gregor33c34ac2010-01-19 00:34:46 +00002757 * declaration, the extent covers the declaration itself. For a reference,
2758 * the extent covers the location of the reference (e.g., where the referenced
2759 * entity was actually used).
2760 */
2761CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorad27e8b2010-01-19 01:20:04 +00002762
Douglas Gregor6007cf22010-01-22 22:29:16 +00002763/**
2764 * @}
2765 */
Ted Kremeneka5940822010-08-26 01:42:22 +00002766
Douglas Gregor6007cf22010-01-22 22:29:16 +00002767/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002768 * \defgroup CINDEX_TYPES Type information for CXCursors
2769 *
2770 * @{
2771 */
2772
2773/**
2774 * \brief Describes the kind of type
2775 */
2776enum CXTypeKind {
2777 /**
Nico Weber7deebef2014-04-24 03:17:47 +00002778 * \brief Represents an invalid type (e.g., where no type is available).
Ted Kremenek6bca9842010-05-14 21:29:26 +00002779 */
2780 CXType_Invalid = 0,
2781
2782 /**
2783 * \brief A type whose specific kind is not exposed via this
2784 * interface.
2785 */
2786 CXType_Unexposed = 1,
2787
2788 /* Builtin types */
2789 CXType_Void = 2,
2790 CXType_Bool = 3,
2791 CXType_Char_U = 4,
2792 CXType_UChar = 5,
2793 CXType_Char16 = 6,
2794 CXType_Char32 = 7,
2795 CXType_UShort = 8,
2796 CXType_UInt = 9,
2797 CXType_ULong = 10,
2798 CXType_ULongLong = 11,
2799 CXType_UInt128 = 12,
2800 CXType_Char_S = 13,
2801 CXType_SChar = 14,
2802 CXType_WChar = 15,
2803 CXType_Short = 16,
2804 CXType_Int = 17,
2805 CXType_Long = 18,
2806 CXType_LongLong = 19,
2807 CXType_Int128 = 20,
2808 CXType_Float = 21,
2809 CXType_Double = 22,
2810 CXType_LongDouble = 23,
2811 CXType_NullPtr = 24,
2812 CXType_Overload = 25,
2813 CXType_Dependent = 26,
2814 CXType_ObjCId = 27,
2815 CXType_ObjCClass = 28,
2816 CXType_ObjCSel = 29,
2817 CXType_FirstBuiltin = CXType_Void,
2818 CXType_LastBuiltin = CXType_ObjCSel,
2819
2820 CXType_Complex = 100,
2821 CXType_Pointer = 101,
2822 CXType_BlockPointer = 102,
2823 CXType_LValueReference = 103,
2824 CXType_RValueReference = 104,
2825 CXType_Record = 105,
2826 CXType_Enum = 106,
2827 CXType_Typedef = 107,
2828 CXType_ObjCInterface = 108,
Ted Kremenekc1508872010-06-21 20:15:39 +00002829 CXType_ObjCObjectPointer = 109,
2830 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00002831 CXType_FunctionProto = 111,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002832 CXType_ConstantArray = 112,
Argyrios Kyrtzidis0661a712013-07-23 17:36:21 +00002833 CXType_Vector = 113,
2834 CXType_IncompleteArray = 114,
2835 CXType_VariableArray = 115,
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00002836 CXType_DependentSizedArray = 116,
2837 CXType_MemberPointer = 117
Ted Kremenek6bca9842010-05-14 21:29:26 +00002838};
2839
2840/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002841 * \brief Describes the calling convention of a function type
2842 */
2843enum CXCallingConv {
2844 CXCallingConv_Default = 0,
2845 CXCallingConv_C = 1,
2846 CXCallingConv_X86StdCall = 2,
2847 CXCallingConv_X86FastCall = 3,
2848 CXCallingConv_X86ThisCall = 4,
2849 CXCallingConv_X86Pascal = 5,
2850 CXCallingConv_AAPCS = 6,
2851 CXCallingConv_AAPCS_VFP = 7,
Derek Schuffa2020962012-10-16 22:30:41 +00002852 CXCallingConv_PnaclCall = 8,
Guy Benyeif0a014b2012-12-25 08:53:55 +00002853 CXCallingConv_IntelOclBicc = 9,
Charles Davisb5a214e2013-08-30 04:39:01 +00002854 CXCallingConv_X86_64Win64 = 10,
2855 CXCallingConv_X86_64SysV = 11,
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002856
2857 CXCallingConv_Invalid = 100,
2858 CXCallingConv_Unexposed = 200
2859};
2860
2861
2862/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00002863 * \brief The type of an element in the abstract syntax tree.
2864 *
2865 */
2866typedef struct {
2867 enum CXTypeKind kind;
2868 void *data[2];
2869} CXType;
2870
2871/**
2872 * \brief Retrieve the type of a CXCursor (if any).
2873 */
2874CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2875
2876/**
Dmitri Gribenko00353722013-02-15 21:15:49 +00002877 * \brief Pretty-print the underlying type using the rules of the
2878 * language of the translation unit from which it came.
2879 *
2880 * If the type is invalid, an empty string is returned.
2881 */
2882CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
2883
2884/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00002885 * \brief Retrieve the underlying type of a typedef declaration.
2886 *
2887 * If the cursor does not reference a typedef declaration, an invalid type is
2888 * returned.
2889 */
2890CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2891
2892/**
2893 * \brief Retrieve the integer type of an enum declaration.
2894 *
2895 * If the cursor does not reference an enum declaration, an invalid type is
2896 * returned.
2897 */
2898CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2899
2900/**
2901 * \brief Retrieve the integer value of an enum constant declaration as a signed
2902 * long long.
2903 *
2904 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2905 * Since this is also potentially a valid constant value, the kind of the cursor
2906 * must be verified before calling this function.
2907 */
2908CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2909
2910/**
2911 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2912 * long long.
2913 *
2914 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2915 * Since this is also potentially a valid constant value, the kind of the cursor
2916 * must be verified before calling this function.
2917 */
2918CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2919
2920/**
Dmitri Gribenkob506ba12012-12-04 15:13:46 +00002921 * \brief Retrieve the bit width of a bit field declaration as an integer.
2922 *
2923 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
2924 */
2925CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
2926
2927/**
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002928 * \brief Retrieve the number of non-variadic arguments associated with a given
2929 * cursor.
2930 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002931 * The number of arguments can be determined for calls as well as for
2932 * declarations of functions or methods. For other cursors -1 is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002933 */
2934CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2935
2936/**
2937 * \brief Retrieve the argument cursor of a function or method.
2938 *
Argyrios Kyrtzidisb2792972013-04-01 17:38:59 +00002939 * The argument cursor can be determined for calls as well as for declarations
2940 * of functions or methods. For other cursors and for invalid indices, an
2941 * invalid cursor is returned.
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00002942 */
2943CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2944
2945/**
Eli Benderskyc27a0c42014-10-10 20:01:05 +00002946 * \brief Describes the kind of a template argument.
2947 *
2948 * See the definition of llvm::clang::TemplateArgument::ArgKind for full
2949 * element descriptions.
2950 */
2951enum CXTemplateArgumentKind {
2952 CXTemplateArgumentKind_Null,
2953 CXTemplateArgumentKind_Type,
2954 CXTemplateArgumentKind_Declaration,
2955 CXTemplateArgumentKind_NullPtr,
2956 CXTemplateArgumentKind_Integral,
2957 CXTemplateArgumentKind_Template,
2958 CXTemplateArgumentKind_TemplateExpansion,
2959 CXTemplateArgumentKind_Expression,
2960 CXTemplateArgumentKind_Pack,
2961 /* Indicates an error case, preventing the kind from being deduced. */
2962 CXTemplateArgumentKind_Invalid
2963};
2964
2965/**
2966 *\brief Returns the number of template args of a function decl representing a
2967 * template specialization.
2968 *
2969 * If the argument cursor cannot be converted into a template function
2970 * declaration, -1 is returned.
2971 *
2972 * For example, for the following declaration and specialization:
2973 * template <typename T, int kInt, bool kBool>
2974 * void foo() { ... }
2975 *
2976 * template <>
2977 * void foo<float, -7, true>();
2978 *
2979 * The value 3 would be returned from this call.
2980 */
2981CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C);
2982
2983/**
2984 * \brief Retrieve the kind of the I'th template argument of the CXCursor C.
2985 *
2986 * If the argument CXCursor does not represent a FunctionDecl, an invalid
2987 * template argument kind is returned.
2988 *
2989 * For example, for the following declaration and specialization:
2990 * template <typename T, int kInt, bool kBool>
2991 * void foo() { ... }
2992 *
2993 * template <>
2994 * void foo<float, -7, true>();
2995 *
2996 * For I = 0, 1, and 2, Type, Integral, and Integral will be returned,
2997 * respectively.
2998 */
2999CINDEX_LINKAGE enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(
3000 CXCursor C, unsigned I);
3001
3002/**
3003 * \brief Retrieve a CXType representing the type of a TemplateArgument of a
3004 * function decl representing a template specialization.
3005 *
3006 * If the argument CXCursor does not represent a FunctionDecl whose I'th
3007 * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
3008 * is returned.
3009 *
3010 * For example, for the following declaration and specialization:
3011 * template <typename T, int kInt, bool kBool>
3012 * void foo() { ... }
3013 *
3014 * template <>
3015 * void foo<float, -7, true>();
3016 *
3017 * If called with I = 0, "float", will be returned.
3018 * Invalid types will be returned for I == 1 or 2.
3019 */
3020CINDEX_LINKAGE CXType clang_Cursor_getTemplateArgumentType(CXCursor C,
3021 unsigned I);
3022
3023/**
3024 * \brief Retrieve the value of an Integral TemplateArgument (of a function
3025 * decl representing a template specialization) as a signed long long.
3026 *
3027 * It is undefined to call this function on a CXCursor that does not represent a
3028 * FunctionDecl or whose I'th template argument is not an integral value.
3029 *
3030 * For example, for the following declaration and specialization:
3031 * template <typename T, int kInt, bool kBool>
3032 * void foo() { ... }
3033 *
3034 * template <>
3035 * void foo<float, -7, true>();
3036 *
3037 * If called with I = 1 or 2, -7 or true will be returned, respectively.
3038 * For I == 0, this function's behavior is undefined.
3039 */
3040CINDEX_LINKAGE long long clang_Cursor_getTemplateArgumentValue(CXCursor C,
3041 unsigned I);
3042
3043/**
3044 * \brief Retrieve the value of an Integral TemplateArgument (of a function
3045 * decl representing a template specialization) as an unsigned long long.
3046 *
3047 * It is undefined to call this function on a CXCursor that does not represent a
3048 * FunctionDecl or whose I'th template argument is not an integral value.
3049 *
3050 * For example, for the following declaration and specialization:
3051 * template <typename T, int kInt, bool kBool>
3052 * void foo() { ... }
3053 *
3054 * template <>
3055 * void foo<float, 2147483649, true>();
3056 *
3057 * If called with I = 1 or 2, 2147483649 or true will be returned, respectively.
3058 * For I == 0, this function's behavior is undefined.
3059 */
3060CINDEX_LINKAGE unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue(
3061 CXCursor C, unsigned I);
3062
3063/**
James Dennett574cb4c2012-06-15 05:41:51 +00003064 * \brief Determine whether two CXTypes represent the same type.
Ted Kremenek6bca9842010-05-14 21:29:26 +00003065 *
James Dennett574cb4c2012-06-15 05:41:51 +00003066 * \returns non-zero if the CXTypes represent the same type and
3067 * zero otherwise.
Ted Kremenek6bca9842010-05-14 21:29:26 +00003068 */
3069CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
3070
3071/**
3072 * \brief Return the canonical type for a CXType.
3073 *
3074 * Clang's type system explicitly models typedefs and all the ways
3075 * a specific type can be represented. The canonical type is the underlying
3076 * type with all the "sugar" removed. For example, if 'T' is a typedef
3077 * for 'int', the canonical type for 'T' would be 'int'.
3078 */
3079CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
3080
3081/**
James Dennett574cb4c2012-06-15 05:41:51 +00003082 * \brief Determine whether a CXType has the "const" qualifier set,
3083 * without looking through typedefs that may have added "const" at a
3084 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00003085 */
3086CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
3087
3088/**
James Dennett574cb4c2012-06-15 05:41:51 +00003089 * \brief Determine whether a CXType has the "volatile" qualifier set,
3090 * without looking through typedefs that may have added "volatile" at
3091 * a different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00003092 */
3093CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
3094
3095/**
James Dennett574cb4c2012-06-15 05:41:51 +00003096 * \brief Determine whether a CXType has the "restrict" qualifier set,
3097 * without looking through typedefs that may have added "restrict" at a
3098 * different level.
Douglas Gregor56a63802011-01-27 16:27:11 +00003099 */
3100CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
3101
3102/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00003103 * \brief For pointer types, returns the type of the pointee.
Ted Kremenek6bca9842010-05-14 21:29:26 +00003104 */
3105CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
3106
3107/**
3108 * \brief Return the cursor for the declaration of the given type.
3109 */
3110CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
3111
David Chisnall50e4eba2010-12-30 14:05:53 +00003112/**
3113 * Returns the Objective-C type encoding for the specified declaration.
3114 */
3115CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek6bca9842010-05-14 21:29:26 +00003116
3117/**
3118 * \brief Retrieve the spelling of a given CXTypeKind.
3119 */
3120CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
3121
3122/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003123 * \brief Retrieve the calling convention associated with a function type.
3124 *
3125 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
3126 */
3127CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
3128
3129/**
Alp Toker314cc812014-01-25 16:55:45 +00003130 * \brief Retrieve the return type associated with a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003131 *
3132 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenekc1508872010-06-21 20:15:39 +00003133 */
3134CINDEX_LINKAGE CXType clang_getResultType(CXType T);
3135
3136/**
Alp Toker601b22c2014-01-21 23:35:24 +00003137 * \brief Retrieve the number of non-variadic parameters associated with a
James Dennett574cb4c2012-06-15 05:41:51 +00003138 * function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003139 *
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00003140 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003141 */
Argyrios Kyrtzidis0c27e4b2012-04-11 19:32:19 +00003142CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003143
3144/**
Alp Toker601b22c2014-01-21 23:35:24 +00003145 * \brief Retrieve the type of a parameter of a function type.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003146 *
James Dennett574cb4c2012-06-15 05:41:51 +00003147 * If a non-function type is passed in or the function does not have enough
3148 * parameters, an invalid type is returned.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003149 */
3150CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
3151
3152/**
3153 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003154 */
3155CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
3156
3157/**
Alp Toker314cc812014-01-25 16:55:45 +00003158 * \brief Retrieve the return type associated with a given cursor.
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003159 *
3160 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenekc62ab8d2010-06-21 20:48:56 +00003161 */
3162CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
3163
3164/**
Ted Kremenek0c7476a2010-07-30 00:14:11 +00003165 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
3166 * otherwise.
3167 */
3168CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
3169
3170/**
Argyrios Kyrtzidis66f433a2011-12-06 22:05:01 +00003171 * \brief Return the element type of an array, complex, or vector type.
3172 *
3173 * If a type is passed in that is not an array, complex, or vector type,
3174 * an invalid type is returned.
3175 */
3176CINDEX_LINKAGE CXType clang_getElementType(CXType T);
3177
3178/**
3179 * \brief Return the number of elements of an array or vector type.
3180 *
3181 * If a type is passed in that is not an array or vector type,
3182 * -1 is returned.
3183 */
3184CINDEX_LINKAGE long long clang_getNumElements(CXType T);
3185
3186/**
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00003187 * \brief Return the element type of an array type.
3188 *
3189 * If a non-array type is passed in, an invalid type is returned.
3190 */
3191CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
3192
3193/**
Sylvestre Ledru830885c2012-07-23 08:59:39 +00003194 * \brief Return the array size of a constant array.
Argyrios Kyrtzidis2b0cf602011-09-27 17:44:34 +00003195 *
3196 * If a non-array type is passed in, -1 is returned.
3197 */
3198CINDEX_LINKAGE long long clang_getArraySize(CXType T);
3199
3200/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003201 * \brief List the possible error codes for \c clang_Type_getSizeOf,
3202 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
3203 * \c clang_Cursor_getOffsetOf.
3204 *
3205 * A value of this enumeration type can be returned if the target type is not
3206 * a valid argument to sizeof, alignof or offsetof.
3207 */
3208enum CXTypeLayoutError {
3209 /**
3210 * \brief Type is of kind CXType_Invalid.
3211 */
3212 CXTypeLayoutError_Invalid = -1,
3213 /**
3214 * \brief The type is an incomplete Type.
3215 */
3216 CXTypeLayoutError_Incomplete = -2,
3217 /**
3218 * \brief The type is a dependent Type.
3219 */
3220 CXTypeLayoutError_Dependent = -3,
3221 /**
3222 * \brief The type is not a constant size type.
3223 */
3224 CXTypeLayoutError_NotConstantSize = -4,
3225 /**
3226 * \brief The Field name is not valid for this record.
3227 */
3228 CXTypeLayoutError_InvalidFieldName = -5
3229};
3230
3231/**
3232 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
3233 * standard.
3234 *
3235 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3236 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3237 * is returned.
3238 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3239 * returned.
3240 * If the type declaration is not a constant size type,
3241 * CXTypeLayoutError_NotConstantSize is returned.
3242 */
3243CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
3244
3245/**
Argyrios Kyrtzidis7a4253b2013-10-03 16:19:23 +00003246 * \brief Return the class type of an member pointer type.
3247 *
3248 * If a non-member-pointer type is passed in, an invalid type is returned.
3249 */
3250CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T);
3251
3252/**
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003253 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
3254 *
3255 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3256 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3257 * is returned.
3258 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3259 * returned.
3260 */
3261CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
3262
3263/**
3264 * \brief Return the offset of a field named S in a record of type T in bits
3265 * as it would be returned by __offsetof__ as per C++11[18.2p4]
3266 *
3267 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
3268 * is returned.
3269 * If the field's type declaration is an incomplete type,
3270 * CXTypeLayoutError_Incomplete is returned.
3271 * If the field's type declaration is a dependent type,
3272 * CXTypeLayoutError_Dependent is returned.
3273 * If the field's name S is not found,
3274 * CXTypeLayoutError_InvalidFieldName is returned.
3275 */
3276CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
3277
Argyrios Kyrtzidisadff3ae2013-10-11 19:58:38 +00003278enum CXRefQualifierKind {
3279 /** \brief No ref-qualifier was provided. */
3280 CXRefQualifier_None = 0,
3281 /** \brief An lvalue ref-qualifier was provided (\c &). */
3282 CXRefQualifier_LValue,
3283 /** \brief An rvalue ref-qualifier was provided (\c &&). */
3284 CXRefQualifier_RValue
3285};
3286
3287/**
Dmitri Gribenko6ede6ab2014-02-27 16:05:05 +00003288 * \brief Returns the number of template arguments for given class template
3289 * specialization, or -1 if type \c T is not a class template specialization.
3290 *
3291 * Variadic argument packs count as only one argument, and can not be inspected
3292 * further.
3293 */
3294CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T);
3295
3296/**
3297 * \brief Returns the type template argument of a template class specialization
3298 * at given index.
3299 *
3300 * This function only returns template type arguments and does not handle
3301 * template template arguments or variadic packs.
3302 */
3303CINDEX_LINKAGE CXType clang_Type_getTemplateArgumentAsType(CXType T, unsigned i);
3304
3305/**
Argyrios Kyrtzidisadff3ae2013-10-11 19:58:38 +00003306 * \brief Retrieve the ref-qualifier kind of a function or method.
3307 *
3308 * The ref-qualifier is returned for C++ functions or methods. For other types
3309 * or non-C++ declarations, CXRefQualifier_None is returned.
3310 */
3311CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
3312
Argyrios Kyrtzidise822f582013-04-11 01:20:11 +00003313/**
3314 * \brief Returns non-zero if the cursor specifies a Record member that is a
3315 * bitfield.
3316 */
3317CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
3318
3319/**
Ted Kremenekae9e2212010-08-27 21:34:58 +00003320 * \brief Returns 1 if the base class specified by the cursor with kind
3321 * CX_CXXBaseSpecifier is virtual.
3322 */
3323CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3324
3325/**
3326 * \brief Represents the C++ access control level to a base class for a
3327 * cursor with kind CX_CXXBaseSpecifier.
3328 */
3329enum CX_CXXAccessSpecifier {
3330 CX_CXXInvalidAccessSpecifier,
3331 CX_CXXPublic,
3332 CX_CXXProtected,
3333 CX_CXXPrivate
3334};
3335
3336/**
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003337 * \brief Returns the access control level for the referenced object.
Argyrios Kyrtzidisf6464082013-04-11 17:31:13 +00003338 *
Argyrios Kyrtzidis1ab09cc2013-04-11 17:02:10 +00003339 * If the cursor refers to a C++ declaration, its access control level within its
3340 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3341 * access specifier, the specifier itself is returned.
Ted Kremenekae9e2212010-08-27 21:34:58 +00003342 */
3343CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3344
3345/**
Argyrios Kyrtzidis4e0854f2014-10-15 17:05:31 +00003346 * \brief Represents the storage classes as declared in the source. CX_SC_Invalid
3347 * was added for the clase that the passed cursor in not a declaration.
3348 */
3349enum CX_StorageClass {
3350 CX_SC_Invalid,
3351 CX_SC_None,
3352 CX_SC_Extern,
3353 CX_SC_Static,
3354 CX_SC_PrivateExtern,
3355 CX_SC_OpenCLWorkGroupLocal,
3356 CX_SC_Auto,
3357 CX_SC_Register
3358};
3359
3360/**
3361 * \brief Returns the storage class for a function or variable declaration.
3362 *
3363 * If the passed in Cursor is not a function or variable declaration,
3364 * CX_SC_Invalid is returned else the storage class.
3365 */
3366CINDEX_LINKAGE enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor);
3367
3368/**
Douglas Gregor16a2bdd2010-09-13 22:52:57 +00003369 * \brief Determine the number of overloaded declarations referenced by a
3370 * \c CXCursor_OverloadedDeclRef cursor.
3371 *
3372 * \param cursor The cursor whose overloaded declarations are being queried.
3373 *
3374 * \returns The number of overloaded declarations referenced by \c cursor. If it
3375 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3376 */
3377CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3378
3379/**
3380 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3381 * by a \c CXCursor_OverloadedDeclRef cursor.
3382 *
3383 * \param cursor The cursor whose overloaded declarations are being queried.
3384 *
3385 * \param index The zero-based index into the set of overloaded declarations in
3386 * the cursor.
3387 *
3388 * \returns A cursor representing the declaration referenced by the given
3389 * \c cursor at the specified \c index. If the cursor does not have an
3390 * associated set of overloaded declarations, or if the index is out of bounds,
3391 * returns \c clang_getNullCursor();
3392 */
3393CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3394 unsigned index);
3395
3396/**
Ted Kremenek6bca9842010-05-14 21:29:26 +00003397 * @}
3398 */
Ted Kremeneka5940822010-08-26 01:42:22 +00003399
3400/**
Ted Kremenek2c2c5f32010-08-27 21:34:51 +00003401 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremeneka5940822010-08-26 01:42:22 +00003402 *
3403 * @{
3404 */
3405
3406
3407/**
3408 * \brief For cursors representing an iboutletcollection attribute,
3409 * this function returns the collection element type.
3410 *
3411 */
3412CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3413
3414/**
3415 * @}
3416 */
Ted Kremenek6bca9842010-05-14 21:29:26 +00003417
3418/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003419 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3420 *
3421 * These routines provide the ability to traverse the abstract syntax tree
3422 * using cursors.
3423 *
3424 * @{
3425 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003426
Douglas Gregor6007cf22010-01-22 22:29:16 +00003427/**
3428 * \brief Describes how the traversal of the children of a particular
3429 * cursor should proceed after visiting a particular child cursor.
3430 *
3431 * A value of this enumeration type should be returned by each
3432 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3433 */
3434enum CXChildVisitResult {
3435 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003436 * \brief Terminates the cursor traversal.
Douglas Gregor6007cf22010-01-22 22:29:16 +00003437 */
3438 CXChildVisit_Break,
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003439 /**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003440 * \brief Continues the cursor traversal with the next sibling of
3441 * the cursor just visited, without visiting its children.
3442 */
3443 CXChildVisit_Continue,
3444 /**
3445 * \brief Recursively traverse the children of this cursor, using
3446 * the same visitor and client data.
3447 */
3448 CXChildVisit_Recurse
3449};
3450
3451/**
3452 * \brief Visitor invoked for each cursor found by a traversal.
3453 *
3454 * This visitor function will be invoked for each cursor found by
3455 * clang_visitCursorChildren(). Its first argument is the cursor being
3456 * visited, its second argument is the parent visitor for that cursor,
3457 * and its third argument is the client data provided to
3458 * clang_visitCursorChildren().
3459 *
3460 * The visitor should return one of the \c CXChildVisitResult values
3461 * to direct clang_visitCursorChildren().
3462 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003463typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3464 CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003465 CXClientData client_data);
3466
3467/**
3468 * \brief Visit the children of a particular cursor.
3469 *
3470 * This function visits all the direct children of the given cursor,
3471 * invoking the given \p visitor function with the cursors of each
3472 * visited child. The traversal may be recursive, if the visitor returns
3473 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3474 * the visitor returns \c CXChildVisit_Break.
3475 *
Douglas Gregor6007cf22010-01-22 22:29:16 +00003476 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbarb9999fd2010-01-24 04:10:31 +00003477 * cursors can be visited, including invalid cursors (which, by
Douglas Gregor6007cf22010-01-22 22:29:16 +00003478 * definition, have no children).
3479 *
3480 * \param visitor the visitor function that will be invoked for each
3481 * child of \p parent.
3482 *
3483 * \param client_data pointer data supplied by the client, which will
3484 * be passed to the visitor each time it is invoked.
3485 *
3486 * \returns a non-zero value if the traversal was terminated
3487 * prematurely by the visitor returning \c CXChildVisit_Break.
3488 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003489CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregor6007cf22010-01-22 22:29:16 +00003490 CXCursorVisitor visitor,
3491 CXClientData client_data);
David Chisnallb2aa0ef2010-11-03 14:12:26 +00003492#ifdef __has_feature
3493# if __has_feature(blocks)
3494/**
3495 * \brief Visitor invoked for each cursor found by a traversal.
3496 *
3497 * This visitor block will be invoked for each cursor found by
3498 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3499 * visited, its second argument is the parent visitor for that cursor.
3500 *
3501 * The visitor should return one of the \c CXChildVisitResult values
3502 * to direct clang_visitChildrenWithBlock().
3503 */
3504typedef enum CXChildVisitResult
3505 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3506
3507/**
3508 * Visits the children of a cursor using the specified block. Behaves
3509 * identically to clang_visitChildren() in all other respects.
3510 */
3511unsigned clang_visitChildrenWithBlock(CXCursor parent,
3512 CXCursorVisitorBlock block);
3513# endif
3514#endif
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003515
Douglas Gregor6007cf22010-01-22 22:29:16 +00003516/**
3517 * @}
3518 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003519
Douglas Gregor6007cf22010-01-22 22:29:16 +00003520/**
3521 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3522 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003523 * These routines provide the ability to determine references within and
Douglas Gregor6007cf22010-01-22 22:29:16 +00003524 * across translation units, by providing the names of the entities referenced
3525 * by cursors, follow reference cursors to the declarations they reference,
3526 * and associate declarations with their definitions.
3527 *
3528 * @{
3529 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003530
Douglas Gregor6007cf22010-01-22 22:29:16 +00003531/**
3532 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3533 * by the given cursor.
3534 *
3535 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3536 * entity (function, class, variable, etc.) within a program. USRs can be
3537 * compared across translation units to determine, e.g., when references in
3538 * one translation refer to an entity defined in another translation unit.
3539 */
3540CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3541
3542/**
Ted Kremenekd071c602010-03-13 02:50:34 +00003543 * \brief Construct a USR for a specified Objective-C class.
3544 */
3545CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3546
3547/**
3548 * \brief Construct a USR for a specified Objective-C category.
3549 */
3550CINDEX_LINKAGE CXString
Ted Kremenekbc1a67b2010-03-15 17:38:58 +00003551 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenekd071c602010-03-13 02:50:34 +00003552 const char *category_name);
3553
3554/**
3555 * \brief Construct a USR for a specified Objective-C protocol.
3556 */
3557CINDEX_LINKAGE CXString
3558 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3559
3560
3561/**
3562 * \brief Construct a USR for a specified Objective-C instance variable and
3563 * the USR for its containing class.
3564 */
3565CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3566 CXString classUSR);
3567
3568/**
3569 * \brief Construct a USR for a specified Objective-C method and
3570 * the USR for its containing class.
3571 */
3572CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3573 unsigned isInstanceMethod,
3574 CXString classUSR);
3575
3576/**
3577 * \brief Construct a USR for a specified Objective-C property and the USR
3578 * for its containing class.
3579 */
3580CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3581 CXString classUSR);
3582
3583/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00003584 * \brief Retrieve a name for the entity referenced by this cursor.
3585 */
3586CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3587
Douglas Gregor97c75712010-10-02 22:49:11 +00003588/**
Argyrios Kyrtzidis191a6a82012-03-30 20:58:35 +00003589 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3590 * Most of the times there is only one range for the complete spelling but for
Nico Weber7deebef2014-04-24 03:17:47 +00003591 * Objective-C methods and Objective-C message expressions, there are multiple
3592 * pieces for each selector identifier.
Argyrios Kyrtzidis191a6a82012-03-30 20:58:35 +00003593 *
3594 * \param pieceIndex the index of the spelling name piece. If this is greater
3595 * than the actual number of pieces, it will return a NULL (invalid) range.
3596 *
3597 * \param options Reserved.
3598 */
3599CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3600 unsigned pieceIndex,
3601 unsigned options);
3602
3603/**
Douglas Gregor97c75712010-10-02 22:49:11 +00003604 * \brief Retrieve the display name for the entity referenced by this cursor.
3605 *
3606 * The display name contains extra information that helps identify the cursor,
3607 * such as the parameters of a function or template or the arguments of a
3608 * class template specialization.
3609 */
3610CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3611
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003612/** \brief For a cursor that is a reference, retrieve a cursor representing the
3613 * entity that it references.
3614 *
3615 * Reference cursors refer to other entities in the AST. For example, an
3616 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003617 * This function produces the cursor for the Objective-C class from the
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003618 * cursor for the superclass reference. If the input cursor is a declaration or
3619 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003620 * Otherwise, returns the NULL cursor.
Douglas Gregorad27e8b2010-01-19 01:20:04 +00003621 */
3622CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003623
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003624/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003625 * \brief For a cursor that is either a reference to or a declaration
3626 * of some entity, retrieve a cursor that describes the definition of
3627 * that entity.
3628 *
3629 * Some entities can be declared multiple times within a translation
3630 * unit, but only one of those declarations can also be a
3631 * definition. For example, given:
3632 *
3633 * \code
3634 * int f(int, int);
3635 * int g(int x, int y) { return f(x, y); }
3636 * int f(int a, int b) { return a + b; }
3637 * int f(int, int);
3638 * \endcode
3639 *
3640 * there are three declarations of the function "f", but only the
3641 * second one is a definition. The clang_getCursorDefinition()
3642 * function will take any cursor pointing to a declaration of "f"
3643 * (the first or fourth lines of the example) or a cursor referenced
3644 * that uses "f" (the call to "f' inside "g") and will return a
3645 * declaration cursor pointing to the definition (the second "f"
3646 * declaration).
3647 *
3648 * If given a cursor for which there is no corresponding definition,
3649 * e.g., because there is no definition of that entity within this
3650 * translation unit, returns a NULL cursor.
3651 */
3652CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3653
Daniel Dunbar62ebf252010-01-24 02:54:26 +00003654/**
Douglas Gregor6b8232f2010-01-19 19:34:47 +00003655 * \brief Determine whether the declaration pointed to by this cursor
3656 * is also a definition of that entity.
3657 */
3658CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3659
Douglas Gregor6007cf22010-01-22 22:29:16 +00003660/**
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003661 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3662 *
3663 * In the C family of languages, many kinds of entities can be declared several
3664 * times within a single translation unit. For example, a structure type can
3665 * be forward-declared (possibly multiple times) and later defined:
3666 *
3667 * \code
3668 * struct X;
3669 * struct X;
3670 * struct X {
3671 * int member;
3672 * };
3673 * \endcode
3674 *
3675 * The declarations and the definition of \c X are represented by three
3676 * different cursors, all of which are declarations of the same underlying
3677 * entity. One of these cursor is considered the "canonical" cursor, which
3678 * is effectively the representative for the underlying entity. One can
3679 * determine if two cursors are declarations of the same underlying entity by
3680 * comparing their canonical cursors.
3681 *
3682 * \returns The canonical cursor for the entity referred to by the given cursor.
3683 */
3684CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3685
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003686
3687/**
Nico Weber7deebef2014-04-24 03:17:47 +00003688 * \brief If the cursor points to a selector identifier in an Objective-C
3689 * method or message expression, this returns the selector index.
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003690 *
James Dennett574cb4c2012-06-15 05:41:51 +00003691 * After getting a cursor with #clang_getCursor, this can be called to
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003692 * determine if the location points to a selector identifier.
3693 *
Nico Weber7deebef2014-04-24 03:17:47 +00003694 * \returns The selector index if the cursor is an Objective-C method or message
Argyrios Kyrtzidis210f29f2012-03-30 22:15:48 +00003695 * expression and the cursor is pointing to a selector identifier, or -1
3696 * otherwise.
3697 */
3698CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3699
Douglas Gregorfec4dc92010-11-19 23:44:15 +00003700/**
Nico Weber7deebef2014-04-24 03:17:47 +00003701 * \brief Given a cursor pointing to a C++ method call or an Objective-C
3702 * message, returns non-zero if the method/message is "dynamic", meaning:
Argyrios Kyrtzidisb6df68212012-07-02 23:54:36 +00003703 *
3704 * For a C++ method: the call is virtual.
Nico Weber7deebef2014-04-24 03:17:47 +00003705 * For an Objective-C message: the receiver is an object instance, not 'super'
3706 * or a specific class.
Argyrios Kyrtzidisb6df68212012-07-02 23:54:36 +00003707 *
3708 * If the method/message is "static" or the cursor does not point to a
3709 * method/message, it will return zero.
3710 */
3711CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3712
3713/**
Nico Weber7deebef2014-04-24 03:17:47 +00003714 * \brief Given a cursor pointing to an Objective-C message, returns the CXType
3715 * of the receiver.
Argyrios Kyrtzidisb26a24c2012-11-01 02:01:34 +00003716 */
3717CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3718
3719/**
Argyrios Kyrtzidis9adfd8a2013-04-18 22:15:49 +00003720 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
3721 */
3722typedef enum {
3723 CXObjCPropertyAttr_noattr = 0x00,
3724 CXObjCPropertyAttr_readonly = 0x01,
3725 CXObjCPropertyAttr_getter = 0x02,
3726 CXObjCPropertyAttr_assign = 0x04,
3727 CXObjCPropertyAttr_readwrite = 0x08,
3728 CXObjCPropertyAttr_retain = 0x10,
3729 CXObjCPropertyAttr_copy = 0x20,
3730 CXObjCPropertyAttr_nonatomic = 0x40,
3731 CXObjCPropertyAttr_setter = 0x80,
3732 CXObjCPropertyAttr_atomic = 0x100,
3733 CXObjCPropertyAttr_weak = 0x200,
3734 CXObjCPropertyAttr_strong = 0x400,
3735 CXObjCPropertyAttr_unsafe_unretained = 0x800
3736} CXObjCPropertyAttrKind;
3737
3738/**
3739 * \brief Given a cursor that represents a property declaration, return the
3740 * associated property attributes. The bits are formed from
3741 * \c CXObjCPropertyAttrKind.
3742 *
3743 * \param reserved Reserved for future use, pass 0.
3744 */
3745CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
3746 unsigned reserved);
3747
3748/**
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003749 * \brief 'Qualifiers' written next to the return and parameter types in
Nico Weber7deebef2014-04-24 03:17:47 +00003750 * Objective-C method declarations.
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003751 */
3752typedef enum {
3753 CXObjCDeclQualifier_None = 0x0,
3754 CXObjCDeclQualifier_In = 0x1,
3755 CXObjCDeclQualifier_Inout = 0x2,
3756 CXObjCDeclQualifier_Out = 0x4,
3757 CXObjCDeclQualifier_Bycopy = 0x8,
3758 CXObjCDeclQualifier_Byref = 0x10,
3759 CXObjCDeclQualifier_Oneway = 0x20
3760} CXObjCDeclQualifierKind;
3761
3762/**
Nico Weber7deebef2014-04-24 03:17:47 +00003763 * \brief Given a cursor that represents an Objective-C method or parameter
3764 * declaration, return the associated Objective-C qualifiers for the return
3765 * type or the parameter respectively. The bits are formed from
3766 * CXObjCDeclQualifierKind.
Argyrios Kyrtzidis9d9bc012013-04-18 23:29:12 +00003767 */
3768CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
3769
3770/**
Nico Weber7deebef2014-04-24 03:17:47 +00003771 * \brief Given a cursor that represents an Objective-C method or property
3772 * declaration, return non-zero if the declaration was affected by "@optional".
Argyrios Kyrtzidis7b50fc52013-07-05 20:44:37 +00003773 * Returns zero if the cursor is not such a declaration or it is "@required".
3774 */
3775CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
3776
3777/**
Argyrios Kyrtzidis23814e42013-04-18 23:53:05 +00003778 * \brief Returns non-zero if the given cursor is a variadic function or method.
3779 */
3780CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
3781
3782/**
Dmitri Gribenkoaab83832012-06-20 00:34:58 +00003783 * \brief Given a cursor that represents a declaration, return the associated
3784 * comment's source range. The range may include multiple consecutive comments
3785 * with whitespace in between.
3786 */
3787CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3788
3789/**
3790 * \brief Given a cursor that represents a declaration, return the associated
3791 * comment text, including comment markers.
3792 */
3793CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3794
3795/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003796 * \brief Given a cursor that represents a documentable entity (e.g.,
3797 * declaration), return the associated \\brief paragraph; otherwise return the
3798 * first paragraph.
Dmitri Gribenko5188c4b2012-06-26 20:39:18 +00003799 */
3800CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3801
3802/**
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003803 * @}
3804 */
3805
Eli Bendersky44a206f2014-07-31 18:04:56 +00003806/** \defgroup CINDEX_MANGLE Name Mangling API Functions
3807 *
3808 * @{
3809 */
3810
3811/**
3812 * \brief Retrieve the CXString representing the mangled name of the cursor.
3813 */
3814CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor);
3815
3816/**
3817 * @}
3818 */
3819
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00003820/**
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003821 * \defgroup CINDEX_MODULE Module introspection
3822 *
3823 * The functions in this group provide access to information about modules.
3824 *
3825 * @{
3826 */
3827
3828typedef void *CXModule;
3829
3830/**
3831 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3832 */
3833CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3834
3835/**
Argyrios Kyrtzidisf6d49c32014-05-14 23:14:37 +00003836 * \brief Given a CXFile header file, return the module that contains it, if one
3837 * exists.
3838 */
3839CINDEX_LINKAGE CXModule clang_getModuleForFile(CXTranslationUnit, CXFile);
3840
3841/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003842 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003843 *
Argyrios Kyrtzidis12fdb9e2013-04-26 22:47:49 +00003844 * \returns the module file where the provided module object came from.
3845 */
3846CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3847
3848/**
3849 * \param Module a module object.
3850 *
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003851 * \returns the parent of a sub-module or NULL if the given module is top-level,
3852 * e.g. for 'std.vector' it will return the 'std' module.
3853 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003854CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003855
3856/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003857 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003858 *
3859 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3860 * will return "vector".
3861 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003862CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003863
3864/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003865 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003866 *
3867 * \returns the full name of the module, e.g. "std.vector".
3868 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003869CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003870
3871/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003872 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003873 *
Argyrios Kyrtzidis884337f2014-05-15 04:44:25 +00003874 * \returns non-zero if the module is a system one.
3875 */
3876CINDEX_LINKAGE int clang_Module_isSystem(CXModule Module);
3877
3878/**
3879 * \param Module a module object.
3880 *
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003881 * \returns the number of top level headers associated with this module.
3882 */
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003883CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
3884 CXModule Module);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003885
3886/**
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003887 * \param Module a module object.
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003888 *
3889 * \param Index top level header index (zero-based).
3890 *
3891 * \returns the specified top level header associated with the module.
3892 */
Argyrios Kyrtzidisba30d922012-10-06 01:18:38 +00003893CINDEX_LINKAGE
Argyrios Kyrtzidis3c5305c2013-03-13 21:13:43 +00003894CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
3895 CXModule Module, unsigned Index);
Argyrios Kyrtzidis2b9b5bb2012-10-05 00:22:37 +00003896
3897/**
3898 * @}
3899 */
3900
3901/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00003902 * \defgroup CINDEX_CPP C++ AST introspection
3903 *
3904 * The routines in this group provide access information in the ASTs specific
3905 * to C++ language features.
3906 *
3907 * @{
3908 */
3909
3910/**
Dmitri Gribenko62770be2013-05-17 18:38:35 +00003911 * \brief Determine if a C++ member function or member function template is
3912 * pure virtual.
3913 */
3914CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
3915
3916/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00003917 * \brief Determine if a C++ member function or member function template is
3918 * declared 'static'.
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00003919 */
3920CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3921
3922/**
Douglas Gregor9519d922011-05-12 15:17:24 +00003923 * \brief Determine if a C++ member function or member function template is
3924 * explicitly declared 'virtual' or if it overrides a virtual method from
3925 * one of the base classes.
3926 */
3927CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3928
3929/**
Dmitri Gribenkoe570ede2014-04-07 14:59:13 +00003930 * \brief Determine if a C++ member function or member function template is
3931 * declared 'const'.
3932 */
3933CINDEX_LINKAGE unsigned clang_CXXMethod_isConst(CXCursor C);
3934
3935/**
Douglas Gregorf11309e2010-08-31 22:12:17 +00003936 * \brief Given a cursor that represents a template, determine
3937 * the cursor kind of the specializations would be generated by instantiating
3938 * the template.
3939 *
3940 * This routine can be used to determine what flavor of function template,
3941 * class template, or class template partial specialization is stored in the
3942 * cursor. For example, it can describe whether a class template cursor is
3943 * declared with "struct", "class" or "union".
3944 *
3945 * \param C The cursor to query. This cursor should represent a template
3946 * declaration.
3947 *
3948 * \returns The cursor kind of the specializations that would be generated
3949 * by instantiating the template \p C. If \p C is not a template, returns
3950 * \c CXCursor_NoDeclFound.
3951 */
3952CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3953
3954/**
Douglas Gregord3f48bd2010-09-02 00:07:54 +00003955 * \brief Given a cursor that may represent a specialization or instantiation
3956 * of a template, retrieve the cursor that represents the template that it
3957 * specializes or from which it was instantiated.
3958 *
3959 * This routine determines the template involved both for explicit
3960 * specializations of templates and for implicit instantiations of the template,
3961 * both of which are referred to as "specializations". For a class template
3962 * specialization (e.g., \c std::vector<bool>), this routine will return
3963 * either the primary template (\c std::vector) or, if the specialization was
3964 * instantiated from a class template partial specialization, the class template
3965 * partial specialization. For a class template partial specialization and a
3966 * function template specialization (including instantiations), this
3967 * this routine will return the specialized template.
3968 *
3969 * For members of a class template (e.g., member functions, member classes, or
3970 * static data members), returns the specialized or instantiated member.
3971 * Although not strictly "templates" in the C++ language, members of class
3972 * templates have the same notions of specializations and instantiations that
3973 * templates do, so this routine treats them similarly.
3974 *
3975 * \param C A cursor that may be a specialization of a template or a member
3976 * of a template.
3977 *
3978 * \returns If the given cursor is a specialization or instantiation of a
3979 * template or a member thereof, the template or member that it specializes or
3980 * from which it was instantiated. Otherwise, returns a NULL cursor.
3981 */
3982CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregorc1679ec2011-07-25 17:48:11 +00003983
3984/**
3985 * \brief Given a cursor that references something else, return the source range
3986 * covering that reference.
3987 *
3988 * \param C A cursor pointing to a member reference, a declaration reference, or
3989 * an operator call.
3990 * \param NameFlags A bitset with three independent flags:
3991 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3992 * CXNameRange_WantSinglePiece.
3993 * \param PieceIndex For contiguous names or when passing the flag
3994 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3995 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
Benjamin Kramer474261a2012-06-02 10:20:41 +00003996 * non-contiguous names, this index can be used to retrieve the individual
Douglas Gregorc1679ec2011-07-25 17:48:11 +00003997 * pieces of the name. See also CXNameRange_WantSinglePiece.
3998 *
3999 * \returns The piece of the name pointed to by the given cursor. If there is no
4000 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4001 */
Francois Pichetece689f2011-07-25 22:00:44 +00004002CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4003 unsigned NameFlags,
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004004 unsigned PieceIndex);
4005
4006enum CXNameRefFlags {
4007 /**
4008 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4009 * range.
4010 */
4011 CXNameRange_WantQualifier = 0x1,
4012
4013 /**
James Dennett574cb4c2012-06-15 05:41:51 +00004014 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4015 * in the range.
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004016 */
4017 CXNameRange_WantTemplateArgs = 0x2,
4018
4019 /**
4020 * \brief If the name is non-contiguous, return the full spanning range.
4021 *
4022 * Non-contiguous names occur in Objective-C when a selector with two or more
4023 * parameters is used, or in C++ when using an operator:
4024 * \code
Nico Weber7deebef2014-04-24 03:17:47 +00004025 * [object doSomething:here withValue:there]; // Objective-C
Douglas Gregorc1679ec2011-07-25 17:48:11 +00004026 * return some_vector[1]; // C++
4027 * \endcode
4028 */
4029 CXNameRange_WantSinglePiece = 0x4
4030};
Douglas Gregord3f48bd2010-09-02 00:07:54 +00004031
4032/**
Ted Kremenek9cfe9e62010-05-17 20:06:56 +00004033 * @}
4034 */
4035
4036/**
Douglas Gregor61656112010-01-26 18:31:56 +00004037 * \defgroup CINDEX_LEX Token extraction and manipulation
4038 *
4039 * The routines in this group provide access to the tokens within a
4040 * translation unit, along with a semantic mapping of those tokens to
4041 * their corresponding cursors.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004042 *
4043 * @{
4044 */
4045
4046/**
4047 * \brief Describes a kind of token.
4048 */
4049typedef enum CXTokenKind {
4050 /**
4051 * \brief A token that contains some kind of punctuation.
4052 */
4053 CXToken_Punctuation,
Ted Kremenekd071c602010-03-13 02:50:34 +00004054
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004055 /**
Douglas Gregor61656112010-01-26 18:31:56 +00004056 * \brief A language keyword.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004057 */
4058 CXToken_Keyword,
Ted Kremenekd071c602010-03-13 02:50:34 +00004059
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004060 /**
4061 * \brief An identifier (that is not a keyword).
4062 */
4063 CXToken_Identifier,
Ted Kremenekd071c602010-03-13 02:50:34 +00004064
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004065 /**
4066 * \brief A numeric, string, or character literal.
4067 */
4068 CXToken_Literal,
Ted Kremenekd071c602010-03-13 02:50:34 +00004069
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004070 /**
4071 * \brief A comment.
4072 */
4073 CXToken_Comment
4074} CXTokenKind;
4075
4076/**
4077 * \brief Describes a single preprocessing token.
4078 */
4079typedef struct {
4080 unsigned int_data[4];
4081 void *ptr_data;
4082} CXToken;
4083
4084/**
4085 * \brief Determine the kind of the given token.
4086 */
4087CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004088
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004089/**
4090 * \brief Determine the spelling of the given token.
4091 *
4092 * The spelling of a token is the textual representation of that token, e.g.,
4093 * the text of an identifier or keyword.
4094 */
4095CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004096
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004097/**
4098 * \brief Retrieve the source location of the given token.
4099 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004100CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004101 CXToken);
Ted Kremenekd071c602010-03-13 02:50:34 +00004102
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004103/**
4104 * \brief Retrieve a source range that covers the given token.
4105 */
4106CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4107
4108/**
4109 * \brief Tokenize the source code described by the given range into raw
4110 * lexical tokens.
4111 *
4112 * \param TU the translation unit whose text is being tokenized.
4113 *
4114 * \param Range the source range in which text should be tokenized. All of the
4115 * tokens produced by tokenization will fall within this source range,
4116 *
4117 * \param Tokens this pointer will be set to point to the array of tokens
4118 * that occur within the given source range. The returned pointer must be
4119 * freed with clang_disposeTokens() before the translation unit is destroyed.
4120 *
4121 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4122 * array.
4123 *
4124 */
4125CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4126 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004127
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004128/**
4129 * \brief Annotate the given set of tokens by providing cursors for each token
4130 * that can be mapped to a specific entity within the abstract syntax tree.
4131 *
Douglas Gregor61656112010-01-26 18:31:56 +00004132 * This token-annotation routine is equivalent to invoking
4133 * clang_getCursor() for the source locations of each of the
4134 * tokens. The cursors provided are filtered, so that only those
4135 * cursors that have a direct correspondence to the token are
4136 * accepted. For example, given a function call \c f(x),
4137 * clang_getCursor() would provide the following cursors:
4138 *
4139 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4140 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4141 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4142 *
4143 * Only the first and last of these cursors will occur within the
4144 * annotate, since the tokens "f" and "x' directly refer to a function
4145 * and a variable, respectively, but the parentheses are just a small
4146 * part of the full syntax of the function call expression, which is
4147 * not provided as an annotation.
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004148 *
4149 * \param TU the translation unit that owns the given tokens.
4150 *
4151 * \param Tokens the set of tokens to annotate.
4152 *
4153 * \param NumTokens the number of tokens in \p Tokens.
4154 *
4155 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4156 * replaced with the cursors corresponding to each token.
4157 */
4158CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4159 CXToken *Tokens, unsigned NumTokens,
4160 CXCursor *Cursors);
Ted Kremenekd071c602010-03-13 02:50:34 +00004161
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004162/**
4163 * \brief Free the given set of tokens.
4164 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004165CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004166 CXToken *Tokens, unsigned NumTokens);
Ted Kremenekd071c602010-03-13 02:50:34 +00004167
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004168/**
4169 * @}
4170 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004171
Douglas Gregor27b4fa92010-01-26 17:06:03 +00004172/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004173 * \defgroup CINDEX_DEBUG Debugging facilities
4174 *
4175 * These routines are used for testing and debugging, only, and should not
4176 * be relied upon.
4177 *
4178 * @{
4179 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004180
Steve Naroff76b8f132009-09-23 17:52:52 +00004181/* for debug/testing */
Ted Kremenek29004672010-02-17 00:41:32 +00004182CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004183CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4184 const char **startBuf,
Steve Naroff76b8f132009-09-23 17:52:52 +00004185 const char **endBuf,
4186 unsigned *startLine,
4187 unsigned *startColumn,
4188 unsigned *endLine,
4189 unsigned *endColumn);
Douglas Gregor1e21cc72010-02-18 23:07:20 +00004190CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar23420652010-11-04 01:26:29 +00004191CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4192 unsigned stack_size);
4193
Douglas Gregor9eb77012009-11-07 00:00:49 +00004194/**
Douglas Gregor6007cf22010-01-22 22:29:16 +00004195 * @}
4196 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004197
Douglas Gregor6007cf22010-01-22 22:29:16 +00004198/**
4199 * \defgroup CINDEX_CODE_COMPLET Code completion
4200 *
4201 * Code completion involves taking an (incomplete) source file, along with
4202 * knowledge of where the user is actively editing that file, and suggesting
4203 * syntactically- and semantically-valid constructs that the user might want to
4204 * use at that particular point in the source code. These data structures and
4205 * routines provide support for code completion.
4206 *
4207 * @{
4208 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004209
Douglas Gregor6007cf22010-01-22 22:29:16 +00004210/**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004211 * \brief A semantic string that describes a code-completion result.
4212 *
4213 * A semantic string that describes the formatting of a code-completion
4214 * result as a single "template" of text that should be inserted into the
4215 * source buffer when a particular code-completion result is selected.
4216 * Each semantic string is made up of some number of "chunks", each of which
4217 * contains some text along with a description of what that text means, e.g.,
4218 * the name of the entity being referenced, whether the text chunk is part of
4219 * the template, or whether it is a "placeholder" that the user should replace
4220 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004221 * description of the different kinds of chunks.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004222 */
4223typedef void *CXCompletionString;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004224
Douglas Gregor9eb77012009-11-07 00:00:49 +00004225/**
4226 * \brief A single result of code completion.
4227 */
4228typedef struct {
4229 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004230 * \brief The kind of entity that this completion refers to.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004231 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004232 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor9eb77012009-11-07 00:00:49 +00004233 * *Decl cursor kinds), describing the entity that the completion is
4234 * referring to.
4235 *
4236 * \todo In the future, we would like to provide a full cursor, to allow
4237 * the client to extract additional information from declaration.
4238 */
4239 enum CXCursorKind CursorKind;
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004240
4241 /**
Douglas Gregor9eb77012009-11-07 00:00:49 +00004242 * \brief The code-completion string that describes how to insert this
4243 * code-completion result into the editing buffer.
4244 */
4245 CXCompletionString CompletionString;
4246} CXCompletionResult;
4247
4248/**
4249 * \brief Describes a single piece of text within a code-completion string.
4250 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004251 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4252 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor9eb77012009-11-07 00:00:49 +00004253 * should be interpreted by the client or is another completion string.
4254 */
4255enum CXCompletionChunkKind {
4256 /**
4257 * \brief A code-completion string that describes "optional" text that
4258 * could be a part of the template (but is not required).
4259 *
4260 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004261 * string for its representation, which is accessible via
Douglas Gregor9eb77012009-11-07 00:00:49 +00004262 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4263 * describes an additional part of the template that is completely optional.
4264 * For example, optional chunks can be used to describe the placeholders for
4265 * arguments that match up with defaulted function parameters, e.g. given:
4266 *
4267 * \code
4268 * void f(int x, float y = 3.14, double z = 2.71828);
4269 * \endcode
4270 *
4271 * The code-completion string for this function would contain:
4272 * - a TypedText chunk for "f".
4273 * - a LeftParen chunk for "(".
4274 * - a Placeholder chunk for "int x"
4275 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4276 * - a Comma chunk for ","
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004277 * - a Placeholder chunk for "float y"
Douglas Gregor9eb77012009-11-07 00:00:49 +00004278 * - an Optional chunk containing the last defaulted argument:
4279 * - a Comma chunk for ","
4280 * - a Placeholder chunk for "double z"
4281 * - a RightParen chunk for ")"
4282 *
Daniel Dunbar4053fae2010-02-17 08:07:44 +00004283 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor9eb77012009-11-07 00:00:49 +00004284 * - Completely ignore optional chunks, in which case the template for the
4285 * function "f" would only include the first parameter ("int x").
4286 * - Fully expand all optional chunks, in which case the template for the
4287 * function "f" would have all of the parameters.
4288 */
4289 CXCompletionChunk_Optional,
4290 /**
4291 * \brief Text that a user would be expected to type to get this
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004292 * code-completion result.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004293 *
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004294 * There will be exactly one "typed text" chunk in a semantic string, which
4295 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004296 * declaration that could be used at the current code point. Clients are
4297 * expected to filter the code-completion results based on the text in this
4298 * chunk.
4299 */
4300 CXCompletionChunk_TypedText,
4301 /**
4302 * \brief Text that should be inserted as part of a code-completion result.
4303 *
4304 * A "text" chunk represents text that is part of the template to be
4305 * inserted into user code should this particular code-completion result
4306 * be selected.
4307 */
4308 CXCompletionChunk_Text,
4309 /**
4310 * \brief Placeholder text that should be replaced by the user.
4311 *
4312 * A "placeholder" chunk marks a place where the user should insert text
4313 * into the code-completion template. For example, placeholders might mark
4314 * the function parameters for a function declaration, to indicate that the
4315 * user should provide arguments for each of those parameters. The actual
4316 * text in a placeholder is a suggestion for the text to display before
4317 * the user replaces the placeholder with real code.
4318 */
4319 CXCompletionChunk_Placeholder,
4320 /**
4321 * \brief Informative text that should be displayed but never inserted as
4322 * part of the template.
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004323 *
Douglas Gregor9eb77012009-11-07 00:00:49 +00004324 * An "informative" chunk contains annotations that can be displayed to
4325 * help the user decide whether a particular code-completion result is the
4326 * right option, but which is not part of the actual template to be inserted
4327 * by code completion.
4328 */
4329 CXCompletionChunk_Informative,
4330 /**
4331 * \brief Text that describes the current parameter when code-completion is
4332 * referring to function call, message send, or template specialization.
4333 *
4334 * A "current parameter" chunk occurs when code-completion is providing
4335 * information about a parameter corresponding to the argument at the
4336 * code-completion point. For example, given a function
4337 *
4338 * \code
4339 * int add(int x, int y);
4340 * \endcode
4341 *
4342 * and the source code \c add(, where the code-completion point is after the
4343 * "(", the code-completion string will contain a "current parameter" chunk
4344 * for "int x", indicating that the current argument will initialize that
4345 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004346 * point is after the ","), the code-completion string will contain a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004347 * "current paremeter" chunk to "int y".
4348 */
4349 CXCompletionChunk_CurrentParameter,
4350 /**
4351 * \brief A left parenthesis ('('), used to initiate a function call or
4352 * signal the beginning of a function parameter list.
4353 */
4354 CXCompletionChunk_LeftParen,
4355 /**
4356 * \brief A right parenthesis (')'), used to finish a function call or
4357 * signal the end of a function parameter list.
4358 */
4359 CXCompletionChunk_RightParen,
4360 /**
4361 * \brief A left bracket ('[').
4362 */
4363 CXCompletionChunk_LeftBracket,
4364 /**
4365 * \brief A right bracket (']').
4366 */
4367 CXCompletionChunk_RightBracket,
4368 /**
4369 * \brief A left brace ('{').
4370 */
4371 CXCompletionChunk_LeftBrace,
4372 /**
4373 * \brief A right brace ('}').
4374 */
4375 CXCompletionChunk_RightBrace,
4376 /**
4377 * \brief A left angle bracket ('<').
4378 */
4379 CXCompletionChunk_LeftAngle,
4380 /**
4381 * \brief A right angle bracket ('>').
4382 */
4383 CXCompletionChunk_RightAngle,
4384 /**
4385 * \brief A comma separator (',').
4386 */
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004387 CXCompletionChunk_Comma,
4388 /**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004389 * \brief Text that specifies the result type of a given result.
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004390 *
4391 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004392 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorb3fa9192009-12-18 18:53:37 +00004393 * expression using the given completion string would have.
4394 */
Douglas Gregor504a6ae2010-01-10 23:08:15 +00004395 CXCompletionChunk_ResultType,
4396 /**
4397 * \brief A colon (':').
4398 */
4399 CXCompletionChunk_Colon,
4400 /**
4401 * \brief A semicolon (';').
4402 */
4403 CXCompletionChunk_SemiColon,
4404 /**
4405 * \brief An '=' sign.
4406 */
4407 CXCompletionChunk_Equal,
4408 /**
4409 * Horizontal space (' ').
4410 */
4411 CXCompletionChunk_HorizontalSpace,
4412 /**
4413 * Vertical space ('\n'), after which it is generally a good idea to
4414 * perform indentation.
4415 */
4416 CXCompletionChunk_VerticalSpace
Douglas Gregor9eb77012009-11-07 00:00:49 +00004417};
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004418
Douglas Gregor9eb77012009-11-07 00:00:49 +00004419/**
4420 * \brief Determine the kind of a particular chunk within a completion string.
4421 *
4422 * \param completion_string the completion string to query.
4423 *
4424 * \param chunk_number the 0-based index of the chunk in the completion string.
4425 *
4426 * \returns the kind of the chunk at the index \c chunk_number.
4427 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004428CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor9eb77012009-11-07 00:00:49 +00004429clang_getCompletionChunkKind(CXCompletionString completion_string,
4430 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004431
Douglas Gregor9eb77012009-11-07 00:00:49 +00004432/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004433 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor9eb77012009-11-07 00:00:49 +00004434 * completion string.
4435 *
4436 * \param completion_string the completion string to query.
4437 *
4438 * \param chunk_number the 0-based index of the chunk in the completion string.
4439 *
4440 * \returns the text associated with the chunk at index \c chunk_number.
4441 */
Ted Kremenekf602f962010-02-17 01:42:24 +00004442CINDEX_LINKAGE CXString
Douglas Gregor9eb77012009-11-07 00:00:49 +00004443clang_getCompletionChunkText(CXCompletionString completion_string,
4444 unsigned chunk_number);
4445
4446/**
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004447 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor9eb77012009-11-07 00:00:49 +00004448 * within a completion string.
4449 *
4450 * \param completion_string the completion string to query.
4451 *
4452 * \param chunk_number the 0-based index of the chunk in the completion string.
4453 *
4454 * \returns the completion string associated with the chunk at index
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004455 * \c chunk_number.
Douglas Gregor9eb77012009-11-07 00:00:49 +00004456 */
4457CINDEX_LINKAGE CXCompletionString
4458clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4459 unsigned chunk_number);
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004460
Douglas Gregor9eb77012009-11-07 00:00:49 +00004461/**
4462 * \brief Retrieve the number of chunks in the given code-completion string.
4463 */
4464CINDEX_LINKAGE unsigned
4465clang_getNumCompletionChunks(CXCompletionString completion_string);
4466
4467/**
Douglas Gregora2db7932010-05-26 22:00:08 +00004468 * \brief Determine the priority of this code completion.
4469 *
4470 * The priority of a code completion indicates how likely it is that this
4471 * particular completion is the completion that the user will select. The
4472 * priority is selected by various internal heuristics.
4473 *
4474 * \param completion_string The completion string to query.
4475 *
4476 * \returns The priority of this completion string. Smaller values indicate
4477 * higher-priority (more likely) completions.
4478 */
4479CINDEX_LINKAGE unsigned
4480clang_getCompletionPriority(CXCompletionString completion_string);
4481
4482/**
Douglas Gregorf757a122010-08-23 23:00:57 +00004483 * \brief Determine the availability of the entity that this code-completion
4484 * string refers to.
4485 *
4486 * \param completion_string The completion string to query.
4487 *
4488 * \returns The availability of the completion string.
4489 */
4490CINDEX_LINKAGE enum CXAvailabilityKind
4491clang_getCompletionAvailability(CXCompletionString completion_string);
4492
4493/**
Erik Verbruggen98ea7f62011-10-14 15:31:08 +00004494 * \brief Retrieve the number of annotations associated with the given
4495 * completion string.
4496 *
4497 * \param completion_string the completion string to query.
4498 *
4499 * \returns the number of annotations associated with the given completion
4500 * string.
4501 */
4502CINDEX_LINKAGE unsigned
4503clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4504
4505/**
4506 * \brief Retrieve the annotation associated with the given completion string.
4507 *
4508 * \param completion_string the completion string to query.
4509 *
4510 * \param annotation_number the 0-based index of the annotation of the
4511 * completion string.
4512 *
4513 * \returns annotation string associated with the completion at index
4514 * \c annotation_number, or a NULL string if that annotation is not available.
4515 */
4516CINDEX_LINKAGE CXString
4517clang_getCompletionAnnotation(CXCompletionString completion_string,
4518 unsigned annotation_number);
4519
4520/**
Douglas Gregor78254c82012-03-27 23:34:16 +00004521 * \brief Retrieve the parent context of the given completion string.
4522 *
4523 * The parent context of a completion string is the semantic parent of
4524 * the declaration (if any) that the code completion represents. For example,
4525 * a code completion for an Objective-C method would have the method's class
4526 * or protocol as its context.
4527 *
4528 * \param completion_string The code completion string whose parent is
4529 * being queried.
4530 *
Argyrios Kyrtzidis9ae39562012-09-26 16:39:56 +00004531 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
Douglas Gregor78254c82012-03-27 23:34:16 +00004532 *
James Dennett574cb4c2012-06-15 05:41:51 +00004533 * \returns The name of the completion parent, e.g., "NSObject" if
Douglas Gregor78254c82012-03-27 23:34:16 +00004534 * the completion string represents a method in the NSObject class.
4535 */
4536CINDEX_LINKAGE CXString
4537clang_getCompletionParent(CXCompletionString completion_string,
4538 enum CXCursorKind *kind);
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004539
4540/**
4541 * \brief Retrieve the brief documentation comment attached to the declaration
4542 * that corresponds to the given completion string.
4543 */
4544CINDEX_LINKAGE CXString
4545clang_getCompletionBriefComment(CXCompletionString completion_string);
4546
Douglas Gregor78254c82012-03-27 23:34:16 +00004547/**
Douglas Gregor3f35bb22011-08-04 20:04:59 +00004548 * \brief Retrieve a completion string for an arbitrary declaration or macro
4549 * definition cursor.
4550 *
4551 * \param cursor The cursor to query.
4552 *
4553 * \returns A non-context-sensitive completion string for declaration and macro
4554 * definition cursors, or NULL for other kinds of cursors.
4555 */
4556CINDEX_LINKAGE CXCompletionString
4557clang_getCursorCompletionString(CXCursor cursor);
4558
4559/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004560 * \brief Contains the results of code-completion.
4561 *
4562 * This data structure contains the results of code completion, as
Douglas Gregor6a9580282010-10-11 21:51:20 +00004563 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004564 * \c clang_disposeCodeCompleteResults.
4565 */
4566typedef struct {
4567 /**
4568 * \brief The code-completion results.
4569 */
4570 CXCompletionResult *Results;
4571
4572 /**
4573 * \brief The number of code-completion results stored in the
4574 * \c Results array.
4575 */
4576 unsigned NumResults;
4577} CXCodeCompleteResults;
4578
4579/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004580 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4581 * modify its behavior.
4582 *
4583 * The enumerators in this enumeration can be bitwise-OR'd together to
4584 * provide multiple options to \c clang_codeCompleteAt().
4585 */
4586enum CXCodeComplete_Flags {
4587 /**
4588 * \brief Whether to include macros within the set of code
4589 * completions returned.
4590 */
4591 CXCodeComplete_IncludeMacros = 0x01,
4592
4593 /**
4594 * \brief Whether to include code patterns for language constructs
4595 * within the set of code completions, e.g., for loops.
4596 */
Dmitri Gribenko3292d062012-07-02 17:35:10 +00004597 CXCodeComplete_IncludeCodePatterns = 0x02,
4598
4599 /**
4600 * \brief Whether to include brief documentation within the set of code
4601 * completions returned.
4602 */
4603 CXCodeComplete_IncludeBriefComments = 0x04
Douglas Gregorb68bc592010-08-05 09:09:23 +00004604};
4605
4606/**
Douglas Gregor21325842011-07-07 16:03:39 +00004607 * \brief Bits that represent the context under which completion is occurring.
4608 *
4609 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4610 * contexts are occurring simultaneously.
4611 */
4612enum CXCompletionContext {
4613 /**
4614 * \brief The context for completions is unexposed, as only Clang results
4615 * should be included. (This is equivalent to having no context bits set.)
4616 */
4617 CXCompletionContext_Unexposed = 0,
4618
4619 /**
4620 * \brief Completions for any possible type should be included in the results.
4621 */
4622 CXCompletionContext_AnyType = 1 << 0,
4623
4624 /**
4625 * \brief Completions for any possible value (variables, function calls, etc.)
4626 * should be included in the results.
4627 */
4628 CXCompletionContext_AnyValue = 1 << 1,
4629 /**
4630 * \brief Completions for values that resolve to an Objective-C object should
4631 * be included in the results.
4632 */
4633 CXCompletionContext_ObjCObjectValue = 1 << 2,
4634 /**
4635 * \brief Completions for values that resolve to an Objective-C selector
4636 * should be included in the results.
4637 */
4638 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4639 /**
4640 * \brief Completions for values that resolve to a C++ class type should be
4641 * included in the results.
4642 */
4643 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4644
4645 /**
4646 * \brief Completions for fields of the member being accessed using the dot
4647 * operator should be included in the results.
4648 */
4649 CXCompletionContext_DotMemberAccess = 1 << 5,
4650 /**
4651 * \brief Completions for fields of the member being accessed using the arrow
4652 * operator should be included in the results.
4653 */
4654 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4655 /**
4656 * \brief Completions for properties of the Objective-C object being accessed
4657 * using the dot operator should be included in the results.
4658 */
4659 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4660
4661 /**
4662 * \brief Completions for enum tags should be included in the results.
4663 */
4664 CXCompletionContext_EnumTag = 1 << 8,
4665 /**
4666 * \brief Completions for union tags should be included in the results.
4667 */
4668 CXCompletionContext_UnionTag = 1 << 9,
4669 /**
4670 * \brief Completions for struct tags should be included in the results.
4671 */
4672 CXCompletionContext_StructTag = 1 << 10,
4673
4674 /**
4675 * \brief Completions for C++ class names should be included in the results.
4676 */
4677 CXCompletionContext_ClassTag = 1 << 11,
4678 /**
4679 * \brief Completions for C++ namespaces and namespace aliases should be
4680 * included in the results.
4681 */
4682 CXCompletionContext_Namespace = 1 << 12,
4683 /**
4684 * \brief Completions for C++ nested name specifiers should be included in
4685 * the results.
4686 */
4687 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4688
4689 /**
4690 * \brief Completions for Objective-C interfaces (classes) should be included
4691 * in the results.
4692 */
4693 CXCompletionContext_ObjCInterface = 1 << 14,
4694 /**
4695 * \brief Completions for Objective-C protocols should be included in
4696 * the results.
4697 */
4698 CXCompletionContext_ObjCProtocol = 1 << 15,
4699 /**
4700 * \brief Completions for Objective-C categories should be included in
4701 * the results.
4702 */
4703 CXCompletionContext_ObjCCategory = 1 << 16,
4704 /**
4705 * \brief Completions for Objective-C instance messages should be included
4706 * in the results.
4707 */
4708 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4709 /**
4710 * \brief Completions for Objective-C class messages should be included in
4711 * the results.
4712 */
4713 CXCompletionContext_ObjCClassMessage = 1 << 18,
4714 /**
4715 * \brief Completions for Objective-C selector names should be included in
4716 * the results.
4717 */
4718 CXCompletionContext_ObjCSelectorName = 1 << 19,
4719
4720 /**
4721 * \brief Completions for preprocessor macro names should be included in
4722 * the results.
4723 */
4724 CXCompletionContext_MacroName = 1 << 20,
4725
4726 /**
4727 * \brief Natural language completions should be included in the results.
4728 */
4729 CXCompletionContext_NaturalLanguage = 1 << 21,
4730
4731 /**
4732 * \brief The current context is unknown, so set all contexts.
4733 */
4734 CXCompletionContext_Unknown = ((1 << 22) - 1)
4735};
4736
4737/**
Douglas Gregorb68bc592010-08-05 09:09:23 +00004738 * \brief Returns a default set of code-completion options that can be
4739 * passed to\c clang_codeCompleteAt().
4740 */
4741CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4742
4743/**
Douglas Gregor8e984da2010-08-04 16:47:14 +00004744 * \brief Perform code completion at a given location in a translation unit.
4745 *
4746 * This function performs code completion at a particular file, line, and
4747 * column within source code, providing results that suggest potential
4748 * code snippets based on the context of the completion. The basic model
4749 * for code completion is that Clang will parse a complete source file,
4750 * performing syntax checking up to the location where code-completion has
4751 * been requested. At that point, a special code-completion token is passed
4752 * to the parser, which recognizes this token and determines, based on the
4753 * current location in the C/Objective-C/C++ grammar and the state of
4754 * semantic analysis, what completions to provide. These completions are
4755 * returned via a new \c CXCodeCompleteResults structure.
4756 *
4757 * Code completion itself is meant to be triggered by the client when the
4758 * user types punctuation characters or whitespace, at which point the
4759 * code-completion location will coincide with the cursor. For example, if \c p
4760 * is a pointer, code-completion might be triggered after the "-" and then
4761 * after the ">" in \c p->. When the code-completion location is afer the ">",
4762 * the completion results will provide, e.g., the members of the struct that
4763 * "p" points to. The client is responsible for placing the cursor at the
4764 * beginning of the token currently being typed, then filtering the results
4765 * based on the contents of the token. For example, when code-completing for
4766 * the expression \c p->get, the client should provide the location just after
4767 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4768 * client can filter the results based on the current token text ("get"), only
4769 * showing those results that start with "get". The intent of this interface
4770 * is to separate the relatively high-latency acquisition of code-completion
4771 * results from the filtering of results on a per-character basis, which must
4772 * have a lower latency.
4773 *
4774 * \param TU The translation unit in which code-completion should
4775 * occur. The source files for this translation unit need not be
4776 * completely up-to-date (and the contents of those source files may
4777 * be overridden via \p unsaved_files). Cursors referring into the
4778 * translation unit may be invalidated by this invocation.
4779 *
4780 * \param complete_filename The name of the source file where code
4781 * completion should be performed. This filename may be any file
4782 * included in the translation unit.
4783 *
4784 * \param complete_line The line at which code-completion should occur.
4785 *
4786 * \param complete_column The column at which code-completion should occur.
4787 * Note that the column should point just after the syntactic construct that
4788 * initiated code completion, and not in the middle of a lexical token.
4789 *
4790 * \param unsaved_files the Tiles that have not yet been saved to disk
4791 * but may be required for parsing or code completion, including the
4792 * contents of those files. The contents and name of these files (as
4793 * specified by CXUnsavedFile) are copied when necessary, so the
4794 * client only needs to guarantee their validity until the call to
4795 * this function returns.
4796 *
4797 * \param num_unsaved_files The number of unsaved file entries in \p
4798 * unsaved_files.
4799 *
Douglas Gregorb68bc592010-08-05 09:09:23 +00004800 * \param options Extra options that control the behavior of code
4801 * completion, expressed as a bitwise OR of the enumerators of the
4802 * CXCodeComplete_Flags enumeration. The
4803 * \c clang_defaultCodeCompleteOptions() function returns a default set
4804 * of code-completion options.
4805 *
Douglas Gregor8e984da2010-08-04 16:47:14 +00004806 * \returns If successful, a new \c CXCodeCompleteResults structure
4807 * containing code-completion results, which should eventually be
4808 * freed with \c clang_disposeCodeCompleteResults(). If code
4809 * completion fails, returns NULL.
4810 */
4811CINDEX_LINKAGE
4812CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4813 const char *complete_filename,
4814 unsigned complete_line,
4815 unsigned complete_column,
4816 struct CXUnsavedFile *unsaved_files,
Douglas Gregorb68bc592010-08-05 09:09:23 +00004817 unsigned num_unsaved_files,
4818 unsigned options);
Douglas Gregor8e984da2010-08-04 16:47:14 +00004819
4820/**
Douglas Gregor49f67ce2010-08-26 13:48:20 +00004821 * \brief Sort the code-completion results in case-insensitive alphabetical
4822 * order.
4823 *
4824 * \param Results The set of results to sort.
4825 * \param NumResults The number of results in \p Results.
4826 */
4827CINDEX_LINKAGE
4828void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4829 unsigned NumResults);
4830
4831/**
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004832 * \brief Free the given set of code-completion results.
4833 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004834CINDEX_LINKAGE
Douglas Gregorf72b6ac2009-12-18 16:20:58 +00004835void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregorf757a122010-08-23 23:00:57 +00004836
Douglas Gregor52606ff2010-01-20 01:10:47 +00004837/**
Douglas Gregor33cdd812010-02-18 18:08:43 +00004838 * \brief Determine the number of diagnostics produced prior to the
4839 * location where code completion was performed.
4840 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004841CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00004842unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4843
4844/**
4845 * \brief Retrieve a diagnostic associated with the given code completion.
4846 *
James Dennett574cb4c2012-06-15 05:41:51 +00004847 * \param Results the code completion results to query.
Douglas Gregor33cdd812010-02-18 18:08:43 +00004848 * \param Index the zero-based diagnostic number to retrieve.
4849 *
4850 * \returns the requested diagnostic. This diagnostic must be freed
4851 * via a call to \c clang_disposeDiagnostic().
4852 */
Ted Kremenekd071c602010-03-13 02:50:34 +00004853CINDEX_LINKAGE
Douglas Gregor33cdd812010-02-18 18:08:43 +00004854CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4855 unsigned Index);
4856
4857/**
Nico Weberdd9c19f2014-04-24 03:06:18 +00004858 * \brief Determines what completions are appropriate for the context
Douglas Gregor21325842011-07-07 16:03:39 +00004859 * the given code completion.
4860 *
4861 * \param Results the code completion results to query
4862 *
4863 * \returns the kinds of completions that are appropriate for use
4864 * along with the given code completion results.
4865 */
4866CINDEX_LINKAGE
4867unsigned long long clang_codeCompleteGetContexts(
4868 CXCodeCompleteResults *Results);
Douglas Gregor63745d52011-07-21 01:05:26 +00004869
4870/**
4871 * \brief Returns the cursor kind for the container for the current code
4872 * completion context. The container is only guaranteed to be set for
4873 * contexts where a container exists (i.e. member accesses or Objective-C
4874 * message sends); if there is not a container, this function will return
4875 * CXCursor_InvalidCode.
4876 *
4877 * \param Results the code completion results to query
4878 *
4879 * \param IsIncomplete on return, this value will be false if Clang has complete
4880 * information about the container. If Clang does not have complete
4881 * information, this value will be true.
4882 *
4883 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4884 * container
4885 */
4886CINDEX_LINKAGE
4887enum CXCursorKind clang_codeCompleteGetContainerKind(
4888 CXCodeCompleteResults *Results,
4889 unsigned *IsIncomplete);
4890
4891/**
4892 * \brief Returns the USR for the container for the current code completion
4893 * context. If there is not a container for the current context, this
4894 * function will return the empty string.
4895 *
4896 * \param Results the code completion results to query
4897 *
4898 * \returns the USR for the container
4899 */
4900CINDEX_LINKAGE
4901CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor21325842011-07-07 16:03:39 +00004902
Douglas Gregorea777402011-07-26 15:24:30 +00004903
4904/**
4905 * \brief Returns the currently-entered selector for an Objective-C message
4906 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4907 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4908 * CXCompletionContext_ObjCClassMessage.
4909 *
4910 * \param Results the code completion results to query
4911 *
4912 * \returns the selector (or partial selector) that has been entered thus far
4913 * for an Objective-C message send.
4914 */
4915CINDEX_LINKAGE
4916CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4917
Douglas Gregor21325842011-07-07 16:03:39 +00004918/**
Douglas Gregor52606ff2010-01-20 01:10:47 +00004919 * @}
4920 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004921
4922
Ted Kremenekc0f3f722010-01-22 22:44:15 +00004923/**
4924 * \defgroup CINDEX_MISC Miscellaneous utility functions
4925 *
4926 * @{
4927 */
Ted Kremenek3e315a22010-01-23 17:51:23 +00004928
4929/**
4930 * \brief Return a version string, suitable for showing to a user, but not
4931 * intended to be parsed (the format is not guaranteed to be stable).
4932 */
NAKAMURA Takumieacd6672013-01-10 02:12:38 +00004933CINDEX_LINKAGE CXString clang_getClangVersion(void);
Ted Kremenekc0f3f722010-01-22 22:44:15 +00004934
Ted Kremenek1ec7b332011-03-18 23:05:39 +00004935
4936/**
4937 * \brief Enable/disable crash recovery.
4938 *
James Dennett574cb4c2012-06-15 05:41:51 +00004939 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
4940 * value enables crash recovery, while 0 disables it.
Ted Kremenek1ec7b332011-03-18 23:05:39 +00004941 */
4942CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4943
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00004944 /**
Ted Kremenekd071c602010-03-13 02:50:34 +00004945 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00004946 * (used with clang_getInclusions()).
4947 *
4948 * This visitor function will be invoked by clang_getInclusions() for each
James Dennett574cb4c2012-06-15 05:41:51 +00004949 * file included (either at the top-level or by \#include directives) within
Ted Kremenek0b86e3a2010-01-26 19:31:51 +00004950 * a translation unit. The first argument is the file being included, and
4951 * the second and third arguments provide the inclusion stack. The
4952 * array is sorted in order of immediate inclusion. For example,
4953 * the first element refers to the location that included 'included_file'.
4954 */
4955typedef void (*CXInclusionVisitor)(CXFile included_file,
4956 CXSourceLocation* inclusion_stack,
4957 unsigned include_len,
4958 CXClientData client_data);
4959
4960/**
4961 * \brief Visit the set of preprocessor inclusions in a translation unit.
4962 * The visitor function is called with the provided data for every included
4963 * file. This does not include headers included by the PCH file (unless one
4964 * is inspecting the inclusions in the PCH file itself).
4965 */
4966CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4967 CXInclusionVisitor visitor,
4968 CXClientData client_data);
4969
4970/**
Ted Kremenekc0f3f722010-01-22 22:44:15 +00004971 * @}
4972 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00004973
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00004974/** \defgroup CINDEX_REMAPPING Remapping functions
4975 *
4976 * @{
4977 */
4978
4979/**
4980 * \brief A remapping of original source files and their translated files.
4981 */
4982typedef void *CXRemapping;
4983
4984/**
4985 * \brief Retrieve a remapping.
4986 *
4987 * \param path the path that contains metadata about remappings.
4988 *
4989 * \returns the requested remapping. This remapping must be freed
4990 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4991 */
4992CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4993
4994/**
Ted Kremenekf7639e12012-03-06 20:06:33 +00004995 * \brief Retrieve a remapping.
4996 *
4997 * \param filePaths pointer to an array of file paths containing remapping info.
4998 *
4999 * \param numFiles number of file paths.
5000 *
5001 * \returns the requested remapping. This remapping must be freed
5002 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5003 */
5004CINDEX_LINKAGE
5005CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5006 unsigned numFiles);
5007
5008/**
Argyrios Kyrtzidisf89cc692011-07-11 20:15:00 +00005009 * \brief Determine the number of remappings.
5010 */
5011CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5012
5013/**
5014 * \brief Get the original and the associated filename from the remapping.
5015 *
5016 * \param original If non-NULL, will be set to the original filename.
5017 *
5018 * \param transformed If non-NULL, will be set to the filename that the original
5019 * is associated with.
5020 */
5021CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5022 CXString *original, CXString *transformed);
5023
5024/**
5025 * \brief Dispose the remapping.
5026 */
5027CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5028
5029/**
5030 * @}
5031 */
5032
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005033/** \defgroup CINDEX_HIGH Higher level API functions
5034 *
5035 * @{
5036 */
5037
5038enum CXVisitorResult {
5039 CXVisit_Break,
5040 CXVisit_Continue
5041};
5042
5043typedef struct {
5044 void *context;
5045 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5046} CXCursorAndRangeVisitor;
5047
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005048typedef enum {
5049 /**
5050 * \brief Function returned successfully.
5051 */
5052 CXResult_Success = 0,
5053 /**
5054 * \brief One of the parameters was invalid for the function.
5055 */
5056 CXResult_Invalid = 1,
5057 /**
5058 * \brief The function was terminated by a callback (e.g. it returned
5059 * CXVisit_Break)
5060 */
5061 CXResult_VisitBreak = 2
5062
5063} CXResult;
5064
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005065/**
5066 * \brief Find references of a declaration in a specific file.
5067 *
5068 * \param cursor pointing to a declaration or a reference of one.
5069 *
5070 * \param file to search for references.
5071 *
5072 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5073 * each reference found.
5074 * The CXSourceRange will point inside the file; if the reference is inside
5075 * a macro (and not a macro argument) the CXSourceRange will be invalid.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005076 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005077 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005078 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005079CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5080 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005081
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005082/**
5083 * \brief Find #import/#include directives in a specific file.
5084 *
5085 * \param TU translation unit containing the file to query.
5086 *
5087 * \param file to search for #import/#include directives.
5088 *
5089 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5090 * each directive found.
Argyrios Kyrtzidis951f61f2013-03-08 20:42:33 +00005091 *
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005092 * \returns one of the CXResult enumerators.
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005093 */
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005094CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5095 CXFile file,
5096 CXCursorAndRangeVisitor visitor);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005097
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005098#ifdef __has_feature
5099# if __has_feature(blocks)
5100
5101typedef enum CXVisitorResult
5102 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5103
5104CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005105CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5106 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005107
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005108CINDEX_LINKAGE
Argyrios Kyrtzidis51c33182013-03-08 22:47:41 +00005109CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5110 CXCursorAndRangeVisitorBlock);
Argyrios Kyrtzidis503c83a2013-03-08 02:32:34 +00005111
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005112# endif
5113#endif
5114
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005115/**
5116 * \brief The client's data object that is associated with a CXFile.
5117 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005118typedef void *CXIdxClientFile;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005119
5120/**
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005121 * \brief The client's data object that is associated with a semantic entity.
5122 */
5123typedef void *CXIdxClientEntity;
5124
5125/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005126 * \brief The client's data object that is associated with a semantic container
5127 * of entities.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005128 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005129typedef void *CXIdxClientContainer;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005130
5131/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005132 * \brief The client's data object that is associated with an AST file (PCH
5133 * or module).
5134 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005135typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005136
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005137/**
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005138 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005139 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005140typedef struct {
5141 void *ptr_data[2];
5142 unsigned int_data;
5143} CXIdxLoc;
5144
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005145/**
James Dennett574cb4c2012-06-15 05:41:51 +00005146 * \brief Data for ppIncludedFile callback.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005147 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005148typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005149 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005150 * \brief Location of '#' in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005151 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005152 CXIdxLoc hashLoc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005153 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005154 * \brief Filename as written in the \#include/\#import directive.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005155 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005156 const char *filename;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005157 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005158 * \brief The actual file that the \#include/\#import directive resolved to.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005159 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005160 CXFile file;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005161 int isImport;
5162 int isAngled;
Argyrios Kyrtzidis5e2ec482012-10-18 00:17:05 +00005163 /**
5164 * \brief Non-zero if the directive was automatically turned into a module
5165 * import.
5166 */
5167 int isModuleImport;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005168} CXIdxIncludedFileInfo;
5169
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005170/**
James Dennett574cb4c2012-06-15 05:41:51 +00005171 * \brief Data for IndexerCallbacks#importedASTFile.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005172 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005173typedef struct {
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005174 /**
5175 * \brief Top level AST file containing the imported PCH, module or submodule.
5176 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005177 CXFile file;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005178 /**
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005179 * \brief The imported module or NULL if the AST file is a PCH.
5180 */
5181 CXModule module;
5182 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005183 * \brief Location where the file is imported. Applicable only for modules.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005184 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005185 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005186 /**
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005187 * \brief Non-zero if an inclusion directive was automatically turned into
Argyrios Kyrtzidisdc78f3e2012-10-05 00:22:40 +00005188 * a module import. Applicable only for modules.
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005189 */
Argyrios Kyrtzidis184b1442012-10-03 21:05:44 +00005190 int isImplicit;
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005191
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005192} CXIdxImportedASTFileInfo;
5193
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005194typedef enum {
5195 CXIdxEntity_Unexposed = 0,
5196 CXIdxEntity_Typedef = 1,
5197 CXIdxEntity_Function = 2,
5198 CXIdxEntity_Variable = 3,
5199 CXIdxEntity_Field = 4,
5200 CXIdxEntity_EnumConstant = 5,
5201
5202 CXIdxEntity_ObjCClass = 6,
5203 CXIdxEntity_ObjCProtocol = 7,
5204 CXIdxEntity_ObjCCategory = 8,
5205
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005206 CXIdxEntity_ObjCInstanceMethod = 9,
5207 CXIdxEntity_ObjCClassMethod = 10,
5208 CXIdxEntity_ObjCProperty = 11,
5209 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005210
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005211 CXIdxEntity_Enum = 13,
5212 CXIdxEntity_Struct = 14,
5213 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005214
5215 CXIdxEntity_CXXClass = 16,
5216 CXIdxEntity_CXXNamespace = 17,
5217 CXIdxEntity_CXXNamespaceAlias = 18,
5218 CXIdxEntity_CXXStaticVariable = 19,
5219 CXIdxEntity_CXXStaticMethod = 20,
5220 CXIdxEntity_CXXInstanceMethod = 21,
Joao Matose9a3ed42012-08-31 22:18:20 +00005221 CXIdxEntity_CXXConstructor = 22,
5222 CXIdxEntity_CXXDestructor = 23,
5223 CXIdxEntity_CXXConversionFunction = 24,
5224 CXIdxEntity_CXXTypeAlias = 25,
5225 CXIdxEntity_CXXInterface = 26
5226
5227} CXIdxEntityKind;
5228
Argyrios Kyrtzidis52002882011-12-07 20:44:12 +00005229typedef enum {
5230 CXIdxEntityLang_None = 0,
5231 CXIdxEntityLang_C = 1,
5232 CXIdxEntityLang_ObjC = 2,
5233 CXIdxEntityLang_CXX = 3
5234} CXIdxEntityLanguage;
5235
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005236/**
5237 * \brief Extra C++ template information for an entity. This can apply to:
5238 * CXIdxEntity_Function
5239 * CXIdxEntity_CXXClass
5240 * CXIdxEntity_CXXStaticMethod
5241 * CXIdxEntity_CXXInstanceMethod
5242 * CXIdxEntity_CXXConstructor
5243 * CXIdxEntity_CXXConversionFunction
5244 * CXIdxEntity_CXXTypeAlias
5245 */
5246typedef enum {
5247 CXIdxEntity_NonTemplate = 0,
5248 CXIdxEntity_Template = 1,
5249 CXIdxEntity_TemplatePartialSpecialization = 2,
5250 CXIdxEntity_TemplateSpecialization = 3
5251} CXIdxEntityCXXTemplateKind;
5252
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005253typedef enum {
5254 CXIdxAttr_Unexposed = 0,
5255 CXIdxAttr_IBAction = 1,
5256 CXIdxAttr_IBOutlet = 2,
5257 CXIdxAttr_IBOutletCollection = 3
5258} CXIdxAttrKind;
5259
5260typedef struct {
5261 CXIdxAttrKind kind;
5262 CXCursor cursor;
5263 CXIdxLoc loc;
5264} CXIdxAttrInfo;
5265
5266typedef struct {
Argyrios Kyrtzidis4d873b72011-12-15 00:05:00 +00005267 CXIdxEntityKind kind;
5268 CXIdxEntityCXXTemplateKind templateKind;
5269 CXIdxEntityLanguage lang;
5270 const char *name;
5271 const char *USR;
5272 CXCursor cursor;
5273 const CXIdxAttrInfo *const *attributes;
5274 unsigned numAttributes;
5275} CXIdxEntityInfo;
5276
5277typedef struct {
5278 CXCursor cursor;
5279} CXIdxContainerInfo;
5280
5281typedef struct {
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005282 const CXIdxAttrInfo *attrInfo;
5283 const CXIdxEntityInfo *objcClass;
5284 CXCursor classCursor;
5285 CXIdxLoc classLoc;
5286} CXIdxIBOutletCollectionAttrInfo;
5287
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005288typedef enum {
5289 CXIdxDeclFlag_Skipped = 0x1
5290} CXIdxDeclInfoFlags;
5291
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005292typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005293 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005294 CXCursor cursor;
5295 CXIdxLoc loc;
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005296 const CXIdxContainerInfo *semanticContainer;
5297 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005298 * \brief Generally same as #semanticContainer but can be different in
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005299 * cases like out-of-line C++ member functions.
5300 */
5301 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005302 int isRedeclaration;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005303 int isDefinition;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005304 int isContainer;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005305 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005306 /**
5307 * \brief Whether the declaration exists in code or was created implicitly
Nico Weber7deebef2014-04-24 03:17:47 +00005308 * by the compiler, e.g. implicit Objective-C methods for properties.
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005309 */
5310 int isImplicit;
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005311 const CXIdxAttrInfo *const *attributes;
5312 unsigned numAttributes;
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005313
5314 unsigned flags;
5315
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005316} CXIdxDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005317
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005318typedef enum {
5319 CXIdxObjCContainer_ForwardRef = 0,
5320 CXIdxObjCContainer_Interface = 1,
5321 CXIdxObjCContainer_Implementation = 2
5322} CXIdxObjCContainerKind;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005323
5324typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005325 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005326 CXIdxObjCContainerKind kind;
5327} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005328
5329typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005330 const CXIdxEntityInfo *base;
5331 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005332 CXIdxLoc loc;
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005333} CXIdxBaseClassInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005334
5335typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005336 const CXIdxEntityInfo *protocol;
5337 CXCursor cursor;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005338 CXIdxLoc loc;
5339} CXIdxObjCProtocolRefInfo;
5340
5341typedef struct {
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005342 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005343 unsigned numProtocols;
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005344} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005345
5346typedef struct {
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005347 const CXIdxObjCContainerDeclInfo *containerInfo;
5348 const CXIdxBaseClassInfo *superInfo;
5349 const CXIdxObjCProtocolRefListInfo *protocols;
5350} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005351
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005352typedef struct {
Argyrios Kyrtzidis9b9f7a92011-12-13 18:47:45 +00005353 const CXIdxObjCContainerDeclInfo *containerInfo;
5354 const CXIdxEntityInfo *objcClass;
5355 CXCursor classCursor;
5356 CXIdxLoc classLoc;
5357 const CXIdxObjCProtocolRefListInfo *protocols;
5358} CXIdxObjCCategoryDeclInfo;
5359
5360typedef struct {
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005361 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005362 const CXIdxEntityInfo *getter;
5363 const CXIdxEntityInfo *setter;
5364} CXIdxObjCPropertyDeclInfo;
5365
5366typedef struct {
5367 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005368 const CXIdxBaseClassInfo *const *bases;
5369 unsigned numBases;
5370} CXIdxCXXClassDeclInfo;
5371
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005372/**
James Dennett574cb4c2012-06-15 05:41:51 +00005373 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005374 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005375typedef enum {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005376 /**
5377 * \brief The entity is referenced directly in user's code.
5378 */
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005379 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005380 /**
Nico Weber7deebef2014-04-24 03:17:47 +00005381 * \brief An implicit reference, e.g. a reference of an Objective-C method
5382 * via the dot syntax.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005383 */
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005384 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidis0c7735e52011-10-18 15:50:50 +00005385} CXIdxEntityRefKind;
5386
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005387/**
James Dennett574cb4c2012-06-15 05:41:51 +00005388 * \brief Data for IndexerCallbacks#indexEntityReference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005389 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005390typedef struct {
Argyrios Kyrtzidis663c8ec2011-12-07 20:44:19 +00005391 CXIdxEntityRefKind kind;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005392 /**
5393 * \brief Reference cursor.
5394 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005395 CXCursor cursor;
5396 CXIdxLoc loc;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005397 /**
5398 * \brief The entity that gets referenced.
5399 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005400 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005401 /**
5402 * \brief Immediate "parent" of the reference. For example:
5403 *
5404 * \code
5405 * Foo *var;
5406 * \endcode
5407 *
5408 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005409 * For references inside statement bodies of functions/methods,
5410 * the parentEntity will be the function/method.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005411 */
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005412 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005413 /**
Argyrios Kyrtzidis25cb0ff2011-12-13 18:47:41 +00005414 * \brief Lexical container context of the reference.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005415 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005416 const CXIdxContainerInfo *container;
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005417} CXIdxEntityRefInfo;
5418
James Dennett574cb4c2012-06-15 05:41:51 +00005419/**
5420 * \brief A group of callbacks used by #clang_indexSourceFile and
5421 * #clang_indexTranslationUnit.
5422 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005423typedef struct {
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005424 /**
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005425 * \brief Called periodically to check whether indexing should be aborted.
5426 * Should return 0 to continue, and non-zero to abort.
5427 */
5428 int (*abortQuery)(CXClientData client_data, void *reserved);
5429
5430 /**
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005431 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005432 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005433 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005434 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005435
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005436 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
James Dennett574cb4c2012-06-15 05:41:51 +00005437 CXFile mainFile, void *reserved);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005438
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005439 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005440 * \brief Called when a file gets \#included/\#imported.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005441 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005442 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005443 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005444
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005445 /**
5446 * \brief Called when a AST file (PCH or module) gets imported.
5447 *
5448 * AST files will not get indexed (there will not be callbacks to index all
5449 * the entities in an AST file). The recommended action is that, if the AST
Argyrios Kyrtzidis472eda02012-10-02 16:10:38 +00005450 * file is not already indexed, to initiate a new indexing job specific to
5451 * the AST file.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005452 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005453 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005454 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005455
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005456 /**
5457 * \brief Called at the beginning of indexing a translation unit.
5458 */
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005459 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005460 void *reserved);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005461
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005462 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005463 const CXIdxDeclInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005464
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005465 /**
5466 * \brief Called to index a reference of an entity.
5467 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005468 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005469 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005470
5471} IndexerCallbacks;
5472
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005473CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005474CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5475clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005476
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005477CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5478clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5479
NAKAMURA Takumiaacef7e2011-11-11 02:51:09 +00005480CINDEX_LINKAGE
Argyrios Kyrtzidis3e429e72011-11-12 02:16:30 +00005481const CXIdxObjCCategoryDeclInfo *
5482clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5483
Argyrios Kyrtzidis86acd722011-11-14 22:39:19 +00005484CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5485clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005486
Argyrios Kyrtzidis93db2922012-02-28 17:50:33 +00005487CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5488clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5489
Argyrios Kyrtzidiseffdbf52011-11-18 00:26:51 +00005490CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5491clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5492
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005493CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5494clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5495
5496/**
5497 * \brief For retrieving a custom CXIdxClientContainer attached to a
5498 * container.
5499 */
5500CINDEX_LINKAGE CXIdxClientContainer
5501clang_index_getClientContainer(const CXIdxContainerInfo *);
5502
5503/**
5504 * \brief For setting a custom CXIdxClientContainer attached to a
5505 * container.
5506 */
5507CINDEX_LINKAGE void
5508clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5509
5510/**
5511 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5512 */
5513CINDEX_LINKAGE CXIdxClientEntity
5514clang_index_getClientEntity(const CXIdxEntityInfo *);
5515
5516/**
5517 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5518 */
5519CINDEX_LINKAGE void
5520clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5521
5522/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005523 * \brief An indexing action/session, to be applied to one or multiple
5524 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005525 */
5526typedef void *CXIndexAction;
5527
5528/**
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005529 * \brief An indexing action/session, to be applied to one or multiple
5530 * translation units.
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005531 *
5532 * \param CIdx The index object with which the index action will be associated.
5533 */
5534CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5535
5536/**
5537 * \brief Destroy the given index action.
5538 *
5539 * The index action must not be destroyed until all of the translation units
5540 * created within that index action have been destroyed.
5541 */
5542CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5543
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005544typedef enum {
5545 /**
5546 * \brief Used to indicate that no special indexing options are needed.
5547 */
5548 CXIndexOpt_None = 0x0,
5549
5550 /**
James Dennett574cb4c2012-06-15 05:41:51 +00005551 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5552 * be invoked for only one reference of an entity per source file that does
5553 * not also include a declaration/definition of the entity.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005554 */
Argyrios Kyrtzidisfb7d1452012-01-14 00:11:49 +00005555 CXIndexOpt_SuppressRedundantRefs = 0x1,
5556
5557 /**
5558 * \brief Function-local symbols should be indexed. If this is not set
5559 * function-local symbols will be ignored.
5560 */
Argyrios Kyrtzidis7e747952012-02-14 22:23:11 +00005561 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5562
5563 /**
5564 * \brief Implicit function/class template instantiations should be indexed.
5565 * If this is not set, implicit instantiations will be ignored.
5566 */
Argyrios Kyrtzidis6c9ed7d2012-03-27 21:38:03 +00005567 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5568
5569 /**
5570 * \brief Suppress all compiler warnings when parsing for indexing.
5571 */
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005572 CXIndexOpt_SuppressWarnings = 0x8,
5573
5574 /**
5575 * \brief Skip a function/method body that was already parsed during an
Nico Weber7deebef2014-04-24 03:17:47 +00005576 * indexing session associated with a \c CXIndexAction object.
Argyrios Kyrtzidis8b71bc72012-12-06 19:41:16 +00005577 * Bodies in system headers are always skipped.
5578 */
5579 CXIndexOpt_SkipParsedBodiesInSession = 0x10
5580
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005581} CXIndexOptFlags;
5582
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005583/**
5584 * \brief Index the given source file and the translation unit corresponding
James Dennett574cb4c2012-06-15 05:41:51 +00005585 * to that file via callbacks implemented through #IndexerCallbacks.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005586 *
5587 * \param client_data pointer data supplied by the client, which will
5588 * be passed to the invoked callbacks.
5589 *
5590 * \param index_callbacks Pointer to indexing callbacks that the client
5591 * implements.
5592 *
James Dennett574cb4c2012-06-15 05:41:51 +00005593 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005594 * passed in index_callbacks.
5595 *
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005596 * \param index_options A bitmask of options that affects how indexing is
5597 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005598 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00005599 * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be
5600 * reused after indexing is finished. Set to \c NULL if you do not require it.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005601 *
Dmitri Gribenkoea4d1c32014-02-12 19:12:37 +00005602 * \returns 0 on success or if there were errors from which the compiler could
5603 * recover. If there is a failure from which the there is no recovery, returns
5604 * a non-zero \c CXErrorCode.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005605 *
James Dennett574cb4c2012-06-15 05:41:51 +00005606 * The rest of the parameters are the same as #clang_parseTranslationUnit.
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005607 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005608CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005609 CXClientData client_data,
5610 IndexerCallbacks *index_callbacks,
5611 unsigned index_callbacks_size,
5612 unsigned index_options,
5613 const char *source_filename,
5614 const char * const *command_line_args,
5615 int num_command_line_args,
5616 struct CXUnsavedFile *unsaved_files,
5617 unsigned num_unsaved_files,
5618 CXTranslationUnit *out_TU,
5619 unsigned TU_options);
5620
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005621/**
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005622 * \brief Index the given translation unit via callbacks implemented through
James Dennett574cb4c2012-06-15 05:41:51 +00005623 * #IndexerCallbacks.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005624 *
5625 * The order of callback invocations is not guaranteed to be the same as
5626 * when indexing a source file. The high level order will be:
5627 *
5628 * -Preprocessor callbacks invocations
5629 * -Declaration/reference callbacks invocations
5630 * -Diagnostic callback invocations
5631 *
James Dennett574cb4c2012-06-15 05:41:51 +00005632 * The parameters are the same as #clang_indexSourceFile.
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005633 *
5634 * \returns If there is a failure from which the there is no recovery, returns
5635 * non-zero, otherwise returns 0.
5636 */
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005637CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005638 CXClientData client_data,
5639 IndexerCallbacks *index_callbacks,
5640 unsigned index_callbacks_size,
Argyrios Kyrtzidis4c910b12011-11-22 07:24:51 +00005641 unsigned index_options,
5642 CXTranslationUnit);
Argyrios Kyrtzidisd992e142011-11-15 06:20:16 +00005643
5644/**
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005645 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5646 * the given CXIdxLoc.
5647 *
5648 * If the location refers into a macro expansion, retrieves the
5649 * location of the macro expansion and if it refers into a macro argument
5650 * retrieves the location of the argument.
5651 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005652CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidis7519c5e2011-11-11 00:23:36 +00005653 CXIdxClientFile *indexFile,
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005654 CXFile *file,
5655 unsigned *line,
5656 unsigned *column,
5657 unsigned *offset);
5658
Argyrios Kyrtzidis11d61142011-10-27 17:36:12 +00005659/**
5660 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5661 */
Argyrios Kyrtzidisdc199a32011-10-17 19:48:19 +00005662CINDEX_LINKAGE
5663CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
5664
Argyrios Kyrtzidiscddafd32011-10-06 07:00:54 +00005665/**
5666 * @}
5667 */
5668
Douglas Gregor6007cf22010-01-22 22:29:16 +00005669/**
5670 * @}
5671 */
Daniel Dunbar62ebf252010-01-24 02:54:26 +00005672
Alp Toker59c6bc52014-04-28 02:39:27 +00005673/* Include the comment API for compatibility. This will eventually go away. */
5674#include "clang-c/Documentation.h"
5675
Ted Kremenekb60d87c2009-08-26 22:36:44 +00005676#ifdef __cplusplus
5677}
5678#endif
5679#endif
5680