blob: 13ba6ba2ae167ff8006533700f7d887516d7c5d1 [file] [log] [blame]
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
Steve Naroff88145032009-10-27 14:35:18 +000019#include <sys/stat.h>
Chandler Carruth3d315602009-12-17 09:27:29 +000020#include <time.h>
Douglas Gregor0a812cf2010-02-18 23:07:20 +000021#include <stdio.h>
Steve Naroff88145032009-10-27 14:35:18 +000022
Ted Kremenekd2fa5662009-08-26 22:36:44 +000023#ifdef __cplusplus
24extern "C" {
25#endif
26
Steve Naroff88145032009-10-27 14:35:18 +000027/* MSVC DLL import/export. */
John Thompson2e06fc82009-10-27 13:42:56 +000028#ifdef _MSC_VER
29 #ifdef _CINDEX_LIB_
30 #define CINDEX_LINKAGE __declspec(dllexport)
31 #else
32 #define CINDEX_LINKAGE __declspec(dllimport)
33 #endif
34#else
35 #define CINDEX_LINKAGE
36#endif
37
Ted Kremenek78d5d3b2012-04-12 00:03:31 +000038#ifdef __GNUC__
39 #define CINDEX_DEPRECATED __attribute__((deprecated))
40#else
41 #ifdef _MSC_VER
42 #define CINDEX_DEPRECATED __declspec(deprecated)
43 #else
44 #define CINDEX_DEPRECATED
45 #endif
46#endif
47
Douglas Gregor87fb9402011-02-23 17:45:25 +000048/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000049 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000050 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000051 * facilities for parsing source code into an abstract syntax tree (AST),
52 * loading already-parsed ASTs, traversing the AST, associating
53 * physical source locations with elements within the AST, and other
54 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000055 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000056 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000057 * representation stored in Clang's C++ AST, nor should it: the intent is to
58 * maintain an API that is relatively stable from one release to the next,
59 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000060 *
61 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000062 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000063 *
64 * @{
65 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000066
Douglas Gregor7f173762010-01-20 22:28:27 +000067/**
68 * \brief An "index" that consists of a set of translation units that would
69 * typically be linked together into an executable or library.
70 */
71typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000072
Douglas Gregor7f173762010-01-20 22:28:27 +000073/**
74 * \brief A single translation unit, which resides in an index.
75 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000076typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000077
Douglas Gregor7f173762010-01-20 22:28:27 +000078/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000079 * \brief Opaque pointer representing client data that will be passed through
80 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000081 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000082typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000083
Douglas Gregor735df882009-12-02 09:21:34 +000084/**
85 * \brief Provides the contents of a file that has not yet been saved to disk.
86 *
87 * Each CXUnsavedFile instance provides the name of a file on the
88 * system along with the current contents of that file that have not
89 * yet been saved to disk.
90 */
91struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000092 /**
93 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000094 *
95 * This file must already exist in the file system.
96 */
97 const char *Filename;
98
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000099 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000100 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +0000101 */
102 const char *Contents;
103
104 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +0000105 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +0000106 */
107 unsigned long Length;
108};
109
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000110/**
111 * \brief Describes the availability of a particular entity, which indicates
112 * whether the use of this entity will result in a warning or error due to
113 * it being deprecated or unavailable.
114 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000115enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000116 /**
117 * \brief The entity is available.
118 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000119 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000120 /**
121 * \brief The entity is available, but has been deprecated (and its use is
122 * not recommended).
123 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000124 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000125 /**
126 * \brief The entity is not available; any use of it will be an error.
127 */
Erik Verbruggend1205962011-10-06 07:27:49 +0000128 CXAvailability_NotAvailable,
129 /**
130 * \brief The entity is available, but not accessible; any use of it will be
131 * an error.
132 */
133 CXAvailability_NotAccessible
Douglas Gregor58ddb602010-08-23 23:00:57 +0000134};
135
Douglas Gregor7f173762010-01-20 22:28:27 +0000136/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000137 * \defgroup CINDEX_STRING String manipulation routines
138 *
139 * @{
140 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000141
Douglas Gregor7f173762010-01-20 22:28:27 +0000142/**
143 * \brief A character string.
144 *
145 * The \c CXString type is used to return strings from the interface when
146 * the ownership of that string might different from one call to the next.
147 * Use \c clang_getCString() to retrieve the string data and, once finished
148 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000149 */
150typedef struct {
Ted Kremeneka60ed472010-11-16 08:15:36 +0000151 void *data;
Ted Kremeneked122732010-11-16 01:56:27 +0000152 unsigned private_flags;
Steve Naroffef0cef62009-11-09 17:45:52 +0000153} CXString;
154
Douglas Gregor7f173762010-01-20 22:28:27 +0000155/**
156 * \brief Retrieve the character data associated with the given string.
157 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000158CINDEX_LINKAGE const char *clang_getCString(CXString string);
159
Douglas Gregor7f173762010-01-20 22:28:27 +0000160/**
161 * \brief Free the given string,
162 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000163CINDEX_LINKAGE void clang_disposeString(CXString string);
164
Douglas Gregor7f173762010-01-20 22:28:27 +0000165/**
166 * @}
167 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000168
169/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000170 * \brief clang_createIndex() provides a shared context for creating
171 * translation units. It provides two options:
172 *
173 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
174 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000175 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000176 * header that was used by the translation unit. If zero, all declarations
177 * will be enumerated.
178 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000179 * Here is an example:
180 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000181 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
182 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000183 *
184 * // IndexTest.pch was produced with the following command:
185 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
186 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
187 *
188 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000189 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000190 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000191 * clang_disposeTranslationUnit(TU);
192 *
193 * // This will load all the symbols from 'IndexTest.c', excluding symbols
194 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000195 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
196 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
197 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000198 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
199 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000200 * clang_disposeTranslationUnit(TU);
201 *
202 * This process of creating the 'pch', loading it separately, and using it (via
203 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
204 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000205 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000206CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
207 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000208
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000209/**
210 * \brief Destroy the given index.
211 *
212 * The index must not be destroyed until all of the translation units created
213 * within that index have been destroyed.
214 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000215CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000216
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +0000217typedef enum {
218 /**
219 * \brief Used to indicate that no special CXIndex options are needed.
220 */
221 CXGlobalOpt_None = 0x0,
222
223 /**
224 * \brief Used to indicate that threads that libclang creates for indexing
225 * purposes should use background priority.
226 * Affects \see clang_indexSourceFile, \see clang_indexTranslationUnit,
227 * \see clang_parseTranslationUnit, \see clang_saveTranslationUnit.
228 */
229 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
230
231 /**
232 * \brief Used to indicate that threads that libclang creates for editing
233 * purposes should use background priority.
234 * Affects \see clang_reparseTranslationUnit, \see clang_codeCompleteAt,
235 * \see clang_annotateTokens
236 */
237 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
238
239 /**
240 * \brief Used to indicate that all threads that libclang creates should use
241 * background priority.
242 */
243 CXGlobalOpt_ThreadBackgroundPriorityForAll =
244 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
245 CXGlobalOpt_ThreadBackgroundPriorityForEditing
246
247} CXGlobalOptFlags;
248
249/**
250 * \brief Sets general options associated with a CXIndex.
251 *
252 * For example:
253 * \code
254 * CXIndex idx = ...;
255 * clang_CXIndex_setGlobalOptions(idx,
256 * clang_CXIndex_getGlobalOptions(idx) |
257 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
258 * \endcode
259 *
260 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
261 */
262CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
263
264/**
265 * \brief Gets the general options associated with a CXIndex.
266 *
267 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
268 * are associated with the given CXIndex object.
269 */
270CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
271
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000272/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000273 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000274 *
275 * @{
276 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000277
Douglas Gregorf5525442010-01-20 22:45:41 +0000278/**
279 * \brief A particular source file that is part of a translation unit.
280 */
281typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000282
Douglas Gregorf5525442010-01-20 22:45:41 +0000283
284/**
285 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000286 */
Ted Kremenek74844072010-02-17 00:41:20 +0000287CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000288
Douglas Gregorf5525442010-01-20 22:45:41 +0000289/**
290 * \brief Retrieve the last modification time of the given file.
291 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000292CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000293
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000294/**
Douglas Gregordd3e5542011-05-04 00:14:37 +0000295 * \brief Determine whether the given header is guarded against
296 * multiple inclusions, either with the conventional
297 * #ifndef/#define/#endif macro guards or with #pragma once.
298 */
299CINDEX_LINKAGE unsigned
300clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
301
302/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000303 * \brief Retrieve a file handle within the given translation unit.
304 *
305 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000306 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000307 * \param file_name the name of the file.
308 *
309 * \returns the file handle for the named file in the translation unit \p tu,
310 * or a NULL file handle if the file was not a part of this translation unit.
311 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000312CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000313 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000314
Douglas Gregorb9790342010-01-22 21:44:22 +0000315/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000316 * @}
317 */
318
319/**
320 * \defgroup CINDEX_LOCATIONS Physical source locations
321 *
322 * Clang represents physical source locations in its abstract syntax tree in
323 * great detail, with file, line, and column information for the majority of
324 * the tokens parsed in the source code. These data types and functions are
325 * used to represent source location information, either for a particular
326 * point in the program or for a range of points in the program, and extract
327 * specific location information from those data types.
328 *
329 * @{
330 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000331
Douglas Gregorf5525442010-01-20 22:45:41 +0000332/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000333 * \brief Identifies a specific source location within a translation
334 * unit.
335 *
Chandler Carruth20174222011-08-31 16:53:37 +0000336 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregora9b06d42010-11-09 06:24:54 +0000337 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000338 */
339typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000340 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000341 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000342} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000343
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000344/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000345 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000346 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000347 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
348 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000349 */
350typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000351 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000352 unsigned begin_int_data;
353 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000354} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000355
Douglas Gregor1db19de2010-01-19 21:36:55 +0000356/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000357 * \brief Retrieve a NULL (invalid) source location.
358 */
359CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000360
Douglas Gregorb9790342010-01-22 21:44:22 +0000361/**
362 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000363 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000364 * code.
365 *
366 * \returns non-zero if the source locations refer to the same location, zero
367 * if they refer to different locations.
368 */
369CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
370 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000371
Douglas Gregorb9790342010-01-22 21:44:22 +0000372/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000373 * \brief Retrieves the source location associated with a given file/line/column
374 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000375 */
376CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
377 CXFile file,
378 unsigned line,
379 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000380/**
381 * \brief Retrieves the source location associated with a given character offset
382 * in a particular translation unit.
383 */
384CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
385 CXFile file,
386 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000387
Douglas Gregorb9790342010-01-22 21:44:22 +0000388/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000389 * \brief Retrieve a NULL (invalid) source range.
390 */
391CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000392
Douglas Gregor5352ac02010-01-28 00:27:43 +0000393/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000394 * \brief Retrieve a source range given the beginning and ending source
395 * locations.
396 */
397CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
398 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000399
Douglas Gregorb9790342010-01-22 21:44:22 +0000400/**
Douglas Gregorab4e83b2011-07-23 19:35:14 +0000401 * \brief Determine whether two ranges are equivalent.
402 *
403 * \returns non-zero if the ranges are the same, zero if they differ.
404 */
405CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
406 CXSourceRange range2);
407
408/**
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000409 * \brief Returns non-zero if \arg range is null.
410 */
Erik Verbruggen733dbc82011-10-06 12:11:57 +0000411CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000412
413/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000414 * \brief Retrieve the file, line, column, and offset represented by
415 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000416 *
Chandler Carruth20174222011-08-31 16:53:37 +0000417 * If the location refers into a macro expansion, retrieves the
418 * location of the macro expansion.
Douglas Gregora9b06d42010-11-09 06:24:54 +0000419 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000420 * \param location the location within a source file that will be decomposed
421 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000422 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000423 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000424 * source location points.
425 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000426 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000427 * source location points.
428 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000429 * \param column [out] if non-NULL, will be set to the column to which the given
430 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000431 *
432 * \param offset [out] if non-NULL, will be set to the offset into the
433 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000434 */
Chandler Carruth20174222011-08-31 16:53:37 +0000435CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
436 CXFile *file,
437 unsigned *line,
438 unsigned *column,
439 unsigned *offset);
440
441/**
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000442 * \brief Retrieve the file, line, column, and offset represented by
443 * the given source location, as specified in a # line directive.
444 *
445 * Example: given the following source code in a file somefile.c
446 *
447 * #123 "dummy.c" 1
448 *
449 * static int func(void)
450 * {
451 * return 0;
452 * }
453 *
454 * the location information returned by this function would be
455 *
456 * File: dummy.c Line: 124 Column: 12
457 *
458 * whereas clang_getExpansionLocation would have returned
459 *
460 * File: somefile.c Line: 3 Column: 12
461 *
462 * \param location the location within a source file that will be decomposed
463 * into its parts.
464 *
465 * \param filename [out] if non-NULL, will be set to the filename of the
466 * source location. Note that filenames returned will be for "virtual" files,
467 * which don't necessarily exist on the machine running clang - e.g. when
468 * parsing preprocessed output obtained from a different environment. If
469 * a non-NULL value is passed in, remember to dispose of the returned value
470 * using \c clang_disposeString() once you've finished with it. For an invalid
471 * source location, an empty string is returned.
472 *
473 * \param line [out] if non-NULL, will be set to the line number of the
474 * source location. For an invalid source location, zero is returned.
475 *
476 * \param column [out] if non-NULL, will be set to the column number of the
477 * source location. For an invalid source location, zero is returned.
478 */
479CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
480 CXString *filename,
481 unsigned *line,
482 unsigned *column);
483
484/**
Chandler Carruth20174222011-08-31 16:53:37 +0000485 * \brief Legacy API to retrieve the file, line, column, and offset represented
486 * by the given source location.
487 *
488 * This interface has been replaced by the newer interface
489 * \see clang_getExpansionLocation(). See that interface's documentation for
490 * details.
491 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000492CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
493 CXFile *file,
494 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000495 unsigned *column,
496 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000497
498/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000499 * \brief Retrieve the file, line, column, and offset represented by
500 * the given source location.
501 *
502 * If the location refers into a macro instantiation, return where the
503 * location was originally spelled in the source file.
504 *
505 * \param location the location within a source file that will be decomposed
506 * into its parts.
507 *
508 * \param file [out] if non-NULL, will be set to the file to which the given
509 * source location points.
510 *
511 * \param line [out] if non-NULL, will be set to the line to which the given
512 * source location points.
513 *
514 * \param column [out] if non-NULL, will be set to the column to which the given
515 * source location points.
516 *
517 * \param offset [out] if non-NULL, will be set to the offset into the
518 * buffer to which the given source location points.
519 */
520CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
521 CXFile *file,
522 unsigned *line,
523 unsigned *column,
524 unsigned *offset);
525
526/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000527 * \brief Retrieve a source location representing the first character within a
528 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000529 */
530CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
531
532/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000533 * \brief Retrieve a source location representing the last character within a
534 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000535 */
536CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
537
Douglas Gregorf5525442010-01-20 22:45:41 +0000538/**
539 * @}
540 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000541
542/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000543 * \defgroup CINDEX_DIAG Diagnostic reporting
544 *
545 * @{
546 */
547
548/**
549 * \brief Describes the severity of a particular diagnostic.
550 */
551enum CXDiagnosticSeverity {
552 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000553 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000554 * option.
555 */
556 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000557
Douglas Gregor5352ac02010-01-28 00:27:43 +0000558 /**
559 * \brief This diagnostic is a note that should be attached to the
560 * previous (non-note) diagnostic.
561 */
562 CXDiagnostic_Note = 1,
563
564 /**
565 * \brief This diagnostic indicates suspicious code that may not be
566 * wrong.
567 */
568 CXDiagnostic_Warning = 2,
569
570 /**
571 * \brief This diagnostic indicates that the code is ill-formed.
572 */
573 CXDiagnostic_Error = 3,
574
575 /**
576 * \brief This diagnostic indicates that the code is ill-formed such
577 * that future parser recovery is unlikely to produce useful
578 * results.
579 */
580 CXDiagnostic_Fatal = 4
581};
582
583/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000584 * \brief A single diagnostic, containing the diagnostic's severity,
585 * location, text, source ranges, and fix-it hints.
586 */
587typedef void *CXDiagnostic;
588
589/**
Ted Kremenek15322172011-11-10 08:43:12 +0000590 * \brief A group of CXDiagnostics.
591 */
592typedef void *CXDiagnosticSet;
593
594/**
595 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
596 */
597CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
598
599/**
600 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
601 *
602 * \param Unit the CXDiagnosticSet to query.
603 * \param Index the zero-based diagnostic number to retrieve.
604 *
605 * \returns the requested diagnostic. This diagnostic must be freed
606 * via a call to \c clang_disposeDiagnostic().
607 */
608CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
609 unsigned Index);
610
611
612/**
613 * \brief Describes the kind of error that occurred (if any) in a call to
614 * \c clang_loadDiagnostics.
615 */
616enum CXLoadDiag_Error {
617 /**
618 * \brief Indicates that no error occurred.
619 */
620 CXLoadDiag_None = 0,
621
622 /**
623 * \brief Indicates that an unknown error occurred while attempting to
624 * deserialize diagnostics.
625 */
626 CXLoadDiag_Unknown = 1,
627
628 /**
629 * \brief Indicates that the file containing the serialized diagnostics
630 * could not be opened.
631 */
632 CXLoadDiag_CannotLoad = 2,
633
634 /**
635 * \brief Indicates that the serialized diagnostics file is invalid or
636 * corrupt.
637 */
638 CXLoadDiag_InvalidFile = 3
639};
640
641/**
642 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
643 * file.
644 *
645 * \param The name of the file to deserialize.
646 * \param A pointer to a enum value recording if there was a problem
647 * deserializing the diagnostics.
648 * \param A pointer to a CXString for recording the error string
649 * if the file was not successfully loaded.
650 *
651 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
652 * diagnostics should be released using clang_disposeDiagnosticSet().
653 */
654CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
655 enum CXLoadDiag_Error *error,
656 CXString *errorString);
657
658/**
659 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
660 */
661CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
662
663/**
664 * \brief Retrieve the child diagnostics of a CXDiagnostic. This
665 * CXDiagnosticSet does not need to be released by clang_diposeDiagnosticSet.
666 */
667CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
668
669/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000670 * \brief Determine the number of diagnostics produced for the given
671 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000672 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000673CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
674
675/**
676 * \brief Retrieve a diagnostic associated with the given translation unit.
677 *
678 * \param Unit the translation unit to query.
679 * \param Index the zero-based diagnostic number to retrieve.
680 *
681 * \returns the requested diagnostic. This diagnostic must be freed
682 * via a call to \c clang_disposeDiagnostic().
683 */
684CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
685 unsigned Index);
686
687/**
Ted Kremenek0373fcc2011-12-09 22:28:32 +0000688 * \brief Retrieve the complete set of diagnostics associated with a
689 * translation unit.
690 *
691 * \param Unit the translation unit to query.
692 */
693CINDEX_LINKAGE CXDiagnosticSet
694 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
695
696/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000697 * \brief Destroy a diagnostic.
698 */
699CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000700
701/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000702 * \brief Options to control the display of diagnostics.
703 *
704 * The values in this enum are meant to be combined to customize the
705 * behavior of \c clang_displayDiagnostic().
706 */
707enum CXDiagnosticDisplayOptions {
708 /**
709 * \brief Display the source-location information where the
710 * diagnostic was located.
711 *
712 * When set, diagnostics will be prefixed by the file, line, and
713 * (optionally) column to which the diagnostic refers. For example,
714 *
715 * \code
716 * test.c:28: warning: extra tokens at end of #endif directive
717 * \endcode
718 *
719 * This option corresponds to the clang flag \c -fshow-source-location.
720 */
721 CXDiagnostic_DisplaySourceLocation = 0x01,
722
723 /**
724 * \brief If displaying the source-location information of the
725 * diagnostic, also include the column number.
726 *
727 * This option corresponds to the clang flag \c -fshow-column.
728 */
729 CXDiagnostic_DisplayColumn = 0x02,
730
731 /**
732 * \brief If displaying the source-location information of the
733 * diagnostic, also include information about source ranges in a
734 * machine-parsable format.
735 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000736 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000737 * \c -fdiagnostics-print-source-range-info.
738 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000739 CXDiagnostic_DisplaySourceRanges = 0x04,
740
741 /**
742 * \brief Display the option name associated with this diagnostic, if any.
743 *
744 * The option name displayed (e.g., -Wconversion) will be placed in brackets
745 * after the diagnostic text. This option corresponds to the clang flag
746 * \c -fdiagnostics-show-option.
747 */
748 CXDiagnostic_DisplayOption = 0x08,
749
750 /**
751 * \brief Display the category number associated with this diagnostic, if any.
752 *
753 * The category number is displayed within brackets after the diagnostic text.
754 * This option corresponds to the clang flag
755 * \c -fdiagnostics-show-category=id.
756 */
757 CXDiagnostic_DisplayCategoryId = 0x10,
758
759 /**
760 * \brief Display the category name associated with this diagnostic, if any.
761 *
762 * The category name is displayed within brackets after the diagnostic text.
763 * This option corresponds to the clang flag
764 * \c -fdiagnostics-show-category=name.
765 */
766 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000767};
768
769/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000770 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000771 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000772 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000773 * the diagnostic according to the various options given. The
774 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000775 * options that most closely mimics the behavior of the clang compiler.
776 *
777 * \param Diagnostic The diagnostic to print.
778 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000779 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000780 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000781 *
782 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000783 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000784CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
785 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000786
787/**
788 * \brief Retrieve the set of display options most similar to the
789 * default behavior of the clang compiler.
790 *
791 * \returns A set of display options suitable for use with \c
792 * clang_displayDiagnostic().
793 */
794CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
795
796/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000797 * \brief Determine the severity of the given diagnostic.
798 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000799CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000800clang_getDiagnosticSeverity(CXDiagnostic);
801
802/**
803 * \brief Retrieve the source location of the given diagnostic.
804 *
805 * This location is where Clang would print the caret ('^') when
806 * displaying the diagnostic on the command line.
807 */
808CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
809
810/**
811 * \brief Retrieve the text of the given diagnostic.
812 */
813CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000814
815/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000816 * \brief Retrieve the name of the command-line option that enabled this
817 * diagnostic.
818 *
819 * \param Diag The diagnostic to be queried.
820 *
821 * \param Disable If non-NULL, will be set to the option that disables this
822 * diagnostic (if any).
823 *
824 * \returns A string that contains the command-line option used to enable this
825 * warning, such as "-Wconversion" or "-pedantic".
826 */
827CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
828 CXString *Disable);
829
830/**
831 * \brief Retrieve the category number for this diagnostic.
832 *
833 * Diagnostics can be categorized into groups along with other, related
834 * diagnostics (e.g., diagnostics under the same warning flag). This routine
835 * retrieves the category number for the given diagnostic.
836 *
837 * \returns The number of the category that contains this diagnostic, or zero
838 * if this diagnostic is uncategorized.
839 */
840CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
841
842/**
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000843 * \brief Retrieve the name of a particular diagnostic category. This
844 * is now deprecated. Use clang_getDiagnosticCategoryText()
845 * instead.
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000846 *
847 * \param Category A diagnostic category number, as returned by
848 * \c clang_getDiagnosticCategory().
849 *
850 * \returns The name of the given diagnostic category.
851 */
Ted Kremenek78d5d3b2012-04-12 00:03:31 +0000852CINDEX_DEPRECATED CINDEX_LINKAGE
853CXString clang_getDiagnosticCategoryName(unsigned Category);
854
855/**
856 * \brief Retrieve the diagnostic category text for a given diagnostic.
857 *
858 *
859 * \returns The text of the given diagnostic category.
860 */
861CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000862
863/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000864 * \brief Determine the number of source ranges associated with the given
865 * diagnostic.
866 */
867CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000868
Douglas Gregor5352ac02010-01-28 00:27:43 +0000869/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000870 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000871 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000872 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000873 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000874 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000875 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000876 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000877 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000878 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000879 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000880 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000881 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000882CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000883 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000884
885/**
886 * \brief Determine the number of fix-it hints associated with the
887 * given diagnostic.
888 */
889CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
890
891/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000892 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000893 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000894 * Fix-its are described in terms of a source range whose contents
895 * should be replaced by a string. This approach generalizes over
896 * three kinds of operations: removal of source code (the range covers
897 * the code to be removed and the replacement string is empty),
898 * replacement of source code (the range covers the code to be
899 * replaced and the replacement string provides the new code), and
900 * insertion (both the start and end of the range point at the
901 * insertion location, and the replacement string provides the text to
902 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000903 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000904 * \param Diagnostic The diagnostic whose fix-its are being queried.
905 *
906 * \param FixIt The zero-based index of the fix-it.
907 *
908 * \param ReplacementRange The source range whose contents will be
909 * replaced with the returned replacement string. Note that source
910 * ranges are half-open ranges [a, b), so the source code should be
911 * replaced from a and up to (but not including) b.
912 *
913 * \returns A string containing text that should be replace the source
914 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000915 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000916CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000917 unsigned FixIt,
918 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000919
920/**
921 * @}
922 */
923
924/**
925 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
926 *
927 * The routines in this group provide the ability to create and destroy
928 * translation units from files, either by parsing the contents of the files or
929 * by reading in a serialized representation of a translation unit.
930 *
931 * @{
932 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000933
Douglas Gregor5352ac02010-01-28 00:27:43 +0000934/**
935 * \brief Get the original translation unit source file name.
936 */
937CINDEX_LINKAGE CXString
938clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
939
940/**
941 * \brief Return the CXTranslationUnit for a given source file and the provided
942 * command line arguments one would pass to the compiler.
943 *
944 * Note: The 'source_filename' argument is optional. If the caller provides a
945 * NULL pointer, the name of the source file is expected to reside in the
946 * specified command line arguments.
947 *
948 * Note: When encountered in 'clang_command_line_args', the following options
949 * are ignored:
950 *
951 * '-c'
952 * '-emit-ast'
953 * '-fsyntax-only'
954 * '-o <output file>' (both '-o' and '<output file>' are ignored)
955 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000956 * \param CIdx The index object with which the translation unit will be
957 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000958 *
959 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000960 * source file is included in \p clang_command_line_args.
961 *
962 * \param num_clang_command_line_args The number of command-line arguments in
963 * \p clang_command_line_args.
964 *
965 * \param clang_command_line_args The command-line arguments that would be
966 * passed to the \c clang executable if it were being invoked out-of-process.
967 * These command-line options will be parsed and will affect how the translation
968 * unit is parsed. Note that the following options are ignored: '-c',
969 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000970 *
971 * \param num_unsaved_files the number of unsaved file entries in \p
972 * unsaved_files.
973 *
974 * \param unsaved_files the files that have not yet been saved to disk
975 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000976 * those files. The contents and name of these files (as specified by
977 * CXUnsavedFile) are copied when necessary, so the client only needs to
978 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000979 */
980CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
981 CXIndex CIdx,
982 const char *source_filename,
983 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000984 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000985 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000986 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000987
Douglas Gregor5352ac02010-01-28 00:27:43 +0000988/**
989 * \brief Create a translation unit from an AST file (-emit-ast).
990 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000991CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000992 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000993
Douglas Gregor44c181a2010-07-23 00:33:23 +0000994/**
995 * \brief Flags that control the creation of translation units.
996 *
997 * The enumerators in this enumeration type are meant to be bitwise
998 * ORed together to specify which options should be used when
999 * constructing the translation unit.
1000 */
Douglas Gregor5a430212010-07-21 18:52:53 +00001001enum CXTranslationUnit_Flags {
1002 /**
1003 * \brief Used to indicate that no special translation-unit options are
1004 * needed.
1005 */
1006 CXTranslationUnit_None = 0x0,
1007
1008 /**
1009 * \brief Used to indicate that the parser should construct a "detailed"
1010 * preprocessing record, including all macro definitions and instantiations.
1011 *
1012 * Constructing a detailed preprocessing record requires more memory
1013 * and time to parse, since the information contained in the record
1014 * is usually not retained. However, it can be useful for
1015 * applications that require more detailed information about the
1016 * behavior of the preprocessor.
1017 */
Douglas Gregor44c181a2010-07-23 00:33:23 +00001018 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1019
1020 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001021 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001022 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001023 * When a translation unit is considered "incomplete", semantic
1024 * analysis that is typically performed at the end of the
1025 * translation unit will be suppressed. For example, this suppresses
1026 * the completion of tentative declarations in C and of
1027 * instantiation of implicitly-instantiation function templates in
1028 * C++. This option is typically used when parsing a header with the
1029 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +00001030 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001031 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +00001032
1033 /**
1034 * \brief Used to indicate that the translation unit should be built with an
1035 * implicit precompiled header for the preamble.
1036 *
1037 * An implicit precompiled header is used as an optimization when a
1038 * particular translation unit is likely to be reparsed many times
1039 * when the sources aren't changing that often. In this case, an
1040 * implicit precompiled header will be built containing all of the
1041 * initial includes at the top of the main file (what we refer to as
1042 * the "preamble" of the file). In subsequent parses, if the
1043 * preamble or the files in it have not changed, \c
1044 * clang_reparseTranslationUnit() will re-use the implicit
1045 * precompiled header to improve parsing performance.
1046 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001047 CXTranslationUnit_PrecompiledPreamble = 0x04,
1048
1049 /**
1050 * \brief Used to indicate that the translation unit should cache some
1051 * code-completion results with each reparse of the source file.
1052 *
1053 * Caching of code-completion results is a performance optimization that
1054 * introduces some overhead to reparsing but improves the performance of
1055 * code-completion operations.
1056 */
Douglas Gregor99ba2022010-10-27 17:24:53 +00001057 CXTranslationUnit_CacheCompletionResults = 0x08,
1058 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001059 * \brief DEPRECATED: Enable precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001060 *
1061 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001062 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001063 */
1064 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
1065
1066 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +00001067 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001068 *
1069 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +00001070 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +00001071 */
Erik Verbruggen6a91d382012-04-12 10:11:59 +00001072 CXTranslationUnit_CXXChainedPCH = 0x20,
1073
1074 /**
1075 * \brief Used to indicate that function/method bodies should be skipped while
1076 * parsing.
1077 *
1078 * This option can be used to search for declarations/definitions while
1079 * ignoring the usages.
1080 */
1081 CXTranslationUnit_SkipFunctionBodies = 0x40
Douglas Gregor5a430212010-07-21 18:52:53 +00001082};
1083
1084/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001085 * \brief Returns the set of flags that is suitable for parsing a translation
1086 * unit that is being edited.
1087 *
1088 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1089 * to indicate that the translation unit is likely to be reparsed many times,
1090 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1091 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1092 * set contains an unspecified set of optimizations (e.g., the precompiled
1093 * preamble) geared toward improving the performance of these routines. The
1094 * set of optimizations enabled may change from one version to the next.
1095 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001096CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001097
1098/**
Douglas Gregor5a430212010-07-21 18:52:53 +00001099 * \brief Parse the given source file and the translation unit corresponding
1100 * to that file.
1101 *
1102 * This routine is the main entry point for the Clang C API, providing the
1103 * ability to parse a source file into a translation unit that can then be
1104 * queried by other functions in the API. This routine accepts a set of
1105 * command-line arguments so that the compilation can be configured in the same
1106 * way that the compiler is configured on the command line.
1107 *
1108 * \param CIdx The index object with which the translation unit will be
1109 * associated.
1110 *
1111 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001112 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +00001113 *
1114 * \param command_line_args The command-line arguments that would be
1115 * passed to the \c clang executable if it were being invoked out-of-process.
1116 * These command-line options will be parsed and will affect how the translation
1117 * unit is parsed. Note that the following options are ignored: '-c',
1118 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
1119 *
1120 * \param num_command_line_args The number of command-line arguments in
1121 * \p command_line_args.
1122 *
1123 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00001124 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +00001125 * those files. The contents and name of these files (as specified by
1126 * CXUnsavedFile) are copied when necessary, so the client only needs to
1127 * guarantee their validity until the call to this function returns.
1128 *
1129 * \param num_unsaved_files the number of unsaved file entries in \p
1130 * unsaved_files.
1131 *
1132 * \param options A bitmask of options that affects how the translation unit
1133 * is managed but not its compilation. This should be a bitwise OR of the
1134 * CXTranslationUnit_XXX flags.
1135 *
1136 * \returns A new translation unit describing the parsed code and containing
1137 * any diagnostics produced by the compiler. If there is a failure from which
1138 * the compiler cannot recover, returns NULL.
1139 */
1140CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1141 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001142 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +00001143 int num_command_line_args,
1144 struct CXUnsavedFile *unsaved_files,
1145 unsigned num_unsaved_files,
1146 unsigned options);
1147
Douglas Gregor5352ac02010-01-28 00:27:43 +00001148/**
Douglas Gregor19998442010-08-13 15:35:05 +00001149 * \brief Flags that control how translation units are saved.
1150 *
1151 * The enumerators in this enumeration type are meant to be bitwise
1152 * ORed together to specify which options should be used when
1153 * saving the translation unit.
1154 */
1155enum CXSaveTranslationUnit_Flags {
1156 /**
1157 * \brief Used to indicate that no special saving options are needed.
1158 */
1159 CXSaveTranslationUnit_None = 0x0
1160};
1161
1162/**
1163 * \brief Returns the set of flags that is suitable for saving a translation
1164 * unit.
1165 *
1166 * The set of flags returned provide options for
1167 * \c clang_saveTranslationUnit() by default. The returned flag
1168 * set contains an unspecified set of options that save translation units with
1169 * the most commonly-requested data.
1170 */
1171CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1172
1173/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001174 * \brief Describes the kind of error that occurred (if any) in a call to
1175 * \c clang_saveTranslationUnit().
1176 */
1177enum CXSaveError {
1178 /**
1179 * \brief Indicates that no error occurred while saving a translation unit.
1180 */
1181 CXSaveError_None = 0,
1182
1183 /**
1184 * \brief Indicates that an unknown error occurred while attempting to save
1185 * the file.
1186 *
1187 * This error typically indicates that file I/O failed when attempting to
1188 * write the file.
1189 */
1190 CXSaveError_Unknown = 1,
1191
1192 /**
1193 * \brief Indicates that errors during translation prevented this attempt
1194 * to save the translation unit.
1195 *
1196 * Errors that prevent the translation unit from being saved can be
1197 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1198 */
1199 CXSaveError_TranslationErrors = 2,
1200
1201 /**
1202 * \brief Indicates that the translation unit to be saved was somehow
1203 * invalid (e.g., NULL).
1204 */
1205 CXSaveError_InvalidTU = 3
1206};
1207
1208/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001209 * \brief Saves a translation unit into a serialized representation of
1210 * that translation unit on disk.
1211 *
1212 * Any translation unit that was parsed without error can be saved
1213 * into a file. The translation unit can then be deserialized into a
1214 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1215 * if it is an incomplete translation unit that corresponds to a
1216 * header, used as a precompiled header when parsing other translation
1217 * units.
1218 *
1219 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001220 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001221 * \param FileName The file to which the translation unit will be saved.
1222 *
Douglas Gregor19998442010-08-13 15:35:05 +00001223 * \param options A bitmask of options that affects how the translation unit
1224 * is saved. This should be a bitwise OR of the
1225 * CXSaveTranslationUnit_XXX flags.
1226 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001227 * \returns A value that will match one of the enumerators of the CXSaveError
1228 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1229 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001230 */
1231CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001232 const char *FileName,
1233 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001234
1235/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001236 * \brief Destroy the specified CXTranslationUnit object.
1237 */
1238CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001239
Douglas Gregor5352ac02010-01-28 00:27:43 +00001240/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001241 * \brief Flags that control the reparsing of translation units.
1242 *
1243 * The enumerators in this enumeration type are meant to be bitwise
1244 * ORed together to specify which options should be used when
1245 * reparsing the translation unit.
1246 */
1247enum CXReparse_Flags {
1248 /**
1249 * \brief Used to indicate that no special reparsing options are needed.
1250 */
1251 CXReparse_None = 0x0
1252};
1253
1254/**
1255 * \brief Returns the set of flags that is suitable for reparsing a translation
1256 * unit.
1257 *
1258 * The set of flags returned provide options for
1259 * \c clang_reparseTranslationUnit() by default. The returned flag
1260 * set contains an unspecified set of optimizations geared toward common uses
1261 * of reparsing. The set of optimizations enabled may change from one version
1262 * to the next.
1263 */
1264CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1265
1266/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001267 * \brief Reparse the source files that produced this translation unit.
1268 *
1269 * This routine can be used to re-parse the source files that originally
1270 * created the given translation unit, for example because those source files
1271 * have changed (either on disk or as passed via \p unsaved_files). The
1272 * source code will be reparsed with the same command-line options as it
1273 * was originally parsed.
1274 *
1275 * Reparsing a translation unit invalidates all cursors and source locations
1276 * that refer into that translation unit. This makes reparsing a translation
1277 * unit semantically equivalent to destroying the translation unit and then
1278 * creating a new translation unit with the same command-line arguments.
1279 * However, it may be more efficient to reparse a translation
1280 * unit using this routine.
1281 *
1282 * \param TU The translation unit whose contents will be re-parsed. The
1283 * translation unit must originally have been built with
1284 * \c clang_createTranslationUnitFromSourceFile().
1285 *
1286 * \param num_unsaved_files The number of unsaved file entries in \p
1287 * unsaved_files.
1288 *
1289 * \param unsaved_files The files that have not yet been saved to disk
1290 * but may be required for parsing, including the contents of
1291 * those files. The contents and name of these files (as specified by
1292 * CXUnsavedFile) are copied when necessary, so the client only needs to
1293 * guarantee their validity until the call to this function returns.
1294 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001295 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1296 * The function \c clang_defaultReparseOptions() produces a default set of
1297 * options recommended for most uses, based on the translation unit.
1298 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001299 * \returns 0 if the sources could be reparsed. A non-zero value will be
1300 * returned if reparsing was impossible, such that the translation unit is
1301 * invalid. In such cases, the only valid call for \p TU is
1302 * \c clang_disposeTranslationUnit(TU).
1303 */
1304CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1305 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001306 struct CXUnsavedFile *unsaved_files,
1307 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001308
1309/**
1310 * \brief Categorizes how memory is being used by a translation unit.
1311 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001312enum CXTUResourceUsageKind {
1313 CXTUResourceUsage_AST = 1,
1314 CXTUResourceUsage_Identifiers = 2,
1315 CXTUResourceUsage_Selectors = 3,
1316 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001317 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001318 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001319 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001320 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1321 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1322 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001323 CXTUResourceUsage_Preprocessor = 11,
1324 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001325 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001326 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001327 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1328 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001329 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001330
1331 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001332 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001333};
1334
1335/**
1336 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001337 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001338 */
1339CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001340const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001341
Ted Kremenekf7870022011-04-20 16:41:07 +00001342typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001343 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001344 enum CXTUResourceUsageKind kind;
1345 /* \brief Amount of resources used.
1346 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001347 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001348} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001349
1350/**
1351 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1352 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001353typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001354 /* \brief Private data member, used for queries. */
1355 void *data;
1356
1357 /* \brief The number of entries in the 'entries' array. */
1358 unsigned numEntries;
1359
1360 /* \brief An array of key-value pairs, representing the breakdown of memory
1361 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001362 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001363
Ted Kremenekf7870022011-04-20 16:41:07 +00001364} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001365
1366/**
1367 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001368 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001369 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001370CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001371
Ted Kremenekf7870022011-04-20 16:41:07 +00001372CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001373
Douglas Gregorabc563f2010-07-19 21:46:24 +00001374/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001375 * @}
1376 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001377
Douglas Gregor5352ac02010-01-28 00:27:43 +00001378/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001379 * \brief Describes the kind of entity that a cursor refers to.
1380 */
1381enum CXCursorKind {
1382 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001383 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001384 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001385 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001386 *
1387 * Unexposed declarations have the same operations as any other kind
1388 * of declaration; one can extract their location information,
1389 * spelling, find their definitions, etc. However, the specific kind
1390 * of the declaration is not reported.
1391 */
1392 CXCursor_UnexposedDecl = 1,
1393 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001394 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001395 /** \brief A C or C++ union. */
1396 CXCursor_UnionDecl = 3,
1397 /** \brief A C++ class. */
1398 CXCursor_ClassDecl = 4,
1399 /** \brief An enumeration. */
1400 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001401 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001402 * \brief A field (in C) or non-static data member (in C++) in a
1403 * struct, union, or C++ class.
1404 */
1405 CXCursor_FieldDecl = 6,
1406 /** \brief An enumerator constant. */
1407 CXCursor_EnumConstantDecl = 7,
1408 /** \brief A function. */
1409 CXCursor_FunctionDecl = 8,
1410 /** \brief A variable. */
1411 CXCursor_VarDecl = 9,
1412 /** \brief A function or method parameter. */
1413 CXCursor_ParmDecl = 10,
1414 /** \brief An Objective-C @interface. */
1415 CXCursor_ObjCInterfaceDecl = 11,
1416 /** \brief An Objective-C @interface for a category. */
1417 CXCursor_ObjCCategoryDecl = 12,
1418 /** \brief An Objective-C @protocol declaration. */
1419 CXCursor_ObjCProtocolDecl = 13,
1420 /** \brief An Objective-C @property declaration. */
1421 CXCursor_ObjCPropertyDecl = 14,
1422 /** \brief An Objective-C instance variable. */
1423 CXCursor_ObjCIvarDecl = 15,
1424 /** \brief An Objective-C instance method. */
1425 CXCursor_ObjCInstanceMethodDecl = 16,
1426 /** \brief An Objective-C class method. */
1427 CXCursor_ObjCClassMethodDecl = 17,
1428 /** \brief An Objective-C @implementation. */
1429 CXCursor_ObjCImplementationDecl = 18,
1430 /** \brief An Objective-C @implementation for a category. */
1431 CXCursor_ObjCCategoryImplDecl = 19,
1432 /** \brief A typedef */
1433 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001434 /** \brief A C++ class method. */
1435 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001436 /** \brief A C++ namespace. */
1437 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001438 /** \brief A linkage specification, e.g. 'extern "C"'. */
1439 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001440 /** \brief A C++ constructor. */
1441 CXCursor_Constructor = 24,
1442 /** \brief A C++ destructor. */
1443 CXCursor_Destructor = 25,
1444 /** \brief A C++ conversion function. */
1445 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001446 /** \brief A C++ template type parameter. */
1447 CXCursor_TemplateTypeParameter = 27,
1448 /** \brief A C++ non-type template parameter. */
1449 CXCursor_NonTypeTemplateParameter = 28,
1450 /** \brief A C++ template template parameter. */
1451 CXCursor_TemplateTemplateParameter = 29,
1452 /** \brief A C++ function template. */
1453 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001454 /** \brief A C++ class template. */
1455 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001456 /** \brief A C++ class template partial specialization. */
1457 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001458 /** \brief A C++ namespace alias declaration. */
1459 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001460 /** \brief A C++ using directive. */
1461 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001462 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001463 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001464 /** \brief A C++ alias declaration */
1465 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001466 /** \brief An Objective-C @synthesize definition. */
1467 CXCursor_ObjCSynthesizeDecl = 37,
1468 /** \brief An Objective-C @dynamic definition. */
1469 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001470 /** \brief An access specifier. */
1471 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor42b29842011-10-05 19:00:14 +00001472
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001473 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001474 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001475
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001476 /* References */
1477 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001478 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001479 CXCursor_ObjCProtocolRef = 41,
1480 CXCursor_ObjCClassRef = 42,
1481 /**
1482 * \brief A reference to a type declaration.
1483 *
1484 * A type reference occurs anywhere where a type is named but not
1485 * declared. For example, given:
1486 *
1487 * \code
1488 * typedef unsigned size_type;
1489 * size_type size;
1490 * \endcode
1491 *
1492 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1493 * while the type of the variable "size" is referenced. The cursor
1494 * referenced by the type of size is the typedef for size_type.
1495 */
1496 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001497 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001498 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001499 * \brief A reference to a class template, function template, template
1500 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001501 */
1502 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001503 /**
1504 * \brief A reference to a namespace or namespace alias.
1505 */
1506 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001507 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001508 * \brief A reference to a member of a struct, union, or class that occurs in
1509 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001510 */
1511 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001512 /**
1513 * \brief A reference to a labeled statement.
1514 *
1515 * This cursor kind is used to describe the jump to "start_over" in the
1516 * goto statement in the following example:
1517 *
1518 * \code
1519 * start_over:
1520 * ++counter;
1521 *
1522 * goto start_over;
1523 * \endcode
1524 *
1525 * A label reference cursor refers to a label statement.
1526 */
1527 CXCursor_LabelRef = 48,
1528
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001529 /**
1530 * \brief A reference to a set of overloaded functions or function templates
1531 * that has not yet been resolved to a specific function or function template.
1532 *
1533 * An overloaded declaration reference cursor occurs in C++ templates where
1534 * a dependent name refers to a function. For example:
1535 *
1536 * \code
1537 * template<typename T> void swap(T&, T&);
1538 *
1539 * struct X { ... };
1540 * void swap(X&, X&);
1541 *
1542 * template<typename T>
1543 * void reverse(T* first, T* last) {
1544 * while (first < last - 1) {
1545 * swap(*first, *--last);
1546 * ++first;
1547 * }
1548 * }
1549 *
1550 * struct Y { };
1551 * void swap(Y&, Y&);
1552 * \endcode
1553 *
1554 * Here, the identifier "swap" is associated with an overloaded declaration
1555 * reference. In the template definition, "swap" refers to either of the two
1556 * "swap" functions declared above, so both results will be available. At
1557 * instantiation time, "swap" may also refer to other functions found via
1558 * argument-dependent lookup (e.g., the "swap" function at the end of the
1559 * example).
1560 *
1561 * The functions \c clang_getNumOverloadedDecls() and
1562 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1563 * referenced by this cursor.
1564 */
1565 CXCursor_OverloadedDeclRef = 49,
1566
Douglas Gregor011d8b92012-02-15 00:54:55 +00001567 /**
1568 * \brief A reference to a variable that occurs in some non-expression
1569 * context, e.g., a C++ lambda capture list.
1570 */
1571 CXCursor_VariableRef = 50,
1572
1573 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001574
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001575 /* Error conditions */
1576 CXCursor_FirstInvalid = 70,
1577 CXCursor_InvalidFile = 70,
1578 CXCursor_NoDeclFound = 71,
1579 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001580 CXCursor_InvalidCode = 73,
1581 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001582
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001583 /* Expressions */
1584 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001585
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001586 /**
1587 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001588 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001589 *
1590 * Unexposed expressions have the same operations as any other kind
1591 * of expression; one can extract their location information,
1592 * spelling, children, etc. However, the specific kind of the
1593 * expression is not reported.
1594 */
1595 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001596
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001597 /**
1598 * \brief An expression that refers to some value declaration, such
1599 * as a function, varible, or enumerator.
1600 */
1601 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001602
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001603 /**
1604 * \brief An expression that refers to a member of a struct, union,
1605 * class, Objective-C class, etc.
1606 */
1607 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001608
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001609 /** \brief An expression that calls a function. */
1610 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001611
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001612 /** \brief An expression that sends a message to an Objective-C
1613 object or class. */
1614 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001615
1616 /** \brief An expression that represents a block literal. */
1617 CXCursor_BlockExpr = 105,
1618
Douglas Gregor42b29842011-10-05 19:00:14 +00001619 /** \brief An integer literal.
1620 */
1621 CXCursor_IntegerLiteral = 106,
1622
1623 /** \brief A floating point number literal.
1624 */
1625 CXCursor_FloatingLiteral = 107,
1626
1627 /** \brief An imaginary number literal.
1628 */
1629 CXCursor_ImaginaryLiteral = 108,
1630
1631 /** \brief A string literal.
1632 */
1633 CXCursor_StringLiteral = 109,
1634
1635 /** \brief A character literal.
1636 */
1637 CXCursor_CharacterLiteral = 110,
1638
1639 /** \brief A parenthesized expression, e.g. "(1)".
1640 *
1641 * This AST node is only formed if full location information is requested.
1642 */
1643 CXCursor_ParenExpr = 111,
1644
1645 /** \brief This represents the unary-expression's (except sizeof and
1646 * alignof).
1647 */
1648 CXCursor_UnaryOperator = 112,
1649
1650 /** \brief [C99 6.5.2.1] Array Subscripting.
1651 */
1652 CXCursor_ArraySubscriptExpr = 113,
1653
1654 /** \brief A builtin binary operation expression such as "x + y" or
1655 * "x <= y".
1656 */
1657 CXCursor_BinaryOperator = 114,
1658
1659 /** \brief Compound assignment such as "+=".
1660 */
1661 CXCursor_CompoundAssignOperator = 115,
1662
1663 /** \brief The ?: ternary operator.
1664 */
1665 CXCursor_ConditionalOperator = 116,
1666
1667 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1668 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1669 *
1670 * For example: (int)f.
1671 */
1672 CXCursor_CStyleCastExpr = 117,
1673
1674 /** \brief [C99 6.5.2.5]
1675 */
1676 CXCursor_CompoundLiteralExpr = 118,
1677
1678 /** \brief Describes an C or C++ initializer list.
1679 */
1680 CXCursor_InitListExpr = 119,
1681
1682 /** \brief The GNU address of label extension, representing &&label.
1683 */
1684 CXCursor_AddrLabelExpr = 120,
1685
1686 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1687 */
1688 CXCursor_StmtExpr = 121,
1689
Benjamin Kramerffbe9b92011-12-23 17:00:35 +00001690 /** \brief Represents a C11 generic selection.
Douglas Gregor42b29842011-10-05 19:00:14 +00001691 */
1692 CXCursor_GenericSelectionExpr = 122,
1693
1694 /** \brief Implements the GNU __null extension, which is a name for a null
1695 * pointer constant that has integral type (e.g., int or long) and is the same
1696 * size and alignment as a pointer.
1697 *
1698 * The __null extension is typically only used by system headers, which define
1699 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1700 * match the size of a pointer).
1701 */
1702 CXCursor_GNUNullExpr = 123,
1703
1704 /** \brief C++'s static_cast<> expression.
1705 */
1706 CXCursor_CXXStaticCastExpr = 124,
1707
1708 /** \brief C++'s dynamic_cast<> expression.
1709 */
1710 CXCursor_CXXDynamicCastExpr = 125,
1711
1712 /** \brief C++'s reinterpret_cast<> expression.
1713 */
1714 CXCursor_CXXReinterpretCastExpr = 126,
1715
1716 /** \brief C++'s const_cast<> expression.
1717 */
1718 CXCursor_CXXConstCastExpr = 127,
1719
1720 /** \brief Represents an explicit C++ type conversion that uses "functional"
1721 * notion (C++ [expr.type.conv]).
1722 *
1723 * Example:
1724 * \code
1725 * x = int(0.5);
1726 * \endcode
1727 */
1728 CXCursor_CXXFunctionalCastExpr = 128,
1729
1730 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1731 */
1732 CXCursor_CXXTypeidExpr = 129,
1733
1734 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1735 */
1736 CXCursor_CXXBoolLiteralExpr = 130,
1737
1738 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1739 */
1740 CXCursor_CXXNullPtrLiteralExpr = 131,
1741
1742 /** \brief Represents the "this" expression in C++
1743 */
1744 CXCursor_CXXThisExpr = 132,
1745
1746 /** \brief [C++ 15] C++ Throw Expression.
1747 *
1748 * This handles 'throw' and 'throw' assignment-expression. When
1749 * assignment-expression isn't present, Op will be null.
1750 */
1751 CXCursor_CXXThrowExpr = 133,
1752
1753 /** \brief A new expression for memory allocation and constructor calls, e.g:
1754 * "new CXXNewExpr(foo)".
1755 */
1756 CXCursor_CXXNewExpr = 134,
1757
1758 /** \brief A delete expression for memory deallocation and destructor calls,
1759 * e.g. "delete[] pArray".
1760 */
1761 CXCursor_CXXDeleteExpr = 135,
1762
1763 /** \brief A unary expression.
1764 */
1765 CXCursor_UnaryExpr = 136,
1766
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001767 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor42b29842011-10-05 19:00:14 +00001768 */
1769 CXCursor_ObjCStringLiteral = 137,
1770
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001771 /** \brief An Objective-C @encode expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001772 */
1773 CXCursor_ObjCEncodeExpr = 138,
1774
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001775 /** \brief An Objective-C @selector expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001776 */
1777 CXCursor_ObjCSelectorExpr = 139,
1778
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001779 /** \brief An Objective-C @protocol expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001780 */
1781 CXCursor_ObjCProtocolExpr = 140,
1782
1783 /** \brief An Objective-C "bridged" cast expression, which casts between
1784 * Objective-C pointers and C pointers, transferring ownership in the process.
1785 *
1786 * \code
1787 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1788 * \endcode
1789 */
1790 CXCursor_ObjCBridgedCastExpr = 141,
1791
1792 /** \brief Represents a C++0x pack expansion that produces a sequence of
1793 * expressions.
1794 *
1795 * A pack expansion expression contains a pattern (which itself is an
1796 * expression) followed by an ellipsis. For example:
1797 *
1798 * \code
1799 * template<typename F, typename ...Types>
1800 * void forward(F f, Types &&...args) {
1801 * f(static_cast<Types&&>(args)...);
1802 * }
1803 * \endcode
1804 */
1805 CXCursor_PackExpansionExpr = 142,
1806
1807 /** \brief Represents an expression that computes the length of a parameter
1808 * pack.
1809 *
1810 * \code
1811 * template<typename ...Types>
1812 * struct count {
1813 * static const unsigned value = sizeof...(Types);
1814 * };
1815 * \endcode
1816 */
1817 CXCursor_SizeOfPackExpr = 143,
1818
Douglas Gregor011d8b92012-02-15 00:54:55 +00001819 /* \brief Represents a C++ lambda expression that produces a local function
1820 * object.
1821 *
1822 * \code
1823 * void abssort(float *x, unsigned N) {
1824 * std::sort(x, x + N,
1825 * [](float a, float b) {
1826 * return std::abs(a) < std::abs(b);
1827 * });
1828 * }
1829 * \endcode
1830 */
1831 CXCursor_LambdaExpr = 144,
1832
Ted Kremenekb3f75422012-03-06 20:06:06 +00001833 /** \brief Objective-c Boolean Literal.
1834 */
1835 CXCursor_ObjCBoolLiteralExpr = 145,
1836
1837 CXCursor_LastExpr = CXCursor_ObjCBoolLiteralExpr,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001838
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001839 /* Statements */
1840 CXCursor_FirstStmt = 200,
1841 /**
1842 * \brief A statement whose specific kind is not exposed via this
1843 * interface.
1844 *
1845 * Unexposed statements have the same operations as any other kind of
1846 * statement; one can extract their location information, spelling,
1847 * children, etc. However, the specific kind of the statement is not
1848 * reported.
1849 */
1850 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001851
1852 /** \brief A labelled statement in a function.
1853 *
1854 * This cursor kind is used to describe the "start_over:" label statement in
1855 * the following example:
1856 *
1857 * \code
1858 * start_over:
1859 * ++counter;
1860 * \endcode
1861 *
1862 */
1863 CXCursor_LabelStmt = 201,
Douglas Gregor42b29842011-10-05 19:00:14 +00001864
1865 /** \brief A group of statements like { stmt stmt }.
1866 *
1867 * This cursor kind is used to describe compound statements, e.g. function
1868 * bodies.
1869 */
1870 CXCursor_CompoundStmt = 202,
1871
1872 /** \brief A case statment.
1873 */
1874 CXCursor_CaseStmt = 203,
1875
1876 /** \brief A default statement.
1877 */
1878 CXCursor_DefaultStmt = 204,
1879
1880 /** \brief An if statement
1881 */
1882 CXCursor_IfStmt = 205,
1883
1884 /** \brief A switch statement.
1885 */
1886 CXCursor_SwitchStmt = 206,
1887
1888 /** \brief A while statement.
1889 */
1890 CXCursor_WhileStmt = 207,
1891
1892 /** \brief A do statement.
1893 */
1894 CXCursor_DoStmt = 208,
1895
1896 /** \brief A for statement.
1897 */
1898 CXCursor_ForStmt = 209,
1899
1900 /** \brief A goto statement.
1901 */
1902 CXCursor_GotoStmt = 210,
1903
1904 /** \brief An indirect goto statement.
1905 */
1906 CXCursor_IndirectGotoStmt = 211,
1907
1908 /** \brief A continue statement.
1909 */
1910 CXCursor_ContinueStmt = 212,
1911
1912 /** \brief A break statement.
1913 */
1914 CXCursor_BreakStmt = 213,
1915
1916 /** \brief A return statement.
1917 */
1918 CXCursor_ReturnStmt = 214,
1919
1920 /** \brief A GNU inline assembly statement extension.
1921 */
1922 CXCursor_AsmStmt = 215,
1923
Douglas Gregor3f54d482011-11-08 21:07:04 +00001924 /** \brief Objective-C's overall @try-@catch-@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001925 */
1926 CXCursor_ObjCAtTryStmt = 216,
1927
1928 /** \brief Objective-C's @catch statement.
1929 */
1930 CXCursor_ObjCAtCatchStmt = 217,
1931
1932 /** \brief Objective-C's @finally statement.
1933 */
1934 CXCursor_ObjCAtFinallyStmt = 218,
1935
1936 /** \brief Objective-C's @throw statement.
1937 */
1938 CXCursor_ObjCAtThrowStmt = 219,
1939
1940 /** \brief Objective-C's @synchronized statement.
1941 */
1942 CXCursor_ObjCAtSynchronizedStmt = 220,
1943
1944 /** \brief Objective-C's autorelease pool statement.
1945 */
1946 CXCursor_ObjCAutoreleasePoolStmt = 221,
1947
1948 /** \brief Objective-C's collection statement.
1949 */
1950 CXCursor_ObjCForCollectionStmt = 222,
1951
1952 /** \brief C++'s catch statement.
1953 */
1954 CXCursor_CXXCatchStmt = 223,
1955
1956 /** \brief C++'s try statement.
1957 */
1958 CXCursor_CXXTryStmt = 224,
1959
1960 /** \brief C++'s for (* : *) statement.
1961 */
1962 CXCursor_CXXForRangeStmt = 225,
1963
1964 /** \brief Windows Structured Exception Handling's try statement.
1965 */
1966 CXCursor_SEHTryStmt = 226,
1967
1968 /** \brief Windows Structured Exception Handling's except statement.
1969 */
1970 CXCursor_SEHExceptStmt = 227,
1971
1972 /** \brief Windows Structured Exception Handling's finally statement.
1973 */
1974 CXCursor_SEHFinallyStmt = 228,
1975
1976 /** \brief The null satement ";": C99 6.8.3p3.
1977 *
1978 * This cursor kind is used to describe the null statement.
1979 */
1980 CXCursor_NullStmt = 230,
1981
1982 /** \brief Adaptor class for mixing declarations with statements and
1983 * expressions.
1984 */
1985 CXCursor_DeclStmt = 231,
1986
1987 CXCursor_LastStmt = CXCursor_DeclStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001988
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001989 /**
1990 * \brief Cursor that represents the translation unit itself.
1991 *
1992 * The translation unit cursor exists primarily to act as the root
1993 * cursor for traversing the contents of a translation unit.
1994 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001995 CXCursor_TranslationUnit = 300,
1996
1997 /* Attributes */
1998 CXCursor_FirstAttr = 400,
1999 /**
2000 * \brief An attribute whose specific kind is not exposed via this
2001 * interface.
2002 */
2003 CXCursor_UnexposedAttr = 400,
2004
2005 CXCursor_IBActionAttr = 401,
2006 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00002007 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00002008 CXCursor_CXXFinalAttr = 404,
2009 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002010 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002011 CXCursor_AsmLabelAttr = 407,
2012 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002013
2014 /* Preprocessing */
2015 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00002016 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00002017 CXCursor_MacroExpansion = 502,
2018 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002019 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002020 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00002021 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002022};
2023
2024/**
2025 * \brief A cursor representing some element in the abstract syntax tree for
2026 * a translation unit.
2027 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002028 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002029 * program--declaration, statements, expressions, references to declarations,
2030 * etc.--under a single "cursor" abstraction with a common set of operations.
2031 * Common operation for a cursor include: getting the physical location in
2032 * a source file where the cursor points, getting the name associated with a
2033 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2034 *
2035 * Cursors can be produced in two specific ways.
2036 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2037 * from which one can use clang_visitChildren() to explore the rest of the
2038 * translation unit. clang_getCursor() maps from a physical source location
2039 * to the entity that resides at that location, allowing one to map from the
2040 * source code into the AST.
2041 */
2042typedef struct {
2043 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00002044 int xdata;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002045 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002046} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002047
2048/**
2049 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2050 *
2051 * @{
2052 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002053
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002054/**
2055 * \brief Retrieve the NULL cursor, which represents no entity.
2056 */
2057CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002058
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002059/**
2060 * \brief Retrieve the cursor that represents the given translation unit.
2061 *
2062 * The translation unit cursor can be used to start traversing the
2063 * various declarations within the given translation unit.
2064 */
2065CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2066
2067/**
2068 * \brief Determine whether two cursors are equivalent.
2069 */
2070CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002071
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002072/**
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002073 * \brief Returns non-zero if \arg cursor is null.
2074 */
Benjamin Kramer5b419362012-02-01 20:37:28 +00002075CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002076
2077/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00002078 * \brief Compute a hash value for the given cursor.
2079 */
2080CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2081
2082/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002083 * \brief Retrieve the kind of the given cursor.
2084 */
2085CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2086
2087/**
2088 * \brief Determine whether the given cursor kind represents a declaration.
2089 */
2090CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2091
2092/**
2093 * \brief Determine whether the given cursor kind represents a simple
2094 * reference.
2095 *
2096 * Note that other kinds of cursors (such as expressions) can also refer to
2097 * other cursors. Use clang_getCursorReferenced() to determine whether a
2098 * particular cursor refers to another entity.
2099 */
2100CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2101
2102/**
2103 * \brief Determine whether the given cursor kind represents an expression.
2104 */
2105CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2106
2107/**
2108 * \brief Determine whether the given cursor kind represents a statement.
2109 */
2110CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2111
2112/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002113 * \brief Determine whether the given cursor kind represents an attribute.
2114 */
2115CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2116
2117/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002118 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002119 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002120 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002121CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2122
2123/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002124 * \brief Determine whether the given cursor kind represents a translation
2125 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002126 */
2127CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002128
Ted Kremenekad6eff62010-03-08 21:17:29 +00002129/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002130 * \brief Determine whether the given cursor represents a preprocessing
2131 * element, such as a preprocessor directive or macro instantiation.
2132 */
2133CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2134
2135/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002136 * \brief Determine whether the given cursor represents a currently
2137 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2138 */
2139CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2140
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002141/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002142 * \brief Describe the linkage of the entity referred to by a cursor.
2143 */
2144enum CXLinkageKind {
2145 /** \brief This value indicates that no linkage information is available
2146 * for a provided CXCursor. */
2147 CXLinkage_Invalid,
2148 /**
2149 * \brief This is the linkage for variables, parameters, and so on that
2150 * have automatic storage. This covers normal (non-extern) local variables.
2151 */
2152 CXLinkage_NoLinkage,
2153 /** \brief This is the linkage for static variables and static functions. */
2154 CXLinkage_Internal,
2155 /** \brief This is the linkage for entities with external linkage that live
2156 * in C++ anonymous namespaces.*/
2157 CXLinkage_UniqueExternal,
2158 /** \brief This is the linkage for entities with true, external linkage. */
2159 CXLinkage_External
2160};
2161
2162/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002163 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002164 */
2165CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2166
2167/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002168 * \brief Determine the availability of the entity that this cursor refers to.
2169 *
2170 * \param cursor The cursor to query.
2171 *
2172 * \returns The availability of the cursor.
2173 */
2174CINDEX_LINKAGE enum CXAvailabilityKind
2175clang_getCursorAvailability(CXCursor cursor);
2176
2177/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002178 * \brief Describe the "language" of the entity referred to by a cursor.
2179 */
2180CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002181 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002182 CXLanguage_C,
2183 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002184 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002185};
2186
2187/**
2188 * \brief Determine the "language" of the entity referred to by a given cursor.
2189 */
2190CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2191
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002192/**
2193 * \brief Returns the translation unit that a cursor originated from.
2194 */
2195CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2196
Ted Kremenekeca099b2010-12-08 23:43:14 +00002197
2198/**
2199 * \brief A fast container representing a set of CXCursors.
2200 */
2201typedef struct CXCursorSetImpl *CXCursorSet;
2202
2203/**
2204 * \brief Creates an empty CXCursorSet.
2205 */
2206CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2207
2208/**
2209 * \brief Disposes a CXCursorSet and releases its associated memory.
2210 */
2211CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2212
2213/**
2214 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2215 *
2216 * \returns non-zero if the set contains the specified cursor.
2217*/
2218CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2219 CXCursor cursor);
2220
2221/**
2222 * \brief Inserts a CXCursor into a CXCursorSet.
2223 *
2224 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2225*/
2226CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2227 CXCursor cursor);
2228
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002229/**
2230 * \brief Determine the semantic parent of the given cursor.
2231 *
2232 * The semantic parent of a cursor is the cursor that semantically contains
2233 * the given \p cursor. For many declarations, the lexical and semantic parents
2234 * are equivalent (the lexical parent is returned by
2235 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2236 * definitions are provided out-of-line. For example:
2237 *
2238 * \code
2239 * class C {
2240 * void f();
2241 * };
2242 *
2243 * void C::f() { }
2244 * \endcode
2245 *
2246 * In the out-of-line definition of \c C::f, the semantic parent is the
2247 * the class \c C, of which this function is a member. The lexical parent is
2248 * the place where the declaration actually occurs in the source code; in this
2249 * case, the definition occurs in the translation unit. In general, the
2250 * lexical parent for a given entity can change without affecting the semantics
2251 * of the program, and the lexical parent of different declarations of the
2252 * same entity may be different. Changing the semantic parent of a declaration,
2253 * on the other hand, can have a major impact on semantics, and redeclarations
2254 * of a particular entity should all have the same semantic context.
2255 *
2256 * In the example above, both declarations of \c C::f have \c C as their
2257 * semantic context, while the lexical context of the first \c C::f is \c C
2258 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002259 *
2260 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002261 */
2262CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2263
2264/**
2265 * \brief Determine the lexical parent of the given cursor.
2266 *
2267 * The lexical parent of a cursor is the cursor in which the given \p cursor
2268 * was actually written. For many declarations, the lexical and semantic parents
2269 * are equivalent (the semantic parent is returned by
2270 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2271 * definitions are provided out-of-line. For example:
2272 *
2273 * \code
2274 * class C {
2275 * void f();
2276 * };
2277 *
2278 * void C::f() { }
2279 * \endcode
2280 *
2281 * In the out-of-line definition of \c C::f, the semantic parent is the
2282 * the class \c C, of which this function is a member. The lexical parent is
2283 * the place where the declaration actually occurs in the source code; in this
2284 * case, the definition occurs in the translation unit. In general, the
2285 * lexical parent for a given entity can change without affecting the semantics
2286 * of the program, and the lexical parent of different declarations of the
2287 * same entity may be different. Changing the semantic parent of a declaration,
2288 * on the other hand, can have a major impact on semantics, and redeclarations
2289 * of a particular entity should all have the same semantic context.
2290 *
2291 * In the example above, both declarations of \c C::f have \c C as their
2292 * semantic context, while the lexical context of the first \c C::f is \c C
2293 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002294 *
2295 * For declarations written in the global scope, the lexical parent is
2296 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002297 */
2298CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002299
2300/**
2301 * \brief Determine the set of methods that are overridden by the given
2302 * method.
2303 *
2304 * In both Objective-C and C++, a method (aka virtual member function,
2305 * in C++) can override a virtual method in a base class. For
2306 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002307 * base class, its protocols, or its categories' protocols, that has the same
2308 * selector and is of the same kind (class or instance).
2309 * If no such method exists, the search continues to the class's superclass,
2310 * its protocols, and its categories, and so on. A method from an Objective-C
2311 * implementation is considered to override the same methods as its
2312 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002313 *
2314 * For C++, a virtual member function overrides any virtual member
2315 * function with the same signature that occurs in its base
2316 * classes. With multiple inheritance, a virtual member function can
2317 * override several virtual member functions coming from different
2318 * base classes.
2319 *
2320 * In all cases, this function determines the immediate overridden
2321 * method, rather than all of the overridden methods. For example, if
2322 * a method is originally declared in a class A, then overridden in B
2323 * (which in inherits from A) and also in C (which inherited from B),
2324 * then the only overridden method returned from this function when
2325 * invoked on C's method will be B's method. The client may then
2326 * invoke this function again, given the previously-found overridden
2327 * methods, to map out the complete method-override set.
2328 *
2329 * \param cursor A cursor representing an Objective-C or C++
2330 * method. This routine will compute the set of methods that this
2331 * method overrides.
2332 *
2333 * \param overridden A pointer whose pointee will be replaced with a
2334 * pointer to an array of cursors, representing the set of overridden
2335 * methods. If there are no overridden methods, the pointee will be
2336 * set to NULL. The pointee must be freed via a call to
2337 * \c clang_disposeOverriddenCursors().
2338 *
2339 * \param num_overridden A pointer to the number of overridden
2340 * functions, will be set to the number of overridden functions in the
2341 * array pointed to by \p overridden.
2342 */
2343CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2344 CXCursor **overridden,
2345 unsigned *num_overridden);
2346
2347/**
2348 * \brief Free the set of overridden cursors returned by \c
2349 * clang_getOverriddenCursors().
2350 */
2351CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2352
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002353/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002354 * \brief Retrieve the file that is included by the given inclusion directive
2355 * cursor.
2356 */
2357CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2358
2359/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002360 * @}
2361 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002362
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002363/**
2364 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2365 *
2366 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2367 * routines help map between cursors and the physical locations where the
2368 * described entities occur in the source code. The mapping is provided in
2369 * both directions, so one can map from source code to the AST and back.
2370 *
2371 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002372 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002373
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002374/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002375 * \brief Map a source location to the cursor that describes the entity at that
2376 * location in the source code.
2377 *
2378 * clang_getCursor() maps an arbitrary source location within a translation
2379 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002380 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002381 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002382 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002383 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2384 * will return a cursor referring to the "+" expression.
2385 *
2386 * \returns a cursor representing the entity at the given source location, or
2387 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002388 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002389CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002390
Douglas Gregor98258af2010-01-18 22:46:11 +00002391/**
2392 * \brief Retrieve the physical location of the source constructor referenced
2393 * by the given cursor.
2394 *
2395 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002396 * declaration, where the name of that declaration would occur if it is
2397 * unnamed, or some keyword that introduces that particular declaration.
2398 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002399 * source code.
2400 */
2401CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002402
Douglas Gregorb6998662010-01-19 19:34:47 +00002403/**
2404 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002405 * the given cursor.
2406 *
2407 * The extent of a cursor starts with the file/line/column pointing at the
2408 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002409 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002410 * declaration, the extent covers the declaration itself. For a reference,
2411 * the extent covers the location of the reference (e.g., where the referenced
2412 * entity was actually used).
2413 */
2414CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002415
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002416/**
2417 * @}
2418 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002419
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002420/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002421 * \defgroup CINDEX_TYPES Type information for CXCursors
2422 *
2423 * @{
2424 */
2425
2426/**
2427 * \brief Describes the kind of type
2428 */
2429enum CXTypeKind {
2430 /**
2431 * \brief Reprents an invalid type (e.g., where no type is available).
2432 */
2433 CXType_Invalid = 0,
2434
2435 /**
2436 * \brief A type whose specific kind is not exposed via this
2437 * interface.
2438 */
2439 CXType_Unexposed = 1,
2440
2441 /* Builtin types */
2442 CXType_Void = 2,
2443 CXType_Bool = 3,
2444 CXType_Char_U = 4,
2445 CXType_UChar = 5,
2446 CXType_Char16 = 6,
2447 CXType_Char32 = 7,
2448 CXType_UShort = 8,
2449 CXType_UInt = 9,
2450 CXType_ULong = 10,
2451 CXType_ULongLong = 11,
2452 CXType_UInt128 = 12,
2453 CXType_Char_S = 13,
2454 CXType_SChar = 14,
2455 CXType_WChar = 15,
2456 CXType_Short = 16,
2457 CXType_Int = 17,
2458 CXType_Long = 18,
2459 CXType_LongLong = 19,
2460 CXType_Int128 = 20,
2461 CXType_Float = 21,
2462 CXType_Double = 22,
2463 CXType_LongDouble = 23,
2464 CXType_NullPtr = 24,
2465 CXType_Overload = 25,
2466 CXType_Dependent = 26,
2467 CXType_ObjCId = 27,
2468 CXType_ObjCClass = 28,
2469 CXType_ObjCSel = 29,
2470 CXType_FirstBuiltin = CXType_Void,
2471 CXType_LastBuiltin = CXType_ObjCSel,
2472
2473 CXType_Complex = 100,
2474 CXType_Pointer = 101,
2475 CXType_BlockPointer = 102,
2476 CXType_LValueReference = 103,
2477 CXType_RValueReference = 104,
2478 CXType_Record = 105,
2479 CXType_Enum = 106,
2480 CXType_Typedef = 107,
2481 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002482 CXType_ObjCObjectPointer = 109,
2483 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002484 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002485 CXType_ConstantArray = 112,
2486 CXType_Vector = 113
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002487};
2488
2489/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002490 * \brief Describes the calling convention of a function type
2491 */
2492enum CXCallingConv {
2493 CXCallingConv_Default = 0,
2494 CXCallingConv_C = 1,
2495 CXCallingConv_X86StdCall = 2,
2496 CXCallingConv_X86FastCall = 3,
2497 CXCallingConv_X86ThisCall = 4,
2498 CXCallingConv_X86Pascal = 5,
2499 CXCallingConv_AAPCS = 6,
2500 CXCallingConv_AAPCS_VFP = 7,
2501
2502 CXCallingConv_Invalid = 100,
2503 CXCallingConv_Unexposed = 200
2504};
2505
2506
2507/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002508 * \brief The type of an element in the abstract syntax tree.
2509 *
2510 */
2511typedef struct {
2512 enum CXTypeKind kind;
2513 void *data[2];
2514} CXType;
2515
2516/**
2517 * \brief Retrieve the type of a CXCursor (if any).
2518 */
2519CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2520
2521/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002522 * \brief Retrieve the underlying type of a typedef declaration.
2523 *
2524 * If the cursor does not reference a typedef declaration, an invalid type is
2525 * returned.
2526 */
2527CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2528
2529/**
2530 * \brief Retrieve the integer type of an enum declaration.
2531 *
2532 * If the cursor does not reference an enum declaration, an invalid type is
2533 * returned.
2534 */
2535CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2536
2537/**
2538 * \brief Retrieve the integer value of an enum constant declaration as a signed
2539 * long long.
2540 *
2541 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2542 * Since this is also potentially a valid constant value, the kind of the cursor
2543 * must be verified before calling this function.
2544 */
2545CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2546
2547/**
2548 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2549 * long long.
2550 *
2551 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2552 * Since this is also potentially a valid constant value, the kind of the cursor
2553 * must be verified before calling this function.
2554 */
2555CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2556
2557/**
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002558 * \brief Retrieve the number of non-variadic arguments associated with a given
2559 * cursor.
2560 *
2561 * If a cursor that is not a function or method is passed in, -1 is returned.
2562 */
2563CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2564
2565/**
2566 * \brief Retrieve the argument cursor of a function or method.
2567 *
2568 * If a cursor that is not a function or method is passed in or the index
2569 * exceeds the number of arguments, an invalid cursor is returned.
2570 */
2571CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2572
2573/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002574 * \determine Determine whether two CXTypes represent the same type.
2575 *
2576 * \returns non-zero if the CXTypes represent the same type and
2577 zero otherwise.
2578 */
2579CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2580
2581/**
2582 * \brief Return the canonical type for a CXType.
2583 *
2584 * Clang's type system explicitly models typedefs and all the ways
2585 * a specific type can be represented. The canonical type is the underlying
2586 * type with all the "sugar" removed. For example, if 'T' is a typedef
2587 * for 'int', the canonical type for 'T' would be 'int'.
2588 */
2589CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2590
2591/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002592 * \determine Determine whether a CXType has the "const" qualifier set,
2593 * without looking through typedefs that may have added "const" at a different level.
2594 */
2595CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2596
2597/**
2598 * \determine Determine whether a CXType has the "volatile" qualifier set,
2599 * without looking through typedefs that may have added "volatile" at a different level.
2600 */
2601CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2602
2603/**
2604 * \determine Determine whether a CXType has the "restrict" qualifier set,
2605 * without looking through typedefs that may have added "restrict" at a different level.
2606 */
2607CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2608
2609/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002610 * \brief For pointer types, returns the type of the pointee.
2611 *
2612 */
2613CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2614
2615/**
2616 * \brief Return the cursor for the declaration of the given type.
2617 */
2618CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2619
David Chisnall5389f482010-12-30 14:05:53 +00002620/**
2621 * Returns the Objective-C type encoding for the specified declaration.
2622 */
2623CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002624
2625/**
2626 * \brief Retrieve the spelling of a given CXTypeKind.
2627 */
2628CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2629
2630/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002631 * \brief Retrieve the calling convention associated with a function type.
2632 *
2633 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2634 */
2635CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2636
2637/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002638 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002639 *
2640 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002641 */
2642CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2643
2644/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002645 * \brief Retrieve the number of non-variadic arguments associated with a function type.
2646 *
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002647 * If a non-function type is passed in, -1 is returned.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002648 */
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00002649CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002650
2651/**
2652 * \brief Retrieve the type of an argument of a function type.
2653 *
2654 * If a non-function type is passed in or the function does not have enough parameters,
2655 * an invalid type is returned.
2656 */
2657CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2658
2659/**
2660 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2661 *
2662 */
2663CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2664
2665/**
2666 * \brief Retrieve the result type associated with a given cursor.
2667 *
2668 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002669 */
2670CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2671
2672/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002673 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2674 * otherwise.
2675 */
2676CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2677
2678/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002679 * \brief Return the element type of an array, complex, or vector type.
2680 *
2681 * If a type is passed in that is not an array, complex, or vector type,
2682 * an invalid type is returned.
2683 */
2684CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2685
2686/**
2687 * \brief Return the number of elements of an array or vector type.
2688 *
2689 * If a type is passed in that is not an array or vector type,
2690 * -1 is returned.
2691 */
2692CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2693
2694/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002695 * \brief Return the element type of an array type.
2696 *
2697 * If a non-array type is passed in, an invalid type is returned.
2698 */
2699CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2700
2701/**
2702 * \brief Return the the array size of a constant array.
2703 *
2704 * If a non-array type is passed in, -1 is returned.
2705 */
2706CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2707
2708/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002709 * \brief Returns 1 if the base class specified by the cursor with kind
2710 * CX_CXXBaseSpecifier is virtual.
2711 */
2712CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2713
2714/**
2715 * \brief Represents the C++ access control level to a base class for a
2716 * cursor with kind CX_CXXBaseSpecifier.
2717 */
2718enum CX_CXXAccessSpecifier {
2719 CX_CXXInvalidAccessSpecifier,
2720 CX_CXXPublic,
2721 CX_CXXProtected,
2722 CX_CXXPrivate
2723};
2724
2725/**
2726 * \brief Returns the access control level for the C++ base specifier
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00002727 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2728 * CXCursor_AccessSpecifier.
Ted Kremenek3064ef92010-08-27 21:34:58 +00002729 */
2730CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2731
2732/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002733 * \brief Determine the number of overloaded declarations referenced by a
2734 * \c CXCursor_OverloadedDeclRef cursor.
2735 *
2736 * \param cursor The cursor whose overloaded declarations are being queried.
2737 *
2738 * \returns The number of overloaded declarations referenced by \c cursor. If it
2739 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2740 */
2741CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2742
2743/**
2744 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2745 * by a \c CXCursor_OverloadedDeclRef cursor.
2746 *
2747 * \param cursor The cursor whose overloaded declarations are being queried.
2748 *
2749 * \param index The zero-based index into the set of overloaded declarations in
2750 * the cursor.
2751 *
2752 * \returns A cursor representing the declaration referenced by the given
2753 * \c cursor at the specified \c index. If the cursor does not have an
2754 * associated set of overloaded declarations, or if the index is out of bounds,
2755 * returns \c clang_getNullCursor();
2756 */
2757CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2758 unsigned index);
2759
2760/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002761 * @}
2762 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002763
2764/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002765 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002766 *
2767 * @{
2768 */
2769
2770
2771/**
2772 * \brief For cursors representing an iboutletcollection attribute,
2773 * this function returns the collection element type.
2774 *
2775 */
2776CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2777
2778/**
2779 * @}
2780 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002781
2782/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002783 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2784 *
2785 * These routines provide the ability to traverse the abstract syntax tree
2786 * using cursors.
2787 *
2788 * @{
2789 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002790
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002791/**
2792 * \brief Describes how the traversal of the children of a particular
2793 * cursor should proceed after visiting a particular child cursor.
2794 *
2795 * A value of this enumeration type should be returned by each
2796 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2797 */
2798enum CXChildVisitResult {
2799 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002800 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002801 */
2802 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002803 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002804 * \brief Continues the cursor traversal with the next sibling of
2805 * the cursor just visited, without visiting its children.
2806 */
2807 CXChildVisit_Continue,
2808 /**
2809 * \brief Recursively traverse the children of this cursor, using
2810 * the same visitor and client data.
2811 */
2812 CXChildVisit_Recurse
2813};
2814
2815/**
2816 * \brief Visitor invoked for each cursor found by a traversal.
2817 *
2818 * This visitor function will be invoked for each cursor found by
2819 * clang_visitCursorChildren(). Its first argument is the cursor being
2820 * visited, its second argument is the parent visitor for that cursor,
2821 * and its third argument is the client data provided to
2822 * clang_visitCursorChildren().
2823 *
2824 * The visitor should return one of the \c CXChildVisitResult values
2825 * to direct clang_visitCursorChildren().
2826 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002827typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2828 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002829 CXClientData client_data);
2830
2831/**
2832 * \brief Visit the children of a particular cursor.
2833 *
2834 * This function visits all the direct children of the given cursor,
2835 * invoking the given \p visitor function with the cursors of each
2836 * visited child. The traversal may be recursive, if the visitor returns
2837 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2838 * the visitor returns \c CXChildVisit_Break.
2839 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002840 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002841 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002842 * definition, have no children).
2843 *
2844 * \param visitor the visitor function that will be invoked for each
2845 * child of \p parent.
2846 *
2847 * \param client_data pointer data supplied by the client, which will
2848 * be passed to the visitor each time it is invoked.
2849 *
2850 * \returns a non-zero value if the traversal was terminated
2851 * prematurely by the visitor returning \c CXChildVisit_Break.
2852 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002853CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002854 CXCursorVisitor visitor,
2855 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002856#ifdef __has_feature
2857# if __has_feature(blocks)
2858/**
2859 * \brief Visitor invoked for each cursor found by a traversal.
2860 *
2861 * This visitor block will be invoked for each cursor found by
2862 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2863 * visited, its second argument is the parent visitor for that cursor.
2864 *
2865 * The visitor should return one of the \c CXChildVisitResult values
2866 * to direct clang_visitChildrenWithBlock().
2867 */
2868typedef enum CXChildVisitResult
2869 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2870
2871/**
2872 * Visits the children of a cursor using the specified block. Behaves
2873 * identically to clang_visitChildren() in all other respects.
2874 */
2875unsigned clang_visitChildrenWithBlock(CXCursor parent,
2876 CXCursorVisitorBlock block);
2877# endif
2878#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002879
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002880/**
2881 * @}
2882 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002883
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002884/**
2885 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2886 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002887 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002888 * across translation units, by providing the names of the entities referenced
2889 * by cursors, follow reference cursors to the declarations they reference,
2890 * and associate declarations with their definitions.
2891 *
2892 * @{
2893 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002894
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002895/**
2896 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2897 * by the given cursor.
2898 *
2899 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2900 * entity (function, class, variable, etc.) within a program. USRs can be
2901 * compared across translation units to determine, e.g., when references in
2902 * one translation refer to an entity defined in another translation unit.
2903 */
2904CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2905
2906/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002907 * \brief Construct a USR for a specified Objective-C class.
2908 */
2909CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2910
2911/**
2912 * \brief Construct a USR for a specified Objective-C category.
2913 */
2914CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002915 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002916 const char *category_name);
2917
2918/**
2919 * \brief Construct a USR for a specified Objective-C protocol.
2920 */
2921CINDEX_LINKAGE CXString
2922 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2923
2924
2925/**
2926 * \brief Construct a USR for a specified Objective-C instance variable and
2927 * the USR for its containing class.
2928 */
2929CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2930 CXString classUSR);
2931
2932/**
2933 * \brief Construct a USR for a specified Objective-C method and
2934 * the USR for its containing class.
2935 */
2936CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2937 unsigned isInstanceMethod,
2938 CXString classUSR);
2939
2940/**
2941 * \brief Construct a USR for a specified Objective-C property and the USR
2942 * for its containing class.
2943 */
2944CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2945 CXString classUSR);
2946
2947/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002948 * \brief Retrieve a name for the entity referenced by this cursor.
2949 */
2950CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2951
Douglas Gregor358559d2010-10-02 22:49:11 +00002952/**
Argyrios Kyrtzidisba1da142012-03-30 20:58:35 +00002953 * \brief Retrieve a range for a piece that forms the cursors spelling name.
2954 * Most of the times there is only one range for the complete spelling but for
2955 * objc methods and objc message expressions, there are multiple pieces for each
2956 * selector identifier.
2957 *
2958 * \param pieceIndex the index of the spelling name piece. If this is greater
2959 * than the actual number of pieces, it will return a NULL (invalid) range.
2960 *
2961 * \param options Reserved.
2962 */
2963CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
2964 unsigned pieceIndex,
2965 unsigned options);
2966
2967/**
Douglas Gregor358559d2010-10-02 22:49:11 +00002968 * \brief Retrieve the display name for the entity referenced by this cursor.
2969 *
2970 * The display name contains extra information that helps identify the cursor,
2971 * such as the parameters of a function or template or the arguments of a
2972 * class template specialization.
2973 */
2974CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2975
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002976/** \brief For a cursor that is a reference, retrieve a cursor representing the
2977 * entity that it references.
2978 *
2979 * Reference cursors refer to other entities in the AST. For example, an
2980 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002981 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002982 * cursor for the superclass reference. If the input cursor is a declaration or
2983 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002984 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002985 */
2986CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002987
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002988/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002989 * \brief For a cursor that is either a reference to or a declaration
2990 * of some entity, retrieve a cursor that describes the definition of
2991 * that entity.
2992 *
2993 * Some entities can be declared multiple times within a translation
2994 * unit, but only one of those declarations can also be a
2995 * definition. For example, given:
2996 *
2997 * \code
2998 * int f(int, int);
2999 * int g(int x, int y) { return f(x, y); }
3000 * int f(int a, int b) { return a + b; }
3001 * int f(int, int);
3002 * \endcode
3003 *
3004 * there are three declarations of the function "f", but only the
3005 * second one is a definition. The clang_getCursorDefinition()
3006 * function will take any cursor pointing to a declaration of "f"
3007 * (the first or fourth lines of the example) or a cursor referenced
3008 * that uses "f" (the call to "f' inside "g") and will return a
3009 * declaration cursor pointing to the definition (the second "f"
3010 * declaration).
3011 *
3012 * If given a cursor for which there is no corresponding definition,
3013 * e.g., because there is no definition of that entity within this
3014 * translation unit, returns a NULL cursor.
3015 */
3016CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3017
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003018/**
Douglas Gregorb6998662010-01-19 19:34:47 +00003019 * \brief Determine whether the declaration pointed to by this cursor
3020 * is also a definition of that entity.
3021 */
3022CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3023
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003024/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003025 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3026 *
3027 * In the C family of languages, many kinds of entities can be declared several
3028 * times within a single translation unit. For example, a structure type can
3029 * be forward-declared (possibly multiple times) and later defined:
3030 *
3031 * \code
3032 * struct X;
3033 * struct X;
3034 * struct X {
3035 * int member;
3036 * };
3037 * \endcode
3038 *
3039 * The declarations and the definition of \c X are represented by three
3040 * different cursors, all of which are declarations of the same underlying
3041 * entity. One of these cursor is considered the "canonical" cursor, which
3042 * is effectively the representative for the underlying entity. One can
3043 * determine if two cursors are declarations of the same underlying entity by
3044 * comparing their canonical cursors.
3045 *
3046 * \returns The canonical cursor for the entity referred to by the given cursor.
3047 */
3048CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3049
Argyrios Kyrtzidis34ebe1e2012-03-30 22:15:48 +00003050
3051/**
3052 * \brief If the cursor points to a selector identifier in a objc method or
3053 * message expression, this returns the selector index.
3054 *
3055 * After getting a cursor with \see clang_getCursor, this can be called to
3056 * determine if the location points to a selector identifier.
3057 *
3058 * \returns The selector index if the cursor is an objc method or message
3059 * expression and the cursor is pointing to a selector identifier, or -1
3060 * otherwise.
3061 */
3062CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3063
Douglas Gregor1a9d0502010-11-19 23:44:15 +00003064/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003065 * @}
3066 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003067
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003068/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003069 * \defgroup CINDEX_CPP C++ AST introspection
3070 *
3071 * The routines in this group provide access information in the ASTs specific
3072 * to C++ language features.
3073 *
3074 * @{
3075 */
3076
3077/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003078 * \brief Determine if a C++ member function or member function template is
3079 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003080 */
3081CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3082
3083/**
Douglas Gregor211924b2011-05-12 15:17:24 +00003084 * \brief Determine if a C++ member function or member function template is
3085 * explicitly declared 'virtual' or if it overrides a virtual method from
3086 * one of the base classes.
3087 */
3088CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3089
3090/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00003091 * \brief Given a cursor that represents a template, determine
3092 * the cursor kind of the specializations would be generated by instantiating
3093 * the template.
3094 *
3095 * This routine can be used to determine what flavor of function template,
3096 * class template, or class template partial specialization is stored in the
3097 * cursor. For example, it can describe whether a class template cursor is
3098 * declared with "struct", "class" or "union".
3099 *
3100 * \param C The cursor to query. This cursor should represent a template
3101 * declaration.
3102 *
3103 * \returns The cursor kind of the specializations that would be generated
3104 * by instantiating the template \p C. If \p C is not a template, returns
3105 * \c CXCursor_NoDeclFound.
3106 */
3107CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3108
3109/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00003110 * \brief Given a cursor that may represent a specialization or instantiation
3111 * of a template, retrieve the cursor that represents the template that it
3112 * specializes or from which it was instantiated.
3113 *
3114 * This routine determines the template involved both for explicit
3115 * specializations of templates and for implicit instantiations of the template,
3116 * both of which are referred to as "specializations". For a class template
3117 * specialization (e.g., \c std::vector<bool>), this routine will return
3118 * either the primary template (\c std::vector) or, if the specialization was
3119 * instantiated from a class template partial specialization, the class template
3120 * partial specialization. For a class template partial specialization and a
3121 * function template specialization (including instantiations), this
3122 * this routine will return the specialized template.
3123 *
3124 * For members of a class template (e.g., member functions, member classes, or
3125 * static data members), returns the specialized or instantiated member.
3126 * Although not strictly "templates" in the C++ language, members of class
3127 * templates have the same notions of specializations and instantiations that
3128 * templates do, so this routine treats them similarly.
3129 *
3130 * \param C A cursor that may be a specialization of a template or a member
3131 * of a template.
3132 *
3133 * \returns If the given cursor is a specialization or instantiation of a
3134 * template or a member thereof, the template or member that it specializes or
3135 * from which it was instantiated. Otherwise, returns a NULL cursor.
3136 */
3137CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00003138
3139/**
3140 * \brief Given a cursor that references something else, return the source range
3141 * covering that reference.
3142 *
3143 * \param C A cursor pointing to a member reference, a declaration reference, or
3144 * an operator call.
3145 * \param NameFlags A bitset with three independent flags:
3146 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3147 * CXNameRange_WantSinglePiece.
3148 * \param PieceIndex For contiguous names or when passing the flag
3149 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3150 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
3151 * non-contiguous names, this index can be used to retreive the individual
3152 * pieces of the name. See also CXNameRange_WantSinglePiece.
3153 *
3154 * \returns The piece of the name pointed to by the given cursor. If there is no
3155 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3156 */
Francois Pichet48a8d142011-07-25 22:00:44 +00003157CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3158 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00003159 unsigned PieceIndex);
3160
3161enum CXNameRefFlags {
3162 /**
3163 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3164 * range.
3165 */
3166 CXNameRange_WantQualifier = 0x1,
3167
3168 /**
3169 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
3170 * the range.
3171 */
3172 CXNameRange_WantTemplateArgs = 0x2,
3173
3174 /**
3175 * \brief If the name is non-contiguous, return the full spanning range.
3176 *
3177 * Non-contiguous names occur in Objective-C when a selector with two or more
3178 * parameters is used, or in C++ when using an operator:
3179 * \code
3180 * [object doSomething:here withValue:there]; // ObjC
3181 * return some_vector[1]; // C++
3182 * \endcode
3183 */
3184 CXNameRange_WantSinglePiece = 0x4
3185};
Douglas Gregore0329ac2010-09-02 00:07:54 +00003186
3187/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003188 * @}
3189 */
3190
3191/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003192 * \defgroup CINDEX_LEX Token extraction and manipulation
3193 *
3194 * The routines in this group provide access to the tokens within a
3195 * translation unit, along with a semantic mapping of those tokens to
3196 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003197 *
3198 * @{
3199 */
3200
3201/**
3202 * \brief Describes a kind of token.
3203 */
3204typedef enum CXTokenKind {
3205 /**
3206 * \brief A token that contains some kind of punctuation.
3207 */
3208 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003209
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003210 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003211 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003212 */
3213 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003214
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003215 /**
3216 * \brief An identifier (that is not a keyword).
3217 */
3218 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003219
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003220 /**
3221 * \brief A numeric, string, or character literal.
3222 */
3223 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003224
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003225 /**
3226 * \brief A comment.
3227 */
3228 CXToken_Comment
3229} CXTokenKind;
3230
3231/**
3232 * \brief Describes a single preprocessing token.
3233 */
3234typedef struct {
3235 unsigned int_data[4];
3236 void *ptr_data;
3237} CXToken;
3238
3239/**
3240 * \brief Determine the kind of the given token.
3241 */
3242CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003243
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003244/**
3245 * \brief Determine the spelling of the given token.
3246 *
3247 * The spelling of a token is the textual representation of that token, e.g.,
3248 * the text of an identifier or keyword.
3249 */
3250CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003251
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003252/**
3253 * \brief Retrieve the source location of the given token.
3254 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003255CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003256 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003257
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003258/**
3259 * \brief Retrieve a source range that covers the given token.
3260 */
3261CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
3262
3263/**
3264 * \brief Tokenize the source code described by the given range into raw
3265 * lexical tokens.
3266 *
3267 * \param TU the translation unit whose text is being tokenized.
3268 *
3269 * \param Range the source range in which text should be tokenized. All of the
3270 * tokens produced by tokenization will fall within this source range,
3271 *
3272 * \param Tokens this pointer will be set to point to the array of tokens
3273 * that occur within the given source range. The returned pointer must be
3274 * freed with clang_disposeTokens() before the translation unit is destroyed.
3275 *
3276 * \param NumTokens will be set to the number of tokens in the \c *Tokens
3277 * array.
3278 *
3279 */
3280CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
3281 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003282
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003283/**
3284 * \brief Annotate the given set of tokens by providing cursors for each token
3285 * that can be mapped to a specific entity within the abstract syntax tree.
3286 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003287 * This token-annotation routine is equivalent to invoking
3288 * clang_getCursor() for the source locations of each of the
3289 * tokens. The cursors provided are filtered, so that only those
3290 * cursors that have a direct correspondence to the token are
3291 * accepted. For example, given a function call \c f(x),
3292 * clang_getCursor() would provide the following cursors:
3293 *
3294 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
3295 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
3296 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
3297 *
3298 * Only the first and last of these cursors will occur within the
3299 * annotate, since the tokens "f" and "x' directly refer to a function
3300 * and a variable, respectively, but the parentheses are just a small
3301 * part of the full syntax of the function call expression, which is
3302 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003303 *
3304 * \param TU the translation unit that owns the given tokens.
3305 *
3306 * \param Tokens the set of tokens to annotate.
3307 *
3308 * \param NumTokens the number of tokens in \p Tokens.
3309 *
3310 * \param Cursors an array of \p NumTokens cursors, whose contents will be
3311 * replaced with the cursors corresponding to each token.
3312 */
3313CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
3314 CXToken *Tokens, unsigned NumTokens,
3315 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003316
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003317/**
3318 * \brief Free the given set of tokens.
3319 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003320CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003321 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003322
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003323/**
3324 * @}
3325 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003326
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003327/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003328 * \defgroup CINDEX_DEBUG Debugging facilities
3329 *
3330 * These routines are used for testing and debugging, only, and should not
3331 * be relied upon.
3332 *
3333 * @{
3334 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003335
Steve Naroff4ade6d62009-09-23 17:52:52 +00003336/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00003337CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003338CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3339 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00003340 const char **endBuf,
3341 unsigned *startLine,
3342 unsigned *startColumn,
3343 unsigned *endLine,
3344 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00003345CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00003346CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
3347 unsigned stack_size);
3348
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003349/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003350 * @}
3351 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003352
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003353/**
3354 * \defgroup CINDEX_CODE_COMPLET Code completion
3355 *
3356 * Code completion involves taking an (incomplete) source file, along with
3357 * knowledge of where the user is actively editing that file, and suggesting
3358 * syntactically- and semantically-valid constructs that the user might want to
3359 * use at that particular point in the source code. These data structures and
3360 * routines provide support for code completion.
3361 *
3362 * @{
3363 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003364
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003365/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003366 * \brief A semantic string that describes a code-completion result.
3367 *
3368 * A semantic string that describes the formatting of a code-completion
3369 * result as a single "template" of text that should be inserted into the
3370 * source buffer when a particular code-completion result is selected.
3371 * Each semantic string is made up of some number of "chunks", each of which
3372 * contains some text along with a description of what that text means, e.g.,
3373 * the name of the entity being referenced, whether the text chunk is part of
3374 * the template, or whether it is a "placeholder" that the user should replace
3375 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003376 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003377 */
3378typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003379
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003380/**
3381 * \brief A single result of code completion.
3382 */
3383typedef struct {
3384 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003385 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003386 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003387 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003388 * *Decl cursor kinds), describing the entity that the completion is
3389 * referring to.
3390 *
3391 * \todo In the future, we would like to provide a full cursor, to allow
3392 * the client to extract additional information from declaration.
3393 */
3394 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003395
3396 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003397 * \brief The code-completion string that describes how to insert this
3398 * code-completion result into the editing buffer.
3399 */
3400 CXCompletionString CompletionString;
3401} CXCompletionResult;
3402
3403/**
3404 * \brief Describes a single piece of text within a code-completion string.
3405 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003406 * Each "chunk" within a code-completion string (\c CXCompletionString) is
3407 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003408 * should be interpreted by the client or is another completion string.
3409 */
3410enum CXCompletionChunkKind {
3411 /**
3412 * \brief A code-completion string that describes "optional" text that
3413 * could be a part of the template (but is not required).
3414 *
3415 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003416 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003417 * \c clang_getCompletionChunkCompletionString(). The code-completion string
3418 * describes an additional part of the template that is completely optional.
3419 * For example, optional chunks can be used to describe the placeholders for
3420 * arguments that match up with defaulted function parameters, e.g. given:
3421 *
3422 * \code
3423 * void f(int x, float y = 3.14, double z = 2.71828);
3424 * \endcode
3425 *
3426 * The code-completion string for this function would contain:
3427 * - a TypedText chunk for "f".
3428 * - a LeftParen chunk for "(".
3429 * - a Placeholder chunk for "int x"
3430 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
3431 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00003432 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003433 * - an Optional chunk containing the last defaulted argument:
3434 * - a Comma chunk for ","
3435 * - a Placeholder chunk for "double z"
3436 * - a RightParen chunk for ")"
3437 *
Daniel Dunbar71570182010-02-17 08:07:44 +00003438 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003439 * - Completely ignore optional chunks, in which case the template for the
3440 * function "f" would only include the first parameter ("int x").
3441 * - Fully expand all optional chunks, in which case the template for the
3442 * function "f" would have all of the parameters.
3443 */
3444 CXCompletionChunk_Optional,
3445 /**
3446 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003447 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003448 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003449 * There will be exactly one "typed text" chunk in a semantic string, which
3450 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003451 * declaration that could be used at the current code point. Clients are
3452 * expected to filter the code-completion results based on the text in this
3453 * chunk.
3454 */
3455 CXCompletionChunk_TypedText,
3456 /**
3457 * \brief Text that should be inserted as part of a code-completion result.
3458 *
3459 * A "text" chunk represents text that is part of the template to be
3460 * inserted into user code should this particular code-completion result
3461 * be selected.
3462 */
3463 CXCompletionChunk_Text,
3464 /**
3465 * \brief Placeholder text that should be replaced by the user.
3466 *
3467 * A "placeholder" chunk marks a place where the user should insert text
3468 * into the code-completion template. For example, placeholders might mark
3469 * the function parameters for a function declaration, to indicate that the
3470 * user should provide arguments for each of those parameters. The actual
3471 * text in a placeholder is a suggestion for the text to display before
3472 * the user replaces the placeholder with real code.
3473 */
3474 CXCompletionChunk_Placeholder,
3475 /**
3476 * \brief Informative text that should be displayed but never inserted as
3477 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003478 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003479 * An "informative" chunk contains annotations that can be displayed to
3480 * help the user decide whether a particular code-completion result is the
3481 * right option, but which is not part of the actual template to be inserted
3482 * by code completion.
3483 */
3484 CXCompletionChunk_Informative,
3485 /**
3486 * \brief Text that describes the current parameter when code-completion is
3487 * referring to function call, message send, or template specialization.
3488 *
3489 * A "current parameter" chunk occurs when code-completion is providing
3490 * information about a parameter corresponding to the argument at the
3491 * code-completion point. For example, given a function
3492 *
3493 * \code
3494 * int add(int x, int y);
3495 * \endcode
3496 *
3497 * and the source code \c add(, where the code-completion point is after the
3498 * "(", the code-completion string will contain a "current parameter" chunk
3499 * for "int x", indicating that the current argument will initialize that
3500 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003501 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003502 * "current paremeter" chunk to "int y".
3503 */
3504 CXCompletionChunk_CurrentParameter,
3505 /**
3506 * \brief A left parenthesis ('('), used to initiate a function call or
3507 * signal the beginning of a function parameter list.
3508 */
3509 CXCompletionChunk_LeftParen,
3510 /**
3511 * \brief A right parenthesis (')'), used to finish a function call or
3512 * signal the end of a function parameter list.
3513 */
3514 CXCompletionChunk_RightParen,
3515 /**
3516 * \brief A left bracket ('[').
3517 */
3518 CXCompletionChunk_LeftBracket,
3519 /**
3520 * \brief A right bracket (']').
3521 */
3522 CXCompletionChunk_RightBracket,
3523 /**
3524 * \brief A left brace ('{').
3525 */
3526 CXCompletionChunk_LeftBrace,
3527 /**
3528 * \brief A right brace ('}').
3529 */
3530 CXCompletionChunk_RightBrace,
3531 /**
3532 * \brief A left angle bracket ('<').
3533 */
3534 CXCompletionChunk_LeftAngle,
3535 /**
3536 * \brief A right angle bracket ('>').
3537 */
3538 CXCompletionChunk_RightAngle,
3539 /**
3540 * \brief A comma separator (',').
3541 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003542 CXCompletionChunk_Comma,
3543 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003544 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003545 *
3546 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003547 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003548 * expression using the given completion string would have.
3549 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00003550 CXCompletionChunk_ResultType,
3551 /**
3552 * \brief A colon (':').
3553 */
3554 CXCompletionChunk_Colon,
3555 /**
3556 * \brief A semicolon (';').
3557 */
3558 CXCompletionChunk_SemiColon,
3559 /**
3560 * \brief An '=' sign.
3561 */
3562 CXCompletionChunk_Equal,
3563 /**
3564 * Horizontal space (' ').
3565 */
3566 CXCompletionChunk_HorizontalSpace,
3567 /**
3568 * Vertical space ('\n'), after which it is generally a good idea to
3569 * perform indentation.
3570 */
3571 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003572};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003573
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003574/**
3575 * \brief Determine the kind of a particular chunk within a completion string.
3576 *
3577 * \param completion_string the completion string to query.
3578 *
3579 * \param chunk_number the 0-based index of the chunk in the completion string.
3580 *
3581 * \returns the kind of the chunk at the index \c chunk_number.
3582 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003583CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003584clang_getCompletionChunkKind(CXCompletionString completion_string,
3585 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003586
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003587/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003588 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003589 * completion string.
3590 *
3591 * \param completion_string the completion string to query.
3592 *
3593 * \param chunk_number the 0-based index of the chunk in the completion string.
3594 *
3595 * \returns the text associated with the chunk at index \c chunk_number.
3596 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00003597CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003598clang_getCompletionChunkText(CXCompletionString completion_string,
3599 unsigned chunk_number);
3600
3601/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003602 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003603 * within a completion string.
3604 *
3605 * \param completion_string the completion string to query.
3606 *
3607 * \param chunk_number the 0-based index of the chunk in the completion string.
3608 *
3609 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003610 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003611 */
3612CINDEX_LINKAGE CXCompletionString
3613clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
3614 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003615
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003616/**
3617 * \brief Retrieve the number of chunks in the given code-completion string.
3618 */
3619CINDEX_LINKAGE unsigned
3620clang_getNumCompletionChunks(CXCompletionString completion_string);
3621
3622/**
Douglas Gregor12e13132010-05-26 22:00:08 +00003623 * \brief Determine the priority of this code completion.
3624 *
3625 * The priority of a code completion indicates how likely it is that this
3626 * particular completion is the completion that the user will select. The
3627 * priority is selected by various internal heuristics.
3628 *
3629 * \param completion_string The completion string to query.
3630 *
3631 * \returns The priority of this completion string. Smaller values indicate
3632 * higher-priority (more likely) completions.
3633 */
3634CINDEX_LINKAGE unsigned
3635clang_getCompletionPriority(CXCompletionString completion_string);
3636
3637/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00003638 * \brief Determine the availability of the entity that this code-completion
3639 * string refers to.
3640 *
3641 * \param completion_string The completion string to query.
3642 *
3643 * \returns The availability of the completion string.
3644 */
3645CINDEX_LINKAGE enum CXAvailabilityKind
3646clang_getCompletionAvailability(CXCompletionString completion_string);
3647
3648/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003649 * \brief Retrieve the number of annotations associated with the given
3650 * completion string.
3651 *
3652 * \param completion_string the completion string to query.
3653 *
3654 * \returns the number of annotations associated with the given completion
3655 * string.
3656 */
3657CINDEX_LINKAGE unsigned
3658clang_getCompletionNumAnnotations(CXCompletionString completion_string);
3659
3660/**
3661 * \brief Retrieve the annotation associated with the given completion string.
3662 *
3663 * \param completion_string the completion string to query.
3664 *
3665 * \param annotation_number the 0-based index of the annotation of the
3666 * completion string.
3667 *
3668 * \returns annotation string associated with the completion at index
3669 * \c annotation_number, or a NULL string if that annotation is not available.
3670 */
3671CINDEX_LINKAGE CXString
3672clang_getCompletionAnnotation(CXCompletionString completion_string,
3673 unsigned annotation_number);
3674
3675/**
Douglas Gregorba103062012-03-27 23:34:16 +00003676 * \brief Retrieve the parent context of the given completion string.
3677 *
3678 * The parent context of a completion string is the semantic parent of
3679 * the declaration (if any) that the code completion represents. For example,
3680 * a code completion for an Objective-C method would have the method's class
3681 * or protocol as its context.
3682 *
3683 * \param completion_string The code completion string whose parent is
3684 * being queried.
3685 *
3686 * \param kind If non-NULL, will be set to the kind of the parent context,
3687 * or CXCursor_NotImplemented if there is no context.
3688 *
3689 * \param Returns the name of the completion parent, e.g., "NSObject" if
3690 * the completion string represents a method in the NSObject class.
3691 */
3692CINDEX_LINKAGE CXString
3693clang_getCompletionParent(CXCompletionString completion_string,
3694 enum CXCursorKind *kind);
3695/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00003696 * \brief Retrieve a completion string for an arbitrary declaration or macro
3697 * definition cursor.
3698 *
3699 * \param cursor The cursor to query.
3700 *
3701 * \returns A non-context-sensitive completion string for declaration and macro
3702 * definition cursors, or NULL for other kinds of cursors.
3703 */
3704CINDEX_LINKAGE CXCompletionString
3705clang_getCursorCompletionString(CXCursor cursor);
3706
3707/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003708 * \brief Contains the results of code-completion.
3709 *
3710 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00003711 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00003712 * \c clang_disposeCodeCompleteResults.
3713 */
3714typedef struct {
3715 /**
3716 * \brief The code-completion results.
3717 */
3718 CXCompletionResult *Results;
3719
3720 /**
3721 * \brief The number of code-completion results stored in the
3722 * \c Results array.
3723 */
3724 unsigned NumResults;
3725} CXCodeCompleteResults;
3726
3727/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003728 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3729 * modify its behavior.
3730 *
3731 * The enumerators in this enumeration can be bitwise-OR'd together to
3732 * provide multiple options to \c clang_codeCompleteAt().
3733 */
3734enum CXCodeComplete_Flags {
3735 /**
3736 * \brief Whether to include macros within the set of code
3737 * completions returned.
3738 */
3739 CXCodeComplete_IncludeMacros = 0x01,
3740
3741 /**
3742 * \brief Whether to include code patterns for language constructs
3743 * within the set of code completions, e.g., for loops.
3744 */
3745 CXCodeComplete_IncludeCodePatterns = 0x02
3746};
3747
3748/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003749 * \brief Bits that represent the context under which completion is occurring.
3750 *
3751 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3752 * contexts are occurring simultaneously.
3753 */
3754enum CXCompletionContext {
3755 /**
3756 * \brief The context for completions is unexposed, as only Clang results
3757 * should be included. (This is equivalent to having no context bits set.)
3758 */
3759 CXCompletionContext_Unexposed = 0,
3760
3761 /**
3762 * \brief Completions for any possible type should be included in the results.
3763 */
3764 CXCompletionContext_AnyType = 1 << 0,
3765
3766 /**
3767 * \brief Completions for any possible value (variables, function calls, etc.)
3768 * should be included in the results.
3769 */
3770 CXCompletionContext_AnyValue = 1 << 1,
3771 /**
3772 * \brief Completions for values that resolve to an Objective-C object should
3773 * be included in the results.
3774 */
3775 CXCompletionContext_ObjCObjectValue = 1 << 2,
3776 /**
3777 * \brief Completions for values that resolve to an Objective-C selector
3778 * should be included in the results.
3779 */
3780 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3781 /**
3782 * \brief Completions for values that resolve to a C++ class type should be
3783 * included in the results.
3784 */
3785 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3786
3787 /**
3788 * \brief Completions for fields of the member being accessed using the dot
3789 * operator should be included in the results.
3790 */
3791 CXCompletionContext_DotMemberAccess = 1 << 5,
3792 /**
3793 * \brief Completions for fields of the member being accessed using the arrow
3794 * operator should be included in the results.
3795 */
3796 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3797 /**
3798 * \brief Completions for properties of the Objective-C object being accessed
3799 * using the dot operator should be included in the results.
3800 */
3801 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3802
3803 /**
3804 * \brief Completions for enum tags should be included in the results.
3805 */
3806 CXCompletionContext_EnumTag = 1 << 8,
3807 /**
3808 * \brief Completions for union tags should be included in the results.
3809 */
3810 CXCompletionContext_UnionTag = 1 << 9,
3811 /**
3812 * \brief Completions for struct tags should be included in the results.
3813 */
3814 CXCompletionContext_StructTag = 1 << 10,
3815
3816 /**
3817 * \brief Completions for C++ class names should be included in the results.
3818 */
3819 CXCompletionContext_ClassTag = 1 << 11,
3820 /**
3821 * \brief Completions for C++ namespaces and namespace aliases should be
3822 * included in the results.
3823 */
3824 CXCompletionContext_Namespace = 1 << 12,
3825 /**
3826 * \brief Completions for C++ nested name specifiers should be included in
3827 * the results.
3828 */
3829 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3830
3831 /**
3832 * \brief Completions for Objective-C interfaces (classes) should be included
3833 * in the results.
3834 */
3835 CXCompletionContext_ObjCInterface = 1 << 14,
3836 /**
3837 * \brief Completions for Objective-C protocols should be included in
3838 * the results.
3839 */
3840 CXCompletionContext_ObjCProtocol = 1 << 15,
3841 /**
3842 * \brief Completions for Objective-C categories should be included in
3843 * the results.
3844 */
3845 CXCompletionContext_ObjCCategory = 1 << 16,
3846 /**
3847 * \brief Completions for Objective-C instance messages should be included
3848 * in the results.
3849 */
3850 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3851 /**
3852 * \brief Completions for Objective-C class messages should be included in
3853 * the results.
3854 */
3855 CXCompletionContext_ObjCClassMessage = 1 << 18,
3856 /**
3857 * \brief Completions for Objective-C selector names should be included in
3858 * the results.
3859 */
3860 CXCompletionContext_ObjCSelectorName = 1 << 19,
3861
3862 /**
3863 * \brief Completions for preprocessor macro names should be included in
3864 * the results.
3865 */
3866 CXCompletionContext_MacroName = 1 << 20,
3867
3868 /**
3869 * \brief Natural language completions should be included in the results.
3870 */
3871 CXCompletionContext_NaturalLanguage = 1 << 21,
3872
3873 /**
3874 * \brief The current context is unknown, so set all contexts.
3875 */
3876 CXCompletionContext_Unknown = ((1 << 22) - 1)
3877};
3878
3879/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003880 * \brief Returns a default set of code-completion options that can be
3881 * passed to\c clang_codeCompleteAt().
3882 */
3883CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3884
3885/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003886 * \brief Perform code completion at a given location in a translation unit.
3887 *
3888 * This function performs code completion at a particular file, line, and
3889 * column within source code, providing results that suggest potential
3890 * code snippets based on the context of the completion. The basic model
3891 * for code completion is that Clang will parse a complete source file,
3892 * performing syntax checking up to the location where code-completion has
3893 * been requested. At that point, a special code-completion token is passed
3894 * to the parser, which recognizes this token and determines, based on the
3895 * current location in the C/Objective-C/C++ grammar and the state of
3896 * semantic analysis, what completions to provide. These completions are
3897 * returned via a new \c CXCodeCompleteResults structure.
3898 *
3899 * Code completion itself is meant to be triggered by the client when the
3900 * user types punctuation characters or whitespace, at which point the
3901 * code-completion location will coincide with the cursor. For example, if \c p
3902 * is a pointer, code-completion might be triggered after the "-" and then
3903 * after the ">" in \c p->. When the code-completion location is afer the ">",
3904 * the completion results will provide, e.g., the members of the struct that
3905 * "p" points to. The client is responsible for placing the cursor at the
3906 * beginning of the token currently being typed, then filtering the results
3907 * based on the contents of the token. For example, when code-completing for
3908 * the expression \c p->get, the client should provide the location just after
3909 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3910 * client can filter the results based on the current token text ("get"), only
3911 * showing those results that start with "get". The intent of this interface
3912 * is to separate the relatively high-latency acquisition of code-completion
3913 * results from the filtering of results on a per-character basis, which must
3914 * have a lower latency.
3915 *
3916 * \param TU The translation unit in which code-completion should
3917 * occur. The source files for this translation unit need not be
3918 * completely up-to-date (and the contents of those source files may
3919 * be overridden via \p unsaved_files). Cursors referring into the
3920 * translation unit may be invalidated by this invocation.
3921 *
3922 * \param complete_filename The name of the source file where code
3923 * completion should be performed. This filename may be any file
3924 * included in the translation unit.
3925 *
3926 * \param complete_line The line at which code-completion should occur.
3927 *
3928 * \param complete_column The column at which code-completion should occur.
3929 * Note that the column should point just after the syntactic construct that
3930 * initiated code completion, and not in the middle of a lexical token.
3931 *
3932 * \param unsaved_files the Tiles that have not yet been saved to disk
3933 * but may be required for parsing or code completion, including the
3934 * contents of those files. The contents and name of these files (as
3935 * specified by CXUnsavedFile) are copied when necessary, so the
3936 * client only needs to guarantee their validity until the call to
3937 * this function returns.
3938 *
3939 * \param num_unsaved_files The number of unsaved file entries in \p
3940 * unsaved_files.
3941 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00003942 * \param options Extra options that control the behavior of code
3943 * completion, expressed as a bitwise OR of the enumerators of the
3944 * CXCodeComplete_Flags enumeration. The
3945 * \c clang_defaultCodeCompleteOptions() function returns a default set
3946 * of code-completion options.
3947 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003948 * \returns If successful, a new \c CXCodeCompleteResults structure
3949 * containing code-completion results, which should eventually be
3950 * freed with \c clang_disposeCodeCompleteResults(). If code
3951 * completion fails, returns NULL.
3952 */
3953CINDEX_LINKAGE
3954CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3955 const char *complete_filename,
3956 unsigned complete_line,
3957 unsigned complete_column,
3958 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00003959 unsigned num_unsaved_files,
3960 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003961
3962/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00003963 * \brief Sort the code-completion results in case-insensitive alphabetical
3964 * order.
3965 *
3966 * \param Results The set of results to sort.
3967 * \param NumResults The number of results in \p Results.
3968 */
3969CINDEX_LINKAGE
3970void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3971 unsigned NumResults);
3972
3973/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003974 * \brief Free the given set of code-completion results.
3975 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003976CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00003977void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00003978
Douglas Gregor20d416c2010-01-20 01:10:47 +00003979/**
Douglas Gregora88084b2010-02-18 18:08:43 +00003980 * \brief Determine the number of diagnostics produced prior to the
3981 * location where code completion was performed.
3982 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003983CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003984unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3985
3986/**
3987 * \brief Retrieve a diagnostic associated with the given code completion.
3988 *
3989 * \param Result the code completion results to query.
3990 * \param Index the zero-based diagnostic number to retrieve.
3991 *
3992 * \returns the requested diagnostic. This diagnostic must be freed
3993 * via a call to \c clang_disposeDiagnostic().
3994 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003995CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003996CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3997 unsigned Index);
3998
3999/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00004000 * \brief Determines what compeltions are appropriate for the context
4001 * the given code completion.
4002 *
4003 * \param Results the code completion results to query
4004 *
4005 * \returns the kinds of completions that are appropriate for use
4006 * along with the given code completion results.
4007 */
4008CINDEX_LINKAGE
4009unsigned long long clang_codeCompleteGetContexts(
4010 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00004011
4012/**
4013 * \brief Returns the cursor kind for the container for the current code
4014 * completion context. The container is only guaranteed to be set for
4015 * contexts where a container exists (i.e. member accesses or Objective-C
4016 * message sends); if there is not a container, this function will return
4017 * CXCursor_InvalidCode.
4018 *
4019 * \param Results the code completion results to query
4020 *
4021 * \param IsIncomplete on return, this value will be false if Clang has complete
4022 * information about the container. If Clang does not have complete
4023 * information, this value will be true.
4024 *
4025 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4026 * container
4027 */
4028CINDEX_LINKAGE
4029enum CXCursorKind clang_codeCompleteGetContainerKind(
4030 CXCodeCompleteResults *Results,
4031 unsigned *IsIncomplete);
4032
4033/**
4034 * \brief Returns the USR for the container for the current code completion
4035 * context. If there is not a container for the current context, this
4036 * function will return the empty string.
4037 *
4038 * \param Results the code completion results to query
4039 *
4040 * \returns the USR for the container
4041 */
4042CINDEX_LINKAGE
4043CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00004044
Douglas Gregor0a47d692011-07-26 15:24:30 +00004045
4046/**
4047 * \brief Returns the currently-entered selector for an Objective-C message
4048 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4049 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4050 * CXCompletionContext_ObjCClassMessage.
4051 *
4052 * \param Results the code completion results to query
4053 *
4054 * \returns the selector (or partial selector) that has been entered thus far
4055 * for an Objective-C message send.
4056 */
4057CINDEX_LINKAGE
4058CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4059
Douglas Gregor3da626b2011-07-07 16:03:39 +00004060/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00004061 * @}
4062 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004063
4064
Ted Kremenek04bb7162010-01-22 22:44:15 +00004065/**
4066 * \defgroup CINDEX_MISC Miscellaneous utility functions
4067 *
4068 * @{
4069 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00004070
4071/**
4072 * \brief Return a version string, suitable for showing to a user, but not
4073 * intended to be parsed (the format is not guaranteed to be stable).
4074 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00004075CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00004076
Ted Kremenekd2427dd2011-03-18 23:05:39 +00004077
4078/**
4079 * \brief Enable/disable crash recovery.
4080 *
4081 * \param Flag to indicate if crash recovery is enabled. A non-zero value
4082 * enables crash recovery, while 0 disables it.
4083 */
4084CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4085
Ted Kremenek16b55a72010-01-26 19:31:51 +00004086 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00004087 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00004088 * (used with clang_getInclusions()).
4089 *
4090 * This visitor function will be invoked by clang_getInclusions() for each
4091 * file included (either at the top-level or by #include directives) within
4092 * a translation unit. The first argument is the file being included, and
4093 * the second and third arguments provide the inclusion stack. The
4094 * array is sorted in order of immediate inclusion. For example,
4095 * the first element refers to the location that included 'included_file'.
4096 */
4097typedef void (*CXInclusionVisitor)(CXFile included_file,
4098 CXSourceLocation* inclusion_stack,
4099 unsigned include_len,
4100 CXClientData client_data);
4101
4102/**
4103 * \brief Visit the set of preprocessor inclusions in a translation unit.
4104 * The visitor function is called with the provided data for every included
4105 * file. This does not include headers included by the PCH file (unless one
4106 * is inspecting the inclusions in the PCH file itself).
4107 */
4108CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4109 CXInclusionVisitor visitor,
4110 CXClientData client_data);
4111
4112/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00004113 * @}
4114 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004115
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004116/** \defgroup CINDEX_REMAPPING Remapping functions
4117 *
4118 * @{
4119 */
4120
4121/**
4122 * \brief A remapping of original source files and their translated files.
4123 */
4124typedef void *CXRemapping;
4125
4126/**
4127 * \brief Retrieve a remapping.
4128 *
4129 * \param path the path that contains metadata about remappings.
4130 *
4131 * \returns the requested remapping. This remapping must be freed
4132 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4133 */
4134CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4135
4136/**
Ted Kremenek30660a82012-03-06 20:06:33 +00004137 * \brief Retrieve a remapping.
4138 *
4139 * \param filePaths pointer to an array of file paths containing remapping info.
4140 *
4141 * \param numFiles number of file paths.
4142 *
4143 * \returns the requested remapping. This remapping must be freed
4144 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4145 */
4146CINDEX_LINKAGE
4147CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
4148 unsigned numFiles);
4149
4150/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004151 * \brief Determine the number of remappings.
4152 */
4153CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4154
4155/**
4156 * \brief Get the original and the associated filename from the remapping.
4157 *
4158 * \param original If non-NULL, will be set to the original filename.
4159 *
4160 * \param transformed If non-NULL, will be set to the filename that the original
4161 * is associated with.
4162 */
4163CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4164 CXString *original, CXString *transformed);
4165
4166/**
4167 * \brief Dispose the remapping.
4168 */
4169CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4170
4171/**
4172 * @}
4173 */
4174
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004175/** \defgroup CINDEX_HIGH Higher level API functions
4176 *
4177 * @{
4178 */
4179
4180enum CXVisitorResult {
4181 CXVisit_Break,
4182 CXVisit_Continue
4183};
4184
4185typedef struct {
4186 void *context;
4187 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4188} CXCursorAndRangeVisitor;
4189
4190/**
4191 * \brief Find references of a declaration in a specific file.
4192 *
4193 * \param cursor pointing to a declaration or a reference of one.
4194 *
4195 * \param file to search for references.
4196 *
4197 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4198 * each reference found.
4199 * The CXSourceRange will point inside the file; if the reference is inside
4200 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4201 */
4202CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4203 CXCursorAndRangeVisitor visitor);
4204
4205#ifdef __has_feature
4206# if __has_feature(blocks)
4207
4208typedef enum CXVisitorResult
4209 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4210
4211CINDEX_LINKAGE
4212void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4213 CXCursorAndRangeVisitorBlock);
4214
4215# endif
4216#endif
4217
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004218/**
4219 * \brief The client's data object that is associated with a CXFile.
4220 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004221typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004222
4223/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004224 * \brief The client's data object that is associated with a semantic entity.
4225 */
4226typedef void *CXIdxClientEntity;
4227
4228/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004229 * \brief The client's data object that is associated with a semantic container
4230 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004231 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004232typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004233
4234/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004235 * \brief The client's data object that is associated with an AST file (PCH
4236 * or module).
4237 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004238typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004239
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004240/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004241 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004242 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004243typedef struct {
4244 void *ptr_data[2];
4245 unsigned int_data;
4246} CXIdxLoc;
4247
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004248/**
4249 * \brief Data for \see ppIncludedFile callback.
4250 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004251typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004252 /**
4253 * \brief Location of '#' in the #include/#import directive.
4254 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004255 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004256 /**
4257 * \brief Filename as written in the #include/#import directive.
4258 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004259 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004260 /**
4261 * \brief The actual file that the #include/#import directive resolved to.
4262 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004263 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004264 int isImport;
4265 int isAngled;
4266} CXIdxIncludedFileInfo;
4267
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004268/**
4269 * \brief Data for \see importedASTFile callback.
4270 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004271typedef struct {
4272 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004273 /**
4274 * \brief Location where the file is imported. It is useful mostly for
4275 * modules.
4276 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004277 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004278 /**
4279 * \brief Non-zero if the AST file is a module otherwise it's a PCH.
4280 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004281 int isModule;
4282} CXIdxImportedASTFileInfo;
4283
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004284typedef enum {
4285 CXIdxEntity_Unexposed = 0,
4286 CXIdxEntity_Typedef = 1,
4287 CXIdxEntity_Function = 2,
4288 CXIdxEntity_Variable = 3,
4289 CXIdxEntity_Field = 4,
4290 CXIdxEntity_EnumConstant = 5,
4291
4292 CXIdxEntity_ObjCClass = 6,
4293 CXIdxEntity_ObjCProtocol = 7,
4294 CXIdxEntity_ObjCCategory = 8,
4295
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004296 CXIdxEntity_ObjCInstanceMethod = 9,
4297 CXIdxEntity_ObjCClassMethod = 10,
4298 CXIdxEntity_ObjCProperty = 11,
4299 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004300
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004301 CXIdxEntity_Enum = 13,
4302 CXIdxEntity_Struct = 14,
4303 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004304
4305 CXIdxEntity_CXXClass = 16,
4306 CXIdxEntity_CXXNamespace = 17,
4307 CXIdxEntity_CXXNamespaceAlias = 18,
4308 CXIdxEntity_CXXStaticVariable = 19,
4309 CXIdxEntity_CXXStaticMethod = 20,
4310 CXIdxEntity_CXXInstanceMethod = 21,
4311 CXIdxEntity_CXXConstructor = 22,
4312 CXIdxEntity_CXXDestructor = 23,
4313 CXIdxEntity_CXXConversionFunction = 24,
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004314 CXIdxEntity_CXXTypeAlias = 25
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004315
4316} CXIdxEntityKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004317
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004318typedef enum {
4319 CXIdxEntityLang_None = 0,
4320 CXIdxEntityLang_C = 1,
4321 CXIdxEntityLang_ObjC = 2,
4322 CXIdxEntityLang_CXX = 3
4323} CXIdxEntityLanguage;
4324
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004325/**
4326 * \brief Extra C++ template information for an entity. This can apply to:
4327 * CXIdxEntity_Function
4328 * CXIdxEntity_CXXClass
4329 * CXIdxEntity_CXXStaticMethod
4330 * CXIdxEntity_CXXInstanceMethod
4331 * CXIdxEntity_CXXConstructor
4332 * CXIdxEntity_CXXConversionFunction
4333 * CXIdxEntity_CXXTypeAlias
4334 */
4335typedef enum {
4336 CXIdxEntity_NonTemplate = 0,
4337 CXIdxEntity_Template = 1,
4338 CXIdxEntity_TemplatePartialSpecialization = 2,
4339 CXIdxEntity_TemplateSpecialization = 3
4340} CXIdxEntityCXXTemplateKind;
4341
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004342typedef enum {
4343 CXIdxAttr_Unexposed = 0,
4344 CXIdxAttr_IBAction = 1,
4345 CXIdxAttr_IBOutlet = 2,
4346 CXIdxAttr_IBOutletCollection = 3
4347} CXIdxAttrKind;
4348
4349typedef struct {
4350 CXIdxAttrKind kind;
4351 CXCursor cursor;
4352 CXIdxLoc loc;
4353} CXIdxAttrInfo;
4354
4355typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00004356 CXIdxEntityKind kind;
4357 CXIdxEntityCXXTemplateKind templateKind;
4358 CXIdxEntityLanguage lang;
4359 const char *name;
4360 const char *USR;
4361 CXCursor cursor;
4362 const CXIdxAttrInfo *const *attributes;
4363 unsigned numAttributes;
4364} CXIdxEntityInfo;
4365
4366typedef struct {
4367 CXCursor cursor;
4368} CXIdxContainerInfo;
4369
4370typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004371 const CXIdxAttrInfo *attrInfo;
4372 const CXIdxEntityInfo *objcClass;
4373 CXCursor classCursor;
4374 CXIdxLoc classLoc;
4375} CXIdxIBOutletCollectionAttrInfo;
4376
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004377typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004378 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004379 CXCursor cursor;
4380 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004381 const CXIdxContainerInfo *semanticContainer;
4382 /**
4383 * \brief Generally same as \see semanticContainer but can be different in
4384 * cases like out-of-line C++ member functions.
4385 */
4386 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004387 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004388 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004389 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004390 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004391 /**
4392 * \brief Whether the declaration exists in code or was created implicitly
4393 * by the compiler, e.g. implicit objc methods for properties.
4394 */
4395 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004396 const CXIdxAttrInfo *const *attributes;
4397 unsigned numAttributes;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004398} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004399
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004400typedef enum {
4401 CXIdxObjCContainer_ForwardRef = 0,
4402 CXIdxObjCContainer_Interface = 1,
4403 CXIdxObjCContainer_Implementation = 2
4404} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004405
4406typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004407 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004408 CXIdxObjCContainerKind kind;
4409} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004410
4411typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004412 const CXIdxEntityInfo *base;
4413 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004414 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004415} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004416
4417typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004418 const CXIdxEntityInfo *protocol;
4419 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004420 CXIdxLoc loc;
4421} CXIdxObjCProtocolRefInfo;
4422
4423typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004424 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004425 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004426} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004427
4428typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004429 const CXIdxObjCContainerDeclInfo *containerInfo;
4430 const CXIdxBaseClassInfo *superInfo;
4431 const CXIdxObjCProtocolRefListInfo *protocols;
4432} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004433
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004434typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00004435 const CXIdxObjCContainerDeclInfo *containerInfo;
4436 const CXIdxEntityInfo *objcClass;
4437 CXCursor classCursor;
4438 CXIdxLoc classLoc;
4439 const CXIdxObjCProtocolRefListInfo *protocols;
4440} CXIdxObjCCategoryDeclInfo;
4441
4442typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004443 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004444 const CXIdxEntityInfo *getter;
4445 const CXIdxEntityInfo *setter;
4446} CXIdxObjCPropertyDeclInfo;
4447
4448typedef struct {
4449 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004450 const CXIdxBaseClassInfo *const *bases;
4451 unsigned numBases;
4452} CXIdxCXXClassDeclInfo;
4453
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004454/**
4455 * \brief Data for \see indexEntityReference callback.
4456 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004457typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004458 /**
4459 * \brief The entity is referenced directly in user's code.
4460 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004461 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004462 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004463 * \brief An implicit reference, e.g. a reference of an ObjC method via the
4464 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004465 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004466 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004467} CXIdxEntityRefKind;
4468
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004469/**
4470 * \brief Data for \see indexEntityReference callback.
4471 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004472typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004473 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004474 /**
4475 * \brief Reference cursor.
4476 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004477 CXCursor cursor;
4478 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004479 /**
4480 * \brief The entity that gets referenced.
4481 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004482 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004483 /**
4484 * \brief Immediate "parent" of the reference. For example:
4485 *
4486 * \code
4487 * Foo *var;
4488 * \endcode
4489 *
4490 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004491 * For references inside statement bodies of functions/methods,
4492 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004493 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004494 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004495 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004496 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004497 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004498 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004499} CXIdxEntityRefInfo;
4500
4501typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004502 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004503 * \brief Called periodically to check whether indexing should be aborted.
4504 * Should return 0 to continue, and non-zero to abort.
4505 */
4506 int (*abortQuery)(CXClientData client_data, void *reserved);
4507
4508 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004509 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004510 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004511 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004512 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004513
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004514 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
4515 CXFile mainFile, void *reserved);
4516
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004517 /**
4518 * \brief Called when a file gets #included/#imported.
4519 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004520 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004521 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004522
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004523 /**
4524 * \brief Called when a AST file (PCH or module) gets imported.
4525 *
4526 * AST files will not get indexed (there will not be callbacks to index all
4527 * the entities in an AST file). The recommended action is that, if the AST
4528 * file is not already indexed, to block further indexing and initiate a new
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004529 * indexing job specific to the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004530 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004531 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004532 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004533
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004534 /**
4535 * \brief Called at the beginning of indexing a translation unit.
4536 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004537 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004538 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004539
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004540 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004541 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004542
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004543 /**
4544 * \brief Called to index a reference of an entity.
4545 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004546 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004547 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004548
4549} IndexerCallbacks;
4550
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004551CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004552CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
4553clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004554
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004555CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
4556clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
4557
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004558CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004559const CXIdxObjCCategoryDeclInfo *
4560clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
4561
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004562CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
4563clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004564
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004565CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
4566clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
4567
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004568CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
4569clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
4570
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004571CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
4572clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
4573
4574/**
4575 * \brief For retrieving a custom CXIdxClientContainer attached to a
4576 * container.
4577 */
4578CINDEX_LINKAGE CXIdxClientContainer
4579clang_index_getClientContainer(const CXIdxContainerInfo *);
4580
4581/**
4582 * \brief For setting a custom CXIdxClientContainer attached to a
4583 * container.
4584 */
4585CINDEX_LINKAGE void
4586clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
4587
4588/**
4589 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
4590 */
4591CINDEX_LINKAGE CXIdxClientEntity
4592clang_index_getClientEntity(const CXIdxEntityInfo *);
4593
4594/**
4595 * \brief For setting a custom CXIdxClientEntity attached to an entity.
4596 */
4597CINDEX_LINKAGE void
4598clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
4599
4600/**
4601 * \brief An indexing action, to be applied to one or multiple translation units
4602 * but not on concurrent threads. If there are threads doing indexing
4603 * concurrently, they should use different CXIndexAction objects.
4604 */
4605typedef void *CXIndexAction;
4606
4607/**
4608 * \brief An indexing action, to be applied to one or multiple translation units
4609 * but not on concurrent threads. If there are threads doing indexing
4610 * concurrently, they should use different CXIndexAction objects.
4611 *
4612 * \param CIdx The index object with which the index action will be associated.
4613 */
4614CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
4615
4616/**
4617 * \brief Destroy the given index action.
4618 *
4619 * The index action must not be destroyed until all of the translation units
4620 * created within that index action have been destroyed.
4621 */
4622CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
4623
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004624typedef enum {
4625 /**
4626 * \brief Used to indicate that no special indexing options are needed.
4627 */
4628 CXIndexOpt_None = 0x0,
4629
4630 /**
4631 * \brief Used to indicate that \see indexEntityReference should be invoked
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004632 * for only one reference of an entity per source file that does not also
4633 * include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004634 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00004635 CXIndexOpt_SuppressRedundantRefs = 0x1,
4636
4637 /**
4638 * \brief Function-local symbols should be indexed. If this is not set
4639 * function-local symbols will be ignored.
4640 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00004641 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
4642
4643 /**
4644 * \brief Implicit function/class template instantiations should be indexed.
4645 * If this is not set, implicit instantiations will be ignored.
4646 */
Argyrios Kyrtzidisb49a29f2012-03-27 21:38:03 +00004647 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
4648
4649 /**
4650 * \brief Suppress all compiler warnings when parsing for indexing.
4651 */
4652 CXIndexOpt_SuppressWarnings = 0x8
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004653} CXIndexOptFlags;
4654
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004655/**
4656 * \brief Index the given source file and the translation unit corresponding
4657 * to that file via callbacks implemented through \see IndexerCallbacks.
4658 *
4659 * \param client_data pointer data supplied by the client, which will
4660 * be passed to the invoked callbacks.
4661 *
4662 * \param index_callbacks Pointer to indexing callbacks that the client
4663 * implements.
4664 *
4665 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets
4666 * passed in index_callbacks.
4667 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004668 * \param index_options A bitmask of options that affects how indexing is
4669 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004670 *
4671 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
4672 * after indexing is finished. Set to NULL if you do not require it.
4673 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004674 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004675 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004676 *
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004677 * The rest of the parameters are the same as \see clang_parseTranslationUnit.
4678 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004679CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004680 CXClientData client_data,
4681 IndexerCallbacks *index_callbacks,
4682 unsigned index_callbacks_size,
4683 unsigned index_options,
4684 const char *source_filename,
4685 const char * const *command_line_args,
4686 int num_command_line_args,
4687 struct CXUnsavedFile *unsaved_files,
4688 unsigned num_unsaved_files,
4689 CXTranslationUnit *out_TU,
4690 unsigned TU_options);
4691
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004692/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004693 * \brief Index the given translation unit via callbacks implemented through
4694 * \see IndexerCallbacks.
4695 *
4696 * The order of callback invocations is not guaranteed to be the same as
4697 * when indexing a source file. The high level order will be:
4698 *
4699 * -Preprocessor callbacks invocations
4700 * -Declaration/reference callbacks invocations
4701 * -Diagnostic callback invocations
4702 *
4703 * The parameters are the same as \see clang_indexSourceFile.
4704 *
4705 * \returns If there is a failure from which the there is no recovery, returns
4706 * non-zero, otherwise returns 0.
4707 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004708CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004709 CXClientData client_data,
4710 IndexerCallbacks *index_callbacks,
4711 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004712 unsigned index_options,
4713 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004714
4715/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004716 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
4717 * the given CXIdxLoc.
4718 *
4719 * If the location refers into a macro expansion, retrieves the
4720 * location of the macro expansion and if it refers into a macro argument
4721 * retrieves the location of the argument.
4722 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004723CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004724 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004725 CXFile *file,
4726 unsigned *line,
4727 unsigned *column,
4728 unsigned *offset);
4729
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004730/**
4731 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
4732 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004733CINDEX_LINKAGE
4734CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
4735
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004736/**
4737 * @}
4738 */
4739
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004740/**
4741 * @}
4742 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004743
Ted Kremenekd2fa5662009-08-26 22:36:44 +00004744#ifdef __cplusplus
4745}
4746#endif
4747#endif
4748