blob: 0ce57723697b21df0f46fbdaa7343a4dfb1da6ad [file] [log] [blame]
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
Steve Naroff88145032009-10-27 14:35:18 +000019#include <sys/stat.h>
Chandler Carruth3d315602009-12-17 09:27:29 +000020#include <time.h>
Douglas Gregor0a812cf2010-02-18 23:07:20 +000021#include <stdio.h>
Steve Naroff88145032009-10-27 14:35:18 +000022
Ted Kremenekd2fa5662009-08-26 22:36:44 +000023#ifdef __cplusplus
24extern "C" {
25#endif
26
Steve Naroff88145032009-10-27 14:35:18 +000027/* MSVC DLL import/export. */
John Thompson2e06fc82009-10-27 13:42:56 +000028#ifdef _MSC_VER
29 #ifdef _CINDEX_LIB_
30 #define CINDEX_LINKAGE __declspec(dllexport)
31 #else
32 #define CINDEX_LINKAGE __declspec(dllimport)
33 #endif
34#else
35 #define CINDEX_LINKAGE
36#endif
37
Douglas Gregor87fb9402011-02-23 17:45:25 +000038/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000039 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000040 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000041 * facilities for parsing source code into an abstract syntax tree (AST),
42 * loading already-parsed ASTs, traversing the AST, associating
43 * physical source locations with elements within the AST, and other
44 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000045 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000046 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000047 * representation stored in Clang's C++ AST, nor should it: the intent is to
48 * maintain an API that is relatively stable from one release to the next,
49 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000050 *
51 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000052 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000053 *
54 * @{
55 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000056
Douglas Gregor7f173762010-01-20 22:28:27 +000057/**
58 * \brief An "index" that consists of a set of translation units that would
59 * typically be linked together into an executable or library.
60 */
61typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000062
Douglas Gregor7f173762010-01-20 22:28:27 +000063/**
64 * \brief A single translation unit, which resides in an index.
65 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000066typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000067
Douglas Gregor7f173762010-01-20 22:28:27 +000068/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000069 * \brief Opaque pointer representing client data that will be passed through
70 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000071 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000072typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000073
Douglas Gregor735df882009-12-02 09:21:34 +000074/**
75 * \brief Provides the contents of a file that has not yet been saved to disk.
76 *
77 * Each CXUnsavedFile instance provides the name of a file on the
78 * system along with the current contents of that file that have not
79 * yet been saved to disk.
80 */
81struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000082 /**
83 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000084 *
85 * This file must already exist in the file system.
86 */
87 const char *Filename;
88
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000089 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000090 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +000091 */
92 const char *Contents;
93
94 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000095 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +000096 */
97 unsigned long Length;
98};
99
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000100/**
101 * \brief Describes the availability of a particular entity, which indicates
102 * whether the use of this entity will result in a warning or error due to
103 * it being deprecated or unavailable.
104 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000105enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000106 /**
107 * \brief The entity is available.
108 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000109 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000110 /**
111 * \brief The entity is available, but has been deprecated (and its use is
112 * not recommended).
113 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000114 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000115 /**
116 * \brief The entity is not available; any use of it will be an error.
117 */
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 {
Ted Kremeneka60ed472010-11-16 08:15:36 +0000136 void *data;
Ted Kremeneked122732010-11-16 01:56:27 +0000137 unsigned private_flags;
Steve Naroffef0cef62009-11-09 17:45:52 +0000138} CXString;
139
Douglas Gregor7f173762010-01-20 22:28:27 +0000140/**
141 * \brief Retrieve the character data associated with the given string.
142 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000143CINDEX_LINKAGE const char *clang_getCString(CXString string);
144
Douglas Gregor7f173762010-01-20 22:28:27 +0000145/**
146 * \brief Free the given string,
147 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000148CINDEX_LINKAGE void clang_disposeString(CXString string);
149
Douglas Gregor7f173762010-01-20 22:28:27 +0000150/**
151 * @}
152 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000153
154/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000155 * \brief clang_createIndex() provides a shared context for creating
156 * translation units. It provides two options:
157 *
158 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
159 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000160 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000161 * header that was used by the translation unit. If zero, all declarations
162 * will be enumerated.
163 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000164 * Here is an example:
165 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000166 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
167 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000168 *
169 * // IndexTest.pch was produced with the following command:
170 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
171 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
172 *
173 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000174 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000175 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000176 * clang_disposeTranslationUnit(TU);
177 *
178 * // This will load all the symbols from 'IndexTest.c', excluding symbols
179 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000180 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
181 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
182 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000183 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
184 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000185 * clang_disposeTranslationUnit(TU);
186 *
187 * This process of creating the 'pch', loading it separately, and using it (via
188 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
189 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000190 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000191CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
192 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000193
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000194/**
195 * \brief Destroy the given index.
196 *
197 * The index must not be destroyed until all of the translation units created
198 * within that index have been destroyed.
199 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000200CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000201
202/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000203 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000204 *
205 * @{
206 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000207
Douglas Gregorf5525442010-01-20 22:45:41 +0000208/**
209 * \brief A particular source file that is part of a translation unit.
210 */
211typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000212
Douglas Gregorf5525442010-01-20 22:45:41 +0000213
214/**
215 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000216 */
Ted Kremenek74844072010-02-17 00:41:20 +0000217CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000218
Douglas Gregorf5525442010-01-20 22:45:41 +0000219/**
220 * \brief Retrieve the last modification time of the given file.
221 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000222CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000223
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000224/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000225 * \brief Retrieve a file handle within the given translation unit.
226 *
227 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000228 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000229 * \param file_name the name of the file.
230 *
231 * \returns the file handle for the named file in the translation unit \p tu,
232 * or a NULL file handle if the file was not a part of this translation unit.
233 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000234CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000235 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000236
Douglas Gregorb9790342010-01-22 21:44:22 +0000237/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000238 * @}
239 */
240
241/**
242 * \defgroup CINDEX_LOCATIONS Physical source locations
243 *
244 * Clang represents physical source locations in its abstract syntax tree in
245 * great detail, with file, line, and column information for the majority of
246 * the tokens parsed in the source code. These data types and functions are
247 * used to represent source location information, either for a particular
248 * point in the program or for a range of points in the program, and extract
249 * specific location information from those data types.
250 *
251 * @{
252 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000253
Douglas Gregorf5525442010-01-20 22:45:41 +0000254/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000255 * \brief Identifies a specific source location within a translation
256 * unit.
257 *
Douglas Gregora9b06d42010-11-09 06:24:54 +0000258 * Use clang_getInstantiationLocation() or clang_getSpellingLocation()
259 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000260 */
261typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000262 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000263 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000264} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000265
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000266/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000267 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000268 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000269 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
270 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000271 */
272typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000273 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000274 unsigned begin_int_data;
275 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000276} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000277
Douglas Gregor1db19de2010-01-19 21:36:55 +0000278/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000279 * \brief Retrieve a NULL (invalid) source location.
280 */
281CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000282
Douglas Gregorb9790342010-01-22 21:44:22 +0000283/**
284 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000285 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000286 * code.
287 *
288 * \returns non-zero if the source locations refer to the same location, zero
289 * if they refer to different locations.
290 */
291CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
292 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000293
Douglas Gregorb9790342010-01-22 21:44:22 +0000294/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000295 * \brief Retrieves the source location associated with a given file/line/column
296 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000297 */
298CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
299 CXFile file,
300 unsigned line,
301 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000302/**
303 * \brief Retrieves the source location associated with a given character offset
304 * in a particular translation unit.
305 */
306CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
307 CXFile file,
308 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000309
Douglas Gregorb9790342010-01-22 21:44:22 +0000310/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000311 * \brief Retrieve a NULL (invalid) source range.
312 */
313CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000314
Douglas Gregor5352ac02010-01-28 00:27:43 +0000315/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000316 * \brief Retrieve a source range given the beginning and ending source
317 * locations.
318 */
319CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
320 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000321
Douglas Gregorb9790342010-01-22 21:44:22 +0000322/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000323 * \brief Retrieve the file, line, column, and offset represented by
324 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000325 *
Douglas Gregora9b06d42010-11-09 06:24:54 +0000326 * If the location refers into a macro instantiation, retrieves the
327 * location of the macro instantiation.
328 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000329 * \param location the location within a source file that will be decomposed
330 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000331 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000332 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000333 * source location points.
334 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000335 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000336 * source location points.
337 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000338 * \param column [out] if non-NULL, will be set to the column to which the given
339 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000340 *
341 * \param offset [out] if non-NULL, will be set to the offset into the
342 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000343 */
344CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
345 CXFile *file,
346 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000347 unsigned *column,
348 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000349
350/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000351 * \brief Retrieve the file, line, column, and offset represented by
352 * the given source location.
353 *
354 * If the location refers into a macro instantiation, return where the
355 * location was originally spelled in the source file.
356 *
357 * \param location the location within a source file that will be decomposed
358 * into its parts.
359 *
360 * \param file [out] if non-NULL, will be set to the file to which the given
361 * source location points.
362 *
363 * \param line [out] if non-NULL, will be set to the line to which the given
364 * source location points.
365 *
366 * \param column [out] if non-NULL, will be set to the column to which the given
367 * source location points.
368 *
369 * \param offset [out] if non-NULL, will be set to the offset into the
370 * buffer to which the given source location points.
371 */
372CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
373 CXFile *file,
374 unsigned *line,
375 unsigned *column,
376 unsigned *offset);
377
378/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000379 * \brief Retrieve a source location representing the first character within a
380 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000381 */
382CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
383
384/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000385 * \brief Retrieve a source location representing the last character within a
386 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000387 */
388CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
389
Douglas Gregorf5525442010-01-20 22:45:41 +0000390/**
391 * @}
392 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000393
394/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000395 * \defgroup CINDEX_DIAG Diagnostic reporting
396 *
397 * @{
398 */
399
400/**
401 * \brief Describes the severity of a particular diagnostic.
402 */
403enum CXDiagnosticSeverity {
404 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000405 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000406 * option.
407 */
408 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000409
Douglas Gregor5352ac02010-01-28 00:27:43 +0000410 /**
411 * \brief This diagnostic is a note that should be attached to the
412 * previous (non-note) diagnostic.
413 */
414 CXDiagnostic_Note = 1,
415
416 /**
417 * \brief This diagnostic indicates suspicious code that may not be
418 * wrong.
419 */
420 CXDiagnostic_Warning = 2,
421
422 /**
423 * \brief This diagnostic indicates that the code is ill-formed.
424 */
425 CXDiagnostic_Error = 3,
426
427 /**
428 * \brief This diagnostic indicates that the code is ill-formed such
429 * that future parser recovery is unlikely to produce useful
430 * results.
431 */
432 CXDiagnostic_Fatal = 4
433};
434
435/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000436 * \brief A single diagnostic, containing the diagnostic's severity,
437 * location, text, source ranges, and fix-it hints.
438 */
439typedef void *CXDiagnostic;
440
441/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000442 * \brief Determine the number of diagnostics produced for the given
443 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000444 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000445CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
446
447/**
448 * \brief Retrieve a diagnostic associated with the given translation unit.
449 *
450 * \param Unit the translation unit to query.
451 * \param Index the zero-based diagnostic number to retrieve.
452 *
453 * \returns the requested diagnostic. This diagnostic must be freed
454 * via a call to \c clang_disposeDiagnostic().
455 */
456CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
457 unsigned Index);
458
459/**
460 * \brief Destroy a diagnostic.
461 */
462CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000463
464/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000465 * \brief Options to control the display of diagnostics.
466 *
467 * The values in this enum are meant to be combined to customize the
468 * behavior of \c clang_displayDiagnostic().
469 */
470enum CXDiagnosticDisplayOptions {
471 /**
472 * \brief Display the source-location information where the
473 * diagnostic was located.
474 *
475 * When set, diagnostics will be prefixed by the file, line, and
476 * (optionally) column to which the diagnostic refers. For example,
477 *
478 * \code
479 * test.c:28: warning: extra tokens at end of #endif directive
480 * \endcode
481 *
482 * This option corresponds to the clang flag \c -fshow-source-location.
483 */
484 CXDiagnostic_DisplaySourceLocation = 0x01,
485
486 /**
487 * \brief If displaying the source-location information of the
488 * diagnostic, also include the column number.
489 *
490 * This option corresponds to the clang flag \c -fshow-column.
491 */
492 CXDiagnostic_DisplayColumn = 0x02,
493
494 /**
495 * \brief If displaying the source-location information of the
496 * diagnostic, also include information about source ranges in a
497 * machine-parsable format.
498 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000499 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000500 * \c -fdiagnostics-print-source-range-info.
501 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000502 CXDiagnostic_DisplaySourceRanges = 0x04,
503
504 /**
505 * \brief Display the option name associated with this diagnostic, if any.
506 *
507 * The option name displayed (e.g., -Wconversion) will be placed in brackets
508 * after the diagnostic text. This option corresponds to the clang flag
509 * \c -fdiagnostics-show-option.
510 */
511 CXDiagnostic_DisplayOption = 0x08,
512
513 /**
514 * \brief Display the category number associated with this diagnostic, if any.
515 *
516 * The category number is displayed within brackets after the diagnostic text.
517 * This option corresponds to the clang flag
518 * \c -fdiagnostics-show-category=id.
519 */
520 CXDiagnostic_DisplayCategoryId = 0x10,
521
522 /**
523 * \brief Display the category name associated with this diagnostic, if any.
524 *
525 * The category name is displayed within brackets after the diagnostic text.
526 * This option corresponds to the clang flag
527 * \c -fdiagnostics-show-category=name.
528 */
529 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000530};
531
532/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000533 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000534 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000535 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000536 * the diagnostic according to the various options given. The
537 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000538 * options that most closely mimics the behavior of the clang compiler.
539 *
540 * \param Diagnostic The diagnostic to print.
541 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000542 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000543 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000544 *
545 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000546 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000547CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
548 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000549
550/**
551 * \brief Retrieve the set of display options most similar to the
552 * default behavior of the clang compiler.
553 *
554 * \returns A set of display options suitable for use with \c
555 * clang_displayDiagnostic().
556 */
557CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
558
559/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000560 * \brief Determine the severity of the given diagnostic.
561 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000562CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000563clang_getDiagnosticSeverity(CXDiagnostic);
564
565/**
566 * \brief Retrieve the source location of the given diagnostic.
567 *
568 * This location is where Clang would print the caret ('^') when
569 * displaying the diagnostic on the command line.
570 */
571CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
572
573/**
574 * \brief Retrieve the text of the given diagnostic.
575 */
576CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000577
578/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000579 * \brief Retrieve the name of the command-line option that enabled this
580 * diagnostic.
581 *
582 * \param Diag The diagnostic to be queried.
583 *
584 * \param Disable If non-NULL, will be set to the option that disables this
585 * diagnostic (if any).
586 *
587 * \returns A string that contains the command-line option used to enable this
588 * warning, such as "-Wconversion" or "-pedantic".
589 */
590CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
591 CXString *Disable);
592
593/**
594 * \brief Retrieve the category number for this diagnostic.
595 *
596 * Diagnostics can be categorized into groups along with other, related
597 * diagnostics (e.g., diagnostics under the same warning flag). This routine
598 * retrieves the category number for the given diagnostic.
599 *
600 * \returns The number of the category that contains this diagnostic, or zero
601 * if this diagnostic is uncategorized.
602 */
603CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
604
605/**
606 * \brief Retrieve the name of a particular diagnostic category.
607 *
608 * \param Category A diagnostic category number, as returned by
609 * \c clang_getDiagnosticCategory().
610 *
611 * \returns The name of the given diagnostic category.
612 */
613CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
614
615/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000616 * \brief Determine the number of source ranges associated with the given
617 * diagnostic.
618 */
619CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000620
Douglas Gregor5352ac02010-01-28 00:27:43 +0000621/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000622 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000623 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000624 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000625 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000626 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000627 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000628 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000629 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000630 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000631 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000632 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000633 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000634CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000635 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000636
637/**
638 * \brief Determine the number of fix-it hints associated with the
639 * given diagnostic.
640 */
641CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
642
643/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000644 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000645 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000646 * Fix-its are described in terms of a source range whose contents
647 * should be replaced by a string. This approach generalizes over
648 * three kinds of operations: removal of source code (the range covers
649 * the code to be removed and the replacement string is empty),
650 * replacement of source code (the range covers the code to be
651 * replaced and the replacement string provides the new code), and
652 * insertion (both the start and end of the range point at the
653 * insertion location, and the replacement string provides the text to
654 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000655 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000656 * \param Diagnostic The diagnostic whose fix-its are being queried.
657 *
658 * \param FixIt The zero-based index of the fix-it.
659 *
660 * \param ReplacementRange The source range whose contents will be
661 * replaced with the returned replacement string. Note that source
662 * ranges are half-open ranges [a, b), so the source code should be
663 * replaced from a and up to (but not including) b.
664 *
665 * \returns A string containing text that should be replace the source
666 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000667 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000668CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000669 unsigned FixIt,
670 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000671
672/**
673 * @}
674 */
675
676/**
677 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
678 *
679 * The routines in this group provide the ability to create and destroy
680 * translation units from files, either by parsing the contents of the files or
681 * by reading in a serialized representation of a translation unit.
682 *
683 * @{
684 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000685
Douglas Gregor5352ac02010-01-28 00:27:43 +0000686/**
687 * \brief Get the original translation unit source file name.
688 */
689CINDEX_LINKAGE CXString
690clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
691
692/**
693 * \brief Return the CXTranslationUnit for a given source file and the provided
694 * command line arguments one would pass to the compiler.
695 *
696 * Note: The 'source_filename' argument is optional. If the caller provides a
697 * NULL pointer, the name of the source file is expected to reside in the
698 * specified command line arguments.
699 *
700 * Note: When encountered in 'clang_command_line_args', the following options
701 * are ignored:
702 *
703 * '-c'
704 * '-emit-ast'
705 * '-fsyntax-only'
706 * '-o <output file>' (both '-o' and '<output file>' are ignored)
707 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000708 * \param CIdx The index object with which the translation unit will be
709 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000710 *
711 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000712 * source file is included in \p clang_command_line_args.
713 *
714 * \param num_clang_command_line_args The number of command-line arguments in
715 * \p clang_command_line_args.
716 *
717 * \param clang_command_line_args The command-line arguments that would be
718 * passed to the \c clang executable if it were being invoked out-of-process.
719 * These command-line options will be parsed and will affect how the translation
720 * unit is parsed. Note that the following options are ignored: '-c',
721 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000722 *
723 * \param num_unsaved_files the number of unsaved file entries in \p
724 * unsaved_files.
725 *
726 * \param unsaved_files the files that have not yet been saved to disk
727 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000728 * those files. The contents and name of these files (as specified by
729 * CXUnsavedFile) are copied when necessary, so the client only needs to
730 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000731 */
732CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
733 CXIndex CIdx,
734 const char *source_filename,
735 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000736 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000737 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000738 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000739
Douglas Gregor5352ac02010-01-28 00:27:43 +0000740/**
741 * \brief Create a translation unit from an AST file (-emit-ast).
742 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000743CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000744 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000745
Douglas Gregor44c181a2010-07-23 00:33:23 +0000746/**
747 * \brief Flags that control the creation of translation units.
748 *
749 * The enumerators in this enumeration type are meant to be bitwise
750 * ORed together to specify which options should be used when
751 * constructing the translation unit.
752 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000753enum CXTranslationUnit_Flags {
754 /**
755 * \brief Used to indicate that no special translation-unit options are
756 * needed.
757 */
758 CXTranslationUnit_None = 0x0,
759
760 /**
761 * \brief Used to indicate that the parser should construct a "detailed"
762 * preprocessing record, including all macro definitions and instantiations.
763 *
764 * Constructing a detailed preprocessing record requires more memory
765 * and time to parse, since the information contained in the record
766 * is usually not retained. However, it can be useful for
767 * applications that require more detailed information about the
768 * behavior of the preprocessor.
769 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000770 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
771
772 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000773 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000774 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000775 * When a translation unit is considered "incomplete", semantic
776 * analysis that is typically performed at the end of the
777 * translation unit will be suppressed. For example, this suppresses
778 * the completion of tentative declarations in C and of
779 * instantiation of implicitly-instantiation function templates in
780 * C++. This option is typically used when parsing a header with the
781 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000782 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000783 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000784
785 /**
786 * \brief Used to indicate that the translation unit should be built with an
787 * implicit precompiled header for the preamble.
788 *
789 * An implicit precompiled header is used as an optimization when a
790 * particular translation unit is likely to be reparsed many times
791 * when the sources aren't changing that often. In this case, an
792 * implicit precompiled header will be built containing all of the
793 * initial includes at the top of the main file (what we refer to as
794 * the "preamble" of the file). In subsequent parses, if the
795 * preamble or the files in it have not changed, \c
796 * clang_reparseTranslationUnit() will re-use the implicit
797 * precompiled header to improve parsing performance.
798 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000799 CXTranslationUnit_PrecompiledPreamble = 0x04,
800
801 /**
802 * \brief Used to indicate that the translation unit should cache some
803 * code-completion results with each reparse of the source file.
804 *
805 * Caching of code-completion results is a performance optimization that
806 * introduces some overhead to reparsing but improves the performance of
807 * code-completion operations.
808 */
Douglas Gregor99ba2022010-10-27 17:24:53 +0000809 CXTranslationUnit_CacheCompletionResults = 0x08,
810 /**
811 * \brief Enable precompiled preambles in C++.
812 *
813 * Note: this is a *temporary* option that is available only while
814 * we are testing C++ precompiled preamble support.
815 */
816 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
817
818 /**
819 * \brief Enabled chained precompiled preambles in C++.
820 *
821 * Note: this is a *temporary* option that is available only while
822 * we are testing C++ precompiled preamble support.
823 */
824 CXTranslationUnit_CXXChainedPCH = 0x20
Douglas Gregor5a430212010-07-21 18:52:53 +0000825};
826
827/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000828 * \brief Returns the set of flags that is suitable for parsing a translation
829 * unit that is being edited.
830 *
831 * The set of flags returned provide options for \c clang_parseTranslationUnit()
832 * to indicate that the translation unit is likely to be reparsed many times,
833 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
834 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
835 * set contains an unspecified set of optimizations (e.g., the precompiled
836 * preamble) geared toward improving the performance of these routines. The
837 * set of optimizations enabled may change from one version to the next.
838 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000839CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000840
841/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000842 * \brief Parse the given source file and the translation unit corresponding
843 * to that file.
844 *
845 * This routine is the main entry point for the Clang C API, providing the
846 * ability to parse a source file into a translation unit that can then be
847 * queried by other functions in the API. This routine accepts a set of
848 * command-line arguments so that the compilation can be configured in the same
849 * way that the compiler is configured on the command line.
850 *
851 * \param CIdx The index object with which the translation unit will be
852 * associated.
853 *
854 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000855 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +0000856 *
857 * \param command_line_args The command-line arguments that would be
858 * passed to the \c clang executable if it were being invoked out-of-process.
859 * These command-line options will be parsed and will affect how the translation
860 * unit is parsed. Note that the following options are ignored: '-c',
861 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
862 *
863 * \param num_command_line_args The number of command-line arguments in
864 * \p command_line_args.
865 *
866 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000867 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000868 * those files. The contents and name of these files (as specified by
869 * CXUnsavedFile) are copied when necessary, so the client only needs to
870 * guarantee their validity until the call to this function returns.
871 *
872 * \param num_unsaved_files the number of unsaved file entries in \p
873 * unsaved_files.
874 *
875 * \param options A bitmask of options that affects how the translation unit
876 * is managed but not its compilation. This should be a bitwise OR of the
877 * CXTranslationUnit_XXX flags.
878 *
879 * \returns A new translation unit describing the parsed code and containing
880 * any diagnostics produced by the compiler. If there is a failure from which
881 * the compiler cannot recover, returns NULL.
882 */
883CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
884 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000885 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000886 int num_command_line_args,
887 struct CXUnsavedFile *unsaved_files,
888 unsigned num_unsaved_files,
889 unsigned options);
890
Douglas Gregor5352ac02010-01-28 00:27:43 +0000891/**
Douglas Gregor19998442010-08-13 15:35:05 +0000892 * \brief Flags that control how translation units are saved.
893 *
894 * The enumerators in this enumeration type are meant to be bitwise
895 * ORed together to specify which options should be used when
896 * saving the translation unit.
897 */
898enum CXSaveTranslationUnit_Flags {
899 /**
900 * \brief Used to indicate that no special saving options are needed.
901 */
902 CXSaveTranslationUnit_None = 0x0
903};
904
905/**
906 * \brief Returns the set of flags that is suitable for saving a translation
907 * unit.
908 *
909 * The set of flags returned provide options for
910 * \c clang_saveTranslationUnit() by default. The returned flag
911 * set contains an unspecified set of options that save translation units with
912 * the most commonly-requested data.
913 */
914CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
915
916/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000917 * \brief Saves a translation unit into a serialized representation of
918 * that translation unit on disk.
919 *
920 * Any translation unit that was parsed without error can be saved
921 * into a file. The translation unit can then be deserialized into a
922 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
923 * if it is an incomplete translation unit that corresponds to a
924 * header, used as a precompiled header when parsing other translation
925 * units.
926 *
927 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +0000928 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000929 * \param FileName The file to which the translation unit will be saved.
930 *
Douglas Gregor19998442010-08-13 15:35:05 +0000931 * \param options A bitmask of options that affects how the translation unit
932 * is saved. This should be a bitwise OR of the
933 * CXSaveTranslationUnit_XXX flags.
934 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000935 * \returns Zero if the translation unit was saved successfully, a
936 * non-zero value otherwise.
937 */
938CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +0000939 const char *FileName,
940 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000941
942/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000943 * \brief Destroy the specified CXTranslationUnit object.
944 */
945CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000946
Douglas Gregor5352ac02010-01-28 00:27:43 +0000947/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000948 * \brief Flags that control the reparsing of translation units.
949 *
950 * The enumerators in this enumeration type are meant to be bitwise
951 * ORed together to specify which options should be used when
952 * reparsing the translation unit.
953 */
954enum CXReparse_Flags {
955 /**
956 * \brief Used to indicate that no special reparsing options are needed.
957 */
958 CXReparse_None = 0x0
959};
960
961/**
962 * \brief Returns the set of flags that is suitable for reparsing a translation
963 * unit.
964 *
965 * The set of flags returned provide options for
966 * \c clang_reparseTranslationUnit() by default. The returned flag
967 * set contains an unspecified set of optimizations geared toward common uses
968 * of reparsing. The set of optimizations enabled may change from one version
969 * to the next.
970 */
971CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
972
973/**
Douglas Gregorabc563f2010-07-19 21:46:24 +0000974 * \brief Reparse the source files that produced this translation unit.
975 *
976 * This routine can be used to re-parse the source files that originally
977 * created the given translation unit, for example because those source files
978 * have changed (either on disk or as passed via \p unsaved_files). The
979 * source code will be reparsed with the same command-line options as it
980 * was originally parsed.
981 *
982 * Reparsing a translation unit invalidates all cursors and source locations
983 * that refer into that translation unit. This makes reparsing a translation
984 * unit semantically equivalent to destroying the translation unit and then
985 * creating a new translation unit with the same command-line arguments.
986 * However, it may be more efficient to reparse a translation
987 * unit using this routine.
988 *
989 * \param TU The translation unit whose contents will be re-parsed. The
990 * translation unit must originally have been built with
991 * \c clang_createTranslationUnitFromSourceFile().
992 *
993 * \param num_unsaved_files The number of unsaved file entries in \p
994 * unsaved_files.
995 *
996 * \param unsaved_files The files that have not yet been saved to disk
997 * but may be required for parsing, including the contents of
998 * those files. The contents and name of these files (as specified by
999 * CXUnsavedFile) are copied when necessary, so the client only needs to
1000 * guarantee their validity until the call to this function returns.
1001 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001002 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1003 * The function \c clang_defaultReparseOptions() produces a default set of
1004 * options recommended for most uses, based on the translation unit.
1005 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001006 * \returns 0 if the sources could be reparsed. A non-zero value will be
1007 * returned if reparsing was impossible, such that the translation unit is
1008 * invalid. In such cases, the only valid call for \p TU is
1009 * \c clang_disposeTranslationUnit(TU).
1010 */
1011CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1012 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001013 struct CXUnsavedFile *unsaved_files,
1014 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001015
1016/**
1017 * \brief Categorizes how memory is being used by a translation unit.
1018 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001019enum CXTUResourceUsageKind {
1020 CXTUResourceUsage_AST = 1,
1021 CXTUResourceUsage_Identifiers = 2,
1022 CXTUResourceUsage_Selectors = 3,
1023 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001024 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001025 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001026 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
1027 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
Ted Kremenekf7870022011-04-20 16:41:07 +00001028
1029 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1030 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekf61b8312011-04-28 20:36:42 +00001031 CXTUResourceUsage_SourceManager_Membuffer_MMap,
Ted Kremenekf7870022011-04-20 16:41:07 +00001032
1033 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001034 CXTUResourceUsage_Last = CXTUResourceUsage_SourceManager_Membuffer_MMap
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001035};
1036
1037/**
1038 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001039 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001040 */
1041CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001042const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001043
Ted Kremenekf7870022011-04-20 16:41:07 +00001044typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001045 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001046 enum CXTUResourceUsageKind kind;
1047 /* \brief Amount of resources used.
1048 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001049 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001050} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001051
1052/**
1053 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1054 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001055typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001056 /* \brief Private data member, used for queries. */
1057 void *data;
1058
1059 /* \brief The number of entries in the 'entries' array. */
1060 unsigned numEntries;
1061
1062 /* \brief An array of key-value pairs, representing the breakdown of memory
1063 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001064 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001065
Ted Kremenekf7870022011-04-20 16:41:07 +00001066} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001067
1068/**
1069 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001070 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001071 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001072CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001073
Ted Kremenekf7870022011-04-20 16:41:07 +00001074CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001075
Douglas Gregorabc563f2010-07-19 21:46:24 +00001076/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001077 * @}
1078 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001079
Douglas Gregor5352ac02010-01-28 00:27:43 +00001080/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001081 * \brief Describes the kind of entity that a cursor refers to.
1082 */
1083enum CXCursorKind {
1084 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001085 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001086 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001087 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001088 *
1089 * Unexposed declarations have the same operations as any other kind
1090 * of declaration; one can extract their location information,
1091 * spelling, find their definitions, etc. However, the specific kind
1092 * of the declaration is not reported.
1093 */
1094 CXCursor_UnexposedDecl = 1,
1095 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001096 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001097 /** \brief A C or C++ union. */
1098 CXCursor_UnionDecl = 3,
1099 /** \brief A C++ class. */
1100 CXCursor_ClassDecl = 4,
1101 /** \brief An enumeration. */
1102 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001103 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001104 * \brief A field (in C) or non-static data member (in C++) in a
1105 * struct, union, or C++ class.
1106 */
1107 CXCursor_FieldDecl = 6,
1108 /** \brief An enumerator constant. */
1109 CXCursor_EnumConstantDecl = 7,
1110 /** \brief A function. */
1111 CXCursor_FunctionDecl = 8,
1112 /** \brief A variable. */
1113 CXCursor_VarDecl = 9,
1114 /** \brief A function or method parameter. */
1115 CXCursor_ParmDecl = 10,
1116 /** \brief An Objective-C @interface. */
1117 CXCursor_ObjCInterfaceDecl = 11,
1118 /** \brief An Objective-C @interface for a category. */
1119 CXCursor_ObjCCategoryDecl = 12,
1120 /** \brief An Objective-C @protocol declaration. */
1121 CXCursor_ObjCProtocolDecl = 13,
1122 /** \brief An Objective-C @property declaration. */
1123 CXCursor_ObjCPropertyDecl = 14,
1124 /** \brief An Objective-C instance variable. */
1125 CXCursor_ObjCIvarDecl = 15,
1126 /** \brief An Objective-C instance method. */
1127 CXCursor_ObjCInstanceMethodDecl = 16,
1128 /** \brief An Objective-C class method. */
1129 CXCursor_ObjCClassMethodDecl = 17,
1130 /** \brief An Objective-C @implementation. */
1131 CXCursor_ObjCImplementationDecl = 18,
1132 /** \brief An Objective-C @implementation for a category. */
1133 CXCursor_ObjCCategoryImplDecl = 19,
1134 /** \brief A typedef */
1135 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001136 /** \brief A C++ class method. */
1137 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001138 /** \brief A C++ namespace. */
1139 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001140 /** \brief A linkage specification, e.g. 'extern "C"'. */
1141 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001142 /** \brief A C++ constructor. */
1143 CXCursor_Constructor = 24,
1144 /** \brief A C++ destructor. */
1145 CXCursor_Destructor = 25,
1146 /** \brief A C++ conversion function. */
1147 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001148 /** \brief A C++ template type parameter. */
1149 CXCursor_TemplateTypeParameter = 27,
1150 /** \brief A C++ non-type template parameter. */
1151 CXCursor_NonTypeTemplateParameter = 28,
1152 /** \brief A C++ template template parameter. */
1153 CXCursor_TemplateTemplateParameter = 29,
1154 /** \brief A C++ function template. */
1155 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001156 /** \brief A C++ class template. */
1157 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001158 /** \brief A C++ class template partial specialization. */
1159 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001160 /** \brief A C++ namespace alias declaration. */
1161 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001162 /** \brief A C++ using directive. */
1163 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001164 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001165 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001166 /** \brief A C++ alias declaration */
1167 CXCursor_TypeAliasDecl = 36,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001168 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Richard Smith162e1c12011-04-15 14:24:37 +00001169 CXCursor_LastDecl = CXCursor_TypeAliasDecl,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001170
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001171 /* References */
1172 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001173 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001174 CXCursor_ObjCProtocolRef = 41,
1175 CXCursor_ObjCClassRef = 42,
1176 /**
1177 * \brief A reference to a type declaration.
1178 *
1179 * A type reference occurs anywhere where a type is named but not
1180 * declared. For example, given:
1181 *
1182 * \code
1183 * typedef unsigned size_type;
1184 * size_type size;
1185 * \endcode
1186 *
1187 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1188 * while the type of the variable "size" is referenced. The cursor
1189 * referenced by the type of size is the typedef for size_type.
1190 */
1191 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001192 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001193 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001194 * \brief A reference to a class template, function template, template
1195 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001196 */
1197 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001198 /**
1199 * \brief A reference to a namespace or namespace alias.
1200 */
1201 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001202 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001203 * \brief A reference to a member of a struct, union, or class that occurs in
1204 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001205 */
1206 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001207 /**
1208 * \brief A reference to a labeled statement.
1209 *
1210 * This cursor kind is used to describe the jump to "start_over" in the
1211 * goto statement in the following example:
1212 *
1213 * \code
1214 * start_over:
1215 * ++counter;
1216 *
1217 * goto start_over;
1218 * \endcode
1219 *
1220 * A label reference cursor refers to a label statement.
1221 */
1222 CXCursor_LabelRef = 48,
1223
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001224 /**
1225 * \brief A reference to a set of overloaded functions or function templates
1226 * that has not yet been resolved to a specific function or function template.
1227 *
1228 * An overloaded declaration reference cursor occurs in C++ templates where
1229 * a dependent name refers to a function. For example:
1230 *
1231 * \code
1232 * template<typename T> void swap(T&, T&);
1233 *
1234 * struct X { ... };
1235 * void swap(X&, X&);
1236 *
1237 * template<typename T>
1238 * void reverse(T* first, T* last) {
1239 * while (first < last - 1) {
1240 * swap(*first, *--last);
1241 * ++first;
1242 * }
1243 * }
1244 *
1245 * struct Y { };
1246 * void swap(Y&, Y&);
1247 * \endcode
1248 *
1249 * Here, the identifier "swap" is associated with an overloaded declaration
1250 * reference. In the template definition, "swap" refers to either of the two
1251 * "swap" functions declared above, so both results will be available. At
1252 * instantiation time, "swap" may also refer to other functions found via
1253 * argument-dependent lookup (e.g., the "swap" function at the end of the
1254 * example).
1255 *
1256 * The functions \c clang_getNumOverloadedDecls() and
1257 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1258 * referenced by this cursor.
1259 */
1260 CXCursor_OverloadedDeclRef = 49,
1261
1262 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001263
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001264 /* Error conditions */
1265 CXCursor_FirstInvalid = 70,
1266 CXCursor_InvalidFile = 70,
1267 CXCursor_NoDeclFound = 71,
1268 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001269 CXCursor_InvalidCode = 73,
1270 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001271
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001272 /* Expressions */
1273 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001274
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001275 /**
1276 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001277 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001278 *
1279 * Unexposed expressions have the same operations as any other kind
1280 * of expression; one can extract their location information,
1281 * spelling, children, etc. However, the specific kind of the
1282 * expression is not reported.
1283 */
1284 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001285
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001286 /**
1287 * \brief An expression that refers to some value declaration, such
1288 * as a function, varible, or enumerator.
1289 */
1290 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001291
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001292 /**
1293 * \brief An expression that refers to a member of a struct, union,
1294 * class, Objective-C class, etc.
1295 */
1296 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001297
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001298 /** \brief An expression that calls a function. */
1299 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001300
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001301 /** \brief An expression that sends a message to an Objective-C
1302 object or class. */
1303 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001304
1305 /** \brief An expression that represents a block literal. */
1306 CXCursor_BlockExpr = 105,
1307
1308 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001309
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001310 /* Statements */
1311 CXCursor_FirstStmt = 200,
1312 /**
1313 * \brief A statement whose specific kind is not exposed via this
1314 * interface.
1315 *
1316 * Unexposed statements have the same operations as any other kind of
1317 * statement; one can extract their location information, spelling,
1318 * children, etc. However, the specific kind of the statement is not
1319 * reported.
1320 */
1321 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001322
1323 /** \brief A labelled statement in a function.
1324 *
1325 * This cursor kind is used to describe the "start_over:" label statement in
1326 * the following example:
1327 *
1328 * \code
1329 * start_over:
1330 * ++counter;
1331 * \endcode
1332 *
1333 */
1334 CXCursor_LabelStmt = 201,
1335
1336 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001337
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001338 /**
1339 * \brief Cursor that represents the translation unit itself.
1340 *
1341 * The translation unit cursor exists primarily to act as the root
1342 * cursor for traversing the contents of a translation unit.
1343 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001344 CXCursor_TranslationUnit = 300,
1345
1346 /* Attributes */
1347 CXCursor_FirstAttr = 400,
1348 /**
1349 * \brief An attribute whose specific kind is not exposed via this
1350 * interface.
1351 */
1352 CXCursor_UnexposedAttr = 400,
1353
1354 CXCursor_IBActionAttr = 401,
1355 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001356 CXCursor_IBOutletCollectionAttr = 403,
1357 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001358
1359 /* Preprocessing */
1360 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001361 CXCursor_MacroDefinition = 501,
1362 CXCursor_MacroInstantiation = 502,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001363 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001364 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001365 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001366};
1367
1368/**
1369 * \brief A cursor representing some element in the abstract syntax tree for
1370 * a translation unit.
1371 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001372 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001373 * program--declaration, statements, expressions, references to declarations,
1374 * etc.--under a single "cursor" abstraction with a common set of operations.
1375 * Common operation for a cursor include: getting the physical location in
1376 * a source file where the cursor points, getting the name associated with a
1377 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1378 *
1379 * Cursors can be produced in two specific ways.
1380 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1381 * from which one can use clang_visitChildren() to explore the rest of the
1382 * translation unit. clang_getCursor() maps from a physical source location
1383 * to the entity that resides at that location, allowing one to map from the
1384 * source code into the AST.
1385 */
1386typedef struct {
1387 enum CXCursorKind kind;
1388 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001389} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001390
1391/**
1392 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1393 *
1394 * @{
1395 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001396
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001397/**
1398 * \brief Retrieve the NULL cursor, which represents no entity.
1399 */
1400CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001401
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001402/**
1403 * \brief Retrieve the cursor that represents the given translation unit.
1404 *
1405 * The translation unit cursor can be used to start traversing the
1406 * various declarations within the given translation unit.
1407 */
1408CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1409
1410/**
1411 * \brief Determine whether two cursors are equivalent.
1412 */
1413CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001414
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001415/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001416 * \brief Compute a hash value for the given cursor.
1417 */
1418CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1419
1420/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001421 * \brief Retrieve the kind of the given cursor.
1422 */
1423CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1424
1425/**
1426 * \brief Determine whether the given cursor kind represents a declaration.
1427 */
1428CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1429
1430/**
1431 * \brief Determine whether the given cursor kind represents a simple
1432 * reference.
1433 *
1434 * Note that other kinds of cursors (such as expressions) can also refer to
1435 * other cursors. Use clang_getCursorReferenced() to determine whether a
1436 * particular cursor refers to another entity.
1437 */
1438CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1439
1440/**
1441 * \brief Determine whether the given cursor kind represents an expression.
1442 */
1443CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1444
1445/**
1446 * \brief Determine whether the given cursor kind represents a statement.
1447 */
1448CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1449
1450/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001451 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001452 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001453 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001454CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1455
1456/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001457 * \brief Determine whether the given cursor kind represents a translation
1458 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001459 */
1460CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001461
Ted Kremenekad6eff62010-03-08 21:17:29 +00001462/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001463 * \brief Determine whether the given cursor represents a preprocessing
1464 * element, such as a preprocessor directive or macro instantiation.
1465 */
1466CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1467
1468/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001469 * \brief Determine whether the given cursor represents a currently
1470 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1471 */
1472CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1473
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001474/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001475 * \brief Describe the linkage of the entity referred to by a cursor.
1476 */
1477enum CXLinkageKind {
1478 /** \brief This value indicates that no linkage information is available
1479 * for a provided CXCursor. */
1480 CXLinkage_Invalid,
1481 /**
1482 * \brief This is the linkage for variables, parameters, and so on that
1483 * have automatic storage. This covers normal (non-extern) local variables.
1484 */
1485 CXLinkage_NoLinkage,
1486 /** \brief This is the linkage for static variables and static functions. */
1487 CXLinkage_Internal,
1488 /** \brief This is the linkage for entities with external linkage that live
1489 * in C++ anonymous namespaces.*/
1490 CXLinkage_UniqueExternal,
1491 /** \brief This is the linkage for entities with true, external linkage. */
1492 CXLinkage_External
1493};
1494
1495/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001496 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001497 */
1498CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1499
1500/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001501 * \brief Determine the availability of the entity that this cursor refers to.
1502 *
1503 * \param cursor The cursor to query.
1504 *
1505 * \returns The availability of the cursor.
1506 */
1507CINDEX_LINKAGE enum CXAvailabilityKind
1508clang_getCursorAvailability(CXCursor cursor);
1509
1510/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001511 * \brief Describe the "language" of the entity referred to by a cursor.
1512 */
1513CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001514 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001515 CXLanguage_C,
1516 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001517 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001518};
1519
1520/**
1521 * \brief Determine the "language" of the entity referred to by a given cursor.
1522 */
1523CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1524
Ted Kremenekeca099b2010-12-08 23:43:14 +00001525
1526/**
1527 * \brief A fast container representing a set of CXCursors.
1528 */
1529typedef struct CXCursorSetImpl *CXCursorSet;
1530
1531/**
1532 * \brief Creates an empty CXCursorSet.
1533 */
1534CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
1535
1536/**
1537 * \brief Disposes a CXCursorSet and releases its associated memory.
1538 */
1539CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
1540
1541/**
1542 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
1543 *
1544 * \returns non-zero if the set contains the specified cursor.
1545*/
1546CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
1547 CXCursor cursor);
1548
1549/**
1550 * \brief Inserts a CXCursor into a CXCursorSet.
1551 *
1552 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
1553*/
1554CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
1555 CXCursor cursor);
1556
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001557/**
1558 * \brief Determine the semantic parent of the given cursor.
1559 *
1560 * The semantic parent of a cursor is the cursor that semantically contains
1561 * the given \p cursor. For many declarations, the lexical and semantic parents
1562 * are equivalent (the lexical parent is returned by
1563 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1564 * definitions are provided out-of-line. For example:
1565 *
1566 * \code
1567 * class C {
1568 * void f();
1569 * };
1570 *
1571 * void C::f() { }
1572 * \endcode
1573 *
1574 * In the out-of-line definition of \c C::f, the semantic parent is the
1575 * the class \c C, of which this function is a member. The lexical parent is
1576 * the place where the declaration actually occurs in the source code; in this
1577 * case, the definition occurs in the translation unit. In general, the
1578 * lexical parent for a given entity can change without affecting the semantics
1579 * of the program, and the lexical parent of different declarations of the
1580 * same entity may be different. Changing the semantic parent of a declaration,
1581 * on the other hand, can have a major impact on semantics, and redeclarations
1582 * of a particular entity should all have the same semantic context.
1583 *
1584 * In the example above, both declarations of \c C::f have \c C as their
1585 * semantic context, while the lexical context of the first \c C::f is \c C
1586 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001587 *
1588 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001589 */
1590CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1591
1592/**
1593 * \brief Determine the lexical parent of the given cursor.
1594 *
1595 * The lexical parent of a cursor is the cursor in which the given \p cursor
1596 * was actually written. For many declarations, the lexical and semantic parents
1597 * are equivalent (the semantic parent is returned by
1598 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1599 * definitions are provided out-of-line. For example:
1600 *
1601 * \code
1602 * class C {
1603 * void f();
1604 * };
1605 *
1606 * void C::f() { }
1607 * \endcode
1608 *
1609 * In the out-of-line definition of \c C::f, the semantic parent is the
1610 * the class \c C, of which this function is a member. The lexical parent is
1611 * the place where the declaration actually occurs in the source code; in this
1612 * case, the definition occurs in the translation unit. In general, the
1613 * lexical parent for a given entity can change without affecting the semantics
1614 * of the program, and the lexical parent of different declarations of the
1615 * same entity may be different. Changing the semantic parent of a declaration,
1616 * on the other hand, can have a major impact on semantics, and redeclarations
1617 * of a particular entity should all have the same semantic context.
1618 *
1619 * In the example above, both declarations of \c C::f have \c C as their
1620 * semantic context, while the lexical context of the first \c C::f is \c C
1621 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001622 *
1623 * For declarations written in the global scope, the lexical parent is
1624 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001625 */
1626CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001627
1628/**
1629 * \brief Determine the set of methods that are overridden by the given
1630 * method.
1631 *
1632 * In both Objective-C and C++, a method (aka virtual member function,
1633 * in C++) can override a virtual method in a base class. For
1634 * Objective-C, a method is said to override any method in the class's
1635 * interface (if we're coming from an implementation), its protocols,
1636 * or its categories, that has the same selector and is of the same
1637 * kind (class or instance). If no such method exists, the search
1638 * continues to the class's superclass, its protocols, and its
1639 * categories, and so on.
1640 *
1641 * For C++, a virtual member function overrides any virtual member
1642 * function with the same signature that occurs in its base
1643 * classes. With multiple inheritance, a virtual member function can
1644 * override several virtual member functions coming from different
1645 * base classes.
1646 *
1647 * In all cases, this function determines the immediate overridden
1648 * method, rather than all of the overridden methods. For example, if
1649 * a method is originally declared in a class A, then overridden in B
1650 * (which in inherits from A) and also in C (which inherited from B),
1651 * then the only overridden method returned from this function when
1652 * invoked on C's method will be B's method. The client may then
1653 * invoke this function again, given the previously-found overridden
1654 * methods, to map out the complete method-override set.
1655 *
1656 * \param cursor A cursor representing an Objective-C or C++
1657 * method. This routine will compute the set of methods that this
1658 * method overrides.
1659 *
1660 * \param overridden A pointer whose pointee will be replaced with a
1661 * pointer to an array of cursors, representing the set of overridden
1662 * methods. If there are no overridden methods, the pointee will be
1663 * set to NULL. The pointee must be freed via a call to
1664 * \c clang_disposeOverriddenCursors().
1665 *
1666 * \param num_overridden A pointer to the number of overridden
1667 * functions, will be set to the number of overridden functions in the
1668 * array pointed to by \p overridden.
1669 */
1670CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1671 CXCursor **overridden,
1672 unsigned *num_overridden);
1673
1674/**
1675 * \brief Free the set of overridden cursors returned by \c
1676 * clang_getOverriddenCursors().
1677 */
1678CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1679
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001680/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001681 * \brief Retrieve the file that is included by the given inclusion directive
1682 * cursor.
1683 */
1684CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1685
1686/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001687 * @}
1688 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001689
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001690/**
1691 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1692 *
1693 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1694 * routines help map between cursors and the physical locations where the
1695 * described entities occur in the source code. The mapping is provided in
1696 * both directions, so one can map from source code to the AST and back.
1697 *
1698 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001699 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001700
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001701/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001702 * \brief Map a source location to the cursor that describes the entity at that
1703 * location in the source code.
1704 *
1705 * clang_getCursor() maps an arbitrary source location within a translation
1706 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001707 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001708 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001709 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001710 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1711 * will return a cursor referring to the "+" expression.
1712 *
1713 * \returns a cursor representing the entity at the given source location, or
1714 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001715 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001716CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001717
Douglas Gregor98258af2010-01-18 22:46:11 +00001718/**
1719 * \brief Retrieve the physical location of the source constructor referenced
1720 * by the given cursor.
1721 *
1722 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001723 * declaration, where the name of that declaration would occur if it is
1724 * unnamed, or some keyword that introduces that particular declaration.
1725 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001726 * source code.
1727 */
1728CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001729
Douglas Gregorb6998662010-01-19 19:34:47 +00001730/**
1731 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001732 * the given cursor.
1733 *
1734 * The extent of a cursor starts with the file/line/column pointing at the
1735 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001736 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001737 * declaration, the extent covers the declaration itself. For a reference,
1738 * the extent covers the location of the reference (e.g., where the referenced
1739 * entity was actually used).
1740 */
1741CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001742
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001743/**
1744 * @}
1745 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001746
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001747/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001748 * \defgroup CINDEX_TYPES Type information for CXCursors
1749 *
1750 * @{
1751 */
1752
1753/**
1754 * \brief Describes the kind of type
1755 */
1756enum CXTypeKind {
1757 /**
1758 * \brief Reprents an invalid type (e.g., where no type is available).
1759 */
1760 CXType_Invalid = 0,
1761
1762 /**
1763 * \brief A type whose specific kind is not exposed via this
1764 * interface.
1765 */
1766 CXType_Unexposed = 1,
1767
1768 /* Builtin types */
1769 CXType_Void = 2,
1770 CXType_Bool = 3,
1771 CXType_Char_U = 4,
1772 CXType_UChar = 5,
1773 CXType_Char16 = 6,
1774 CXType_Char32 = 7,
1775 CXType_UShort = 8,
1776 CXType_UInt = 9,
1777 CXType_ULong = 10,
1778 CXType_ULongLong = 11,
1779 CXType_UInt128 = 12,
1780 CXType_Char_S = 13,
1781 CXType_SChar = 14,
1782 CXType_WChar = 15,
1783 CXType_Short = 16,
1784 CXType_Int = 17,
1785 CXType_Long = 18,
1786 CXType_LongLong = 19,
1787 CXType_Int128 = 20,
1788 CXType_Float = 21,
1789 CXType_Double = 22,
1790 CXType_LongDouble = 23,
1791 CXType_NullPtr = 24,
1792 CXType_Overload = 25,
1793 CXType_Dependent = 26,
1794 CXType_ObjCId = 27,
1795 CXType_ObjCClass = 28,
1796 CXType_ObjCSel = 29,
1797 CXType_FirstBuiltin = CXType_Void,
1798 CXType_LastBuiltin = CXType_ObjCSel,
1799
1800 CXType_Complex = 100,
1801 CXType_Pointer = 101,
1802 CXType_BlockPointer = 102,
1803 CXType_LValueReference = 103,
1804 CXType_RValueReference = 104,
1805 CXType_Record = 105,
1806 CXType_Enum = 106,
1807 CXType_Typedef = 107,
1808 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001809 CXType_ObjCObjectPointer = 109,
1810 CXType_FunctionNoProto = 110,
1811 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001812};
1813
1814/**
1815 * \brief The type of an element in the abstract syntax tree.
1816 *
1817 */
1818typedef struct {
1819 enum CXTypeKind kind;
1820 void *data[2];
1821} CXType;
1822
1823/**
1824 * \brief Retrieve the type of a CXCursor (if any).
1825 */
1826CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1827
1828/**
1829 * \determine Determine whether two CXTypes represent the same type.
1830 *
1831 * \returns non-zero if the CXTypes represent the same type and
1832 zero otherwise.
1833 */
1834CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1835
1836/**
1837 * \brief Return the canonical type for a CXType.
1838 *
1839 * Clang's type system explicitly models typedefs and all the ways
1840 * a specific type can be represented. The canonical type is the underlying
1841 * type with all the "sugar" removed. For example, if 'T' is a typedef
1842 * for 'int', the canonical type for 'T' would be 'int'.
1843 */
1844CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1845
1846/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00001847 * \determine Determine whether a CXType has the "const" qualifier set,
1848 * without looking through typedefs that may have added "const" at a different level.
1849 */
1850CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
1851
1852/**
1853 * \determine Determine whether a CXType has the "volatile" qualifier set,
1854 * without looking through typedefs that may have added "volatile" at a different level.
1855 */
1856CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
1857
1858/**
1859 * \determine Determine whether a CXType has the "restrict" qualifier set,
1860 * without looking through typedefs that may have added "restrict" at a different level.
1861 */
1862CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
1863
1864/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001865 * \brief For pointer types, returns the type of the pointee.
1866 *
1867 */
1868CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1869
1870/**
1871 * \brief Return the cursor for the declaration of the given type.
1872 */
1873CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1874
David Chisnall5389f482010-12-30 14:05:53 +00001875/**
1876 * Returns the Objective-C type encoding for the specified declaration.
1877 */
1878CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001879
1880/**
1881 * \brief Retrieve the spelling of a given CXTypeKind.
1882 */
1883CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1884
1885/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001886 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001887 */
1888CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1889
1890/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001891 * \brief Retrieve the result type associated with a given cursor. This only
1892 * returns a valid type of the cursor refers to a function or method.
1893 */
1894CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1895
1896/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001897 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1898 * otherwise.
1899 */
1900CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1901
1902/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001903 * \brief Returns 1 if the base class specified by the cursor with kind
1904 * CX_CXXBaseSpecifier is virtual.
1905 */
1906CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1907
1908/**
1909 * \brief Represents the C++ access control level to a base class for a
1910 * cursor with kind CX_CXXBaseSpecifier.
1911 */
1912enum CX_CXXAccessSpecifier {
1913 CX_CXXInvalidAccessSpecifier,
1914 CX_CXXPublic,
1915 CX_CXXProtected,
1916 CX_CXXPrivate
1917};
1918
1919/**
1920 * \brief Returns the access control level for the C++ base specifier
1921 * represented by a cursor with kind CX_CXXBaseSpecifier.
1922 */
1923CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
1924
1925/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001926 * \brief Determine the number of overloaded declarations referenced by a
1927 * \c CXCursor_OverloadedDeclRef cursor.
1928 *
1929 * \param cursor The cursor whose overloaded declarations are being queried.
1930 *
1931 * \returns The number of overloaded declarations referenced by \c cursor. If it
1932 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
1933 */
1934CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
1935
1936/**
1937 * \brief Retrieve a cursor for one of the overloaded declarations referenced
1938 * by a \c CXCursor_OverloadedDeclRef cursor.
1939 *
1940 * \param cursor The cursor whose overloaded declarations are being queried.
1941 *
1942 * \param index The zero-based index into the set of overloaded declarations in
1943 * the cursor.
1944 *
1945 * \returns A cursor representing the declaration referenced by the given
1946 * \c cursor at the specified \c index. If the cursor does not have an
1947 * associated set of overloaded declarations, or if the index is out of bounds,
1948 * returns \c clang_getNullCursor();
1949 */
1950CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
1951 unsigned index);
1952
1953/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001954 * @}
1955 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001956
1957/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00001958 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00001959 *
1960 * @{
1961 */
1962
1963
1964/**
1965 * \brief For cursors representing an iboutletcollection attribute,
1966 * this function returns the collection element type.
1967 *
1968 */
1969CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
1970
1971/**
1972 * @}
1973 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001974
1975/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001976 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
1977 *
1978 * These routines provide the ability to traverse the abstract syntax tree
1979 * using cursors.
1980 *
1981 * @{
1982 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001983
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001984/**
1985 * \brief Describes how the traversal of the children of a particular
1986 * cursor should proceed after visiting a particular child cursor.
1987 *
1988 * A value of this enumeration type should be returned by each
1989 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
1990 */
1991enum CXChildVisitResult {
1992 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001993 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001994 */
1995 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001996 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001997 * \brief Continues the cursor traversal with the next sibling of
1998 * the cursor just visited, without visiting its children.
1999 */
2000 CXChildVisit_Continue,
2001 /**
2002 * \brief Recursively traverse the children of this cursor, using
2003 * the same visitor and client data.
2004 */
2005 CXChildVisit_Recurse
2006};
2007
2008/**
2009 * \brief Visitor invoked for each cursor found by a traversal.
2010 *
2011 * This visitor function will be invoked for each cursor found by
2012 * clang_visitCursorChildren(). Its first argument is the cursor being
2013 * visited, its second argument is the parent visitor for that cursor,
2014 * and its third argument is the client data provided to
2015 * clang_visitCursorChildren().
2016 *
2017 * The visitor should return one of the \c CXChildVisitResult values
2018 * to direct clang_visitCursorChildren().
2019 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002020typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2021 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002022 CXClientData client_data);
2023
2024/**
2025 * \brief Visit the children of a particular cursor.
2026 *
2027 * This function visits all the direct children of the given cursor,
2028 * invoking the given \p visitor function with the cursors of each
2029 * visited child. The traversal may be recursive, if the visitor returns
2030 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2031 * the visitor returns \c CXChildVisit_Break.
2032 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002033 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002034 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002035 * definition, have no children).
2036 *
2037 * \param visitor the visitor function that will be invoked for each
2038 * child of \p parent.
2039 *
2040 * \param client_data pointer data supplied by the client, which will
2041 * be passed to the visitor each time it is invoked.
2042 *
2043 * \returns a non-zero value if the traversal was terminated
2044 * prematurely by the visitor returning \c CXChildVisit_Break.
2045 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002046CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002047 CXCursorVisitor visitor,
2048 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002049#ifdef __has_feature
2050# if __has_feature(blocks)
2051/**
2052 * \brief Visitor invoked for each cursor found by a traversal.
2053 *
2054 * This visitor block will be invoked for each cursor found by
2055 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2056 * visited, its second argument is the parent visitor for that cursor.
2057 *
2058 * The visitor should return one of the \c CXChildVisitResult values
2059 * to direct clang_visitChildrenWithBlock().
2060 */
2061typedef enum CXChildVisitResult
2062 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2063
2064/**
2065 * Visits the children of a cursor using the specified block. Behaves
2066 * identically to clang_visitChildren() in all other respects.
2067 */
2068unsigned clang_visitChildrenWithBlock(CXCursor parent,
2069 CXCursorVisitorBlock block);
2070# endif
2071#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002072
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002073/**
2074 * @}
2075 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002076
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002077/**
2078 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2079 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002080 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002081 * across translation units, by providing the names of the entities referenced
2082 * by cursors, follow reference cursors to the declarations they reference,
2083 * and associate declarations with their definitions.
2084 *
2085 * @{
2086 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002087
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002088/**
2089 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2090 * by the given cursor.
2091 *
2092 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2093 * entity (function, class, variable, etc.) within a program. USRs can be
2094 * compared across translation units to determine, e.g., when references in
2095 * one translation refer to an entity defined in another translation unit.
2096 */
2097CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2098
2099/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002100 * \brief Construct a USR for a specified Objective-C class.
2101 */
2102CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2103
2104/**
2105 * \brief Construct a USR for a specified Objective-C category.
2106 */
2107CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002108 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002109 const char *category_name);
2110
2111/**
2112 * \brief Construct a USR for a specified Objective-C protocol.
2113 */
2114CINDEX_LINKAGE CXString
2115 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2116
2117
2118/**
2119 * \brief Construct a USR for a specified Objective-C instance variable and
2120 * the USR for its containing class.
2121 */
2122CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2123 CXString classUSR);
2124
2125/**
2126 * \brief Construct a USR for a specified Objective-C method and
2127 * the USR for its containing class.
2128 */
2129CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2130 unsigned isInstanceMethod,
2131 CXString classUSR);
2132
2133/**
2134 * \brief Construct a USR for a specified Objective-C property and the USR
2135 * for its containing class.
2136 */
2137CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2138 CXString classUSR);
2139
2140/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002141 * \brief Retrieve a name for the entity referenced by this cursor.
2142 */
2143CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2144
Douglas Gregor358559d2010-10-02 22:49:11 +00002145/**
2146 * \brief Retrieve the display name for the entity referenced by this cursor.
2147 *
2148 * The display name contains extra information that helps identify the cursor,
2149 * such as the parameters of a function or template or the arguments of a
2150 * class template specialization.
2151 */
2152CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2153
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002154/** \brief For a cursor that is a reference, retrieve a cursor representing the
2155 * entity that it references.
2156 *
2157 * Reference cursors refer to other entities in the AST. For example, an
2158 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002159 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002160 * cursor for the superclass reference. If the input cursor is a declaration or
2161 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002162 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002163 */
2164CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002165
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002166/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002167 * \brief For a cursor that is either a reference to or a declaration
2168 * of some entity, retrieve a cursor that describes the definition of
2169 * that entity.
2170 *
2171 * Some entities can be declared multiple times within a translation
2172 * unit, but only one of those declarations can also be a
2173 * definition. For example, given:
2174 *
2175 * \code
2176 * int f(int, int);
2177 * int g(int x, int y) { return f(x, y); }
2178 * int f(int a, int b) { return a + b; }
2179 * int f(int, int);
2180 * \endcode
2181 *
2182 * there are three declarations of the function "f", but only the
2183 * second one is a definition. The clang_getCursorDefinition()
2184 * function will take any cursor pointing to a declaration of "f"
2185 * (the first or fourth lines of the example) or a cursor referenced
2186 * that uses "f" (the call to "f' inside "g") and will return a
2187 * declaration cursor pointing to the definition (the second "f"
2188 * declaration).
2189 *
2190 * If given a cursor for which there is no corresponding definition,
2191 * e.g., because there is no definition of that entity within this
2192 * translation unit, returns a NULL cursor.
2193 */
2194CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2195
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002196/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002197 * \brief Determine whether the declaration pointed to by this cursor
2198 * is also a definition of that entity.
2199 */
2200CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2201
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002202/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002203 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2204 *
2205 * In the C family of languages, many kinds of entities can be declared several
2206 * times within a single translation unit. For example, a structure type can
2207 * be forward-declared (possibly multiple times) and later defined:
2208 *
2209 * \code
2210 * struct X;
2211 * struct X;
2212 * struct X {
2213 * int member;
2214 * };
2215 * \endcode
2216 *
2217 * The declarations and the definition of \c X are represented by three
2218 * different cursors, all of which are declarations of the same underlying
2219 * entity. One of these cursor is considered the "canonical" cursor, which
2220 * is effectively the representative for the underlying entity. One can
2221 * determine if two cursors are declarations of the same underlying entity by
2222 * comparing their canonical cursors.
2223 *
2224 * \returns The canonical cursor for the entity referred to by the given cursor.
2225 */
2226CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2227
2228/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002229 * @}
2230 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002231
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002232/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002233 * \defgroup CINDEX_CPP C++ AST introspection
2234 *
2235 * The routines in this group provide access information in the ASTs specific
2236 * to C++ language features.
2237 *
2238 * @{
2239 */
2240
2241/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002242 * \brief Determine if a C++ member function or member function template is
2243 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002244 */
2245CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2246
2247/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002248 * \brief Given a cursor that represents a template, determine
2249 * the cursor kind of the specializations would be generated by instantiating
2250 * the template.
2251 *
2252 * This routine can be used to determine what flavor of function template,
2253 * class template, or class template partial specialization is stored in the
2254 * cursor. For example, it can describe whether a class template cursor is
2255 * declared with "struct", "class" or "union".
2256 *
2257 * \param C The cursor to query. This cursor should represent a template
2258 * declaration.
2259 *
2260 * \returns The cursor kind of the specializations that would be generated
2261 * by instantiating the template \p C. If \p C is not a template, returns
2262 * \c CXCursor_NoDeclFound.
2263 */
2264CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2265
2266/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002267 * \brief Given a cursor that may represent a specialization or instantiation
2268 * of a template, retrieve the cursor that represents the template that it
2269 * specializes or from which it was instantiated.
2270 *
2271 * This routine determines the template involved both for explicit
2272 * specializations of templates and for implicit instantiations of the template,
2273 * both of which are referred to as "specializations". For a class template
2274 * specialization (e.g., \c std::vector<bool>), this routine will return
2275 * either the primary template (\c std::vector) or, if the specialization was
2276 * instantiated from a class template partial specialization, the class template
2277 * partial specialization. For a class template partial specialization and a
2278 * function template specialization (including instantiations), this
2279 * this routine will return the specialized template.
2280 *
2281 * For members of a class template (e.g., member functions, member classes, or
2282 * static data members), returns the specialized or instantiated member.
2283 * Although not strictly "templates" in the C++ language, members of class
2284 * templates have the same notions of specializations and instantiations that
2285 * templates do, so this routine treats them similarly.
2286 *
2287 * \param C A cursor that may be a specialization of a template or a member
2288 * of a template.
2289 *
2290 * \returns If the given cursor is a specialization or instantiation of a
2291 * template or a member thereof, the template or member that it specializes or
2292 * from which it was instantiated. Otherwise, returns a NULL cursor.
2293 */
2294CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
2295
2296/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002297 * @}
2298 */
2299
2300/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002301 * \defgroup CINDEX_LEX Token extraction and manipulation
2302 *
2303 * The routines in this group provide access to the tokens within a
2304 * translation unit, along with a semantic mapping of those tokens to
2305 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002306 *
2307 * @{
2308 */
2309
2310/**
2311 * \brief Describes a kind of token.
2312 */
2313typedef enum CXTokenKind {
2314 /**
2315 * \brief A token that contains some kind of punctuation.
2316 */
2317 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002318
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002319 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002320 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002321 */
2322 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002323
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002324 /**
2325 * \brief An identifier (that is not a keyword).
2326 */
2327 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002328
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002329 /**
2330 * \brief A numeric, string, or character literal.
2331 */
2332 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002333
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002334 /**
2335 * \brief A comment.
2336 */
2337 CXToken_Comment
2338} CXTokenKind;
2339
2340/**
2341 * \brief Describes a single preprocessing token.
2342 */
2343typedef struct {
2344 unsigned int_data[4];
2345 void *ptr_data;
2346} CXToken;
2347
2348/**
2349 * \brief Determine the kind of the given token.
2350 */
2351CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002352
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002353/**
2354 * \brief Determine the spelling of the given token.
2355 *
2356 * The spelling of a token is the textual representation of that token, e.g.,
2357 * the text of an identifier or keyword.
2358 */
2359CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002360
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002361/**
2362 * \brief Retrieve the source location of the given token.
2363 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002364CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002365 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002366
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002367/**
2368 * \brief Retrieve a source range that covers the given token.
2369 */
2370CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2371
2372/**
2373 * \brief Tokenize the source code described by the given range into raw
2374 * lexical tokens.
2375 *
2376 * \param TU the translation unit whose text is being tokenized.
2377 *
2378 * \param Range the source range in which text should be tokenized. All of the
2379 * tokens produced by tokenization will fall within this source range,
2380 *
2381 * \param Tokens this pointer will be set to point to the array of tokens
2382 * that occur within the given source range. The returned pointer must be
2383 * freed with clang_disposeTokens() before the translation unit is destroyed.
2384 *
2385 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2386 * array.
2387 *
2388 */
2389CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2390 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002391
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002392/**
2393 * \brief Annotate the given set of tokens by providing cursors for each token
2394 * that can be mapped to a specific entity within the abstract syntax tree.
2395 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002396 * This token-annotation routine is equivalent to invoking
2397 * clang_getCursor() for the source locations of each of the
2398 * tokens. The cursors provided are filtered, so that only those
2399 * cursors that have a direct correspondence to the token are
2400 * accepted. For example, given a function call \c f(x),
2401 * clang_getCursor() would provide the following cursors:
2402 *
2403 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2404 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2405 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2406 *
2407 * Only the first and last of these cursors will occur within the
2408 * annotate, since the tokens "f" and "x' directly refer to a function
2409 * and a variable, respectively, but the parentheses are just a small
2410 * part of the full syntax of the function call expression, which is
2411 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002412 *
2413 * \param TU the translation unit that owns the given tokens.
2414 *
2415 * \param Tokens the set of tokens to annotate.
2416 *
2417 * \param NumTokens the number of tokens in \p Tokens.
2418 *
2419 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2420 * replaced with the cursors corresponding to each token.
2421 */
2422CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2423 CXToken *Tokens, unsigned NumTokens,
2424 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002425
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002426/**
2427 * \brief Free the given set of tokens.
2428 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002429CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002430 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002431
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002432/**
2433 * @}
2434 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002435
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002436/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002437 * \defgroup CINDEX_DEBUG Debugging facilities
2438 *
2439 * These routines are used for testing and debugging, only, and should not
2440 * be relied upon.
2441 *
2442 * @{
2443 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002444
Steve Naroff4ade6d62009-09-23 17:52:52 +00002445/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002446CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002447CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2448 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002449 const char **endBuf,
2450 unsigned *startLine,
2451 unsigned *startColumn,
2452 unsigned *endLine,
2453 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002454CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00002455CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
2456 unsigned stack_size);
2457
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002458/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002459 * @}
2460 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002461
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002462/**
2463 * \defgroup CINDEX_CODE_COMPLET Code completion
2464 *
2465 * Code completion involves taking an (incomplete) source file, along with
2466 * knowledge of where the user is actively editing that file, and suggesting
2467 * syntactically- and semantically-valid constructs that the user might want to
2468 * use at that particular point in the source code. These data structures and
2469 * routines provide support for code completion.
2470 *
2471 * @{
2472 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002473
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002474/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002475 * \brief A semantic string that describes a code-completion result.
2476 *
2477 * A semantic string that describes the formatting of a code-completion
2478 * result as a single "template" of text that should be inserted into the
2479 * source buffer when a particular code-completion result is selected.
2480 * Each semantic string is made up of some number of "chunks", each of which
2481 * contains some text along with a description of what that text means, e.g.,
2482 * the name of the entity being referenced, whether the text chunk is part of
2483 * the template, or whether it is a "placeholder" that the user should replace
2484 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002485 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002486 */
2487typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002488
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002489/**
2490 * \brief A single result of code completion.
2491 */
2492typedef struct {
2493 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002494 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002495 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002496 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002497 * *Decl cursor kinds), describing the entity that the completion is
2498 * referring to.
2499 *
2500 * \todo In the future, we would like to provide a full cursor, to allow
2501 * the client to extract additional information from declaration.
2502 */
2503 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002504
2505 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002506 * \brief The code-completion string that describes how to insert this
2507 * code-completion result into the editing buffer.
2508 */
2509 CXCompletionString CompletionString;
2510} CXCompletionResult;
2511
2512/**
2513 * \brief Describes a single piece of text within a code-completion string.
2514 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002515 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2516 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002517 * should be interpreted by the client or is another completion string.
2518 */
2519enum CXCompletionChunkKind {
2520 /**
2521 * \brief A code-completion string that describes "optional" text that
2522 * could be a part of the template (but is not required).
2523 *
2524 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002525 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002526 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2527 * describes an additional part of the template that is completely optional.
2528 * For example, optional chunks can be used to describe the placeholders for
2529 * arguments that match up with defaulted function parameters, e.g. given:
2530 *
2531 * \code
2532 * void f(int x, float y = 3.14, double z = 2.71828);
2533 * \endcode
2534 *
2535 * The code-completion string for this function would contain:
2536 * - a TypedText chunk for "f".
2537 * - a LeftParen chunk for "(".
2538 * - a Placeholder chunk for "int x"
2539 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2540 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002541 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002542 * - an Optional chunk containing the last defaulted argument:
2543 * - a Comma chunk for ","
2544 * - a Placeholder chunk for "double z"
2545 * - a RightParen chunk for ")"
2546 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002547 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002548 * - Completely ignore optional chunks, in which case the template for the
2549 * function "f" would only include the first parameter ("int x").
2550 * - Fully expand all optional chunks, in which case the template for the
2551 * function "f" would have all of the parameters.
2552 */
2553 CXCompletionChunk_Optional,
2554 /**
2555 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002556 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002557 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002558 * There will be exactly one "typed text" chunk in a semantic string, which
2559 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002560 * declaration that could be used at the current code point. Clients are
2561 * expected to filter the code-completion results based on the text in this
2562 * chunk.
2563 */
2564 CXCompletionChunk_TypedText,
2565 /**
2566 * \brief Text that should be inserted as part of a code-completion result.
2567 *
2568 * A "text" chunk represents text that is part of the template to be
2569 * inserted into user code should this particular code-completion result
2570 * be selected.
2571 */
2572 CXCompletionChunk_Text,
2573 /**
2574 * \brief Placeholder text that should be replaced by the user.
2575 *
2576 * A "placeholder" chunk marks a place where the user should insert text
2577 * into the code-completion template. For example, placeholders might mark
2578 * the function parameters for a function declaration, to indicate that the
2579 * user should provide arguments for each of those parameters. The actual
2580 * text in a placeholder is a suggestion for the text to display before
2581 * the user replaces the placeholder with real code.
2582 */
2583 CXCompletionChunk_Placeholder,
2584 /**
2585 * \brief Informative text that should be displayed but never inserted as
2586 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002587 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002588 * An "informative" chunk contains annotations that can be displayed to
2589 * help the user decide whether a particular code-completion result is the
2590 * right option, but which is not part of the actual template to be inserted
2591 * by code completion.
2592 */
2593 CXCompletionChunk_Informative,
2594 /**
2595 * \brief Text that describes the current parameter when code-completion is
2596 * referring to function call, message send, or template specialization.
2597 *
2598 * A "current parameter" chunk occurs when code-completion is providing
2599 * information about a parameter corresponding to the argument at the
2600 * code-completion point. For example, given a function
2601 *
2602 * \code
2603 * int add(int x, int y);
2604 * \endcode
2605 *
2606 * and the source code \c add(, where the code-completion point is after the
2607 * "(", the code-completion string will contain a "current parameter" chunk
2608 * for "int x", indicating that the current argument will initialize that
2609 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002610 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002611 * "current paremeter" chunk to "int y".
2612 */
2613 CXCompletionChunk_CurrentParameter,
2614 /**
2615 * \brief A left parenthesis ('('), used to initiate a function call or
2616 * signal the beginning of a function parameter list.
2617 */
2618 CXCompletionChunk_LeftParen,
2619 /**
2620 * \brief A right parenthesis (')'), used to finish a function call or
2621 * signal the end of a function parameter list.
2622 */
2623 CXCompletionChunk_RightParen,
2624 /**
2625 * \brief A left bracket ('[').
2626 */
2627 CXCompletionChunk_LeftBracket,
2628 /**
2629 * \brief A right bracket (']').
2630 */
2631 CXCompletionChunk_RightBracket,
2632 /**
2633 * \brief A left brace ('{').
2634 */
2635 CXCompletionChunk_LeftBrace,
2636 /**
2637 * \brief A right brace ('}').
2638 */
2639 CXCompletionChunk_RightBrace,
2640 /**
2641 * \brief A left angle bracket ('<').
2642 */
2643 CXCompletionChunk_LeftAngle,
2644 /**
2645 * \brief A right angle bracket ('>').
2646 */
2647 CXCompletionChunk_RightAngle,
2648 /**
2649 * \brief A comma separator (',').
2650 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002651 CXCompletionChunk_Comma,
2652 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002653 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002654 *
2655 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002656 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002657 * expression using the given completion string would have.
2658 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002659 CXCompletionChunk_ResultType,
2660 /**
2661 * \brief A colon (':').
2662 */
2663 CXCompletionChunk_Colon,
2664 /**
2665 * \brief A semicolon (';').
2666 */
2667 CXCompletionChunk_SemiColon,
2668 /**
2669 * \brief An '=' sign.
2670 */
2671 CXCompletionChunk_Equal,
2672 /**
2673 * Horizontal space (' ').
2674 */
2675 CXCompletionChunk_HorizontalSpace,
2676 /**
2677 * Vertical space ('\n'), after which it is generally a good idea to
2678 * perform indentation.
2679 */
2680 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002681};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002682
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002683/**
2684 * \brief Determine the kind of a particular chunk within a completion string.
2685 *
2686 * \param completion_string the completion string to query.
2687 *
2688 * \param chunk_number the 0-based index of the chunk in the completion string.
2689 *
2690 * \returns the kind of the chunk at the index \c chunk_number.
2691 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002692CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002693clang_getCompletionChunkKind(CXCompletionString completion_string,
2694 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002695
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002696/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002697 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002698 * completion string.
2699 *
2700 * \param completion_string the completion string to query.
2701 *
2702 * \param chunk_number the 0-based index of the chunk in the completion string.
2703 *
2704 * \returns the text associated with the chunk at index \c chunk_number.
2705 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002706CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002707clang_getCompletionChunkText(CXCompletionString completion_string,
2708 unsigned chunk_number);
2709
2710/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002711 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002712 * within a completion string.
2713 *
2714 * \param completion_string the completion string to query.
2715 *
2716 * \param chunk_number the 0-based index of the chunk in the completion string.
2717 *
2718 * \returns the completion string associated with the chunk at index
2719 * \c chunk_number, or NULL if that chunk is not represented by a completion
2720 * string.
2721 */
2722CINDEX_LINKAGE CXCompletionString
2723clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2724 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002725
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002726/**
2727 * \brief Retrieve the number of chunks in the given code-completion string.
2728 */
2729CINDEX_LINKAGE unsigned
2730clang_getNumCompletionChunks(CXCompletionString completion_string);
2731
2732/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002733 * \brief Determine the priority of this code completion.
2734 *
2735 * The priority of a code completion indicates how likely it is that this
2736 * particular completion is the completion that the user will select. The
2737 * priority is selected by various internal heuristics.
2738 *
2739 * \param completion_string The completion string to query.
2740 *
2741 * \returns The priority of this completion string. Smaller values indicate
2742 * higher-priority (more likely) completions.
2743 */
2744CINDEX_LINKAGE unsigned
2745clang_getCompletionPriority(CXCompletionString completion_string);
2746
2747/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002748 * \brief Determine the availability of the entity that this code-completion
2749 * string refers to.
2750 *
2751 * \param completion_string The completion string to query.
2752 *
2753 * \returns The availability of the completion string.
2754 */
2755CINDEX_LINKAGE enum CXAvailabilityKind
2756clang_getCompletionAvailability(CXCompletionString completion_string);
2757
2758/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002759 * \brief Contains the results of code-completion.
2760 *
2761 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002762 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002763 * \c clang_disposeCodeCompleteResults.
2764 */
2765typedef struct {
2766 /**
2767 * \brief The code-completion results.
2768 */
2769 CXCompletionResult *Results;
2770
2771 /**
2772 * \brief The number of code-completion results stored in the
2773 * \c Results array.
2774 */
2775 unsigned NumResults;
2776} CXCodeCompleteResults;
2777
2778/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002779 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2780 * modify its behavior.
2781 *
2782 * The enumerators in this enumeration can be bitwise-OR'd together to
2783 * provide multiple options to \c clang_codeCompleteAt().
2784 */
2785enum CXCodeComplete_Flags {
2786 /**
2787 * \brief Whether to include macros within the set of code
2788 * completions returned.
2789 */
2790 CXCodeComplete_IncludeMacros = 0x01,
2791
2792 /**
2793 * \brief Whether to include code patterns for language constructs
2794 * within the set of code completions, e.g., for loops.
2795 */
2796 CXCodeComplete_IncludeCodePatterns = 0x02
2797};
2798
2799/**
2800 * \brief Returns a default set of code-completion options that can be
2801 * passed to\c clang_codeCompleteAt().
2802 */
2803CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
2804
2805/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002806 * \brief Perform code completion at a given location in a translation unit.
2807 *
2808 * This function performs code completion at a particular file, line, and
2809 * column within source code, providing results that suggest potential
2810 * code snippets based on the context of the completion. The basic model
2811 * for code completion is that Clang will parse a complete source file,
2812 * performing syntax checking up to the location where code-completion has
2813 * been requested. At that point, a special code-completion token is passed
2814 * to the parser, which recognizes this token and determines, based on the
2815 * current location in the C/Objective-C/C++ grammar and the state of
2816 * semantic analysis, what completions to provide. These completions are
2817 * returned via a new \c CXCodeCompleteResults structure.
2818 *
2819 * Code completion itself is meant to be triggered by the client when the
2820 * user types punctuation characters or whitespace, at which point the
2821 * code-completion location will coincide with the cursor. For example, if \c p
2822 * is a pointer, code-completion might be triggered after the "-" and then
2823 * after the ">" in \c p->. When the code-completion location is afer the ">",
2824 * the completion results will provide, e.g., the members of the struct that
2825 * "p" points to. The client is responsible for placing the cursor at the
2826 * beginning of the token currently being typed, then filtering the results
2827 * based on the contents of the token. For example, when code-completing for
2828 * the expression \c p->get, the client should provide the location just after
2829 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
2830 * client can filter the results based on the current token text ("get"), only
2831 * showing those results that start with "get". The intent of this interface
2832 * is to separate the relatively high-latency acquisition of code-completion
2833 * results from the filtering of results on a per-character basis, which must
2834 * have a lower latency.
2835 *
2836 * \param TU The translation unit in which code-completion should
2837 * occur. The source files for this translation unit need not be
2838 * completely up-to-date (and the contents of those source files may
2839 * be overridden via \p unsaved_files). Cursors referring into the
2840 * translation unit may be invalidated by this invocation.
2841 *
2842 * \param complete_filename The name of the source file where code
2843 * completion should be performed. This filename may be any file
2844 * included in the translation unit.
2845 *
2846 * \param complete_line The line at which code-completion should occur.
2847 *
2848 * \param complete_column The column at which code-completion should occur.
2849 * Note that the column should point just after the syntactic construct that
2850 * initiated code completion, and not in the middle of a lexical token.
2851 *
2852 * \param unsaved_files the Tiles that have not yet been saved to disk
2853 * but may be required for parsing or code completion, including the
2854 * contents of those files. The contents and name of these files (as
2855 * specified by CXUnsavedFile) are copied when necessary, so the
2856 * client only needs to guarantee their validity until the call to
2857 * this function returns.
2858 *
2859 * \param num_unsaved_files The number of unsaved file entries in \p
2860 * unsaved_files.
2861 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00002862 * \param options Extra options that control the behavior of code
2863 * completion, expressed as a bitwise OR of the enumerators of the
2864 * CXCodeComplete_Flags enumeration. The
2865 * \c clang_defaultCodeCompleteOptions() function returns a default set
2866 * of code-completion options.
2867 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002868 * \returns If successful, a new \c CXCodeCompleteResults structure
2869 * containing code-completion results, which should eventually be
2870 * freed with \c clang_disposeCodeCompleteResults(). If code
2871 * completion fails, returns NULL.
2872 */
2873CINDEX_LINKAGE
2874CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
2875 const char *complete_filename,
2876 unsigned complete_line,
2877 unsigned complete_column,
2878 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00002879 unsigned num_unsaved_files,
2880 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002881
2882/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00002883 * \brief Sort the code-completion results in case-insensitive alphabetical
2884 * order.
2885 *
2886 * \param Results The set of results to sort.
2887 * \param NumResults The number of results in \p Results.
2888 */
2889CINDEX_LINKAGE
2890void clang_sortCodeCompletionResults(CXCompletionResult *Results,
2891 unsigned NumResults);
2892
2893/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002894 * \brief Free the given set of code-completion results.
2895 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002896CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00002897void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00002898
Douglas Gregor20d416c2010-01-20 01:10:47 +00002899/**
Douglas Gregora88084b2010-02-18 18:08:43 +00002900 * \brief Determine the number of diagnostics produced prior to the
2901 * location where code completion was performed.
2902 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002903CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002904unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
2905
2906/**
2907 * \brief Retrieve a diagnostic associated with the given code completion.
2908 *
2909 * \param Result the code completion results to query.
2910 * \param Index the zero-based diagnostic number to retrieve.
2911 *
2912 * \returns the requested diagnostic. This diagnostic must be freed
2913 * via a call to \c clang_disposeDiagnostic().
2914 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002915CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002916CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
2917 unsigned Index);
2918
2919/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00002920 * @}
2921 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002922
2923
Ted Kremenek04bb7162010-01-22 22:44:15 +00002924/**
2925 * \defgroup CINDEX_MISC Miscellaneous utility functions
2926 *
2927 * @{
2928 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00002929
2930/**
2931 * \brief Return a version string, suitable for showing to a user, but not
2932 * intended to be parsed (the format is not guaranteed to be stable).
2933 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00002934CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00002935
Ted Kremenekd2427dd2011-03-18 23:05:39 +00002936
2937/**
2938 * \brief Enable/disable crash recovery.
2939 *
2940 * \param Flag to indicate if crash recovery is enabled. A non-zero value
2941 * enables crash recovery, while 0 disables it.
2942 */
2943CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
2944
Ted Kremenek16b55a72010-01-26 19:31:51 +00002945 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002946 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00002947 * (used with clang_getInclusions()).
2948 *
2949 * This visitor function will be invoked by clang_getInclusions() for each
2950 * file included (either at the top-level or by #include directives) within
2951 * a translation unit. The first argument is the file being included, and
2952 * the second and third arguments provide the inclusion stack. The
2953 * array is sorted in order of immediate inclusion. For example,
2954 * the first element refers to the location that included 'included_file'.
2955 */
2956typedef void (*CXInclusionVisitor)(CXFile included_file,
2957 CXSourceLocation* inclusion_stack,
2958 unsigned include_len,
2959 CXClientData client_data);
2960
2961/**
2962 * \brief Visit the set of preprocessor inclusions in a translation unit.
2963 * The visitor function is called with the provided data for every included
2964 * file. This does not include headers included by the PCH file (unless one
2965 * is inspecting the inclusions in the PCH file itself).
2966 */
2967CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
2968 CXInclusionVisitor visitor,
2969 CXClientData client_data);
2970
2971/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00002972 * @}
2973 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002974
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002975/**
2976 * @}
2977 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002978
Ted Kremenekd2fa5662009-08-26 22:36:44 +00002979#ifdef __cplusplus
2980}
2981#endif
2982#endif
2983