blob: d05510e281421b9d7f199aa612debb1815b17425 [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
Douglas Gregor87fb9402011-02-23 17:45:25 +000038/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000039 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000040 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000041 * facilities for parsing source code into an abstract syntax tree (AST),
42 * loading already-parsed ASTs, traversing the AST, associating
43 * physical source locations with elements within the AST, and other
44 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000045 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000046 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000047 * representation stored in Clang's C++ AST, nor should it: the intent is to
48 * maintain an API that is relatively stable from one release to the next,
49 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000050 *
51 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000052 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000053 *
54 * @{
55 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000056
Douglas Gregor7f173762010-01-20 22:28:27 +000057/**
58 * \brief An "index" that consists of a set of translation units that would
59 * typically be linked together into an executable or library.
60 */
61typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000062
Douglas Gregor7f173762010-01-20 22:28:27 +000063/**
64 * \brief A single translation unit, which resides in an index.
65 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000066typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000067
Douglas Gregor7f173762010-01-20 22:28:27 +000068/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000069 * \brief Opaque pointer representing client data that will be passed through
70 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000071 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000072typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000073
Douglas Gregor735df882009-12-02 09:21:34 +000074/**
75 * \brief Provides the contents of a file that has not yet been saved to disk.
76 *
77 * Each CXUnsavedFile instance provides the name of a file on the
78 * system along with the current contents of that file that have not
79 * yet been saved to disk.
80 */
81struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000082 /**
83 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000084 *
85 * This file must already exist in the file system.
86 */
87 const char *Filename;
88
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000089 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000090 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +000091 */
92 const char *Contents;
93
94 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000095 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +000096 */
97 unsigned long Length;
98};
99
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000100/**
101 * \brief Describes the availability of a particular entity, which indicates
102 * whether the use of this entity will result in a warning or error due to
103 * it being deprecated or unavailable.
104 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000105enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000106 /**
107 * \brief The entity is available.
108 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000109 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000110 /**
111 * \brief The entity is available, but has been deprecated (and its use is
112 * not recommended).
113 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000114 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000115 /**
116 * \brief The entity is not available; any use of it will be an error.
117 */
Erik Verbruggend1205962011-10-06 07:27:49 +0000118 CXAvailability_NotAvailable,
119 /**
120 * \brief The entity is available, but not accessible; any use of it will be
121 * an error.
122 */
123 CXAvailability_NotAccessible
Douglas Gregor58ddb602010-08-23 23:00:57 +0000124};
125
Douglas Gregor7f173762010-01-20 22:28:27 +0000126/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000127 * \defgroup CINDEX_STRING String manipulation routines
128 *
129 * @{
130 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000131
Douglas Gregor7f173762010-01-20 22:28:27 +0000132/**
133 * \brief A character string.
134 *
135 * The \c CXString type is used to return strings from the interface when
136 * the ownership of that string might different from one call to the next.
137 * Use \c clang_getCString() to retrieve the string data and, once finished
138 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000139 */
140typedef struct {
Ted Kremeneka60ed472010-11-16 08:15:36 +0000141 void *data;
Ted Kremeneked122732010-11-16 01:56:27 +0000142 unsigned private_flags;
Steve Naroffef0cef62009-11-09 17:45:52 +0000143} CXString;
144
Douglas Gregor7f173762010-01-20 22:28:27 +0000145/**
146 * \brief Retrieve the character data associated with the given string.
147 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000148CINDEX_LINKAGE const char *clang_getCString(CXString string);
149
Douglas Gregor7f173762010-01-20 22:28:27 +0000150/**
151 * \brief Free the given string,
152 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000153CINDEX_LINKAGE void clang_disposeString(CXString string);
154
Douglas Gregor7f173762010-01-20 22:28:27 +0000155/**
156 * @}
157 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000158
159/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000160 * \brief clang_createIndex() provides a shared context for creating
161 * translation units. It provides two options:
162 *
163 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
164 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000165 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000166 * header that was used by the translation unit. If zero, all declarations
167 * will be enumerated.
168 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000169 * Here is an example:
170 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000171 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
172 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000173 *
174 * // IndexTest.pch was produced with the following command:
175 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
176 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
177 *
178 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000179 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000180 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000181 * clang_disposeTranslationUnit(TU);
182 *
183 * // This will load all the symbols from 'IndexTest.c', excluding symbols
184 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000185 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
186 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
187 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000188 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
189 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000190 * clang_disposeTranslationUnit(TU);
191 *
192 * This process of creating the 'pch', loading it separately, and using it (via
193 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
194 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000195 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000196CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
197 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000198
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000199/**
200 * \brief Destroy the given index.
201 *
202 * The index must not be destroyed until all of the translation units created
203 * within that index have been destroyed.
204 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000205CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000206
207/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000208 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000209 *
210 * @{
211 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000212
Douglas Gregorf5525442010-01-20 22:45:41 +0000213/**
214 * \brief A particular source file that is part of a translation unit.
215 */
216typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000217
Douglas Gregorf5525442010-01-20 22:45:41 +0000218
219/**
220 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000221 */
Ted Kremenek74844072010-02-17 00:41:20 +0000222CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000223
Douglas Gregorf5525442010-01-20 22:45:41 +0000224/**
225 * \brief Retrieve the last modification time of the given file.
226 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000227CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000228
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000229/**
Douglas Gregordd3e5542011-05-04 00:14:37 +0000230 * \brief Determine whether the given header is guarded against
231 * multiple inclusions, either with the conventional
232 * #ifndef/#define/#endif macro guards or with #pragma once.
233 */
234CINDEX_LINKAGE unsigned
235clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
236
237/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000238 * \brief Retrieve a file handle within the given translation unit.
239 *
240 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000241 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000242 * \param file_name the name of the file.
243 *
244 * \returns the file handle for the named file in the translation unit \p tu,
245 * or a NULL file handle if the file was not a part of this translation unit.
246 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000247CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000248 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000249
Douglas Gregorb9790342010-01-22 21:44:22 +0000250/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000251 * @}
252 */
253
254/**
255 * \defgroup CINDEX_LOCATIONS Physical source locations
256 *
257 * Clang represents physical source locations in its abstract syntax tree in
258 * great detail, with file, line, and column information for the majority of
259 * the tokens parsed in the source code. These data types and functions are
260 * used to represent source location information, either for a particular
261 * point in the program or for a range of points in the program, and extract
262 * specific location information from those data types.
263 *
264 * @{
265 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000266
Douglas Gregorf5525442010-01-20 22:45:41 +0000267/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000268 * \brief Identifies a specific source location within a translation
269 * unit.
270 *
Chandler Carruth20174222011-08-31 16:53:37 +0000271 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregora9b06d42010-11-09 06:24:54 +0000272 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000273 */
274typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000275 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000276 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000277} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000278
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000279/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000280 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000281 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000282 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
283 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000284 */
285typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000286 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000287 unsigned begin_int_data;
288 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000289} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000290
Douglas Gregor1db19de2010-01-19 21:36:55 +0000291/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000292 * \brief Retrieve a NULL (invalid) source location.
293 */
294CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000295
Douglas Gregorb9790342010-01-22 21:44:22 +0000296/**
297 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000298 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000299 * code.
300 *
301 * \returns non-zero if the source locations refer to the same location, zero
302 * if they refer to different locations.
303 */
304CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
305 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000306
Douglas Gregorb9790342010-01-22 21:44:22 +0000307/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000308 * \brief Retrieves the source location associated with a given file/line/column
309 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000310 */
311CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
312 CXFile file,
313 unsigned line,
314 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000315/**
316 * \brief Retrieves the source location associated with a given character offset
317 * in a particular translation unit.
318 */
319CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
320 CXFile file,
321 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000322
Douglas Gregorb9790342010-01-22 21:44:22 +0000323/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000324 * \brief Retrieve a NULL (invalid) source range.
325 */
326CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000327
Douglas Gregor5352ac02010-01-28 00:27:43 +0000328/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000329 * \brief Retrieve a source range given the beginning and ending source
330 * locations.
331 */
332CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
333 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000334
Douglas Gregorb9790342010-01-22 21:44:22 +0000335/**
Douglas Gregorab4e83b2011-07-23 19:35:14 +0000336 * \brief Determine whether two ranges are equivalent.
337 *
338 * \returns non-zero if the ranges are the same, zero if they differ.
339 */
340CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
341 CXSourceRange range2);
342
343/**
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000344 * \brief Returns non-zero if \arg range is null.
345 */
Erik Verbruggen733dbc82011-10-06 12:11:57 +0000346CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
Argyrios Kyrtzidisde5db642011-09-28 18:14:21 +0000347
348/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000349 * \brief Retrieve the file, line, column, and offset represented by
350 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000351 *
Chandler Carruth20174222011-08-31 16:53:37 +0000352 * If the location refers into a macro expansion, retrieves the
353 * location of the macro expansion.
Douglas Gregora9b06d42010-11-09 06:24:54 +0000354 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000355 * \param location the location within a source file that will be decomposed
356 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000357 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000358 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000359 * source location points.
360 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000361 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000362 * source location points.
363 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000364 * \param column [out] if non-NULL, will be set to the column to which the given
365 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000366 *
367 * \param offset [out] if non-NULL, will be set to the offset into the
368 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000369 */
Chandler Carruth20174222011-08-31 16:53:37 +0000370CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
371 CXFile *file,
372 unsigned *line,
373 unsigned *column,
374 unsigned *offset);
375
376/**
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000377 * \brief Retrieve the file, line, column, and offset represented by
378 * the given source location, as specified in a # line directive.
379 *
380 * Example: given the following source code in a file somefile.c
381 *
382 * #123 "dummy.c" 1
383 *
384 * static int func(void)
385 * {
386 * return 0;
387 * }
388 *
389 * the location information returned by this function would be
390 *
391 * File: dummy.c Line: 124 Column: 12
392 *
393 * whereas clang_getExpansionLocation would have returned
394 *
395 * File: somefile.c Line: 3 Column: 12
396 *
397 * \param location the location within a source file that will be decomposed
398 * into its parts.
399 *
400 * \param filename [out] if non-NULL, will be set to the filename of the
401 * source location. Note that filenames returned will be for "virtual" files,
402 * which don't necessarily exist on the machine running clang - e.g. when
403 * parsing preprocessed output obtained from a different environment. If
404 * a non-NULL value is passed in, remember to dispose of the returned value
405 * using \c clang_disposeString() once you've finished with it. For an invalid
406 * source location, an empty string is returned.
407 *
408 * \param line [out] if non-NULL, will be set to the line number of the
409 * source location. For an invalid source location, zero is returned.
410 *
411 * \param column [out] if non-NULL, will be set to the column number of the
412 * source location. For an invalid source location, zero is returned.
413 */
414CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
415 CXString *filename,
416 unsigned *line,
417 unsigned *column);
418
419/**
Chandler Carruth20174222011-08-31 16:53:37 +0000420 * \brief Legacy API to retrieve the file, line, column, and offset represented
421 * by the given source location.
422 *
423 * This interface has been replaced by the newer interface
424 * \see clang_getExpansionLocation(). See that interface's documentation for
425 * details.
426 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000427CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
428 CXFile *file,
429 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000430 unsigned *column,
431 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000432
433/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000434 * \brief Retrieve the file, line, column, and offset represented by
435 * the given source location.
436 *
437 * If the location refers into a macro instantiation, return where the
438 * location was originally spelled in the source file.
439 *
440 * \param location the location within a source file that will be decomposed
441 * into its parts.
442 *
443 * \param file [out] if non-NULL, will be set to the file to which the given
444 * source location points.
445 *
446 * \param line [out] if non-NULL, will be set to the line to which the given
447 * source location points.
448 *
449 * \param column [out] if non-NULL, will be set to the column to which the given
450 * source location points.
451 *
452 * \param offset [out] if non-NULL, will be set to the offset into the
453 * buffer to which the given source location points.
454 */
455CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
456 CXFile *file,
457 unsigned *line,
458 unsigned *column,
459 unsigned *offset);
460
461/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000462 * \brief Retrieve a source location representing the first character within a
463 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000464 */
465CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
466
467/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000468 * \brief Retrieve a source location representing the last character within a
469 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000470 */
471CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
472
Douglas Gregorf5525442010-01-20 22:45:41 +0000473/**
474 * @}
475 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000476
477/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000478 * \defgroup CINDEX_DIAG Diagnostic reporting
479 *
480 * @{
481 */
482
483/**
484 * \brief Describes the severity of a particular diagnostic.
485 */
486enum CXDiagnosticSeverity {
487 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000488 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000489 * option.
490 */
491 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000492
Douglas Gregor5352ac02010-01-28 00:27:43 +0000493 /**
494 * \brief This diagnostic is a note that should be attached to the
495 * previous (non-note) diagnostic.
496 */
497 CXDiagnostic_Note = 1,
498
499 /**
500 * \brief This diagnostic indicates suspicious code that may not be
501 * wrong.
502 */
503 CXDiagnostic_Warning = 2,
504
505 /**
506 * \brief This diagnostic indicates that the code is ill-formed.
507 */
508 CXDiagnostic_Error = 3,
509
510 /**
511 * \brief This diagnostic indicates that the code is ill-formed such
512 * that future parser recovery is unlikely to produce useful
513 * results.
514 */
515 CXDiagnostic_Fatal = 4
516};
517
518/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000519 * \brief A single diagnostic, containing the diagnostic's severity,
520 * location, text, source ranges, and fix-it hints.
521 */
522typedef void *CXDiagnostic;
523
524/**
Ted Kremenek15322172011-11-10 08:43:12 +0000525 * \brief A group of CXDiagnostics.
526 */
527typedef void *CXDiagnosticSet;
528
529/**
530 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
531 */
532CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
533
534/**
535 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
536 *
537 * \param Unit the CXDiagnosticSet to query.
538 * \param Index the zero-based diagnostic number to retrieve.
539 *
540 * \returns the requested diagnostic. This diagnostic must be freed
541 * via a call to \c clang_disposeDiagnostic().
542 */
543CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
544 unsigned Index);
545
546
547/**
548 * \brief Describes the kind of error that occurred (if any) in a call to
549 * \c clang_loadDiagnostics.
550 */
551enum CXLoadDiag_Error {
552 /**
553 * \brief Indicates that no error occurred.
554 */
555 CXLoadDiag_None = 0,
556
557 /**
558 * \brief Indicates that an unknown error occurred while attempting to
559 * deserialize diagnostics.
560 */
561 CXLoadDiag_Unknown = 1,
562
563 /**
564 * \brief Indicates that the file containing the serialized diagnostics
565 * could not be opened.
566 */
567 CXLoadDiag_CannotLoad = 2,
568
569 /**
570 * \brief Indicates that the serialized diagnostics file is invalid or
571 * corrupt.
572 */
573 CXLoadDiag_InvalidFile = 3
574};
575
576/**
577 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
578 * file.
579 *
580 * \param The name of the file to deserialize.
581 * \param A pointer to a enum value recording if there was a problem
582 * deserializing the diagnostics.
583 * \param A pointer to a CXString for recording the error string
584 * if the file was not successfully loaded.
585 *
586 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
587 * diagnostics should be released using clang_disposeDiagnosticSet().
588 */
589CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
590 enum CXLoadDiag_Error *error,
591 CXString *errorString);
592
593/**
594 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
595 */
596CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
597
598/**
599 * \brief Retrieve the child diagnostics of a CXDiagnostic. This
600 * CXDiagnosticSet does not need to be released by clang_diposeDiagnosticSet.
601 */
602CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
603
604/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000605 * \brief Determine the number of diagnostics produced for the given
606 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000607 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000608CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
609
610/**
611 * \brief Retrieve a diagnostic associated with the given translation unit.
612 *
613 * \param Unit the translation unit to query.
614 * \param Index the zero-based diagnostic number to retrieve.
615 *
616 * \returns the requested diagnostic. This diagnostic must be freed
617 * via a call to \c clang_disposeDiagnostic().
618 */
619CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
620 unsigned Index);
621
622/**
Ted Kremenek0373fcc2011-12-09 22:28:32 +0000623 * \brief Retrieve the complete set of diagnostics associated with a
624 * translation unit.
625 *
626 * \param Unit the translation unit to query.
627 */
628CINDEX_LINKAGE CXDiagnosticSet
629 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
630
631/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000632 * \brief Destroy a diagnostic.
633 */
634CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000635
636/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000637 * \brief Options to control the display of diagnostics.
638 *
639 * The values in this enum are meant to be combined to customize the
640 * behavior of \c clang_displayDiagnostic().
641 */
642enum CXDiagnosticDisplayOptions {
643 /**
644 * \brief Display the source-location information where the
645 * diagnostic was located.
646 *
647 * When set, diagnostics will be prefixed by the file, line, and
648 * (optionally) column to which the diagnostic refers. For example,
649 *
650 * \code
651 * test.c:28: warning: extra tokens at end of #endif directive
652 * \endcode
653 *
654 * This option corresponds to the clang flag \c -fshow-source-location.
655 */
656 CXDiagnostic_DisplaySourceLocation = 0x01,
657
658 /**
659 * \brief If displaying the source-location information of the
660 * diagnostic, also include the column number.
661 *
662 * This option corresponds to the clang flag \c -fshow-column.
663 */
664 CXDiagnostic_DisplayColumn = 0x02,
665
666 /**
667 * \brief If displaying the source-location information of the
668 * diagnostic, also include information about source ranges in a
669 * machine-parsable format.
670 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000671 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000672 * \c -fdiagnostics-print-source-range-info.
673 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000674 CXDiagnostic_DisplaySourceRanges = 0x04,
675
676 /**
677 * \brief Display the option name associated with this diagnostic, if any.
678 *
679 * The option name displayed (e.g., -Wconversion) will be placed in brackets
680 * after the diagnostic text. This option corresponds to the clang flag
681 * \c -fdiagnostics-show-option.
682 */
683 CXDiagnostic_DisplayOption = 0x08,
684
685 /**
686 * \brief Display the category number associated with this diagnostic, if any.
687 *
688 * The category number is displayed within brackets after the diagnostic text.
689 * This option corresponds to the clang flag
690 * \c -fdiagnostics-show-category=id.
691 */
692 CXDiagnostic_DisplayCategoryId = 0x10,
693
694 /**
695 * \brief Display the category name associated with this diagnostic, if any.
696 *
697 * The category name is displayed within brackets after the diagnostic text.
698 * This option corresponds to the clang flag
699 * \c -fdiagnostics-show-category=name.
700 */
701 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000702};
703
704/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000705 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000706 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000707 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000708 * the diagnostic according to the various options given. The
709 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000710 * options that most closely mimics the behavior of the clang compiler.
711 *
712 * \param Diagnostic The diagnostic to print.
713 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000714 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000715 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000716 *
717 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000718 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000719CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
720 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000721
722/**
723 * \brief Retrieve the set of display options most similar to the
724 * default behavior of the clang compiler.
725 *
726 * \returns A set of display options suitable for use with \c
727 * clang_displayDiagnostic().
728 */
729CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
730
731/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000732 * \brief Determine the severity of the given diagnostic.
733 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000734CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000735clang_getDiagnosticSeverity(CXDiagnostic);
736
737/**
738 * \brief Retrieve the source location of the given diagnostic.
739 *
740 * This location is where Clang would print the caret ('^') when
741 * displaying the diagnostic on the command line.
742 */
743CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
744
745/**
746 * \brief Retrieve the text of the given diagnostic.
747 */
748CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000749
750/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000751 * \brief Retrieve the name of the command-line option that enabled this
752 * diagnostic.
753 *
754 * \param Diag The diagnostic to be queried.
755 *
756 * \param Disable If non-NULL, will be set to the option that disables this
757 * diagnostic (if any).
758 *
759 * \returns A string that contains the command-line option used to enable this
760 * warning, such as "-Wconversion" or "-pedantic".
761 */
762CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
763 CXString *Disable);
764
765/**
766 * \brief Retrieve the category number for this diagnostic.
767 *
768 * Diagnostics can be categorized into groups along with other, related
769 * diagnostics (e.g., diagnostics under the same warning flag). This routine
770 * retrieves the category number for the given diagnostic.
771 *
772 * \returns The number of the category that contains this diagnostic, or zero
773 * if this diagnostic is uncategorized.
774 */
775CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
776
777/**
778 * \brief Retrieve the name of a particular diagnostic category.
779 *
780 * \param Category A diagnostic category number, as returned by
781 * \c clang_getDiagnosticCategory().
782 *
783 * \returns The name of the given diagnostic category.
784 */
785CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
786
787/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000788 * \brief Determine the number of source ranges associated with the given
789 * diagnostic.
790 */
791CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000792
Douglas Gregor5352ac02010-01-28 00:27:43 +0000793/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000794 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000795 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000796 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000797 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000798 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000799 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000800 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000801 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000802 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000803 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000804 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000805 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000806CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000807 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000808
809/**
810 * \brief Determine the number of fix-it hints associated with the
811 * given diagnostic.
812 */
813CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
814
815/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000816 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000817 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000818 * Fix-its are described in terms of a source range whose contents
819 * should be replaced by a string. This approach generalizes over
820 * three kinds of operations: removal of source code (the range covers
821 * the code to be removed and the replacement string is empty),
822 * replacement of source code (the range covers the code to be
823 * replaced and the replacement string provides the new code), and
824 * insertion (both the start and end of the range point at the
825 * insertion location, and the replacement string provides the text to
826 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000827 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000828 * \param Diagnostic The diagnostic whose fix-its are being queried.
829 *
830 * \param FixIt The zero-based index of the fix-it.
831 *
832 * \param ReplacementRange The source range whose contents will be
833 * replaced with the returned replacement string. Note that source
834 * ranges are half-open ranges [a, b), so the source code should be
835 * replaced from a and up to (but not including) b.
836 *
837 * \returns A string containing text that should be replace the source
838 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000839 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000840CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000841 unsigned FixIt,
842 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000843
844/**
845 * @}
846 */
847
848/**
849 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
850 *
851 * The routines in this group provide the ability to create and destroy
852 * translation units from files, either by parsing the contents of the files or
853 * by reading in a serialized representation of a translation unit.
854 *
855 * @{
856 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000857
Douglas Gregor5352ac02010-01-28 00:27:43 +0000858/**
859 * \brief Get the original translation unit source file name.
860 */
861CINDEX_LINKAGE CXString
862clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
863
864/**
865 * \brief Return the CXTranslationUnit for a given source file and the provided
866 * command line arguments one would pass to the compiler.
867 *
868 * Note: The 'source_filename' argument is optional. If the caller provides a
869 * NULL pointer, the name of the source file is expected to reside in the
870 * specified command line arguments.
871 *
872 * Note: When encountered in 'clang_command_line_args', the following options
873 * are ignored:
874 *
875 * '-c'
876 * '-emit-ast'
877 * '-fsyntax-only'
878 * '-o <output file>' (both '-o' and '<output file>' are ignored)
879 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000880 * \param CIdx The index object with which the translation unit will be
881 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000882 *
883 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000884 * source file is included in \p clang_command_line_args.
885 *
886 * \param num_clang_command_line_args The number of command-line arguments in
887 * \p clang_command_line_args.
888 *
889 * \param clang_command_line_args The command-line arguments that would be
890 * passed to the \c clang executable if it were being invoked out-of-process.
891 * These command-line options will be parsed and will affect how the translation
892 * unit is parsed. Note that the following options are ignored: '-c',
893 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000894 *
895 * \param num_unsaved_files the number of unsaved file entries in \p
896 * unsaved_files.
897 *
898 * \param unsaved_files the files that have not yet been saved to disk
899 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000900 * those files. The contents and name of these files (as specified by
901 * CXUnsavedFile) are copied when necessary, so the client only needs to
902 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000903 */
904CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
905 CXIndex CIdx,
906 const char *source_filename,
907 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000908 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000909 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000910 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000911
Douglas Gregor5352ac02010-01-28 00:27:43 +0000912/**
913 * \brief Create a translation unit from an AST file (-emit-ast).
914 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000915CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000916 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000917
Douglas Gregor44c181a2010-07-23 00:33:23 +0000918/**
919 * \brief Flags that control the creation of translation units.
920 *
921 * The enumerators in this enumeration type are meant to be bitwise
922 * ORed together to specify which options should be used when
923 * constructing the translation unit.
924 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000925enum CXTranslationUnit_Flags {
926 /**
927 * \brief Used to indicate that no special translation-unit options are
928 * needed.
929 */
930 CXTranslationUnit_None = 0x0,
931
932 /**
933 * \brief Used to indicate that the parser should construct a "detailed"
934 * preprocessing record, including all macro definitions and instantiations.
935 *
936 * Constructing a detailed preprocessing record requires more memory
937 * and time to parse, since the information contained in the record
938 * is usually not retained. However, it can be useful for
939 * applications that require more detailed information about the
940 * behavior of the preprocessor.
941 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000942 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
943
944 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000945 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000946 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000947 * When a translation unit is considered "incomplete", semantic
948 * analysis that is typically performed at the end of the
949 * translation unit will be suppressed. For example, this suppresses
950 * the completion of tentative declarations in C and of
951 * instantiation of implicitly-instantiation function templates in
952 * C++. This option is typically used when parsing a header with the
953 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000954 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000955 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000956
957 /**
958 * \brief Used to indicate that the translation unit should be built with an
959 * implicit precompiled header for the preamble.
960 *
961 * An implicit precompiled header is used as an optimization when a
962 * particular translation unit is likely to be reparsed many times
963 * when the sources aren't changing that often. In this case, an
964 * implicit precompiled header will be built containing all of the
965 * initial includes at the top of the main file (what we refer to as
966 * the "preamble" of the file). In subsequent parses, if the
967 * preamble or the files in it have not changed, \c
968 * clang_reparseTranslationUnit() will re-use the implicit
969 * precompiled header to improve parsing performance.
970 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000971 CXTranslationUnit_PrecompiledPreamble = 0x04,
972
973 /**
974 * \brief Used to indicate that the translation unit should cache some
975 * code-completion results with each reparse of the source file.
976 *
977 * Caching of code-completion results is a performance optimization that
978 * introduces some overhead to reparsing but improves the performance of
979 * code-completion operations.
980 */
Douglas Gregor99ba2022010-10-27 17:24:53 +0000981 CXTranslationUnit_CacheCompletionResults = 0x08,
982 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +0000983 * \brief DEPRECATED: Enable precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000984 *
985 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +0000986 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000987 */
988 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
989
990 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +0000991 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000992 *
993 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +0000994 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000995 */
Argyrios Kyrtzidise1d43302012-02-25 02:41:16 +0000996 CXTranslationUnit_CXXChainedPCH = 0x20
Douglas Gregor5a430212010-07-21 18:52:53 +0000997};
998
999/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001000 * \brief Returns the set of flags that is suitable for parsing a translation
1001 * unit that is being edited.
1002 *
1003 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1004 * to indicate that the translation unit is likely to be reparsed many times,
1005 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1006 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1007 * set contains an unspecified set of optimizations (e.g., the precompiled
1008 * preamble) geared toward improving the performance of these routines. The
1009 * set of optimizations enabled may change from one version to the next.
1010 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001011CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +00001012
1013/**
Douglas Gregor5a430212010-07-21 18:52:53 +00001014 * \brief Parse the given source file and the translation unit corresponding
1015 * to that file.
1016 *
1017 * This routine is the main entry point for the Clang C API, providing the
1018 * ability to parse a source file into a translation unit that can then be
1019 * queried by other functions in the API. This routine accepts a set of
1020 * command-line arguments so that the compilation can be configured in the same
1021 * way that the compiler is configured on the command line.
1022 *
1023 * \param CIdx The index object with which the translation unit will be
1024 * associated.
1025 *
1026 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +00001027 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +00001028 *
1029 * \param command_line_args The command-line arguments that would be
1030 * passed to the \c clang executable if it were being invoked out-of-process.
1031 * These command-line options will be parsed and will affect how the translation
1032 * unit is parsed. Note that the following options are ignored: '-c',
1033 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
1034 *
1035 * \param num_command_line_args The number of command-line arguments in
1036 * \p command_line_args.
1037 *
1038 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00001039 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +00001040 * those files. The contents and name of these files (as specified by
1041 * CXUnsavedFile) are copied when necessary, so the client only needs to
1042 * guarantee their validity until the call to this function returns.
1043 *
1044 * \param num_unsaved_files the number of unsaved file entries in \p
1045 * unsaved_files.
1046 *
1047 * \param options A bitmask of options that affects how the translation unit
1048 * is managed but not its compilation. This should be a bitwise OR of the
1049 * CXTranslationUnit_XXX flags.
1050 *
1051 * \returns A new translation unit describing the parsed code and containing
1052 * any diagnostics produced by the compiler. If there is a failure from which
1053 * the compiler cannot recover, returns NULL.
1054 */
1055CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1056 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +00001057 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +00001058 int num_command_line_args,
1059 struct CXUnsavedFile *unsaved_files,
1060 unsigned num_unsaved_files,
1061 unsigned options);
1062
Douglas Gregor5352ac02010-01-28 00:27:43 +00001063/**
Douglas Gregor19998442010-08-13 15:35:05 +00001064 * \brief Flags that control how translation units are saved.
1065 *
1066 * The enumerators in this enumeration type are meant to be bitwise
1067 * ORed together to specify which options should be used when
1068 * saving the translation unit.
1069 */
1070enum CXSaveTranslationUnit_Flags {
1071 /**
1072 * \brief Used to indicate that no special saving options are needed.
1073 */
1074 CXSaveTranslationUnit_None = 0x0
1075};
1076
1077/**
1078 * \brief Returns the set of flags that is suitable for saving a translation
1079 * unit.
1080 *
1081 * The set of flags returned provide options for
1082 * \c clang_saveTranslationUnit() by default. The returned flag
1083 * set contains an unspecified set of options that save translation units with
1084 * the most commonly-requested data.
1085 */
1086CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1087
1088/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001089 * \brief Describes the kind of error that occurred (if any) in a call to
1090 * \c clang_saveTranslationUnit().
1091 */
1092enum CXSaveError {
1093 /**
1094 * \brief Indicates that no error occurred while saving a translation unit.
1095 */
1096 CXSaveError_None = 0,
1097
1098 /**
1099 * \brief Indicates that an unknown error occurred while attempting to save
1100 * the file.
1101 *
1102 * This error typically indicates that file I/O failed when attempting to
1103 * write the file.
1104 */
1105 CXSaveError_Unknown = 1,
1106
1107 /**
1108 * \brief Indicates that errors during translation prevented this attempt
1109 * to save the translation unit.
1110 *
1111 * Errors that prevent the translation unit from being saved can be
1112 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1113 */
1114 CXSaveError_TranslationErrors = 2,
1115
1116 /**
1117 * \brief Indicates that the translation unit to be saved was somehow
1118 * invalid (e.g., NULL).
1119 */
1120 CXSaveError_InvalidTU = 3
1121};
1122
1123/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001124 * \brief Saves a translation unit into a serialized representation of
1125 * that translation unit on disk.
1126 *
1127 * Any translation unit that was parsed without error can be saved
1128 * into a file. The translation unit can then be deserialized into a
1129 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1130 * if it is an incomplete translation unit that corresponds to a
1131 * header, used as a precompiled header when parsing other translation
1132 * units.
1133 *
1134 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001135 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001136 * \param FileName The file to which the translation unit will be saved.
1137 *
Douglas Gregor19998442010-08-13 15:35:05 +00001138 * \param options A bitmask of options that affects how the translation unit
1139 * is saved. This should be a bitwise OR of the
1140 * CXSaveTranslationUnit_XXX flags.
1141 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001142 * \returns A value that will match one of the enumerators of the CXSaveError
1143 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1144 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001145 */
1146CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001147 const char *FileName,
1148 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001149
1150/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001151 * \brief Destroy the specified CXTranslationUnit object.
1152 */
1153CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001154
Douglas Gregor5352ac02010-01-28 00:27:43 +00001155/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001156 * \brief Flags that control the reparsing of translation units.
1157 *
1158 * The enumerators in this enumeration type are meant to be bitwise
1159 * ORed together to specify which options should be used when
1160 * reparsing the translation unit.
1161 */
1162enum CXReparse_Flags {
1163 /**
1164 * \brief Used to indicate that no special reparsing options are needed.
1165 */
1166 CXReparse_None = 0x0
1167};
1168
1169/**
1170 * \brief Returns the set of flags that is suitable for reparsing a translation
1171 * unit.
1172 *
1173 * The set of flags returned provide options for
1174 * \c clang_reparseTranslationUnit() by default. The returned flag
1175 * set contains an unspecified set of optimizations geared toward common uses
1176 * of reparsing. The set of optimizations enabled may change from one version
1177 * to the next.
1178 */
1179CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1180
1181/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001182 * \brief Reparse the source files that produced this translation unit.
1183 *
1184 * This routine can be used to re-parse the source files that originally
1185 * created the given translation unit, for example because those source files
1186 * have changed (either on disk or as passed via \p unsaved_files). The
1187 * source code will be reparsed with the same command-line options as it
1188 * was originally parsed.
1189 *
1190 * Reparsing a translation unit invalidates all cursors and source locations
1191 * that refer into that translation unit. This makes reparsing a translation
1192 * unit semantically equivalent to destroying the translation unit and then
1193 * creating a new translation unit with the same command-line arguments.
1194 * However, it may be more efficient to reparse a translation
1195 * unit using this routine.
1196 *
1197 * \param TU The translation unit whose contents will be re-parsed. The
1198 * translation unit must originally have been built with
1199 * \c clang_createTranslationUnitFromSourceFile().
1200 *
1201 * \param num_unsaved_files The number of unsaved file entries in \p
1202 * unsaved_files.
1203 *
1204 * \param unsaved_files The files that have not yet been saved to disk
1205 * but may be required for parsing, including the contents of
1206 * those files. The contents and name of these files (as specified by
1207 * CXUnsavedFile) are copied when necessary, so the client only needs to
1208 * guarantee their validity until the call to this function returns.
1209 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001210 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1211 * The function \c clang_defaultReparseOptions() produces a default set of
1212 * options recommended for most uses, based on the translation unit.
1213 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001214 * \returns 0 if the sources could be reparsed. A non-zero value will be
1215 * returned if reparsing was impossible, such that the translation unit is
1216 * invalid. In such cases, the only valid call for \p TU is
1217 * \c clang_disposeTranslationUnit(TU).
1218 */
1219CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1220 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001221 struct CXUnsavedFile *unsaved_files,
1222 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001223
1224/**
1225 * \brief Categorizes how memory is being used by a translation unit.
1226 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001227enum CXTUResourceUsageKind {
1228 CXTUResourceUsage_AST = 1,
1229 CXTUResourceUsage_Identifiers = 2,
1230 CXTUResourceUsage_Selectors = 3,
1231 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001232 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001233 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001234 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001235 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1236 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1237 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001238 CXTUResourceUsage_Preprocessor = 11,
1239 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001240 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001241 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001242 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1243 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001244 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001245
1246 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001247 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001248};
1249
1250/**
1251 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001252 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001253 */
1254CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001255const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001256
Ted Kremenekf7870022011-04-20 16:41:07 +00001257typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001258 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001259 enum CXTUResourceUsageKind kind;
1260 /* \brief Amount of resources used.
1261 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001262 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001263} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001264
1265/**
1266 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1267 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001268typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001269 /* \brief Private data member, used for queries. */
1270 void *data;
1271
1272 /* \brief The number of entries in the 'entries' array. */
1273 unsigned numEntries;
1274
1275 /* \brief An array of key-value pairs, representing the breakdown of memory
1276 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001277 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001278
Ted Kremenekf7870022011-04-20 16:41:07 +00001279} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001280
1281/**
1282 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001283 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001284 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001285CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001286
Ted Kremenekf7870022011-04-20 16:41:07 +00001287CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001288
Douglas Gregorabc563f2010-07-19 21:46:24 +00001289/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001290 * @}
1291 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001292
Douglas Gregor5352ac02010-01-28 00:27:43 +00001293/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001294 * \brief Describes the kind of entity that a cursor refers to.
1295 */
1296enum CXCursorKind {
1297 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001298 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001299 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001300 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001301 *
1302 * Unexposed declarations have the same operations as any other kind
1303 * of declaration; one can extract their location information,
1304 * spelling, find their definitions, etc. However, the specific kind
1305 * of the declaration is not reported.
1306 */
1307 CXCursor_UnexposedDecl = 1,
1308 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001309 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001310 /** \brief A C or C++ union. */
1311 CXCursor_UnionDecl = 3,
1312 /** \brief A C++ class. */
1313 CXCursor_ClassDecl = 4,
1314 /** \brief An enumeration. */
1315 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001316 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001317 * \brief A field (in C) or non-static data member (in C++) in a
1318 * struct, union, or C++ class.
1319 */
1320 CXCursor_FieldDecl = 6,
1321 /** \brief An enumerator constant. */
1322 CXCursor_EnumConstantDecl = 7,
1323 /** \brief A function. */
1324 CXCursor_FunctionDecl = 8,
1325 /** \brief A variable. */
1326 CXCursor_VarDecl = 9,
1327 /** \brief A function or method parameter. */
1328 CXCursor_ParmDecl = 10,
1329 /** \brief An Objective-C @interface. */
1330 CXCursor_ObjCInterfaceDecl = 11,
1331 /** \brief An Objective-C @interface for a category. */
1332 CXCursor_ObjCCategoryDecl = 12,
1333 /** \brief An Objective-C @protocol declaration. */
1334 CXCursor_ObjCProtocolDecl = 13,
1335 /** \brief An Objective-C @property declaration. */
1336 CXCursor_ObjCPropertyDecl = 14,
1337 /** \brief An Objective-C instance variable. */
1338 CXCursor_ObjCIvarDecl = 15,
1339 /** \brief An Objective-C instance method. */
1340 CXCursor_ObjCInstanceMethodDecl = 16,
1341 /** \brief An Objective-C class method. */
1342 CXCursor_ObjCClassMethodDecl = 17,
1343 /** \brief An Objective-C @implementation. */
1344 CXCursor_ObjCImplementationDecl = 18,
1345 /** \brief An Objective-C @implementation for a category. */
1346 CXCursor_ObjCCategoryImplDecl = 19,
1347 /** \brief A typedef */
1348 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001349 /** \brief A C++ class method. */
1350 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001351 /** \brief A C++ namespace. */
1352 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001353 /** \brief A linkage specification, e.g. 'extern "C"'. */
1354 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001355 /** \brief A C++ constructor. */
1356 CXCursor_Constructor = 24,
1357 /** \brief A C++ destructor. */
1358 CXCursor_Destructor = 25,
1359 /** \brief A C++ conversion function. */
1360 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001361 /** \brief A C++ template type parameter. */
1362 CXCursor_TemplateTypeParameter = 27,
1363 /** \brief A C++ non-type template parameter. */
1364 CXCursor_NonTypeTemplateParameter = 28,
1365 /** \brief A C++ template template parameter. */
1366 CXCursor_TemplateTemplateParameter = 29,
1367 /** \brief A C++ function template. */
1368 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001369 /** \brief A C++ class template. */
1370 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001371 /** \brief A C++ class template partial specialization. */
1372 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001373 /** \brief A C++ namespace alias declaration. */
1374 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001375 /** \brief A C++ using directive. */
1376 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001377 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001378 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001379 /** \brief A C++ alias declaration */
1380 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001381 /** \brief An Objective-C @synthesize definition. */
1382 CXCursor_ObjCSynthesizeDecl = 37,
1383 /** \brief An Objective-C @dynamic definition. */
1384 CXCursor_ObjCDynamicDecl = 38,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001385 /** \brief An access specifier. */
1386 CXCursor_CXXAccessSpecifier = 39,
Douglas Gregor42b29842011-10-05 19:00:14 +00001387
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001388 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00001389 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001390
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001391 /* References */
1392 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001393 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001394 CXCursor_ObjCProtocolRef = 41,
1395 CXCursor_ObjCClassRef = 42,
1396 /**
1397 * \brief A reference to a type declaration.
1398 *
1399 * A type reference occurs anywhere where a type is named but not
1400 * declared. For example, given:
1401 *
1402 * \code
1403 * typedef unsigned size_type;
1404 * size_type size;
1405 * \endcode
1406 *
1407 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1408 * while the type of the variable "size" is referenced. The cursor
1409 * referenced by the type of size is the typedef for size_type.
1410 */
1411 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001412 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001413 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001414 * \brief A reference to a class template, function template, template
1415 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001416 */
1417 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001418 /**
1419 * \brief A reference to a namespace or namespace alias.
1420 */
1421 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001422 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001423 * \brief A reference to a member of a struct, union, or class that occurs in
1424 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001425 */
1426 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001427 /**
1428 * \brief A reference to a labeled statement.
1429 *
1430 * This cursor kind is used to describe the jump to "start_over" in the
1431 * goto statement in the following example:
1432 *
1433 * \code
1434 * start_over:
1435 * ++counter;
1436 *
1437 * goto start_over;
1438 * \endcode
1439 *
1440 * A label reference cursor refers to a label statement.
1441 */
1442 CXCursor_LabelRef = 48,
1443
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001444 /**
1445 * \brief A reference to a set of overloaded functions or function templates
1446 * that has not yet been resolved to a specific function or function template.
1447 *
1448 * An overloaded declaration reference cursor occurs in C++ templates where
1449 * a dependent name refers to a function. For example:
1450 *
1451 * \code
1452 * template<typename T> void swap(T&, T&);
1453 *
1454 * struct X { ... };
1455 * void swap(X&, X&);
1456 *
1457 * template<typename T>
1458 * void reverse(T* first, T* last) {
1459 * while (first < last - 1) {
1460 * swap(*first, *--last);
1461 * ++first;
1462 * }
1463 * }
1464 *
1465 * struct Y { };
1466 * void swap(Y&, Y&);
1467 * \endcode
1468 *
1469 * Here, the identifier "swap" is associated with an overloaded declaration
1470 * reference. In the template definition, "swap" refers to either of the two
1471 * "swap" functions declared above, so both results will be available. At
1472 * instantiation time, "swap" may also refer to other functions found via
1473 * argument-dependent lookup (e.g., the "swap" function at the end of the
1474 * example).
1475 *
1476 * The functions \c clang_getNumOverloadedDecls() and
1477 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1478 * referenced by this cursor.
1479 */
1480 CXCursor_OverloadedDeclRef = 49,
1481
Douglas Gregor011d8b92012-02-15 00:54:55 +00001482 /**
1483 * \brief A reference to a variable that occurs in some non-expression
1484 * context, e.g., a C++ lambda capture list.
1485 */
1486 CXCursor_VariableRef = 50,
1487
1488 CXCursor_LastRef = CXCursor_VariableRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001489
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001490 /* Error conditions */
1491 CXCursor_FirstInvalid = 70,
1492 CXCursor_InvalidFile = 70,
1493 CXCursor_NoDeclFound = 71,
1494 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001495 CXCursor_InvalidCode = 73,
1496 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001497
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001498 /* Expressions */
1499 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001500
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001501 /**
1502 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001503 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001504 *
1505 * Unexposed expressions have the same operations as any other kind
1506 * of expression; one can extract their location information,
1507 * spelling, children, etc. However, the specific kind of the
1508 * expression is not reported.
1509 */
1510 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001511
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001512 /**
1513 * \brief An expression that refers to some value declaration, such
1514 * as a function, varible, or enumerator.
1515 */
1516 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001517
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001518 /**
1519 * \brief An expression that refers to a member of a struct, union,
1520 * class, Objective-C class, etc.
1521 */
1522 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001523
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001524 /** \brief An expression that calls a function. */
1525 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001526
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001527 /** \brief An expression that sends a message to an Objective-C
1528 object or class. */
1529 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001530
1531 /** \brief An expression that represents a block literal. */
1532 CXCursor_BlockExpr = 105,
1533
Douglas Gregor42b29842011-10-05 19:00:14 +00001534 /** \brief An integer literal.
1535 */
1536 CXCursor_IntegerLiteral = 106,
1537
1538 /** \brief A floating point number literal.
1539 */
1540 CXCursor_FloatingLiteral = 107,
1541
1542 /** \brief An imaginary number literal.
1543 */
1544 CXCursor_ImaginaryLiteral = 108,
1545
1546 /** \brief A string literal.
1547 */
1548 CXCursor_StringLiteral = 109,
1549
1550 /** \brief A character literal.
1551 */
1552 CXCursor_CharacterLiteral = 110,
1553
1554 /** \brief A parenthesized expression, e.g. "(1)".
1555 *
1556 * This AST node is only formed if full location information is requested.
1557 */
1558 CXCursor_ParenExpr = 111,
1559
1560 /** \brief This represents the unary-expression's (except sizeof and
1561 * alignof).
1562 */
1563 CXCursor_UnaryOperator = 112,
1564
1565 /** \brief [C99 6.5.2.1] Array Subscripting.
1566 */
1567 CXCursor_ArraySubscriptExpr = 113,
1568
1569 /** \brief A builtin binary operation expression such as "x + y" or
1570 * "x <= y".
1571 */
1572 CXCursor_BinaryOperator = 114,
1573
1574 /** \brief Compound assignment such as "+=".
1575 */
1576 CXCursor_CompoundAssignOperator = 115,
1577
1578 /** \brief The ?: ternary operator.
1579 */
1580 CXCursor_ConditionalOperator = 116,
1581
1582 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1583 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1584 *
1585 * For example: (int)f.
1586 */
1587 CXCursor_CStyleCastExpr = 117,
1588
1589 /** \brief [C99 6.5.2.5]
1590 */
1591 CXCursor_CompoundLiteralExpr = 118,
1592
1593 /** \brief Describes an C or C++ initializer list.
1594 */
1595 CXCursor_InitListExpr = 119,
1596
1597 /** \brief The GNU address of label extension, representing &&label.
1598 */
1599 CXCursor_AddrLabelExpr = 120,
1600
1601 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1602 */
1603 CXCursor_StmtExpr = 121,
1604
Benjamin Kramerffbe9b92011-12-23 17:00:35 +00001605 /** \brief Represents a C11 generic selection.
Douglas Gregor42b29842011-10-05 19:00:14 +00001606 */
1607 CXCursor_GenericSelectionExpr = 122,
1608
1609 /** \brief Implements the GNU __null extension, which is a name for a null
1610 * pointer constant that has integral type (e.g., int or long) and is the same
1611 * size and alignment as a pointer.
1612 *
1613 * The __null extension is typically only used by system headers, which define
1614 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1615 * match the size of a pointer).
1616 */
1617 CXCursor_GNUNullExpr = 123,
1618
1619 /** \brief C++'s static_cast<> expression.
1620 */
1621 CXCursor_CXXStaticCastExpr = 124,
1622
1623 /** \brief C++'s dynamic_cast<> expression.
1624 */
1625 CXCursor_CXXDynamicCastExpr = 125,
1626
1627 /** \brief C++'s reinterpret_cast<> expression.
1628 */
1629 CXCursor_CXXReinterpretCastExpr = 126,
1630
1631 /** \brief C++'s const_cast<> expression.
1632 */
1633 CXCursor_CXXConstCastExpr = 127,
1634
1635 /** \brief Represents an explicit C++ type conversion that uses "functional"
1636 * notion (C++ [expr.type.conv]).
1637 *
1638 * Example:
1639 * \code
1640 * x = int(0.5);
1641 * \endcode
1642 */
1643 CXCursor_CXXFunctionalCastExpr = 128,
1644
1645 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1646 */
1647 CXCursor_CXXTypeidExpr = 129,
1648
1649 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1650 */
1651 CXCursor_CXXBoolLiteralExpr = 130,
1652
1653 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1654 */
1655 CXCursor_CXXNullPtrLiteralExpr = 131,
1656
1657 /** \brief Represents the "this" expression in C++
1658 */
1659 CXCursor_CXXThisExpr = 132,
1660
1661 /** \brief [C++ 15] C++ Throw Expression.
1662 *
1663 * This handles 'throw' and 'throw' assignment-expression. When
1664 * assignment-expression isn't present, Op will be null.
1665 */
1666 CXCursor_CXXThrowExpr = 133,
1667
1668 /** \brief A new expression for memory allocation and constructor calls, e.g:
1669 * "new CXXNewExpr(foo)".
1670 */
1671 CXCursor_CXXNewExpr = 134,
1672
1673 /** \brief A delete expression for memory deallocation and destructor calls,
1674 * e.g. "delete[] pArray".
1675 */
1676 CXCursor_CXXDeleteExpr = 135,
1677
1678 /** \brief A unary expression.
1679 */
1680 CXCursor_UnaryExpr = 136,
1681
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001682 /** \brief An Objective-C string literal i.e. @"foo".
Douglas Gregor42b29842011-10-05 19:00:14 +00001683 */
1684 CXCursor_ObjCStringLiteral = 137,
1685
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001686 /** \brief An Objective-C @encode expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001687 */
1688 CXCursor_ObjCEncodeExpr = 138,
1689
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001690 /** \brief An Objective-C @selector expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001691 */
1692 CXCursor_ObjCSelectorExpr = 139,
1693
Douglas Gregor9793e8f2011-11-11 22:35:18 +00001694 /** \brief An Objective-C @protocol expression.
Douglas Gregor42b29842011-10-05 19:00:14 +00001695 */
1696 CXCursor_ObjCProtocolExpr = 140,
1697
1698 /** \brief An Objective-C "bridged" cast expression, which casts between
1699 * Objective-C pointers and C pointers, transferring ownership in the process.
1700 *
1701 * \code
1702 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1703 * \endcode
1704 */
1705 CXCursor_ObjCBridgedCastExpr = 141,
1706
1707 /** \brief Represents a C++0x pack expansion that produces a sequence of
1708 * expressions.
1709 *
1710 * A pack expansion expression contains a pattern (which itself is an
1711 * expression) followed by an ellipsis. For example:
1712 *
1713 * \code
1714 * template<typename F, typename ...Types>
1715 * void forward(F f, Types &&...args) {
1716 * f(static_cast<Types&&>(args)...);
1717 * }
1718 * \endcode
1719 */
1720 CXCursor_PackExpansionExpr = 142,
1721
1722 /** \brief Represents an expression that computes the length of a parameter
1723 * pack.
1724 *
1725 * \code
1726 * template<typename ...Types>
1727 * struct count {
1728 * static const unsigned value = sizeof...(Types);
1729 * };
1730 * \endcode
1731 */
1732 CXCursor_SizeOfPackExpr = 143,
1733
Douglas Gregor011d8b92012-02-15 00:54:55 +00001734 /* \brief Represents a C++ lambda expression that produces a local function
1735 * object.
1736 *
1737 * \code
1738 * void abssort(float *x, unsigned N) {
1739 * std::sort(x, x + N,
1740 * [](float a, float b) {
1741 * return std::abs(a) < std::abs(b);
1742 * });
1743 * }
1744 * \endcode
1745 */
1746 CXCursor_LambdaExpr = 144,
1747
Ted Kremenekb3f75422012-03-06 20:06:06 +00001748 /** \brief Objective-c Boolean Literal.
1749 */
1750 CXCursor_ObjCBoolLiteralExpr = 145,
1751
1752 CXCursor_LastExpr = CXCursor_ObjCBoolLiteralExpr,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001753
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001754 /* Statements */
1755 CXCursor_FirstStmt = 200,
1756 /**
1757 * \brief A statement whose specific kind is not exposed via this
1758 * interface.
1759 *
1760 * Unexposed statements have the same operations as any other kind of
1761 * statement; one can extract their location information, spelling,
1762 * children, etc. However, the specific kind of the statement is not
1763 * reported.
1764 */
1765 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001766
1767 /** \brief A labelled statement in a function.
1768 *
1769 * This cursor kind is used to describe the "start_over:" label statement in
1770 * the following example:
1771 *
1772 * \code
1773 * start_over:
1774 * ++counter;
1775 * \endcode
1776 *
1777 */
1778 CXCursor_LabelStmt = 201,
Douglas Gregor42b29842011-10-05 19:00:14 +00001779
1780 /** \brief A group of statements like { stmt stmt }.
1781 *
1782 * This cursor kind is used to describe compound statements, e.g. function
1783 * bodies.
1784 */
1785 CXCursor_CompoundStmt = 202,
1786
1787 /** \brief A case statment.
1788 */
1789 CXCursor_CaseStmt = 203,
1790
1791 /** \brief A default statement.
1792 */
1793 CXCursor_DefaultStmt = 204,
1794
1795 /** \brief An if statement
1796 */
1797 CXCursor_IfStmt = 205,
1798
1799 /** \brief A switch statement.
1800 */
1801 CXCursor_SwitchStmt = 206,
1802
1803 /** \brief A while statement.
1804 */
1805 CXCursor_WhileStmt = 207,
1806
1807 /** \brief A do statement.
1808 */
1809 CXCursor_DoStmt = 208,
1810
1811 /** \brief A for statement.
1812 */
1813 CXCursor_ForStmt = 209,
1814
1815 /** \brief A goto statement.
1816 */
1817 CXCursor_GotoStmt = 210,
1818
1819 /** \brief An indirect goto statement.
1820 */
1821 CXCursor_IndirectGotoStmt = 211,
1822
1823 /** \brief A continue statement.
1824 */
1825 CXCursor_ContinueStmt = 212,
1826
1827 /** \brief A break statement.
1828 */
1829 CXCursor_BreakStmt = 213,
1830
1831 /** \brief A return statement.
1832 */
1833 CXCursor_ReturnStmt = 214,
1834
1835 /** \brief A GNU inline assembly statement extension.
1836 */
1837 CXCursor_AsmStmt = 215,
1838
Douglas Gregor3f54d482011-11-08 21:07:04 +00001839 /** \brief Objective-C's overall @try-@catch-@finally statement.
Douglas Gregor42b29842011-10-05 19:00:14 +00001840 */
1841 CXCursor_ObjCAtTryStmt = 216,
1842
1843 /** \brief Objective-C's @catch statement.
1844 */
1845 CXCursor_ObjCAtCatchStmt = 217,
1846
1847 /** \brief Objective-C's @finally statement.
1848 */
1849 CXCursor_ObjCAtFinallyStmt = 218,
1850
1851 /** \brief Objective-C's @throw statement.
1852 */
1853 CXCursor_ObjCAtThrowStmt = 219,
1854
1855 /** \brief Objective-C's @synchronized statement.
1856 */
1857 CXCursor_ObjCAtSynchronizedStmt = 220,
1858
1859 /** \brief Objective-C's autorelease pool statement.
1860 */
1861 CXCursor_ObjCAutoreleasePoolStmt = 221,
1862
1863 /** \brief Objective-C's collection statement.
1864 */
1865 CXCursor_ObjCForCollectionStmt = 222,
1866
1867 /** \brief C++'s catch statement.
1868 */
1869 CXCursor_CXXCatchStmt = 223,
1870
1871 /** \brief C++'s try statement.
1872 */
1873 CXCursor_CXXTryStmt = 224,
1874
1875 /** \brief C++'s for (* : *) statement.
1876 */
1877 CXCursor_CXXForRangeStmt = 225,
1878
1879 /** \brief Windows Structured Exception Handling's try statement.
1880 */
1881 CXCursor_SEHTryStmt = 226,
1882
1883 /** \brief Windows Structured Exception Handling's except statement.
1884 */
1885 CXCursor_SEHExceptStmt = 227,
1886
1887 /** \brief Windows Structured Exception Handling's finally statement.
1888 */
1889 CXCursor_SEHFinallyStmt = 228,
1890
1891 /** \brief The null satement ";": C99 6.8.3p3.
1892 *
1893 * This cursor kind is used to describe the null statement.
1894 */
1895 CXCursor_NullStmt = 230,
1896
1897 /** \brief Adaptor class for mixing declarations with statements and
1898 * expressions.
1899 */
1900 CXCursor_DeclStmt = 231,
1901
1902 CXCursor_LastStmt = CXCursor_DeclStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001903
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001904 /**
1905 * \brief Cursor that represents the translation unit itself.
1906 *
1907 * The translation unit cursor exists primarily to act as the root
1908 * cursor for traversing the contents of a translation unit.
1909 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001910 CXCursor_TranslationUnit = 300,
1911
1912 /* Attributes */
1913 CXCursor_FirstAttr = 400,
1914 /**
1915 * \brief An attribute whose specific kind is not exposed via this
1916 * interface.
1917 */
1918 CXCursor_UnexposedAttr = 400,
1919
1920 CXCursor_IBActionAttr = 401,
1921 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001922 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00001923 CXCursor_CXXFinalAttr = 404,
1924 CXCursor_CXXOverrideAttr = 405,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00001925 CXCursor_AnnotateAttr = 406,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00001926 CXCursor_AsmLabelAttr = 407,
1927 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001928
1929 /* Preprocessing */
1930 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001931 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00001932 CXCursor_MacroExpansion = 502,
1933 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001934 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001935 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001936 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001937};
1938
1939/**
1940 * \brief A cursor representing some element in the abstract syntax tree for
1941 * a translation unit.
1942 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001943 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001944 * program--declaration, statements, expressions, references to declarations,
1945 * etc.--under a single "cursor" abstraction with a common set of operations.
1946 * Common operation for a cursor include: getting the physical location in
1947 * a source file where the cursor points, getting the name associated with a
1948 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1949 *
1950 * Cursors can be produced in two specific ways.
1951 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1952 * from which one can use clang_visitChildren() to explore the rest of the
1953 * translation unit. clang_getCursor() maps from a physical source location
1954 * to the entity that resides at that location, allowing one to map from the
1955 * source code into the AST.
1956 */
1957typedef struct {
1958 enum CXCursorKind kind;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00001959 int xdata;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001960 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001961} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001962
1963/**
1964 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1965 *
1966 * @{
1967 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001968
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001969/**
1970 * \brief Retrieve the NULL cursor, which represents no entity.
1971 */
1972CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001973
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001974/**
1975 * \brief Retrieve the cursor that represents the given translation unit.
1976 *
1977 * The translation unit cursor can be used to start traversing the
1978 * various declarations within the given translation unit.
1979 */
1980CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1981
1982/**
1983 * \brief Determine whether two cursors are equivalent.
1984 */
1985CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001986
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001987/**
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001988 * \brief Returns non-zero if \arg cursor is null.
1989 */
Benjamin Kramer5b419362012-02-01 20:37:28 +00001990CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001991
1992/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001993 * \brief Compute a hash value for the given cursor.
1994 */
1995CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1996
1997/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001998 * \brief Retrieve the kind of the given cursor.
1999 */
2000CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2001
2002/**
2003 * \brief Determine whether the given cursor kind represents a declaration.
2004 */
2005CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2006
2007/**
2008 * \brief Determine whether the given cursor kind represents a simple
2009 * reference.
2010 *
2011 * Note that other kinds of cursors (such as expressions) can also refer to
2012 * other cursors. Use clang_getCursorReferenced() to determine whether a
2013 * particular cursor refers to another entity.
2014 */
2015CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2016
2017/**
2018 * \brief Determine whether the given cursor kind represents an expression.
2019 */
2020CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2021
2022/**
2023 * \brief Determine whether the given cursor kind represents a statement.
2024 */
2025CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2026
2027/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00002028 * \brief Determine whether the given cursor kind represents an attribute.
2029 */
2030CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2031
2032/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002033 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002034 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002035 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002036CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2037
2038/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002039 * \brief Determine whether the given cursor kind represents a translation
2040 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002041 */
2042CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002043
Ted Kremenekad6eff62010-03-08 21:17:29 +00002044/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00002045 * \brief Determine whether the given cursor represents a preprocessing
2046 * element, such as a preprocessor directive or macro instantiation.
2047 */
2048CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2049
2050/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00002051 * \brief Determine whether the given cursor represents a currently
2052 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2053 */
2054CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2055
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002056/**
Ted Kremenek16b42592010-03-03 06:36:57 +00002057 * \brief Describe the linkage of the entity referred to by a cursor.
2058 */
2059enum CXLinkageKind {
2060 /** \brief This value indicates that no linkage information is available
2061 * for a provided CXCursor. */
2062 CXLinkage_Invalid,
2063 /**
2064 * \brief This is the linkage for variables, parameters, and so on that
2065 * have automatic storage. This covers normal (non-extern) local variables.
2066 */
2067 CXLinkage_NoLinkage,
2068 /** \brief This is the linkage for static variables and static functions. */
2069 CXLinkage_Internal,
2070 /** \brief This is the linkage for entities with external linkage that live
2071 * in C++ anonymous namespaces.*/
2072 CXLinkage_UniqueExternal,
2073 /** \brief This is the linkage for entities with true, external linkage. */
2074 CXLinkage_External
2075};
2076
2077/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002078 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00002079 */
2080CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2081
2082/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002083 * \brief Determine the availability of the entity that this cursor refers to.
2084 *
2085 * \param cursor The cursor to query.
2086 *
2087 * \returns The availability of the cursor.
2088 */
2089CINDEX_LINKAGE enum CXAvailabilityKind
2090clang_getCursorAvailability(CXCursor cursor);
2091
2092/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002093 * \brief Describe the "language" of the entity referred to by a cursor.
2094 */
2095CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002096 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002097 CXLanguage_C,
2098 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00002099 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002100};
2101
2102/**
2103 * \brief Determine the "language" of the entity referred to by a given cursor.
2104 */
2105CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2106
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00002107/**
2108 * \brief Returns the translation unit that a cursor originated from.
2109 */
2110CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2111
Ted Kremenekeca099b2010-12-08 23:43:14 +00002112
2113/**
2114 * \brief A fast container representing a set of CXCursors.
2115 */
2116typedef struct CXCursorSetImpl *CXCursorSet;
2117
2118/**
2119 * \brief Creates an empty CXCursorSet.
2120 */
2121CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2122
2123/**
2124 * \brief Disposes a CXCursorSet and releases its associated memory.
2125 */
2126CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2127
2128/**
2129 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2130 *
2131 * \returns non-zero if the set contains the specified cursor.
2132*/
2133CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2134 CXCursor cursor);
2135
2136/**
2137 * \brief Inserts a CXCursor into a CXCursorSet.
2138 *
2139 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2140*/
2141CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2142 CXCursor cursor);
2143
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002144/**
2145 * \brief Determine the semantic parent of the given cursor.
2146 *
2147 * The semantic parent of a cursor is the cursor that semantically contains
2148 * the given \p cursor. For many declarations, the lexical and semantic parents
2149 * are equivalent (the lexical parent is returned by
2150 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2151 * definitions are provided out-of-line. For example:
2152 *
2153 * \code
2154 * class C {
2155 * void f();
2156 * };
2157 *
2158 * void C::f() { }
2159 * \endcode
2160 *
2161 * In the out-of-line definition of \c C::f, the semantic parent is the
2162 * the class \c C, of which this function is a member. The lexical parent is
2163 * the place where the declaration actually occurs in the source code; in this
2164 * case, the definition occurs in the translation unit. In general, the
2165 * lexical parent for a given entity can change without affecting the semantics
2166 * of the program, and the lexical parent of different declarations of the
2167 * same entity may be different. Changing the semantic parent of a declaration,
2168 * on the other hand, can have a major impact on semantics, and redeclarations
2169 * of a particular entity should all have the same semantic context.
2170 *
2171 * In the example above, both declarations of \c C::f have \c C as their
2172 * semantic context, while the lexical context of the first \c C::f is \c C
2173 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002174 *
2175 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002176 */
2177CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2178
2179/**
2180 * \brief Determine the lexical parent of the given cursor.
2181 *
2182 * The lexical parent of a cursor is the cursor in which the given \p cursor
2183 * was actually written. For many declarations, the lexical and semantic parents
2184 * are equivalent (the semantic parent is returned by
2185 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2186 * definitions are provided out-of-line. For example:
2187 *
2188 * \code
2189 * class C {
2190 * void f();
2191 * };
2192 *
2193 * void C::f() { }
2194 * \endcode
2195 *
2196 * In the out-of-line definition of \c C::f, the semantic parent is the
2197 * the class \c C, of which this function is a member. The lexical parent is
2198 * the place where the declaration actually occurs in the source code; in this
2199 * case, the definition occurs in the translation unit. In general, the
2200 * lexical parent for a given entity can change without affecting the semantics
2201 * of the program, and the lexical parent of different declarations of the
2202 * same entity may be different. Changing the semantic parent of a declaration,
2203 * on the other hand, can have a major impact on semantics, and redeclarations
2204 * of a particular entity should all have the same semantic context.
2205 *
2206 * In the example above, both declarations of \c C::f have \c C as their
2207 * semantic context, while the lexical context of the first \c C::f is \c C
2208 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00002209 *
2210 * For declarations written in the global scope, the lexical parent is
2211 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00002212 */
2213CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00002214
2215/**
2216 * \brief Determine the set of methods that are overridden by the given
2217 * method.
2218 *
2219 * In both Objective-C and C++, a method (aka virtual member function,
2220 * in C++) can override a virtual method in a base class. For
2221 * Objective-C, a method is said to override any method in the class's
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +00002222 * base class, its protocols, or its categories' protocols, that has the same
2223 * selector and is of the same kind (class or instance).
2224 * If no such method exists, the search continues to the class's superclass,
2225 * its protocols, and its categories, and so on. A method from an Objective-C
2226 * implementation is considered to override the same methods as its
2227 * corresponding method in the interface.
Douglas Gregor9f592342010-10-01 20:25:15 +00002228 *
2229 * For C++, a virtual member function overrides any virtual member
2230 * function with the same signature that occurs in its base
2231 * classes. With multiple inheritance, a virtual member function can
2232 * override several virtual member functions coming from different
2233 * base classes.
2234 *
2235 * In all cases, this function determines the immediate overridden
2236 * method, rather than all of the overridden methods. For example, if
2237 * a method is originally declared in a class A, then overridden in B
2238 * (which in inherits from A) and also in C (which inherited from B),
2239 * then the only overridden method returned from this function when
2240 * invoked on C's method will be B's method. The client may then
2241 * invoke this function again, given the previously-found overridden
2242 * methods, to map out the complete method-override set.
2243 *
2244 * \param cursor A cursor representing an Objective-C or C++
2245 * method. This routine will compute the set of methods that this
2246 * method overrides.
2247 *
2248 * \param overridden A pointer whose pointee will be replaced with a
2249 * pointer to an array of cursors, representing the set of overridden
2250 * methods. If there are no overridden methods, the pointee will be
2251 * set to NULL. The pointee must be freed via a call to
2252 * \c clang_disposeOverriddenCursors().
2253 *
2254 * \param num_overridden A pointer to the number of overridden
2255 * functions, will be set to the number of overridden functions in the
2256 * array pointed to by \p overridden.
2257 */
2258CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2259 CXCursor **overridden,
2260 unsigned *num_overridden);
2261
2262/**
2263 * \brief Free the set of overridden cursors returned by \c
2264 * clang_getOverriddenCursors().
2265 */
2266CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2267
Ted Kremenek45e1dae2010-04-12 21:22:16 +00002268/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00002269 * \brief Retrieve the file that is included by the given inclusion directive
2270 * cursor.
2271 */
2272CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2273
2274/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002275 * @}
2276 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002277
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002278/**
2279 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2280 *
2281 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2282 * routines help map between cursors and the physical locations where the
2283 * described entities occur in the source code. The mapping is provided in
2284 * both directions, so one can map from source code to the AST and back.
2285 *
2286 * @{
Steve Naroff50398192009-08-28 15:28:48 +00002287 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002288
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002289/**
Douglas Gregorb9790342010-01-22 21:44:22 +00002290 * \brief Map a source location to the cursor that describes the entity at that
2291 * location in the source code.
2292 *
2293 * clang_getCursor() maps an arbitrary source location within a translation
2294 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002295 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00002296 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002297 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00002298 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2299 * will return a cursor referring to the "+" expression.
2300 *
2301 * \returns a cursor representing the entity at the given source location, or
2302 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00002303 */
Douglas Gregorb9790342010-01-22 21:44:22 +00002304CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002305
Douglas Gregor98258af2010-01-18 22:46:11 +00002306/**
2307 * \brief Retrieve the physical location of the source constructor referenced
2308 * by the given cursor.
2309 *
2310 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002311 * declaration, where the name of that declaration would occur if it is
2312 * unnamed, or some keyword that introduces that particular declaration.
2313 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00002314 * source code.
2315 */
2316CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002317
Douglas Gregorb6998662010-01-19 19:34:47 +00002318/**
2319 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00002320 * the given cursor.
2321 *
2322 * The extent of a cursor starts with the file/line/column pointing at the
2323 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002324 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00002325 * declaration, the extent covers the declaration itself. For a reference,
2326 * the extent covers the location of the reference (e.g., where the referenced
2327 * entity was actually used).
2328 */
2329CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002330
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002331/**
2332 * @}
2333 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002334
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002335/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002336 * \defgroup CINDEX_TYPES Type information for CXCursors
2337 *
2338 * @{
2339 */
2340
2341/**
2342 * \brief Describes the kind of type
2343 */
2344enum CXTypeKind {
2345 /**
2346 * \brief Reprents an invalid type (e.g., where no type is available).
2347 */
2348 CXType_Invalid = 0,
2349
2350 /**
2351 * \brief A type whose specific kind is not exposed via this
2352 * interface.
2353 */
2354 CXType_Unexposed = 1,
2355
2356 /* Builtin types */
2357 CXType_Void = 2,
2358 CXType_Bool = 3,
2359 CXType_Char_U = 4,
2360 CXType_UChar = 5,
2361 CXType_Char16 = 6,
2362 CXType_Char32 = 7,
2363 CXType_UShort = 8,
2364 CXType_UInt = 9,
2365 CXType_ULong = 10,
2366 CXType_ULongLong = 11,
2367 CXType_UInt128 = 12,
2368 CXType_Char_S = 13,
2369 CXType_SChar = 14,
2370 CXType_WChar = 15,
2371 CXType_Short = 16,
2372 CXType_Int = 17,
2373 CXType_Long = 18,
2374 CXType_LongLong = 19,
2375 CXType_Int128 = 20,
2376 CXType_Float = 21,
2377 CXType_Double = 22,
2378 CXType_LongDouble = 23,
2379 CXType_NullPtr = 24,
2380 CXType_Overload = 25,
2381 CXType_Dependent = 26,
2382 CXType_ObjCId = 27,
2383 CXType_ObjCClass = 28,
2384 CXType_ObjCSel = 29,
2385 CXType_FirstBuiltin = CXType_Void,
2386 CXType_LastBuiltin = CXType_ObjCSel,
2387
2388 CXType_Complex = 100,
2389 CXType_Pointer = 101,
2390 CXType_BlockPointer = 102,
2391 CXType_LValueReference = 103,
2392 CXType_RValueReference = 104,
2393 CXType_Record = 105,
2394 CXType_Enum = 106,
2395 CXType_Typedef = 107,
2396 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002397 CXType_ObjCObjectPointer = 109,
2398 CXType_FunctionNoProto = 110,
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002399 CXType_FunctionProto = 111,
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002400 CXType_ConstantArray = 112,
2401 CXType_Vector = 113
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002402};
2403
2404/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002405 * \brief Describes the calling convention of a function type
2406 */
2407enum CXCallingConv {
2408 CXCallingConv_Default = 0,
2409 CXCallingConv_C = 1,
2410 CXCallingConv_X86StdCall = 2,
2411 CXCallingConv_X86FastCall = 3,
2412 CXCallingConv_X86ThisCall = 4,
2413 CXCallingConv_X86Pascal = 5,
2414 CXCallingConv_AAPCS = 6,
2415 CXCallingConv_AAPCS_VFP = 7,
2416
2417 CXCallingConv_Invalid = 100,
2418 CXCallingConv_Unexposed = 200
2419};
2420
2421
2422/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002423 * \brief The type of an element in the abstract syntax tree.
2424 *
2425 */
2426typedef struct {
2427 enum CXTypeKind kind;
2428 void *data[2];
2429} CXType;
2430
2431/**
2432 * \brief Retrieve the type of a CXCursor (if any).
2433 */
2434CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2435
2436/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002437 * \brief Retrieve the underlying type of a typedef declaration.
2438 *
2439 * If the cursor does not reference a typedef declaration, an invalid type is
2440 * returned.
2441 */
2442CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2443
2444/**
2445 * \brief Retrieve the integer type of an enum declaration.
2446 *
2447 * If the cursor does not reference an enum declaration, an invalid type is
2448 * returned.
2449 */
2450CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2451
2452/**
2453 * \brief Retrieve the integer value of an enum constant declaration as a signed
2454 * long long.
2455 *
2456 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2457 * Since this is also potentially a valid constant value, the kind of the cursor
2458 * must be verified before calling this function.
2459 */
2460CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2461
2462/**
2463 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2464 * long long.
2465 *
2466 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2467 * Since this is also potentially a valid constant value, the kind of the cursor
2468 * must be verified before calling this function.
2469 */
2470CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2471
2472/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002473 * \determine Determine whether two CXTypes represent the same type.
2474 *
2475 * \returns non-zero if the CXTypes represent the same type and
2476 zero otherwise.
2477 */
2478CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2479
2480/**
2481 * \brief Return the canonical type for a CXType.
2482 *
2483 * Clang's type system explicitly models typedefs and all the ways
2484 * a specific type can be represented. The canonical type is the underlying
2485 * type with all the "sugar" removed. For example, if 'T' is a typedef
2486 * for 'int', the canonical type for 'T' would be 'int'.
2487 */
2488CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2489
2490/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002491 * \determine Determine whether a CXType has the "const" qualifier set,
2492 * without looking through typedefs that may have added "const" at a different level.
2493 */
2494CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2495
2496/**
2497 * \determine Determine whether a CXType has the "volatile" qualifier set,
2498 * without looking through typedefs that may have added "volatile" at a different level.
2499 */
2500CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2501
2502/**
2503 * \determine Determine whether a CXType has the "restrict" qualifier set,
2504 * without looking through typedefs that may have added "restrict" at a different level.
2505 */
2506CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2507
2508/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002509 * \brief For pointer types, returns the type of the pointee.
2510 *
2511 */
2512CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2513
2514/**
2515 * \brief Return the cursor for the declaration of the given type.
2516 */
2517CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2518
David Chisnall5389f482010-12-30 14:05:53 +00002519/**
2520 * Returns the Objective-C type encoding for the specified declaration.
2521 */
2522CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002523
2524/**
2525 * \brief Retrieve the spelling of a given CXTypeKind.
2526 */
2527CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2528
2529/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002530 * \brief Retrieve the calling convention associated with a function type.
2531 *
2532 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2533 */
2534CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2535
2536/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002537 * \brief Retrieve the result type associated with a function type.
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002538 *
2539 * If a non-function type is passed in, an invalid type is returned.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002540 */
2541CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2542
2543/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002544 * \brief Retrieve the number of non-variadic arguments associated with a function type.
2545 *
2546 * If a non-function type is passed in, UINT_MAX is returned.
2547 */
2548CINDEX_LINKAGE unsigned clang_getNumArgTypes(CXType T);
2549
2550/**
2551 * \brief Retrieve the type of an argument of a function type.
2552 *
2553 * If a non-function type is passed in or the function does not have enough parameters,
2554 * an invalid type is returned.
2555 */
2556CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2557
2558/**
2559 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2560 *
2561 */
2562CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2563
2564/**
2565 * \brief Retrieve the result type associated with a given cursor.
2566 *
2567 * This only returns a valid type if the cursor refers to a function or method.
Ted Kremenek9a140842010-06-21 20:48:56 +00002568 */
2569CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2570
2571/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002572 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2573 * otherwise.
2574 */
2575CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2576
2577/**
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +00002578 * \brief Return the element type of an array, complex, or vector type.
2579 *
2580 * If a type is passed in that is not an array, complex, or vector type,
2581 * an invalid type is returned.
2582 */
2583CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2584
2585/**
2586 * \brief Return the number of elements of an array or vector type.
2587 *
2588 * If a type is passed in that is not an array or vector type,
2589 * -1 is returned.
2590 */
2591CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2592
2593/**
Argyrios Kyrtzidis5f0bfc52011-09-27 17:44:34 +00002594 * \brief Return the element type of an array type.
2595 *
2596 * If a non-array type is passed in, an invalid type is returned.
2597 */
2598CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2599
2600/**
2601 * \brief Return the the array size of a constant array.
2602 *
2603 * If a non-array type is passed in, -1 is returned.
2604 */
2605CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2606
2607/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002608 * \brief Returns 1 if the base class specified by the cursor with kind
2609 * CX_CXXBaseSpecifier is virtual.
2610 */
2611CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2612
2613/**
2614 * \brief Represents the C++ access control level to a base class for a
2615 * cursor with kind CX_CXXBaseSpecifier.
2616 */
2617enum CX_CXXAccessSpecifier {
2618 CX_CXXInvalidAccessSpecifier,
2619 CX_CXXPublic,
2620 CX_CXXProtected,
2621 CX_CXXPrivate
2622};
2623
2624/**
2625 * \brief Returns the access control level for the C++ base specifier
Argyrios Kyrtzidis2dfdb942011-09-30 17:58:23 +00002626 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2627 * CXCursor_AccessSpecifier.
Ted Kremenek3064ef92010-08-27 21:34:58 +00002628 */
2629CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2630
2631/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002632 * \brief Determine the number of overloaded declarations referenced by a
2633 * \c CXCursor_OverloadedDeclRef cursor.
2634 *
2635 * \param cursor The cursor whose overloaded declarations are being queried.
2636 *
2637 * \returns The number of overloaded declarations referenced by \c cursor. If it
2638 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2639 */
2640CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2641
2642/**
2643 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2644 * by a \c CXCursor_OverloadedDeclRef cursor.
2645 *
2646 * \param cursor The cursor whose overloaded declarations are being queried.
2647 *
2648 * \param index The zero-based index into the set of overloaded declarations in
2649 * the cursor.
2650 *
2651 * \returns A cursor representing the declaration referenced by the given
2652 * \c cursor at the specified \c index. If the cursor does not have an
2653 * associated set of overloaded declarations, or if the index is out of bounds,
2654 * returns \c clang_getNullCursor();
2655 */
2656CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2657 unsigned index);
2658
2659/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002660 * @}
2661 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002662
2663/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002664 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002665 *
2666 * @{
2667 */
2668
2669
2670/**
2671 * \brief For cursors representing an iboutletcollection attribute,
2672 * this function returns the collection element type.
2673 *
2674 */
2675CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2676
2677/**
2678 * @}
2679 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002680
2681/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002682 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2683 *
2684 * These routines provide the ability to traverse the abstract syntax tree
2685 * using cursors.
2686 *
2687 * @{
2688 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002689
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002690/**
2691 * \brief Describes how the traversal of the children of a particular
2692 * cursor should proceed after visiting a particular child cursor.
2693 *
2694 * A value of this enumeration type should be returned by each
2695 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2696 */
2697enum CXChildVisitResult {
2698 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002699 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002700 */
2701 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002702 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002703 * \brief Continues the cursor traversal with the next sibling of
2704 * the cursor just visited, without visiting its children.
2705 */
2706 CXChildVisit_Continue,
2707 /**
2708 * \brief Recursively traverse the children of this cursor, using
2709 * the same visitor and client data.
2710 */
2711 CXChildVisit_Recurse
2712};
2713
2714/**
2715 * \brief Visitor invoked for each cursor found by a traversal.
2716 *
2717 * This visitor function will be invoked for each cursor found by
2718 * clang_visitCursorChildren(). Its first argument is the cursor being
2719 * visited, its second argument is the parent visitor for that cursor,
2720 * and its third argument is the client data provided to
2721 * clang_visitCursorChildren().
2722 *
2723 * The visitor should return one of the \c CXChildVisitResult values
2724 * to direct clang_visitCursorChildren().
2725 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002726typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2727 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002728 CXClientData client_data);
2729
2730/**
2731 * \brief Visit the children of a particular cursor.
2732 *
2733 * This function visits all the direct children of the given cursor,
2734 * invoking the given \p visitor function with the cursors of each
2735 * visited child. The traversal may be recursive, if the visitor returns
2736 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2737 * the visitor returns \c CXChildVisit_Break.
2738 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002739 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002740 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002741 * definition, have no children).
2742 *
2743 * \param visitor the visitor function that will be invoked for each
2744 * child of \p parent.
2745 *
2746 * \param client_data pointer data supplied by the client, which will
2747 * be passed to the visitor each time it is invoked.
2748 *
2749 * \returns a non-zero value if the traversal was terminated
2750 * prematurely by the visitor returning \c CXChildVisit_Break.
2751 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002752CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002753 CXCursorVisitor visitor,
2754 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002755#ifdef __has_feature
2756# if __has_feature(blocks)
2757/**
2758 * \brief Visitor invoked for each cursor found by a traversal.
2759 *
2760 * This visitor block will be invoked for each cursor found by
2761 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2762 * visited, its second argument is the parent visitor for that cursor.
2763 *
2764 * The visitor should return one of the \c CXChildVisitResult values
2765 * to direct clang_visitChildrenWithBlock().
2766 */
2767typedef enum CXChildVisitResult
2768 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2769
2770/**
2771 * Visits the children of a cursor using the specified block. Behaves
2772 * identically to clang_visitChildren() in all other respects.
2773 */
2774unsigned clang_visitChildrenWithBlock(CXCursor parent,
2775 CXCursorVisitorBlock block);
2776# endif
2777#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002778
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002779/**
2780 * @}
2781 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002782
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002783/**
2784 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2785 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002786 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002787 * across translation units, by providing the names of the entities referenced
2788 * by cursors, follow reference cursors to the declarations they reference,
2789 * and associate declarations with their definitions.
2790 *
2791 * @{
2792 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002793
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002794/**
2795 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2796 * by the given cursor.
2797 *
2798 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2799 * entity (function, class, variable, etc.) within a program. USRs can be
2800 * compared across translation units to determine, e.g., when references in
2801 * one translation refer to an entity defined in another translation unit.
2802 */
2803CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2804
2805/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002806 * \brief Construct a USR for a specified Objective-C class.
2807 */
2808CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2809
2810/**
2811 * \brief Construct a USR for a specified Objective-C category.
2812 */
2813CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002814 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002815 const char *category_name);
2816
2817/**
2818 * \brief Construct a USR for a specified Objective-C protocol.
2819 */
2820CINDEX_LINKAGE CXString
2821 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2822
2823
2824/**
2825 * \brief Construct a USR for a specified Objective-C instance variable and
2826 * the USR for its containing class.
2827 */
2828CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2829 CXString classUSR);
2830
2831/**
2832 * \brief Construct a USR for a specified Objective-C method and
2833 * the USR for its containing class.
2834 */
2835CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2836 unsigned isInstanceMethod,
2837 CXString classUSR);
2838
2839/**
2840 * \brief Construct a USR for a specified Objective-C property and the USR
2841 * for its containing class.
2842 */
2843CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2844 CXString classUSR);
2845
2846/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002847 * \brief Retrieve a name for the entity referenced by this cursor.
2848 */
2849CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2850
Douglas Gregor358559d2010-10-02 22:49:11 +00002851/**
2852 * \brief Retrieve the display name for the entity referenced by this cursor.
2853 *
2854 * The display name contains extra information that helps identify the cursor,
2855 * such as the parameters of a function or template or the arguments of a
2856 * class template specialization.
2857 */
2858CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2859
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002860/** \brief For a cursor that is a reference, retrieve a cursor representing the
2861 * entity that it references.
2862 *
2863 * Reference cursors refer to other entities in the AST. For example, an
2864 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002865 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002866 * cursor for the superclass reference. If the input cursor is a declaration or
2867 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002868 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002869 */
2870CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002871
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002872/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002873 * \brief For a cursor that is either a reference to or a declaration
2874 * of some entity, retrieve a cursor that describes the definition of
2875 * that entity.
2876 *
2877 * Some entities can be declared multiple times within a translation
2878 * unit, but only one of those declarations can also be a
2879 * definition. For example, given:
2880 *
2881 * \code
2882 * int f(int, int);
2883 * int g(int x, int y) { return f(x, y); }
2884 * int f(int a, int b) { return a + b; }
2885 * int f(int, int);
2886 * \endcode
2887 *
2888 * there are three declarations of the function "f", but only the
2889 * second one is a definition. The clang_getCursorDefinition()
2890 * function will take any cursor pointing to a declaration of "f"
2891 * (the first or fourth lines of the example) or a cursor referenced
2892 * that uses "f" (the call to "f' inside "g") and will return a
2893 * declaration cursor pointing to the definition (the second "f"
2894 * declaration).
2895 *
2896 * If given a cursor for which there is no corresponding definition,
2897 * e.g., because there is no definition of that entity within this
2898 * translation unit, returns a NULL cursor.
2899 */
2900CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2901
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002902/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002903 * \brief Determine whether the declaration pointed to by this cursor
2904 * is also a definition of that entity.
2905 */
2906CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2907
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002908/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002909 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2910 *
2911 * In the C family of languages, many kinds of entities can be declared several
2912 * times within a single translation unit. For example, a structure type can
2913 * be forward-declared (possibly multiple times) and later defined:
2914 *
2915 * \code
2916 * struct X;
2917 * struct X;
2918 * struct X {
2919 * int member;
2920 * };
2921 * \endcode
2922 *
2923 * The declarations and the definition of \c X are represented by three
2924 * different cursors, all of which are declarations of the same underlying
2925 * entity. One of these cursor is considered the "canonical" cursor, which
2926 * is effectively the representative for the underlying entity. One can
2927 * determine if two cursors are declarations of the same underlying entity by
2928 * comparing their canonical cursors.
2929 *
2930 * \returns The canonical cursor for the entity referred to by the given cursor.
2931 */
2932CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2933
2934/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002935 * @}
2936 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002937
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002938/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002939 * \defgroup CINDEX_CPP C++ AST introspection
2940 *
2941 * The routines in this group provide access information in the ASTs specific
2942 * to C++ language features.
2943 *
2944 * @{
2945 */
2946
2947/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002948 * \brief Determine if a C++ member function or member function template is
2949 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002950 */
2951CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2952
2953/**
Douglas Gregor211924b2011-05-12 15:17:24 +00002954 * \brief Determine if a C++ member function or member function template is
2955 * explicitly declared 'virtual' or if it overrides a virtual method from
2956 * one of the base classes.
2957 */
2958CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2959
2960/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002961 * \brief Given a cursor that represents a template, determine
2962 * the cursor kind of the specializations would be generated by instantiating
2963 * the template.
2964 *
2965 * This routine can be used to determine what flavor of function template,
2966 * class template, or class template partial specialization is stored in the
2967 * cursor. For example, it can describe whether a class template cursor is
2968 * declared with "struct", "class" or "union".
2969 *
2970 * \param C The cursor to query. This cursor should represent a template
2971 * declaration.
2972 *
2973 * \returns The cursor kind of the specializations that would be generated
2974 * by instantiating the template \p C. If \p C is not a template, returns
2975 * \c CXCursor_NoDeclFound.
2976 */
2977CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2978
2979/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002980 * \brief Given a cursor that may represent a specialization or instantiation
2981 * of a template, retrieve the cursor that represents the template that it
2982 * specializes or from which it was instantiated.
2983 *
2984 * This routine determines the template involved both for explicit
2985 * specializations of templates and for implicit instantiations of the template,
2986 * both of which are referred to as "specializations". For a class template
2987 * specialization (e.g., \c std::vector<bool>), this routine will return
2988 * either the primary template (\c std::vector) or, if the specialization was
2989 * instantiated from a class template partial specialization, the class template
2990 * partial specialization. For a class template partial specialization and a
2991 * function template specialization (including instantiations), this
2992 * this routine will return the specialized template.
2993 *
2994 * For members of a class template (e.g., member functions, member classes, or
2995 * static data members), returns the specialized or instantiated member.
2996 * Although not strictly "templates" in the C++ language, members of class
2997 * templates have the same notions of specializations and instantiations that
2998 * templates do, so this routine treats them similarly.
2999 *
3000 * \param C A cursor that may be a specialization of a template or a member
3001 * of a template.
3002 *
3003 * \returns If the given cursor is a specialization or instantiation of a
3004 * template or a member thereof, the template or member that it specializes or
3005 * from which it was instantiated. Otherwise, returns a NULL cursor.
3006 */
3007CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00003008
3009/**
3010 * \brief Given a cursor that references something else, return the source range
3011 * covering that reference.
3012 *
3013 * \param C A cursor pointing to a member reference, a declaration reference, or
3014 * an operator call.
3015 * \param NameFlags A bitset with three independent flags:
3016 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3017 * CXNameRange_WantSinglePiece.
3018 * \param PieceIndex For contiguous names or when passing the flag
3019 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3020 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
3021 * non-contiguous names, this index can be used to retreive the individual
3022 * pieces of the name. See also CXNameRange_WantSinglePiece.
3023 *
3024 * \returns The piece of the name pointed to by the given cursor. If there is no
3025 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3026 */
Francois Pichet48a8d142011-07-25 22:00:44 +00003027CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3028 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00003029 unsigned PieceIndex);
3030
3031enum CXNameRefFlags {
3032 /**
3033 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3034 * range.
3035 */
3036 CXNameRange_WantQualifier = 0x1,
3037
3038 /**
3039 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
3040 * the range.
3041 */
3042 CXNameRange_WantTemplateArgs = 0x2,
3043
3044 /**
3045 * \brief If the name is non-contiguous, return the full spanning range.
3046 *
3047 * Non-contiguous names occur in Objective-C when a selector with two or more
3048 * parameters is used, or in C++ when using an operator:
3049 * \code
3050 * [object doSomething:here withValue:there]; // ObjC
3051 * return some_vector[1]; // C++
3052 * \endcode
3053 */
3054 CXNameRange_WantSinglePiece = 0x4
3055};
Douglas Gregore0329ac2010-09-02 00:07:54 +00003056
3057/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00003058 * @}
3059 */
3060
3061/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003062 * \defgroup CINDEX_LEX Token extraction and manipulation
3063 *
3064 * The routines in this group provide access to the tokens within a
3065 * translation unit, along with a semantic mapping of those tokens to
3066 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003067 *
3068 * @{
3069 */
3070
3071/**
3072 * \brief Describes a kind of token.
3073 */
3074typedef enum CXTokenKind {
3075 /**
3076 * \brief A token that contains some kind of punctuation.
3077 */
3078 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003079
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003080 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003081 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003082 */
3083 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003084
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003085 /**
3086 * \brief An identifier (that is not a keyword).
3087 */
3088 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003089
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003090 /**
3091 * \brief A numeric, string, or character literal.
3092 */
3093 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00003094
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003095 /**
3096 * \brief A comment.
3097 */
3098 CXToken_Comment
3099} CXTokenKind;
3100
3101/**
3102 * \brief Describes a single preprocessing token.
3103 */
3104typedef struct {
3105 unsigned int_data[4];
3106 void *ptr_data;
3107} CXToken;
3108
3109/**
3110 * \brief Determine the kind of the given token.
3111 */
3112CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003113
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003114/**
3115 * \brief Determine the spelling of the given token.
3116 *
3117 * The spelling of a token is the textual representation of that token, e.g.,
3118 * the text of an identifier or keyword.
3119 */
3120CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003121
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003122/**
3123 * \brief Retrieve the source location of the given token.
3124 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003125CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003126 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003127
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003128/**
3129 * \brief Retrieve a source range that covers the given token.
3130 */
3131CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
3132
3133/**
3134 * \brief Tokenize the source code described by the given range into raw
3135 * lexical tokens.
3136 *
3137 * \param TU the translation unit whose text is being tokenized.
3138 *
3139 * \param Range the source range in which text should be tokenized. All of the
3140 * tokens produced by tokenization will fall within this source range,
3141 *
3142 * \param Tokens this pointer will be set to point to the array of tokens
3143 * that occur within the given source range. The returned pointer must be
3144 * freed with clang_disposeTokens() before the translation unit is destroyed.
3145 *
3146 * \param NumTokens will be set to the number of tokens in the \c *Tokens
3147 * array.
3148 *
3149 */
3150CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
3151 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003152
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003153/**
3154 * \brief Annotate the given set of tokens by providing cursors for each token
3155 * that can be mapped to a specific entity within the abstract syntax tree.
3156 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00003157 * This token-annotation routine is equivalent to invoking
3158 * clang_getCursor() for the source locations of each of the
3159 * tokens. The cursors provided are filtered, so that only those
3160 * cursors that have a direct correspondence to the token are
3161 * accepted. For example, given a function call \c f(x),
3162 * clang_getCursor() would provide the following cursors:
3163 *
3164 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
3165 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
3166 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
3167 *
3168 * Only the first and last of these cursors will occur within the
3169 * annotate, since the tokens "f" and "x' directly refer to a function
3170 * and a variable, respectively, but the parentheses are just a small
3171 * part of the full syntax of the function call expression, which is
3172 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003173 *
3174 * \param TU the translation unit that owns the given tokens.
3175 *
3176 * \param Tokens the set of tokens to annotate.
3177 *
3178 * \param NumTokens the number of tokens in \p Tokens.
3179 *
3180 * \param Cursors an array of \p NumTokens cursors, whose contents will be
3181 * replaced with the cursors corresponding to each token.
3182 */
3183CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
3184 CXToken *Tokens, unsigned NumTokens,
3185 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003186
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003187/**
3188 * \brief Free the given set of tokens.
3189 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003190CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003191 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00003192
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003193/**
3194 * @}
3195 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003196
Douglas Gregorfc8ea232010-01-26 17:06:03 +00003197/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003198 * \defgroup CINDEX_DEBUG Debugging facilities
3199 *
3200 * These routines are used for testing and debugging, only, and should not
3201 * be relied upon.
3202 *
3203 * @{
3204 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003205
Steve Naroff4ade6d62009-09-23 17:52:52 +00003206/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00003207CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003208CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3209 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00003210 const char **endBuf,
3211 unsigned *startLine,
3212 unsigned *startColumn,
3213 unsigned *endLine,
3214 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00003215CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00003216CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
3217 unsigned stack_size);
3218
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003219/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003220 * @}
3221 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003222
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003223/**
3224 * \defgroup CINDEX_CODE_COMPLET Code completion
3225 *
3226 * Code completion involves taking an (incomplete) source file, along with
3227 * knowledge of where the user is actively editing that file, and suggesting
3228 * syntactically- and semantically-valid constructs that the user might want to
3229 * use at that particular point in the source code. These data structures and
3230 * routines provide support for code completion.
3231 *
3232 * @{
3233 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003234
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003235/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003236 * \brief A semantic string that describes a code-completion result.
3237 *
3238 * A semantic string that describes the formatting of a code-completion
3239 * result as a single "template" of text that should be inserted into the
3240 * source buffer when a particular code-completion result is selected.
3241 * Each semantic string is made up of some number of "chunks", each of which
3242 * contains some text along with a description of what that text means, e.g.,
3243 * the name of the entity being referenced, whether the text chunk is part of
3244 * the template, or whether it is a "placeholder" that the user should replace
3245 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003246 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003247 */
3248typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003249
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003250/**
3251 * \brief A single result of code completion.
3252 */
3253typedef struct {
3254 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003255 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003256 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003257 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003258 * *Decl cursor kinds), describing the entity that the completion is
3259 * referring to.
3260 *
3261 * \todo In the future, we would like to provide a full cursor, to allow
3262 * the client to extract additional information from declaration.
3263 */
3264 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003265
3266 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003267 * \brief The code-completion string that describes how to insert this
3268 * code-completion result into the editing buffer.
3269 */
3270 CXCompletionString CompletionString;
3271} CXCompletionResult;
3272
3273/**
3274 * \brief Describes a single piece of text within a code-completion string.
3275 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003276 * Each "chunk" within a code-completion string (\c CXCompletionString) is
3277 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003278 * should be interpreted by the client or is another completion string.
3279 */
3280enum CXCompletionChunkKind {
3281 /**
3282 * \brief A code-completion string that describes "optional" text that
3283 * could be a part of the template (but is not required).
3284 *
3285 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003286 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003287 * \c clang_getCompletionChunkCompletionString(). The code-completion string
3288 * describes an additional part of the template that is completely optional.
3289 * For example, optional chunks can be used to describe the placeholders for
3290 * arguments that match up with defaulted function parameters, e.g. given:
3291 *
3292 * \code
3293 * void f(int x, float y = 3.14, double z = 2.71828);
3294 * \endcode
3295 *
3296 * The code-completion string for this function would contain:
3297 * - a TypedText chunk for "f".
3298 * - a LeftParen chunk for "(".
3299 * - a Placeholder chunk for "int x"
3300 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
3301 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00003302 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003303 * - an Optional chunk containing the last defaulted argument:
3304 * - a Comma chunk for ","
3305 * - a Placeholder chunk for "double z"
3306 * - a RightParen chunk for ")"
3307 *
Daniel Dunbar71570182010-02-17 08:07:44 +00003308 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003309 * - Completely ignore optional chunks, in which case the template for the
3310 * function "f" would only include the first parameter ("int x").
3311 * - Fully expand all optional chunks, in which case the template for the
3312 * function "f" would have all of the parameters.
3313 */
3314 CXCompletionChunk_Optional,
3315 /**
3316 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003317 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003318 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003319 * There will be exactly one "typed text" chunk in a semantic string, which
3320 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003321 * declaration that could be used at the current code point. Clients are
3322 * expected to filter the code-completion results based on the text in this
3323 * chunk.
3324 */
3325 CXCompletionChunk_TypedText,
3326 /**
3327 * \brief Text that should be inserted as part of a code-completion result.
3328 *
3329 * A "text" chunk represents text that is part of the template to be
3330 * inserted into user code should this particular code-completion result
3331 * be selected.
3332 */
3333 CXCompletionChunk_Text,
3334 /**
3335 * \brief Placeholder text that should be replaced by the user.
3336 *
3337 * A "placeholder" chunk marks a place where the user should insert text
3338 * into the code-completion template. For example, placeholders might mark
3339 * the function parameters for a function declaration, to indicate that the
3340 * user should provide arguments for each of those parameters. The actual
3341 * text in a placeholder is a suggestion for the text to display before
3342 * the user replaces the placeholder with real code.
3343 */
3344 CXCompletionChunk_Placeholder,
3345 /**
3346 * \brief Informative text that should be displayed but never inserted as
3347 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003348 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003349 * An "informative" chunk contains annotations that can be displayed to
3350 * help the user decide whether a particular code-completion result is the
3351 * right option, but which is not part of the actual template to be inserted
3352 * by code completion.
3353 */
3354 CXCompletionChunk_Informative,
3355 /**
3356 * \brief Text that describes the current parameter when code-completion is
3357 * referring to function call, message send, or template specialization.
3358 *
3359 * A "current parameter" chunk occurs when code-completion is providing
3360 * information about a parameter corresponding to the argument at the
3361 * code-completion point. For example, given a function
3362 *
3363 * \code
3364 * int add(int x, int y);
3365 * \endcode
3366 *
3367 * and the source code \c add(, where the code-completion point is after the
3368 * "(", the code-completion string will contain a "current parameter" chunk
3369 * for "int x", indicating that the current argument will initialize that
3370 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003371 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003372 * "current paremeter" chunk to "int y".
3373 */
3374 CXCompletionChunk_CurrentParameter,
3375 /**
3376 * \brief A left parenthesis ('('), used to initiate a function call or
3377 * signal the beginning of a function parameter list.
3378 */
3379 CXCompletionChunk_LeftParen,
3380 /**
3381 * \brief A right parenthesis (')'), used to finish a function call or
3382 * signal the end of a function parameter list.
3383 */
3384 CXCompletionChunk_RightParen,
3385 /**
3386 * \brief A left bracket ('[').
3387 */
3388 CXCompletionChunk_LeftBracket,
3389 /**
3390 * \brief A right bracket (']').
3391 */
3392 CXCompletionChunk_RightBracket,
3393 /**
3394 * \brief A left brace ('{').
3395 */
3396 CXCompletionChunk_LeftBrace,
3397 /**
3398 * \brief A right brace ('}').
3399 */
3400 CXCompletionChunk_RightBrace,
3401 /**
3402 * \brief A left angle bracket ('<').
3403 */
3404 CXCompletionChunk_LeftAngle,
3405 /**
3406 * \brief A right angle bracket ('>').
3407 */
3408 CXCompletionChunk_RightAngle,
3409 /**
3410 * \brief A comma separator (',').
3411 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003412 CXCompletionChunk_Comma,
3413 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003414 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003415 *
3416 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003417 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00003418 * expression using the given completion string would have.
3419 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00003420 CXCompletionChunk_ResultType,
3421 /**
3422 * \brief A colon (':').
3423 */
3424 CXCompletionChunk_Colon,
3425 /**
3426 * \brief A semicolon (';').
3427 */
3428 CXCompletionChunk_SemiColon,
3429 /**
3430 * \brief An '=' sign.
3431 */
3432 CXCompletionChunk_Equal,
3433 /**
3434 * Horizontal space (' ').
3435 */
3436 CXCompletionChunk_HorizontalSpace,
3437 /**
3438 * Vertical space ('\n'), after which it is generally a good idea to
3439 * perform indentation.
3440 */
3441 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003442};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003443
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003444/**
3445 * \brief Determine the kind of a particular chunk within a completion string.
3446 *
3447 * \param completion_string the completion string to query.
3448 *
3449 * \param chunk_number the 0-based index of the chunk in the completion string.
3450 *
3451 * \returns the kind of the chunk at the index \c chunk_number.
3452 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003453CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003454clang_getCompletionChunkKind(CXCompletionString completion_string,
3455 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003456
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003457/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003458 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003459 * completion string.
3460 *
3461 * \param completion_string the completion string to query.
3462 *
3463 * \param chunk_number the 0-based index of the chunk in the completion string.
3464 *
3465 * \returns the text associated with the chunk at index \c chunk_number.
3466 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00003467CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003468clang_getCompletionChunkText(CXCompletionString completion_string,
3469 unsigned chunk_number);
3470
3471/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003472 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003473 * within a completion string.
3474 *
3475 * \param completion_string the completion string to query.
3476 *
3477 * \param chunk_number the 0-based index of the chunk in the completion string.
3478 *
3479 * \returns the completion string associated with the chunk at index
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003480 * \c chunk_number.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003481 */
3482CINDEX_LINKAGE CXCompletionString
3483clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
3484 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003485
Douglas Gregor0c8296d2009-11-07 00:00:49 +00003486/**
3487 * \brief Retrieve the number of chunks in the given code-completion string.
3488 */
3489CINDEX_LINKAGE unsigned
3490clang_getNumCompletionChunks(CXCompletionString completion_string);
3491
3492/**
Douglas Gregor12e13132010-05-26 22:00:08 +00003493 * \brief Determine the priority of this code completion.
3494 *
3495 * The priority of a code completion indicates how likely it is that this
3496 * particular completion is the completion that the user will select. The
3497 * priority is selected by various internal heuristics.
3498 *
3499 * \param completion_string The completion string to query.
3500 *
3501 * \returns The priority of this completion string. Smaller values indicate
3502 * higher-priority (more likely) completions.
3503 */
3504CINDEX_LINKAGE unsigned
3505clang_getCompletionPriority(CXCompletionString completion_string);
3506
3507/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00003508 * \brief Determine the availability of the entity that this code-completion
3509 * string refers to.
3510 *
3511 * \param completion_string The completion string to query.
3512 *
3513 * \returns The availability of the completion string.
3514 */
3515CINDEX_LINKAGE enum CXAvailabilityKind
3516clang_getCompletionAvailability(CXCompletionString completion_string);
3517
3518/**
Erik Verbruggen6164ea12011-10-14 15:31:08 +00003519 * \brief Retrieve the number of annotations associated with the given
3520 * completion string.
3521 *
3522 * \param completion_string the completion string to query.
3523 *
3524 * \returns the number of annotations associated with the given completion
3525 * string.
3526 */
3527CINDEX_LINKAGE unsigned
3528clang_getCompletionNumAnnotations(CXCompletionString completion_string);
3529
3530/**
3531 * \brief Retrieve the annotation associated with the given completion string.
3532 *
3533 * \param completion_string the completion string to query.
3534 *
3535 * \param annotation_number the 0-based index of the annotation of the
3536 * completion string.
3537 *
3538 * \returns annotation string associated with the completion at index
3539 * \c annotation_number, or a NULL string if that annotation is not available.
3540 */
3541CINDEX_LINKAGE CXString
3542clang_getCompletionAnnotation(CXCompletionString completion_string,
3543 unsigned annotation_number);
3544
3545/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00003546 * \brief Retrieve a completion string for an arbitrary declaration or macro
3547 * definition cursor.
3548 *
3549 * \param cursor The cursor to query.
3550 *
3551 * \returns A non-context-sensitive completion string for declaration and macro
3552 * definition cursors, or NULL for other kinds of cursors.
3553 */
3554CINDEX_LINKAGE CXCompletionString
3555clang_getCursorCompletionString(CXCursor cursor);
3556
3557/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003558 * \brief Contains the results of code-completion.
3559 *
3560 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00003561 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00003562 * \c clang_disposeCodeCompleteResults.
3563 */
3564typedef struct {
3565 /**
3566 * \brief The code-completion results.
3567 */
3568 CXCompletionResult *Results;
3569
3570 /**
3571 * \brief The number of code-completion results stored in the
3572 * \c Results array.
3573 */
3574 unsigned NumResults;
3575} CXCodeCompleteResults;
3576
3577/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003578 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3579 * modify its behavior.
3580 *
3581 * The enumerators in this enumeration can be bitwise-OR'd together to
3582 * provide multiple options to \c clang_codeCompleteAt().
3583 */
3584enum CXCodeComplete_Flags {
3585 /**
3586 * \brief Whether to include macros within the set of code
3587 * completions returned.
3588 */
3589 CXCodeComplete_IncludeMacros = 0x01,
3590
3591 /**
3592 * \brief Whether to include code patterns for language constructs
3593 * within the set of code completions, e.g., for loops.
3594 */
3595 CXCodeComplete_IncludeCodePatterns = 0x02
3596};
3597
3598/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003599 * \brief Bits that represent the context under which completion is occurring.
3600 *
3601 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3602 * contexts are occurring simultaneously.
3603 */
3604enum CXCompletionContext {
3605 /**
3606 * \brief The context for completions is unexposed, as only Clang results
3607 * should be included. (This is equivalent to having no context bits set.)
3608 */
3609 CXCompletionContext_Unexposed = 0,
3610
3611 /**
3612 * \brief Completions for any possible type should be included in the results.
3613 */
3614 CXCompletionContext_AnyType = 1 << 0,
3615
3616 /**
3617 * \brief Completions for any possible value (variables, function calls, etc.)
3618 * should be included in the results.
3619 */
3620 CXCompletionContext_AnyValue = 1 << 1,
3621 /**
3622 * \brief Completions for values that resolve to an Objective-C object should
3623 * be included in the results.
3624 */
3625 CXCompletionContext_ObjCObjectValue = 1 << 2,
3626 /**
3627 * \brief Completions for values that resolve to an Objective-C selector
3628 * should be included in the results.
3629 */
3630 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3631 /**
3632 * \brief Completions for values that resolve to a C++ class type should be
3633 * included in the results.
3634 */
3635 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3636
3637 /**
3638 * \brief Completions for fields of the member being accessed using the dot
3639 * operator should be included in the results.
3640 */
3641 CXCompletionContext_DotMemberAccess = 1 << 5,
3642 /**
3643 * \brief Completions for fields of the member being accessed using the arrow
3644 * operator should be included in the results.
3645 */
3646 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3647 /**
3648 * \brief Completions for properties of the Objective-C object being accessed
3649 * using the dot operator should be included in the results.
3650 */
3651 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3652
3653 /**
3654 * \brief Completions for enum tags should be included in the results.
3655 */
3656 CXCompletionContext_EnumTag = 1 << 8,
3657 /**
3658 * \brief Completions for union tags should be included in the results.
3659 */
3660 CXCompletionContext_UnionTag = 1 << 9,
3661 /**
3662 * \brief Completions for struct tags should be included in the results.
3663 */
3664 CXCompletionContext_StructTag = 1 << 10,
3665
3666 /**
3667 * \brief Completions for C++ class names should be included in the results.
3668 */
3669 CXCompletionContext_ClassTag = 1 << 11,
3670 /**
3671 * \brief Completions for C++ namespaces and namespace aliases should be
3672 * included in the results.
3673 */
3674 CXCompletionContext_Namespace = 1 << 12,
3675 /**
3676 * \brief Completions for C++ nested name specifiers should be included in
3677 * the results.
3678 */
3679 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3680
3681 /**
3682 * \brief Completions for Objective-C interfaces (classes) should be included
3683 * in the results.
3684 */
3685 CXCompletionContext_ObjCInterface = 1 << 14,
3686 /**
3687 * \brief Completions for Objective-C protocols should be included in
3688 * the results.
3689 */
3690 CXCompletionContext_ObjCProtocol = 1 << 15,
3691 /**
3692 * \brief Completions for Objective-C categories should be included in
3693 * the results.
3694 */
3695 CXCompletionContext_ObjCCategory = 1 << 16,
3696 /**
3697 * \brief Completions for Objective-C instance messages should be included
3698 * in the results.
3699 */
3700 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3701 /**
3702 * \brief Completions for Objective-C class messages should be included in
3703 * the results.
3704 */
3705 CXCompletionContext_ObjCClassMessage = 1 << 18,
3706 /**
3707 * \brief Completions for Objective-C selector names should be included in
3708 * the results.
3709 */
3710 CXCompletionContext_ObjCSelectorName = 1 << 19,
3711
3712 /**
3713 * \brief Completions for preprocessor macro names should be included in
3714 * the results.
3715 */
3716 CXCompletionContext_MacroName = 1 << 20,
3717
3718 /**
3719 * \brief Natural language completions should be included in the results.
3720 */
3721 CXCompletionContext_NaturalLanguage = 1 << 21,
3722
3723 /**
3724 * \brief The current context is unknown, so set all contexts.
3725 */
3726 CXCompletionContext_Unknown = ((1 << 22) - 1)
3727};
3728
3729/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003730 * \brief Returns a default set of code-completion options that can be
3731 * passed to\c clang_codeCompleteAt().
3732 */
3733CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3734
3735/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003736 * \brief Perform code completion at a given location in a translation unit.
3737 *
3738 * This function performs code completion at a particular file, line, and
3739 * column within source code, providing results that suggest potential
3740 * code snippets based on the context of the completion. The basic model
3741 * for code completion is that Clang will parse a complete source file,
3742 * performing syntax checking up to the location where code-completion has
3743 * been requested. At that point, a special code-completion token is passed
3744 * to the parser, which recognizes this token and determines, based on the
3745 * current location in the C/Objective-C/C++ grammar and the state of
3746 * semantic analysis, what completions to provide. These completions are
3747 * returned via a new \c CXCodeCompleteResults structure.
3748 *
3749 * Code completion itself is meant to be triggered by the client when the
3750 * user types punctuation characters or whitespace, at which point the
3751 * code-completion location will coincide with the cursor. For example, if \c p
3752 * is a pointer, code-completion might be triggered after the "-" and then
3753 * after the ">" in \c p->. When the code-completion location is afer the ">",
3754 * the completion results will provide, e.g., the members of the struct that
3755 * "p" points to. The client is responsible for placing the cursor at the
3756 * beginning of the token currently being typed, then filtering the results
3757 * based on the contents of the token. For example, when code-completing for
3758 * the expression \c p->get, the client should provide the location just after
3759 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3760 * client can filter the results based on the current token text ("get"), only
3761 * showing those results that start with "get". The intent of this interface
3762 * is to separate the relatively high-latency acquisition of code-completion
3763 * results from the filtering of results on a per-character basis, which must
3764 * have a lower latency.
3765 *
3766 * \param TU The translation unit in which code-completion should
3767 * occur. The source files for this translation unit need not be
3768 * completely up-to-date (and the contents of those source files may
3769 * be overridden via \p unsaved_files). Cursors referring into the
3770 * translation unit may be invalidated by this invocation.
3771 *
3772 * \param complete_filename The name of the source file where code
3773 * completion should be performed. This filename may be any file
3774 * included in the translation unit.
3775 *
3776 * \param complete_line The line at which code-completion should occur.
3777 *
3778 * \param complete_column The column at which code-completion should occur.
3779 * Note that the column should point just after the syntactic construct that
3780 * initiated code completion, and not in the middle of a lexical token.
3781 *
3782 * \param unsaved_files the Tiles that have not yet been saved to disk
3783 * but may be required for parsing or code completion, including the
3784 * contents of those files. The contents and name of these files (as
3785 * specified by CXUnsavedFile) are copied when necessary, so the
3786 * client only needs to guarantee their validity until the call to
3787 * this function returns.
3788 *
3789 * \param num_unsaved_files The number of unsaved file entries in \p
3790 * unsaved_files.
3791 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00003792 * \param options Extra options that control the behavior of code
3793 * completion, expressed as a bitwise OR of the enumerators of the
3794 * CXCodeComplete_Flags enumeration. The
3795 * \c clang_defaultCodeCompleteOptions() function returns a default set
3796 * of code-completion options.
3797 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003798 * \returns If successful, a new \c CXCodeCompleteResults structure
3799 * containing code-completion results, which should eventually be
3800 * freed with \c clang_disposeCodeCompleteResults(). If code
3801 * completion fails, returns NULL.
3802 */
3803CINDEX_LINKAGE
3804CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3805 const char *complete_filename,
3806 unsigned complete_line,
3807 unsigned complete_column,
3808 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00003809 unsigned num_unsaved_files,
3810 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003811
3812/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00003813 * \brief Sort the code-completion results in case-insensitive alphabetical
3814 * order.
3815 *
3816 * \param Results The set of results to sort.
3817 * \param NumResults The number of results in \p Results.
3818 */
3819CINDEX_LINKAGE
3820void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3821 unsigned NumResults);
3822
3823/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003824 * \brief Free the given set of code-completion results.
3825 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003826CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00003827void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00003828
Douglas Gregor20d416c2010-01-20 01:10:47 +00003829/**
Douglas Gregora88084b2010-02-18 18:08:43 +00003830 * \brief Determine the number of diagnostics produced prior to the
3831 * location where code completion was performed.
3832 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003833CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003834unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3835
3836/**
3837 * \brief Retrieve a diagnostic associated with the given code completion.
3838 *
3839 * \param Result the code completion results to query.
3840 * \param Index the zero-based diagnostic number to retrieve.
3841 *
3842 * \returns the requested diagnostic. This diagnostic must be freed
3843 * via a call to \c clang_disposeDiagnostic().
3844 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003845CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003846CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3847 unsigned Index);
3848
3849/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003850 * \brief Determines what compeltions are appropriate for the context
3851 * the given code completion.
3852 *
3853 * \param Results the code completion results to query
3854 *
3855 * \returns the kinds of completions that are appropriate for use
3856 * along with the given code completion results.
3857 */
3858CINDEX_LINKAGE
3859unsigned long long clang_codeCompleteGetContexts(
3860 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00003861
3862/**
3863 * \brief Returns the cursor kind for the container for the current code
3864 * completion context. The container is only guaranteed to be set for
3865 * contexts where a container exists (i.e. member accesses or Objective-C
3866 * message sends); if there is not a container, this function will return
3867 * CXCursor_InvalidCode.
3868 *
3869 * \param Results the code completion results to query
3870 *
3871 * \param IsIncomplete on return, this value will be false if Clang has complete
3872 * information about the container. If Clang does not have complete
3873 * information, this value will be true.
3874 *
3875 * \returns the container kind, or CXCursor_InvalidCode if there is not a
3876 * container
3877 */
3878CINDEX_LINKAGE
3879enum CXCursorKind clang_codeCompleteGetContainerKind(
3880 CXCodeCompleteResults *Results,
3881 unsigned *IsIncomplete);
3882
3883/**
3884 * \brief Returns the USR for the container for the current code completion
3885 * context. If there is not a container for the current context, this
3886 * function will return the empty string.
3887 *
3888 * \param Results the code completion results to query
3889 *
3890 * \returns the USR for the container
3891 */
3892CINDEX_LINKAGE
3893CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00003894
Douglas Gregor0a47d692011-07-26 15:24:30 +00003895
3896/**
3897 * \brief Returns the currently-entered selector for an Objective-C message
3898 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
3899 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
3900 * CXCompletionContext_ObjCClassMessage.
3901 *
3902 * \param Results the code completion results to query
3903 *
3904 * \returns the selector (or partial selector) that has been entered thus far
3905 * for an Objective-C message send.
3906 */
3907CINDEX_LINKAGE
3908CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
3909
Douglas Gregor3da626b2011-07-07 16:03:39 +00003910/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00003911 * @}
3912 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003913
3914
Ted Kremenek04bb7162010-01-22 22:44:15 +00003915/**
3916 * \defgroup CINDEX_MISC Miscellaneous utility functions
3917 *
3918 * @{
3919 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00003920
3921/**
3922 * \brief Return a version string, suitable for showing to a user, but not
3923 * intended to be parsed (the format is not guaranteed to be stable).
3924 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00003925CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00003926
Ted Kremenekd2427dd2011-03-18 23:05:39 +00003927
3928/**
3929 * \brief Enable/disable crash recovery.
3930 *
3931 * \param Flag to indicate if crash recovery is enabled. A non-zero value
3932 * enables crash recovery, while 0 disables it.
3933 */
3934CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
3935
Ted Kremenek16b55a72010-01-26 19:31:51 +00003936 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003937 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00003938 * (used with clang_getInclusions()).
3939 *
3940 * This visitor function will be invoked by clang_getInclusions() for each
3941 * file included (either at the top-level or by #include directives) within
3942 * a translation unit. The first argument is the file being included, and
3943 * the second and third arguments provide the inclusion stack. The
3944 * array is sorted in order of immediate inclusion. For example,
3945 * the first element refers to the location that included 'included_file'.
3946 */
3947typedef void (*CXInclusionVisitor)(CXFile included_file,
3948 CXSourceLocation* inclusion_stack,
3949 unsigned include_len,
3950 CXClientData client_data);
3951
3952/**
3953 * \brief Visit the set of preprocessor inclusions in a translation unit.
3954 * The visitor function is called with the provided data for every included
3955 * file. This does not include headers included by the PCH file (unless one
3956 * is inspecting the inclusions in the PCH file itself).
3957 */
3958CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3959 CXInclusionVisitor visitor,
3960 CXClientData client_data);
3961
3962/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00003963 * @}
3964 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003965
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00003966/** \defgroup CINDEX_REMAPPING Remapping functions
3967 *
3968 * @{
3969 */
3970
3971/**
3972 * \brief A remapping of original source files and their translated files.
3973 */
3974typedef void *CXRemapping;
3975
3976/**
3977 * \brief Retrieve a remapping.
3978 *
3979 * \param path the path that contains metadata about remappings.
3980 *
3981 * \returns the requested remapping. This remapping must be freed
3982 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3983 */
3984CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
3985
3986/**
Ted Kremenek30660a82012-03-06 20:06:33 +00003987 * \brief Retrieve a remapping.
3988 *
3989 * \param filePaths pointer to an array of file paths containing remapping info.
3990 *
3991 * \param numFiles number of file paths.
3992 *
3993 * \returns the requested remapping. This remapping must be freed
3994 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3995 */
3996CINDEX_LINKAGE
3997CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
3998 unsigned numFiles);
3999
4000/**
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00004001 * \brief Determine the number of remappings.
4002 */
4003CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4004
4005/**
4006 * \brief Get the original and the associated filename from the remapping.
4007 *
4008 * \param original If non-NULL, will be set to the original filename.
4009 *
4010 * \param transformed If non-NULL, will be set to the filename that the original
4011 * is associated with.
4012 */
4013CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4014 CXString *original, CXString *transformed);
4015
4016/**
4017 * \brief Dispose the remapping.
4018 */
4019CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4020
4021/**
4022 * @}
4023 */
4024
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004025/** \defgroup CINDEX_HIGH Higher level API functions
4026 *
4027 * @{
4028 */
4029
4030enum CXVisitorResult {
4031 CXVisit_Break,
4032 CXVisit_Continue
4033};
4034
4035typedef struct {
4036 void *context;
4037 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4038} CXCursorAndRangeVisitor;
4039
4040/**
4041 * \brief Find references of a declaration in a specific file.
4042 *
4043 * \param cursor pointing to a declaration or a reference of one.
4044 *
4045 * \param file to search for references.
4046 *
4047 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4048 * each reference found.
4049 * The CXSourceRange will point inside the file; if the reference is inside
4050 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4051 */
4052CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4053 CXCursorAndRangeVisitor visitor);
4054
4055#ifdef __has_feature
4056# if __has_feature(blocks)
4057
4058typedef enum CXVisitorResult
4059 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4060
4061CINDEX_LINKAGE
4062void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4063 CXCursorAndRangeVisitorBlock);
4064
4065# endif
4066#endif
4067
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004068/**
4069 * \brief The client's data object that is associated with a CXFile.
4070 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004071typedef void *CXIdxClientFile;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004072
4073/**
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004074 * \brief The client's data object that is associated with a semantic entity.
4075 */
4076typedef void *CXIdxClientEntity;
4077
4078/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004079 * \brief The client's data object that is associated with a semantic container
4080 * of entities.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004081 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004082typedef void *CXIdxClientContainer;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004083
4084/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004085 * \brief The client's data object that is associated with an AST file (PCH
4086 * or module).
4087 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004088typedef void *CXIdxClientASTFile;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004089
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004090/**
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004091 * \brief Source location passed to index callbacks.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004092 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004093typedef struct {
4094 void *ptr_data[2];
4095 unsigned int_data;
4096} CXIdxLoc;
4097
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004098/**
4099 * \brief Data for \see ppIncludedFile callback.
4100 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004101typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004102 /**
4103 * \brief Location of '#' in the #include/#import directive.
4104 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004105 CXIdxLoc hashLoc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004106 /**
4107 * \brief Filename as written in the #include/#import directive.
4108 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004109 const char *filename;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004110 /**
4111 * \brief The actual file that the #include/#import directive resolved to.
4112 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004113 CXFile file;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004114 int isImport;
4115 int isAngled;
4116} CXIdxIncludedFileInfo;
4117
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004118/**
4119 * \brief Data for \see importedASTFile callback.
4120 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004121typedef struct {
4122 CXFile file;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004123 /**
4124 * \brief Location where the file is imported. It is useful mostly for
4125 * modules.
4126 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004127 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004128 /**
4129 * \brief Non-zero if the AST file is a module otherwise it's a PCH.
4130 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004131 int isModule;
4132} CXIdxImportedASTFileInfo;
4133
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004134typedef enum {
4135 CXIdxEntity_Unexposed = 0,
4136 CXIdxEntity_Typedef = 1,
4137 CXIdxEntity_Function = 2,
4138 CXIdxEntity_Variable = 3,
4139 CXIdxEntity_Field = 4,
4140 CXIdxEntity_EnumConstant = 5,
4141
4142 CXIdxEntity_ObjCClass = 6,
4143 CXIdxEntity_ObjCProtocol = 7,
4144 CXIdxEntity_ObjCCategory = 8,
4145
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004146 CXIdxEntity_ObjCInstanceMethod = 9,
4147 CXIdxEntity_ObjCClassMethod = 10,
4148 CXIdxEntity_ObjCProperty = 11,
4149 CXIdxEntity_ObjCIvar = 12,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004150
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004151 CXIdxEntity_Enum = 13,
4152 CXIdxEntity_Struct = 14,
4153 CXIdxEntity_Union = 15,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004154
4155 CXIdxEntity_CXXClass = 16,
4156 CXIdxEntity_CXXNamespace = 17,
4157 CXIdxEntity_CXXNamespaceAlias = 18,
4158 CXIdxEntity_CXXStaticVariable = 19,
4159 CXIdxEntity_CXXStaticMethod = 20,
4160 CXIdxEntity_CXXInstanceMethod = 21,
4161 CXIdxEntity_CXXConstructor = 22,
4162 CXIdxEntity_CXXDestructor = 23,
4163 CXIdxEntity_CXXConversionFunction = 24,
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004164 CXIdxEntity_CXXTypeAlias = 25
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004165
4166} CXIdxEntityKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004167
Argyrios Kyrtzidis838d3c22011-12-07 20:44:12 +00004168typedef enum {
4169 CXIdxEntityLang_None = 0,
4170 CXIdxEntityLang_C = 1,
4171 CXIdxEntityLang_ObjC = 2,
4172 CXIdxEntityLang_CXX = 3
4173} CXIdxEntityLanguage;
4174
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004175/**
4176 * \brief Extra C++ template information for an entity. This can apply to:
4177 * CXIdxEntity_Function
4178 * CXIdxEntity_CXXClass
4179 * CXIdxEntity_CXXStaticMethod
4180 * CXIdxEntity_CXXInstanceMethod
4181 * CXIdxEntity_CXXConstructor
4182 * CXIdxEntity_CXXConversionFunction
4183 * CXIdxEntity_CXXTypeAlias
4184 */
4185typedef enum {
4186 CXIdxEntity_NonTemplate = 0,
4187 CXIdxEntity_Template = 1,
4188 CXIdxEntity_TemplatePartialSpecialization = 2,
4189 CXIdxEntity_TemplateSpecialization = 3
4190} CXIdxEntityCXXTemplateKind;
4191
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004192typedef enum {
4193 CXIdxAttr_Unexposed = 0,
4194 CXIdxAttr_IBAction = 1,
4195 CXIdxAttr_IBOutlet = 2,
4196 CXIdxAttr_IBOutletCollection = 3
4197} CXIdxAttrKind;
4198
4199typedef struct {
4200 CXIdxAttrKind kind;
4201 CXCursor cursor;
4202 CXIdxLoc loc;
4203} CXIdxAttrInfo;
4204
4205typedef struct {
Argyrios Kyrtzidis643d3ce2011-12-15 00:05:00 +00004206 CXIdxEntityKind kind;
4207 CXIdxEntityCXXTemplateKind templateKind;
4208 CXIdxEntityLanguage lang;
4209 const char *name;
4210 const char *USR;
4211 CXCursor cursor;
4212 const CXIdxAttrInfo *const *attributes;
4213 unsigned numAttributes;
4214} CXIdxEntityInfo;
4215
4216typedef struct {
4217 CXCursor cursor;
4218} CXIdxContainerInfo;
4219
4220typedef struct {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004221 const CXIdxAttrInfo *attrInfo;
4222 const CXIdxEntityInfo *objcClass;
4223 CXCursor classCursor;
4224 CXIdxLoc classLoc;
4225} CXIdxIBOutletCollectionAttrInfo;
4226
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004227typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004228 const CXIdxEntityInfo *entityInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004229 CXCursor cursor;
4230 CXIdxLoc loc;
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004231 const CXIdxContainerInfo *semanticContainer;
4232 /**
4233 * \brief Generally same as \see semanticContainer but can be different in
4234 * cases like out-of-line C++ member functions.
4235 */
4236 const CXIdxContainerInfo *lexicalContainer;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004237 int isRedeclaration;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004238 int isDefinition;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004239 int isContainer;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004240 const CXIdxContainerInfo *declAsContainer;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004241 /**
4242 * \brief Whether the declaration exists in code or was created implicitly
4243 * by the compiler, e.g. implicit objc methods for properties.
4244 */
4245 int isImplicit;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004246 const CXIdxAttrInfo *const *attributes;
4247 unsigned numAttributes;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004248} CXIdxDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004249
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004250typedef enum {
4251 CXIdxObjCContainer_ForwardRef = 0,
4252 CXIdxObjCContainer_Interface = 1,
4253 CXIdxObjCContainer_Implementation = 2
4254} CXIdxObjCContainerKind;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004255
4256typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004257 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004258 CXIdxObjCContainerKind kind;
4259} CXIdxObjCContainerDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004260
4261typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004262 const CXIdxEntityInfo *base;
4263 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004264 CXIdxLoc loc;
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004265} CXIdxBaseClassInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004266
4267typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004268 const CXIdxEntityInfo *protocol;
4269 CXCursor cursor;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004270 CXIdxLoc loc;
4271} CXIdxObjCProtocolRefInfo;
4272
4273typedef struct {
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004274 const CXIdxObjCProtocolRefInfo *const *protocols;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004275 unsigned numProtocols;
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004276} CXIdxObjCProtocolRefListInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004277
4278typedef struct {
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004279 const CXIdxObjCContainerDeclInfo *containerInfo;
4280 const CXIdxBaseClassInfo *superInfo;
4281 const CXIdxObjCProtocolRefListInfo *protocols;
4282} CXIdxObjCInterfaceDeclInfo;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004283
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004284typedef struct {
Argyrios Kyrtzidisc10a4c82011-12-13 18:47:45 +00004285 const CXIdxObjCContainerDeclInfo *containerInfo;
4286 const CXIdxEntityInfo *objcClass;
4287 CXCursor classCursor;
4288 CXIdxLoc classLoc;
4289 const CXIdxObjCProtocolRefListInfo *protocols;
4290} CXIdxObjCCategoryDeclInfo;
4291
4292typedef struct {
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004293 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004294 const CXIdxEntityInfo *getter;
4295 const CXIdxEntityInfo *setter;
4296} CXIdxObjCPropertyDeclInfo;
4297
4298typedef struct {
4299 const CXIdxDeclInfo *declInfo;
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004300 const CXIdxBaseClassInfo *const *bases;
4301 unsigned numBases;
4302} CXIdxCXXClassDeclInfo;
4303
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004304/**
4305 * \brief Data for \see indexEntityReference callback.
4306 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004307typedef enum {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004308 /**
4309 * \brief The entity is referenced directly in user's code.
4310 */
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004311 CXIdxEntityRef_Direct = 1,
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004312 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004313 * \brief An implicit reference, e.g. a reference of an ObjC method via the
4314 * dot syntax.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004315 */
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004316 CXIdxEntityRef_Implicit = 2
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +00004317} CXIdxEntityRefKind;
4318
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004319/**
4320 * \brief Data for \see indexEntityReference callback.
4321 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004322typedef struct {
Argyrios Kyrtzidisb1febb62011-12-07 20:44:19 +00004323 CXIdxEntityRefKind kind;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004324 /**
4325 * \brief Reference cursor.
4326 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004327 CXCursor cursor;
4328 CXIdxLoc loc;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004329 /**
4330 * \brief The entity that gets referenced.
4331 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004332 const CXIdxEntityInfo *referencedEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004333 /**
4334 * \brief Immediate "parent" of the reference. For example:
4335 *
4336 * \code
4337 * Foo *var;
4338 * \endcode
4339 *
4340 * The parent of reference of type 'Foo' is the variable 'var'.
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004341 * For references inside statement bodies of functions/methods,
4342 * the parentEntity will be the function/method.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004343 */
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004344 const CXIdxEntityInfo *parentEntity;
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004345 /**
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +00004346 * \brief Lexical container context of the reference.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004347 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004348 const CXIdxContainerInfo *container;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004349} CXIdxEntityRefInfo;
4350
4351typedef struct {
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004352 /**
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004353 * \brief Called periodically to check whether indexing should be aborted.
4354 * Should return 0 to continue, and non-zero to abort.
4355 */
4356 int (*abortQuery)(CXClientData client_data, void *reserved);
4357
4358 /**
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004359 * \brief Called at the end of indexing; passes the complete diagnostic set.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004360 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004361 void (*diagnostic)(CXClientData client_data,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004362 CXDiagnosticSet, void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004363
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004364 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
4365 CXFile mainFile, void *reserved);
4366
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004367 /**
4368 * \brief Called when a file gets #included/#imported.
4369 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004370 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004371 const CXIdxIncludedFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004372
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004373 /**
4374 * \brief Called when a AST file (PCH or module) gets imported.
4375 *
4376 * AST files will not get indexed (there will not be callbacks to index all
4377 * the entities in an AST file). The recommended action is that, if the AST
4378 * file is not already indexed, to block further indexing and initiate a new
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004379 * indexing job specific to the AST file.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004380 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004381 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004382 const CXIdxImportedASTFileInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004383
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004384 /**
4385 * \brief Called at the beginning of indexing a translation unit.
4386 */
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004387 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004388 void *reserved);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004389
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004390 void (*indexDeclaration)(CXClientData client_data,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004391 const CXIdxDeclInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004392
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004393 /**
4394 * \brief Called to index a reference of an entity.
4395 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004396 void (*indexEntityReference)(CXClientData client_data,
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004397 const CXIdxEntityRefInfo *);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004398
4399} IndexerCallbacks;
4400
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004401CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004402CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
4403clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004404
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004405CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
4406clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
4407
NAKAMURA Takumiab336c12011-11-11 02:51:09 +00004408CINDEX_LINKAGE
Argyrios Kyrtzidis6ec43ad2011-11-12 02:16:30 +00004409const CXIdxObjCCategoryDeclInfo *
4410clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
4411
Argyrios Kyrtzidisc71d5542011-11-14 22:39:19 +00004412CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
4413clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004414
Argyrios Kyrtzidis792db262012-02-28 17:50:33 +00004415CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
4416clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
4417
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004418CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
4419clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
4420
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004421CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
4422clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
4423
4424/**
4425 * \brief For retrieving a custom CXIdxClientContainer attached to a
4426 * container.
4427 */
4428CINDEX_LINKAGE CXIdxClientContainer
4429clang_index_getClientContainer(const CXIdxContainerInfo *);
4430
4431/**
4432 * \brief For setting a custom CXIdxClientContainer attached to a
4433 * container.
4434 */
4435CINDEX_LINKAGE void
4436clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
4437
4438/**
4439 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
4440 */
4441CINDEX_LINKAGE CXIdxClientEntity
4442clang_index_getClientEntity(const CXIdxEntityInfo *);
4443
4444/**
4445 * \brief For setting a custom CXIdxClientEntity attached to an entity.
4446 */
4447CINDEX_LINKAGE void
4448clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
4449
4450/**
4451 * \brief An indexing action, to be applied to one or multiple translation units
4452 * but not on concurrent threads. If there are threads doing indexing
4453 * concurrently, they should use different CXIndexAction objects.
4454 */
4455typedef void *CXIndexAction;
4456
4457/**
4458 * \brief An indexing action, to be applied to one or multiple translation units
4459 * but not on concurrent threads. If there are threads doing indexing
4460 * concurrently, they should use different CXIndexAction objects.
4461 *
4462 * \param CIdx The index object with which the index action will be associated.
4463 */
4464CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
4465
4466/**
4467 * \brief Destroy the given index action.
4468 *
4469 * The index action must not be destroyed until all of the translation units
4470 * created within that index action have been destroyed.
4471 */
4472CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
4473
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004474typedef enum {
4475 /**
4476 * \brief Used to indicate that no special indexing options are needed.
4477 */
4478 CXIndexOpt_None = 0x0,
4479
4480 /**
4481 * \brief Used to indicate that \see indexEntityReference should be invoked
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +00004482 * for only one reference of an entity per source file that does not also
4483 * include a declaration/definition of the entity.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004484 */
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +00004485 CXIndexOpt_SuppressRedundantRefs = 0x1,
4486
4487 /**
4488 * \brief Function-local symbols should be indexed. If this is not set
4489 * function-local symbols will be ignored.
4490 */
Argyrios Kyrtzidis58d2dbe2012-02-14 22:23:11 +00004491 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
4492
4493 /**
4494 * \brief Implicit function/class template instantiations should be indexed.
4495 * If this is not set, implicit instantiations will be ignored.
4496 */
4497 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004498} CXIndexOptFlags;
4499
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004500/**
4501 * \brief Index the given source file and the translation unit corresponding
4502 * to that file via callbacks implemented through \see IndexerCallbacks.
4503 *
4504 * \param client_data pointer data supplied by the client, which will
4505 * be passed to the invoked callbacks.
4506 *
4507 * \param index_callbacks Pointer to indexing callbacks that the client
4508 * implements.
4509 *
4510 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets
4511 * passed in index_callbacks.
4512 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004513 * \param index_options A bitmask of options that affects how indexing is
4514 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004515 *
4516 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
4517 * after indexing is finished. Set to NULL if you do not require it.
4518 *
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004519 * \returns If there is a failure from which the there is no recovery, returns
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004520 * non-zero, otherwise returns 0.
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004521 *
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004522 * The rest of the parameters are the same as \see clang_parseTranslationUnit.
4523 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004524CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004525 CXClientData client_data,
4526 IndexerCallbacks *index_callbacks,
4527 unsigned index_callbacks_size,
4528 unsigned index_options,
4529 const char *source_filename,
4530 const char * const *command_line_args,
4531 int num_command_line_args,
4532 struct CXUnsavedFile *unsaved_files,
4533 unsigned num_unsaved_files,
4534 CXTranslationUnit *out_TU,
4535 unsigned TU_options);
4536
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004537/**
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004538 * \brief Index the given translation unit via callbacks implemented through
4539 * \see IndexerCallbacks.
4540 *
4541 * The order of callback invocations is not guaranteed to be the same as
4542 * when indexing a source file. The high level order will be:
4543 *
4544 * -Preprocessor callbacks invocations
4545 * -Declaration/reference callbacks invocations
4546 * -Diagnostic callback invocations
4547 *
4548 * The parameters are the same as \see clang_indexSourceFile.
4549 *
4550 * \returns If there is a failure from which the there is no recovery, returns
4551 * non-zero, otherwise returns 0.
4552 */
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004553CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004554 CXClientData client_data,
4555 IndexerCallbacks *index_callbacks,
4556 unsigned index_callbacks_size,
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +00004557 unsigned index_options,
4558 CXTranslationUnit);
Argyrios Kyrtzidis21ee5702011-11-15 06:20:16 +00004559
4560/**
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004561 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
4562 * the given CXIdxLoc.
4563 *
4564 * If the location refers into a macro expansion, retrieves the
4565 * location of the macro expansion and if it refers into a macro argument
4566 * retrieves the location of the argument.
4567 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004568CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
Argyrios Kyrtzidisdd93c592011-11-11 00:23:36 +00004569 CXIdxClientFile *indexFile,
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004570 CXFile *file,
4571 unsigned *line,
4572 unsigned *column,
4573 unsigned *offset);
4574
Argyrios Kyrtzidisbd0ddf82011-10-27 17:36:12 +00004575/**
4576 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
4577 */
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00004578CINDEX_LINKAGE
4579CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
4580
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +00004581/**
4582 * @}
4583 */
4584
Douglas Gregorc42fefa2010-01-22 22:29:16 +00004585/**
4586 * @}
4587 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00004588
Ted Kremenekd2fa5662009-08-26 22:36:44 +00004589#ifdef __cplusplus
4590}
4591#endif
4592#endif
4593