blob: 7c322504381e83e46771618e4242186f3d59fdd9 [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 Gregorab4e83b2011-07-23 19:35:14 +0000331 * \brief Determine whether two ranges are equivalent.
332 *
333 * \returns non-zero if the ranges are the same, zero if they differ.
334 */
335CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
336 CXSourceRange range2);
337
338/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000339 * \brief Retrieve the file, line, column, and offset represented by
340 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000341 *
Douglas Gregora9b06d42010-11-09 06:24:54 +0000342 * If the location refers into a macro instantiation, retrieves the
343 * location of the macro instantiation.
344 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000345 * \param location the location within a source file that will be decomposed
346 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000347 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000348 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000349 * source location points.
350 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000351 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000352 * source location points.
353 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000354 * \param column [out] if non-NULL, will be set to the column to which the given
355 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000356 *
357 * \param offset [out] if non-NULL, will be set to the offset into the
358 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000359 */
360CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
361 CXFile *file,
362 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000363 unsigned *column,
364 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000365
366/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000367 * \brief Retrieve the file, line, column, and offset represented by
368 * the given source location.
369 *
370 * If the location refers into a macro instantiation, return where the
371 * location was originally spelled in the source file.
372 *
373 * \param location the location within a source file that will be decomposed
374 * into its parts.
375 *
376 * \param file [out] if non-NULL, will be set to the file to which the given
377 * source location points.
378 *
379 * \param line [out] if non-NULL, will be set to the line to which the given
380 * source location points.
381 *
382 * \param column [out] if non-NULL, will be set to the column to which the given
383 * source location points.
384 *
385 * \param offset [out] if non-NULL, will be set to the offset into the
386 * buffer to which the given source location points.
387 */
388CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
389 CXFile *file,
390 unsigned *line,
391 unsigned *column,
392 unsigned *offset);
393
394/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000395 * \brief Retrieve a source location representing the first character within a
396 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000397 */
398CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
399
400/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000401 * \brief Retrieve a source location representing the last character within a
402 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000403 */
404CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
405
Douglas Gregorf5525442010-01-20 22:45:41 +0000406/**
407 * @}
408 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000409
410/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000411 * \defgroup CINDEX_DIAG Diagnostic reporting
412 *
413 * @{
414 */
415
416/**
417 * \brief Describes the severity of a particular diagnostic.
418 */
419enum CXDiagnosticSeverity {
420 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000421 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000422 * option.
423 */
424 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000425
Douglas Gregor5352ac02010-01-28 00:27:43 +0000426 /**
427 * \brief This diagnostic is a note that should be attached to the
428 * previous (non-note) diagnostic.
429 */
430 CXDiagnostic_Note = 1,
431
432 /**
433 * \brief This diagnostic indicates suspicious code that may not be
434 * wrong.
435 */
436 CXDiagnostic_Warning = 2,
437
438 /**
439 * \brief This diagnostic indicates that the code is ill-formed.
440 */
441 CXDiagnostic_Error = 3,
442
443 /**
444 * \brief This diagnostic indicates that the code is ill-formed such
445 * that future parser recovery is unlikely to produce useful
446 * results.
447 */
448 CXDiagnostic_Fatal = 4
449};
450
451/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000452 * \brief A single diagnostic, containing the diagnostic's severity,
453 * location, text, source ranges, and fix-it hints.
454 */
455typedef void *CXDiagnostic;
456
457/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000458 * \brief Determine the number of diagnostics produced for the given
459 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000460 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000461CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
462
463/**
464 * \brief Retrieve a diagnostic associated with the given translation unit.
465 *
466 * \param Unit the translation unit to query.
467 * \param Index the zero-based diagnostic number to retrieve.
468 *
469 * \returns the requested diagnostic. This diagnostic must be freed
470 * via a call to \c clang_disposeDiagnostic().
471 */
472CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
473 unsigned Index);
474
475/**
476 * \brief Destroy a diagnostic.
477 */
478CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000479
480/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000481 * \brief Options to control the display of diagnostics.
482 *
483 * The values in this enum are meant to be combined to customize the
484 * behavior of \c clang_displayDiagnostic().
485 */
486enum CXDiagnosticDisplayOptions {
487 /**
488 * \brief Display the source-location information where the
489 * diagnostic was located.
490 *
491 * When set, diagnostics will be prefixed by the file, line, and
492 * (optionally) column to which the diagnostic refers. For example,
493 *
494 * \code
495 * test.c:28: warning: extra tokens at end of #endif directive
496 * \endcode
497 *
498 * This option corresponds to the clang flag \c -fshow-source-location.
499 */
500 CXDiagnostic_DisplaySourceLocation = 0x01,
501
502 /**
503 * \brief If displaying the source-location information of the
504 * diagnostic, also include the column number.
505 *
506 * This option corresponds to the clang flag \c -fshow-column.
507 */
508 CXDiagnostic_DisplayColumn = 0x02,
509
510 /**
511 * \brief If displaying the source-location information of the
512 * diagnostic, also include information about source ranges in a
513 * machine-parsable format.
514 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000515 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000516 * \c -fdiagnostics-print-source-range-info.
517 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000518 CXDiagnostic_DisplaySourceRanges = 0x04,
519
520 /**
521 * \brief Display the option name associated with this diagnostic, if any.
522 *
523 * The option name displayed (e.g., -Wconversion) will be placed in brackets
524 * after the diagnostic text. This option corresponds to the clang flag
525 * \c -fdiagnostics-show-option.
526 */
527 CXDiagnostic_DisplayOption = 0x08,
528
529 /**
530 * \brief Display the category number associated with this diagnostic, if any.
531 *
532 * The category number is displayed within brackets after the diagnostic text.
533 * This option corresponds to the clang flag
534 * \c -fdiagnostics-show-category=id.
535 */
536 CXDiagnostic_DisplayCategoryId = 0x10,
537
538 /**
539 * \brief Display the category name associated with this diagnostic, if any.
540 *
541 * The category name is displayed within brackets after the diagnostic text.
542 * This option corresponds to the clang flag
543 * \c -fdiagnostics-show-category=name.
544 */
545 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000546};
547
548/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000549 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000550 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000551 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000552 * the diagnostic according to the various options given. The
553 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000554 * options that most closely mimics the behavior of the clang compiler.
555 *
556 * \param Diagnostic The diagnostic to print.
557 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000558 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000559 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000560 *
561 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000562 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000563CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
564 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000565
566/**
567 * \brief Retrieve the set of display options most similar to the
568 * default behavior of the clang compiler.
569 *
570 * \returns A set of display options suitable for use with \c
571 * clang_displayDiagnostic().
572 */
573CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
574
575/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000576 * \brief Determine the severity of the given diagnostic.
577 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000578CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000579clang_getDiagnosticSeverity(CXDiagnostic);
580
581/**
582 * \brief Retrieve the source location of the given diagnostic.
583 *
584 * This location is where Clang would print the caret ('^') when
585 * displaying the diagnostic on the command line.
586 */
587CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
588
589/**
590 * \brief Retrieve the text of the given diagnostic.
591 */
592CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000593
594/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000595 * \brief Retrieve the name of the command-line option that enabled this
596 * diagnostic.
597 *
598 * \param Diag The diagnostic to be queried.
599 *
600 * \param Disable If non-NULL, will be set to the option that disables this
601 * diagnostic (if any).
602 *
603 * \returns A string that contains the command-line option used to enable this
604 * warning, such as "-Wconversion" or "-pedantic".
605 */
606CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
607 CXString *Disable);
608
609/**
610 * \brief Retrieve the category number for this diagnostic.
611 *
612 * Diagnostics can be categorized into groups along with other, related
613 * diagnostics (e.g., diagnostics under the same warning flag). This routine
614 * retrieves the category number for the given diagnostic.
615 *
616 * \returns The number of the category that contains this diagnostic, or zero
617 * if this diagnostic is uncategorized.
618 */
619CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
620
621/**
622 * \brief Retrieve the name of a particular diagnostic category.
623 *
624 * \param Category A diagnostic category number, as returned by
625 * \c clang_getDiagnosticCategory().
626 *
627 * \returns The name of the given diagnostic category.
628 */
629CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
630
631/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000632 * \brief Determine the number of source ranges associated with the given
633 * diagnostic.
634 */
635CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000636
Douglas Gregor5352ac02010-01-28 00:27:43 +0000637/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000638 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000639 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000640 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000641 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000642 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000643 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000644 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000645 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000646 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000647 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000648 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000649 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000650CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000651 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000652
653/**
654 * \brief Determine the number of fix-it hints associated with the
655 * given diagnostic.
656 */
657CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
658
659/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000660 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000661 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000662 * Fix-its are described in terms of a source range whose contents
663 * should be replaced by a string. This approach generalizes over
664 * three kinds of operations: removal of source code (the range covers
665 * the code to be removed and the replacement string is empty),
666 * replacement of source code (the range covers the code to be
667 * replaced and the replacement string provides the new code), and
668 * insertion (both the start and end of the range point at the
669 * insertion location, and the replacement string provides the text to
670 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000671 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000672 * \param Diagnostic The diagnostic whose fix-its are being queried.
673 *
674 * \param FixIt The zero-based index of the fix-it.
675 *
676 * \param ReplacementRange The source range whose contents will be
677 * replaced with the returned replacement string. Note that source
678 * ranges are half-open ranges [a, b), so the source code should be
679 * replaced from a and up to (but not including) b.
680 *
681 * \returns A string containing text that should be replace the source
682 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000683 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000684CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000685 unsigned FixIt,
686 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000687
688/**
689 * @}
690 */
691
692/**
693 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
694 *
695 * The routines in this group provide the ability to create and destroy
696 * translation units from files, either by parsing the contents of the files or
697 * by reading in a serialized representation of a translation unit.
698 *
699 * @{
700 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000701
Douglas Gregor5352ac02010-01-28 00:27:43 +0000702/**
703 * \brief Get the original translation unit source file name.
704 */
705CINDEX_LINKAGE CXString
706clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
707
708/**
709 * \brief Return the CXTranslationUnit for a given source file and the provided
710 * command line arguments one would pass to the compiler.
711 *
712 * Note: The 'source_filename' argument is optional. If the caller provides a
713 * NULL pointer, the name of the source file is expected to reside in the
714 * specified command line arguments.
715 *
716 * Note: When encountered in 'clang_command_line_args', the following options
717 * are ignored:
718 *
719 * '-c'
720 * '-emit-ast'
721 * '-fsyntax-only'
722 * '-o <output file>' (both '-o' and '<output file>' are ignored)
723 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000724 * \param CIdx The index object with which the translation unit will be
725 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000726 *
727 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000728 * source file is included in \p clang_command_line_args.
729 *
730 * \param num_clang_command_line_args The number of command-line arguments in
731 * \p clang_command_line_args.
732 *
733 * \param clang_command_line_args The command-line arguments that would be
734 * passed to the \c clang executable if it were being invoked out-of-process.
735 * These command-line options will be parsed and will affect how the translation
736 * unit is parsed. Note that the following options are ignored: '-c',
737 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000738 *
739 * \param num_unsaved_files the number of unsaved file entries in \p
740 * unsaved_files.
741 *
742 * \param unsaved_files the files that have not yet been saved to disk
743 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000744 * those files. The contents and name of these files (as specified by
745 * CXUnsavedFile) are copied when necessary, so the client only needs to
746 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000747 */
748CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
749 CXIndex CIdx,
750 const char *source_filename,
751 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000752 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000753 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000754 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000755
Douglas Gregor5352ac02010-01-28 00:27:43 +0000756/**
757 * \brief Create a translation unit from an AST file (-emit-ast).
758 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000759CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000760 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000761
Douglas Gregor44c181a2010-07-23 00:33:23 +0000762/**
763 * \brief Flags that control the creation of translation units.
764 *
765 * The enumerators in this enumeration type are meant to be bitwise
766 * ORed together to specify which options should be used when
767 * constructing the translation unit.
768 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000769enum CXTranslationUnit_Flags {
770 /**
771 * \brief Used to indicate that no special translation-unit options are
772 * needed.
773 */
774 CXTranslationUnit_None = 0x0,
775
776 /**
777 * \brief Used to indicate that the parser should construct a "detailed"
778 * preprocessing record, including all macro definitions and instantiations.
779 *
780 * Constructing a detailed preprocessing record requires more memory
781 * and time to parse, since the information contained in the record
782 * is usually not retained. However, it can be useful for
783 * applications that require more detailed information about the
784 * behavior of the preprocessor.
785 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000786 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
787
788 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000789 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000790 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000791 * When a translation unit is considered "incomplete", semantic
792 * analysis that is typically performed at the end of the
793 * translation unit will be suppressed. For example, this suppresses
794 * the completion of tentative declarations in C and of
795 * instantiation of implicitly-instantiation function templates in
796 * C++. This option is typically used when parsing a header with the
797 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000798 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000799 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000800
801 /**
802 * \brief Used to indicate that the translation unit should be built with an
803 * implicit precompiled header for the preamble.
804 *
805 * An implicit precompiled header is used as an optimization when a
806 * particular translation unit is likely to be reparsed many times
807 * when the sources aren't changing that often. In this case, an
808 * implicit precompiled header will be built containing all of the
809 * initial includes at the top of the main file (what we refer to as
810 * the "preamble" of the file). In subsequent parses, if the
811 * preamble or the files in it have not changed, \c
812 * clang_reparseTranslationUnit() will re-use the implicit
813 * precompiled header to improve parsing performance.
814 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000815 CXTranslationUnit_PrecompiledPreamble = 0x04,
816
817 /**
818 * \brief Used to indicate that the translation unit should cache some
819 * code-completion results with each reparse of the source file.
820 *
821 * Caching of code-completion results is a performance optimization that
822 * introduces some overhead to reparsing but improves the performance of
823 * code-completion operations.
824 */
Douglas Gregor99ba2022010-10-27 17:24:53 +0000825 CXTranslationUnit_CacheCompletionResults = 0x08,
826 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +0000827 * \brief DEPRECATED: Enable precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000828 *
829 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +0000830 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000831 */
832 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
833
834 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +0000835 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000836 *
837 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +0000838 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000839 */
Douglas Gregordca8ee82011-05-06 16:33:08 +0000840 CXTranslationUnit_CXXChainedPCH = 0x20,
841
842 /**
843 * \brief Used to indicate that the "detailed" preprocessing record,
Chandler Carruthfd14e912011-07-14 16:08:00 +0000844 * if requested, should also contain nested macro expansions.
Douglas Gregordca8ee82011-05-06 16:33:08 +0000845 *
Chandler Carruthfd14e912011-07-14 16:08:00 +0000846 * Nested macro expansions (i.e., macro expansions that occur
847 * inside another macro expansion) can, in some code bases, require
Douglas Gregordca8ee82011-05-06 16:33:08 +0000848 * a large amount of storage to due preprocessor metaprogramming. Moreover,
849 * its fairly rare that this information is useful for libclang clients.
850 */
Chandler Carruthba7537f2011-07-14 09:02:10 +0000851 CXTranslationUnit_NestedMacroExpansions = 0x40,
852
853 /**
854 * \brief Legacy name to indicate that the "detailed" preprocessing record,
Chandler Carruthfd14e912011-07-14 16:08:00 +0000855 * if requested, should contain nested macro expansions.
Chandler Carruthba7537f2011-07-14 09:02:10 +0000856 *
857 * \see CXTranslationUnit_NestedMacroExpansions for the current name for this
858 * value, and its semantics. This is just an alias.
859 */
860 CXTranslationUnit_NestedMacroInstantiations =
861 CXTranslationUnit_NestedMacroExpansions
Douglas Gregor5a430212010-07-21 18:52:53 +0000862};
863
864/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000865 * \brief Returns the set of flags that is suitable for parsing a translation
866 * unit that is being edited.
867 *
868 * The set of flags returned provide options for \c clang_parseTranslationUnit()
869 * to indicate that the translation unit is likely to be reparsed many times,
870 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
871 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
872 * set contains an unspecified set of optimizations (e.g., the precompiled
873 * preamble) geared toward improving the performance of these routines. The
874 * set of optimizations enabled may change from one version to the next.
875 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000876CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000877
878/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000879 * \brief Parse the given source file and the translation unit corresponding
880 * to that file.
881 *
882 * This routine is the main entry point for the Clang C API, providing the
883 * ability to parse a source file into a translation unit that can then be
884 * queried by other functions in the API. This routine accepts a set of
885 * command-line arguments so that the compilation can be configured in the same
886 * way that the compiler is configured on the command line.
887 *
888 * \param CIdx The index object with which the translation unit will be
889 * associated.
890 *
891 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000892 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +0000893 *
894 * \param command_line_args The command-line arguments that would be
895 * passed to the \c clang executable if it were being invoked out-of-process.
896 * These command-line options will be parsed and will affect how the translation
897 * unit is parsed. Note that the following options are ignored: '-c',
898 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
899 *
900 * \param num_command_line_args The number of command-line arguments in
901 * \p command_line_args.
902 *
903 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000904 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000905 * those files. The contents and name of these files (as specified by
906 * CXUnsavedFile) are copied when necessary, so the client only needs to
907 * guarantee their validity until the call to this function returns.
908 *
909 * \param num_unsaved_files the number of unsaved file entries in \p
910 * unsaved_files.
911 *
912 * \param options A bitmask of options that affects how the translation unit
913 * is managed but not its compilation. This should be a bitwise OR of the
914 * CXTranslationUnit_XXX flags.
915 *
916 * \returns A new translation unit describing the parsed code and containing
917 * any diagnostics produced by the compiler. If there is a failure from which
918 * the compiler cannot recover, returns NULL.
919 */
920CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
921 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000922 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000923 int num_command_line_args,
924 struct CXUnsavedFile *unsaved_files,
925 unsigned num_unsaved_files,
926 unsigned options);
927
Douglas Gregor5352ac02010-01-28 00:27:43 +0000928/**
Douglas Gregor19998442010-08-13 15:35:05 +0000929 * \brief Flags that control how translation units are saved.
930 *
931 * The enumerators in this enumeration type are meant to be bitwise
932 * ORed together to specify which options should be used when
933 * saving the translation unit.
934 */
935enum CXSaveTranslationUnit_Flags {
936 /**
937 * \brief Used to indicate that no special saving options are needed.
938 */
939 CXSaveTranslationUnit_None = 0x0
940};
941
942/**
943 * \brief Returns the set of flags that is suitable for saving a translation
944 * unit.
945 *
946 * The set of flags returned provide options for
947 * \c clang_saveTranslationUnit() by default. The returned flag
948 * set contains an unspecified set of options that save translation units with
949 * the most commonly-requested data.
950 */
951CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
952
953/**
Douglas Gregor39c411f2011-07-06 16:43:36 +0000954 * \brief Describes the kind of error that occurred (if any) in a call to
955 * \c clang_saveTranslationUnit().
956 */
957enum CXSaveError {
958 /**
959 * \brief Indicates that no error occurred while saving a translation unit.
960 */
961 CXSaveError_None = 0,
962
963 /**
964 * \brief Indicates that an unknown error occurred while attempting to save
965 * the file.
966 *
967 * This error typically indicates that file I/O failed when attempting to
968 * write the file.
969 */
970 CXSaveError_Unknown = 1,
971
972 /**
973 * \brief Indicates that errors during translation prevented this attempt
974 * to save the translation unit.
975 *
976 * Errors that prevent the translation unit from being saved can be
977 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
978 */
979 CXSaveError_TranslationErrors = 2,
980
981 /**
982 * \brief Indicates that the translation unit to be saved was somehow
983 * invalid (e.g., NULL).
984 */
985 CXSaveError_InvalidTU = 3
986};
987
988/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000989 * \brief Saves a translation unit into a serialized representation of
990 * that translation unit on disk.
991 *
992 * Any translation unit that was parsed without error can be saved
993 * into a file. The translation unit can then be deserialized into a
994 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
995 * if it is an incomplete translation unit that corresponds to a
996 * header, used as a precompiled header when parsing other translation
997 * units.
998 *
999 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001000 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001001 * \param FileName The file to which the translation unit will be saved.
1002 *
Douglas Gregor19998442010-08-13 15:35:05 +00001003 * \param options A bitmask of options that affects how the translation unit
1004 * is saved. This should be a bitwise OR of the
1005 * CXSaveTranslationUnit_XXX flags.
1006 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001007 * \returns A value that will match one of the enumerators of the CXSaveError
1008 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1009 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001010 */
1011CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001012 const char *FileName,
1013 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001014
1015/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001016 * \brief Destroy the specified CXTranslationUnit object.
1017 */
1018CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001019
Douglas Gregor5352ac02010-01-28 00:27:43 +00001020/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001021 * \brief Flags that control the reparsing of translation units.
1022 *
1023 * The enumerators in this enumeration type are meant to be bitwise
1024 * ORed together to specify which options should be used when
1025 * reparsing the translation unit.
1026 */
1027enum CXReparse_Flags {
1028 /**
1029 * \brief Used to indicate that no special reparsing options are needed.
1030 */
1031 CXReparse_None = 0x0
1032};
1033
1034/**
1035 * \brief Returns the set of flags that is suitable for reparsing a translation
1036 * unit.
1037 *
1038 * The set of flags returned provide options for
1039 * \c clang_reparseTranslationUnit() by default. The returned flag
1040 * set contains an unspecified set of optimizations geared toward common uses
1041 * of reparsing. The set of optimizations enabled may change from one version
1042 * to the next.
1043 */
1044CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1045
1046/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001047 * \brief Reparse the source files that produced this translation unit.
1048 *
1049 * This routine can be used to re-parse the source files that originally
1050 * created the given translation unit, for example because those source files
1051 * have changed (either on disk or as passed via \p unsaved_files). The
1052 * source code will be reparsed with the same command-line options as it
1053 * was originally parsed.
1054 *
1055 * Reparsing a translation unit invalidates all cursors and source locations
1056 * that refer into that translation unit. This makes reparsing a translation
1057 * unit semantically equivalent to destroying the translation unit and then
1058 * creating a new translation unit with the same command-line arguments.
1059 * However, it may be more efficient to reparse a translation
1060 * unit using this routine.
1061 *
1062 * \param TU The translation unit whose contents will be re-parsed. The
1063 * translation unit must originally have been built with
1064 * \c clang_createTranslationUnitFromSourceFile().
1065 *
1066 * \param num_unsaved_files The number of unsaved file entries in \p
1067 * unsaved_files.
1068 *
1069 * \param unsaved_files The files that have not yet been saved to disk
1070 * but may be required for parsing, including the contents of
1071 * those files. The contents and name of these files (as specified by
1072 * CXUnsavedFile) are copied when necessary, so the client only needs to
1073 * guarantee their validity until the call to this function returns.
1074 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001075 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1076 * The function \c clang_defaultReparseOptions() produces a default set of
1077 * options recommended for most uses, based on the translation unit.
1078 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001079 * \returns 0 if the sources could be reparsed. A non-zero value will be
1080 * returned if reparsing was impossible, such that the translation unit is
1081 * invalid. In such cases, the only valid call for \p TU is
1082 * \c clang_disposeTranslationUnit(TU).
1083 */
1084CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1085 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001086 struct CXUnsavedFile *unsaved_files,
1087 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001088
1089/**
1090 * \brief Categorizes how memory is being used by a translation unit.
1091 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001092enum CXTUResourceUsageKind {
1093 CXTUResourceUsage_AST = 1,
1094 CXTUResourceUsage_Identifiers = 2,
1095 CXTUResourceUsage_Selectors = 3,
1096 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001097 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001098 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001099 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001100 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1101 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1102 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001103 CXTUResourceUsage_Preprocessor = 11,
1104 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001105 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001106 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001107 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1108 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001109 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001110
1111 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001112 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001113};
1114
1115/**
1116 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001117 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001118 */
1119CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001120const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001121
Ted Kremenekf7870022011-04-20 16:41:07 +00001122typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001123 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001124 enum CXTUResourceUsageKind kind;
1125 /* \brief Amount of resources used.
1126 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001127 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001128} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001129
1130/**
1131 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1132 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001133typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001134 /* \brief Private data member, used for queries. */
1135 void *data;
1136
1137 /* \brief The number of entries in the 'entries' array. */
1138 unsigned numEntries;
1139
1140 /* \brief An array of key-value pairs, representing the breakdown of memory
1141 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001142 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001143
Ted Kremenekf7870022011-04-20 16:41:07 +00001144} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001145
1146/**
1147 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001148 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001149 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001150CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001151
Ted Kremenekf7870022011-04-20 16:41:07 +00001152CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001153
Douglas Gregorabc563f2010-07-19 21:46:24 +00001154/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001155 * @}
1156 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001157
Douglas Gregor5352ac02010-01-28 00:27:43 +00001158/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001159 * \brief Describes the kind of entity that a cursor refers to.
1160 */
1161enum CXCursorKind {
1162 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001163 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001164 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001165 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001166 *
1167 * Unexposed declarations have the same operations as any other kind
1168 * of declaration; one can extract their location information,
1169 * spelling, find their definitions, etc. However, the specific kind
1170 * of the declaration is not reported.
1171 */
1172 CXCursor_UnexposedDecl = 1,
1173 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001174 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001175 /** \brief A C or C++ union. */
1176 CXCursor_UnionDecl = 3,
1177 /** \brief A C++ class. */
1178 CXCursor_ClassDecl = 4,
1179 /** \brief An enumeration. */
1180 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001181 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001182 * \brief A field (in C) or non-static data member (in C++) in a
1183 * struct, union, or C++ class.
1184 */
1185 CXCursor_FieldDecl = 6,
1186 /** \brief An enumerator constant. */
1187 CXCursor_EnumConstantDecl = 7,
1188 /** \brief A function. */
1189 CXCursor_FunctionDecl = 8,
1190 /** \brief A variable. */
1191 CXCursor_VarDecl = 9,
1192 /** \brief A function or method parameter. */
1193 CXCursor_ParmDecl = 10,
1194 /** \brief An Objective-C @interface. */
1195 CXCursor_ObjCInterfaceDecl = 11,
1196 /** \brief An Objective-C @interface for a category. */
1197 CXCursor_ObjCCategoryDecl = 12,
1198 /** \brief An Objective-C @protocol declaration. */
1199 CXCursor_ObjCProtocolDecl = 13,
1200 /** \brief An Objective-C @property declaration. */
1201 CXCursor_ObjCPropertyDecl = 14,
1202 /** \brief An Objective-C instance variable. */
1203 CXCursor_ObjCIvarDecl = 15,
1204 /** \brief An Objective-C instance method. */
1205 CXCursor_ObjCInstanceMethodDecl = 16,
1206 /** \brief An Objective-C class method. */
1207 CXCursor_ObjCClassMethodDecl = 17,
1208 /** \brief An Objective-C @implementation. */
1209 CXCursor_ObjCImplementationDecl = 18,
1210 /** \brief An Objective-C @implementation for a category. */
1211 CXCursor_ObjCCategoryImplDecl = 19,
1212 /** \brief A typedef */
1213 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001214 /** \brief A C++ class method. */
1215 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001216 /** \brief A C++ namespace. */
1217 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001218 /** \brief A linkage specification, e.g. 'extern "C"'. */
1219 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001220 /** \brief A C++ constructor. */
1221 CXCursor_Constructor = 24,
1222 /** \brief A C++ destructor. */
1223 CXCursor_Destructor = 25,
1224 /** \brief A C++ conversion function. */
1225 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001226 /** \brief A C++ template type parameter. */
1227 CXCursor_TemplateTypeParameter = 27,
1228 /** \brief A C++ non-type template parameter. */
1229 CXCursor_NonTypeTemplateParameter = 28,
1230 /** \brief A C++ template template parameter. */
1231 CXCursor_TemplateTemplateParameter = 29,
1232 /** \brief A C++ function template. */
1233 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001234 /** \brief A C++ class template. */
1235 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001236 /** \brief A C++ class template partial specialization. */
1237 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001238 /** \brief A C++ namespace alias declaration. */
1239 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001240 /** \brief A C++ using directive. */
1241 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001242 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001243 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001244 /** \brief A C++ alias declaration */
1245 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001246 /** \brief An Objective-C @synthesize definition. */
1247 CXCursor_ObjCSynthesizeDecl = 37,
1248 /** \brief An Objective-C @dynamic definition. */
1249 CXCursor_ObjCDynamicDecl = 38,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001250 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor352697a2011-06-03 23:08:58 +00001251 CXCursor_LastDecl = CXCursor_ObjCDynamicDecl,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001252
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001253 /* References */
1254 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001255 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001256 CXCursor_ObjCProtocolRef = 41,
1257 CXCursor_ObjCClassRef = 42,
1258 /**
1259 * \brief A reference to a type declaration.
1260 *
1261 * A type reference occurs anywhere where a type is named but not
1262 * declared. For example, given:
1263 *
1264 * \code
1265 * typedef unsigned size_type;
1266 * size_type size;
1267 * \endcode
1268 *
1269 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1270 * while the type of the variable "size" is referenced. The cursor
1271 * referenced by the type of size is the typedef for size_type.
1272 */
1273 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001274 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001275 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001276 * \brief A reference to a class template, function template, template
1277 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001278 */
1279 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001280 /**
1281 * \brief A reference to a namespace or namespace alias.
1282 */
1283 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001284 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001285 * \brief A reference to a member of a struct, union, or class that occurs in
1286 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001287 */
1288 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001289 /**
1290 * \brief A reference to a labeled statement.
1291 *
1292 * This cursor kind is used to describe the jump to "start_over" in the
1293 * goto statement in the following example:
1294 *
1295 * \code
1296 * start_over:
1297 * ++counter;
1298 *
1299 * goto start_over;
1300 * \endcode
1301 *
1302 * A label reference cursor refers to a label statement.
1303 */
1304 CXCursor_LabelRef = 48,
1305
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001306 /**
1307 * \brief A reference to a set of overloaded functions or function templates
1308 * that has not yet been resolved to a specific function or function template.
1309 *
1310 * An overloaded declaration reference cursor occurs in C++ templates where
1311 * a dependent name refers to a function. For example:
1312 *
1313 * \code
1314 * template<typename T> void swap(T&, T&);
1315 *
1316 * struct X { ... };
1317 * void swap(X&, X&);
1318 *
1319 * template<typename T>
1320 * void reverse(T* first, T* last) {
1321 * while (first < last - 1) {
1322 * swap(*first, *--last);
1323 * ++first;
1324 * }
1325 * }
1326 *
1327 * struct Y { };
1328 * void swap(Y&, Y&);
1329 * \endcode
1330 *
1331 * Here, the identifier "swap" is associated with an overloaded declaration
1332 * reference. In the template definition, "swap" refers to either of the two
1333 * "swap" functions declared above, so both results will be available. At
1334 * instantiation time, "swap" may also refer to other functions found via
1335 * argument-dependent lookup (e.g., the "swap" function at the end of the
1336 * example).
1337 *
1338 * The functions \c clang_getNumOverloadedDecls() and
1339 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1340 * referenced by this cursor.
1341 */
1342 CXCursor_OverloadedDeclRef = 49,
1343
1344 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001345
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001346 /* Error conditions */
1347 CXCursor_FirstInvalid = 70,
1348 CXCursor_InvalidFile = 70,
1349 CXCursor_NoDeclFound = 71,
1350 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001351 CXCursor_InvalidCode = 73,
1352 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001353
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001354 /* Expressions */
1355 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001356
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001357 /**
1358 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001359 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001360 *
1361 * Unexposed expressions have the same operations as any other kind
1362 * of expression; one can extract their location information,
1363 * spelling, children, etc. However, the specific kind of the
1364 * expression is not reported.
1365 */
1366 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001367
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001368 /**
1369 * \brief An expression that refers to some value declaration, such
1370 * as a function, varible, or enumerator.
1371 */
1372 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001373
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001374 /**
1375 * \brief An expression that refers to a member of a struct, union,
1376 * class, Objective-C class, etc.
1377 */
1378 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001379
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001380 /** \brief An expression that calls a function. */
1381 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001382
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001383 /** \brief An expression that sends a message to an Objective-C
1384 object or class. */
1385 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001386
1387 /** \brief An expression that represents a block literal. */
1388 CXCursor_BlockExpr = 105,
1389
1390 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001391
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001392 /* Statements */
1393 CXCursor_FirstStmt = 200,
1394 /**
1395 * \brief A statement whose specific kind is not exposed via this
1396 * interface.
1397 *
1398 * Unexposed statements have the same operations as any other kind of
1399 * statement; one can extract their location information, spelling,
1400 * children, etc. However, the specific kind of the statement is not
1401 * reported.
1402 */
1403 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001404
1405 /** \brief A labelled statement in a function.
1406 *
1407 * This cursor kind is used to describe the "start_over:" label statement in
1408 * the following example:
1409 *
1410 * \code
1411 * start_over:
1412 * ++counter;
1413 * \endcode
1414 *
1415 */
1416 CXCursor_LabelStmt = 201,
1417
1418 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001419
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001420 /**
1421 * \brief Cursor that represents the translation unit itself.
1422 *
1423 * The translation unit cursor exists primarily to act as the root
1424 * cursor for traversing the contents of a translation unit.
1425 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001426 CXCursor_TranslationUnit = 300,
1427
1428 /* Attributes */
1429 CXCursor_FirstAttr = 400,
1430 /**
1431 * \brief An attribute whose specific kind is not exposed via this
1432 * interface.
1433 */
1434 CXCursor_UnexposedAttr = 400,
1435
1436 CXCursor_IBActionAttr = 401,
1437 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001438 CXCursor_IBOutletCollectionAttr = 403,
1439 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001440
1441 /* Preprocessing */
1442 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001443 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00001444 CXCursor_MacroExpansion = 502,
1445 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001446 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001447 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001448 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001449};
1450
1451/**
1452 * \brief A cursor representing some element in the abstract syntax tree for
1453 * a translation unit.
1454 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001455 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001456 * program--declaration, statements, expressions, references to declarations,
1457 * etc.--under a single "cursor" abstraction with a common set of operations.
1458 * Common operation for a cursor include: getting the physical location in
1459 * a source file where the cursor points, getting the name associated with a
1460 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1461 *
1462 * Cursors can be produced in two specific ways.
1463 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1464 * from which one can use clang_visitChildren() to explore the rest of the
1465 * translation unit. clang_getCursor() maps from a physical source location
1466 * to the entity that resides at that location, allowing one to map from the
1467 * source code into the AST.
1468 */
1469typedef struct {
1470 enum CXCursorKind kind;
1471 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001472} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001473
1474/**
1475 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1476 *
1477 * @{
1478 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001479
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001480/**
1481 * \brief Retrieve the NULL cursor, which represents no entity.
1482 */
1483CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001484
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001485/**
1486 * \brief Retrieve the cursor that represents the given translation unit.
1487 *
1488 * The translation unit cursor can be used to start traversing the
1489 * various declarations within the given translation unit.
1490 */
1491CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1492
1493/**
1494 * \brief Determine whether two cursors are equivalent.
1495 */
1496CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001497
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001498/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001499 * \brief Compute a hash value for the given cursor.
1500 */
1501CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1502
1503/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001504 * \brief Retrieve the kind of the given cursor.
1505 */
1506CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1507
1508/**
1509 * \brief Determine whether the given cursor kind represents a declaration.
1510 */
1511CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1512
1513/**
1514 * \brief Determine whether the given cursor kind represents a simple
1515 * reference.
1516 *
1517 * Note that other kinds of cursors (such as expressions) can also refer to
1518 * other cursors. Use clang_getCursorReferenced() to determine whether a
1519 * particular cursor refers to another entity.
1520 */
1521CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1522
1523/**
1524 * \brief Determine whether the given cursor kind represents an expression.
1525 */
1526CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1527
1528/**
1529 * \brief Determine whether the given cursor kind represents a statement.
1530 */
1531CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1532
1533/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00001534 * \brief Determine whether the given cursor kind represents an attribute.
1535 */
1536CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
1537
1538/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001539 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001540 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001541 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001542CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1543
1544/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001545 * \brief Determine whether the given cursor kind represents a translation
1546 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001547 */
1548CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001549
Ted Kremenekad6eff62010-03-08 21:17:29 +00001550/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001551 * \brief Determine whether the given cursor represents a preprocessing
1552 * element, such as a preprocessor directive or macro instantiation.
1553 */
1554CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1555
1556/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001557 * \brief Determine whether the given cursor represents a currently
1558 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1559 */
1560CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1561
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001562/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001563 * \brief Describe the linkage of the entity referred to by a cursor.
1564 */
1565enum CXLinkageKind {
1566 /** \brief This value indicates that no linkage information is available
1567 * for a provided CXCursor. */
1568 CXLinkage_Invalid,
1569 /**
1570 * \brief This is the linkage for variables, parameters, and so on that
1571 * have automatic storage. This covers normal (non-extern) local variables.
1572 */
1573 CXLinkage_NoLinkage,
1574 /** \brief This is the linkage for static variables and static functions. */
1575 CXLinkage_Internal,
1576 /** \brief This is the linkage for entities with external linkage that live
1577 * in C++ anonymous namespaces.*/
1578 CXLinkage_UniqueExternal,
1579 /** \brief This is the linkage for entities with true, external linkage. */
1580 CXLinkage_External
1581};
1582
1583/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001584 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001585 */
1586CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1587
1588/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001589 * \brief Determine the availability of the entity that this cursor refers to.
1590 *
1591 * \param cursor The cursor to query.
1592 *
1593 * \returns The availability of the cursor.
1594 */
1595CINDEX_LINKAGE enum CXAvailabilityKind
1596clang_getCursorAvailability(CXCursor cursor);
1597
1598/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001599 * \brief Describe the "language" of the entity referred to by a cursor.
1600 */
1601CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001602 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001603 CXLanguage_C,
1604 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001605 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001606};
1607
1608/**
1609 * \brief Determine the "language" of the entity referred to by a given cursor.
1610 */
1611CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1612
Ted Kremenekeca099b2010-12-08 23:43:14 +00001613
1614/**
1615 * \brief A fast container representing a set of CXCursors.
1616 */
1617typedef struct CXCursorSetImpl *CXCursorSet;
1618
1619/**
1620 * \brief Creates an empty CXCursorSet.
1621 */
1622CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
1623
1624/**
1625 * \brief Disposes a CXCursorSet and releases its associated memory.
1626 */
1627CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
1628
1629/**
1630 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
1631 *
1632 * \returns non-zero if the set contains the specified cursor.
1633*/
1634CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
1635 CXCursor cursor);
1636
1637/**
1638 * \brief Inserts a CXCursor into a CXCursorSet.
1639 *
1640 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
1641*/
1642CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
1643 CXCursor cursor);
1644
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001645/**
1646 * \brief Determine the semantic parent of the given cursor.
1647 *
1648 * The semantic parent of a cursor is the cursor that semantically contains
1649 * the given \p cursor. For many declarations, the lexical and semantic parents
1650 * are equivalent (the lexical parent is returned by
1651 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1652 * definitions are provided out-of-line. For example:
1653 *
1654 * \code
1655 * class C {
1656 * void f();
1657 * };
1658 *
1659 * void C::f() { }
1660 * \endcode
1661 *
1662 * In the out-of-line definition of \c C::f, the semantic parent is the
1663 * the class \c C, of which this function is a member. The lexical parent is
1664 * the place where the declaration actually occurs in the source code; in this
1665 * case, the definition occurs in the translation unit. In general, the
1666 * lexical parent for a given entity can change without affecting the semantics
1667 * of the program, and the lexical parent of different declarations of the
1668 * same entity may be different. Changing the semantic parent of a declaration,
1669 * on the other hand, can have a major impact on semantics, and redeclarations
1670 * of a particular entity should all have the same semantic context.
1671 *
1672 * In the example above, both declarations of \c C::f have \c C as their
1673 * semantic context, while the lexical context of the first \c C::f is \c C
1674 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001675 *
1676 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001677 */
1678CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1679
1680/**
1681 * \brief Determine the lexical parent of the given cursor.
1682 *
1683 * The lexical parent of a cursor is the cursor in which the given \p cursor
1684 * was actually written. For many declarations, the lexical and semantic parents
1685 * are equivalent (the semantic parent is returned by
1686 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1687 * definitions are provided out-of-line. For example:
1688 *
1689 * \code
1690 * class C {
1691 * void f();
1692 * };
1693 *
1694 * void C::f() { }
1695 * \endcode
1696 *
1697 * In the out-of-line definition of \c C::f, the semantic parent is the
1698 * the class \c C, of which this function is a member. The lexical parent is
1699 * the place where the declaration actually occurs in the source code; in this
1700 * case, the definition occurs in the translation unit. In general, the
1701 * lexical parent for a given entity can change without affecting the semantics
1702 * of the program, and the lexical parent of different declarations of the
1703 * same entity may be different. Changing the semantic parent of a declaration,
1704 * on the other hand, can have a major impact on semantics, and redeclarations
1705 * of a particular entity should all have the same semantic context.
1706 *
1707 * In the example above, both declarations of \c C::f have \c C as their
1708 * semantic context, while the lexical context of the first \c C::f is \c C
1709 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001710 *
1711 * For declarations written in the global scope, the lexical parent is
1712 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001713 */
1714CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001715
1716/**
1717 * \brief Determine the set of methods that are overridden by the given
1718 * method.
1719 *
1720 * In both Objective-C and C++, a method (aka virtual member function,
1721 * in C++) can override a virtual method in a base class. For
1722 * Objective-C, a method is said to override any method in the class's
1723 * interface (if we're coming from an implementation), its protocols,
1724 * or its categories, that has the same selector and is of the same
1725 * kind (class or instance). If no such method exists, the search
1726 * continues to the class's superclass, its protocols, and its
1727 * categories, and so on.
1728 *
1729 * For C++, a virtual member function overrides any virtual member
1730 * function with the same signature that occurs in its base
1731 * classes. With multiple inheritance, a virtual member function can
1732 * override several virtual member functions coming from different
1733 * base classes.
1734 *
1735 * In all cases, this function determines the immediate overridden
1736 * method, rather than all of the overridden methods. For example, if
1737 * a method is originally declared in a class A, then overridden in B
1738 * (which in inherits from A) and also in C (which inherited from B),
1739 * then the only overridden method returned from this function when
1740 * invoked on C's method will be B's method. The client may then
1741 * invoke this function again, given the previously-found overridden
1742 * methods, to map out the complete method-override set.
1743 *
1744 * \param cursor A cursor representing an Objective-C or C++
1745 * method. This routine will compute the set of methods that this
1746 * method overrides.
1747 *
1748 * \param overridden A pointer whose pointee will be replaced with a
1749 * pointer to an array of cursors, representing the set of overridden
1750 * methods. If there are no overridden methods, the pointee will be
1751 * set to NULL. The pointee must be freed via a call to
1752 * \c clang_disposeOverriddenCursors().
1753 *
1754 * \param num_overridden A pointer to the number of overridden
1755 * functions, will be set to the number of overridden functions in the
1756 * array pointed to by \p overridden.
1757 */
1758CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1759 CXCursor **overridden,
1760 unsigned *num_overridden);
1761
1762/**
1763 * \brief Free the set of overridden cursors returned by \c
1764 * clang_getOverriddenCursors().
1765 */
1766CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1767
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001768/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001769 * \brief Retrieve the file that is included by the given inclusion directive
1770 * cursor.
1771 */
1772CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1773
1774/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001775 * @}
1776 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001777
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001778/**
1779 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1780 *
1781 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1782 * routines help map between cursors and the physical locations where the
1783 * described entities occur in the source code. The mapping is provided in
1784 * both directions, so one can map from source code to the AST and back.
1785 *
1786 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001787 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001788
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001789/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001790 * \brief Map a source location to the cursor that describes the entity at that
1791 * location in the source code.
1792 *
1793 * clang_getCursor() maps an arbitrary source location within a translation
1794 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001795 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001796 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001797 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001798 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1799 * will return a cursor referring to the "+" expression.
1800 *
1801 * \returns a cursor representing the entity at the given source location, or
1802 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001803 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001804CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001805
Douglas Gregor98258af2010-01-18 22:46:11 +00001806/**
1807 * \brief Retrieve the physical location of the source constructor referenced
1808 * by the given cursor.
1809 *
1810 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001811 * declaration, where the name of that declaration would occur if it is
1812 * unnamed, or some keyword that introduces that particular declaration.
1813 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001814 * source code.
1815 */
1816CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001817
Douglas Gregorb6998662010-01-19 19:34:47 +00001818/**
1819 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001820 * the given cursor.
1821 *
1822 * The extent of a cursor starts with the file/line/column pointing at the
1823 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001824 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001825 * declaration, the extent covers the declaration itself. For a reference,
1826 * the extent covers the location of the reference (e.g., where the referenced
1827 * entity was actually used).
1828 */
1829CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001830
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001831/**
1832 * @}
1833 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001834
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001835/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001836 * \defgroup CINDEX_TYPES Type information for CXCursors
1837 *
1838 * @{
1839 */
1840
1841/**
1842 * \brief Describes the kind of type
1843 */
1844enum CXTypeKind {
1845 /**
1846 * \brief Reprents an invalid type (e.g., where no type is available).
1847 */
1848 CXType_Invalid = 0,
1849
1850 /**
1851 * \brief A type whose specific kind is not exposed via this
1852 * interface.
1853 */
1854 CXType_Unexposed = 1,
1855
1856 /* Builtin types */
1857 CXType_Void = 2,
1858 CXType_Bool = 3,
1859 CXType_Char_U = 4,
1860 CXType_UChar = 5,
1861 CXType_Char16 = 6,
1862 CXType_Char32 = 7,
1863 CXType_UShort = 8,
1864 CXType_UInt = 9,
1865 CXType_ULong = 10,
1866 CXType_ULongLong = 11,
1867 CXType_UInt128 = 12,
1868 CXType_Char_S = 13,
1869 CXType_SChar = 14,
1870 CXType_WChar = 15,
1871 CXType_Short = 16,
1872 CXType_Int = 17,
1873 CXType_Long = 18,
1874 CXType_LongLong = 19,
1875 CXType_Int128 = 20,
1876 CXType_Float = 21,
1877 CXType_Double = 22,
1878 CXType_LongDouble = 23,
1879 CXType_NullPtr = 24,
1880 CXType_Overload = 25,
1881 CXType_Dependent = 26,
1882 CXType_ObjCId = 27,
1883 CXType_ObjCClass = 28,
1884 CXType_ObjCSel = 29,
1885 CXType_FirstBuiltin = CXType_Void,
1886 CXType_LastBuiltin = CXType_ObjCSel,
1887
1888 CXType_Complex = 100,
1889 CXType_Pointer = 101,
1890 CXType_BlockPointer = 102,
1891 CXType_LValueReference = 103,
1892 CXType_RValueReference = 104,
1893 CXType_Record = 105,
1894 CXType_Enum = 106,
1895 CXType_Typedef = 107,
1896 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001897 CXType_ObjCObjectPointer = 109,
1898 CXType_FunctionNoProto = 110,
1899 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001900};
1901
1902/**
1903 * \brief The type of an element in the abstract syntax tree.
1904 *
1905 */
1906typedef struct {
1907 enum CXTypeKind kind;
1908 void *data[2];
1909} CXType;
1910
1911/**
1912 * \brief Retrieve the type of a CXCursor (if any).
1913 */
1914CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1915
1916/**
1917 * \determine Determine whether two CXTypes represent the same type.
1918 *
1919 * \returns non-zero if the CXTypes represent the same type and
1920 zero otherwise.
1921 */
1922CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1923
1924/**
1925 * \brief Return the canonical type for a CXType.
1926 *
1927 * Clang's type system explicitly models typedefs and all the ways
1928 * a specific type can be represented. The canonical type is the underlying
1929 * type with all the "sugar" removed. For example, if 'T' is a typedef
1930 * for 'int', the canonical type for 'T' would be 'int'.
1931 */
1932CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1933
1934/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00001935 * \determine Determine whether a CXType has the "const" qualifier set,
1936 * without looking through typedefs that may have added "const" at a different level.
1937 */
1938CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
1939
1940/**
1941 * \determine Determine whether a CXType has the "volatile" qualifier set,
1942 * without looking through typedefs that may have added "volatile" at a different level.
1943 */
1944CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
1945
1946/**
1947 * \determine Determine whether a CXType has the "restrict" qualifier set,
1948 * without looking through typedefs that may have added "restrict" at a different level.
1949 */
1950CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
1951
1952/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001953 * \brief For pointer types, returns the type of the pointee.
1954 *
1955 */
1956CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1957
1958/**
1959 * \brief Return the cursor for the declaration of the given type.
1960 */
1961CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1962
David Chisnall5389f482010-12-30 14:05:53 +00001963/**
1964 * Returns the Objective-C type encoding for the specified declaration.
1965 */
1966CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001967
1968/**
1969 * \brief Retrieve the spelling of a given CXTypeKind.
1970 */
1971CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1972
1973/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001974 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001975 */
1976CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1977
1978/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001979 * \brief Retrieve the result type associated with a given cursor. This only
1980 * returns a valid type of the cursor refers to a function or method.
1981 */
1982CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1983
1984/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001985 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1986 * otherwise.
1987 */
1988CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1989
1990/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001991 * \brief Returns 1 if the base class specified by the cursor with kind
1992 * CX_CXXBaseSpecifier is virtual.
1993 */
1994CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1995
1996/**
1997 * \brief Represents the C++ access control level to a base class for a
1998 * cursor with kind CX_CXXBaseSpecifier.
1999 */
2000enum CX_CXXAccessSpecifier {
2001 CX_CXXInvalidAccessSpecifier,
2002 CX_CXXPublic,
2003 CX_CXXProtected,
2004 CX_CXXPrivate
2005};
2006
2007/**
2008 * \brief Returns the access control level for the C++ base specifier
2009 * represented by a cursor with kind CX_CXXBaseSpecifier.
2010 */
2011CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2012
2013/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002014 * \brief Determine the number of overloaded declarations referenced by a
2015 * \c CXCursor_OverloadedDeclRef cursor.
2016 *
2017 * \param cursor The cursor whose overloaded declarations are being queried.
2018 *
2019 * \returns The number of overloaded declarations referenced by \c cursor. If it
2020 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2021 */
2022CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2023
2024/**
2025 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2026 * by a \c CXCursor_OverloadedDeclRef cursor.
2027 *
2028 * \param cursor The cursor whose overloaded declarations are being queried.
2029 *
2030 * \param index The zero-based index into the set of overloaded declarations in
2031 * the cursor.
2032 *
2033 * \returns A cursor representing the declaration referenced by the given
2034 * \c cursor at the specified \c index. If the cursor does not have an
2035 * associated set of overloaded declarations, or if the index is out of bounds,
2036 * returns \c clang_getNullCursor();
2037 */
2038CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2039 unsigned index);
2040
2041/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002042 * @}
2043 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002044
2045/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002046 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002047 *
2048 * @{
2049 */
2050
2051
2052/**
2053 * \brief For cursors representing an iboutletcollection attribute,
2054 * this function returns the collection element type.
2055 *
2056 */
2057CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2058
2059/**
2060 * @}
2061 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002062
2063/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002064 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2065 *
2066 * These routines provide the ability to traverse the abstract syntax tree
2067 * using cursors.
2068 *
2069 * @{
2070 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002071
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002072/**
2073 * \brief Describes how the traversal of the children of a particular
2074 * cursor should proceed after visiting a particular child cursor.
2075 *
2076 * A value of this enumeration type should be returned by each
2077 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2078 */
2079enum CXChildVisitResult {
2080 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002081 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002082 */
2083 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002084 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002085 * \brief Continues the cursor traversal with the next sibling of
2086 * the cursor just visited, without visiting its children.
2087 */
2088 CXChildVisit_Continue,
2089 /**
2090 * \brief Recursively traverse the children of this cursor, using
2091 * the same visitor and client data.
2092 */
2093 CXChildVisit_Recurse
2094};
2095
2096/**
2097 * \brief Visitor invoked for each cursor found by a traversal.
2098 *
2099 * This visitor function will be invoked for each cursor found by
2100 * clang_visitCursorChildren(). Its first argument is the cursor being
2101 * visited, its second argument is the parent visitor for that cursor,
2102 * and its third argument is the client data provided to
2103 * clang_visitCursorChildren().
2104 *
2105 * The visitor should return one of the \c CXChildVisitResult values
2106 * to direct clang_visitCursorChildren().
2107 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002108typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2109 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002110 CXClientData client_data);
2111
2112/**
2113 * \brief Visit the children of a particular cursor.
2114 *
2115 * This function visits all the direct children of the given cursor,
2116 * invoking the given \p visitor function with the cursors of each
2117 * visited child. The traversal may be recursive, if the visitor returns
2118 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2119 * the visitor returns \c CXChildVisit_Break.
2120 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002121 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002122 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002123 * definition, have no children).
2124 *
2125 * \param visitor the visitor function that will be invoked for each
2126 * child of \p parent.
2127 *
2128 * \param client_data pointer data supplied by the client, which will
2129 * be passed to the visitor each time it is invoked.
2130 *
2131 * \returns a non-zero value if the traversal was terminated
2132 * prematurely by the visitor returning \c CXChildVisit_Break.
2133 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002134CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002135 CXCursorVisitor visitor,
2136 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002137#ifdef __has_feature
2138# if __has_feature(blocks)
2139/**
2140 * \brief Visitor invoked for each cursor found by a traversal.
2141 *
2142 * This visitor block will be invoked for each cursor found by
2143 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2144 * visited, its second argument is the parent visitor for that cursor.
2145 *
2146 * The visitor should return one of the \c CXChildVisitResult values
2147 * to direct clang_visitChildrenWithBlock().
2148 */
2149typedef enum CXChildVisitResult
2150 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2151
2152/**
2153 * Visits the children of a cursor using the specified block. Behaves
2154 * identically to clang_visitChildren() in all other respects.
2155 */
2156unsigned clang_visitChildrenWithBlock(CXCursor parent,
2157 CXCursorVisitorBlock block);
2158# endif
2159#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002160
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002161/**
2162 * @}
2163 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002164
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002165/**
2166 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2167 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002168 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002169 * across translation units, by providing the names of the entities referenced
2170 * by cursors, follow reference cursors to the declarations they reference,
2171 * and associate declarations with their definitions.
2172 *
2173 * @{
2174 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002175
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002176/**
2177 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2178 * by the given cursor.
2179 *
2180 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2181 * entity (function, class, variable, etc.) within a program. USRs can be
2182 * compared across translation units to determine, e.g., when references in
2183 * one translation refer to an entity defined in another translation unit.
2184 */
2185CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2186
2187/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002188 * \brief Construct a USR for a specified Objective-C class.
2189 */
2190CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2191
2192/**
2193 * \brief Construct a USR for a specified Objective-C category.
2194 */
2195CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002196 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002197 const char *category_name);
2198
2199/**
2200 * \brief Construct a USR for a specified Objective-C protocol.
2201 */
2202CINDEX_LINKAGE CXString
2203 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2204
2205
2206/**
2207 * \brief Construct a USR for a specified Objective-C instance variable and
2208 * the USR for its containing class.
2209 */
2210CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2211 CXString classUSR);
2212
2213/**
2214 * \brief Construct a USR for a specified Objective-C method and
2215 * the USR for its containing class.
2216 */
2217CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2218 unsigned isInstanceMethod,
2219 CXString classUSR);
2220
2221/**
2222 * \brief Construct a USR for a specified Objective-C property and the USR
2223 * for its containing class.
2224 */
2225CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2226 CXString classUSR);
2227
2228/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002229 * \brief Retrieve a name for the entity referenced by this cursor.
2230 */
2231CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2232
Douglas Gregor358559d2010-10-02 22:49:11 +00002233/**
2234 * \brief Retrieve the display name for the entity referenced by this cursor.
2235 *
2236 * The display name contains extra information that helps identify the cursor,
2237 * such as the parameters of a function or template or the arguments of a
2238 * class template specialization.
2239 */
2240CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2241
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002242/** \brief For a cursor that is a reference, retrieve a cursor representing the
2243 * entity that it references.
2244 *
2245 * Reference cursors refer to other entities in the AST. For example, an
2246 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002247 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002248 * cursor for the superclass reference. If the input cursor is a declaration or
2249 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002250 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002251 */
2252CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002253
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002254/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002255 * \brief For a cursor that is either a reference to or a declaration
2256 * of some entity, retrieve a cursor that describes the definition of
2257 * that entity.
2258 *
2259 * Some entities can be declared multiple times within a translation
2260 * unit, but only one of those declarations can also be a
2261 * definition. For example, given:
2262 *
2263 * \code
2264 * int f(int, int);
2265 * int g(int x, int y) { return f(x, y); }
2266 * int f(int a, int b) { return a + b; }
2267 * int f(int, int);
2268 * \endcode
2269 *
2270 * there are three declarations of the function "f", but only the
2271 * second one is a definition. The clang_getCursorDefinition()
2272 * function will take any cursor pointing to a declaration of "f"
2273 * (the first or fourth lines of the example) or a cursor referenced
2274 * that uses "f" (the call to "f' inside "g") and will return a
2275 * declaration cursor pointing to the definition (the second "f"
2276 * declaration).
2277 *
2278 * If given a cursor for which there is no corresponding definition,
2279 * e.g., because there is no definition of that entity within this
2280 * translation unit, returns a NULL cursor.
2281 */
2282CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2283
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002284/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002285 * \brief Determine whether the declaration pointed to by this cursor
2286 * is also a definition of that entity.
2287 */
2288CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2289
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002290/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002291 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2292 *
2293 * In the C family of languages, many kinds of entities can be declared several
2294 * times within a single translation unit. For example, a structure type can
2295 * be forward-declared (possibly multiple times) and later defined:
2296 *
2297 * \code
2298 * struct X;
2299 * struct X;
2300 * struct X {
2301 * int member;
2302 * };
2303 * \endcode
2304 *
2305 * The declarations and the definition of \c X are represented by three
2306 * different cursors, all of which are declarations of the same underlying
2307 * entity. One of these cursor is considered the "canonical" cursor, which
2308 * is effectively the representative for the underlying entity. One can
2309 * determine if two cursors are declarations of the same underlying entity by
2310 * comparing their canonical cursors.
2311 *
2312 * \returns The canonical cursor for the entity referred to by the given cursor.
2313 */
2314CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2315
2316/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002317 * @}
2318 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002319
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002320/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002321 * \defgroup CINDEX_CPP C++ AST introspection
2322 *
2323 * The routines in this group provide access information in the ASTs specific
2324 * to C++ language features.
2325 *
2326 * @{
2327 */
2328
2329/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002330 * \brief Determine if a C++ member function or member function template is
2331 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002332 */
2333CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2334
2335/**
Douglas Gregor211924b2011-05-12 15:17:24 +00002336 * \brief Determine if a C++ member function or member function template is
2337 * explicitly declared 'virtual' or if it overrides a virtual method from
2338 * one of the base classes.
2339 */
2340CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2341
2342/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002343 * \brief Given a cursor that represents a template, determine
2344 * the cursor kind of the specializations would be generated by instantiating
2345 * the template.
2346 *
2347 * This routine can be used to determine what flavor of function template,
2348 * class template, or class template partial specialization is stored in the
2349 * cursor. For example, it can describe whether a class template cursor is
2350 * declared with "struct", "class" or "union".
2351 *
2352 * \param C The cursor to query. This cursor should represent a template
2353 * declaration.
2354 *
2355 * \returns The cursor kind of the specializations that would be generated
2356 * by instantiating the template \p C. If \p C is not a template, returns
2357 * \c CXCursor_NoDeclFound.
2358 */
2359CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2360
2361/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002362 * \brief Given a cursor that may represent a specialization or instantiation
2363 * of a template, retrieve the cursor that represents the template that it
2364 * specializes or from which it was instantiated.
2365 *
2366 * This routine determines the template involved both for explicit
2367 * specializations of templates and for implicit instantiations of the template,
2368 * both of which are referred to as "specializations". For a class template
2369 * specialization (e.g., \c std::vector<bool>), this routine will return
2370 * either the primary template (\c std::vector) or, if the specialization was
2371 * instantiated from a class template partial specialization, the class template
2372 * partial specialization. For a class template partial specialization and a
2373 * function template specialization (including instantiations), this
2374 * this routine will return the specialized template.
2375 *
2376 * For members of a class template (e.g., member functions, member classes, or
2377 * static data members), returns the specialized or instantiated member.
2378 * Although not strictly "templates" in the C++ language, members of class
2379 * templates have the same notions of specializations and instantiations that
2380 * templates do, so this routine treats them similarly.
2381 *
2382 * \param C A cursor that may be a specialization of a template or a member
2383 * of a template.
2384 *
2385 * \returns If the given cursor is a specialization or instantiation of a
2386 * template or a member thereof, the template or member that it specializes or
2387 * from which it was instantiated. Otherwise, returns a NULL cursor.
2388 */
2389CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00002390
2391/**
2392 * \brief Given a cursor that references something else, return the source range
2393 * covering that reference.
2394 *
2395 * \param C A cursor pointing to a member reference, a declaration reference, or
2396 * an operator call.
2397 * \param NameFlags A bitset with three independent flags:
2398 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
2399 * CXNameRange_WantSinglePiece.
2400 * \param PieceIndex For contiguous names or when passing the flag
2401 * CXNameRange_WantSinglePiece, only one piece with index 0 is
2402 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
2403 * non-contiguous names, this index can be used to retreive the individual
2404 * pieces of the name. See also CXNameRange_WantSinglePiece.
2405 *
2406 * \returns The piece of the name pointed to by the given cursor. If there is no
2407 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
2408 */
Francois Pichet48a8d142011-07-25 22:00:44 +00002409CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
2410 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00002411 unsigned PieceIndex);
2412
2413enum CXNameRefFlags {
2414 /**
2415 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
2416 * range.
2417 */
2418 CXNameRange_WantQualifier = 0x1,
2419
2420 /**
2421 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
2422 * the range.
2423 */
2424 CXNameRange_WantTemplateArgs = 0x2,
2425
2426 /**
2427 * \brief If the name is non-contiguous, return the full spanning range.
2428 *
2429 * Non-contiguous names occur in Objective-C when a selector with two or more
2430 * parameters is used, or in C++ when using an operator:
2431 * \code
2432 * [object doSomething:here withValue:there]; // ObjC
2433 * return some_vector[1]; // C++
2434 * \endcode
2435 */
2436 CXNameRange_WantSinglePiece = 0x4
2437};
Douglas Gregore0329ac2010-09-02 00:07:54 +00002438
2439/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002440 * @}
2441 */
2442
2443/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002444 * \defgroup CINDEX_LEX Token extraction and manipulation
2445 *
2446 * The routines in this group provide access to the tokens within a
2447 * translation unit, along with a semantic mapping of those tokens to
2448 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002449 *
2450 * @{
2451 */
2452
2453/**
2454 * \brief Describes a kind of token.
2455 */
2456typedef enum CXTokenKind {
2457 /**
2458 * \brief A token that contains some kind of punctuation.
2459 */
2460 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002461
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002462 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002463 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002464 */
2465 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002466
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002467 /**
2468 * \brief An identifier (that is not a keyword).
2469 */
2470 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002471
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002472 /**
2473 * \brief A numeric, string, or character literal.
2474 */
2475 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002476
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002477 /**
2478 * \brief A comment.
2479 */
2480 CXToken_Comment
2481} CXTokenKind;
2482
2483/**
2484 * \brief Describes a single preprocessing token.
2485 */
2486typedef struct {
2487 unsigned int_data[4];
2488 void *ptr_data;
2489} CXToken;
2490
2491/**
2492 * \brief Determine the kind of the given token.
2493 */
2494CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002495
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002496/**
2497 * \brief Determine the spelling of the given token.
2498 *
2499 * The spelling of a token is the textual representation of that token, e.g.,
2500 * the text of an identifier or keyword.
2501 */
2502CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002503
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002504/**
2505 * \brief Retrieve the source location of the given token.
2506 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002507CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002508 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002509
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002510/**
2511 * \brief Retrieve a source range that covers the given token.
2512 */
2513CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2514
2515/**
2516 * \brief Tokenize the source code described by the given range into raw
2517 * lexical tokens.
2518 *
2519 * \param TU the translation unit whose text is being tokenized.
2520 *
2521 * \param Range the source range in which text should be tokenized. All of the
2522 * tokens produced by tokenization will fall within this source range,
2523 *
2524 * \param Tokens this pointer will be set to point to the array of tokens
2525 * that occur within the given source range. The returned pointer must be
2526 * freed with clang_disposeTokens() before the translation unit is destroyed.
2527 *
2528 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2529 * array.
2530 *
2531 */
2532CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2533 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002534
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002535/**
2536 * \brief Annotate the given set of tokens by providing cursors for each token
2537 * that can be mapped to a specific entity within the abstract syntax tree.
2538 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002539 * This token-annotation routine is equivalent to invoking
2540 * clang_getCursor() for the source locations of each of the
2541 * tokens. The cursors provided are filtered, so that only those
2542 * cursors that have a direct correspondence to the token are
2543 * accepted. For example, given a function call \c f(x),
2544 * clang_getCursor() would provide the following cursors:
2545 *
2546 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2547 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2548 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2549 *
2550 * Only the first and last of these cursors will occur within the
2551 * annotate, since the tokens "f" and "x' directly refer to a function
2552 * and a variable, respectively, but the parentheses are just a small
2553 * part of the full syntax of the function call expression, which is
2554 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002555 *
2556 * \param TU the translation unit that owns the given tokens.
2557 *
2558 * \param Tokens the set of tokens to annotate.
2559 *
2560 * \param NumTokens the number of tokens in \p Tokens.
2561 *
2562 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2563 * replaced with the cursors corresponding to each token.
2564 */
2565CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2566 CXToken *Tokens, unsigned NumTokens,
2567 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002568
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002569/**
2570 * \brief Free the given set of tokens.
2571 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002572CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002573 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002574
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002575/**
2576 * @}
2577 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002578
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002579/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002580 * \defgroup CINDEX_DEBUG Debugging facilities
2581 *
2582 * These routines are used for testing and debugging, only, and should not
2583 * be relied upon.
2584 *
2585 * @{
2586 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002587
Steve Naroff4ade6d62009-09-23 17:52:52 +00002588/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002589CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002590CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2591 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002592 const char **endBuf,
2593 unsigned *startLine,
2594 unsigned *startColumn,
2595 unsigned *endLine,
2596 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002597CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00002598CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
2599 unsigned stack_size);
2600
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002601/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002602 * @}
2603 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002604
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002605/**
2606 * \defgroup CINDEX_CODE_COMPLET Code completion
2607 *
2608 * Code completion involves taking an (incomplete) source file, along with
2609 * knowledge of where the user is actively editing that file, and suggesting
2610 * syntactically- and semantically-valid constructs that the user might want to
2611 * use at that particular point in the source code. These data structures and
2612 * routines provide support for code completion.
2613 *
2614 * @{
2615 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002616
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002617/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002618 * \brief A semantic string that describes a code-completion result.
2619 *
2620 * A semantic string that describes the formatting of a code-completion
2621 * result as a single "template" of text that should be inserted into the
2622 * source buffer when a particular code-completion result is selected.
2623 * Each semantic string is made up of some number of "chunks", each of which
2624 * contains some text along with a description of what that text means, e.g.,
2625 * the name of the entity being referenced, whether the text chunk is part of
2626 * the template, or whether it is a "placeholder" that the user should replace
2627 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002628 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002629 */
2630typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002631
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002632/**
2633 * \brief A single result of code completion.
2634 */
2635typedef struct {
2636 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002637 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002638 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002639 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002640 * *Decl cursor kinds), describing the entity that the completion is
2641 * referring to.
2642 *
2643 * \todo In the future, we would like to provide a full cursor, to allow
2644 * the client to extract additional information from declaration.
2645 */
2646 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002647
2648 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002649 * \brief The code-completion string that describes how to insert this
2650 * code-completion result into the editing buffer.
2651 */
2652 CXCompletionString CompletionString;
2653} CXCompletionResult;
2654
2655/**
2656 * \brief Describes a single piece of text within a code-completion string.
2657 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002658 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2659 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002660 * should be interpreted by the client or is another completion string.
2661 */
2662enum CXCompletionChunkKind {
2663 /**
2664 * \brief A code-completion string that describes "optional" text that
2665 * could be a part of the template (but is not required).
2666 *
2667 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002668 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002669 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2670 * describes an additional part of the template that is completely optional.
2671 * For example, optional chunks can be used to describe the placeholders for
2672 * arguments that match up with defaulted function parameters, e.g. given:
2673 *
2674 * \code
2675 * void f(int x, float y = 3.14, double z = 2.71828);
2676 * \endcode
2677 *
2678 * The code-completion string for this function would contain:
2679 * - a TypedText chunk for "f".
2680 * - a LeftParen chunk for "(".
2681 * - a Placeholder chunk for "int x"
2682 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2683 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002684 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002685 * - an Optional chunk containing the last defaulted argument:
2686 * - a Comma chunk for ","
2687 * - a Placeholder chunk for "double z"
2688 * - a RightParen chunk for ")"
2689 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002690 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002691 * - Completely ignore optional chunks, in which case the template for the
2692 * function "f" would only include the first parameter ("int x").
2693 * - Fully expand all optional chunks, in which case the template for the
2694 * function "f" would have all of the parameters.
2695 */
2696 CXCompletionChunk_Optional,
2697 /**
2698 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002699 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002700 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002701 * There will be exactly one "typed text" chunk in a semantic string, which
2702 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002703 * declaration that could be used at the current code point. Clients are
2704 * expected to filter the code-completion results based on the text in this
2705 * chunk.
2706 */
2707 CXCompletionChunk_TypedText,
2708 /**
2709 * \brief Text that should be inserted as part of a code-completion result.
2710 *
2711 * A "text" chunk represents text that is part of the template to be
2712 * inserted into user code should this particular code-completion result
2713 * be selected.
2714 */
2715 CXCompletionChunk_Text,
2716 /**
2717 * \brief Placeholder text that should be replaced by the user.
2718 *
2719 * A "placeholder" chunk marks a place where the user should insert text
2720 * into the code-completion template. For example, placeholders might mark
2721 * the function parameters for a function declaration, to indicate that the
2722 * user should provide arguments for each of those parameters. The actual
2723 * text in a placeholder is a suggestion for the text to display before
2724 * the user replaces the placeholder with real code.
2725 */
2726 CXCompletionChunk_Placeholder,
2727 /**
2728 * \brief Informative text that should be displayed but never inserted as
2729 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002730 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002731 * An "informative" chunk contains annotations that can be displayed to
2732 * help the user decide whether a particular code-completion result is the
2733 * right option, but which is not part of the actual template to be inserted
2734 * by code completion.
2735 */
2736 CXCompletionChunk_Informative,
2737 /**
2738 * \brief Text that describes the current parameter when code-completion is
2739 * referring to function call, message send, or template specialization.
2740 *
2741 * A "current parameter" chunk occurs when code-completion is providing
2742 * information about a parameter corresponding to the argument at the
2743 * code-completion point. For example, given a function
2744 *
2745 * \code
2746 * int add(int x, int y);
2747 * \endcode
2748 *
2749 * and the source code \c add(, where the code-completion point is after the
2750 * "(", the code-completion string will contain a "current parameter" chunk
2751 * for "int x", indicating that the current argument will initialize that
2752 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002753 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002754 * "current paremeter" chunk to "int y".
2755 */
2756 CXCompletionChunk_CurrentParameter,
2757 /**
2758 * \brief A left parenthesis ('('), used to initiate a function call or
2759 * signal the beginning of a function parameter list.
2760 */
2761 CXCompletionChunk_LeftParen,
2762 /**
2763 * \brief A right parenthesis (')'), used to finish a function call or
2764 * signal the end of a function parameter list.
2765 */
2766 CXCompletionChunk_RightParen,
2767 /**
2768 * \brief A left bracket ('[').
2769 */
2770 CXCompletionChunk_LeftBracket,
2771 /**
2772 * \brief A right bracket (']').
2773 */
2774 CXCompletionChunk_RightBracket,
2775 /**
2776 * \brief A left brace ('{').
2777 */
2778 CXCompletionChunk_LeftBrace,
2779 /**
2780 * \brief A right brace ('}').
2781 */
2782 CXCompletionChunk_RightBrace,
2783 /**
2784 * \brief A left angle bracket ('<').
2785 */
2786 CXCompletionChunk_LeftAngle,
2787 /**
2788 * \brief A right angle bracket ('>').
2789 */
2790 CXCompletionChunk_RightAngle,
2791 /**
2792 * \brief A comma separator (',').
2793 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002794 CXCompletionChunk_Comma,
2795 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002796 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002797 *
2798 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002799 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002800 * expression using the given completion string would have.
2801 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002802 CXCompletionChunk_ResultType,
2803 /**
2804 * \brief A colon (':').
2805 */
2806 CXCompletionChunk_Colon,
2807 /**
2808 * \brief A semicolon (';').
2809 */
2810 CXCompletionChunk_SemiColon,
2811 /**
2812 * \brief An '=' sign.
2813 */
2814 CXCompletionChunk_Equal,
2815 /**
2816 * Horizontal space (' ').
2817 */
2818 CXCompletionChunk_HorizontalSpace,
2819 /**
2820 * Vertical space ('\n'), after which it is generally a good idea to
2821 * perform indentation.
2822 */
2823 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002824};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002825
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002826/**
2827 * \brief Determine the kind of a particular chunk within a completion string.
2828 *
2829 * \param completion_string the completion string to query.
2830 *
2831 * \param chunk_number the 0-based index of the chunk in the completion string.
2832 *
2833 * \returns the kind of the chunk at the index \c chunk_number.
2834 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002835CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002836clang_getCompletionChunkKind(CXCompletionString completion_string,
2837 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002838
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002839/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002840 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002841 * completion string.
2842 *
2843 * \param completion_string the completion string to query.
2844 *
2845 * \param chunk_number the 0-based index of the chunk in the completion string.
2846 *
2847 * \returns the text associated with the chunk at index \c chunk_number.
2848 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002849CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002850clang_getCompletionChunkText(CXCompletionString completion_string,
2851 unsigned chunk_number);
2852
2853/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002854 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002855 * within a completion string.
2856 *
2857 * \param completion_string the completion string to query.
2858 *
2859 * \param chunk_number the 0-based index of the chunk in the completion string.
2860 *
2861 * \returns the completion string associated with the chunk at index
2862 * \c chunk_number, or NULL if that chunk is not represented by a completion
2863 * string.
2864 */
2865CINDEX_LINKAGE CXCompletionString
2866clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2867 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002868
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002869/**
2870 * \brief Retrieve the number of chunks in the given code-completion string.
2871 */
2872CINDEX_LINKAGE unsigned
2873clang_getNumCompletionChunks(CXCompletionString completion_string);
2874
2875/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002876 * \brief Determine the priority of this code completion.
2877 *
2878 * The priority of a code completion indicates how likely it is that this
2879 * particular completion is the completion that the user will select. The
2880 * priority is selected by various internal heuristics.
2881 *
2882 * \param completion_string The completion string to query.
2883 *
2884 * \returns The priority of this completion string. Smaller values indicate
2885 * higher-priority (more likely) completions.
2886 */
2887CINDEX_LINKAGE unsigned
2888clang_getCompletionPriority(CXCompletionString completion_string);
2889
2890/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002891 * \brief Determine the availability of the entity that this code-completion
2892 * string refers to.
2893 *
2894 * \param completion_string The completion string to query.
2895 *
2896 * \returns The availability of the completion string.
2897 */
2898CINDEX_LINKAGE enum CXAvailabilityKind
2899clang_getCompletionAvailability(CXCompletionString completion_string);
2900
2901/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00002902 * \brief Retrieve a completion string for an arbitrary declaration or macro
2903 * definition cursor.
2904 *
2905 * \param cursor The cursor to query.
2906 *
2907 * \returns A non-context-sensitive completion string for declaration and macro
2908 * definition cursors, or NULL for other kinds of cursors.
2909 */
2910CINDEX_LINKAGE CXCompletionString
2911clang_getCursorCompletionString(CXCursor cursor);
2912
2913/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002914 * \brief Contains the results of code-completion.
2915 *
2916 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002917 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002918 * \c clang_disposeCodeCompleteResults.
2919 */
2920typedef struct {
2921 /**
2922 * \brief The code-completion results.
2923 */
2924 CXCompletionResult *Results;
2925
2926 /**
2927 * \brief The number of code-completion results stored in the
2928 * \c Results array.
2929 */
2930 unsigned NumResults;
2931} CXCodeCompleteResults;
2932
2933/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002934 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2935 * modify its behavior.
2936 *
2937 * The enumerators in this enumeration can be bitwise-OR'd together to
2938 * provide multiple options to \c clang_codeCompleteAt().
2939 */
2940enum CXCodeComplete_Flags {
2941 /**
2942 * \brief Whether to include macros within the set of code
2943 * completions returned.
2944 */
2945 CXCodeComplete_IncludeMacros = 0x01,
2946
2947 /**
2948 * \brief Whether to include code patterns for language constructs
2949 * within the set of code completions, e.g., for loops.
2950 */
2951 CXCodeComplete_IncludeCodePatterns = 0x02
2952};
2953
2954/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00002955 * \brief Bits that represent the context under which completion is occurring.
2956 *
2957 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
2958 * contexts are occurring simultaneously.
2959 */
2960enum CXCompletionContext {
2961 /**
2962 * \brief The context for completions is unexposed, as only Clang results
2963 * should be included. (This is equivalent to having no context bits set.)
2964 */
2965 CXCompletionContext_Unexposed = 0,
2966
2967 /**
2968 * \brief Completions for any possible type should be included in the results.
2969 */
2970 CXCompletionContext_AnyType = 1 << 0,
2971
2972 /**
2973 * \brief Completions for any possible value (variables, function calls, etc.)
2974 * should be included in the results.
2975 */
2976 CXCompletionContext_AnyValue = 1 << 1,
2977 /**
2978 * \brief Completions for values that resolve to an Objective-C object should
2979 * be included in the results.
2980 */
2981 CXCompletionContext_ObjCObjectValue = 1 << 2,
2982 /**
2983 * \brief Completions for values that resolve to an Objective-C selector
2984 * should be included in the results.
2985 */
2986 CXCompletionContext_ObjCSelectorValue = 1 << 3,
2987 /**
2988 * \brief Completions for values that resolve to a C++ class type should be
2989 * included in the results.
2990 */
2991 CXCompletionContext_CXXClassTypeValue = 1 << 4,
2992
2993 /**
2994 * \brief Completions for fields of the member being accessed using the dot
2995 * operator should be included in the results.
2996 */
2997 CXCompletionContext_DotMemberAccess = 1 << 5,
2998 /**
2999 * \brief Completions for fields of the member being accessed using the arrow
3000 * operator should be included in the results.
3001 */
3002 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3003 /**
3004 * \brief Completions for properties of the Objective-C object being accessed
3005 * using the dot operator should be included in the results.
3006 */
3007 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3008
3009 /**
3010 * \brief Completions for enum tags should be included in the results.
3011 */
3012 CXCompletionContext_EnumTag = 1 << 8,
3013 /**
3014 * \brief Completions for union tags should be included in the results.
3015 */
3016 CXCompletionContext_UnionTag = 1 << 9,
3017 /**
3018 * \brief Completions for struct tags should be included in the results.
3019 */
3020 CXCompletionContext_StructTag = 1 << 10,
3021
3022 /**
3023 * \brief Completions for C++ class names should be included in the results.
3024 */
3025 CXCompletionContext_ClassTag = 1 << 11,
3026 /**
3027 * \brief Completions for C++ namespaces and namespace aliases should be
3028 * included in the results.
3029 */
3030 CXCompletionContext_Namespace = 1 << 12,
3031 /**
3032 * \brief Completions for C++ nested name specifiers should be included in
3033 * the results.
3034 */
3035 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3036
3037 /**
3038 * \brief Completions for Objective-C interfaces (classes) should be included
3039 * in the results.
3040 */
3041 CXCompletionContext_ObjCInterface = 1 << 14,
3042 /**
3043 * \brief Completions for Objective-C protocols should be included in
3044 * the results.
3045 */
3046 CXCompletionContext_ObjCProtocol = 1 << 15,
3047 /**
3048 * \brief Completions for Objective-C categories should be included in
3049 * the results.
3050 */
3051 CXCompletionContext_ObjCCategory = 1 << 16,
3052 /**
3053 * \brief Completions for Objective-C instance messages should be included
3054 * in the results.
3055 */
3056 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3057 /**
3058 * \brief Completions for Objective-C class messages should be included in
3059 * the results.
3060 */
3061 CXCompletionContext_ObjCClassMessage = 1 << 18,
3062 /**
3063 * \brief Completions for Objective-C selector names should be included in
3064 * the results.
3065 */
3066 CXCompletionContext_ObjCSelectorName = 1 << 19,
3067
3068 /**
3069 * \brief Completions for preprocessor macro names should be included in
3070 * the results.
3071 */
3072 CXCompletionContext_MacroName = 1 << 20,
3073
3074 /**
3075 * \brief Natural language completions should be included in the results.
3076 */
3077 CXCompletionContext_NaturalLanguage = 1 << 21,
3078
3079 /**
3080 * \brief The current context is unknown, so set all contexts.
3081 */
3082 CXCompletionContext_Unknown = ((1 << 22) - 1)
3083};
3084
3085/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003086 * \brief Returns a default set of code-completion options that can be
3087 * passed to\c clang_codeCompleteAt().
3088 */
3089CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3090
3091/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003092 * \brief Perform code completion at a given location in a translation unit.
3093 *
3094 * This function performs code completion at a particular file, line, and
3095 * column within source code, providing results that suggest potential
3096 * code snippets based on the context of the completion. The basic model
3097 * for code completion is that Clang will parse a complete source file,
3098 * performing syntax checking up to the location where code-completion has
3099 * been requested. At that point, a special code-completion token is passed
3100 * to the parser, which recognizes this token and determines, based on the
3101 * current location in the C/Objective-C/C++ grammar and the state of
3102 * semantic analysis, what completions to provide. These completions are
3103 * returned via a new \c CXCodeCompleteResults structure.
3104 *
3105 * Code completion itself is meant to be triggered by the client when the
3106 * user types punctuation characters or whitespace, at which point the
3107 * code-completion location will coincide with the cursor. For example, if \c p
3108 * is a pointer, code-completion might be triggered after the "-" and then
3109 * after the ">" in \c p->. When the code-completion location is afer the ">",
3110 * the completion results will provide, e.g., the members of the struct that
3111 * "p" points to. The client is responsible for placing the cursor at the
3112 * beginning of the token currently being typed, then filtering the results
3113 * based on the contents of the token. For example, when code-completing for
3114 * the expression \c p->get, the client should provide the location just after
3115 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3116 * client can filter the results based on the current token text ("get"), only
3117 * showing those results that start with "get". The intent of this interface
3118 * is to separate the relatively high-latency acquisition of code-completion
3119 * results from the filtering of results on a per-character basis, which must
3120 * have a lower latency.
3121 *
3122 * \param TU The translation unit in which code-completion should
3123 * occur. The source files for this translation unit need not be
3124 * completely up-to-date (and the contents of those source files may
3125 * be overridden via \p unsaved_files). Cursors referring into the
3126 * translation unit may be invalidated by this invocation.
3127 *
3128 * \param complete_filename The name of the source file where code
3129 * completion should be performed. This filename may be any file
3130 * included in the translation unit.
3131 *
3132 * \param complete_line The line at which code-completion should occur.
3133 *
3134 * \param complete_column The column at which code-completion should occur.
3135 * Note that the column should point just after the syntactic construct that
3136 * initiated code completion, and not in the middle of a lexical token.
3137 *
3138 * \param unsaved_files the Tiles that have not yet been saved to disk
3139 * but may be required for parsing or code completion, including the
3140 * contents of those files. The contents and name of these files (as
3141 * specified by CXUnsavedFile) are copied when necessary, so the
3142 * client only needs to guarantee their validity until the call to
3143 * this function returns.
3144 *
3145 * \param num_unsaved_files The number of unsaved file entries in \p
3146 * unsaved_files.
3147 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00003148 * \param options Extra options that control the behavior of code
3149 * completion, expressed as a bitwise OR of the enumerators of the
3150 * CXCodeComplete_Flags enumeration. The
3151 * \c clang_defaultCodeCompleteOptions() function returns a default set
3152 * of code-completion options.
3153 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003154 * \returns If successful, a new \c CXCodeCompleteResults structure
3155 * containing code-completion results, which should eventually be
3156 * freed with \c clang_disposeCodeCompleteResults(). If code
3157 * completion fails, returns NULL.
3158 */
3159CINDEX_LINKAGE
3160CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3161 const char *complete_filename,
3162 unsigned complete_line,
3163 unsigned complete_column,
3164 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00003165 unsigned num_unsaved_files,
3166 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003167
3168/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00003169 * \brief Sort the code-completion results in case-insensitive alphabetical
3170 * order.
3171 *
3172 * \param Results The set of results to sort.
3173 * \param NumResults The number of results in \p Results.
3174 */
3175CINDEX_LINKAGE
3176void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3177 unsigned NumResults);
3178
3179/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003180 * \brief Free the given set of code-completion results.
3181 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003182CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00003183void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00003184
Douglas Gregor20d416c2010-01-20 01:10:47 +00003185/**
Douglas Gregora88084b2010-02-18 18:08:43 +00003186 * \brief Determine the number of diagnostics produced prior to the
3187 * location where code completion was performed.
3188 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003189CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003190unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3191
3192/**
3193 * \brief Retrieve a diagnostic associated with the given code completion.
3194 *
3195 * \param Result the code completion results to query.
3196 * \param Index the zero-based diagnostic number to retrieve.
3197 *
3198 * \returns the requested diagnostic. This diagnostic must be freed
3199 * via a call to \c clang_disposeDiagnostic().
3200 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003201CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003202CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3203 unsigned Index);
3204
3205/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003206 * \brief Determines what compeltions are appropriate for the context
3207 * the given code completion.
3208 *
3209 * \param Results the code completion results to query
3210 *
3211 * \returns the kinds of completions that are appropriate for use
3212 * along with the given code completion results.
3213 */
3214CINDEX_LINKAGE
3215unsigned long long clang_codeCompleteGetContexts(
3216 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00003217
3218/**
3219 * \brief Returns the cursor kind for the container for the current code
3220 * completion context. The container is only guaranteed to be set for
3221 * contexts where a container exists (i.e. member accesses or Objective-C
3222 * message sends); if there is not a container, this function will return
3223 * CXCursor_InvalidCode.
3224 *
3225 * \param Results the code completion results to query
3226 *
3227 * \param IsIncomplete on return, this value will be false if Clang has complete
3228 * information about the container. If Clang does not have complete
3229 * information, this value will be true.
3230 *
3231 * \returns the container kind, or CXCursor_InvalidCode if there is not a
3232 * container
3233 */
3234CINDEX_LINKAGE
3235enum CXCursorKind clang_codeCompleteGetContainerKind(
3236 CXCodeCompleteResults *Results,
3237 unsigned *IsIncomplete);
3238
3239/**
3240 * \brief Returns the USR for the container for the current code completion
3241 * context. If there is not a container for the current context, this
3242 * function will return the empty string.
3243 *
3244 * \param Results the code completion results to query
3245 *
3246 * \returns the USR for the container
3247 */
3248CINDEX_LINKAGE
3249CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00003250
Douglas Gregor0a47d692011-07-26 15:24:30 +00003251
3252/**
3253 * \brief Returns the currently-entered selector for an Objective-C message
3254 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
3255 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
3256 * CXCompletionContext_ObjCClassMessage.
3257 *
3258 * \param Results the code completion results to query
3259 *
3260 * \returns the selector (or partial selector) that has been entered thus far
3261 * for an Objective-C message send.
3262 */
3263CINDEX_LINKAGE
3264CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
3265
Douglas Gregor3da626b2011-07-07 16:03:39 +00003266/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00003267 * @}
3268 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003269
3270
Ted Kremenek04bb7162010-01-22 22:44:15 +00003271/**
3272 * \defgroup CINDEX_MISC Miscellaneous utility functions
3273 *
3274 * @{
3275 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00003276
3277/**
3278 * \brief Return a version string, suitable for showing to a user, but not
3279 * intended to be parsed (the format is not guaranteed to be stable).
3280 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00003281CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00003282
Ted Kremenekd2427dd2011-03-18 23:05:39 +00003283
3284/**
3285 * \brief Enable/disable crash recovery.
3286 *
3287 * \param Flag to indicate if crash recovery is enabled. A non-zero value
3288 * enables crash recovery, while 0 disables it.
3289 */
3290CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
3291
Ted Kremenek16b55a72010-01-26 19:31:51 +00003292 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003293 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00003294 * (used with clang_getInclusions()).
3295 *
3296 * This visitor function will be invoked by clang_getInclusions() for each
3297 * file included (either at the top-level or by #include directives) within
3298 * a translation unit. The first argument is the file being included, and
3299 * the second and third arguments provide the inclusion stack. The
3300 * array is sorted in order of immediate inclusion. For example,
3301 * the first element refers to the location that included 'included_file'.
3302 */
3303typedef void (*CXInclusionVisitor)(CXFile included_file,
3304 CXSourceLocation* inclusion_stack,
3305 unsigned include_len,
3306 CXClientData client_data);
3307
3308/**
3309 * \brief Visit the set of preprocessor inclusions in a translation unit.
3310 * The visitor function is called with the provided data for every included
3311 * file. This does not include headers included by the PCH file (unless one
3312 * is inspecting the inclusions in the PCH file itself).
3313 */
3314CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3315 CXInclusionVisitor visitor,
3316 CXClientData client_data);
3317
3318/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00003319 * @}
3320 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003321
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00003322/** \defgroup CINDEX_REMAPPING Remapping functions
3323 *
3324 * @{
3325 */
3326
3327/**
3328 * \brief A remapping of original source files and their translated files.
3329 */
3330typedef void *CXRemapping;
3331
3332/**
3333 * \brief Retrieve a remapping.
3334 *
3335 * \param path the path that contains metadata about remappings.
3336 *
3337 * \returns the requested remapping. This remapping must be freed
3338 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3339 */
3340CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
3341
3342/**
3343 * \brief Determine the number of remappings.
3344 */
3345CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
3346
3347/**
3348 * \brief Get the original and the associated filename from the remapping.
3349 *
3350 * \param original If non-NULL, will be set to the original filename.
3351 *
3352 * \param transformed If non-NULL, will be set to the filename that the original
3353 * is associated with.
3354 */
3355CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
3356 CXString *original, CXString *transformed);
3357
3358/**
3359 * \brief Dispose the remapping.
3360 */
3361CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
3362
3363/**
3364 * @}
3365 */
3366
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003367/**
3368 * @}
3369 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003370
Ted Kremenekd2fa5662009-08-26 22:36:44 +00003371#ifdef __cplusplus
3372}
3373#endif
3374#endif
3375