blob: 8d35419a4324b3b213f1000be2815637056c6434 [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 /**
827 * \brief Enable precompiled preambles in C++.
828 *
829 * Note: this is a *temporary* option that is available only while
830 * we are testing C++ precompiled preamble support.
831 */
832 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
833
834 /**
835 * \brief Enabled chained precompiled preambles in C++.
836 *
837 * Note: this is a *temporary* option that is available only while
838 * we are testing C++ precompiled preamble support.
839 */
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 Kremenekf7870022011-04-20 16:41:07 +00001105 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1106 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001107 CXTUResourceUsage_PreprocessingRecord,
Ted Kremenekf7870022011-04-20 16:41:07 +00001108
1109 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001110 CXTUResourceUsage_Last = CXTUResourceUsage_PreprocessingRecord
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001111};
1112
1113/**
1114 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001115 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001116 */
1117CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001118const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001119
Ted Kremenekf7870022011-04-20 16:41:07 +00001120typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001121 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001122 enum CXTUResourceUsageKind kind;
1123 /* \brief Amount of resources used.
1124 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001125 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001126} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001127
1128/**
1129 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1130 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001131typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001132 /* \brief Private data member, used for queries. */
1133 void *data;
1134
1135 /* \brief The number of entries in the 'entries' array. */
1136 unsigned numEntries;
1137
1138 /* \brief An array of key-value pairs, representing the breakdown of memory
1139 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001140 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001141
Ted Kremenekf7870022011-04-20 16:41:07 +00001142} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001143
1144/**
1145 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001146 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001147 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001148CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001149
Ted Kremenekf7870022011-04-20 16:41:07 +00001150CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001151
Douglas Gregorabc563f2010-07-19 21:46:24 +00001152/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001153 * @}
1154 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001155
Douglas Gregor5352ac02010-01-28 00:27:43 +00001156/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001157 * \brief Describes the kind of entity that a cursor refers to.
1158 */
1159enum CXCursorKind {
1160 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001161 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001162 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001163 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001164 *
1165 * Unexposed declarations have the same operations as any other kind
1166 * of declaration; one can extract their location information,
1167 * spelling, find their definitions, etc. However, the specific kind
1168 * of the declaration is not reported.
1169 */
1170 CXCursor_UnexposedDecl = 1,
1171 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001172 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001173 /** \brief A C or C++ union. */
1174 CXCursor_UnionDecl = 3,
1175 /** \brief A C++ class. */
1176 CXCursor_ClassDecl = 4,
1177 /** \brief An enumeration. */
1178 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001179 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001180 * \brief A field (in C) or non-static data member (in C++) in a
1181 * struct, union, or C++ class.
1182 */
1183 CXCursor_FieldDecl = 6,
1184 /** \brief An enumerator constant. */
1185 CXCursor_EnumConstantDecl = 7,
1186 /** \brief A function. */
1187 CXCursor_FunctionDecl = 8,
1188 /** \brief A variable. */
1189 CXCursor_VarDecl = 9,
1190 /** \brief A function or method parameter. */
1191 CXCursor_ParmDecl = 10,
1192 /** \brief An Objective-C @interface. */
1193 CXCursor_ObjCInterfaceDecl = 11,
1194 /** \brief An Objective-C @interface for a category. */
1195 CXCursor_ObjCCategoryDecl = 12,
1196 /** \brief An Objective-C @protocol declaration. */
1197 CXCursor_ObjCProtocolDecl = 13,
1198 /** \brief An Objective-C @property declaration. */
1199 CXCursor_ObjCPropertyDecl = 14,
1200 /** \brief An Objective-C instance variable. */
1201 CXCursor_ObjCIvarDecl = 15,
1202 /** \brief An Objective-C instance method. */
1203 CXCursor_ObjCInstanceMethodDecl = 16,
1204 /** \brief An Objective-C class method. */
1205 CXCursor_ObjCClassMethodDecl = 17,
1206 /** \brief An Objective-C @implementation. */
1207 CXCursor_ObjCImplementationDecl = 18,
1208 /** \brief An Objective-C @implementation for a category. */
1209 CXCursor_ObjCCategoryImplDecl = 19,
1210 /** \brief A typedef */
1211 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001212 /** \brief A C++ class method. */
1213 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001214 /** \brief A C++ namespace. */
1215 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001216 /** \brief A linkage specification, e.g. 'extern "C"'. */
1217 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001218 /** \brief A C++ constructor. */
1219 CXCursor_Constructor = 24,
1220 /** \brief A C++ destructor. */
1221 CXCursor_Destructor = 25,
1222 /** \brief A C++ conversion function. */
1223 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001224 /** \brief A C++ template type parameter. */
1225 CXCursor_TemplateTypeParameter = 27,
1226 /** \brief A C++ non-type template parameter. */
1227 CXCursor_NonTypeTemplateParameter = 28,
1228 /** \brief A C++ template template parameter. */
1229 CXCursor_TemplateTemplateParameter = 29,
1230 /** \brief A C++ function template. */
1231 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001232 /** \brief A C++ class template. */
1233 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001234 /** \brief A C++ class template partial specialization. */
1235 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001236 /** \brief A C++ namespace alias declaration. */
1237 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001238 /** \brief A C++ using directive. */
1239 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001240 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001241 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001242 /** \brief A C++ alias declaration */
1243 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001244 /** \brief An Objective-C @synthesize definition. */
1245 CXCursor_ObjCSynthesizeDecl = 37,
1246 /** \brief An Objective-C @dynamic definition. */
1247 CXCursor_ObjCDynamicDecl = 38,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001248 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor352697a2011-06-03 23:08:58 +00001249 CXCursor_LastDecl = CXCursor_ObjCDynamicDecl,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001250
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001251 /* References */
1252 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001253 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001254 CXCursor_ObjCProtocolRef = 41,
1255 CXCursor_ObjCClassRef = 42,
1256 /**
1257 * \brief A reference to a type declaration.
1258 *
1259 * A type reference occurs anywhere where a type is named but not
1260 * declared. For example, given:
1261 *
1262 * \code
1263 * typedef unsigned size_type;
1264 * size_type size;
1265 * \endcode
1266 *
1267 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1268 * while the type of the variable "size" is referenced. The cursor
1269 * referenced by the type of size is the typedef for size_type.
1270 */
1271 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001272 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001273 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001274 * \brief A reference to a class template, function template, template
1275 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001276 */
1277 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001278 /**
1279 * \brief A reference to a namespace or namespace alias.
1280 */
1281 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001282 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001283 * \brief A reference to a member of a struct, union, or class that occurs in
1284 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001285 */
1286 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001287 /**
1288 * \brief A reference to a labeled statement.
1289 *
1290 * This cursor kind is used to describe the jump to "start_over" in the
1291 * goto statement in the following example:
1292 *
1293 * \code
1294 * start_over:
1295 * ++counter;
1296 *
1297 * goto start_over;
1298 * \endcode
1299 *
1300 * A label reference cursor refers to a label statement.
1301 */
1302 CXCursor_LabelRef = 48,
1303
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001304 /**
1305 * \brief A reference to a set of overloaded functions or function templates
1306 * that has not yet been resolved to a specific function or function template.
1307 *
1308 * An overloaded declaration reference cursor occurs in C++ templates where
1309 * a dependent name refers to a function. For example:
1310 *
1311 * \code
1312 * template<typename T> void swap(T&, T&);
1313 *
1314 * struct X { ... };
1315 * void swap(X&, X&);
1316 *
1317 * template<typename T>
1318 * void reverse(T* first, T* last) {
1319 * while (first < last - 1) {
1320 * swap(*first, *--last);
1321 * ++first;
1322 * }
1323 * }
1324 *
1325 * struct Y { };
1326 * void swap(Y&, Y&);
1327 * \endcode
1328 *
1329 * Here, the identifier "swap" is associated with an overloaded declaration
1330 * reference. In the template definition, "swap" refers to either of the two
1331 * "swap" functions declared above, so both results will be available. At
1332 * instantiation time, "swap" may also refer to other functions found via
1333 * argument-dependent lookup (e.g., the "swap" function at the end of the
1334 * example).
1335 *
1336 * The functions \c clang_getNumOverloadedDecls() and
1337 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1338 * referenced by this cursor.
1339 */
1340 CXCursor_OverloadedDeclRef = 49,
1341
1342 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001343
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001344 /* Error conditions */
1345 CXCursor_FirstInvalid = 70,
1346 CXCursor_InvalidFile = 70,
1347 CXCursor_NoDeclFound = 71,
1348 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001349 CXCursor_InvalidCode = 73,
1350 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001351
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001352 /* Expressions */
1353 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001354
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001355 /**
1356 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001357 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001358 *
1359 * Unexposed expressions have the same operations as any other kind
1360 * of expression; one can extract their location information,
1361 * spelling, children, etc. However, the specific kind of the
1362 * expression is not reported.
1363 */
1364 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001365
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001366 /**
1367 * \brief An expression that refers to some value declaration, such
1368 * as a function, varible, or enumerator.
1369 */
1370 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001371
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001372 /**
1373 * \brief An expression that refers to a member of a struct, union,
1374 * class, Objective-C class, etc.
1375 */
1376 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001377
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001378 /** \brief An expression that calls a function. */
1379 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001380
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001381 /** \brief An expression that sends a message to an Objective-C
1382 object or class. */
1383 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001384
1385 /** \brief An expression that represents a block literal. */
1386 CXCursor_BlockExpr = 105,
1387
1388 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001389
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001390 /* Statements */
1391 CXCursor_FirstStmt = 200,
1392 /**
1393 * \brief A statement whose specific kind is not exposed via this
1394 * interface.
1395 *
1396 * Unexposed statements have the same operations as any other kind of
1397 * statement; one can extract their location information, spelling,
1398 * children, etc. However, the specific kind of the statement is not
1399 * reported.
1400 */
1401 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001402
1403 /** \brief A labelled statement in a function.
1404 *
1405 * This cursor kind is used to describe the "start_over:" label statement in
1406 * the following example:
1407 *
1408 * \code
1409 * start_over:
1410 * ++counter;
1411 * \endcode
1412 *
1413 */
1414 CXCursor_LabelStmt = 201,
1415
1416 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001417
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001418 /**
1419 * \brief Cursor that represents the translation unit itself.
1420 *
1421 * The translation unit cursor exists primarily to act as the root
1422 * cursor for traversing the contents of a translation unit.
1423 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001424 CXCursor_TranslationUnit = 300,
1425
1426 /* Attributes */
1427 CXCursor_FirstAttr = 400,
1428 /**
1429 * \brief An attribute whose specific kind is not exposed via this
1430 * interface.
1431 */
1432 CXCursor_UnexposedAttr = 400,
1433
1434 CXCursor_IBActionAttr = 401,
1435 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001436 CXCursor_IBOutletCollectionAttr = 403,
1437 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001438
1439 /* Preprocessing */
1440 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001441 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00001442 CXCursor_MacroExpansion = 502,
1443 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001444 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001445 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001446 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001447};
1448
1449/**
1450 * \brief A cursor representing some element in the abstract syntax tree for
1451 * a translation unit.
1452 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001453 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001454 * program--declaration, statements, expressions, references to declarations,
1455 * etc.--under a single "cursor" abstraction with a common set of operations.
1456 * Common operation for a cursor include: getting the physical location in
1457 * a source file where the cursor points, getting the name associated with a
1458 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1459 *
1460 * Cursors can be produced in two specific ways.
1461 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1462 * from which one can use clang_visitChildren() to explore the rest of the
1463 * translation unit. clang_getCursor() maps from a physical source location
1464 * to the entity that resides at that location, allowing one to map from the
1465 * source code into the AST.
1466 */
1467typedef struct {
1468 enum CXCursorKind kind;
1469 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001470} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001471
1472/**
1473 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1474 *
1475 * @{
1476 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001477
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001478/**
1479 * \brief Retrieve the NULL cursor, which represents no entity.
1480 */
1481CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001482
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001483/**
1484 * \brief Retrieve the cursor that represents the given translation unit.
1485 *
1486 * The translation unit cursor can be used to start traversing the
1487 * various declarations within the given translation unit.
1488 */
1489CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1490
1491/**
1492 * \brief Determine whether two cursors are equivalent.
1493 */
1494CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001495
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001496/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001497 * \brief Compute a hash value for the given cursor.
1498 */
1499CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1500
1501/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001502 * \brief Retrieve the kind of the given cursor.
1503 */
1504CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1505
1506/**
1507 * \brief Determine whether the given cursor kind represents a declaration.
1508 */
1509CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1510
1511/**
1512 * \brief Determine whether the given cursor kind represents a simple
1513 * reference.
1514 *
1515 * Note that other kinds of cursors (such as expressions) can also refer to
1516 * other cursors. Use clang_getCursorReferenced() to determine whether a
1517 * particular cursor refers to another entity.
1518 */
1519CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1520
1521/**
1522 * \brief Determine whether the given cursor kind represents an expression.
1523 */
1524CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1525
1526/**
1527 * \brief Determine whether the given cursor kind represents a statement.
1528 */
1529CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1530
1531/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00001532 * \brief Determine whether the given cursor kind represents an attribute.
1533 */
1534CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
1535
1536/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001537 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001538 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001539 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001540CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1541
1542/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001543 * \brief Determine whether the given cursor kind represents a translation
1544 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001545 */
1546CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001547
Ted Kremenekad6eff62010-03-08 21:17:29 +00001548/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001549 * \brief Determine whether the given cursor represents a preprocessing
1550 * element, such as a preprocessor directive or macro instantiation.
1551 */
1552CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1553
1554/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001555 * \brief Determine whether the given cursor represents a currently
1556 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1557 */
1558CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1559
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001560/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001561 * \brief Describe the linkage of the entity referred to by a cursor.
1562 */
1563enum CXLinkageKind {
1564 /** \brief This value indicates that no linkage information is available
1565 * for a provided CXCursor. */
1566 CXLinkage_Invalid,
1567 /**
1568 * \brief This is the linkage for variables, parameters, and so on that
1569 * have automatic storage. This covers normal (non-extern) local variables.
1570 */
1571 CXLinkage_NoLinkage,
1572 /** \brief This is the linkage for static variables and static functions. */
1573 CXLinkage_Internal,
1574 /** \brief This is the linkage for entities with external linkage that live
1575 * in C++ anonymous namespaces.*/
1576 CXLinkage_UniqueExternal,
1577 /** \brief This is the linkage for entities with true, external linkage. */
1578 CXLinkage_External
1579};
1580
1581/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001582 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001583 */
1584CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1585
1586/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001587 * \brief Determine the availability of the entity that this cursor refers to.
1588 *
1589 * \param cursor The cursor to query.
1590 *
1591 * \returns The availability of the cursor.
1592 */
1593CINDEX_LINKAGE enum CXAvailabilityKind
1594clang_getCursorAvailability(CXCursor cursor);
1595
1596/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001597 * \brief Describe the "language" of the entity referred to by a cursor.
1598 */
1599CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001600 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001601 CXLanguage_C,
1602 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001603 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001604};
1605
1606/**
1607 * \brief Determine the "language" of the entity referred to by a given cursor.
1608 */
1609CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1610
Ted Kremenekeca099b2010-12-08 23:43:14 +00001611
1612/**
1613 * \brief A fast container representing a set of CXCursors.
1614 */
1615typedef struct CXCursorSetImpl *CXCursorSet;
1616
1617/**
1618 * \brief Creates an empty CXCursorSet.
1619 */
1620CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
1621
1622/**
1623 * \brief Disposes a CXCursorSet and releases its associated memory.
1624 */
1625CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
1626
1627/**
1628 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
1629 *
1630 * \returns non-zero if the set contains the specified cursor.
1631*/
1632CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
1633 CXCursor cursor);
1634
1635/**
1636 * \brief Inserts a CXCursor into a CXCursorSet.
1637 *
1638 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
1639*/
1640CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
1641 CXCursor cursor);
1642
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001643/**
1644 * \brief Determine the semantic parent of the given cursor.
1645 *
1646 * The semantic parent of a cursor is the cursor that semantically contains
1647 * the given \p cursor. For many declarations, the lexical and semantic parents
1648 * are equivalent (the lexical parent is returned by
1649 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1650 * definitions are provided out-of-line. For example:
1651 *
1652 * \code
1653 * class C {
1654 * void f();
1655 * };
1656 *
1657 * void C::f() { }
1658 * \endcode
1659 *
1660 * In the out-of-line definition of \c C::f, the semantic parent is the
1661 * the class \c C, of which this function is a member. The lexical parent is
1662 * the place where the declaration actually occurs in the source code; in this
1663 * case, the definition occurs in the translation unit. In general, the
1664 * lexical parent for a given entity can change without affecting the semantics
1665 * of the program, and the lexical parent of different declarations of the
1666 * same entity may be different. Changing the semantic parent of a declaration,
1667 * on the other hand, can have a major impact on semantics, and redeclarations
1668 * of a particular entity should all have the same semantic context.
1669 *
1670 * In the example above, both declarations of \c C::f have \c C as their
1671 * semantic context, while the lexical context of the first \c C::f is \c C
1672 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001673 *
1674 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001675 */
1676CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1677
1678/**
1679 * \brief Determine the lexical parent of the given cursor.
1680 *
1681 * The lexical parent of a cursor is the cursor in which the given \p cursor
1682 * was actually written. For many declarations, the lexical and semantic parents
1683 * are equivalent (the semantic parent is returned by
1684 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1685 * definitions are provided out-of-line. For example:
1686 *
1687 * \code
1688 * class C {
1689 * void f();
1690 * };
1691 *
1692 * void C::f() { }
1693 * \endcode
1694 *
1695 * In the out-of-line definition of \c C::f, the semantic parent is the
1696 * the class \c C, of which this function is a member. The lexical parent is
1697 * the place where the declaration actually occurs in the source code; in this
1698 * case, the definition occurs in the translation unit. In general, the
1699 * lexical parent for a given entity can change without affecting the semantics
1700 * of the program, and the lexical parent of different declarations of the
1701 * same entity may be different. Changing the semantic parent of a declaration,
1702 * on the other hand, can have a major impact on semantics, and redeclarations
1703 * of a particular entity should all have the same semantic context.
1704 *
1705 * In the example above, both declarations of \c C::f have \c C as their
1706 * semantic context, while the lexical context of the first \c C::f is \c C
1707 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001708 *
1709 * For declarations written in the global scope, the lexical parent is
1710 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001711 */
1712CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001713
1714/**
1715 * \brief Determine the set of methods that are overridden by the given
1716 * method.
1717 *
1718 * In both Objective-C and C++, a method (aka virtual member function,
1719 * in C++) can override a virtual method in a base class. For
1720 * Objective-C, a method is said to override any method in the class's
1721 * interface (if we're coming from an implementation), its protocols,
1722 * or its categories, that has the same selector and is of the same
1723 * kind (class or instance). If no such method exists, the search
1724 * continues to the class's superclass, its protocols, and its
1725 * categories, and so on.
1726 *
1727 * For C++, a virtual member function overrides any virtual member
1728 * function with the same signature that occurs in its base
1729 * classes. With multiple inheritance, a virtual member function can
1730 * override several virtual member functions coming from different
1731 * base classes.
1732 *
1733 * In all cases, this function determines the immediate overridden
1734 * method, rather than all of the overridden methods. For example, if
1735 * a method is originally declared in a class A, then overridden in B
1736 * (which in inherits from A) and also in C (which inherited from B),
1737 * then the only overridden method returned from this function when
1738 * invoked on C's method will be B's method. The client may then
1739 * invoke this function again, given the previously-found overridden
1740 * methods, to map out the complete method-override set.
1741 *
1742 * \param cursor A cursor representing an Objective-C or C++
1743 * method. This routine will compute the set of methods that this
1744 * method overrides.
1745 *
1746 * \param overridden A pointer whose pointee will be replaced with a
1747 * pointer to an array of cursors, representing the set of overridden
1748 * methods. If there are no overridden methods, the pointee will be
1749 * set to NULL. The pointee must be freed via a call to
1750 * \c clang_disposeOverriddenCursors().
1751 *
1752 * \param num_overridden A pointer to the number of overridden
1753 * functions, will be set to the number of overridden functions in the
1754 * array pointed to by \p overridden.
1755 */
1756CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1757 CXCursor **overridden,
1758 unsigned *num_overridden);
1759
1760/**
1761 * \brief Free the set of overridden cursors returned by \c
1762 * clang_getOverriddenCursors().
1763 */
1764CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1765
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001766/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001767 * \brief Retrieve the file that is included by the given inclusion directive
1768 * cursor.
1769 */
1770CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1771
1772/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001773 * @}
1774 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001775
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001776/**
1777 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1778 *
1779 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1780 * routines help map between cursors and the physical locations where the
1781 * described entities occur in the source code. The mapping is provided in
1782 * both directions, so one can map from source code to the AST and back.
1783 *
1784 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001785 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001786
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001787/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001788 * \brief Map a source location to the cursor that describes the entity at that
1789 * location in the source code.
1790 *
1791 * clang_getCursor() maps an arbitrary source location within a translation
1792 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001793 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001794 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001795 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001796 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1797 * will return a cursor referring to the "+" expression.
1798 *
1799 * \returns a cursor representing the entity at the given source location, or
1800 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001801 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001802CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001803
Douglas Gregor98258af2010-01-18 22:46:11 +00001804/**
1805 * \brief Retrieve the physical location of the source constructor referenced
1806 * by the given cursor.
1807 *
1808 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001809 * declaration, where the name of that declaration would occur if it is
1810 * unnamed, or some keyword that introduces that particular declaration.
1811 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001812 * source code.
1813 */
1814CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001815
Douglas Gregorb6998662010-01-19 19:34:47 +00001816/**
1817 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001818 * the given cursor.
1819 *
1820 * The extent of a cursor starts with the file/line/column pointing at the
1821 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001822 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001823 * declaration, the extent covers the declaration itself. For a reference,
1824 * the extent covers the location of the reference (e.g., where the referenced
1825 * entity was actually used).
1826 */
1827CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001828
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001829/**
1830 * @}
1831 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001832
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001833/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001834 * \defgroup CINDEX_TYPES Type information for CXCursors
1835 *
1836 * @{
1837 */
1838
1839/**
1840 * \brief Describes the kind of type
1841 */
1842enum CXTypeKind {
1843 /**
1844 * \brief Reprents an invalid type (e.g., where no type is available).
1845 */
1846 CXType_Invalid = 0,
1847
1848 /**
1849 * \brief A type whose specific kind is not exposed via this
1850 * interface.
1851 */
1852 CXType_Unexposed = 1,
1853
1854 /* Builtin types */
1855 CXType_Void = 2,
1856 CXType_Bool = 3,
1857 CXType_Char_U = 4,
1858 CXType_UChar = 5,
1859 CXType_Char16 = 6,
1860 CXType_Char32 = 7,
1861 CXType_UShort = 8,
1862 CXType_UInt = 9,
1863 CXType_ULong = 10,
1864 CXType_ULongLong = 11,
1865 CXType_UInt128 = 12,
1866 CXType_Char_S = 13,
1867 CXType_SChar = 14,
1868 CXType_WChar = 15,
1869 CXType_Short = 16,
1870 CXType_Int = 17,
1871 CXType_Long = 18,
1872 CXType_LongLong = 19,
1873 CXType_Int128 = 20,
1874 CXType_Float = 21,
1875 CXType_Double = 22,
1876 CXType_LongDouble = 23,
1877 CXType_NullPtr = 24,
1878 CXType_Overload = 25,
1879 CXType_Dependent = 26,
1880 CXType_ObjCId = 27,
1881 CXType_ObjCClass = 28,
1882 CXType_ObjCSel = 29,
1883 CXType_FirstBuiltin = CXType_Void,
1884 CXType_LastBuiltin = CXType_ObjCSel,
1885
1886 CXType_Complex = 100,
1887 CXType_Pointer = 101,
1888 CXType_BlockPointer = 102,
1889 CXType_LValueReference = 103,
1890 CXType_RValueReference = 104,
1891 CXType_Record = 105,
1892 CXType_Enum = 106,
1893 CXType_Typedef = 107,
1894 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001895 CXType_ObjCObjectPointer = 109,
1896 CXType_FunctionNoProto = 110,
1897 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001898};
1899
1900/**
1901 * \brief The type of an element in the abstract syntax tree.
1902 *
1903 */
1904typedef struct {
1905 enum CXTypeKind kind;
1906 void *data[2];
1907} CXType;
1908
1909/**
1910 * \brief Retrieve the type of a CXCursor (if any).
1911 */
1912CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1913
1914/**
1915 * \determine Determine whether two CXTypes represent the same type.
1916 *
1917 * \returns non-zero if the CXTypes represent the same type and
1918 zero otherwise.
1919 */
1920CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1921
1922/**
1923 * \brief Return the canonical type for a CXType.
1924 *
1925 * Clang's type system explicitly models typedefs and all the ways
1926 * a specific type can be represented. The canonical type is the underlying
1927 * type with all the "sugar" removed. For example, if 'T' is a typedef
1928 * for 'int', the canonical type for 'T' would be 'int'.
1929 */
1930CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1931
1932/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00001933 * \determine Determine whether a CXType has the "const" qualifier set,
1934 * without looking through typedefs that may have added "const" at a different level.
1935 */
1936CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
1937
1938/**
1939 * \determine Determine whether a CXType has the "volatile" qualifier set,
1940 * without looking through typedefs that may have added "volatile" at a different level.
1941 */
1942CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
1943
1944/**
1945 * \determine Determine whether a CXType has the "restrict" qualifier set,
1946 * without looking through typedefs that may have added "restrict" at a different level.
1947 */
1948CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
1949
1950/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001951 * \brief For pointer types, returns the type of the pointee.
1952 *
1953 */
1954CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1955
1956/**
1957 * \brief Return the cursor for the declaration of the given type.
1958 */
1959CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1960
David Chisnall5389f482010-12-30 14:05:53 +00001961/**
1962 * Returns the Objective-C type encoding for the specified declaration.
1963 */
1964CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001965
1966/**
1967 * \brief Retrieve the spelling of a given CXTypeKind.
1968 */
1969CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1970
1971/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001972 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001973 */
1974CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1975
1976/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001977 * \brief Retrieve the result type associated with a given cursor. This only
1978 * returns a valid type of the cursor refers to a function or method.
1979 */
1980CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1981
1982/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001983 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1984 * otherwise.
1985 */
1986CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1987
1988/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001989 * \brief Returns 1 if the base class specified by the cursor with kind
1990 * CX_CXXBaseSpecifier is virtual.
1991 */
1992CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1993
1994/**
1995 * \brief Represents the C++ access control level to a base class for a
1996 * cursor with kind CX_CXXBaseSpecifier.
1997 */
1998enum CX_CXXAccessSpecifier {
1999 CX_CXXInvalidAccessSpecifier,
2000 CX_CXXPublic,
2001 CX_CXXProtected,
2002 CX_CXXPrivate
2003};
2004
2005/**
2006 * \brief Returns the access control level for the C++ base specifier
2007 * represented by a cursor with kind CX_CXXBaseSpecifier.
2008 */
2009CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2010
2011/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002012 * \brief Determine the number of overloaded declarations referenced by a
2013 * \c CXCursor_OverloadedDeclRef cursor.
2014 *
2015 * \param cursor The cursor whose overloaded declarations are being queried.
2016 *
2017 * \returns The number of overloaded declarations referenced by \c cursor. If it
2018 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2019 */
2020CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2021
2022/**
2023 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2024 * by a \c CXCursor_OverloadedDeclRef cursor.
2025 *
2026 * \param cursor The cursor whose overloaded declarations are being queried.
2027 *
2028 * \param index The zero-based index into the set of overloaded declarations in
2029 * the cursor.
2030 *
2031 * \returns A cursor representing the declaration referenced by the given
2032 * \c cursor at the specified \c index. If the cursor does not have an
2033 * associated set of overloaded declarations, or if the index is out of bounds,
2034 * returns \c clang_getNullCursor();
2035 */
2036CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2037 unsigned index);
2038
2039/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002040 * @}
2041 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002042
2043/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002044 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002045 *
2046 * @{
2047 */
2048
2049
2050/**
2051 * \brief For cursors representing an iboutletcollection attribute,
2052 * this function returns the collection element type.
2053 *
2054 */
2055CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2056
2057/**
2058 * @}
2059 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002060
2061/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002062 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2063 *
2064 * These routines provide the ability to traverse the abstract syntax tree
2065 * using cursors.
2066 *
2067 * @{
2068 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002069
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002070/**
2071 * \brief Describes how the traversal of the children of a particular
2072 * cursor should proceed after visiting a particular child cursor.
2073 *
2074 * A value of this enumeration type should be returned by each
2075 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2076 */
2077enum CXChildVisitResult {
2078 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002079 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002080 */
2081 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002082 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002083 * \brief Continues the cursor traversal with the next sibling of
2084 * the cursor just visited, without visiting its children.
2085 */
2086 CXChildVisit_Continue,
2087 /**
2088 * \brief Recursively traverse the children of this cursor, using
2089 * the same visitor and client data.
2090 */
2091 CXChildVisit_Recurse
2092};
2093
2094/**
2095 * \brief Visitor invoked for each cursor found by a traversal.
2096 *
2097 * This visitor function will be invoked for each cursor found by
2098 * clang_visitCursorChildren(). Its first argument is the cursor being
2099 * visited, its second argument is the parent visitor for that cursor,
2100 * and its third argument is the client data provided to
2101 * clang_visitCursorChildren().
2102 *
2103 * The visitor should return one of the \c CXChildVisitResult values
2104 * to direct clang_visitCursorChildren().
2105 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002106typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2107 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002108 CXClientData client_data);
2109
2110/**
2111 * \brief Visit the children of a particular cursor.
2112 *
2113 * This function visits all the direct children of the given cursor,
2114 * invoking the given \p visitor function with the cursors of each
2115 * visited child. The traversal may be recursive, if the visitor returns
2116 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2117 * the visitor returns \c CXChildVisit_Break.
2118 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002119 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002120 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002121 * definition, have no children).
2122 *
2123 * \param visitor the visitor function that will be invoked for each
2124 * child of \p parent.
2125 *
2126 * \param client_data pointer data supplied by the client, which will
2127 * be passed to the visitor each time it is invoked.
2128 *
2129 * \returns a non-zero value if the traversal was terminated
2130 * prematurely by the visitor returning \c CXChildVisit_Break.
2131 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002132CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002133 CXCursorVisitor visitor,
2134 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002135#ifdef __has_feature
2136# if __has_feature(blocks)
2137/**
2138 * \brief Visitor invoked for each cursor found by a traversal.
2139 *
2140 * This visitor block will be invoked for each cursor found by
2141 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2142 * visited, its second argument is the parent visitor for that cursor.
2143 *
2144 * The visitor should return one of the \c CXChildVisitResult values
2145 * to direct clang_visitChildrenWithBlock().
2146 */
2147typedef enum CXChildVisitResult
2148 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2149
2150/**
2151 * Visits the children of a cursor using the specified block. Behaves
2152 * identically to clang_visitChildren() in all other respects.
2153 */
2154unsigned clang_visitChildrenWithBlock(CXCursor parent,
2155 CXCursorVisitorBlock block);
2156# endif
2157#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002158
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002159/**
2160 * @}
2161 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002162
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002163/**
2164 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2165 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002166 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002167 * across translation units, by providing the names of the entities referenced
2168 * by cursors, follow reference cursors to the declarations they reference,
2169 * and associate declarations with their definitions.
2170 *
2171 * @{
2172 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002173
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002174/**
2175 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2176 * by the given cursor.
2177 *
2178 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2179 * entity (function, class, variable, etc.) within a program. USRs can be
2180 * compared across translation units to determine, e.g., when references in
2181 * one translation refer to an entity defined in another translation unit.
2182 */
2183CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2184
2185/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002186 * \brief Construct a USR for a specified Objective-C class.
2187 */
2188CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2189
2190/**
2191 * \brief Construct a USR for a specified Objective-C category.
2192 */
2193CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002194 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002195 const char *category_name);
2196
2197/**
2198 * \brief Construct a USR for a specified Objective-C protocol.
2199 */
2200CINDEX_LINKAGE CXString
2201 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2202
2203
2204/**
2205 * \brief Construct a USR for a specified Objective-C instance variable and
2206 * the USR for its containing class.
2207 */
2208CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2209 CXString classUSR);
2210
2211/**
2212 * \brief Construct a USR for a specified Objective-C method and
2213 * the USR for its containing class.
2214 */
2215CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2216 unsigned isInstanceMethod,
2217 CXString classUSR);
2218
2219/**
2220 * \brief Construct a USR for a specified Objective-C property and the USR
2221 * for its containing class.
2222 */
2223CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2224 CXString classUSR);
2225
2226/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002227 * \brief Retrieve a name for the entity referenced by this cursor.
2228 */
2229CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2230
Douglas Gregor358559d2010-10-02 22:49:11 +00002231/**
2232 * \brief Retrieve the display name for the entity referenced by this cursor.
2233 *
2234 * The display name contains extra information that helps identify the cursor,
2235 * such as the parameters of a function or template or the arguments of a
2236 * class template specialization.
2237 */
2238CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2239
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002240/** \brief For a cursor that is a reference, retrieve a cursor representing the
2241 * entity that it references.
2242 *
2243 * Reference cursors refer to other entities in the AST. For example, an
2244 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002245 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002246 * cursor for the superclass reference. If the input cursor is a declaration or
2247 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002248 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002249 */
2250CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002251
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002252/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002253 * \brief For a cursor that is either a reference to or a declaration
2254 * of some entity, retrieve a cursor that describes the definition of
2255 * that entity.
2256 *
2257 * Some entities can be declared multiple times within a translation
2258 * unit, but only one of those declarations can also be a
2259 * definition. For example, given:
2260 *
2261 * \code
2262 * int f(int, int);
2263 * int g(int x, int y) { return f(x, y); }
2264 * int f(int a, int b) { return a + b; }
2265 * int f(int, int);
2266 * \endcode
2267 *
2268 * there are three declarations of the function "f", but only the
2269 * second one is a definition. The clang_getCursorDefinition()
2270 * function will take any cursor pointing to a declaration of "f"
2271 * (the first or fourth lines of the example) or a cursor referenced
2272 * that uses "f" (the call to "f' inside "g") and will return a
2273 * declaration cursor pointing to the definition (the second "f"
2274 * declaration).
2275 *
2276 * If given a cursor for which there is no corresponding definition,
2277 * e.g., because there is no definition of that entity within this
2278 * translation unit, returns a NULL cursor.
2279 */
2280CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2281
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002282/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002283 * \brief Determine whether the declaration pointed to by this cursor
2284 * is also a definition of that entity.
2285 */
2286CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2287
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002288/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002289 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2290 *
2291 * In the C family of languages, many kinds of entities can be declared several
2292 * times within a single translation unit. For example, a structure type can
2293 * be forward-declared (possibly multiple times) and later defined:
2294 *
2295 * \code
2296 * struct X;
2297 * struct X;
2298 * struct X {
2299 * int member;
2300 * };
2301 * \endcode
2302 *
2303 * The declarations and the definition of \c X are represented by three
2304 * different cursors, all of which are declarations of the same underlying
2305 * entity. One of these cursor is considered the "canonical" cursor, which
2306 * is effectively the representative for the underlying entity. One can
2307 * determine if two cursors are declarations of the same underlying entity by
2308 * comparing their canonical cursors.
2309 *
2310 * \returns The canonical cursor for the entity referred to by the given cursor.
2311 */
2312CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2313
2314/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002315 * @}
2316 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002317
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002318/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002319 * \defgroup CINDEX_CPP C++ AST introspection
2320 *
2321 * The routines in this group provide access information in the ASTs specific
2322 * to C++ language features.
2323 *
2324 * @{
2325 */
2326
2327/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002328 * \brief Determine if a C++ member function or member function template is
2329 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002330 */
2331CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2332
2333/**
Douglas Gregor211924b2011-05-12 15:17:24 +00002334 * \brief Determine if a C++ member function or member function template is
2335 * explicitly declared 'virtual' or if it overrides a virtual method from
2336 * one of the base classes.
2337 */
2338CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2339
2340/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002341 * \brief Given a cursor that represents a template, determine
2342 * the cursor kind of the specializations would be generated by instantiating
2343 * the template.
2344 *
2345 * This routine can be used to determine what flavor of function template,
2346 * class template, or class template partial specialization is stored in the
2347 * cursor. For example, it can describe whether a class template cursor is
2348 * declared with "struct", "class" or "union".
2349 *
2350 * \param C The cursor to query. This cursor should represent a template
2351 * declaration.
2352 *
2353 * \returns The cursor kind of the specializations that would be generated
2354 * by instantiating the template \p C. If \p C is not a template, returns
2355 * \c CXCursor_NoDeclFound.
2356 */
2357CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2358
2359/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002360 * \brief Given a cursor that may represent a specialization or instantiation
2361 * of a template, retrieve the cursor that represents the template that it
2362 * specializes or from which it was instantiated.
2363 *
2364 * This routine determines the template involved both for explicit
2365 * specializations of templates and for implicit instantiations of the template,
2366 * both of which are referred to as "specializations". For a class template
2367 * specialization (e.g., \c std::vector<bool>), this routine will return
2368 * either the primary template (\c std::vector) or, if the specialization was
2369 * instantiated from a class template partial specialization, the class template
2370 * partial specialization. For a class template partial specialization and a
2371 * function template specialization (including instantiations), this
2372 * this routine will return the specialized template.
2373 *
2374 * For members of a class template (e.g., member functions, member classes, or
2375 * static data members), returns the specialized or instantiated member.
2376 * Although not strictly "templates" in the C++ language, members of class
2377 * templates have the same notions of specializations and instantiations that
2378 * templates do, so this routine treats them similarly.
2379 *
2380 * \param C A cursor that may be a specialization of a template or a member
2381 * of a template.
2382 *
2383 * \returns If the given cursor is a specialization or instantiation of a
2384 * template or a member thereof, the template or member that it specializes or
2385 * from which it was instantiated. Otherwise, returns a NULL cursor.
2386 */
2387CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00002388
2389/**
2390 * \brief Given a cursor that references something else, return the source range
2391 * covering that reference.
2392 *
2393 * \param C A cursor pointing to a member reference, a declaration reference, or
2394 * an operator call.
2395 * \param NameFlags A bitset with three independent flags:
2396 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
2397 * CXNameRange_WantSinglePiece.
2398 * \param PieceIndex For contiguous names or when passing the flag
2399 * CXNameRange_WantSinglePiece, only one piece with index 0 is
2400 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
2401 * non-contiguous names, this index can be used to retreive the individual
2402 * pieces of the name. See also CXNameRange_WantSinglePiece.
2403 *
2404 * \returns The piece of the name pointed to by the given cursor. If there is no
2405 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
2406 */
2407CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, unsigned NameFlags,
2408 unsigned PieceIndex);
2409
2410enum CXNameRefFlags {
2411 /**
2412 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
2413 * range.
2414 */
2415 CXNameRange_WantQualifier = 0x1,
2416
2417 /**
2418 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
2419 * the range.
2420 */
2421 CXNameRange_WantTemplateArgs = 0x2,
2422
2423 /**
2424 * \brief If the name is non-contiguous, return the full spanning range.
2425 *
2426 * Non-contiguous names occur in Objective-C when a selector with two or more
2427 * parameters is used, or in C++ when using an operator:
2428 * \code
2429 * [object doSomething:here withValue:there]; // ObjC
2430 * return some_vector[1]; // C++
2431 * \endcode
2432 */
2433 CXNameRange_WantSinglePiece = 0x4
2434};
Douglas Gregore0329ac2010-09-02 00:07:54 +00002435
2436/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002437 * @}
2438 */
2439
2440/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002441 * \defgroup CINDEX_LEX Token extraction and manipulation
2442 *
2443 * The routines in this group provide access to the tokens within a
2444 * translation unit, along with a semantic mapping of those tokens to
2445 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002446 *
2447 * @{
2448 */
2449
2450/**
2451 * \brief Describes a kind of token.
2452 */
2453typedef enum CXTokenKind {
2454 /**
2455 * \brief A token that contains some kind of punctuation.
2456 */
2457 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002458
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002459 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002460 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002461 */
2462 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002463
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002464 /**
2465 * \brief An identifier (that is not a keyword).
2466 */
2467 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002468
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002469 /**
2470 * \brief A numeric, string, or character literal.
2471 */
2472 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002473
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002474 /**
2475 * \brief A comment.
2476 */
2477 CXToken_Comment
2478} CXTokenKind;
2479
2480/**
2481 * \brief Describes a single preprocessing token.
2482 */
2483typedef struct {
2484 unsigned int_data[4];
2485 void *ptr_data;
2486} CXToken;
2487
2488/**
2489 * \brief Determine the kind of the given token.
2490 */
2491CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002492
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002493/**
2494 * \brief Determine the spelling of the given token.
2495 *
2496 * The spelling of a token is the textual representation of that token, e.g.,
2497 * the text of an identifier or keyword.
2498 */
2499CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002500
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002501/**
2502 * \brief Retrieve the source location of the given token.
2503 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002504CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002505 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002506
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002507/**
2508 * \brief Retrieve a source range that covers the given token.
2509 */
2510CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2511
2512/**
2513 * \brief Tokenize the source code described by the given range into raw
2514 * lexical tokens.
2515 *
2516 * \param TU the translation unit whose text is being tokenized.
2517 *
2518 * \param Range the source range in which text should be tokenized. All of the
2519 * tokens produced by tokenization will fall within this source range,
2520 *
2521 * \param Tokens this pointer will be set to point to the array of tokens
2522 * that occur within the given source range. The returned pointer must be
2523 * freed with clang_disposeTokens() before the translation unit is destroyed.
2524 *
2525 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2526 * array.
2527 *
2528 */
2529CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2530 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002531
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002532/**
2533 * \brief Annotate the given set of tokens by providing cursors for each token
2534 * that can be mapped to a specific entity within the abstract syntax tree.
2535 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002536 * This token-annotation routine is equivalent to invoking
2537 * clang_getCursor() for the source locations of each of the
2538 * tokens. The cursors provided are filtered, so that only those
2539 * cursors that have a direct correspondence to the token are
2540 * accepted. For example, given a function call \c f(x),
2541 * clang_getCursor() would provide the following cursors:
2542 *
2543 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2544 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2545 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2546 *
2547 * Only the first and last of these cursors will occur within the
2548 * annotate, since the tokens "f" and "x' directly refer to a function
2549 * and a variable, respectively, but the parentheses are just a small
2550 * part of the full syntax of the function call expression, which is
2551 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002552 *
2553 * \param TU the translation unit that owns the given tokens.
2554 *
2555 * \param Tokens the set of tokens to annotate.
2556 *
2557 * \param NumTokens the number of tokens in \p Tokens.
2558 *
2559 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2560 * replaced with the cursors corresponding to each token.
2561 */
2562CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2563 CXToken *Tokens, unsigned NumTokens,
2564 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002565
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002566/**
2567 * \brief Free the given set of tokens.
2568 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002569CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002570 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002571
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002572/**
2573 * @}
2574 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002575
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002576/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002577 * \defgroup CINDEX_DEBUG Debugging facilities
2578 *
2579 * These routines are used for testing and debugging, only, and should not
2580 * be relied upon.
2581 *
2582 * @{
2583 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002584
Steve Naroff4ade6d62009-09-23 17:52:52 +00002585/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002586CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002587CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2588 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002589 const char **endBuf,
2590 unsigned *startLine,
2591 unsigned *startColumn,
2592 unsigned *endLine,
2593 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002594CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00002595CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
2596 unsigned stack_size);
2597
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002598/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002599 * @}
2600 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002601
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002602/**
2603 * \defgroup CINDEX_CODE_COMPLET Code completion
2604 *
2605 * Code completion involves taking an (incomplete) source file, along with
2606 * knowledge of where the user is actively editing that file, and suggesting
2607 * syntactically- and semantically-valid constructs that the user might want to
2608 * use at that particular point in the source code. These data structures and
2609 * routines provide support for code completion.
2610 *
2611 * @{
2612 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002613
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002614/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002615 * \brief A semantic string that describes a code-completion result.
2616 *
2617 * A semantic string that describes the formatting of a code-completion
2618 * result as a single "template" of text that should be inserted into the
2619 * source buffer when a particular code-completion result is selected.
2620 * Each semantic string is made up of some number of "chunks", each of which
2621 * contains some text along with a description of what that text means, e.g.,
2622 * the name of the entity being referenced, whether the text chunk is part of
2623 * the template, or whether it is a "placeholder" that the user should replace
2624 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002625 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002626 */
2627typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002628
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002629/**
2630 * \brief A single result of code completion.
2631 */
2632typedef struct {
2633 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002634 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002635 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002636 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002637 * *Decl cursor kinds), describing the entity that the completion is
2638 * referring to.
2639 *
2640 * \todo In the future, we would like to provide a full cursor, to allow
2641 * the client to extract additional information from declaration.
2642 */
2643 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002644
2645 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002646 * \brief The code-completion string that describes how to insert this
2647 * code-completion result into the editing buffer.
2648 */
2649 CXCompletionString CompletionString;
2650} CXCompletionResult;
2651
2652/**
2653 * \brief Describes a single piece of text within a code-completion string.
2654 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002655 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2656 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002657 * should be interpreted by the client or is another completion string.
2658 */
2659enum CXCompletionChunkKind {
2660 /**
2661 * \brief A code-completion string that describes "optional" text that
2662 * could be a part of the template (but is not required).
2663 *
2664 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002665 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002666 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2667 * describes an additional part of the template that is completely optional.
2668 * For example, optional chunks can be used to describe the placeholders for
2669 * arguments that match up with defaulted function parameters, e.g. given:
2670 *
2671 * \code
2672 * void f(int x, float y = 3.14, double z = 2.71828);
2673 * \endcode
2674 *
2675 * The code-completion string for this function would contain:
2676 * - a TypedText chunk for "f".
2677 * - a LeftParen chunk for "(".
2678 * - a Placeholder chunk for "int x"
2679 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2680 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002681 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002682 * - an Optional chunk containing the last defaulted argument:
2683 * - a Comma chunk for ","
2684 * - a Placeholder chunk for "double z"
2685 * - a RightParen chunk for ")"
2686 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002687 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002688 * - Completely ignore optional chunks, in which case the template for the
2689 * function "f" would only include the first parameter ("int x").
2690 * - Fully expand all optional chunks, in which case the template for the
2691 * function "f" would have all of the parameters.
2692 */
2693 CXCompletionChunk_Optional,
2694 /**
2695 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002696 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002697 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002698 * There will be exactly one "typed text" chunk in a semantic string, which
2699 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002700 * declaration that could be used at the current code point. Clients are
2701 * expected to filter the code-completion results based on the text in this
2702 * chunk.
2703 */
2704 CXCompletionChunk_TypedText,
2705 /**
2706 * \brief Text that should be inserted as part of a code-completion result.
2707 *
2708 * A "text" chunk represents text that is part of the template to be
2709 * inserted into user code should this particular code-completion result
2710 * be selected.
2711 */
2712 CXCompletionChunk_Text,
2713 /**
2714 * \brief Placeholder text that should be replaced by the user.
2715 *
2716 * A "placeholder" chunk marks a place where the user should insert text
2717 * into the code-completion template. For example, placeholders might mark
2718 * the function parameters for a function declaration, to indicate that the
2719 * user should provide arguments for each of those parameters. The actual
2720 * text in a placeholder is a suggestion for the text to display before
2721 * the user replaces the placeholder with real code.
2722 */
2723 CXCompletionChunk_Placeholder,
2724 /**
2725 * \brief Informative text that should be displayed but never inserted as
2726 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002727 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002728 * An "informative" chunk contains annotations that can be displayed to
2729 * help the user decide whether a particular code-completion result is the
2730 * right option, but which is not part of the actual template to be inserted
2731 * by code completion.
2732 */
2733 CXCompletionChunk_Informative,
2734 /**
2735 * \brief Text that describes the current parameter when code-completion is
2736 * referring to function call, message send, or template specialization.
2737 *
2738 * A "current parameter" chunk occurs when code-completion is providing
2739 * information about a parameter corresponding to the argument at the
2740 * code-completion point. For example, given a function
2741 *
2742 * \code
2743 * int add(int x, int y);
2744 * \endcode
2745 *
2746 * and the source code \c add(, where the code-completion point is after the
2747 * "(", the code-completion string will contain a "current parameter" chunk
2748 * for "int x", indicating that the current argument will initialize that
2749 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002750 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002751 * "current paremeter" chunk to "int y".
2752 */
2753 CXCompletionChunk_CurrentParameter,
2754 /**
2755 * \brief A left parenthesis ('('), used to initiate a function call or
2756 * signal the beginning of a function parameter list.
2757 */
2758 CXCompletionChunk_LeftParen,
2759 /**
2760 * \brief A right parenthesis (')'), used to finish a function call or
2761 * signal the end of a function parameter list.
2762 */
2763 CXCompletionChunk_RightParen,
2764 /**
2765 * \brief A left bracket ('[').
2766 */
2767 CXCompletionChunk_LeftBracket,
2768 /**
2769 * \brief A right bracket (']').
2770 */
2771 CXCompletionChunk_RightBracket,
2772 /**
2773 * \brief A left brace ('{').
2774 */
2775 CXCompletionChunk_LeftBrace,
2776 /**
2777 * \brief A right brace ('}').
2778 */
2779 CXCompletionChunk_RightBrace,
2780 /**
2781 * \brief A left angle bracket ('<').
2782 */
2783 CXCompletionChunk_LeftAngle,
2784 /**
2785 * \brief A right angle bracket ('>').
2786 */
2787 CXCompletionChunk_RightAngle,
2788 /**
2789 * \brief A comma separator (',').
2790 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002791 CXCompletionChunk_Comma,
2792 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002793 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002794 *
2795 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002796 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002797 * expression using the given completion string would have.
2798 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002799 CXCompletionChunk_ResultType,
2800 /**
2801 * \brief A colon (':').
2802 */
2803 CXCompletionChunk_Colon,
2804 /**
2805 * \brief A semicolon (';').
2806 */
2807 CXCompletionChunk_SemiColon,
2808 /**
2809 * \brief An '=' sign.
2810 */
2811 CXCompletionChunk_Equal,
2812 /**
2813 * Horizontal space (' ').
2814 */
2815 CXCompletionChunk_HorizontalSpace,
2816 /**
2817 * Vertical space ('\n'), after which it is generally a good idea to
2818 * perform indentation.
2819 */
2820 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002821};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002822
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002823/**
2824 * \brief Determine the kind of a particular chunk within a completion string.
2825 *
2826 * \param completion_string the completion string to query.
2827 *
2828 * \param chunk_number the 0-based index of the chunk in the completion string.
2829 *
2830 * \returns the kind of the chunk at the index \c chunk_number.
2831 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002832CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002833clang_getCompletionChunkKind(CXCompletionString completion_string,
2834 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002835
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002836/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002837 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002838 * completion string.
2839 *
2840 * \param completion_string the completion string to query.
2841 *
2842 * \param chunk_number the 0-based index of the chunk in the completion string.
2843 *
2844 * \returns the text associated with the chunk at index \c chunk_number.
2845 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002846CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002847clang_getCompletionChunkText(CXCompletionString completion_string,
2848 unsigned chunk_number);
2849
2850/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002851 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002852 * within a completion string.
2853 *
2854 * \param completion_string the completion string to query.
2855 *
2856 * \param chunk_number the 0-based index of the chunk in the completion string.
2857 *
2858 * \returns the completion string associated with the chunk at index
2859 * \c chunk_number, or NULL if that chunk is not represented by a completion
2860 * string.
2861 */
2862CINDEX_LINKAGE CXCompletionString
2863clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2864 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002865
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002866/**
2867 * \brief Retrieve the number of chunks in the given code-completion string.
2868 */
2869CINDEX_LINKAGE unsigned
2870clang_getNumCompletionChunks(CXCompletionString completion_string);
2871
2872/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002873 * \brief Determine the priority of this code completion.
2874 *
2875 * The priority of a code completion indicates how likely it is that this
2876 * particular completion is the completion that the user will select. The
2877 * priority is selected by various internal heuristics.
2878 *
2879 * \param completion_string The completion string to query.
2880 *
2881 * \returns The priority of this completion string. Smaller values indicate
2882 * higher-priority (more likely) completions.
2883 */
2884CINDEX_LINKAGE unsigned
2885clang_getCompletionPriority(CXCompletionString completion_string);
2886
2887/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002888 * \brief Determine the availability of the entity that this code-completion
2889 * string refers to.
2890 *
2891 * \param completion_string The completion string to query.
2892 *
2893 * \returns The availability of the completion string.
2894 */
2895CINDEX_LINKAGE enum CXAvailabilityKind
2896clang_getCompletionAvailability(CXCompletionString completion_string);
2897
2898/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002899 * \brief Contains the results of code-completion.
2900 *
2901 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002902 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002903 * \c clang_disposeCodeCompleteResults.
2904 */
2905typedef struct {
2906 /**
2907 * \brief The code-completion results.
2908 */
2909 CXCompletionResult *Results;
2910
2911 /**
2912 * \brief The number of code-completion results stored in the
2913 * \c Results array.
2914 */
2915 unsigned NumResults;
2916} CXCodeCompleteResults;
2917
2918/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002919 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2920 * modify its behavior.
2921 *
2922 * The enumerators in this enumeration can be bitwise-OR'd together to
2923 * provide multiple options to \c clang_codeCompleteAt().
2924 */
2925enum CXCodeComplete_Flags {
2926 /**
2927 * \brief Whether to include macros within the set of code
2928 * completions returned.
2929 */
2930 CXCodeComplete_IncludeMacros = 0x01,
2931
2932 /**
2933 * \brief Whether to include code patterns for language constructs
2934 * within the set of code completions, e.g., for loops.
2935 */
2936 CXCodeComplete_IncludeCodePatterns = 0x02
2937};
2938
2939/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00002940 * \brief Bits that represent the context under which completion is occurring.
2941 *
2942 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
2943 * contexts are occurring simultaneously.
2944 */
2945enum CXCompletionContext {
2946 /**
2947 * \brief The context for completions is unexposed, as only Clang results
2948 * should be included. (This is equivalent to having no context bits set.)
2949 */
2950 CXCompletionContext_Unexposed = 0,
2951
2952 /**
2953 * \brief Completions for any possible type should be included in the results.
2954 */
2955 CXCompletionContext_AnyType = 1 << 0,
2956
2957 /**
2958 * \brief Completions for any possible value (variables, function calls, etc.)
2959 * should be included in the results.
2960 */
2961 CXCompletionContext_AnyValue = 1 << 1,
2962 /**
2963 * \brief Completions for values that resolve to an Objective-C object should
2964 * be included in the results.
2965 */
2966 CXCompletionContext_ObjCObjectValue = 1 << 2,
2967 /**
2968 * \brief Completions for values that resolve to an Objective-C selector
2969 * should be included in the results.
2970 */
2971 CXCompletionContext_ObjCSelectorValue = 1 << 3,
2972 /**
2973 * \brief Completions for values that resolve to a C++ class type should be
2974 * included in the results.
2975 */
2976 CXCompletionContext_CXXClassTypeValue = 1 << 4,
2977
2978 /**
2979 * \brief Completions for fields of the member being accessed using the dot
2980 * operator should be included in the results.
2981 */
2982 CXCompletionContext_DotMemberAccess = 1 << 5,
2983 /**
2984 * \brief Completions for fields of the member being accessed using the arrow
2985 * operator should be included in the results.
2986 */
2987 CXCompletionContext_ArrowMemberAccess = 1 << 6,
2988 /**
2989 * \brief Completions for properties of the Objective-C object being accessed
2990 * using the dot operator should be included in the results.
2991 */
2992 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
2993
2994 /**
2995 * \brief Completions for enum tags should be included in the results.
2996 */
2997 CXCompletionContext_EnumTag = 1 << 8,
2998 /**
2999 * \brief Completions for union tags should be included in the results.
3000 */
3001 CXCompletionContext_UnionTag = 1 << 9,
3002 /**
3003 * \brief Completions for struct tags should be included in the results.
3004 */
3005 CXCompletionContext_StructTag = 1 << 10,
3006
3007 /**
3008 * \brief Completions for C++ class names should be included in the results.
3009 */
3010 CXCompletionContext_ClassTag = 1 << 11,
3011 /**
3012 * \brief Completions for C++ namespaces and namespace aliases should be
3013 * included in the results.
3014 */
3015 CXCompletionContext_Namespace = 1 << 12,
3016 /**
3017 * \brief Completions for C++ nested name specifiers should be included in
3018 * the results.
3019 */
3020 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3021
3022 /**
3023 * \brief Completions for Objective-C interfaces (classes) should be included
3024 * in the results.
3025 */
3026 CXCompletionContext_ObjCInterface = 1 << 14,
3027 /**
3028 * \brief Completions for Objective-C protocols should be included in
3029 * the results.
3030 */
3031 CXCompletionContext_ObjCProtocol = 1 << 15,
3032 /**
3033 * \brief Completions for Objective-C categories should be included in
3034 * the results.
3035 */
3036 CXCompletionContext_ObjCCategory = 1 << 16,
3037 /**
3038 * \brief Completions for Objective-C instance messages should be included
3039 * in the results.
3040 */
3041 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3042 /**
3043 * \brief Completions for Objective-C class messages should be included in
3044 * the results.
3045 */
3046 CXCompletionContext_ObjCClassMessage = 1 << 18,
3047 /**
3048 * \brief Completions for Objective-C selector names should be included in
3049 * the results.
3050 */
3051 CXCompletionContext_ObjCSelectorName = 1 << 19,
3052
3053 /**
3054 * \brief Completions for preprocessor macro names should be included in
3055 * the results.
3056 */
3057 CXCompletionContext_MacroName = 1 << 20,
3058
3059 /**
3060 * \brief Natural language completions should be included in the results.
3061 */
3062 CXCompletionContext_NaturalLanguage = 1 << 21,
3063
3064 /**
3065 * \brief The current context is unknown, so set all contexts.
3066 */
3067 CXCompletionContext_Unknown = ((1 << 22) - 1)
3068};
3069
3070/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003071 * \brief Returns a default set of code-completion options that can be
3072 * passed to\c clang_codeCompleteAt().
3073 */
3074CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3075
3076/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003077 * \brief Perform code completion at a given location in a translation unit.
3078 *
3079 * This function performs code completion at a particular file, line, and
3080 * column within source code, providing results that suggest potential
3081 * code snippets based on the context of the completion. The basic model
3082 * for code completion is that Clang will parse a complete source file,
3083 * performing syntax checking up to the location where code-completion has
3084 * been requested. At that point, a special code-completion token is passed
3085 * to the parser, which recognizes this token and determines, based on the
3086 * current location in the C/Objective-C/C++ grammar and the state of
3087 * semantic analysis, what completions to provide. These completions are
3088 * returned via a new \c CXCodeCompleteResults structure.
3089 *
3090 * Code completion itself is meant to be triggered by the client when the
3091 * user types punctuation characters or whitespace, at which point the
3092 * code-completion location will coincide with the cursor. For example, if \c p
3093 * is a pointer, code-completion might be triggered after the "-" and then
3094 * after the ">" in \c p->. When the code-completion location is afer the ">",
3095 * the completion results will provide, e.g., the members of the struct that
3096 * "p" points to. The client is responsible for placing the cursor at the
3097 * beginning of the token currently being typed, then filtering the results
3098 * based on the contents of the token. For example, when code-completing for
3099 * the expression \c p->get, the client should provide the location just after
3100 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3101 * client can filter the results based on the current token text ("get"), only
3102 * showing those results that start with "get". The intent of this interface
3103 * is to separate the relatively high-latency acquisition of code-completion
3104 * results from the filtering of results on a per-character basis, which must
3105 * have a lower latency.
3106 *
3107 * \param TU The translation unit in which code-completion should
3108 * occur. The source files for this translation unit need not be
3109 * completely up-to-date (and the contents of those source files may
3110 * be overridden via \p unsaved_files). Cursors referring into the
3111 * translation unit may be invalidated by this invocation.
3112 *
3113 * \param complete_filename The name of the source file where code
3114 * completion should be performed. This filename may be any file
3115 * included in the translation unit.
3116 *
3117 * \param complete_line The line at which code-completion should occur.
3118 *
3119 * \param complete_column The column at which code-completion should occur.
3120 * Note that the column should point just after the syntactic construct that
3121 * initiated code completion, and not in the middle of a lexical token.
3122 *
3123 * \param unsaved_files the Tiles that have not yet been saved to disk
3124 * but may be required for parsing or code completion, including the
3125 * contents of those files. The contents and name of these files (as
3126 * specified by CXUnsavedFile) are copied when necessary, so the
3127 * client only needs to guarantee their validity until the call to
3128 * this function returns.
3129 *
3130 * \param num_unsaved_files The number of unsaved file entries in \p
3131 * unsaved_files.
3132 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00003133 * \param options Extra options that control the behavior of code
3134 * completion, expressed as a bitwise OR of the enumerators of the
3135 * CXCodeComplete_Flags enumeration. The
3136 * \c clang_defaultCodeCompleteOptions() function returns a default set
3137 * of code-completion options.
3138 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003139 * \returns If successful, a new \c CXCodeCompleteResults structure
3140 * containing code-completion results, which should eventually be
3141 * freed with \c clang_disposeCodeCompleteResults(). If code
3142 * completion fails, returns NULL.
3143 */
3144CINDEX_LINKAGE
3145CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3146 const char *complete_filename,
3147 unsigned complete_line,
3148 unsigned complete_column,
3149 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00003150 unsigned num_unsaved_files,
3151 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003152
3153/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00003154 * \brief Sort the code-completion results in case-insensitive alphabetical
3155 * order.
3156 *
3157 * \param Results The set of results to sort.
3158 * \param NumResults The number of results in \p Results.
3159 */
3160CINDEX_LINKAGE
3161void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3162 unsigned NumResults);
3163
3164/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003165 * \brief Free the given set of code-completion results.
3166 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003167CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00003168void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00003169
Douglas Gregor20d416c2010-01-20 01:10:47 +00003170/**
Douglas Gregora88084b2010-02-18 18:08:43 +00003171 * \brief Determine the number of diagnostics produced prior to the
3172 * location where code completion was performed.
3173 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003174CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003175unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3176
3177/**
3178 * \brief Retrieve a diagnostic associated with the given code completion.
3179 *
3180 * \param Result the code completion results to query.
3181 * \param Index the zero-based diagnostic number to retrieve.
3182 *
3183 * \returns the requested diagnostic. This diagnostic must be freed
3184 * via a call to \c clang_disposeDiagnostic().
3185 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003186CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003187CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3188 unsigned Index);
3189
3190/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003191 * \brief Determines what compeltions are appropriate for the context
3192 * the given code completion.
3193 *
3194 * \param Results the code completion results to query
3195 *
3196 * \returns the kinds of completions that are appropriate for use
3197 * along with the given code completion results.
3198 */
3199CINDEX_LINKAGE
3200unsigned long long clang_codeCompleteGetContexts(
3201 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00003202
3203/**
3204 * \brief Returns the cursor kind for the container for the current code
3205 * completion context. The container is only guaranteed to be set for
3206 * contexts where a container exists (i.e. member accesses or Objective-C
3207 * message sends); if there is not a container, this function will return
3208 * CXCursor_InvalidCode.
3209 *
3210 * \param Results the code completion results to query
3211 *
3212 * \param IsIncomplete on return, this value will be false if Clang has complete
3213 * information about the container. If Clang does not have complete
3214 * information, this value will be true.
3215 *
3216 * \returns the container kind, or CXCursor_InvalidCode if there is not a
3217 * container
3218 */
3219CINDEX_LINKAGE
3220enum CXCursorKind clang_codeCompleteGetContainerKind(
3221 CXCodeCompleteResults *Results,
3222 unsigned *IsIncomplete);
3223
3224/**
3225 * \brief Returns the USR for the container for the current code completion
3226 * context. If there is not a container for the current context, this
3227 * function will return the empty string.
3228 *
3229 * \param Results the code completion results to query
3230 *
3231 * \returns the USR for the container
3232 */
3233CINDEX_LINKAGE
3234CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00003235
3236/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00003237 * @}
3238 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003239
3240
Ted Kremenek04bb7162010-01-22 22:44:15 +00003241/**
3242 * \defgroup CINDEX_MISC Miscellaneous utility functions
3243 *
3244 * @{
3245 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00003246
3247/**
3248 * \brief Return a version string, suitable for showing to a user, but not
3249 * intended to be parsed (the format is not guaranteed to be stable).
3250 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00003251CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00003252
Ted Kremenekd2427dd2011-03-18 23:05:39 +00003253
3254/**
3255 * \brief Enable/disable crash recovery.
3256 *
3257 * \param Flag to indicate if crash recovery is enabled. A non-zero value
3258 * enables crash recovery, while 0 disables it.
3259 */
3260CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
3261
Ted Kremenek16b55a72010-01-26 19:31:51 +00003262 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003263 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00003264 * (used with clang_getInclusions()).
3265 *
3266 * This visitor function will be invoked by clang_getInclusions() for each
3267 * file included (either at the top-level or by #include directives) within
3268 * a translation unit. The first argument is the file being included, and
3269 * the second and third arguments provide the inclusion stack. The
3270 * array is sorted in order of immediate inclusion. For example,
3271 * the first element refers to the location that included 'included_file'.
3272 */
3273typedef void (*CXInclusionVisitor)(CXFile included_file,
3274 CXSourceLocation* inclusion_stack,
3275 unsigned include_len,
3276 CXClientData client_data);
3277
3278/**
3279 * \brief Visit the set of preprocessor inclusions in a translation unit.
3280 * The visitor function is called with the provided data for every included
3281 * file. This does not include headers included by the PCH file (unless one
3282 * is inspecting the inclusions in the PCH file itself).
3283 */
3284CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3285 CXInclusionVisitor visitor,
3286 CXClientData client_data);
3287
3288/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00003289 * @}
3290 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003291
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00003292/** \defgroup CINDEX_REMAPPING Remapping functions
3293 *
3294 * @{
3295 */
3296
3297/**
3298 * \brief A remapping of original source files and their translated files.
3299 */
3300typedef void *CXRemapping;
3301
3302/**
3303 * \brief Retrieve a remapping.
3304 *
3305 * \param path the path that contains metadata about remappings.
3306 *
3307 * \returns the requested remapping. This remapping must be freed
3308 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3309 */
3310CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
3311
3312/**
3313 * \brief Determine the number of remappings.
3314 */
3315CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
3316
3317/**
3318 * \brief Get the original and the associated filename from the remapping.
3319 *
3320 * \param original If non-NULL, will be set to the original filename.
3321 *
3322 * \param transformed If non-NULL, will be set to the filename that the original
3323 * is associated with.
3324 */
3325CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
3326 CXString *original, CXString *transformed);
3327
3328/**
3329 * \brief Dispose the remapping.
3330 */
3331CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
3332
3333/**
3334 * @}
3335 */
3336
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003337/**
3338 * @}
3339 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003340
Ted Kremenekd2fa5662009-08-26 22:36:44 +00003341#ifdef __cplusplus
3342}
3343#endif
3344#endif
3345