blob: 707c0df20170a786f8b4ab3005b50860eafbe950 [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 Gregor20d416c2010-01-20 01:10:47 +000038/** \defgroup CINDEX C Interface to Clang
39 *
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 */
Steve Naroff50398192009-08-28 15:28:48 +000066typedef void *CXTranslationUnit; /* A translation unit instance. */
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 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000118 CXAvailability_NotAvailable
119};
120
Douglas Gregor7f173762010-01-20 22:28:27 +0000121/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000122 * \defgroup CINDEX_STRING String manipulation routines
123 *
124 * @{
125 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000126
Douglas Gregor7f173762010-01-20 22:28:27 +0000127/**
128 * \brief A character string.
129 *
130 * The \c CXString type is used to return strings from the interface when
131 * the ownership of that string might different from one call to the next.
132 * Use \c clang_getCString() to retrieve the string data and, once finished
133 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000134 */
135typedef struct {
136 const char *Spelling;
137 /* A 1 value indicates the clang_ indexing API needed to allocate the string
138 (and it must be freed by clang_disposeString()). */
139 int MustFreeString;
140} CXString;
141
Douglas Gregor7f173762010-01-20 22:28:27 +0000142/**
143 * \brief Retrieve the character data associated with the given string.
144 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000145CINDEX_LINKAGE const char *clang_getCString(CXString string);
146
Douglas Gregor7f173762010-01-20 22:28:27 +0000147/**
148 * \brief Free the given string,
149 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000150CINDEX_LINKAGE void clang_disposeString(CXString string);
151
Douglas Gregor7f173762010-01-20 22:28:27 +0000152/**
153 * @}
154 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000155
156/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000157 * \brief clang_createIndex() provides a shared context for creating
158 * translation units. It provides two options:
159 *
160 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
161 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000162 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000163 * header that was used by the translation unit. If zero, all declarations
164 * will be enumerated.
165 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000166 * Here is an example:
167 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000168 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
169 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000170 *
171 * // IndexTest.pch was produced with the following command:
172 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
173 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
174 *
175 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000176 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000177 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000178 * clang_disposeTranslationUnit(TU);
179 *
180 * // This will load all the symbols from 'IndexTest.c', excluding symbols
181 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000182 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
183 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
184 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000185 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
186 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000187 * clang_disposeTranslationUnit(TU);
188 *
189 * This process of creating the 'pch', loading it separately, and using it (via
190 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
191 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000192 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000193CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
194 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000195
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000196/**
197 * \brief Destroy the given index.
198 *
199 * The index must not be destroyed until all of the translation units created
200 * within that index have been destroyed.
201 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000202CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000203
204/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000205 * \brief Request that AST's be generated externally for API calls which parse
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000206 * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
207 *
208 * Note: This is for debugging purposes only, and may be removed at a later
209 * date.
210 *
211 * \param index - The index to update.
212 * \param value - The new flag value.
213 */
214CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
215 int value);
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +0000216/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000217 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000218 *
219 * @{
220 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000221
Douglas Gregorf5525442010-01-20 22:45:41 +0000222/**
223 * \brief A particular source file that is part of a translation unit.
224 */
225typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000226
Douglas Gregorf5525442010-01-20 22:45:41 +0000227
228/**
229 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000230 */
Ted Kremenek74844072010-02-17 00:41:20 +0000231CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000232
Douglas Gregorf5525442010-01-20 22:45:41 +0000233/**
234 * \brief Retrieve the last modification time of the given file.
235 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000236CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000237
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000238/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000239 * \brief Retrieve a file handle within the given translation unit.
240 *
241 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000242 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000243 * \param file_name the name of the file.
244 *
245 * \returns the file handle for the named file in the translation unit \p tu,
246 * or a NULL file handle if the file was not a part of this translation unit.
247 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000248CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000249 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000250
Douglas Gregorb9790342010-01-22 21:44:22 +0000251/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000252 * @}
253 */
254
255/**
256 * \defgroup CINDEX_LOCATIONS Physical source locations
257 *
258 * Clang represents physical source locations in its abstract syntax tree in
259 * great detail, with file, line, and column information for the majority of
260 * the tokens parsed in the source code. These data types and functions are
261 * used to represent source location information, either for a particular
262 * point in the program or for a range of points in the program, and extract
263 * specific location information from those data types.
264 *
265 * @{
266 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000267
Douglas Gregorf5525442010-01-20 22:45:41 +0000268/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000269 * \brief Identifies a specific source location within a translation
270 * unit.
271 *
272 * Use clang_getInstantiationLocation() to map a source location to a
273 * particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000274 */
275typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000276 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000277 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000278} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000279
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000280/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000281 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000282 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000283 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
284 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000285 */
286typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000287 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000288 unsigned begin_int_data;
289 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000290} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000291
Douglas Gregor1db19de2010-01-19 21:36:55 +0000292/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000293 * \brief Retrieve a NULL (invalid) source location.
294 */
295CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000296
Douglas Gregorb9790342010-01-22 21:44:22 +0000297/**
298 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000299 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000300 * code.
301 *
302 * \returns non-zero if the source locations refer to the same location, zero
303 * if they refer to different locations.
304 */
305CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
306 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000307
Douglas Gregorb9790342010-01-22 21:44:22 +0000308/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000309 * \brief Retrieves the source location associated with a given file/line/column
310 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000311 */
312CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
313 CXFile file,
314 unsigned line,
315 unsigned column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000316
Douglas Gregorb9790342010-01-22 21:44:22 +0000317/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000318 * \brief Retrieve a NULL (invalid) source range.
319 */
320CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000321
Douglas Gregor5352ac02010-01-28 00:27:43 +0000322/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000323 * \brief Retrieve a source range given the beginning and ending source
324 * locations.
325 */
326CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
327 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000328
Douglas Gregorb9790342010-01-22 21:44:22 +0000329/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000330 * \brief Retrieve the file, line, column, and offset represented by
331 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000332 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000333 * \param location the location within a source file that will be decomposed
334 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000335 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000336 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000337 * source location points.
338 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000339 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000340 * source location points.
341 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000342 * \param column [out] if non-NULL, will be set to the column to which the given
343 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000344 *
345 * \param offset [out] if non-NULL, will be set to the offset into the
346 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000347 */
348CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
349 CXFile *file,
350 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000351 unsigned *column,
352 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000353
354/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000355 * \brief Retrieve a source location representing the first character within a
356 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000357 */
358CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
359
360/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000361 * \brief Retrieve a source location representing the last character within a
362 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000363 */
364CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
365
Douglas Gregorf5525442010-01-20 22:45:41 +0000366/**
367 * @}
368 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000369
370/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000371 * \defgroup CINDEX_DIAG Diagnostic reporting
372 *
373 * @{
374 */
375
376/**
377 * \brief Describes the severity of a particular diagnostic.
378 */
379enum CXDiagnosticSeverity {
380 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000381 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000382 * option.
383 */
384 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000385
Douglas Gregor5352ac02010-01-28 00:27:43 +0000386 /**
387 * \brief This diagnostic is a note that should be attached to the
388 * previous (non-note) diagnostic.
389 */
390 CXDiagnostic_Note = 1,
391
392 /**
393 * \brief This diagnostic indicates suspicious code that may not be
394 * wrong.
395 */
396 CXDiagnostic_Warning = 2,
397
398 /**
399 * \brief This diagnostic indicates that the code is ill-formed.
400 */
401 CXDiagnostic_Error = 3,
402
403 /**
404 * \brief This diagnostic indicates that the code is ill-formed such
405 * that future parser recovery is unlikely to produce useful
406 * results.
407 */
408 CXDiagnostic_Fatal = 4
409};
410
411/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000412 * \brief A single diagnostic, containing the diagnostic's severity,
413 * location, text, source ranges, and fix-it hints.
414 */
415typedef void *CXDiagnostic;
416
417/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000418 * \brief Determine the number of diagnostics produced for the given
419 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000420 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000421CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
422
423/**
424 * \brief Retrieve a diagnostic associated with the given translation unit.
425 *
426 * \param Unit the translation unit to query.
427 * \param Index the zero-based diagnostic number to retrieve.
428 *
429 * \returns the requested diagnostic. This diagnostic must be freed
430 * via a call to \c clang_disposeDiagnostic().
431 */
432CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
433 unsigned Index);
434
435/**
436 * \brief Destroy a diagnostic.
437 */
438CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000439
440/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000441 * \brief Options to control the display of diagnostics.
442 *
443 * The values in this enum are meant to be combined to customize the
444 * behavior of \c clang_displayDiagnostic().
445 */
446enum CXDiagnosticDisplayOptions {
447 /**
448 * \brief Display the source-location information where the
449 * diagnostic was located.
450 *
451 * When set, diagnostics will be prefixed by the file, line, and
452 * (optionally) column to which the diagnostic refers. For example,
453 *
454 * \code
455 * test.c:28: warning: extra tokens at end of #endif directive
456 * \endcode
457 *
458 * This option corresponds to the clang flag \c -fshow-source-location.
459 */
460 CXDiagnostic_DisplaySourceLocation = 0x01,
461
462 /**
463 * \brief If displaying the source-location information of the
464 * diagnostic, also include the column number.
465 *
466 * This option corresponds to the clang flag \c -fshow-column.
467 */
468 CXDiagnostic_DisplayColumn = 0x02,
469
470 /**
471 * \brief If displaying the source-location information of the
472 * diagnostic, also include information about source ranges in a
473 * machine-parsable format.
474 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000475 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000476 * \c -fdiagnostics-print-source-range-info.
477 */
478 CXDiagnostic_DisplaySourceRanges = 0x04
479};
480
481/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000482 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000483 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000484 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000485 * the diagnostic according to the various options given. The
486 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000487 * options that most closely mimics the behavior of the clang compiler.
488 *
489 * \param Diagnostic The diagnostic to print.
490 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000491 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000492 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000493 *
494 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000495 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000496CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
497 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000498
499/**
500 * \brief Retrieve the set of display options most similar to the
501 * default behavior of the clang compiler.
502 *
503 * \returns A set of display options suitable for use with \c
504 * clang_displayDiagnostic().
505 */
506CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
507
508/**
509 * \brief Print a diagnostic to the given file.
510 */
511
512/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000513 * \brief Determine the severity of the given diagnostic.
514 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000515CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000516clang_getDiagnosticSeverity(CXDiagnostic);
517
518/**
519 * \brief Retrieve the source location of the given diagnostic.
520 *
521 * This location is where Clang would print the caret ('^') when
522 * displaying the diagnostic on the command line.
523 */
524CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
525
526/**
527 * \brief Retrieve the text of the given diagnostic.
528 */
529CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000530
531/**
532 * \brief Determine the number of source ranges associated with the given
533 * diagnostic.
534 */
535CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000536
Douglas Gregor5352ac02010-01-28 00:27:43 +0000537/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000538 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000539 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000540 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000541 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000542 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000543 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000544 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000545 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000546 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000547 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000548 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000549 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000550CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000551 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000552
553/**
554 * \brief Determine the number of fix-it hints associated with the
555 * given diagnostic.
556 */
557CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
558
559/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000560 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000561 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000562 * Fix-its are described in terms of a source range whose contents
563 * should be replaced by a string. This approach generalizes over
564 * three kinds of operations: removal of source code (the range covers
565 * the code to be removed and the replacement string is empty),
566 * replacement of source code (the range covers the code to be
567 * replaced and the replacement string provides the new code), and
568 * insertion (both the start and end of the range point at the
569 * insertion location, and the replacement string provides the text to
570 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000571 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000572 * \param Diagnostic The diagnostic whose fix-its are being queried.
573 *
574 * \param FixIt The zero-based index of the fix-it.
575 *
576 * \param ReplacementRange The source range whose contents will be
577 * replaced with the returned replacement string. Note that source
578 * ranges are half-open ranges [a, b), so the source code should be
579 * replaced from a and up to (but not including) b.
580 *
581 * \returns A string containing text that should be replace the source
582 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000583 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000584CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000585 unsigned FixIt,
586 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000587
588/**
589 * @}
590 */
591
592/**
593 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
594 *
595 * The routines in this group provide the ability to create and destroy
596 * translation units from files, either by parsing the contents of the files or
597 * by reading in a serialized representation of a translation unit.
598 *
599 * @{
600 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000601
Douglas Gregor5352ac02010-01-28 00:27:43 +0000602/**
603 * \brief Get the original translation unit source file name.
604 */
605CINDEX_LINKAGE CXString
606clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
607
608/**
609 * \brief Return the CXTranslationUnit for a given source file and the provided
610 * command line arguments one would pass to the compiler.
611 *
612 * Note: The 'source_filename' argument is optional. If the caller provides a
613 * NULL pointer, the name of the source file is expected to reside in the
614 * specified command line arguments.
615 *
616 * Note: When encountered in 'clang_command_line_args', the following options
617 * are ignored:
618 *
619 * '-c'
620 * '-emit-ast'
621 * '-fsyntax-only'
622 * '-o <output file>' (both '-o' and '<output file>' are ignored)
623 *
624 *
625 * \param source_filename - The name of the source file to load, or NULL if the
626 * source file is included in clang_command_line_args.
627 *
628 * \param num_unsaved_files the number of unsaved file entries in \p
629 * unsaved_files.
630 *
631 * \param unsaved_files the files that have not yet been saved to disk
632 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000633 * those files. The contents and name of these files (as specified by
634 * CXUnsavedFile) are copied when necessary, so the client only needs to
635 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000636 *
637 * \param diag_callback callback function that will receive any diagnostics
638 * emitted while processing this source file. If NULL, diagnostics will be
639 * suppressed.
640 *
641 * \param diag_client_data client data that will be passed to the diagnostic
642 * callback function.
643 */
644CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
645 CXIndex CIdx,
646 const char *source_filename,
647 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000648 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000649 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000650 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000651
Douglas Gregor5352ac02010-01-28 00:27:43 +0000652/**
653 * \brief Create a translation unit from an AST file (-emit-ast).
654 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000655CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000656 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000657
Douglas Gregor44c181a2010-07-23 00:33:23 +0000658/**
659 * \brief Flags that control the creation of translation units.
660 *
661 * The enumerators in this enumeration type are meant to be bitwise
662 * ORed together to specify which options should be used when
663 * constructing the translation unit.
664 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000665enum CXTranslationUnit_Flags {
666 /**
667 * \brief Used to indicate that no special translation-unit options are
668 * needed.
669 */
670 CXTranslationUnit_None = 0x0,
671
672 /**
673 * \brief Used to indicate that the parser should construct a "detailed"
674 * preprocessing record, including all macro definitions and instantiations.
675 *
676 * Constructing a detailed preprocessing record requires more memory
677 * and time to parse, since the information contained in the record
678 * is usually not retained. However, it can be useful for
679 * applications that require more detailed information about the
680 * behavior of the preprocessor.
681 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000682 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
683
684 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000685 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000686 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000687 * When a translation unit is considered "incomplete", semantic
688 * analysis that is typically performed at the end of the
689 * translation unit will be suppressed. For example, this suppresses
690 * the completion of tentative declarations in C and of
691 * instantiation of implicitly-instantiation function templates in
692 * C++. This option is typically used when parsing a header with the
693 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000694 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000695 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000696
697 /**
698 * \brief Used to indicate that the translation unit should be built with an
699 * implicit precompiled header for the preamble.
700 *
701 * An implicit precompiled header is used as an optimization when a
702 * particular translation unit is likely to be reparsed many times
703 * when the sources aren't changing that often. In this case, an
704 * implicit precompiled header will be built containing all of the
705 * initial includes at the top of the main file (what we refer to as
706 * the "preamble" of the file). In subsequent parses, if the
707 * preamble or the files in it have not changed, \c
708 * clang_reparseTranslationUnit() will re-use the implicit
709 * precompiled header to improve parsing performance.
710 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000711 CXTranslationUnit_PrecompiledPreamble = 0x04,
712
713 /**
714 * \brief Used to indicate that the translation unit should cache some
715 * code-completion results with each reparse of the source file.
716 *
717 * Caching of code-completion results is a performance optimization that
718 * introduces some overhead to reparsing but improves the performance of
719 * code-completion operations.
720 */
721 CXTranslationUnit_CacheCompletionResults = 0x08
Douglas Gregor5a430212010-07-21 18:52:53 +0000722};
723
724/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000725 * \brief Returns the set of flags that is suitable for parsing a translation
726 * unit that is being edited.
727 *
728 * The set of flags returned provide options for \c clang_parseTranslationUnit()
729 * to indicate that the translation unit is likely to be reparsed many times,
730 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
731 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
732 * set contains an unspecified set of optimizations (e.g., the precompiled
733 * preamble) geared toward improving the performance of these routines. The
734 * set of optimizations enabled may change from one version to the next.
735 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000736CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000737
738/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000739 * \brief Parse the given source file and the translation unit corresponding
740 * to that file.
741 *
742 * This routine is the main entry point for the Clang C API, providing the
743 * ability to parse a source file into a translation unit that can then be
744 * queried by other functions in the API. This routine accepts a set of
745 * command-line arguments so that the compilation can be configured in the same
746 * way that the compiler is configured on the command line.
747 *
748 * \param CIdx The index object with which the translation unit will be
749 * associated.
750 *
751 * \param source_filename The name of the source file to load, or NULL if the
752 * source file is included in \p clang_command_line_args.
753 *
754 * \param command_line_args The command-line arguments that would be
755 * passed to the \c clang executable if it were being invoked out-of-process.
756 * These command-line options will be parsed and will affect how the translation
757 * unit is parsed. Note that the following options are ignored: '-c',
758 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
759 *
760 * \param num_command_line_args The number of command-line arguments in
761 * \p command_line_args.
762 *
763 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000764 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000765 * those files. The contents and name of these files (as specified by
766 * CXUnsavedFile) are copied when necessary, so the client only needs to
767 * guarantee their validity until the call to this function returns.
768 *
769 * \param num_unsaved_files the number of unsaved file entries in \p
770 * unsaved_files.
771 *
772 * \param options A bitmask of options that affects how the translation unit
773 * is managed but not its compilation. This should be a bitwise OR of the
774 * CXTranslationUnit_XXX flags.
775 *
776 * \returns A new translation unit describing the parsed code and containing
777 * any diagnostics produced by the compiler. If there is a failure from which
778 * the compiler cannot recover, returns NULL.
779 */
780CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
781 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000782 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000783 int num_command_line_args,
784 struct CXUnsavedFile *unsaved_files,
785 unsigned num_unsaved_files,
786 unsigned options);
787
Douglas Gregor5352ac02010-01-28 00:27:43 +0000788/**
Douglas Gregor19998442010-08-13 15:35:05 +0000789 * \brief Flags that control how translation units are saved.
790 *
791 * The enumerators in this enumeration type are meant to be bitwise
792 * ORed together to specify which options should be used when
793 * saving the translation unit.
794 */
795enum CXSaveTranslationUnit_Flags {
796 /**
797 * \brief Used to indicate that no special saving options are needed.
798 */
799 CXSaveTranslationUnit_None = 0x0
800};
801
802/**
803 * \brief Returns the set of flags that is suitable for saving a translation
804 * unit.
805 *
806 * The set of flags returned provide options for
807 * \c clang_saveTranslationUnit() by default. The returned flag
808 * set contains an unspecified set of options that save translation units with
809 * the most commonly-requested data.
810 */
811CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
812
813/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000814 * \brief Saves a translation unit into a serialized representation of
815 * that translation unit on disk.
816 *
817 * Any translation unit that was parsed without error can be saved
818 * into a file. The translation unit can then be deserialized into a
819 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
820 * if it is an incomplete translation unit that corresponds to a
821 * header, used as a precompiled header when parsing other translation
822 * units.
823 *
824 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +0000825 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000826 * \param FileName The file to which the translation unit will be saved.
827 *
Douglas Gregor19998442010-08-13 15:35:05 +0000828 * \param options A bitmask of options that affects how the translation unit
829 * is saved. This should be a bitwise OR of the
830 * CXSaveTranslationUnit_XXX flags.
831 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000832 * \returns Zero if the translation unit was saved successfully, a
833 * non-zero value otherwise.
834 */
835CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +0000836 const char *FileName,
837 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000838
839/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000840 * \brief Destroy the specified CXTranslationUnit object.
841 */
842CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000843
Douglas Gregor5352ac02010-01-28 00:27:43 +0000844/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000845 * \brief Flags that control the reparsing of translation units.
846 *
847 * The enumerators in this enumeration type are meant to be bitwise
848 * ORed together to specify which options should be used when
849 * reparsing the translation unit.
850 */
851enum CXReparse_Flags {
852 /**
853 * \brief Used to indicate that no special reparsing options are needed.
854 */
855 CXReparse_None = 0x0
856};
857
858/**
859 * \brief Returns the set of flags that is suitable for reparsing a translation
860 * unit.
861 *
862 * The set of flags returned provide options for
863 * \c clang_reparseTranslationUnit() by default. The returned flag
864 * set contains an unspecified set of optimizations geared toward common uses
865 * of reparsing. The set of optimizations enabled may change from one version
866 * to the next.
867 */
868CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
869
870/**
Douglas Gregorabc563f2010-07-19 21:46:24 +0000871 * \brief Reparse the source files that produced this translation unit.
872 *
873 * This routine can be used to re-parse the source files that originally
874 * created the given translation unit, for example because those source files
875 * have changed (either on disk or as passed via \p unsaved_files). The
876 * source code will be reparsed with the same command-line options as it
877 * was originally parsed.
878 *
879 * Reparsing a translation unit invalidates all cursors and source locations
880 * that refer into that translation unit. This makes reparsing a translation
881 * unit semantically equivalent to destroying the translation unit and then
882 * creating a new translation unit with the same command-line arguments.
883 * However, it may be more efficient to reparse a translation
884 * unit using this routine.
885 *
886 * \param TU The translation unit whose contents will be re-parsed. The
887 * translation unit must originally have been built with
888 * \c clang_createTranslationUnitFromSourceFile().
889 *
890 * \param num_unsaved_files The number of unsaved file entries in \p
891 * unsaved_files.
892 *
893 * \param unsaved_files The files that have not yet been saved to disk
894 * but may be required for parsing, including the contents of
895 * those files. The contents and name of these files (as specified by
896 * CXUnsavedFile) are copied when necessary, so the client only needs to
897 * guarantee their validity until the call to this function returns.
898 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000899 * \param options A bitset of options composed of the flags in CXReparse_Flags.
900 * The function \c clang_defaultReparseOptions() produces a default set of
901 * options recommended for most uses, based on the translation unit.
902 *
Douglas Gregorabc563f2010-07-19 21:46:24 +0000903 * \returns 0 if the sources could be reparsed. A non-zero value will be
904 * returned if reparsing was impossible, such that the translation unit is
905 * invalid. In such cases, the only valid call for \p TU is
906 * \c clang_disposeTranslationUnit(TU).
907 */
908CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
909 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000910 struct CXUnsavedFile *unsaved_files,
911 unsigned options);
Douglas Gregorabc563f2010-07-19 21:46:24 +0000912
913/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000914 * @}
915 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000916
Douglas Gregor5352ac02010-01-28 00:27:43 +0000917/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000918 * \brief Describes the kind of entity that a cursor refers to.
919 */
920enum CXCursorKind {
921 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000922 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000923 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000924 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000925 *
926 * Unexposed declarations have the same operations as any other kind
927 * of declaration; one can extract their location information,
928 * spelling, find their definitions, etc. However, the specific kind
929 * of the declaration is not reported.
930 */
931 CXCursor_UnexposedDecl = 1,
932 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000933 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000934 /** \brief A C or C++ union. */
935 CXCursor_UnionDecl = 3,
936 /** \brief A C++ class. */
937 CXCursor_ClassDecl = 4,
938 /** \brief An enumeration. */
939 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000940 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000941 * \brief A field (in C) or non-static data member (in C++) in a
942 * struct, union, or C++ class.
943 */
944 CXCursor_FieldDecl = 6,
945 /** \brief An enumerator constant. */
946 CXCursor_EnumConstantDecl = 7,
947 /** \brief A function. */
948 CXCursor_FunctionDecl = 8,
949 /** \brief A variable. */
950 CXCursor_VarDecl = 9,
951 /** \brief A function or method parameter. */
952 CXCursor_ParmDecl = 10,
953 /** \brief An Objective-C @interface. */
954 CXCursor_ObjCInterfaceDecl = 11,
955 /** \brief An Objective-C @interface for a category. */
956 CXCursor_ObjCCategoryDecl = 12,
957 /** \brief An Objective-C @protocol declaration. */
958 CXCursor_ObjCProtocolDecl = 13,
959 /** \brief An Objective-C @property declaration. */
960 CXCursor_ObjCPropertyDecl = 14,
961 /** \brief An Objective-C instance variable. */
962 CXCursor_ObjCIvarDecl = 15,
963 /** \brief An Objective-C instance method. */
964 CXCursor_ObjCInstanceMethodDecl = 16,
965 /** \brief An Objective-C class method. */
966 CXCursor_ObjCClassMethodDecl = 17,
967 /** \brief An Objective-C @implementation. */
968 CXCursor_ObjCImplementationDecl = 18,
969 /** \brief An Objective-C @implementation for a category. */
970 CXCursor_ObjCCategoryImplDecl = 19,
971 /** \brief A typedef */
972 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +0000973 /** \brief A C++ class method. */
974 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +0000975 /** \brief A C++ namespace. */
976 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +0000977 /** \brief A linkage specification, e.g. 'extern "C"'. */
978 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +0000979 /** \brief A C++ constructor. */
980 CXCursor_Constructor = 24,
981 /** \brief A C++ destructor. */
982 CXCursor_Destructor = 25,
983 /** \brief A C++ conversion function. */
984 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000985 /** \brief A C++ template type parameter. */
986 CXCursor_TemplateTypeParameter = 27,
987 /** \brief A C++ non-type template parameter. */
988 CXCursor_NonTypeTemplateParameter = 28,
989 /** \brief A C++ template template parameter. */
990 CXCursor_TemplateTemplateParameter = 29,
991 /** \brief A C++ function template. */
992 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +0000993 /** \brief A C++ class template. */
994 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +0000995 /** \brief A C++ class template partial specialization. */
996 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +0000997 /** \brief A C++ namespace alias declaration. */
998 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +0000999 /** \brief A C++ using directive. */
1000 CXCursor_UsingDirective = 34,
Douglas Gregor7e242562010-09-01 19:52:22 +00001001 /** \brief A using declaration. */
1002 CXCursor_UsingDeclaration = 35,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001003 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor7e242562010-09-01 19:52:22 +00001004 CXCursor_LastDecl = CXCursor_UsingDeclaration,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001005
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001006 /* References */
1007 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001008 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001009 CXCursor_ObjCProtocolRef = 41,
1010 CXCursor_ObjCClassRef = 42,
1011 /**
1012 * \brief A reference to a type declaration.
1013 *
1014 * A type reference occurs anywhere where a type is named but not
1015 * declared. For example, given:
1016 *
1017 * \code
1018 * typedef unsigned size_type;
1019 * size_type size;
1020 * \endcode
1021 *
1022 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1023 * while the type of the variable "size" is referenced. The cursor
1024 * referenced by the type of size is the typedef for size_type.
1025 */
1026 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001027 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001028 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001029 * \brief A reference to a class template, function template, template
1030 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001031 */
1032 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001033 /**
1034 * \brief A reference to a namespace or namespace alias.
1035 */
1036 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001037 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001038 * \brief A reference to a member of a struct, union, or class that occurs in
1039 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001040 */
1041 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001042 /**
1043 * \brief A reference to a labeled statement.
1044 *
1045 * This cursor kind is used to describe the jump to "start_over" in the
1046 * goto statement in the following example:
1047 *
1048 * \code
1049 * start_over:
1050 * ++counter;
1051 *
1052 * goto start_over;
1053 * \endcode
1054 *
1055 * A label reference cursor refers to a label statement.
1056 */
1057 CXCursor_LabelRef = 48,
1058
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001059 /**
1060 * \brief A reference to a set of overloaded functions or function templates
1061 * that has not yet been resolved to a specific function or function template.
1062 *
1063 * An overloaded declaration reference cursor occurs in C++ templates where
1064 * a dependent name refers to a function. For example:
1065 *
1066 * \code
1067 * template<typename T> void swap(T&, T&);
1068 *
1069 * struct X { ... };
1070 * void swap(X&, X&);
1071 *
1072 * template<typename T>
1073 * void reverse(T* first, T* last) {
1074 * while (first < last - 1) {
1075 * swap(*first, *--last);
1076 * ++first;
1077 * }
1078 * }
1079 *
1080 * struct Y { };
1081 * void swap(Y&, Y&);
1082 * \endcode
1083 *
1084 * Here, the identifier "swap" is associated with an overloaded declaration
1085 * reference. In the template definition, "swap" refers to either of the two
1086 * "swap" functions declared above, so both results will be available. At
1087 * instantiation time, "swap" may also refer to other functions found via
1088 * argument-dependent lookup (e.g., the "swap" function at the end of the
1089 * example).
1090 *
1091 * The functions \c clang_getNumOverloadedDecls() and
1092 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1093 * referenced by this cursor.
1094 */
1095 CXCursor_OverloadedDeclRef = 49,
1096
1097 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001098
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001099 /* Error conditions */
1100 CXCursor_FirstInvalid = 70,
1101 CXCursor_InvalidFile = 70,
1102 CXCursor_NoDeclFound = 71,
1103 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001104 CXCursor_InvalidCode = 73,
1105 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001106
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001107 /* Expressions */
1108 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001109
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001110 /**
1111 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001112 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001113 *
1114 * Unexposed expressions have the same operations as any other kind
1115 * of expression; one can extract their location information,
1116 * spelling, children, etc. However, the specific kind of the
1117 * expression is not reported.
1118 */
1119 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001120
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001121 /**
1122 * \brief An expression that refers to some value declaration, such
1123 * as a function, varible, or enumerator.
1124 */
1125 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001126
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001127 /**
1128 * \brief An expression that refers to a member of a struct, union,
1129 * class, Objective-C class, etc.
1130 */
1131 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001132
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001133 /** \brief An expression that calls a function. */
1134 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001135
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001136 /** \brief An expression that sends a message to an Objective-C
1137 object or class. */
1138 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001139
1140 /** \brief An expression that represents a block literal. */
1141 CXCursor_BlockExpr = 105,
1142
1143 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001144
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001145 /* Statements */
1146 CXCursor_FirstStmt = 200,
1147 /**
1148 * \brief A statement whose specific kind is not exposed via this
1149 * interface.
1150 *
1151 * Unexposed statements have the same operations as any other kind of
1152 * statement; one can extract their location information, spelling,
1153 * children, etc. However, the specific kind of the statement is not
1154 * reported.
1155 */
1156 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001157
1158 /** \brief A labelled statement in a function.
1159 *
1160 * This cursor kind is used to describe the "start_over:" label statement in
1161 * the following example:
1162 *
1163 * \code
1164 * start_over:
1165 * ++counter;
1166 * \endcode
1167 *
1168 */
1169 CXCursor_LabelStmt = 201,
1170
1171 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001172
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001173 /**
1174 * \brief Cursor that represents the translation unit itself.
1175 *
1176 * The translation unit cursor exists primarily to act as the root
1177 * cursor for traversing the contents of a translation unit.
1178 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001179 CXCursor_TranslationUnit = 300,
1180
1181 /* Attributes */
1182 CXCursor_FirstAttr = 400,
1183 /**
1184 * \brief An attribute whose specific kind is not exposed via this
1185 * interface.
1186 */
1187 CXCursor_UnexposedAttr = 400,
1188
1189 CXCursor_IBActionAttr = 401,
1190 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001191 CXCursor_IBOutletCollectionAttr = 403,
1192 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001193
1194 /* Preprocessing */
1195 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001196 CXCursor_MacroDefinition = 501,
1197 CXCursor_MacroInstantiation = 502,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001198 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregor48072312010-03-18 15:23:44 +00001199 CXCursor_LastPreprocessing = CXCursor_MacroInstantiation
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001200};
1201
1202/**
1203 * \brief A cursor representing some element in the abstract syntax tree for
1204 * a translation unit.
1205 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001206 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001207 * program--declaration, statements, expressions, references to declarations,
1208 * etc.--under a single "cursor" abstraction with a common set of operations.
1209 * Common operation for a cursor include: getting the physical location in
1210 * a source file where the cursor points, getting the name associated with a
1211 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1212 *
1213 * Cursors can be produced in two specific ways.
1214 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1215 * from which one can use clang_visitChildren() to explore the rest of the
1216 * translation unit. clang_getCursor() maps from a physical source location
1217 * to the entity that resides at that location, allowing one to map from the
1218 * source code into the AST.
1219 */
1220typedef struct {
1221 enum CXCursorKind kind;
1222 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001223} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001224
1225/**
1226 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1227 *
1228 * @{
1229 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001230
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001231/**
1232 * \brief Retrieve the NULL cursor, which represents no entity.
1233 */
1234CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001235
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001236/**
1237 * \brief Retrieve the cursor that represents the given translation unit.
1238 *
1239 * The translation unit cursor can be used to start traversing the
1240 * various declarations within the given translation unit.
1241 */
1242CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1243
1244/**
1245 * \brief Determine whether two cursors are equivalent.
1246 */
1247CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001248
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001249/**
1250 * \brief Retrieve the kind of the given cursor.
1251 */
1252CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1253
1254/**
1255 * \brief Determine whether the given cursor kind represents a declaration.
1256 */
1257CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1258
1259/**
1260 * \brief Determine whether the given cursor kind represents a simple
1261 * reference.
1262 *
1263 * Note that other kinds of cursors (such as expressions) can also refer to
1264 * other cursors. Use clang_getCursorReferenced() to determine whether a
1265 * particular cursor refers to another entity.
1266 */
1267CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1268
1269/**
1270 * \brief Determine whether the given cursor kind represents an expression.
1271 */
1272CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1273
1274/**
1275 * \brief Determine whether the given cursor kind represents a statement.
1276 */
1277CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1278
1279/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001280 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001281 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001282 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001283CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1284
1285/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001286 * \brief Determine whether the given cursor kind represents a translation
1287 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001288 */
1289CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001290
Ted Kremenekad6eff62010-03-08 21:17:29 +00001291/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001292 * \brief Determine whether the given cursor represents a preprocessing
1293 * element, such as a preprocessor directive or macro instantiation.
1294 */
1295CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1296
1297/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001298 * \brief Determine whether the given cursor represents a currently
1299 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1300 */
1301CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1302
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001303/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001304 * \brief Describe the linkage of the entity referred to by a cursor.
1305 */
1306enum CXLinkageKind {
1307 /** \brief This value indicates that no linkage information is available
1308 * for a provided CXCursor. */
1309 CXLinkage_Invalid,
1310 /**
1311 * \brief This is the linkage for variables, parameters, and so on that
1312 * have automatic storage. This covers normal (non-extern) local variables.
1313 */
1314 CXLinkage_NoLinkage,
1315 /** \brief This is the linkage for static variables and static functions. */
1316 CXLinkage_Internal,
1317 /** \brief This is the linkage for entities with external linkage that live
1318 * in C++ anonymous namespaces.*/
1319 CXLinkage_UniqueExternal,
1320 /** \brief This is the linkage for entities with true, external linkage. */
1321 CXLinkage_External
1322};
1323
1324/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001325 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001326 */
1327CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1328
1329/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001330 * \brief Determine the availability of the entity that this cursor refers to.
1331 *
1332 * \param cursor The cursor to query.
1333 *
1334 * \returns The availability of the cursor.
1335 */
1336CINDEX_LINKAGE enum CXAvailabilityKind
1337clang_getCursorAvailability(CXCursor cursor);
1338
1339/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001340 * \brief Describe the "language" of the entity referred to by a cursor.
1341 */
1342CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001343 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001344 CXLanguage_C,
1345 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001346 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001347};
1348
1349/**
1350 * \brief Determine the "language" of the entity referred to by a given cursor.
1351 */
1352CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1353
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001354
1355/**
1356 * \brief Determine the semantic parent of the given cursor.
1357 *
1358 * The semantic parent of a cursor is the cursor that semantically contains
1359 * the given \p cursor. For many declarations, the lexical and semantic parents
1360 * are equivalent (the lexical parent is returned by
1361 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1362 * definitions are provided out-of-line. For example:
1363 *
1364 * \code
1365 * class C {
1366 * void f();
1367 * };
1368 *
1369 * void C::f() { }
1370 * \endcode
1371 *
1372 * In the out-of-line definition of \c C::f, the semantic parent is the
1373 * the class \c C, of which this function is a member. The lexical parent is
1374 * the place where the declaration actually occurs in the source code; in this
1375 * case, the definition occurs in the translation unit. In general, the
1376 * lexical parent for a given entity can change without affecting the semantics
1377 * of the program, and the lexical parent of different declarations of the
1378 * same entity may be different. Changing the semantic parent of a declaration,
1379 * on the other hand, can have a major impact on semantics, and redeclarations
1380 * of a particular entity should all have the same semantic context.
1381 *
1382 * In the example above, both declarations of \c C::f have \c C as their
1383 * semantic context, while the lexical context of the first \c C::f is \c C
1384 * and the lexical context of the second \c C::f is the translation unit.
1385 */
1386CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1387
1388/**
1389 * \brief Determine the lexical parent of the given cursor.
1390 *
1391 * The lexical parent of a cursor is the cursor in which the given \p cursor
1392 * was actually written. For many declarations, the lexical and semantic parents
1393 * are equivalent (the semantic parent is returned by
1394 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1395 * definitions are provided out-of-line. For example:
1396 *
1397 * \code
1398 * class C {
1399 * void f();
1400 * };
1401 *
1402 * void C::f() { }
1403 * \endcode
1404 *
1405 * In the out-of-line definition of \c C::f, the semantic parent is the
1406 * the class \c C, of which this function is a member. The lexical parent is
1407 * the place where the declaration actually occurs in the source code; in this
1408 * case, the definition occurs in the translation unit. In general, the
1409 * lexical parent for a given entity can change without affecting the semantics
1410 * of the program, and the lexical parent of different declarations of the
1411 * same entity may be different. Changing the semantic parent of a declaration,
1412 * on the other hand, can have a major impact on semantics, and redeclarations
1413 * of a particular entity should all have the same semantic context.
1414 *
1415 * In the example above, both declarations of \c C::f have \c C as their
1416 * semantic context, while the lexical context of the first \c C::f is \c C
1417 * and the lexical context of the second \c C::f is the translation unit.
1418 */
1419CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001420
1421/**
1422 * \brief Determine the set of methods that are overridden by the given
1423 * method.
1424 *
1425 * In both Objective-C and C++, a method (aka virtual member function,
1426 * in C++) can override a virtual method in a base class. For
1427 * Objective-C, a method is said to override any method in the class's
1428 * interface (if we're coming from an implementation), its protocols,
1429 * or its categories, that has the same selector and is of the same
1430 * kind (class or instance). If no such method exists, the search
1431 * continues to the class's superclass, its protocols, and its
1432 * categories, and so on.
1433 *
1434 * For C++, a virtual member function overrides any virtual member
1435 * function with the same signature that occurs in its base
1436 * classes. With multiple inheritance, a virtual member function can
1437 * override several virtual member functions coming from different
1438 * base classes.
1439 *
1440 * In all cases, this function determines the immediate overridden
1441 * method, rather than all of the overridden methods. For example, if
1442 * a method is originally declared in a class A, then overridden in B
1443 * (which in inherits from A) and also in C (which inherited from B),
1444 * then the only overridden method returned from this function when
1445 * invoked on C's method will be B's method. The client may then
1446 * invoke this function again, given the previously-found overridden
1447 * methods, to map out the complete method-override set.
1448 *
1449 * \param cursor A cursor representing an Objective-C or C++
1450 * method. This routine will compute the set of methods that this
1451 * method overrides.
1452 *
1453 * \param overridden A pointer whose pointee will be replaced with a
1454 * pointer to an array of cursors, representing the set of overridden
1455 * methods. If there are no overridden methods, the pointee will be
1456 * set to NULL. The pointee must be freed via a call to
1457 * \c clang_disposeOverriddenCursors().
1458 *
1459 * \param num_overridden A pointer to the number of overridden
1460 * functions, will be set to the number of overridden functions in the
1461 * array pointed to by \p overridden.
1462 */
1463CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1464 CXCursor **overridden,
1465 unsigned *num_overridden);
1466
1467/**
1468 * \brief Free the set of overridden cursors returned by \c
1469 * clang_getOverriddenCursors().
1470 */
1471CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1472
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001473/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001474 * @}
1475 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001476
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001477/**
1478 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1479 *
1480 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1481 * routines help map between cursors and the physical locations where the
1482 * described entities occur in the source code. The mapping is provided in
1483 * both directions, so one can map from source code to the AST and back.
1484 *
1485 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001486 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001487
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001488/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001489 * \brief Map a source location to the cursor that describes the entity at that
1490 * location in the source code.
1491 *
1492 * clang_getCursor() maps an arbitrary source location within a translation
1493 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001494 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001495 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001496 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001497 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1498 * will return a cursor referring to the "+" expression.
1499 *
1500 * \returns a cursor representing the entity at the given source location, or
1501 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001502 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001503CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001504
Douglas Gregor98258af2010-01-18 22:46:11 +00001505/**
1506 * \brief Retrieve the physical location of the source constructor referenced
1507 * by the given cursor.
1508 *
1509 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001510 * declaration, where the name of that declaration would occur if it is
1511 * unnamed, or some keyword that introduces that particular declaration.
1512 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001513 * source code.
1514 */
1515CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001516
Douglas Gregorb6998662010-01-19 19:34:47 +00001517/**
1518 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001519 * the given cursor.
1520 *
1521 * The extent of a cursor starts with the file/line/column pointing at the
1522 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001523 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001524 * declaration, the extent covers the declaration itself. For a reference,
1525 * the extent covers the location of the reference (e.g., where the referenced
1526 * entity was actually used).
1527 */
1528CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001529
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001530/**
1531 * @}
1532 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001533
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001534/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001535 * \defgroup CINDEX_TYPES Type information for CXCursors
1536 *
1537 * @{
1538 */
1539
1540/**
1541 * \brief Describes the kind of type
1542 */
1543enum CXTypeKind {
1544 /**
1545 * \brief Reprents an invalid type (e.g., where no type is available).
1546 */
1547 CXType_Invalid = 0,
1548
1549 /**
1550 * \brief A type whose specific kind is not exposed via this
1551 * interface.
1552 */
1553 CXType_Unexposed = 1,
1554
1555 /* Builtin types */
1556 CXType_Void = 2,
1557 CXType_Bool = 3,
1558 CXType_Char_U = 4,
1559 CXType_UChar = 5,
1560 CXType_Char16 = 6,
1561 CXType_Char32 = 7,
1562 CXType_UShort = 8,
1563 CXType_UInt = 9,
1564 CXType_ULong = 10,
1565 CXType_ULongLong = 11,
1566 CXType_UInt128 = 12,
1567 CXType_Char_S = 13,
1568 CXType_SChar = 14,
1569 CXType_WChar = 15,
1570 CXType_Short = 16,
1571 CXType_Int = 17,
1572 CXType_Long = 18,
1573 CXType_LongLong = 19,
1574 CXType_Int128 = 20,
1575 CXType_Float = 21,
1576 CXType_Double = 22,
1577 CXType_LongDouble = 23,
1578 CXType_NullPtr = 24,
1579 CXType_Overload = 25,
1580 CXType_Dependent = 26,
1581 CXType_ObjCId = 27,
1582 CXType_ObjCClass = 28,
1583 CXType_ObjCSel = 29,
1584 CXType_FirstBuiltin = CXType_Void,
1585 CXType_LastBuiltin = CXType_ObjCSel,
1586
1587 CXType_Complex = 100,
1588 CXType_Pointer = 101,
1589 CXType_BlockPointer = 102,
1590 CXType_LValueReference = 103,
1591 CXType_RValueReference = 104,
1592 CXType_Record = 105,
1593 CXType_Enum = 106,
1594 CXType_Typedef = 107,
1595 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001596 CXType_ObjCObjectPointer = 109,
1597 CXType_FunctionNoProto = 110,
1598 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001599};
1600
1601/**
1602 * \brief The type of an element in the abstract syntax tree.
1603 *
1604 */
1605typedef struct {
1606 enum CXTypeKind kind;
1607 void *data[2];
1608} CXType;
1609
1610/**
1611 * \brief Retrieve the type of a CXCursor (if any).
1612 */
1613CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1614
1615/**
1616 * \determine Determine whether two CXTypes represent the same type.
1617 *
1618 * \returns non-zero if the CXTypes represent the same type and
1619 zero otherwise.
1620 */
1621CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1622
1623/**
1624 * \brief Return the canonical type for a CXType.
1625 *
1626 * Clang's type system explicitly models typedefs and all the ways
1627 * a specific type can be represented. The canonical type is the underlying
1628 * type with all the "sugar" removed. For example, if 'T' is a typedef
1629 * for 'int', the canonical type for 'T' would be 'int'.
1630 */
1631CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1632
1633/**
1634 * \brief For pointer types, returns the type of the pointee.
1635 *
1636 */
1637CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1638
1639/**
1640 * \brief Return the cursor for the declaration of the given type.
1641 */
1642CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1643
1644
1645/**
1646 * \brief Retrieve the spelling of a given CXTypeKind.
1647 */
1648CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1649
1650/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001651 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001652 */
1653CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1654
1655/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001656 * \brief Retrieve the result type associated with a given cursor. This only
1657 * returns a valid type of the cursor refers to a function or method.
1658 */
1659CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1660
1661/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001662 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1663 * otherwise.
1664 */
1665CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1666
1667/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001668 * \brief Returns 1 if the base class specified by the cursor with kind
1669 * CX_CXXBaseSpecifier is virtual.
1670 */
1671CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1672
1673/**
1674 * \brief Represents the C++ access control level to a base class for a
1675 * cursor with kind CX_CXXBaseSpecifier.
1676 */
1677enum CX_CXXAccessSpecifier {
1678 CX_CXXInvalidAccessSpecifier,
1679 CX_CXXPublic,
1680 CX_CXXProtected,
1681 CX_CXXPrivate
1682};
1683
1684/**
1685 * \brief Returns the access control level for the C++ base specifier
1686 * represented by a cursor with kind CX_CXXBaseSpecifier.
1687 */
1688CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
1689
1690/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001691 * \brief Determine the number of overloaded declarations referenced by a
1692 * \c CXCursor_OverloadedDeclRef cursor.
1693 *
1694 * \param cursor The cursor whose overloaded declarations are being queried.
1695 *
1696 * \returns The number of overloaded declarations referenced by \c cursor. If it
1697 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
1698 */
1699CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
1700
1701/**
1702 * \brief Retrieve a cursor for one of the overloaded declarations referenced
1703 * by a \c CXCursor_OverloadedDeclRef cursor.
1704 *
1705 * \param cursor The cursor whose overloaded declarations are being queried.
1706 *
1707 * \param index The zero-based index into the set of overloaded declarations in
1708 * the cursor.
1709 *
1710 * \returns A cursor representing the declaration referenced by the given
1711 * \c cursor at the specified \c index. If the cursor does not have an
1712 * associated set of overloaded declarations, or if the index is out of bounds,
1713 * returns \c clang_getNullCursor();
1714 */
1715CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
1716 unsigned index);
1717
1718/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001719 * @}
1720 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001721
1722/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00001723 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00001724 *
1725 * @{
1726 */
1727
1728
1729/**
1730 * \brief For cursors representing an iboutletcollection attribute,
1731 * this function returns the collection element type.
1732 *
1733 */
1734CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
1735
1736/**
1737 * @}
1738 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001739
1740/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001741 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
1742 *
1743 * These routines provide the ability to traverse the abstract syntax tree
1744 * using cursors.
1745 *
1746 * @{
1747 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001748
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001749/**
1750 * \brief Describes how the traversal of the children of a particular
1751 * cursor should proceed after visiting a particular child cursor.
1752 *
1753 * A value of this enumeration type should be returned by each
1754 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
1755 */
1756enum CXChildVisitResult {
1757 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001758 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001759 */
1760 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001761 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001762 * \brief Continues the cursor traversal with the next sibling of
1763 * the cursor just visited, without visiting its children.
1764 */
1765 CXChildVisit_Continue,
1766 /**
1767 * \brief Recursively traverse the children of this cursor, using
1768 * the same visitor and client data.
1769 */
1770 CXChildVisit_Recurse
1771};
1772
1773/**
1774 * \brief Visitor invoked for each cursor found by a traversal.
1775 *
1776 * This visitor function will be invoked for each cursor found by
1777 * clang_visitCursorChildren(). Its first argument is the cursor being
1778 * visited, its second argument is the parent visitor for that cursor,
1779 * and its third argument is the client data provided to
1780 * clang_visitCursorChildren().
1781 *
1782 * The visitor should return one of the \c CXChildVisitResult values
1783 * to direct clang_visitCursorChildren().
1784 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001785typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
1786 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001787 CXClientData client_data);
1788
1789/**
1790 * \brief Visit the children of a particular cursor.
1791 *
1792 * This function visits all the direct children of the given cursor,
1793 * invoking the given \p visitor function with the cursors of each
1794 * visited child. The traversal may be recursive, if the visitor returns
1795 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
1796 * the visitor returns \c CXChildVisit_Break.
1797 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001798 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00001799 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001800 * definition, have no children).
1801 *
1802 * \param visitor the visitor function that will be invoked for each
1803 * child of \p parent.
1804 *
1805 * \param client_data pointer data supplied by the client, which will
1806 * be passed to the visitor each time it is invoked.
1807 *
1808 * \returns a non-zero value if the traversal was terminated
1809 * prematurely by the visitor returning \c CXChildVisit_Break.
1810 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001811CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001812 CXCursorVisitor visitor,
1813 CXClientData client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001814
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001815/**
1816 * @}
1817 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001818
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001819/**
1820 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1821 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001822 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001823 * across translation units, by providing the names of the entities referenced
1824 * by cursors, follow reference cursors to the declarations they reference,
1825 * and associate declarations with their definitions.
1826 *
1827 * @{
1828 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001829
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001830/**
1831 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1832 * by the given cursor.
1833 *
1834 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1835 * entity (function, class, variable, etc.) within a program. USRs can be
1836 * compared across translation units to determine, e.g., when references in
1837 * one translation refer to an entity defined in another translation unit.
1838 */
1839CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1840
1841/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00001842 * \brief Construct a USR for a specified Objective-C class.
1843 */
1844CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
1845
1846/**
1847 * \brief Construct a USR for a specified Objective-C category.
1848 */
1849CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00001850 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001851 const char *category_name);
1852
1853/**
1854 * \brief Construct a USR for a specified Objective-C protocol.
1855 */
1856CINDEX_LINKAGE CXString
1857 clang_constructUSR_ObjCProtocol(const char *protocol_name);
1858
1859
1860/**
1861 * \brief Construct a USR for a specified Objective-C instance variable and
1862 * the USR for its containing class.
1863 */
1864CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
1865 CXString classUSR);
1866
1867/**
1868 * \brief Construct a USR for a specified Objective-C method and
1869 * the USR for its containing class.
1870 */
1871CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
1872 unsigned isInstanceMethod,
1873 CXString classUSR);
1874
1875/**
1876 * \brief Construct a USR for a specified Objective-C property and the USR
1877 * for its containing class.
1878 */
1879CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
1880 CXString classUSR);
1881
1882/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001883 * \brief Retrieve a name for the entity referenced by this cursor.
1884 */
1885CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1886
Douglas Gregor358559d2010-10-02 22:49:11 +00001887/**
1888 * \brief Retrieve the display name for the entity referenced by this cursor.
1889 *
1890 * The display name contains extra information that helps identify the cursor,
1891 * such as the parameters of a function or template or the arguments of a
1892 * class template specialization.
1893 */
1894CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
1895
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001896/** \brief For a cursor that is a reference, retrieve a cursor representing the
1897 * entity that it references.
1898 *
1899 * Reference cursors refer to other entities in the AST. For example, an
1900 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001901 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001902 * cursor for the superclass reference. If the input cursor is a declaration or
1903 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001904 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001905 */
1906CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001907
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001908/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001909 * \brief For a cursor that is either a reference to or a declaration
1910 * of some entity, retrieve a cursor that describes the definition of
1911 * that entity.
1912 *
1913 * Some entities can be declared multiple times within a translation
1914 * unit, but only one of those declarations can also be a
1915 * definition. For example, given:
1916 *
1917 * \code
1918 * int f(int, int);
1919 * int g(int x, int y) { return f(x, y); }
1920 * int f(int a, int b) { return a + b; }
1921 * int f(int, int);
1922 * \endcode
1923 *
1924 * there are three declarations of the function "f", but only the
1925 * second one is a definition. The clang_getCursorDefinition()
1926 * function will take any cursor pointing to a declaration of "f"
1927 * (the first or fourth lines of the example) or a cursor referenced
1928 * that uses "f" (the call to "f' inside "g") and will return a
1929 * declaration cursor pointing to the definition (the second "f"
1930 * declaration).
1931 *
1932 * If given a cursor for which there is no corresponding definition,
1933 * e.g., because there is no definition of that entity within this
1934 * translation unit, returns a NULL cursor.
1935 */
1936CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1937
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001938/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001939 * \brief Determine whether the declaration pointed to by this cursor
1940 * is also a definition of that entity.
1941 */
1942CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1943
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001944/**
1945 * @}
1946 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001947
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001948/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00001949 * \defgroup CINDEX_CPP C++ AST introspection
1950 *
1951 * The routines in this group provide access information in the ASTs specific
1952 * to C++ language features.
1953 *
1954 * @{
1955 */
1956
1957/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00001958 * \brief Determine if a C++ member function or member function template is
1959 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00001960 */
1961CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
1962
1963/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00001964 * \brief Given a cursor that represents a template, determine
1965 * the cursor kind of the specializations would be generated by instantiating
1966 * the template.
1967 *
1968 * This routine can be used to determine what flavor of function template,
1969 * class template, or class template partial specialization is stored in the
1970 * cursor. For example, it can describe whether a class template cursor is
1971 * declared with "struct", "class" or "union".
1972 *
1973 * \param C The cursor to query. This cursor should represent a template
1974 * declaration.
1975 *
1976 * \returns The cursor kind of the specializations that would be generated
1977 * by instantiating the template \p C. If \p C is not a template, returns
1978 * \c CXCursor_NoDeclFound.
1979 */
1980CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
1981
1982/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00001983 * \brief Given a cursor that may represent a specialization or instantiation
1984 * of a template, retrieve the cursor that represents the template that it
1985 * specializes or from which it was instantiated.
1986 *
1987 * This routine determines the template involved both for explicit
1988 * specializations of templates and for implicit instantiations of the template,
1989 * both of which are referred to as "specializations". For a class template
1990 * specialization (e.g., \c std::vector<bool>), this routine will return
1991 * either the primary template (\c std::vector) or, if the specialization was
1992 * instantiated from a class template partial specialization, the class template
1993 * partial specialization. For a class template partial specialization and a
1994 * function template specialization (including instantiations), this
1995 * this routine will return the specialized template.
1996 *
1997 * For members of a class template (e.g., member functions, member classes, or
1998 * static data members), returns the specialized or instantiated member.
1999 * Although not strictly "templates" in the C++ language, members of class
2000 * templates have the same notions of specializations and instantiations that
2001 * templates do, so this routine treats them similarly.
2002 *
2003 * \param C A cursor that may be a specialization of a template or a member
2004 * of a template.
2005 *
2006 * \returns If the given cursor is a specialization or instantiation of a
2007 * template or a member thereof, the template or member that it specializes or
2008 * from which it was instantiated. Otherwise, returns a NULL cursor.
2009 */
2010CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
2011
2012/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002013 * @}
2014 */
2015
2016/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002017 * \defgroup CINDEX_LEX Token extraction and manipulation
2018 *
2019 * The routines in this group provide access to the tokens within a
2020 * translation unit, along with a semantic mapping of those tokens to
2021 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002022 *
2023 * @{
2024 */
2025
2026/**
2027 * \brief Describes a kind of token.
2028 */
2029typedef enum CXTokenKind {
2030 /**
2031 * \brief A token that contains some kind of punctuation.
2032 */
2033 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002034
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002035 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002036 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002037 */
2038 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002039
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002040 /**
2041 * \brief An identifier (that is not a keyword).
2042 */
2043 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002044
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002045 /**
2046 * \brief A numeric, string, or character literal.
2047 */
2048 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002049
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002050 /**
2051 * \brief A comment.
2052 */
2053 CXToken_Comment
2054} CXTokenKind;
2055
2056/**
2057 * \brief Describes a single preprocessing token.
2058 */
2059typedef struct {
2060 unsigned int_data[4];
2061 void *ptr_data;
2062} CXToken;
2063
2064/**
2065 * \brief Determine the kind of the given token.
2066 */
2067CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002068
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002069/**
2070 * \brief Determine the spelling of the given token.
2071 *
2072 * The spelling of a token is the textual representation of that token, e.g.,
2073 * the text of an identifier or keyword.
2074 */
2075CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002076
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002077/**
2078 * \brief Retrieve the source location of the given token.
2079 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002080CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002081 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002082
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002083/**
2084 * \brief Retrieve a source range that covers the given token.
2085 */
2086CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2087
2088/**
2089 * \brief Tokenize the source code described by the given range into raw
2090 * lexical tokens.
2091 *
2092 * \param TU the translation unit whose text is being tokenized.
2093 *
2094 * \param Range the source range in which text should be tokenized. All of the
2095 * tokens produced by tokenization will fall within this source range,
2096 *
2097 * \param Tokens this pointer will be set to point to the array of tokens
2098 * that occur within the given source range. The returned pointer must be
2099 * freed with clang_disposeTokens() before the translation unit is destroyed.
2100 *
2101 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2102 * array.
2103 *
2104 */
2105CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2106 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002107
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002108/**
2109 * \brief Annotate the given set of tokens by providing cursors for each token
2110 * that can be mapped to a specific entity within the abstract syntax tree.
2111 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002112 * This token-annotation routine is equivalent to invoking
2113 * clang_getCursor() for the source locations of each of the
2114 * tokens. The cursors provided are filtered, so that only those
2115 * cursors that have a direct correspondence to the token are
2116 * accepted. For example, given a function call \c f(x),
2117 * clang_getCursor() would provide the following cursors:
2118 *
2119 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2120 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2121 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2122 *
2123 * Only the first and last of these cursors will occur within the
2124 * annotate, since the tokens "f" and "x' directly refer to a function
2125 * and a variable, respectively, but the parentheses are just a small
2126 * part of the full syntax of the function call expression, which is
2127 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002128 *
2129 * \param TU the translation unit that owns the given tokens.
2130 *
2131 * \param Tokens the set of tokens to annotate.
2132 *
2133 * \param NumTokens the number of tokens in \p Tokens.
2134 *
2135 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2136 * replaced with the cursors corresponding to each token.
2137 */
2138CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2139 CXToken *Tokens, unsigned NumTokens,
2140 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002141
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002142/**
2143 * \brief Free the given set of tokens.
2144 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002145CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002146 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002147
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002148/**
2149 * @}
2150 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002151
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002152/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002153 * \defgroup CINDEX_DEBUG Debugging facilities
2154 *
2155 * These routines are used for testing and debugging, only, and should not
2156 * be relied upon.
2157 *
2158 * @{
2159 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002160
Steve Naroff4ade6d62009-09-23 17:52:52 +00002161/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002162CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002163CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2164 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002165 const char **endBuf,
2166 unsigned *startLine,
2167 unsigned *startColumn,
2168 unsigned *endLine,
2169 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002170CINDEX_LINKAGE void clang_enableStackTraces(void);
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002171/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002172 * @}
2173 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002174
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002175/**
2176 * \defgroup CINDEX_CODE_COMPLET Code completion
2177 *
2178 * Code completion involves taking an (incomplete) source file, along with
2179 * knowledge of where the user is actively editing that file, and suggesting
2180 * syntactically- and semantically-valid constructs that the user might want to
2181 * use at that particular point in the source code. These data structures and
2182 * routines provide support for code completion.
2183 *
2184 * @{
2185 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002186
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002187/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002188 * \brief A semantic string that describes a code-completion result.
2189 *
2190 * A semantic string that describes the formatting of a code-completion
2191 * result as a single "template" of text that should be inserted into the
2192 * source buffer when a particular code-completion result is selected.
2193 * Each semantic string is made up of some number of "chunks", each of which
2194 * contains some text along with a description of what that text means, e.g.,
2195 * the name of the entity being referenced, whether the text chunk is part of
2196 * the template, or whether it is a "placeholder" that the user should replace
2197 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002198 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002199 */
2200typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002201
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002202/**
2203 * \brief A single result of code completion.
2204 */
2205typedef struct {
2206 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002207 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002208 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002209 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002210 * *Decl cursor kinds), describing the entity that the completion is
2211 * referring to.
2212 *
2213 * \todo In the future, we would like to provide a full cursor, to allow
2214 * the client to extract additional information from declaration.
2215 */
2216 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002217
2218 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002219 * \brief The code-completion string that describes how to insert this
2220 * code-completion result into the editing buffer.
2221 */
2222 CXCompletionString CompletionString;
2223} CXCompletionResult;
2224
2225/**
2226 * \brief Describes a single piece of text within a code-completion string.
2227 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002228 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2229 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002230 * should be interpreted by the client or is another completion string.
2231 */
2232enum CXCompletionChunkKind {
2233 /**
2234 * \brief A code-completion string that describes "optional" text that
2235 * could be a part of the template (but is not required).
2236 *
2237 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002238 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002239 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2240 * describes an additional part of the template that is completely optional.
2241 * For example, optional chunks can be used to describe the placeholders for
2242 * arguments that match up with defaulted function parameters, e.g. given:
2243 *
2244 * \code
2245 * void f(int x, float y = 3.14, double z = 2.71828);
2246 * \endcode
2247 *
2248 * The code-completion string for this function would contain:
2249 * - a TypedText chunk for "f".
2250 * - a LeftParen chunk for "(".
2251 * - a Placeholder chunk for "int x"
2252 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2253 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002254 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002255 * - an Optional chunk containing the last defaulted argument:
2256 * - a Comma chunk for ","
2257 * - a Placeholder chunk for "double z"
2258 * - a RightParen chunk for ")"
2259 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002260 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002261 * - Completely ignore optional chunks, in which case the template for the
2262 * function "f" would only include the first parameter ("int x").
2263 * - Fully expand all optional chunks, in which case the template for the
2264 * function "f" would have all of the parameters.
2265 */
2266 CXCompletionChunk_Optional,
2267 /**
2268 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002269 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002270 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002271 * There will be exactly one "typed text" chunk in a semantic string, which
2272 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002273 * declaration that could be used at the current code point. Clients are
2274 * expected to filter the code-completion results based on the text in this
2275 * chunk.
2276 */
2277 CXCompletionChunk_TypedText,
2278 /**
2279 * \brief Text that should be inserted as part of a code-completion result.
2280 *
2281 * A "text" chunk represents text that is part of the template to be
2282 * inserted into user code should this particular code-completion result
2283 * be selected.
2284 */
2285 CXCompletionChunk_Text,
2286 /**
2287 * \brief Placeholder text that should be replaced by the user.
2288 *
2289 * A "placeholder" chunk marks a place where the user should insert text
2290 * into the code-completion template. For example, placeholders might mark
2291 * the function parameters for a function declaration, to indicate that the
2292 * user should provide arguments for each of those parameters. The actual
2293 * text in a placeholder is a suggestion for the text to display before
2294 * the user replaces the placeholder with real code.
2295 */
2296 CXCompletionChunk_Placeholder,
2297 /**
2298 * \brief Informative text that should be displayed but never inserted as
2299 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002300 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002301 * An "informative" chunk contains annotations that can be displayed to
2302 * help the user decide whether a particular code-completion result is the
2303 * right option, but which is not part of the actual template to be inserted
2304 * by code completion.
2305 */
2306 CXCompletionChunk_Informative,
2307 /**
2308 * \brief Text that describes the current parameter when code-completion is
2309 * referring to function call, message send, or template specialization.
2310 *
2311 * A "current parameter" chunk occurs when code-completion is providing
2312 * information about a parameter corresponding to the argument at the
2313 * code-completion point. For example, given a function
2314 *
2315 * \code
2316 * int add(int x, int y);
2317 * \endcode
2318 *
2319 * and the source code \c add(, where the code-completion point is after the
2320 * "(", the code-completion string will contain a "current parameter" chunk
2321 * for "int x", indicating that the current argument will initialize that
2322 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002323 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002324 * "current paremeter" chunk to "int y".
2325 */
2326 CXCompletionChunk_CurrentParameter,
2327 /**
2328 * \brief A left parenthesis ('('), used to initiate a function call or
2329 * signal the beginning of a function parameter list.
2330 */
2331 CXCompletionChunk_LeftParen,
2332 /**
2333 * \brief A right parenthesis (')'), used to finish a function call or
2334 * signal the end of a function parameter list.
2335 */
2336 CXCompletionChunk_RightParen,
2337 /**
2338 * \brief A left bracket ('[').
2339 */
2340 CXCompletionChunk_LeftBracket,
2341 /**
2342 * \brief A right bracket (']').
2343 */
2344 CXCompletionChunk_RightBracket,
2345 /**
2346 * \brief A left brace ('{').
2347 */
2348 CXCompletionChunk_LeftBrace,
2349 /**
2350 * \brief A right brace ('}').
2351 */
2352 CXCompletionChunk_RightBrace,
2353 /**
2354 * \brief A left angle bracket ('<').
2355 */
2356 CXCompletionChunk_LeftAngle,
2357 /**
2358 * \brief A right angle bracket ('>').
2359 */
2360 CXCompletionChunk_RightAngle,
2361 /**
2362 * \brief A comma separator (',').
2363 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002364 CXCompletionChunk_Comma,
2365 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002366 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002367 *
2368 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002369 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002370 * expression using the given completion string would have.
2371 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002372 CXCompletionChunk_ResultType,
2373 /**
2374 * \brief A colon (':').
2375 */
2376 CXCompletionChunk_Colon,
2377 /**
2378 * \brief A semicolon (';').
2379 */
2380 CXCompletionChunk_SemiColon,
2381 /**
2382 * \brief An '=' sign.
2383 */
2384 CXCompletionChunk_Equal,
2385 /**
2386 * Horizontal space (' ').
2387 */
2388 CXCompletionChunk_HorizontalSpace,
2389 /**
2390 * Vertical space ('\n'), after which it is generally a good idea to
2391 * perform indentation.
2392 */
2393 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002394};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002395
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002396/**
2397 * \brief Determine the kind of a particular chunk within a completion string.
2398 *
2399 * \param completion_string the completion string to query.
2400 *
2401 * \param chunk_number the 0-based index of the chunk in the completion string.
2402 *
2403 * \returns the kind of the chunk at the index \c chunk_number.
2404 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002405CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002406clang_getCompletionChunkKind(CXCompletionString completion_string,
2407 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002408
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002409/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002410 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002411 * completion string.
2412 *
2413 * \param completion_string the completion string to query.
2414 *
2415 * \param chunk_number the 0-based index of the chunk in the completion string.
2416 *
2417 * \returns the text associated with the chunk at index \c chunk_number.
2418 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002419CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002420clang_getCompletionChunkText(CXCompletionString completion_string,
2421 unsigned chunk_number);
2422
2423/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002424 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002425 * within a completion string.
2426 *
2427 * \param completion_string the completion string to query.
2428 *
2429 * \param chunk_number the 0-based index of the chunk in the completion string.
2430 *
2431 * \returns the completion string associated with the chunk at index
2432 * \c chunk_number, or NULL if that chunk is not represented by a completion
2433 * string.
2434 */
2435CINDEX_LINKAGE CXCompletionString
2436clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2437 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002438
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002439/**
2440 * \brief Retrieve the number of chunks in the given code-completion string.
2441 */
2442CINDEX_LINKAGE unsigned
2443clang_getNumCompletionChunks(CXCompletionString completion_string);
2444
2445/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002446 * \brief Determine the priority of this code completion.
2447 *
2448 * The priority of a code completion indicates how likely it is that this
2449 * particular completion is the completion that the user will select. The
2450 * priority is selected by various internal heuristics.
2451 *
2452 * \param completion_string The completion string to query.
2453 *
2454 * \returns The priority of this completion string. Smaller values indicate
2455 * higher-priority (more likely) completions.
2456 */
2457CINDEX_LINKAGE unsigned
2458clang_getCompletionPriority(CXCompletionString completion_string);
2459
2460/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002461 * \brief Determine the availability of the entity that this code-completion
2462 * string refers to.
2463 *
2464 * \param completion_string The completion string to query.
2465 *
2466 * \returns The availability of the completion string.
2467 */
2468CINDEX_LINKAGE enum CXAvailabilityKind
2469clang_getCompletionAvailability(CXCompletionString completion_string);
2470
2471/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002472 * \brief Contains the results of code-completion.
2473 *
2474 * This data structure contains the results of code completion, as
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002475 * produced by \c clang_codeComplete. Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002476 * \c clang_disposeCodeCompleteResults.
2477 */
2478typedef struct {
2479 /**
2480 * \brief The code-completion results.
2481 */
2482 CXCompletionResult *Results;
2483
2484 /**
2485 * \brief The number of code-completion results stored in the
2486 * \c Results array.
2487 */
2488 unsigned NumResults;
2489} CXCodeCompleteResults;
2490
2491/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002492 * \brief Perform code completion at a given location in a source file.
2493 *
2494 * This function performs code completion at a particular file, line, and
2495 * column within source code, providing results that suggest potential
2496 * code snippets based on the context of the completion. The basic model
2497 * for code completion is that Clang will parse a complete source file,
2498 * performing syntax checking up to the location where code-completion has
2499 * been requested. At that point, a special code-completion token is passed
2500 * to the parser, which recognizes this token and determines, based on the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002501 * current location in the C/Objective-C/C++ grammar and the state of
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002502 * semantic analysis, what completions to provide. These completions are
Douglas Gregorec6762c2009-12-18 16:20:58 +00002503 * returned via a new \c CXCodeCompleteResults structure.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002504 *
2505 * Code completion itself is meant to be triggered by the client when the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002506 * user types punctuation characters or whitespace, at which point the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002507 * code-completion location will coincide with the cursor. For example, if \c p
2508 * is a pointer, code-completion might be triggered after the "-" and then
2509 * after the ">" in \c p->. When the code-completion location is afer the ">",
2510 * the completion results will provide, e.g., the members of the struct that
2511 * "p" points to. The client is responsible for placing the cursor at the
2512 * beginning of the token currently being typed, then filtering the results
2513 * based on the contents of the token. For example, when code-completing for
2514 * the expression \c p->get, the client should provide the location just after
2515 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
2516 * client can filter the results based on the current token text ("get"), only
2517 * showing those results that start with "get". The intent of this interface
Douglas Gregorec6762c2009-12-18 16:20:58 +00002518 * is to separate the relatively high-latency acquisition of code-completion
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002519 * results from the filtering of results on a per-character basis, which must
2520 * have a lower latency.
2521 *
2522 * \param CIdx the \c CXIndex instance that will be used to perform code
2523 * completion.
2524 *
Daniel Dunbar8506dde2009-12-03 01:54:28 +00002525 * \param source_filename the name of the source file that should be parsed to
2526 * perform code-completion. This source file must be the same as or include the
2527 * filename described by \p complete_filename, or no code-completion results
2528 * will be produced. NOTE: One can also specify NULL for this argument if the
2529 * source file is included in command_line_args.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002530 *
2531 * \param num_command_line_args the number of command-line arguments stored in
2532 * \p command_line_args.
2533 *
2534 * \param command_line_args the command-line arguments to pass to the Clang
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002535 * compiler to build the given source file. This should include all of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002536 * necessary include paths, language-dialect switches, precompiled header
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002537 * includes, etc., but should not include any information specific to
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002538 * code completion.
2539 *
Douglas Gregor735df882009-12-02 09:21:34 +00002540 * \param num_unsaved_files the number of unsaved file entries in \p
2541 * unsaved_files.
2542 *
2543 * \param unsaved_files the files that have not yet been saved to disk
2544 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +00002545 * those files. The contents and name of these files (as specified by
2546 * CXUnsavedFile) are copied when necessary, so the client only needs to
2547 * guarantee their validity until the call to this function returns.
Douglas Gregor735df882009-12-02 09:21:34 +00002548 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002549 * \param complete_filename the name of the source file where code completion
2550 * should be performed. In many cases, this name will be the same as the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002551 * source filename. However, the completion filename may also be a file
2552 * included by the source file, which is required when producing
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002553 * code-completion results for a header.
2554 *
2555 * \param complete_line the line at which code-completion should occur.
2556 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002557 * \param complete_column the column at which code-completion should occur.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002558 * Note that the column should point just after the syntactic construct that
2559 * initiated code completion, and not in the middle of a lexical token.
2560 *
Douglas Gregor936ea3b2010-01-28 00:56:43 +00002561 * \param diag_callback callback function that will receive any diagnostics
2562 * emitted while processing this source file. If NULL, diagnostics will be
2563 * suppressed.
2564 *
2565 * \param diag_client_data client data that will be passed to the diagnostic
2566 * callback function.
2567 *
Douglas Gregorec6762c2009-12-18 16:20:58 +00002568 * \returns if successful, a new CXCodeCompleteResults structure
2569 * containing code-completion results, which should eventually be
2570 * freed with \c clang_disposeCodeCompleteResults(). If code
2571 * completion fails, returns NULL.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002572 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002573CINDEX_LINKAGE
2574CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
Douglas Gregorec6762c2009-12-18 16:20:58 +00002575 const char *source_filename,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002576 int num_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +00002577 const char * const *command_line_args,
Douglas Gregorec6762c2009-12-18 16:20:58 +00002578 unsigned num_unsaved_files,
2579 struct CXUnsavedFile *unsaved_files,
2580 const char *complete_filename,
2581 unsigned complete_line,
Douglas Gregora88084b2010-02-18 18:08:43 +00002582 unsigned complete_column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002583
Douglas Gregorec6762c2009-12-18 16:20:58 +00002584/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002585 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2586 * modify its behavior.
2587 *
2588 * The enumerators in this enumeration can be bitwise-OR'd together to
2589 * provide multiple options to \c clang_codeCompleteAt().
2590 */
2591enum CXCodeComplete_Flags {
2592 /**
2593 * \brief Whether to include macros within the set of code
2594 * completions returned.
2595 */
2596 CXCodeComplete_IncludeMacros = 0x01,
2597
2598 /**
2599 * \brief Whether to include code patterns for language constructs
2600 * within the set of code completions, e.g., for loops.
2601 */
2602 CXCodeComplete_IncludeCodePatterns = 0x02
2603};
2604
2605/**
2606 * \brief Returns a default set of code-completion options that can be
2607 * passed to\c clang_codeCompleteAt().
2608 */
2609CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
2610
2611/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002612 * \brief Perform code completion at a given location in a translation unit.
2613 *
2614 * This function performs code completion at a particular file, line, and
2615 * column within source code, providing results that suggest potential
2616 * code snippets based on the context of the completion. The basic model
2617 * for code completion is that Clang will parse a complete source file,
2618 * performing syntax checking up to the location where code-completion has
2619 * been requested. At that point, a special code-completion token is passed
2620 * to the parser, which recognizes this token and determines, based on the
2621 * current location in the C/Objective-C/C++ grammar and the state of
2622 * semantic analysis, what completions to provide. These completions are
2623 * returned via a new \c CXCodeCompleteResults structure.
2624 *
2625 * Code completion itself is meant to be triggered by the client when the
2626 * user types punctuation characters or whitespace, at which point the
2627 * code-completion location will coincide with the cursor. For example, if \c p
2628 * is a pointer, code-completion might be triggered after the "-" and then
2629 * after the ">" in \c p->. When the code-completion location is afer the ">",
2630 * the completion results will provide, e.g., the members of the struct that
2631 * "p" points to. The client is responsible for placing the cursor at the
2632 * beginning of the token currently being typed, then filtering the results
2633 * based on the contents of the token. For example, when code-completing for
2634 * the expression \c p->get, the client should provide the location just after
2635 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
2636 * client can filter the results based on the current token text ("get"), only
2637 * showing those results that start with "get". The intent of this interface
2638 * is to separate the relatively high-latency acquisition of code-completion
2639 * results from the filtering of results on a per-character basis, which must
2640 * have a lower latency.
2641 *
2642 * \param TU The translation unit in which code-completion should
2643 * occur. The source files for this translation unit need not be
2644 * completely up-to-date (and the contents of those source files may
2645 * be overridden via \p unsaved_files). Cursors referring into the
2646 * translation unit may be invalidated by this invocation.
2647 *
2648 * \param complete_filename The name of the source file where code
2649 * completion should be performed. This filename may be any file
2650 * included in the translation unit.
2651 *
2652 * \param complete_line The line at which code-completion should occur.
2653 *
2654 * \param complete_column The column at which code-completion should occur.
2655 * Note that the column should point just after the syntactic construct that
2656 * initiated code completion, and not in the middle of a lexical token.
2657 *
2658 * \param unsaved_files the Tiles that have not yet been saved to disk
2659 * but may be required for parsing or code completion, including the
2660 * contents of those files. The contents and name of these files (as
2661 * specified by CXUnsavedFile) are copied when necessary, so the
2662 * client only needs to guarantee their validity until the call to
2663 * this function returns.
2664 *
2665 * \param num_unsaved_files The number of unsaved file entries in \p
2666 * unsaved_files.
2667 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00002668 * \param options Extra options that control the behavior of code
2669 * completion, expressed as a bitwise OR of the enumerators of the
2670 * CXCodeComplete_Flags enumeration. The
2671 * \c clang_defaultCodeCompleteOptions() function returns a default set
2672 * of code-completion options.
2673 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002674 * \returns If successful, a new \c CXCodeCompleteResults structure
2675 * containing code-completion results, which should eventually be
2676 * freed with \c clang_disposeCodeCompleteResults(). If code
2677 * completion fails, returns NULL.
2678 */
2679CINDEX_LINKAGE
2680CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
2681 const char *complete_filename,
2682 unsigned complete_line,
2683 unsigned complete_column,
2684 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00002685 unsigned num_unsaved_files,
2686 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002687
2688/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00002689 * \brief Sort the code-completion results in case-insensitive alphabetical
2690 * order.
2691 *
2692 * \param Results The set of results to sort.
2693 * \param NumResults The number of results in \p Results.
2694 */
2695CINDEX_LINKAGE
2696void clang_sortCodeCompletionResults(CXCompletionResult *Results,
2697 unsigned NumResults);
2698
2699/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002700 * \brief Free the given set of code-completion results.
2701 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002702CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00002703void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00002704
Douglas Gregor20d416c2010-01-20 01:10:47 +00002705/**
Douglas Gregora88084b2010-02-18 18:08:43 +00002706 * \brief Determine the number of diagnostics produced prior to the
2707 * location where code completion was performed.
2708 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002709CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002710unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
2711
2712/**
2713 * \brief Retrieve a diagnostic associated with the given code completion.
2714 *
2715 * \param Result the code completion results to query.
2716 * \param Index the zero-based diagnostic number to retrieve.
2717 *
2718 * \returns the requested diagnostic. This diagnostic must be freed
2719 * via a call to \c clang_disposeDiagnostic().
2720 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002721CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002722CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
2723 unsigned Index);
2724
2725/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00002726 * @}
2727 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002728
2729
Ted Kremenek04bb7162010-01-22 22:44:15 +00002730/**
2731 * \defgroup CINDEX_MISC Miscellaneous utility functions
2732 *
2733 * @{
2734 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00002735
2736/**
2737 * \brief Return a version string, suitable for showing to a user, but not
2738 * intended to be parsed (the format is not guaranteed to be stable).
2739 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00002740CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00002741
2742/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00002743 * \brief Return a version string, suitable for showing to a user, but not
2744 * intended to be parsed (the format is not guaranteed to be stable).
2745 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002746
2747
Ted Kremenek16b55a72010-01-26 19:31:51 +00002748 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002749 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00002750 * (used with clang_getInclusions()).
2751 *
2752 * This visitor function will be invoked by clang_getInclusions() for each
2753 * file included (either at the top-level or by #include directives) within
2754 * a translation unit. The first argument is the file being included, and
2755 * the second and third arguments provide the inclusion stack. The
2756 * array is sorted in order of immediate inclusion. For example,
2757 * the first element refers to the location that included 'included_file'.
2758 */
2759typedef void (*CXInclusionVisitor)(CXFile included_file,
2760 CXSourceLocation* inclusion_stack,
2761 unsigned include_len,
2762 CXClientData client_data);
2763
2764/**
2765 * \brief Visit the set of preprocessor inclusions in a translation unit.
2766 * The visitor function is called with the provided data for every included
2767 * file. This does not include headers included by the PCH file (unless one
2768 * is inspecting the inclusions in the PCH file itself).
2769 */
2770CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
2771 CXInclusionVisitor visitor,
2772 CXClientData client_data);
2773
2774/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00002775 * @}
2776 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002777
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002778/**
2779 * @}
2780 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002781
Ted Kremenekd2fa5662009-08-26 22:36:44 +00002782#ifdef __cplusplus
2783}
2784#endif
2785#endif
2786