blob: cb0b3c1babcb2d4a1369ce0422eabb466737867e [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 Gregordd3e5542011-05-04 00:14:37 +0000225 * \brief Determine whether the given header is guarded against
226 * multiple inclusions, either with the conventional
227 * #ifndef/#define/#endif macro guards or with #pragma once.
228 */
229CINDEX_LINKAGE unsigned
230clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
231
232/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000233 * \brief Retrieve a file handle within the given translation unit.
234 *
235 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000236 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000237 * \param file_name the name of the file.
238 *
239 * \returns the file handle for the named file in the translation unit \p tu,
240 * or a NULL file handle if the file was not a part of this translation unit.
241 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000242CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000243 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000244
Douglas Gregorb9790342010-01-22 21:44:22 +0000245/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000246 * @}
247 */
248
249/**
250 * \defgroup CINDEX_LOCATIONS Physical source locations
251 *
252 * Clang represents physical source locations in its abstract syntax tree in
253 * great detail, with file, line, and column information for the majority of
254 * the tokens parsed in the source code. These data types and functions are
255 * used to represent source location information, either for a particular
256 * point in the program or for a range of points in the program, and extract
257 * specific location information from those data types.
258 *
259 * @{
260 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000261
Douglas Gregorf5525442010-01-20 22:45:41 +0000262/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000263 * \brief Identifies a specific source location within a translation
264 * unit.
265 *
Douglas Gregora9b06d42010-11-09 06:24:54 +0000266 * Use clang_getInstantiationLocation() or clang_getSpellingLocation()
267 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000268 */
269typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000270 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000271 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000272} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000273
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000274/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000275 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000276 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000277 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
278 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000279 */
280typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000281 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000282 unsigned begin_int_data;
283 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000284} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000285
Douglas Gregor1db19de2010-01-19 21:36:55 +0000286/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000287 * \brief Retrieve a NULL (invalid) source location.
288 */
289CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000290
Douglas Gregorb9790342010-01-22 21:44:22 +0000291/**
292 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000293 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000294 * code.
295 *
296 * \returns non-zero if the source locations refer to the same location, zero
297 * if they refer to different locations.
298 */
299CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
300 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000301
Douglas Gregorb9790342010-01-22 21:44:22 +0000302/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000303 * \brief Retrieves the source location associated with a given file/line/column
304 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000305 */
306CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
307 CXFile file,
308 unsigned line,
309 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000310/**
311 * \brief Retrieves the source location associated with a given character offset
312 * in a particular translation unit.
313 */
314CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
315 CXFile file,
316 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000317
Douglas Gregorb9790342010-01-22 21:44:22 +0000318/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000319 * \brief Retrieve a NULL (invalid) source range.
320 */
321CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000322
Douglas Gregor5352ac02010-01-28 00:27:43 +0000323/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000324 * \brief Retrieve a source range given the beginning and ending source
325 * locations.
326 */
327CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
328 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000329
Douglas Gregorb9790342010-01-22 21:44:22 +0000330/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000331 * \brief Retrieve the file, line, column, and offset represented by
332 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000333 *
Douglas Gregora9b06d42010-11-09 06:24:54 +0000334 * If the location refers into a macro instantiation, retrieves the
335 * location of the macro instantiation.
336 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000337 * \param location the location within a source file that will be decomposed
338 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000339 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000340 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000341 * source location points.
342 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000343 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000344 * source location points.
345 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000346 * \param column [out] if non-NULL, will be set to the column to which the given
347 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000348 *
349 * \param offset [out] if non-NULL, will be set to the offset into the
350 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000351 */
352CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
353 CXFile *file,
354 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000355 unsigned *column,
356 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000357
358/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000359 * \brief Retrieve the file, line, column, and offset represented by
360 * the given source location.
361 *
362 * If the location refers into a macro instantiation, return where the
363 * location was originally spelled in the source file.
364 *
365 * \param location the location within a source file that will be decomposed
366 * into its parts.
367 *
368 * \param file [out] if non-NULL, will be set to the file to which the given
369 * source location points.
370 *
371 * \param line [out] if non-NULL, will be set to the line to which the given
372 * source location points.
373 *
374 * \param column [out] if non-NULL, will be set to the column to which the given
375 * source location points.
376 *
377 * \param offset [out] if non-NULL, will be set to the offset into the
378 * buffer to which the given source location points.
379 */
380CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
381 CXFile *file,
382 unsigned *line,
383 unsigned *column,
384 unsigned *offset);
385
386/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000387 * \brief Retrieve a source location representing the first character within a
388 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000389 */
390CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
391
392/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000393 * \brief Retrieve a source location representing the last character within a
394 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000395 */
396CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
397
Douglas Gregorf5525442010-01-20 22:45:41 +0000398/**
399 * @}
400 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000401
402/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000403 * \defgroup CINDEX_DIAG Diagnostic reporting
404 *
405 * @{
406 */
407
408/**
409 * \brief Describes the severity of a particular diagnostic.
410 */
411enum CXDiagnosticSeverity {
412 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000413 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000414 * option.
415 */
416 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000417
Douglas Gregor5352ac02010-01-28 00:27:43 +0000418 /**
419 * \brief This diagnostic is a note that should be attached to the
420 * previous (non-note) diagnostic.
421 */
422 CXDiagnostic_Note = 1,
423
424 /**
425 * \brief This diagnostic indicates suspicious code that may not be
426 * wrong.
427 */
428 CXDiagnostic_Warning = 2,
429
430 /**
431 * \brief This diagnostic indicates that the code is ill-formed.
432 */
433 CXDiagnostic_Error = 3,
434
435 /**
436 * \brief This diagnostic indicates that the code is ill-formed such
437 * that future parser recovery is unlikely to produce useful
438 * results.
439 */
440 CXDiagnostic_Fatal = 4
441};
442
443/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000444 * \brief A single diagnostic, containing the diagnostic's severity,
445 * location, text, source ranges, and fix-it hints.
446 */
447typedef void *CXDiagnostic;
448
449/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000450 * \brief Determine the number of diagnostics produced for the given
451 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000452 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000453CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
454
455/**
456 * \brief Retrieve a diagnostic associated with the given translation unit.
457 *
458 * \param Unit the translation unit to query.
459 * \param Index the zero-based diagnostic number to retrieve.
460 *
461 * \returns the requested diagnostic. This diagnostic must be freed
462 * via a call to \c clang_disposeDiagnostic().
463 */
464CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
465 unsigned Index);
466
467/**
468 * \brief Destroy a diagnostic.
469 */
470CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000471
472/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000473 * \brief Options to control the display of diagnostics.
474 *
475 * The values in this enum are meant to be combined to customize the
476 * behavior of \c clang_displayDiagnostic().
477 */
478enum CXDiagnosticDisplayOptions {
479 /**
480 * \brief Display the source-location information where the
481 * diagnostic was located.
482 *
483 * When set, diagnostics will be prefixed by the file, line, and
484 * (optionally) column to which the diagnostic refers. For example,
485 *
486 * \code
487 * test.c:28: warning: extra tokens at end of #endif directive
488 * \endcode
489 *
490 * This option corresponds to the clang flag \c -fshow-source-location.
491 */
492 CXDiagnostic_DisplaySourceLocation = 0x01,
493
494 /**
495 * \brief If displaying the source-location information of the
496 * diagnostic, also include the column number.
497 *
498 * This option corresponds to the clang flag \c -fshow-column.
499 */
500 CXDiagnostic_DisplayColumn = 0x02,
501
502 /**
503 * \brief If displaying the source-location information of the
504 * diagnostic, also include information about source ranges in a
505 * machine-parsable format.
506 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000507 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000508 * \c -fdiagnostics-print-source-range-info.
509 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000510 CXDiagnostic_DisplaySourceRanges = 0x04,
511
512 /**
513 * \brief Display the option name associated with this diagnostic, if any.
514 *
515 * The option name displayed (e.g., -Wconversion) will be placed in brackets
516 * after the diagnostic text. This option corresponds to the clang flag
517 * \c -fdiagnostics-show-option.
518 */
519 CXDiagnostic_DisplayOption = 0x08,
520
521 /**
522 * \brief Display the category number associated with this diagnostic, if any.
523 *
524 * The category number is displayed within brackets after the diagnostic text.
525 * This option corresponds to the clang flag
526 * \c -fdiagnostics-show-category=id.
527 */
528 CXDiagnostic_DisplayCategoryId = 0x10,
529
530 /**
531 * \brief Display the category name associated with this diagnostic, if any.
532 *
533 * The category name is displayed within brackets after the diagnostic text.
534 * This option corresponds to the clang flag
535 * \c -fdiagnostics-show-category=name.
536 */
537 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000538};
539
540/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000541 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000542 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000543 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000544 * the diagnostic according to the various options given. The
545 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000546 * options that most closely mimics the behavior of the clang compiler.
547 *
548 * \param Diagnostic The diagnostic to print.
549 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000550 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000551 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000552 *
553 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000554 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000555CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
556 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000557
558/**
559 * \brief Retrieve the set of display options most similar to the
560 * default behavior of the clang compiler.
561 *
562 * \returns A set of display options suitable for use with \c
563 * clang_displayDiagnostic().
564 */
565CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
566
567/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000568 * \brief Determine the severity of the given diagnostic.
569 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000570CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000571clang_getDiagnosticSeverity(CXDiagnostic);
572
573/**
574 * \brief Retrieve the source location of the given diagnostic.
575 *
576 * This location is where Clang would print the caret ('^') when
577 * displaying the diagnostic on the command line.
578 */
579CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
580
581/**
582 * \brief Retrieve the text of the given diagnostic.
583 */
584CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000585
586/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000587 * \brief Retrieve the name of the command-line option that enabled this
588 * diagnostic.
589 *
590 * \param Diag The diagnostic to be queried.
591 *
592 * \param Disable If non-NULL, will be set to the option that disables this
593 * diagnostic (if any).
594 *
595 * \returns A string that contains the command-line option used to enable this
596 * warning, such as "-Wconversion" or "-pedantic".
597 */
598CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
599 CXString *Disable);
600
601/**
602 * \brief Retrieve the category number for this diagnostic.
603 *
604 * Diagnostics can be categorized into groups along with other, related
605 * diagnostics (e.g., diagnostics under the same warning flag). This routine
606 * retrieves the category number for the given diagnostic.
607 *
608 * \returns The number of the category that contains this diagnostic, or zero
609 * if this diagnostic is uncategorized.
610 */
611CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
612
613/**
614 * \brief Retrieve the name of a particular diagnostic category.
615 *
616 * \param Category A diagnostic category number, as returned by
617 * \c clang_getDiagnosticCategory().
618 *
619 * \returns The name of the given diagnostic category.
620 */
621CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
622
623/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000624 * \brief Determine the number of source ranges associated with the given
625 * diagnostic.
626 */
627CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000628
Douglas Gregor5352ac02010-01-28 00:27:43 +0000629/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000630 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000631 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000632 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000633 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000634 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000635 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000636 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000637 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000638 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000639 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000640 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000641 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000642CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000643 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000644
645/**
646 * \brief Determine the number of fix-it hints associated with the
647 * given diagnostic.
648 */
649CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
650
651/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000652 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000653 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000654 * Fix-its are described in terms of a source range whose contents
655 * should be replaced by a string. This approach generalizes over
656 * three kinds of operations: removal of source code (the range covers
657 * the code to be removed and the replacement string is empty),
658 * replacement of source code (the range covers the code to be
659 * replaced and the replacement string provides the new code), and
660 * insertion (both the start and end of the range point at the
661 * insertion location, and the replacement string provides the text to
662 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000663 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000664 * \param Diagnostic The diagnostic whose fix-its are being queried.
665 *
666 * \param FixIt The zero-based index of the fix-it.
667 *
668 * \param ReplacementRange The source range whose contents will be
669 * replaced with the returned replacement string. Note that source
670 * ranges are half-open ranges [a, b), so the source code should be
671 * replaced from a and up to (but not including) b.
672 *
673 * \returns A string containing text that should be replace the source
674 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000675 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000676CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000677 unsigned FixIt,
678 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000679
680/**
681 * @}
682 */
683
684/**
685 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
686 *
687 * The routines in this group provide the ability to create and destroy
688 * translation units from files, either by parsing the contents of the files or
689 * by reading in a serialized representation of a translation unit.
690 *
691 * @{
692 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000693
Douglas Gregor5352ac02010-01-28 00:27:43 +0000694/**
695 * \brief Get the original translation unit source file name.
696 */
697CINDEX_LINKAGE CXString
698clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
699
700/**
701 * \brief Return the CXTranslationUnit for a given source file and the provided
702 * command line arguments one would pass to the compiler.
703 *
704 * Note: The 'source_filename' argument is optional. If the caller provides a
705 * NULL pointer, the name of the source file is expected to reside in the
706 * specified command line arguments.
707 *
708 * Note: When encountered in 'clang_command_line_args', the following options
709 * are ignored:
710 *
711 * '-c'
712 * '-emit-ast'
713 * '-fsyntax-only'
714 * '-o <output file>' (both '-o' and '<output file>' are ignored)
715 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000716 * \param CIdx The index object with which the translation unit will be
717 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000718 *
719 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000720 * source file is included in \p clang_command_line_args.
721 *
722 * \param num_clang_command_line_args The number of command-line arguments in
723 * \p clang_command_line_args.
724 *
725 * \param clang_command_line_args The command-line arguments that would be
726 * passed to the \c clang executable if it were being invoked out-of-process.
727 * These command-line options will be parsed and will affect how the translation
728 * unit is parsed. Note that the following options are ignored: '-c',
729 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000730 *
731 * \param num_unsaved_files the number of unsaved file entries in \p
732 * unsaved_files.
733 *
734 * \param unsaved_files the files that have not yet been saved to disk
735 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000736 * those files. The contents and name of these files (as specified by
737 * CXUnsavedFile) are copied when necessary, so the client only needs to
738 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000739 */
740CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
741 CXIndex CIdx,
742 const char *source_filename,
743 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000744 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000745 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000746 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000747
Douglas Gregor5352ac02010-01-28 00:27:43 +0000748/**
749 * \brief Create a translation unit from an AST file (-emit-ast).
750 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000751CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000752 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000753
Douglas Gregor44c181a2010-07-23 00:33:23 +0000754/**
755 * \brief Flags that control the creation of translation units.
756 *
757 * The enumerators in this enumeration type are meant to be bitwise
758 * ORed together to specify which options should be used when
759 * constructing the translation unit.
760 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000761enum CXTranslationUnit_Flags {
762 /**
763 * \brief Used to indicate that no special translation-unit options are
764 * needed.
765 */
766 CXTranslationUnit_None = 0x0,
767
768 /**
769 * \brief Used to indicate that the parser should construct a "detailed"
770 * preprocessing record, including all macro definitions and instantiations.
771 *
772 * Constructing a detailed preprocessing record requires more memory
773 * and time to parse, since the information contained in the record
774 * is usually not retained. However, it can be useful for
775 * applications that require more detailed information about the
776 * behavior of the preprocessor.
777 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000778 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
779
780 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000781 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000782 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000783 * When a translation unit is considered "incomplete", semantic
784 * analysis that is typically performed at the end of the
785 * translation unit will be suppressed. For example, this suppresses
786 * the completion of tentative declarations in C and of
787 * instantiation of implicitly-instantiation function templates in
788 * C++. This option is typically used when parsing a header with the
789 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000790 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000791 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000792
793 /**
794 * \brief Used to indicate that the translation unit should be built with an
795 * implicit precompiled header for the preamble.
796 *
797 * An implicit precompiled header is used as an optimization when a
798 * particular translation unit is likely to be reparsed many times
799 * when the sources aren't changing that often. In this case, an
800 * implicit precompiled header will be built containing all of the
801 * initial includes at the top of the main file (what we refer to as
802 * the "preamble" of the file). In subsequent parses, if the
803 * preamble or the files in it have not changed, \c
804 * clang_reparseTranslationUnit() will re-use the implicit
805 * precompiled header to improve parsing performance.
806 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000807 CXTranslationUnit_PrecompiledPreamble = 0x04,
808
809 /**
810 * \brief Used to indicate that the translation unit should cache some
811 * code-completion results with each reparse of the source file.
812 *
813 * Caching of code-completion results is a performance optimization that
814 * introduces some overhead to reparsing but improves the performance of
815 * code-completion operations.
816 */
Douglas Gregor99ba2022010-10-27 17:24:53 +0000817 CXTranslationUnit_CacheCompletionResults = 0x08,
818 /**
819 * \brief Enable 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_CXXPrecompiledPreamble = 0x10,
825
826 /**
827 * \brief Enabled chained precompiled preambles in C++.
828 *
829 * Note: this is a *temporary* option that is available only while
830 * we are testing C++ precompiled preamble support.
831 */
Douglas Gregordca8ee82011-05-06 16:33:08 +0000832 CXTranslationUnit_CXXChainedPCH = 0x20,
833
834 /**
835 * \brief Used to indicate that the "detailed" preprocessing record,
836 * if requested, should also contain nested macro instantiations.
837 *
838 * Nested macro instantiations (i.e., macro instantiations that occur
839 * inside another macro instantiation) can, in some code bases, require
840 * a large amount of storage to due preprocessor metaprogramming. Moreover,
841 * its fairly rare that this information is useful for libclang clients.
842 */
843 CXTranslationUnit_NestedMacroInstantiations = 0x40
Douglas Gregor5a430212010-07-21 18:52:53 +0000844};
845
846/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000847 * \brief Returns the set of flags that is suitable for parsing a translation
848 * unit that is being edited.
849 *
850 * The set of flags returned provide options for \c clang_parseTranslationUnit()
851 * to indicate that the translation unit is likely to be reparsed many times,
852 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
853 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
854 * set contains an unspecified set of optimizations (e.g., the precompiled
855 * preamble) geared toward improving the performance of these routines. The
856 * set of optimizations enabled may change from one version to the next.
857 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000858CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000859
860/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000861 * \brief Parse the given source file and the translation unit corresponding
862 * to that file.
863 *
864 * This routine is the main entry point for the Clang C API, providing the
865 * ability to parse a source file into a translation unit that can then be
866 * queried by other functions in the API. This routine accepts a set of
867 * command-line arguments so that the compilation can be configured in the same
868 * way that the compiler is configured on the command line.
869 *
870 * \param CIdx The index object with which the translation unit will be
871 * associated.
872 *
873 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000874 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +0000875 *
876 * \param command_line_args The command-line arguments that would be
877 * passed to the \c clang executable if it were being invoked out-of-process.
878 * These command-line options will be parsed and will affect how the translation
879 * unit is parsed. Note that the following options are ignored: '-c',
880 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
881 *
882 * \param num_command_line_args The number of command-line arguments in
883 * \p command_line_args.
884 *
885 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000886 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000887 * those files. The contents and name of these files (as specified by
888 * CXUnsavedFile) are copied when necessary, so the client only needs to
889 * guarantee their validity until the call to this function returns.
890 *
891 * \param num_unsaved_files the number of unsaved file entries in \p
892 * unsaved_files.
893 *
894 * \param options A bitmask of options that affects how the translation unit
895 * is managed but not its compilation. This should be a bitwise OR of the
896 * CXTranslationUnit_XXX flags.
897 *
898 * \returns A new translation unit describing the parsed code and containing
899 * any diagnostics produced by the compiler. If there is a failure from which
900 * the compiler cannot recover, returns NULL.
901 */
902CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
903 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000904 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000905 int num_command_line_args,
906 struct CXUnsavedFile *unsaved_files,
907 unsigned num_unsaved_files,
908 unsigned options);
909
Douglas Gregor5352ac02010-01-28 00:27:43 +0000910/**
Douglas Gregor19998442010-08-13 15:35:05 +0000911 * \brief Flags that control how translation units are saved.
912 *
913 * The enumerators in this enumeration type are meant to be bitwise
914 * ORed together to specify which options should be used when
915 * saving the translation unit.
916 */
917enum CXSaveTranslationUnit_Flags {
918 /**
919 * \brief Used to indicate that no special saving options are needed.
920 */
921 CXSaveTranslationUnit_None = 0x0
922};
923
924/**
925 * \brief Returns the set of flags that is suitable for saving a translation
926 * unit.
927 *
928 * The set of flags returned provide options for
929 * \c clang_saveTranslationUnit() by default. The returned flag
930 * set contains an unspecified set of options that save translation units with
931 * the most commonly-requested data.
932 */
933CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
934
935/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000936 * \brief Saves a translation unit into a serialized representation of
937 * that translation unit on disk.
938 *
939 * Any translation unit that was parsed without error can be saved
940 * into a file. The translation unit can then be deserialized into a
941 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
942 * if it is an incomplete translation unit that corresponds to a
943 * header, used as a precompiled header when parsing other translation
944 * units.
945 *
946 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +0000947 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000948 * \param FileName The file to which the translation unit will be saved.
949 *
Douglas Gregor19998442010-08-13 15:35:05 +0000950 * \param options A bitmask of options that affects how the translation unit
951 * is saved. This should be a bitwise OR of the
952 * CXSaveTranslationUnit_XXX flags.
953 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000954 * \returns Zero if the translation unit was saved successfully, a
955 * non-zero value otherwise.
956 */
957CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +0000958 const char *FileName,
959 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000960
961/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000962 * \brief Destroy the specified CXTranslationUnit object.
963 */
964CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000965
Douglas Gregor5352ac02010-01-28 00:27:43 +0000966/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000967 * \brief Flags that control the reparsing of translation units.
968 *
969 * The enumerators in this enumeration type are meant to be bitwise
970 * ORed together to specify which options should be used when
971 * reparsing the translation unit.
972 */
973enum CXReparse_Flags {
974 /**
975 * \brief Used to indicate that no special reparsing options are needed.
976 */
977 CXReparse_None = 0x0
978};
979
980/**
981 * \brief Returns the set of flags that is suitable for reparsing a translation
982 * unit.
983 *
984 * The set of flags returned provide options for
985 * \c clang_reparseTranslationUnit() by default. The returned flag
986 * set contains an unspecified set of optimizations geared toward common uses
987 * of reparsing. The set of optimizations enabled may change from one version
988 * to the next.
989 */
990CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
991
992/**
Douglas Gregorabc563f2010-07-19 21:46:24 +0000993 * \brief Reparse the source files that produced this translation unit.
994 *
995 * This routine can be used to re-parse the source files that originally
996 * created the given translation unit, for example because those source files
997 * have changed (either on disk or as passed via \p unsaved_files). The
998 * source code will be reparsed with the same command-line options as it
999 * was originally parsed.
1000 *
1001 * Reparsing a translation unit invalidates all cursors and source locations
1002 * that refer into that translation unit. This makes reparsing a translation
1003 * unit semantically equivalent to destroying the translation unit and then
1004 * creating a new translation unit with the same command-line arguments.
1005 * However, it may be more efficient to reparse a translation
1006 * unit using this routine.
1007 *
1008 * \param TU The translation unit whose contents will be re-parsed. The
1009 * translation unit must originally have been built with
1010 * \c clang_createTranslationUnitFromSourceFile().
1011 *
1012 * \param num_unsaved_files The number of unsaved file entries in \p
1013 * unsaved_files.
1014 *
1015 * \param unsaved_files The files that have not yet been saved to disk
1016 * but may be required for parsing, including the contents of
1017 * those files. The contents and name of these files (as specified by
1018 * CXUnsavedFile) are copied when necessary, so the client only needs to
1019 * guarantee their validity until the call to this function returns.
1020 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001021 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1022 * The function \c clang_defaultReparseOptions() produces a default set of
1023 * options recommended for most uses, based on the translation unit.
1024 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001025 * \returns 0 if the sources could be reparsed. A non-zero value will be
1026 * returned if reparsing was impossible, such that the translation unit is
1027 * invalid. In such cases, the only valid call for \p TU is
1028 * \c clang_disposeTranslationUnit(TU).
1029 */
1030CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1031 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001032 struct CXUnsavedFile *unsaved_files,
1033 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001034
1035/**
1036 * \brief Categorizes how memory is being used by a translation unit.
1037 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001038enum CXTUResourceUsageKind {
1039 CXTUResourceUsage_AST = 1,
1040 CXTUResourceUsage_Identifiers = 2,
1041 CXTUResourceUsage_Selectors = 3,
1042 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001043 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001044 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001045 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001046 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1047 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1048 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001049 CXTUResourceUsage_Preprocessor = 11,
1050 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekf7870022011-04-20 16:41:07 +00001051 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1052 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001053 CXTUResourceUsage_PreprocessingRecord,
Ted Kremenekf7870022011-04-20 16:41:07 +00001054
1055 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001056 CXTUResourceUsage_Last = CXTUResourceUsage_PreprocessingRecord
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001057};
1058
1059/**
1060 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001061 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001062 */
1063CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001064const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001065
Ted Kremenekf7870022011-04-20 16:41:07 +00001066typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001067 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001068 enum CXTUResourceUsageKind kind;
1069 /* \brief Amount of resources used.
1070 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001071 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001072} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001073
1074/**
1075 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1076 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001077typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001078 /* \brief Private data member, used for queries. */
1079 void *data;
1080
1081 /* \brief The number of entries in the 'entries' array. */
1082 unsigned numEntries;
1083
1084 /* \brief An array of key-value pairs, representing the breakdown of memory
1085 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001086 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001087
Ted Kremenekf7870022011-04-20 16:41:07 +00001088} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001089
1090/**
1091 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001092 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001093 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001094CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001095
Ted Kremenekf7870022011-04-20 16:41:07 +00001096CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001097
Douglas Gregorabc563f2010-07-19 21:46:24 +00001098/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001099 * @}
1100 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001101
Douglas Gregor5352ac02010-01-28 00:27:43 +00001102/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001103 * \brief Describes the kind of entity that a cursor refers to.
1104 */
1105enum CXCursorKind {
1106 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001107 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001108 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001109 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001110 *
1111 * Unexposed declarations have the same operations as any other kind
1112 * of declaration; one can extract their location information,
1113 * spelling, find their definitions, etc. However, the specific kind
1114 * of the declaration is not reported.
1115 */
1116 CXCursor_UnexposedDecl = 1,
1117 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001118 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001119 /** \brief A C or C++ union. */
1120 CXCursor_UnionDecl = 3,
1121 /** \brief A C++ class. */
1122 CXCursor_ClassDecl = 4,
1123 /** \brief An enumeration. */
1124 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001125 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001126 * \brief A field (in C) or non-static data member (in C++) in a
1127 * struct, union, or C++ class.
1128 */
1129 CXCursor_FieldDecl = 6,
1130 /** \brief An enumerator constant. */
1131 CXCursor_EnumConstantDecl = 7,
1132 /** \brief A function. */
1133 CXCursor_FunctionDecl = 8,
1134 /** \brief A variable. */
1135 CXCursor_VarDecl = 9,
1136 /** \brief A function or method parameter. */
1137 CXCursor_ParmDecl = 10,
1138 /** \brief An Objective-C @interface. */
1139 CXCursor_ObjCInterfaceDecl = 11,
1140 /** \brief An Objective-C @interface for a category. */
1141 CXCursor_ObjCCategoryDecl = 12,
1142 /** \brief An Objective-C @protocol declaration. */
1143 CXCursor_ObjCProtocolDecl = 13,
1144 /** \brief An Objective-C @property declaration. */
1145 CXCursor_ObjCPropertyDecl = 14,
1146 /** \brief An Objective-C instance variable. */
1147 CXCursor_ObjCIvarDecl = 15,
1148 /** \brief An Objective-C instance method. */
1149 CXCursor_ObjCInstanceMethodDecl = 16,
1150 /** \brief An Objective-C class method. */
1151 CXCursor_ObjCClassMethodDecl = 17,
1152 /** \brief An Objective-C @implementation. */
1153 CXCursor_ObjCImplementationDecl = 18,
1154 /** \brief An Objective-C @implementation for a category. */
1155 CXCursor_ObjCCategoryImplDecl = 19,
1156 /** \brief A typedef */
1157 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001158 /** \brief A C++ class method. */
1159 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001160 /** \brief A C++ namespace. */
1161 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001162 /** \brief A linkage specification, e.g. 'extern "C"'. */
1163 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001164 /** \brief A C++ constructor. */
1165 CXCursor_Constructor = 24,
1166 /** \brief A C++ destructor. */
1167 CXCursor_Destructor = 25,
1168 /** \brief A C++ conversion function. */
1169 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001170 /** \brief A C++ template type parameter. */
1171 CXCursor_TemplateTypeParameter = 27,
1172 /** \brief A C++ non-type template parameter. */
1173 CXCursor_NonTypeTemplateParameter = 28,
1174 /** \brief A C++ template template parameter. */
1175 CXCursor_TemplateTemplateParameter = 29,
1176 /** \brief A C++ function template. */
1177 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001178 /** \brief A C++ class template. */
1179 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001180 /** \brief A C++ class template partial specialization. */
1181 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001182 /** \brief A C++ namespace alias declaration. */
1183 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001184 /** \brief A C++ using directive. */
1185 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001186 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001187 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001188 /** \brief A C++ alias declaration */
1189 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001190 /** \brief An Objective-C @synthesize definition. */
1191 CXCursor_ObjCSynthesizeDecl = 37,
1192 /** \brief An Objective-C @dynamic definition. */
1193 CXCursor_ObjCDynamicDecl = 38,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001194 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor352697a2011-06-03 23:08:58 +00001195 CXCursor_LastDecl = CXCursor_ObjCDynamicDecl,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001196
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001197 /* References */
1198 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001199 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001200 CXCursor_ObjCProtocolRef = 41,
1201 CXCursor_ObjCClassRef = 42,
1202 /**
1203 * \brief A reference to a type declaration.
1204 *
1205 * A type reference occurs anywhere where a type is named but not
1206 * declared. For example, given:
1207 *
1208 * \code
1209 * typedef unsigned size_type;
1210 * size_type size;
1211 * \endcode
1212 *
1213 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1214 * while the type of the variable "size" is referenced. The cursor
1215 * referenced by the type of size is the typedef for size_type.
1216 */
1217 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001218 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001219 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001220 * \brief A reference to a class template, function template, template
1221 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001222 */
1223 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001224 /**
1225 * \brief A reference to a namespace or namespace alias.
1226 */
1227 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001228 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001229 * \brief A reference to a member of a struct, union, or class that occurs in
1230 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001231 */
1232 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001233 /**
1234 * \brief A reference to a labeled statement.
1235 *
1236 * This cursor kind is used to describe the jump to "start_over" in the
1237 * goto statement in the following example:
1238 *
1239 * \code
1240 * start_over:
1241 * ++counter;
1242 *
1243 * goto start_over;
1244 * \endcode
1245 *
1246 * A label reference cursor refers to a label statement.
1247 */
1248 CXCursor_LabelRef = 48,
1249
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001250 /**
1251 * \brief A reference to a set of overloaded functions or function templates
1252 * that has not yet been resolved to a specific function or function template.
1253 *
1254 * An overloaded declaration reference cursor occurs in C++ templates where
1255 * a dependent name refers to a function. For example:
1256 *
1257 * \code
1258 * template<typename T> void swap(T&, T&);
1259 *
1260 * struct X { ... };
1261 * void swap(X&, X&);
1262 *
1263 * template<typename T>
1264 * void reverse(T* first, T* last) {
1265 * while (first < last - 1) {
1266 * swap(*first, *--last);
1267 * ++first;
1268 * }
1269 * }
1270 *
1271 * struct Y { };
1272 * void swap(Y&, Y&);
1273 * \endcode
1274 *
1275 * Here, the identifier "swap" is associated with an overloaded declaration
1276 * reference. In the template definition, "swap" refers to either of the two
1277 * "swap" functions declared above, so both results will be available. At
1278 * instantiation time, "swap" may also refer to other functions found via
1279 * argument-dependent lookup (e.g., the "swap" function at the end of the
1280 * example).
1281 *
1282 * The functions \c clang_getNumOverloadedDecls() and
1283 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1284 * referenced by this cursor.
1285 */
1286 CXCursor_OverloadedDeclRef = 49,
1287
1288 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001289
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001290 /* Error conditions */
1291 CXCursor_FirstInvalid = 70,
1292 CXCursor_InvalidFile = 70,
1293 CXCursor_NoDeclFound = 71,
1294 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001295 CXCursor_InvalidCode = 73,
1296 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001297
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001298 /* Expressions */
1299 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001300
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001301 /**
1302 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001303 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001304 *
1305 * Unexposed expressions have the same operations as any other kind
1306 * of expression; one can extract their location information,
1307 * spelling, children, etc. However, the specific kind of the
1308 * expression is not reported.
1309 */
1310 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001311
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001312 /**
1313 * \brief An expression that refers to some value declaration, such
1314 * as a function, varible, or enumerator.
1315 */
1316 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001317
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001318 /**
1319 * \brief An expression that refers to a member of a struct, union,
1320 * class, Objective-C class, etc.
1321 */
1322 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001323
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001324 /** \brief An expression that calls a function. */
1325 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001326
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001327 /** \brief An expression that sends a message to an Objective-C
1328 object or class. */
1329 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001330
1331 /** \brief An expression that represents a block literal. */
1332 CXCursor_BlockExpr = 105,
1333
1334 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001335
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001336 /* Statements */
1337 CXCursor_FirstStmt = 200,
1338 /**
1339 * \brief A statement whose specific kind is not exposed via this
1340 * interface.
1341 *
1342 * Unexposed statements have the same operations as any other kind of
1343 * statement; one can extract their location information, spelling,
1344 * children, etc. However, the specific kind of the statement is not
1345 * reported.
1346 */
1347 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001348
1349 /** \brief A labelled statement in a function.
1350 *
1351 * This cursor kind is used to describe the "start_over:" label statement in
1352 * the following example:
1353 *
1354 * \code
1355 * start_over:
1356 * ++counter;
1357 * \endcode
1358 *
1359 */
1360 CXCursor_LabelStmt = 201,
1361
1362 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001363
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001364 /**
1365 * \brief Cursor that represents the translation unit itself.
1366 *
1367 * The translation unit cursor exists primarily to act as the root
1368 * cursor for traversing the contents of a translation unit.
1369 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001370 CXCursor_TranslationUnit = 300,
1371
1372 /* Attributes */
1373 CXCursor_FirstAttr = 400,
1374 /**
1375 * \brief An attribute whose specific kind is not exposed via this
1376 * interface.
1377 */
1378 CXCursor_UnexposedAttr = 400,
1379
1380 CXCursor_IBActionAttr = 401,
1381 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001382 CXCursor_IBOutletCollectionAttr = 403,
1383 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001384
1385 /* Preprocessing */
1386 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001387 CXCursor_MacroDefinition = 501,
1388 CXCursor_MacroInstantiation = 502,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001389 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001390 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001391 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001392};
1393
1394/**
1395 * \brief A cursor representing some element in the abstract syntax tree for
1396 * a translation unit.
1397 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001398 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001399 * program--declaration, statements, expressions, references to declarations,
1400 * etc.--under a single "cursor" abstraction with a common set of operations.
1401 * Common operation for a cursor include: getting the physical location in
1402 * a source file where the cursor points, getting the name associated with a
1403 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1404 *
1405 * Cursors can be produced in two specific ways.
1406 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1407 * from which one can use clang_visitChildren() to explore the rest of the
1408 * translation unit. clang_getCursor() maps from a physical source location
1409 * to the entity that resides at that location, allowing one to map from the
1410 * source code into the AST.
1411 */
1412typedef struct {
1413 enum CXCursorKind kind;
1414 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001415} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001416
1417/**
1418 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1419 *
1420 * @{
1421 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001422
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001423/**
1424 * \brief Retrieve the NULL cursor, which represents no entity.
1425 */
1426CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001427
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001428/**
1429 * \brief Retrieve the cursor that represents the given translation unit.
1430 *
1431 * The translation unit cursor can be used to start traversing the
1432 * various declarations within the given translation unit.
1433 */
1434CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1435
1436/**
1437 * \brief Determine whether two cursors are equivalent.
1438 */
1439CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001440
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001441/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001442 * \brief Compute a hash value for the given cursor.
1443 */
1444CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1445
1446/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001447 * \brief Retrieve the kind of the given cursor.
1448 */
1449CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1450
1451/**
1452 * \brief Determine whether the given cursor kind represents a declaration.
1453 */
1454CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1455
1456/**
1457 * \brief Determine whether the given cursor kind represents a simple
1458 * reference.
1459 *
1460 * Note that other kinds of cursors (such as expressions) can also refer to
1461 * other cursors. Use clang_getCursorReferenced() to determine whether a
1462 * particular cursor refers to another entity.
1463 */
1464CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1465
1466/**
1467 * \brief Determine whether the given cursor kind represents an expression.
1468 */
1469CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1470
1471/**
1472 * \brief Determine whether the given cursor kind represents a statement.
1473 */
1474CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1475
1476/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001477 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001478 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001479 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001480CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1481
1482/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001483 * \brief Determine whether the given cursor kind represents a translation
1484 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001485 */
1486CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001487
Ted Kremenekad6eff62010-03-08 21:17:29 +00001488/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001489 * \brief Determine whether the given cursor represents a preprocessing
1490 * element, such as a preprocessor directive or macro instantiation.
1491 */
1492CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1493
1494/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001495 * \brief Determine whether the given cursor represents a currently
1496 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1497 */
1498CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1499
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001500/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001501 * \brief Describe the linkage of the entity referred to by a cursor.
1502 */
1503enum CXLinkageKind {
1504 /** \brief This value indicates that no linkage information is available
1505 * for a provided CXCursor. */
1506 CXLinkage_Invalid,
1507 /**
1508 * \brief This is the linkage for variables, parameters, and so on that
1509 * have automatic storage. This covers normal (non-extern) local variables.
1510 */
1511 CXLinkage_NoLinkage,
1512 /** \brief This is the linkage for static variables and static functions. */
1513 CXLinkage_Internal,
1514 /** \brief This is the linkage for entities with external linkage that live
1515 * in C++ anonymous namespaces.*/
1516 CXLinkage_UniqueExternal,
1517 /** \brief This is the linkage for entities with true, external linkage. */
1518 CXLinkage_External
1519};
1520
1521/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001522 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001523 */
1524CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1525
1526/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001527 * \brief Determine the availability of the entity that this cursor refers to.
1528 *
1529 * \param cursor The cursor to query.
1530 *
1531 * \returns The availability of the cursor.
1532 */
1533CINDEX_LINKAGE enum CXAvailabilityKind
1534clang_getCursorAvailability(CXCursor cursor);
1535
1536/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001537 * \brief Describe the "language" of the entity referred to by a cursor.
1538 */
1539CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001540 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001541 CXLanguage_C,
1542 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001543 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001544};
1545
1546/**
1547 * \brief Determine the "language" of the entity referred to by a given cursor.
1548 */
1549CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1550
Ted Kremenekeca099b2010-12-08 23:43:14 +00001551
1552/**
1553 * \brief A fast container representing a set of CXCursors.
1554 */
1555typedef struct CXCursorSetImpl *CXCursorSet;
1556
1557/**
1558 * \brief Creates an empty CXCursorSet.
1559 */
1560CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
1561
1562/**
1563 * \brief Disposes a CXCursorSet and releases its associated memory.
1564 */
1565CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
1566
1567/**
1568 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
1569 *
1570 * \returns non-zero if the set contains the specified cursor.
1571*/
1572CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
1573 CXCursor cursor);
1574
1575/**
1576 * \brief Inserts a CXCursor into a CXCursorSet.
1577 *
1578 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
1579*/
1580CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
1581 CXCursor cursor);
1582
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001583/**
1584 * \brief Determine the semantic parent of the given cursor.
1585 *
1586 * The semantic parent of a cursor is the cursor that semantically contains
1587 * the given \p cursor. For many declarations, the lexical and semantic parents
1588 * are equivalent (the lexical parent is returned by
1589 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1590 * definitions are provided out-of-line. For example:
1591 *
1592 * \code
1593 * class C {
1594 * void f();
1595 * };
1596 *
1597 * void C::f() { }
1598 * \endcode
1599 *
1600 * In the out-of-line definition of \c C::f, the semantic parent is the
1601 * the class \c C, of which this function is a member. The lexical parent is
1602 * the place where the declaration actually occurs in the source code; in this
1603 * case, the definition occurs in the translation unit. In general, the
1604 * lexical parent for a given entity can change without affecting the semantics
1605 * of the program, and the lexical parent of different declarations of the
1606 * same entity may be different. Changing the semantic parent of a declaration,
1607 * on the other hand, can have a major impact on semantics, and redeclarations
1608 * of a particular entity should all have the same semantic context.
1609 *
1610 * In the example above, both declarations of \c C::f have \c C as their
1611 * semantic context, while the lexical context of the first \c C::f is \c C
1612 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001613 *
1614 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001615 */
1616CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1617
1618/**
1619 * \brief Determine the lexical parent of the given cursor.
1620 *
1621 * The lexical parent of a cursor is the cursor in which the given \p cursor
1622 * was actually written. For many declarations, the lexical and semantic parents
1623 * are equivalent (the semantic parent is returned by
1624 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1625 * definitions are provided out-of-line. For example:
1626 *
1627 * \code
1628 * class C {
1629 * void f();
1630 * };
1631 *
1632 * void C::f() { }
1633 * \endcode
1634 *
1635 * In the out-of-line definition of \c C::f, the semantic parent is the
1636 * the class \c C, of which this function is a member. The lexical parent is
1637 * the place where the declaration actually occurs in the source code; in this
1638 * case, the definition occurs in the translation unit. In general, the
1639 * lexical parent for a given entity can change without affecting the semantics
1640 * of the program, and the lexical parent of different declarations of the
1641 * same entity may be different. Changing the semantic parent of a declaration,
1642 * on the other hand, can have a major impact on semantics, and redeclarations
1643 * of a particular entity should all have the same semantic context.
1644 *
1645 * In the example above, both declarations of \c C::f have \c C as their
1646 * semantic context, while the lexical context of the first \c C::f is \c C
1647 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001648 *
1649 * For declarations written in the global scope, the lexical parent is
1650 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001651 */
1652CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001653
1654/**
1655 * \brief Determine the set of methods that are overridden by the given
1656 * method.
1657 *
1658 * In both Objective-C and C++, a method (aka virtual member function,
1659 * in C++) can override a virtual method in a base class. For
1660 * Objective-C, a method is said to override any method in the class's
1661 * interface (if we're coming from an implementation), its protocols,
1662 * or its categories, that has the same selector and is of the same
1663 * kind (class or instance). If no such method exists, the search
1664 * continues to the class's superclass, its protocols, and its
1665 * categories, and so on.
1666 *
1667 * For C++, a virtual member function overrides any virtual member
1668 * function with the same signature that occurs in its base
1669 * classes. With multiple inheritance, a virtual member function can
1670 * override several virtual member functions coming from different
1671 * base classes.
1672 *
1673 * In all cases, this function determines the immediate overridden
1674 * method, rather than all of the overridden methods. For example, if
1675 * a method is originally declared in a class A, then overridden in B
1676 * (which in inherits from A) and also in C (which inherited from B),
1677 * then the only overridden method returned from this function when
1678 * invoked on C's method will be B's method. The client may then
1679 * invoke this function again, given the previously-found overridden
1680 * methods, to map out the complete method-override set.
1681 *
1682 * \param cursor A cursor representing an Objective-C or C++
1683 * method. This routine will compute the set of methods that this
1684 * method overrides.
1685 *
1686 * \param overridden A pointer whose pointee will be replaced with a
1687 * pointer to an array of cursors, representing the set of overridden
1688 * methods. If there are no overridden methods, the pointee will be
1689 * set to NULL. The pointee must be freed via a call to
1690 * \c clang_disposeOverriddenCursors().
1691 *
1692 * \param num_overridden A pointer to the number of overridden
1693 * functions, will be set to the number of overridden functions in the
1694 * array pointed to by \p overridden.
1695 */
1696CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1697 CXCursor **overridden,
1698 unsigned *num_overridden);
1699
1700/**
1701 * \brief Free the set of overridden cursors returned by \c
1702 * clang_getOverriddenCursors().
1703 */
1704CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1705
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001706/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001707 * \brief Retrieve the file that is included by the given inclusion directive
1708 * cursor.
1709 */
1710CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1711
1712/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001713 * @}
1714 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001715
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001716/**
1717 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1718 *
1719 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1720 * routines help map between cursors and the physical locations where the
1721 * described entities occur in the source code. The mapping is provided in
1722 * both directions, so one can map from source code to the AST and back.
1723 *
1724 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001725 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001726
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001727/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001728 * \brief Map a source location to the cursor that describes the entity at that
1729 * location in the source code.
1730 *
1731 * clang_getCursor() maps an arbitrary source location within a translation
1732 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001733 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001734 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001735 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001736 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1737 * will return a cursor referring to the "+" expression.
1738 *
1739 * \returns a cursor representing the entity at the given source location, or
1740 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001741 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001742CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001743
Douglas Gregor98258af2010-01-18 22:46:11 +00001744/**
1745 * \brief Retrieve the physical location of the source constructor referenced
1746 * by the given cursor.
1747 *
1748 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001749 * declaration, where the name of that declaration would occur if it is
1750 * unnamed, or some keyword that introduces that particular declaration.
1751 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001752 * source code.
1753 */
1754CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001755
Douglas Gregorb6998662010-01-19 19:34:47 +00001756/**
1757 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001758 * the given cursor.
1759 *
1760 * The extent of a cursor starts with the file/line/column pointing at the
1761 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001762 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001763 * declaration, the extent covers the declaration itself. For a reference,
1764 * the extent covers the location of the reference (e.g., where the referenced
1765 * entity was actually used).
1766 */
1767CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001768
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001769/**
1770 * @}
1771 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001772
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001773/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001774 * \defgroup CINDEX_TYPES Type information for CXCursors
1775 *
1776 * @{
1777 */
1778
1779/**
1780 * \brief Describes the kind of type
1781 */
1782enum CXTypeKind {
1783 /**
1784 * \brief Reprents an invalid type (e.g., where no type is available).
1785 */
1786 CXType_Invalid = 0,
1787
1788 /**
1789 * \brief A type whose specific kind is not exposed via this
1790 * interface.
1791 */
1792 CXType_Unexposed = 1,
1793
1794 /* Builtin types */
1795 CXType_Void = 2,
1796 CXType_Bool = 3,
1797 CXType_Char_U = 4,
1798 CXType_UChar = 5,
1799 CXType_Char16 = 6,
1800 CXType_Char32 = 7,
1801 CXType_UShort = 8,
1802 CXType_UInt = 9,
1803 CXType_ULong = 10,
1804 CXType_ULongLong = 11,
1805 CXType_UInt128 = 12,
1806 CXType_Char_S = 13,
1807 CXType_SChar = 14,
1808 CXType_WChar = 15,
1809 CXType_Short = 16,
1810 CXType_Int = 17,
1811 CXType_Long = 18,
1812 CXType_LongLong = 19,
1813 CXType_Int128 = 20,
1814 CXType_Float = 21,
1815 CXType_Double = 22,
1816 CXType_LongDouble = 23,
1817 CXType_NullPtr = 24,
1818 CXType_Overload = 25,
1819 CXType_Dependent = 26,
1820 CXType_ObjCId = 27,
1821 CXType_ObjCClass = 28,
1822 CXType_ObjCSel = 29,
1823 CXType_FirstBuiltin = CXType_Void,
1824 CXType_LastBuiltin = CXType_ObjCSel,
1825
1826 CXType_Complex = 100,
1827 CXType_Pointer = 101,
1828 CXType_BlockPointer = 102,
1829 CXType_LValueReference = 103,
1830 CXType_RValueReference = 104,
1831 CXType_Record = 105,
1832 CXType_Enum = 106,
1833 CXType_Typedef = 107,
1834 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001835 CXType_ObjCObjectPointer = 109,
1836 CXType_FunctionNoProto = 110,
1837 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001838};
1839
1840/**
1841 * \brief The type of an element in the abstract syntax tree.
1842 *
1843 */
1844typedef struct {
1845 enum CXTypeKind kind;
1846 void *data[2];
1847} CXType;
1848
1849/**
1850 * \brief Retrieve the type of a CXCursor (if any).
1851 */
1852CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1853
1854/**
1855 * \determine Determine whether two CXTypes represent the same type.
1856 *
1857 * \returns non-zero if the CXTypes represent the same type and
1858 zero otherwise.
1859 */
1860CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1861
1862/**
1863 * \brief Return the canonical type for a CXType.
1864 *
1865 * Clang's type system explicitly models typedefs and all the ways
1866 * a specific type can be represented. The canonical type is the underlying
1867 * type with all the "sugar" removed. For example, if 'T' is a typedef
1868 * for 'int', the canonical type for 'T' would be 'int'.
1869 */
1870CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1871
1872/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00001873 * \determine Determine whether a CXType has the "const" qualifier set,
1874 * without looking through typedefs that may have added "const" at a different level.
1875 */
1876CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
1877
1878/**
1879 * \determine Determine whether a CXType has the "volatile" qualifier set,
1880 * without looking through typedefs that may have added "volatile" at a different level.
1881 */
1882CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
1883
1884/**
1885 * \determine Determine whether a CXType has the "restrict" qualifier set,
1886 * without looking through typedefs that may have added "restrict" at a different level.
1887 */
1888CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
1889
1890/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001891 * \brief For pointer types, returns the type of the pointee.
1892 *
1893 */
1894CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1895
1896/**
1897 * \brief Return the cursor for the declaration of the given type.
1898 */
1899CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1900
David Chisnall5389f482010-12-30 14:05:53 +00001901/**
1902 * Returns the Objective-C type encoding for the specified declaration.
1903 */
1904CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001905
1906/**
1907 * \brief Retrieve the spelling of a given CXTypeKind.
1908 */
1909CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1910
1911/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001912 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001913 */
1914CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1915
1916/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001917 * \brief Retrieve the result type associated with a given cursor. This only
1918 * returns a valid type of the cursor refers to a function or method.
1919 */
1920CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1921
1922/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001923 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1924 * otherwise.
1925 */
1926CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1927
1928/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001929 * \brief Returns 1 if the base class specified by the cursor with kind
1930 * CX_CXXBaseSpecifier is virtual.
1931 */
1932CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1933
1934/**
1935 * \brief Represents the C++ access control level to a base class for a
1936 * cursor with kind CX_CXXBaseSpecifier.
1937 */
1938enum CX_CXXAccessSpecifier {
1939 CX_CXXInvalidAccessSpecifier,
1940 CX_CXXPublic,
1941 CX_CXXProtected,
1942 CX_CXXPrivate
1943};
1944
1945/**
1946 * \brief Returns the access control level for the C++ base specifier
1947 * represented by a cursor with kind CX_CXXBaseSpecifier.
1948 */
1949CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
1950
1951/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001952 * \brief Determine the number of overloaded declarations referenced by a
1953 * \c CXCursor_OverloadedDeclRef cursor.
1954 *
1955 * \param cursor The cursor whose overloaded declarations are being queried.
1956 *
1957 * \returns The number of overloaded declarations referenced by \c cursor. If it
1958 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
1959 */
1960CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
1961
1962/**
1963 * \brief Retrieve a cursor for one of the overloaded declarations referenced
1964 * by a \c CXCursor_OverloadedDeclRef cursor.
1965 *
1966 * \param cursor The cursor whose overloaded declarations are being queried.
1967 *
1968 * \param index The zero-based index into the set of overloaded declarations in
1969 * the cursor.
1970 *
1971 * \returns A cursor representing the declaration referenced by the given
1972 * \c cursor at the specified \c index. If the cursor does not have an
1973 * associated set of overloaded declarations, or if the index is out of bounds,
1974 * returns \c clang_getNullCursor();
1975 */
1976CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
1977 unsigned index);
1978
1979/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001980 * @}
1981 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001982
1983/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00001984 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00001985 *
1986 * @{
1987 */
1988
1989
1990/**
1991 * \brief For cursors representing an iboutletcollection attribute,
1992 * this function returns the collection element type.
1993 *
1994 */
1995CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
1996
1997/**
1998 * @}
1999 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002000
2001/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002002 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2003 *
2004 * These routines provide the ability to traverse the abstract syntax tree
2005 * using cursors.
2006 *
2007 * @{
2008 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002009
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002010/**
2011 * \brief Describes how the traversal of the children of a particular
2012 * cursor should proceed after visiting a particular child cursor.
2013 *
2014 * A value of this enumeration type should be returned by each
2015 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2016 */
2017enum CXChildVisitResult {
2018 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002019 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002020 */
2021 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002022 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002023 * \brief Continues the cursor traversal with the next sibling of
2024 * the cursor just visited, without visiting its children.
2025 */
2026 CXChildVisit_Continue,
2027 /**
2028 * \brief Recursively traverse the children of this cursor, using
2029 * the same visitor and client data.
2030 */
2031 CXChildVisit_Recurse
2032};
2033
2034/**
2035 * \brief Visitor invoked for each cursor found by a traversal.
2036 *
2037 * This visitor function will be invoked for each cursor found by
2038 * clang_visitCursorChildren(). Its first argument is the cursor being
2039 * visited, its second argument is the parent visitor for that cursor,
2040 * and its third argument is the client data provided to
2041 * clang_visitCursorChildren().
2042 *
2043 * The visitor should return one of the \c CXChildVisitResult values
2044 * to direct clang_visitCursorChildren().
2045 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002046typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2047 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002048 CXClientData client_data);
2049
2050/**
2051 * \brief Visit the children of a particular cursor.
2052 *
2053 * This function visits all the direct children of the given cursor,
2054 * invoking the given \p visitor function with the cursors of each
2055 * visited child. The traversal may be recursive, if the visitor returns
2056 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2057 * the visitor returns \c CXChildVisit_Break.
2058 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002059 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002060 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002061 * definition, have no children).
2062 *
2063 * \param visitor the visitor function that will be invoked for each
2064 * child of \p parent.
2065 *
2066 * \param client_data pointer data supplied by the client, which will
2067 * be passed to the visitor each time it is invoked.
2068 *
2069 * \returns a non-zero value if the traversal was terminated
2070 * prematurely by the visitor returning \c CXChildVisit_Break.
2071 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002072CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002073 CXCursorVisitor visitor,
2074 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002075#ifdef __has_feature
2076# if __has_feature(blocks)
2077/**
2078 * \brief Visitor invoked for each cursor found by a traversal.
2079 *
2080 * This visitor block will be invoked for each cursor found by
2081 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2082 * visited, its second argument is the parent visitor for that cursor.
2083 *
2084 * The visitor should return one of the \c CXChildVisitResult values
2085 * to direct clang_visitChildrenWithBlock().
2086 */
2087typedef enum CXChildVisitResult
2088 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2089
2090/**
2091 * Visits the children of a cursor using the specified block. Behaves
2092 * identically to clang_visitChildren() in all other respects.
2093 */
2094unsigned clang_visitChildrenWithBlock(CXCursor parent,
2095 CXCursorVisitorBlock block);
2096# endif
2097#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002098
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002099/**
2100 * @}
2101 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002102
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002103/**
2104 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2105 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002106 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002107 * across translation units, by providing the names of the entities referenced
2108 * by cursors, follow reference cursors to the declarations they reference,
2109 * and associate declarations with their definitions.
2110 *
2111 * @{
2112 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002113
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002114/**
2115 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2116 * by the given cursor.
2117 *
2118 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2119 * entity (function, class, variable, etc.) within a program. USRs can be
2120 * compared across translation units to determine, e.g., when references in
2121 * one translation refer to an entity defined in another translation unit.
2122 */
2123CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2124
2125/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002126 * \brief Construct a USR for a specified Objective-C class.
2127 */
2128CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2129
2130/**
2131 * \brief Construct a USR for a specified Objective-C category.
2132 */
2133CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002134 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002135 const char *category_name);
2136
2137/**
2138 * \brief Construct a USR for a specified Objective-C protocol.
2139 */
2140CINDEX_LINKAGE CXString
2141 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2142
2143
2144/**
2145 * \brief Construct a USR for a specified Objective-C instance variable and
2146 * the USR for its containing class.
2147 */
2148CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2149 CXString classUSR);
2150
2151/**
2152 * \brief Construct a USR for a specified Objective-C method and
2153 * the USR for its containing class.
2154 */
2155CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2156 unsigned isInstanceMethod,
2157 CXString classUSR);
2158
2159/**
2160 * \brief Construct a USR for a specified Objective-C property and the USR
2161 * for its containing class.
2162 */
2163CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2164 CXString classUSR);
2165
2166/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002167 * \brief Retrieve a name for the entity referenced by this cursor.
2168 */
2169CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2170
Douglas Gregor358559d2010-10-02 22:49:11 +00002171/**
2172 * \brief Retrieve the display name for the entity referenced by this cursor.
2173 *
2174 * The display name contains extra information that helps identify the cursor,
2175 * such as the parameters of a function or template or the arguments of a
2176 * class template specialization.
2177 */
2178CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2179
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002180/** \brief For a cursor that is a reference, retrieve a cursor representing the
2181 * entity that it references.
2182 *
2183 * Reference cursors refer to other entities in the AST. For example, an
2184 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002185 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002186 * cursor for the superclass reference. If the input cursor is a declaration or
2187 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002188 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002189 */
2190CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002191
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002192/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002193 * \brief For a cursor that is either a reference to or a declaration
2194 * of some entity, retrieve a cursor that describes the definition of
2195 * that entity.
2196 *
2197 * Some entities can be declared multiple times within a translation
2198 * unit, but only one of those declarations can also be a
2199 * definition. For example, given:
2200 *
2201 * \code
2202 * int f(int, int);
2203 * int g(int x, int y) { return f(x, y); }
2204 * int f(int a, int b) { return a + b; }
2205 * int f(int, int);
2206 * \endcode
2207 *
2208 * there are three declarations of the function "f", but only the
2209 * second one is a definition. The clang_getCursorDefinition()
2210 * function will take any cursor pointing to a declaration of "f"
2211 * (the first or fourth lines of the example) or a cursor referenced
2212 * that uses "f" (the call to "f' inside "g") and will return a
2213 * declaration cursor pointing to the definition (the second "f"
2214 * declaration).
2215 *
2216 * If given a cursor for which there is no corresponding definition,
2217 * e.g., because there is no definition of that entity within this
2218 * translation unit, returns a NULL cursor.
2219 */
2220CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2221
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002222/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002223 * \brief Determine whether the declaration pointed to by this cursor
2224 * is also a definition of that entity.
2225 */
2226CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2227
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002228/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002229 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2230 *
2231 * In the C family of languages, many kinds of entities can be declared several
2232 * times within a single translation unit. For example, a structure type can
2233 * be forward-declared (possibly multiple times) and later defined:
2234 *
2235 * \code
2236 * struct X;
2237 * struct X;
2238 * struct X {
2239 * int member;
2240 * };
2241 * \endcode
2242 *
2243 * The declarations and the definition of \c X are represented by three
2244 * different cursors, all of which are declarations of the same underlying
2245 * entity. One of these cursor is considered the "canonical" cursor, which
2246 * is effectively the representative for the underlying entity. One can
2247 * determine if two cursors are declarations of the same underlying entity by
2248 * comparing their canonical cursors.
2249 *
2250 * \returns The canonical cursor for the entity referred to by the given cursor.
2251 */
2252CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2253
2254/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002255 * @}
2256 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002257
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002258/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002259 * \defgroup CINDEX_CPP C++ AST introspection
2260 *
2261 * The routines in this group provide access information in the ASTs specific
2262 * to C++ language features.
2263 *
2264 * @{
2265 */
2266
2267/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002268 * \brief Determine if a C++ member function or member function template is
2269 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002270 */
2271CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2272
2273/**
Douglas Gregor211924b2011-05-12 15:17:24 +00002274 * \brief Determine if a C++ member function or member function template is
2275 * explicitly declared 'virtual' or if it overrides a virtual method from
2276 * one of the base classes.
2277 */
2278CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2279
2280/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002281 * \brief Given a cursor that represents a template, determine
2282 * the cursor kind of the specializations would be generated by instantiating
2283 * the template.
2284 *
2285 * This routine can be used to determine what flavor of function template,
2286 * class template, or class template partial specialization is stored in the
2287 * cursor. For example, it can describe whether a class template cursor is
2288 * declared with "struct", "class" or "union".
2289 *
2290 * \param C The cursor to query. This cursor should represent a template
2291 * declaration.
2292 *
2293 * \returns The cursor kind of the specializations that would be generated
2294 * by instantiating the template \p C. If \p C is not a template, returns
2295 * \c CXCursor_NoDeclFound.
2296 */
2297CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2298
2299/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002300 * \brief Given a cursor that may represent a specialization or instantiation
2301 * of a template, retrieve the cursor that represents the template that it
2302 * specializes or from which it was instantiated.
2303 *
2304 * This routine determines the template involved both for explicit
2305 * specializations of templates and for implicit instantiations of the template,
2306 * both of which are referred to as "specializations". For a class template
2307 * specialization (e.g., \c std::vector<bool>), this routine will return
2308 * either the primary template (\c std::vector) or, if the specialization was
2309 * instantiated from a class template partial specialization, the class template
2310 * partial specialization. For a class template partial specialization and a
2311 * function template specialization (including instantiations), this
2312 * this routine will return the specialized template.
2313 *
2314 * For members of a class template (e.g., member functions, member classes, or
2315 * static data members), returns the specialized or instantiated member.
2316 * Although not strictly "templates" in the C++ language, members of class
2317 * templates have the same notions of specializations and instantiations that
2318 * templates do, so this routine treats them similarly.
2319 *
2320 * \param C A cursor that may be a specialization of a template or a member
2321 * of a template.
2322 *
2323 * \returns If the given cursor is a specialization or instantiation of a
2324 * template or a member thereof, the template or member that it specializes or
2325 * from which it was instantiated. Otherwise, returns a NULL cursor.
2326 */
2327CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
2328
2329/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002330 * @}
2331 */
2332
2333/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002334 * \defgroup CINDEX_LEX Token extraction and manipulation
2335 *
2336 * The routines in this group provide access to the tokens within a
2337 * translation unit, along with a semantic mapping of those tokens to
2338 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002339 *
2340 * @{
2341 */
2342
2343/**
2344 * \brief Describes a kind of token.
2345 */
2346typedef enum CXTokenKind {
2347 /**
2348 * \brief A token that contains some kind of punctuation.
2349 */
2350 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002351
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002352 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002353 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002354 */
2355 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002356
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002357 /**
2358 * \brief An identifier (that is not a keyword).
2359 */
2360 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002361
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002362 /**
2363 * \brief A numeric, string, or character literal.
2364 */
2365 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002366
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002367 /**
2368 * \brief A comment.
2369 */
2370 CXToken_Comment
2371} CXTokenKind;
2372
2373/**
2374 * \brief Describes a single preprocessing token.
2375 */
2376typedef struct {
2377 unsigned int_data[4];
2378 void *ptr_data;
2379} CXToken;
2380
2381/**
2382 * \brief Determine the kind of the given token.
2383 */
2384CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002385
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002386/**
2387 * \brief Determine the spelling of the given token.
2388 *
2389 * The spelling of a token is the textual representation of that token, e.g.,
2390 * the text of an identifier or keyword.
2391 */
2392CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002393
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002394/**
2395 * \brief Retrieve the source location of the given token.
2396 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002397CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002398 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002399
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002400/**
2401 * \brief Retrieve a source range that covers the given token.
2402 */
2403CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2404
2405/**
2406 * \brief Tokenize the source code described by the given range into raw
2407 * lexical tokens.
2408 *
2409 * \param TU the translation unit whose text is being tokenized.
2410 *
2411 * \param Range the source range in which text should be tokenized. All of the
2412 * tokens produced by tokenization will fall within this source range,
2413 *
2414 * \param Tokens this pointer will be set to point to the array of tokens
2415 * that occur within the given source range. The returned pointer must be
2416 * freed with clang_disposeTokens() before the translation unit is destroyed.
2417 *
2418 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2419 * array.
2420 *
2421 */
2422CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2423 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002424
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002425/**
2426 * \brief Annotate the given set of tokens by providing cursors for each token
2427 * that can be mapped to a specific entity within the abstract syntax tree.
2428 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002429 * This token-annotation routine is equivalent to invoking
2430 * clang_getCursor() for the source locations of each of the
2431 * tokens. The cursors provided are filtered, so that only those
2432 * cursors that have a direct correspondence to the token are
2433 * accepted. For example, given a function call \c f(x),
2434 * clang_getCursor() would provide the following cursors:
2435 *
2436 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2437 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2438 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2439 *
2440 * Only the first and last of these cursors will occur within the
2441 * annotate, since the tokens "f" and "x' directly refer to a function
2442 * and a variable, respectively, but the parentheses are just a small
2443 * part of the full syntax of the function call expression, which is
2444 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002445 *
2446 * \param TU the translation unit that owns the given tokens.
2447 *
2448 * \param Tokens the set of tokens to annotate.
2449 *
2450 * \param NumTokens the number of tokens in \p Tokens.
2451 *
2452 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2453 * replaced with the cursors corresponding to each token.
2454 */
2455CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2456 CXToken *Tokens, unsigned NumTokens,
2457 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002458
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002459/**
2460 * \brief Free the given set of tokens.
2461 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002462CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002463 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002464
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002465/**
2466 * @}
2467 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002468
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002469/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002470 * \defgroup CINDEX_DEBUG Debugging facilities
2471 *
2472 * These routines are used for testing and debugging, only, and should not
2473 * be relied upon.
2474 *
2475 * @{
2476 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002477
Steve Naroff4ade6d62009-09-23 17:52:52 +00002478/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002479CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002480CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2481 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002482 const char **endBuf,
2483 unsigned *startLine,
2484 unsigned *startColumn,
2485 unsigned *endLine,
2486 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002487CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00002488CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
2489 unsigned stack_size);
2490
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002491/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002492 * @}
2493 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002494
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002495/**
2496 * \defgroup CINDEX_CODE_COMPLET Code completion
2497 *
2498 * Code completion involves taking an (incomplete) source file, along with
2499 * knowledge of where the user is actively editing that file, and suggesting
2500 * syntactically- and semantically-valid constructs that the user might want to
2501 * use at that particular point in the source code. These data structures and
2502 * routines provide support for code completion.
2503 *
2504 * @{
2505 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002506
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002507/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002508 * \brief A semantic string that describes a code-completion result.
2509 *
2510 * A semantic string that describes the formatting of a code-completion
2511 * result as a single "template" of text that should be inserted into the
2512 * source buffer when a particular code-completion result is selected.
2513 * Each semantic string is made up of some number of "chunks", each of which
2514 * contains some text along with a description of what that text means, e.g.,
2515 * the name of the entity being referenced, whether the text chunk is part of
2516 * the template, or whether it is a "placeholder" that the user should replace
2517 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002518 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002519 */
2520typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002521
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002522/**
2523 * \brief A single result of code completion.
2524 */
2525typedef struct {
2526 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002527 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002528 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002529 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002530 * *Decl cursor kinds), describing the entity that the completion is
2531 * referring to.
2532 *
2533 * \todo In the future, we would like to provide a full cursor, to allow
2534 * the client to extract additional information from declaration.
2535 */
2536 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002537
2538 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002539 * \brief The code-completion string that describes how to insert this
2540 * code-completion result into the editing buffer.
2541 */
2542 CXCompletionString CompletionString;
2543} CXCompletionResult;
2544
2545/**
2546 * \brief Describes a single piece of text within a code-completion string.
2547 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002548 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2549 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002550 * should be interpreted by the client or is another completion string.
2551 */
2552enum CXCompletionChunkKind {
2553 /**
2554 * \brief A code-completion string that describes "optional" text that
2555 * could be a part of the template (but is not required).
2556 *
2557 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002558 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002559 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2560 * describes an additional part of the template that is completely optional.
2561 * For example, optional chunks can be used to describe the placeholders for
2562 * arguments that match up with defaulted function parameters, e.g. given:
2563 *
2564 * \code
2565 * void f(int x, float y = 3.14, double z = 2.71828);
2566 * \endcode
2567 *
2568 * The code-completion string for this function would contain:
2569 * - a TypedText chunk for "f".
2570 * - a LeftParen chunk for "(".
2571 * - a Placeholder chunk for "int x"
2572 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2573 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002574 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002575 * - an Optional chunk containing the last defaulted argument:
2576 * - a Comma chunk for ","
2577 * - a Placeholder chunk for "double z"
2578 * - a RightParen chunk for ")"
2579 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002580 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002581 * - Completely ignore optional chunks, in which case the template for the
2582 * function "f" would only include the first parameter ("int x").
2583 * - Fully expand all optional chunks, in which case the template for the
2584 * function "f" would have all of the parameters.
2585 */
2586 CXCompletionChunk_Optional,
2587 /**
2588 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002589 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002590 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002591 * There will be exactly one "typed text" chunk in a semantic string, which
2592 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002593 * declaration that could be used at the current code point. Clients are
2594 * expected to filter the code-completion results based on the text in this
2595 * chunk.
2596 */
2597 CXCompletionChunk_TypedText,
2598 /**
2599 * \brief Text that should be inserted as part of a code-completion result.
2600 *
2601 * A "text" chunk represents text that is part of the template to be
2602 * inserted into user code should this particular code-completion result
2603 * be selected.
2604 */
2605 CXCompletionChunk_Text,
2606 /**
2607 * \brief Placeholder text that should be replaced by the user.
2608 *
2609 * A "placeholder" chunk marks a place where the user should insert text
2610 * into the code-completion template. For example, placeholders might mark
2611 * the function parameters for a function declaration, to indicate that the
2612 * user should provide arguments for each of those parameters. The actual
2613 * text in a placeholder is a suggestion for the text to display before
2614 * the user replaces the placeholder with real code.
2615 */
2616 CXCompletionChunk_Placeholder,
2617 /**
2618 * \brief Informative text that should be displayed but never inserted as
2619 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002620 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002621 * An "informative" chunk contains annotations that can be displayed to
2622 * help the user decide whether a particular code-completion result is the
2623 * right option, but which is not part of the actual template to be inserted
2624 * by code completion.
2625 */
2626 CXCompletionChunk_Informative,
2627 /**
2628 * \brief Text that describes the current parameter when code-completion is
2629 * referring to function call, message send, or template specialization.
2630 *
2631 * A "current parameter" chunk occurs when code-completion is providing
2632 * information about a parameter corresponding to the argument at the
2633 * code-completion point. For example, given a function
2634 *
2635 * \code
2636 * int add(int x, int y);
2637 * \endcode
2638 *
2639 * and the source code \c add(, where the code-completion point is after the
2640 * "(", the code-completion string will contain a "current parameter" chunk
2641 * for "int x", indicating that the current argument will initialize that
2642 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002643 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002644 * "current paremeter" chunk to "int y".
2645 */
2646 CXCompletionChunk_CurrentParameter,
2647 /**
2648 * \brief A left parenthesis ('('), used to initiate a function call or
2649 * signal the beginning of a function parameter list.
2650 */
2651 CXCompletionChunk_LeftParen,
2652 /**
2653 * \brief A right parenthesis (')'), used to finish a function call or
2654 * signal the end of a function parameter list.
2655 */
2656 CXCompletionChunk_RightParen,
2657 /**
2658 * \brief A left bracket ('[').
2659 */
2660 CXCompletionChunk_LeftBracket,
2661 /**
2662 * \brief A right bracket (']').
2663 */
2664 CXCompletionChunk_RightBracket,
2665 /**
2666 * \brief A left brace ('{').
2667 */
2668 CXCompletionChunk_LeftBrace,
2669 /**
2670 * \brief A right brace ('}').
2671 */
2672 CXCompletionChunk_RightBrace,
2673 /**
2674 * \brief A left angle bracket ('<').
2675 */
2676 CXCompletionChunk_LeftAngle,
2677 /**
2678 * \brief A right angle bracket ('>').
2679 */
2680 CXCompletionChunk_RightAngle,
2681 /**
2682 * \brief A comma separator (',').
2683 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002684 CXCompletionChunk_Comma,
2685 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002686 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002687 *
2688 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002689 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002690 * expression using the given completion string would have.
2691 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002692 CXCompletionChunk_ResultType,
2693 /**
2694 * \brief A colon (':').
2695 */
2696 CXCompletionChunk_Colon,
2697 /**
2698 * \brief A semicolon (';').
2699 */
2700 CXCompletionChunk_SemiColon,
2701 /**
2702 * \brief An '=' sign.
2703 */
2704 CXCompletionChunk_Equal,
2705 /**
2706 * Horizontal space (' ').
2707 */
2708 CXCompletionChunk_HorizontalSpace,
2709 /**
2710 * Vertical space ('\n'), after which it is generally a good idea to
2711 * perform indentation.
2712 */
2713 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002714};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002715
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002716/**
2717 * \brief Determine the kind of a particular chunk within a completion string.
2718 *
2719 * \param completion_string the completion string to query.
2720 *
2721 * \param chunk_number the 0-based index of the chunk in the completion string.
2722 *
2723 * \returns the kind of the chunk at the index \c chunk_number.
2724 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002725CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002726clang_getCompletionChunkKind(CXCompletionString completion_string,
2727 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002728
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002729/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002730 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002731 * completion string.
2732 *
2733 * \param completion_string the completion string to query.
2734 *
2735 * \param chunk_number the 0-based index of the chunk in the completion string.
2736 *
2737 * \returns the text associated with the chunk at index \c chunk_number.
2738 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002739CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002740clang_getCompletionChunkText(CXCompletionString completion_string,
2741 unsigned chunk_number);
2742
2743/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002744 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002745 * within a completion string.
2746 *
2747 * \param completion_string the completion string to query.
2748 *
2749 * \param chunk_number the 0-based index of the chunk in the completion string.
2750 *
2751 * \returns the completion string associated with the chunk at index
2752 * \c chunk_number, or NULL if that chunk is not represented by a completion
2753 * string.
2754 */
2755CINDEX_LINKAGE CXCompletionString
2756clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2757 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002758
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002759/**
2760 * \brief Retrieve the number of chunks in the given code-completion string.
2761 */
2762CINDEX_LINKAGE unsigned
2763clang_getNumCompletionChunks(CXCompletionString completion_string);
2764
2765/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002766 * \brief Determine the priority of this code completion.
2767 *
2768 * The priority of a code completion indicates how likely it is that this
2769 * particular completion is the completion that the user will select. The
2770 * priority is selected by various internal heuristics.
2771 *
2772 * \param completion_string The completion string to query.
2773 *
2774 * \returns The priority of this completion string. Smaller values indicate
2775 * higher-priority (more likely) completions.
2776 */
2777CINDEX_LINKAGE unsigned
2778clang_getCompletionPriority(CXCompletionString completion_string);
2779
2780/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002781 * \brief Determine the availability of the entity that this code-completion
2782 * string refers to.
2783 *
2784 * \param completion_string The completion string to query.
2785 *
2786 * \returns The availability of the completion string.
2787 */
2788CINDEX_LINKAGE enum CXAvailabilityKind
2789clang_getCompletionAvailability(CXCompletionString completion_string);
2790
2791/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002792 * \brief Contains the results of code-completion.
2793 *
2794 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002795 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002796 * \c clang_disposeCodeCompleteResults.
2797 */
2798typedef struct {
2799 /**
2800 * \brief The code-completion results.
2801 */
2802 CXCompletionResult *Results;
2803
2804 /**
2805 * \brief The number of code-completion results stored in the
2806 * \c Results array.
2807 */
2808 unsigned NumResults;
2809} CXCodeCompleteResults;
2810
2811/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002812 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2813 * modify its behavior.
2814 *
2815 * The enumerators in this enumeration can be bitwise-OR'd together to
2816 * provide multiple options to \c clang_codeCompleteAt().
2817 */
2818enum CXCodeComplete_Flags {
2819 /**
2820 * \brief Whether to include macros within the set of code
2821 * completions returned.
2822 */
2823 CXCodeComplete_IncludeMacros = 0x01,
2824
2825 /**
2826 * \brief Whether to include code patterns for language constructs
2827 * within the set of code completions, e.g., for loops.
2828 */
2829 CXCodeComplete_IncludeCodePatterns = 0x02
2830};
2831
2832/**
2833 * \brief Returns a default set of code-completion options that can be
2834 * passed to\c clang_codeCompleteAt().
2835 */
2836CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
2837
2838/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002839 * \brief Perform code completion at a given location in a translation unit.
2840 *
2841 * This function performs code completion at a particular file, line, and
2842 * column within source code, providing results that suggest potential
2843 * code snippets based on the context of the completion. The basic model
2844 * for code completion is that Clang will parse a complete source file,
2845 * performing syntax checking up to the location where code-completion has
2846 * been requested. At that point, a special code-completion token is passed
2847 * to the parser, which recognizes this token and determines, based on the
2848 * current location in the C/Objective-C/C++ grammar and the state of
2849 * semantic analysis, what completions to provide. These completions are
2850 * returned via a new \c CXCodeCompleteResults structure.
2851 *
2852 * Code completion itself is meant to be triggered by the client when the
2853 * user types punctuation characters or whitespace, at which point the
2854 * code-completion location will coincide with the cursor. For example, if \c p
2855 * is a pointer, code-completion might be triggered after the "-" and then
2856 * after the ">" in \c p->. When the code-completion location is afer the ">",
2857 * the completion results will provide, e.g., the members of the struct that
2858 * "p" points to. The client is responsible for placing the cursor at the
2859 * beginning of the token currently being typed, then filtering the results
2860 * based on the contents of the token. For example, when code-completing for
2861 * the expression \c p->get, the client should provide the location just after
2862 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
2863 * client can filter the results based on the current token text ("get"), only
2864 * showing those results that start with "get". The intent of this interface
2865 * is to separate the relatively high-latency acquisition of code-completion
2866 * results from the filtering of results on a per-character basis, which must
2867 * have a lower latency.
2868 *
2869 * \param TU The translation unit in which code-completion should
2870 * occur. The source files for this translation unit need not be
2871 * completely up-to-date (and the contents of those source files may
2872 * be overridden via \p unsaved_files). Cursors referring into the
2873 * translation unit may be invalidated by this invocation.
2874 *
2875 * \param complete_filename The name of the source file where code
2876 * completion should be performed. This filename may be any file
2877 * included in the translation unit.
2878 *
2879 * \param complete_line The line at which code-completion should occur.
2880 *
2881 * \param complete_column The column at which code-completion should occur.
2882 * Note that the column should point just after the syntactic construct that
2883 * initiated code completion, and not in the middle of a lexical token.
2884 *
2885 * \param unsaved_files the Tiles that have not yet been saved to disk
2886 * but may be required for parsing or code completion, including the
2887 * contents of those files. The contents and name of these files (as
2888 * specified by CXUnsavedFile) are copied when necessary, so the
2889 * client only needs to guarantee their validity until the call to
2890 * this function returns.
2891 *
2892 * \param num_unsaved_files The number of unsaved file entries in \p
2893 * unsaved_files.
2894 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00002895 * \param options Extra options that control the behavior of code
2896 * completion, expressed as a bitwise OR of the enumerators of the
2897 * CXCodeComplete_Flags enumeration. The
2898 * \c clang_defaultCodeCompleteOptions() function returns a default set
2899 * of code-completion options.
2900 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002901 * \returns If successful, a new \c CXCodeCompleteResults structure
2902 * containing code-completion results, which should eventually be
2903 * freed with \c clang_disposeCodeCompleteResults(). If code
2904 * completion fails, returns NULL.
2905 */
2906CINDEX_LINKAGE
2907CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
2908 const char *complete_filename,
2909 unsigned complete_line,
2910 unsigned complete_column,
2911 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00002912 unsigned num_unsaved_files,
2913 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002914
2915/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00002916 * \brief Sort the code-completion results in case-insensitive alphabetical
2917 * order.
2918 *
2919 * \param Results The set of results to sort.
2920 * \param NumResults The number of results in \p Results.
2921 */
2922CINDEX_LINKAGE
2923void clang_sortCodeCompletionResults(CXCompletionResult *Results,
2924 unsigned NumResults);
2925
2926/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002927 * \brief Free the given set of code-completion results.
2928 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002929CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00002930void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00002931
Douglas Gregor20d416c2010-01-20 01:10:47 +00002932/**
Douglas Gregora88084b2010-02-18 18:08:43 +00002933 * \brief Determine the number of diagnostics produced prior to the
2934 * location where code completion was performed.
2935 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002936CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002937unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
2938
2939/**
2940 * \brief Retrieve a diagnostic associated with the given code completion.
2941 *
2942 * \param Result the code completion results to query.
2943 * \param Index the zero-based diagnostic number to retrieve.
2944 *
2945 * \returns the requested diagnostic. This diagnostic must be freed
2946 * via a call to \c clang_disposeDiagnostic().
2947 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002948CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002949CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
2950 unsigned Index);
2951
2952/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00002953 * @}
2954 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002955
2956
Ted Kremenek04bb7162010-01-22 22:44:15 +00002957/**
2958 * \defgroup CINDEX_MISC Miscellaneous utility functions
2959 *
2960 * @{
2961 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00002962
2963/**
2964 * \brief Return a version string, suitable for showing to a user, but not
2965 * intended to be parsed (the format is not guaranteed to be stable).
2966 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00002967CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00002968
Ted Kremenekd2427dd2011-03-18 23:05:39 +00002969
2970/**
2971 * \brief Enable/disable crash recovery.
2972 *
2973 * \param Flag to indicate if crash recovery is enabled. A non-zero value
2974 * enables crash recovery, while 0 disables it.
2975 */
2976CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
2977
Ted Kremenek16b55a72010-01-26 19:31:51 +00002978 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002979 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00002980 * (used with clang_getInclusions()).
2981 *
2982 * This visitor function will be invoked by clang_getInclusions() for each
2983 * file included (either at the top-level or by #include directives) within
2984 * a translation unit. The first argument is the file being included, and
2985 * the second and third arguments provide the inclusion stack. The
2986 * array is sorted in order of immediate inclusion. For example,
2987 * the first element refers to the location that included 'included_file'.
2988 */
2989typedef void (*CXInclusionVisitor)(CXFile included_file,
2990 CXSourceLocation* inclusion_stack,
2991 unsigned include_len,
2992 CXClientData client_data);
2993
2994/**
2995 * \brief Visit the set of preprocessor inclusions in a translation unit.
2996 * The visitor function is called with the provided data for every included
2997 * file. This does not include headers included by the PCH file (unless one
2998 * is inspecting the inclusions in the PCH file itself).
2999 */
3000CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3001 CXInclusionVisitor visitor,
3002 CXClientData client_data);
3003
3004/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00003005 * @}
3006 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003007
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003008/**
3009 * @}
3010 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003011
Ted Kremenekd2fa5662009-08-26 22:36:44 +00003012#ifdef __cplusplus
3013}
3014#endif
3015#endif
3016