blob: 20c8c1199460cbc59b2488797d6807d6c9b3eeb1 [file] [log] [blame]
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
Steve Naroff88145032009-10-27 14:35:18 +000019#include <sys/stat.h>
Chandler Carruth3d315602009-12-17 09:27:29 +000020#include <time.h>
Douglas Gregor0a812cf2010-02-18 23:07:20 +000021#include <stdio.h>
Steve Naroff88145032009-10-27 14:35:18 +000022
Ted Kremenekd2fa5662009-08-26 22:36:44 +000023#ifdef __cplusplus
24extern "C" {
25#endif
26
Steve Naroff88145032009-10-27 14:35:18 +000027/* MSVC DLL import/export. */
John Thompson2e06fc82009-10-27 13:42:56 +000028#ifdef _MSC_VER
29 #ifdef _CINDEX_LIB_
30 #define CINDEX_LINKAGE __declspec(dllexport)
31 #else
32 #define CINDEX_LINKAGE __declspec(dllimport)
33 #endif
34#else
35 #define CINDEX_LINKAGE
36#endif
37
Douglas Gregor20d416c2010-01-20 01:10:47 +000038/** \defgroup CINDEX C Interface to Clang
39 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000040 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000041 * facilities for parsing source code into an abstract syntax tree (AST),
42 * loading already-parsed ASTs, traversing the AST, associating
43 * physical source locations with elements within the AST, and other
44 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000045 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000046 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000047 * representation stored in Clang's C++ AST, nor should it: the intent is to
48 * maintain an API that is relatively stable from one release to the next,
49 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000050 *
51 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000052 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000053 *
54 * @{
55 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000056
Douglas Gregor7f173762010-01-20 22:28:27 +000057/**
58 * \brief An "index" that consists of a set of translation units that would
59 * typically be linked together into an executable or library.
60 */
61typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000062
Douglas Gregor7f173762010-01-20 22:28:27 +000063/**
64 * \brief A single translation unit, which resides in an index.
65 */
Steve Naroff50398192009-08-28 15:28:48 +000066typedef void *CXTranslationUnit; /* A translation unit instance. */
Steve Naroff600866c2009-08-27 19:51:58 +000067
Douglas Gregor7f173762010-01-20 22:28:27 +000068/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000069 * \brief Opaque pointer representing client data that will be passed through
70 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000071 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000072typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000073
Douglas Gregor735df882009-12-02 09:21:34 +000074/**
75 * \brief Provides the contents of a file that has not yet been saved to disk.
76 *
77 * Each CXUnsavedFile instance provides the name of a file on the
78 * system along with the current contents of that file that have not
79 * yet been saved to disk.
80 */
81struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000082 /**
83 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000084 *
85 * This file must already exist in the file system.
86 */
87 const char *Filename;
88
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000089 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000090 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +000091 */
92 const char *Contents;
93
94 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000095 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +000096 */
97 unsigned long Length;
98};
99
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000100/**
101 * \brief Describes the availability of a particular entity, which indicates
102 * whether the use of this entity will result in a warning or error due to
103 * it being deprecated or unavailable.
104 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000105enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000106 /**
107 * \brief The entity is available.
108 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000109 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000110 /**
111 * \brief The entity is available, but has been deprecated (and its use is
112 * not recommended).
113 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000114 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000115 /**
116 * \brief The entity is not available; any use of it will be an error.
117 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000118 CXAvailability_NotAvailable
119};
120
Douglas Gregor7f173762010-01-20 22:28:27 +0000121/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000122 * \defgroup CINDEX_STRING String manipulation routines
123 *
124 * @{
125 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000126
Douglas Gregor7f173762010-01-20 22:28:27 +0000127/**
128 * \brief A character string.
129 *
130 * The \c CXString type is used to return strings from the interface when
131 * the ownership of that string might different from one call to the next.
132 * Use \c clang_getCString() to retrieve the string data and, once finished
133 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000134 */
135typedef struct {
136 const char *Spelling;
137 /* A 1 value indicates the clang_ indexing API needed to allocate the string
138 (and it must be freed by clang_disposeString()). */
139 int MustFreeString;
140} CXString;
141
Douglas Gregor7f173762010-01-20 22:28:27 +0000142/**
143 * \brief Retrieve the character data associated with the given string.
144 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000145CINDEX_LINKAGE const char *clang_getCString(CXString string);
146
Douglas Gregor7f173762010-01-20 22:28:27 +0000147/**
148 * \brief Free the given string,
149 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000150CINDEX_LINKAGE void clang_disposeString(CXString string);
151
Douglas Gregor7f173762010-01-20 22:28:27 +0000152/**
153 * @}
154 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000155
156/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000157 * \brief clang_createIndex() provides a shared context for creating
158 * translation units. It provides two options:
159 *
160 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
161 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000162 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000163 * header that was used by the translation unit. If zero, all declarations
164 * will be enumerated.
165 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000166 * Here is an example:
167 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000168 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
169 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000170 *
171 * // IndexTest.pch was produced with the following command:
172 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
173 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
174 *
175 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000176 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000177 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000178 * clang_disposeTranslationUnit(TU);
179 *
180 * // This will load all the symbols from 'IndexTest.c', excluding symbols
181 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000182 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
183 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
184 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000185 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
186 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000187 * clang_disposeTranslationUnit(TU);
188 *
189 * This process of creating the 'pch', loading it separately, and using it (via
190 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
191 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000192 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000193CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
194 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000195
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000196/**
197 * \brief Destroy the given index.
198 *
199 * The index must not be destroyed until all of the translation units created
200 * within that index have been destroyed.
201 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000202CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000203
204/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000205 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000206 *
207 * @{
208 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000209
Douglas Gregorf5525442010-01-20 22:45:41 +0000210/**
211 * \brief A particular source file that is part of a translation unit.
212 */
213typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000214
Douglas Gregorf5525442010-01-20 22:45:41 +0000215
216/**
217 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000218 */
Ted Kremenek74844072010-02-17 00:41:20 +0000219CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000220
Douglas Gregorf5525442010-01-20 22:45:41 +0000221/**
222 * \brief Retrieve the last modification time of the given file.
223 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000224CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000225
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000226/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000227 * \brief Retrieve a file handle within the given translation unit.
228 *
229 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000230 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000231 * \param file_name the name of the file.
232 *
233 * \returns the file handle for the named file in the translation unit \p tu,
234 * or a NULL file handle if the file was not a part of this translation unit.
235 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000236CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000237 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000238
Douglas Gregorb9790342010-01-22 21:44:22 +0000239/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000240 * @}
241 */
242
243/**
244 * \defgroup CINDEX_LOCATIONS Physical source locations
245 *
246 * Clang represents physical source locations in its abstract syntax tree in
247 * great detail, with file, line, and column information for the majority of
248 * the tokens parsed in the source code. These data types and functions are
249 * used to represent source location information, either for a particular
250 * point in the program or for a range of points in the program, and extract
251 * specific location information from those data types.
252 *
253 * @{
254 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000255
Douglas Gregorf5525442010-01-20 22:45:41 +0000256/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000257 * \brief Identifies a specific source location within a translation
258 * unit.
259 *
260 * Use clang_getInstantiationLocation() to map a source location to a
261 * particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000262 */
263typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000264 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000265 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000266} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000267
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000268/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000269 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000270 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000271 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
272 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000273 */
274typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000275 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000276 unsigned begin_int_data;
277 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000278} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000279
Douglas Gregor1db19de2010-01-19 21:36:55 +0000280/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000281 * \brief Retrieve a NULL (invalid) source location.
282 */
283CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000284
Douglas Gregorb9790342010-01-22 21:44:22 +0000285/**
286 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000287 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000288 * code.
289 *
290 * \returns non-zero if the source locations refer to the same location, zero
291 * if they refer to different locations.
292 */
293CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
294 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000295
Douglas Gregorb9790342010-01-22 21:44:22 +0000296/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000297 * \brief Retrieves the source location associated with a given file/line/column
298 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000299 */
300CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
301 CXFile file,
302 unsigned line,
303 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000304/**
305 * \brief Retrieves the source location associated with a given character offset
306 * in a particular translation unit.
307 */
308CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
309 CXFile file,
310 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000311
Douglas Gregorb9790342010-01-22 21:44:22 +0000312/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000313 * \brief Retrieve a NULL (invalid) source range.
314 */
315CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000316
Douglas Gregor5352ac02010-01-28 00:27:43 +0000317/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000318 * \brief Retrieve a source range given the beginning and ending source
319 * locations.
320 */
321CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
322 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000323
Douglas Gregorb9790342010-01-22 21:44:22 +0000324/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000325 * \brief Retrieve the file, line, column, and offset represented by
326 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000327 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000328 * \param location the location within a source file that will be decomposed
329 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000330 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000331 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000332 * source location points.
333 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000334 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000335 * source location points.
336 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000337 * \param column [out] if non-NULL, will be set to the column to which the given
338 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000339 *
340 * \param offset [out] if non-NULL, will be set to the offset into the
341 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000342 */
343CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
344 CXFile *file,
345 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000346 unsigned *column,
347 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000348
349/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000350 * \brief Retrieve a source location representing the first character within a
351 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000352 */
353CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
354
355/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000356 * \brief Retrieve a source location representing the last character within a
357 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000358 */
359CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
360
Douglas Gregorf5525442010-01-20 22:45:41 +0000361/**
362 * @}
363 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000364
365/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000366 * \defgroup CINDEX_DIAG Diagnostic reporting
367 *
368 * @{
369 */
370
371/**
372 * \brief Describes the severity of a particular diagnostic.
373 */
374enum CXDiagnosticSeverity {
375 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000376 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000377 * option.
378 */
379 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000380
Douglas Gregor5352ac02010-01-28 00:27:43 +0000381 /**
382 * \brief This diagnostic is a note that should be attached to the
383 * previous (non-note) diagnostic.
384 */
385 CXDiagnostic_Note = 1,
386
387 /**
388 * \brief This diagnostic indicates suspicious code that may not be
389 * wrong.
390 */
391 CXDiagnostic_Warning = 2,
392
393 /**
394 * \brief This diagnostic indicates that the code is ill-formed.
395 */
396 CXDiagnostic_Error = 3,
397
398 /**
399 * \brief This diagnostic indicates that the code is ill-formed such
400 * that future parser recovery is unlikely to produce useful
401 * results.
402 */
403 CXDiagnostic_Fatal = 4
404};
405
406/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000407 * \brief A single diagnostic, containing the diagnostic's severity,
408 * location, text, source ranges, and fix-it hints.
409 */
410typedef void *CXDiagnostic;
411
412/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000413 * \brief Determine the number of diagnostics produced for the given
414 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000415 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000416CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
417
418/**
419 * \brief Retrieve a diagnostic associated with the given translation unit.
420 *
421 * \param Unit the translation unit to query.
422 * \param Index the zero-based diagnostic number to retrieve.
423 *
424 * \returns the requested diagnostic. This diagnostic must be freed
425 * via a call to \c clang_disposeDiagnostic().
426 */
427CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
428 unsigned Index);
429
430/**
431 * \brief Destroy a diagnostic.
432 */
433CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000434
435/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000436 * \brief Options to control the display of diagnostics.
437 *
438 * The values in this enum are meant to be combined to customize the
439 * behavior of \c clang_displayDiagnostic().
440 */
441enum CXDiagnosticDisplayOptions {
442 /**
443 * \brief Display the source-location information where the
444 * diagnostic was located.
445 *
446 * When set, diagnostics will be prefixed by the file, line, and
447 * (optionally) column to which the diagnostic refers. For example,
448 *
449 * \code
450 * test.c:28: warning: extra tokens at end of #endif directive
451 * \endcode
452 *
453 * This option corresponds to the clang flag \c -fshow-source-location.
454 */
455 CXDiagnostic_DisplaySourceLocation = 0x01,
456
457 /**
458 * \brief If displaying the source-location information of the
459 * diagnostic, also include the column number.
460 *
461 * This option corresponds to the clang flag \c -fshow-column.
462 */
463 CXDiagnostic_DisplayColumn = 0x02,
464
465 /**
466 * \brief If displaying the source-location information of the
467 * diagnostic, also include information about source ranges in a
468 * machine-parsable format.
469 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000470 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000471 * \c -fdiagnostics-print-source-range-info.
472 */
473 CXDiagnostic_DisplaySourceRanges = 0x04
474};
475
476/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000477 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000478 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000479 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000480 * the diagnostic according to the various options given. The
481 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000482 * options that most closely mimics the behavior of the clang compiler.
483 *
484 * \param Diagnostic The diagnostic to print.
485 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000486 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000487 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000488 *
489 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000490 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000491CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
492 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000493
494/**
495 * \brief Retrieve the set of display options most similar to the
496 * default behavior of the clang compiler.
497 *
498 * \returns A set of display options suitable for use with \c
499 * clang_displayDiagnostic().
500 */
501CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
502
503/**
504 * \brief Print a diagnostic to the given file.
505 */
506
507/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000508 * \brief Determine the severity of the given diagnostic.
509 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000510CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000511clang_getDiagnosticSeverity(CXDiagnostic);
512
513/**
514 * \brief Retrieve the source location of the given diagnostic.
515 *
516 * This location is where Clang would print the caret ('^') when
517 * displaying the diagnostic on the command line.
518 */
519CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
520
521/**
522 * \brief Retrieve the text of the given diagnostic.
523 */
524CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000525
526/**
527 * \brief Determine the number of source ranges associated with the given
528 * diagnostic.
529 */
530CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000531
Douglas Gregor5352ac02010-01-28 00:27:43 +0000532/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000533 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000534 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000535 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000536 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000537 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000538 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000539 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000540 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000541 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000542 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000543 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000544 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000545CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000546 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000547
548/**
549 * \brief Determine the number of fix-it hints associated with the
550 * given diagnostic.
551 */
552CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
553
554/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000555 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000556 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000557 * Fix-its are described in terms of a source range whose contents
558 * should be replaced by a string. This approach generalizes over
559 * three kinds of operations: removal of source code (the range covers
560 * the code to be removed and the replacement string is empty),
561 * replacement of source code (the range covers the code to be
562 * replaced and the replacement string provides the new code), and
563 * insertion (both the start and end of the range point at the
564 * insertion location, and the replacement string provides the text to
565 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000566 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000567 * \param Diagnostic The diagnostic whose fix-its are being queried.
568 *
569 * \param FixIt The zero-based index of the fix-it.
570 *
571 * \param ReplacementRange The source range whose contents will be
572 * replaced with the returned replacement string. Note that source
573 * ranges are half-open ranges [a, b), so the source code should be
574 * replaced from a and up to (but not including) b.
575 *
576 * \returns A string containing text that should be replace the source
577 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000578 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000579CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000580 unsigned FixIt,
581 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000582
583/**
584 * @}
585 */
586
587/**
588 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
589 *
590 * The routines in this group provide the ability to create and destroy
591 * translation units from files, either by parsing the contents of the files or
592 * by reading in a serialized representation of a translation unit.
593 *
594 * @{
595 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000596
Douglas Gregor5352ac02010-01-28 00:27:43 +0000597/**
598 * \brief Get the original translation unit source file name.
599 */
600CINDEX_LINKAGE CXString
601clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
602
603/**
604 * \brief Return the CXTranslationUnit for a given source file and the provided
605 * command line arguments one would pass to the compiler.
606 *
607 * Note: The 'source_filename' argument is optional. If the caller provides a
608 * NULL pointer, the name of the source file is expected to reside in the
609 * specified command line arguments.
610 *
611 * Note: When encountered in 'clang_command_line_args', the following options
612 * are ignored:
613 *
614 * '-c'
615 * '-emit-ast'
616 * '-fsyntax-only'
617 * '-o <output file>' (both '-o' and '<output file>' are ignored)
618 *
619 *
620 * \param source_filename - The name of the source file to load, or NULL if the
621 * source file is included in clang_command_line_args.
622 *
623 * \param num_unsaved_files the number of unsaved file entries in \p
624 * unsaved_files.
625 *
626 * \param unsaved_files the files that have not yet been saved to disk
627 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000628 * those files. The contents and name of these files (as specified by
629 * CXUnsavedFile) are copied when necessary, so the client only needs to
630 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000631 *
632 * \param diag_callback callback function that will receive any diagnostics
633 * emitted while processing this source file. If NULL, diagnostics will be
634 * suppressed.
635 *
636 * \param diag_client_data client data that will be passed to the diagnostic
637 * callback function.
638 */
639CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
640 CXIndex CIdx,
641 const char *source_filename,
642 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000643 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000644 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000645 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000646
Douglas Gregor5352ac02010-01-28 00:27:43 +0000647/**
648 * \brief Create a translation unit from an AST file (-emit-ast).
649 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000650CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000651 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000652
Douglas Gregor44c181a2010-07-23 00:33:23 +0000653/**
654 * \brief Flags that control the creation of translation units.
655 *
656 * The enumerators in this enumeration type are meant to be bitwise
657 * ORed together to specify which options should be used when
658 * constructing the translation unit.
659 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000660enum CXTranslationUnit_Flags {
661 /**
662 * \brief Used to indicate that no special translation-unit options are
663 * needed.
664 */
665 CXTranslationUnit_None = 0x0,
666
667 /**
668 * \brief Used to indicate that the parser should construct a "detailed"
669 * preprocessing record, including all macro definitions and instantiations.
670 *
671 * Constructing a detailed preprocessing record requires more memory
672 * and time to parse, since the information contained in the record
673 * is usually not retained. However, it can be useful for
674 * applications that require more detailed information about the
675 * behavior of the preprocessor.
676 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000677 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
678
679 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000680 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000681 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000682 * When a translation unit is considered "incomplete", semantic
683 * analysis that is typically performed at the end of the
684 * translation unit will be suppressed. For example, this suppresses
685 * the completion of tentative declarations in C and of
686 * instantiation of implicitly-instantiation function templates in
687 * C++. This option is typically used when parsing a header with the
688 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000689 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000690 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000691
692 /**
693 * \brief Used to indicate that the translation unit should be built with an
694 * implicit precompiled header for the preamble.
695 *
696 * An implicit precompiled header is used as an optimization when a
697 * particular translation unit is likely to be reparsed many times
698 * when the sources aren't changing that often. In this case, an
699 * implicit precompiled header will be built containing all of the
700 * initial includes at the top of the main file (what we refer to as
701 * the "preamble" of the file). In subsequent parses, if the
702 * preamble or the files in it have not changed, \c
703 * clang_reparseTranslationUnit() will re-use the implicit
704 * precompiled header to improve parsing performance.
705 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000706 CXTranslationUnit_PrecompiledPreamble = 0x04,
707
708 /**
709 * \brief Used to indicate that the translation unit should cache some
710 * code-completion results with each reparse of the source file.
711 *
712 * Caching of code-completion results is a performance optimization that
713 * introduces some overhead to reparsing but improves the performance of
714 * code-completion operations.
715 */
Douglas Gregor99ba2022010-10-27 17:24:53 +0000716 CXTranslationUnit_CacheCompletionResults = 0x08,
717 /**
718 * \brief Enable precompiled preambles in C++.
719 *
720 * Note: this is a *temporary* option that is available only while
721 * we are testing C++ precompiled preamble support.
722 */
723 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
724
725 /**
726 * \brief Enabled chained precompiled preambles in C++.
727 *
728 * Note: this is a *temporary* option that is available only while
729 * we are testing C++ precompiled preamble support.
730 */
731 CXTranslationUnit_CXXChainedPCH = 0x20
Douglas Gregor5a430212010-07-21 18:52:53 +0000732};
733
734/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000735 * \brief Returns the set of flags that is suitable for parsing a translation
736 * unit that is being edited.
737 *
738 * The set of flags returned provide options for \c clang_parseTranslationUnit()
739 * to indicate that the translation unit is likely to be reparsed many times,
740 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
741 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
742 * set contains an unspecified set of optimizations (e.g., the precompiled
743 * preamble) geared toward improving the performance of these routines. The
744 * set of optimizations enabled may change from one version to the next.
745 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000746CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000747
748/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000749 * \brief Parse the given source file and the translation unit corresponding
750 * to that file.
751 *
752 * This routine is the main entry point for the Clang C API, providing the
753 * ability to parse a source file into a translation unit that can then be
754 * queried by other functions in the API. This routine accepts a set of
755 * command-line arguments so that the compilation can be configured in the same
756 * way that the compiler is configured on the command line.
757 *
758 * \param CIdx The index object with which the translation unit will be
759 * associated.
760 *
761 * \param source_filename The name of the source file to load, or NULL if the
762 * source file is included in \p clang_command_line_args.
763 *
764 * \param command_line_args The command-line arguments that would be
765 * passed to the \c clang executable if it were being invoked out-of-process.
766 * These command-line options will be parsed and will affect how the translation
767 * unit is parsed. Note that the following options are ignored: '-c',
768 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
769 *
770 * \param num_command_line_args The number of command-line arguments in
771 * \p command_line_args.
772 *
773 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000774 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000775 * those files. The contents and name of these files (as specified by
776 * CXUnsavedFile) are copied when necessary, so the client only needs to
777 * guarantee their validity until the call to this function returns.
778 *
779 * \param num_unsaved_files the number of unsaved file entries in \p
780 * unsaved_files.
781 *
782 * \param options A bitmask of options that affects how the translation unit
783 * is managed but not its compilation. This should be a bitwise OR of the
784 * CXTranslationUnit_XXX flags.
785 *
786 * \returns A new translation unit describing the parsed code and containing
787 * any diagnostics produced by the compiler. If there is a failure from which
788 * the compiler cannot recover, returns NULL.
789 */
790CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
791 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000792 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000793 int num_command_line_args,
794 struct CXUnsavedFile *unsaved_files,
795 unsigned num_unsaved_files,
796 unsigned options);
797
Douglas Gregor5352ac02010-01-28 00:27:43 +0000798/**
Douglas Gregor19998442010-08-13 15:35:05 +0000799 * \brief Flags that control how translation units are saved.
800 *
801 * The enumerators in this enumeration type are meant to be bitwise
802 * ORed together to specify which options should be used when
803 * saving the translation unit.
804 */
805enum CXSaveTranslationUnit_Flags {
806 /**
807 * \brief Used to indicate that no special saving options are needed.
808 */
809 CXSaveTranslationUnit_None = 0x0
810};
811
812/**
813 * \brief Returns the set of flags that is suitable for saving a translation
814 * unit.
815 *
816 * The set of flags returned provide options for
817 * \c clang_saveTranslationUnit() by default. The returned flag
818 * set contains an unspecified set of options that save translation units with
819 * the most commonly-requested data.
820 */
821CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
822
823/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000824 * \brief Saves a translation unit into a serialized representation of
825 * that translation unit on disk.
826 *
827 * Any translation unit that was parsed without error can be saved
828 * into a file. The translation unit can then be deserialized into a
829 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
830 * if it is an incomplete translation unit that corresponds to a
831 * header, used as a precompiled header when parsing other translation
832 * units.
833 *
834 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +0000835 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000836 * \param FileName The file to which the translation unit will be saved.
837 *
Douglas Gregor19998442010-08-13 15:35:05 +0000838 * \param options A bitmask of options that affects how the translation unit
839 * is saved. This should be a bitwise OR of the
840 * CXSaveTranslationUnit_XXX flags.
841 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000842 * \returns Zero if the translation unit was saved successfully, a
843 * non-zero value otherwise.
844 */
845CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +0000846 const char *FileName,
847 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000848
849/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000850 * \brief Destroy the specified CXTranslationUnit object.
851 */
852CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000853
Douglas Gregor5352ac02010-01-28 00:27:43 +0000854/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000855 * \brief Flags that control the reparsing of translation units.
856 *
857 * The enumerators in this enumeration type are meant to be bitwise
858 * ORed together to specify which options should be used when
859 * reparsing the translation unit.
860 */
861enum CXReparse_Flags {
862 /**
863 * \brief Used to indicate that no special reparsing options are needed.
864 */
865 CXReparse_None = 0x0
866};
867
868/**
869 * \brief Returns the set of flags that is suitable for reparsing a translation
870 * unit.
871 *
872 * The set of flags returned provide options for
873 * \c clang_reparseTranslationUnit() by default. The returned flag
874 * set contains an unspecified set of optimizations geared toward common uses
875 * of reparsing. The set of optimizations enabled may change from one version
876 * to the next.
877 */
878CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
879
880/**
Douglas Gregorabc563f2010-07-19 21:46:24 +0000881 * \brief Reparse the source files that produced this translation unit.
882 *
883 * This routine can be used to re-parse the source files that originally
884 * created the given translation unit, for example because those source files
885 * have changed (either on disk or as passed via \p unsaved_files). The
886 * source code will be reparsed with the same command-line options as it
887 * was originally parsed.
888 *
889 * Reparsing a translation unit invalidates all cursors and source locations
890 * that refer into that translation unit. This makes reparsing a translation
891 * unit semantically equivalent to destroying the translation unit and then
892 * creating a new translation unit with the same command-line arguments.
893 * However, it may be more efficient to reparse a translation
894 * unit using this routine.
895 *
896 * \param TU The translation unit whose contents will be re-parsed. The
897 * translation unit must originally have been built with
898 * \c clang_createTranslationUnitFromSourceFile().
899 *
900 * \param num_unsaved_files The number of unsaved file entries in \p
901 * unsaved_files.
902 *
903 * \param unsaved_files The files that have not yet been saved to disk
904 * but may be required for parsing, including the contents of
905 * 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 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000909 * \param options A bitset of options composed of the flags in CXReparse_Flags.
910 * The function \c clang_defaultReparseOptions() produces a default set of
911 * options recommended for most uses, based on the translation unit.
912 *
Douglas Gregorabc563f2010-07-19 21:46:24 +0000913 * \returns 0 if the sources could be reparsed. A non-zero value will be
914 * returned if reparsing was impossible, such that the translation unit is
915 * invalid. In such cases, the only valid call for \p TU is
916 * \c clang_disposeTranslationUnit(TU).
917 */
918CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
919 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000920 struct CXUnsavedFile *unsaved_files,
921 unsigned options);
Douglas Gregorabc563f2010-07-19 21:46:24 +0000922
923/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000924 * @}
925 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000926
Douglas Gregor5352ac02010-01-28 00:27:43 +0000927/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000928 * \brief Describes the kind of entity that a cursor refers to.
929 */
930enum CXCursorKind {
931 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000932 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000933 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000934 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000935 *
936 * Unexposed declarations have the same operations as any other kind
937 * of declaration; one can extract their location information,
938 * spelling, find their definitions, etc. However, the specific kind
939 * of the declaration is not reported.
940 */
941 CXCursor_UnexposedDecl = 1,
942 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000943 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000944 /** \brief A C or C++ union. */
945 CXCursor_UnionDecl = 3,
946 /** \brief A C++ class. */
947 CXCursor_ClassDecl = 4,
948 /** \brief An enumeration. */
949 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000950 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000951 * \brief A field (in C) or non-static data member (in C++) in a
952 * struct, union, or C++ class.
953 */
954 CXCursor_FieldDecl = 6,
955 /** \brief An enumerator constant. */
956 CXCursor_EnumConstantDecl = 7,
957 /** \brief A function. */
958 CXCursor_FunctionDecl = 8,
959 /** \brief A variable. */
960 CXCursor_VarDecl = 9,
961 /** \brief A function or method parameter. */
962 CXCursor_ParmDecl = 10,
963 /** \brief An Objective-C @interface. */
964 CXCursor_ObjCInterfaceDecl = 11,
965 /** \brief An Objective-C @interface for a category. */
966 CXCursor_ObjCCategoryDecl = 12,
967 /** \brief An Objective-C @protocol declaration. */
968 CXCursor_ObjCProtocolDecl = 13,
969 /** \brief An Objective-C @property declaration. */
970 CXCursor_ObjCPropertyDecl = 14,
971 /** \brief An Objective-C instance variable. */
972 CXCursor_ObjCIvarDecl = 15,
973 /** \brief An Objective-C instance method. */
974 CXCursor_ObjCInstanceMethodDecl = 16,
975 /** \brief An Objective-C class method. */
976 CXCursor_ObjCClassMethodDecl = 17,
977 /** \brief An Objective-C @implementation. */
978 CXCursor_ObjCImplementationDecl = 18,
979 /** \brief An Objective-C @implementation for a category. */
980 CXCursor_ObjCCategoryImplDecl = 19,
981 /** \brief A typedef */
982 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +0000983 /** \brief A C++ class method. */
984 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +0000985 /** \brief A C++ namespace. */
986 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +0000987 /** \brief A linkage specification, e.g. 'extern "C"'. */
988 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +0000989 /** \brief A C++ constructor. */
990 CXCursor_Constructor = 24,
991 /** \brief A C++ destructor. */
992 CXCursor_Destructor = 25,
993 /** \brief A C++ conversion function. */
994 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000995 /** \brief A C++ template type parameter. */
996 CXCursor_TemplateTypeParameter = 27,
997 /** \brief A C++ non-type template parameter. */
998 CXCursor_NonTypeTemplateParameter = 28,
999 /** \brief A C++ template template parameter. */
1000 CXCursor_TemplateTemplateParameter = 29,
1001 /** \brief A C++ function template. */
1002 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001003 /** \brief A C++ class template. */
1004 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001005 /** \brief A C++ class template partial specialization. */
1006 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001007 /** \brief A C++ namespace alias declaration. */
1008 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001009 /** \brief A C++ using directive. */
1010 CXCursor_UsingDirective = 34,
Douglas Gregor7e242562010-09-01 19:52:22 +00001011 /** \brief A using declaration. */
1012 CXCursor_UsingDeclaration = 35,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001013 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor7e242562010-09-01 19:52:22 +00001014 CXCursor_LastDecl = CXCursor_UsingDeclaration,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001015
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001016 /* References */
1017 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001018 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001019 CXCursor_ObjCProtocolRef = 41,
1020 CXCursor_ObjCClassRef = 42,
1021 /**
1022 * \brief A reference to a type declaration.
1023 *
1024 * A type reference occurs anywhere where a type is named but not
1025 * declared. For example, given:
1026 *
1027 * \code
1028 * typedef unsigned size_type;
1029 * size_type size;
1030 * \endcode
1031 *
1032 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1033 * while the type of the variable "size" is referenced. The cursor
1034 * referenced by the type of size is the typedef for size_type.
1035 */
1036 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001037 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001038 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001039 * \brief A reference to a class template, function template, template
1040 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001041 */
1042 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001043 /**
1044 * \brief A reference to a namespace or namespace alias.
1045 */
1046 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001047 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001048 * \brief A reference to a member of a struct, union, or class that occurs in
1049 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001050 */
1051 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001052 /**
1053 * \brief A reference to a labeled statement.
1054 *
1055 * This cursor kind is used to describe the jump to "start_over" in the
1056 * goto statement in the following example:
1057 *
1058 * \code
1059 * start_over:
1060 * ++counter;
1061 *
1062 * goto start_over;
1063 * \endcode
1064 *
1065 * A label reference cursor refers to a label statement.
1066 */
1067 CXCursor_LabelRef = 48,
1068
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001069 /**
1070 * \brief A reference to a set of overloaded functions or function templates
1071 * that has not yet been resolved to a specific function or function template.
1072 *
1073 * An overloaded declaration reference cursor occurs in C++ templates where
1074 * a dependent name refers to a function. For example:
1075 *
1076 * \code
1077 * template<typename T> void swap(T&, T&);
1078 *
1079 * struct X { ... };
1080 * void swap(X&, X&);
1081 *
1082 * template<typename T>
1083 * void reverse(T* first, T* last) {
1084 * while (first < last - 1) {
1085 * swap(*first, *--last);
1086 * ++first;
1087 * }
1088 * }
1089 *
1090 * struct Y { };
1091 * void swap(Y&, Y&);
1092 * \endcode
1093 *
1094 * Here, the identifier "swap" is associated with an overloaded declaration
1095 * reference. In the template definition, "swap" refers to either of the two
1096 * "swap" functions declared above, so both results will be available. At
1097 * instantiation time, "swap" may also refer to other functions found via
1098 * argument-dependent lookup (e.g., the "swap" function at the end of the
1099 * example).
1100 *
1101 * The functions \c clang_getNumOverloadedDecls() and
1102 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1103 * referenced by this cursor.
1104 */
1105 CXCursor_OverloadedDeclRef = 49,
1106
1107 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001108
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001109 /* Error conditions */
1110 CXCursor_FirstInvalid = 70,
1111 CXCursor_InvalidFile = 70,
1112 CXCursor_NoDeclFound = 71,
1113 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001114 CXCursor_InvalidCode = 73,
1115 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001116
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001117 /* Expressions */
1118 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001119
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001120 /**
1121 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001122 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001123 *
1124 * Unexposed expressions have the same operations as any other kind
1125 * of expression; one can extract their location information,
1126 * spelling, children, etc. However, the specific kind of the
1127 * expression is not reported.
1128 */
1129 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001130
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001131 /**
1132 * \brief An expression that refers to some value declaration, such
1133 * as a function, varible, or enumerator.
1134 */
1135 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001136
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001137 /**
1138 * \brief An expression that refers to a member of a struct, union,
1139 * class, Objective-C class, etc.
1140 */
1141 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001142
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001143 /** \brief An expression that calls a function. */
1144 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001145
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001146 /** \brief An expression that sends a message to an Objective-C
1147 object or class. */
1148 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001149
1150 /** \brief An expression that represents a block literal. */
1151 CXCursor_BlockExpr = 105,
1152
1153 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001154
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001155 /* Statements */
1156 CXCursor_FirstStmt = 200,
1157 /**
1158 * \brief A statement whose specific kind is not exposed via this
1159 * interface.
1160 *
1161 * Unexposed statements have the same operations as any other kind of
1162 * statement; one can extract their location information, spelling,
1163 * children, etc. However, the specific kind of the statement is not
1164 * reported.
1165 */
1166 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001167
1168 /** \brief A labelled statement in a function.
1169 *
1170 * This cursor kind is used to describe the "start_over:" label statement in
1171 * the following example:
1172 *
1173 * \code
1174 * start_over:
1175 * ++counter;
1176 * \endcode
1177 *
1178 */
1179 CXCursor_LabelStmt = 201,
1180
1181 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001182
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001183 /**
1184 * \brief Cursor that represents the translation unit itself.
1185 *
1186 * The translation unit cursor exists primarily to act as the root
1187 * cursor for traversing the contents of a translation unit.
1188 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001189 CXCursor_TranslationUnit = 300,
1190
1191 /* Attributes */
1192 CXCursor_FirstAttr = 400,
1193 /**
1194 * \brief An attribute whose specific kind is not exposed via this
1195 * interface.
1196 */
1197 CXCursor_UnexposedAttr = 400,
1198
1199 CXCursor_IBActionAttr = 401,
1200 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001201 CXCursor_IBOutletCollectionAttr = 403,
1202 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001203
1204 /* Preprocessing */
1205 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001206 CXCursor_MacroDefinition = 501,
1207 CXCursor_MacroInstantiation = 502,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001208 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001209 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001210 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001211};
1212
1213/**
1214 * \brief A cursor representing some element in the abstract syntax tree for
1215 * a translation unit.
1216 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001217 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001218 * program--declaration, statements, expressions, references to declarations,
1219 * etc.--under a single "cursor" abstraction with a common set of operations.
1220 * Common operation for a cursor include: getting the physical location in
1221 * a source file where the cursor points, getting the name associated with a
1222 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1223 *
1224 * Cursors can be produced in two specific ways.
1225 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1226 * from which one can use clang_visitChildren() to explore the rest of the
1227 * translation unit. clang_getCursor() maps from a physical source location
1228 * to the entity that resides at that location, allowing one to map from the
1229 * source code into the AST.
1230 */
1231typedef struct {
1232 enum CXCursorKind kind;
1233 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001234} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001235
1236/**
1237 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1238 *
1239 * @{
1240 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001241
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001242/**
1243 * \brief Retrieve the NULL cursor, which represents no entity.
1244 */
1245CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001246
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001247/**
1248 * \brief Retrieve the cursor that represents the given translation unit.
1249 *
1250 * The translation unit cursor can be used to start traversing the
1251 * various declarations within the given translation unit.
1252 */
1253CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1254
1255/**
1256 * \brief Determine whether two cursors are equivalent.
1257 */
1258CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001259
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001260/**
1261 * \brief Retrieve the kind of the given cursor.
1262 */
1263CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1264
1265/**
1266 * \brief Determine whether the given cursor kind represents a declaration.
1267 */
1268CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1269
1270/**
1271 * \brief Determine whether the given cursor kind represents a simple
1272 * reference.
1273 *
1274 * Note that other kinds of cursors (such as expressions) can also refer to
1275 * other cursors. Use clang_getCursorReferenced() to determine whether a
1276 * particular cursor refers to another entity.
1277 */
1278CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1279
1280/**
1281 * \brief Determine whether the given cursor kind represents an expression.
1282 */
1283CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1284
1285/**
1286 * \brief Determine whether the given cursor kind represents a statement.
1287 */
1288CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1289
1290/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001291 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001292 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001293 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001294CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1295
1296/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001297 * \brief Determine whether the given cursor kind represents a translation
1298 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001299 */
1300CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001301
Ted Kremenekad6eff62010-03-08 21:17:29 +00001302/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001303 * \brief Determine whether the given cursor represents a preprocessing
1304 * element, such as a preprocessor directive or macro instantiation.
1305 */
1306CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1307
1308/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001309 * \brief Determine whether the given cursor represents a currently
1310 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1311 */
1312CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1313
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001314/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001315 * \brief Describe the linkage of the entity referred to by a cursor.
1316 */
1317enum CXLinkageKind {
1318 /** \brief This value indicates that no linkage information is available
1319 * for a provided CXCursor. */
1320 CXLinkage_Invalid,
1321 /**
1322 * \brief This is the linkage for variables, parameters, and so on that
1323 * have automatic storage. This covers normal (non-extern) local variables.
1324 */
1325 CXLinkage_NoLinkage,
1326 /** \brief This is the linkage for static variables and static functions. */
1327 CXLinkage_Internal,
1328 /** \brief This is the linkage for entities with external linkage that live
1329 * in C++ anonymous namespaces.*/
1330 CXLinkage_UniqueExternal,
1331 /** \brief This is the linkage for entities with true, external linkage. */
1332 CXLinkage_External
1333};
1334
1335/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001336 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001337 */
1338CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1339
1340/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001341 * \brief Determine the availability of the entity that this cursor refers to.
1342 *
1343 * \param cursor The cursor to query.
1344 *
1345 * \returns The availability of the cursor.
1346 */
1347CINDEX_LINKAGE enum CXAvailabilityKind
1348clang_getCursorAvailability(CXCursor cursor);
1349
1350/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001351 * \brief Describe the "language" of the entity referred to by a cursor.
1352 */
1353CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001354 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001355 CXLanguage_C,
1356 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001357 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001358};
1359
1360/**
1361 * \brief Determine the "language" of the entity referred to by a given cursor.
1362 */
1363CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1364
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001365
1366/**
1367 * \brief Determine the semantic parent of the given cursor.
1368 *
1369 * The semantic parent of a cursor is the cursor that semantically contains
1370 * the given \p cursor. For many declarations, the lexical and semantic parents
1371 * are equivalent (the lexical parent is returned by
1372 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1373 * definitions are provided out-of-line. For example:
1374 *
1375 * \code
1376 * class C {
1377 * void f();
1378 * };
1379 *
1380 * void C::f() { }
1381 * \endcode
1382 *
1383 * In the out-of-line definition of \c C::f, the semantic parent is the
1384 * the class \c C, of which this function is a member. The lexical parent is
1385 * the place where the declaration actually occurs in the source code; in this
1386 * case, the definition occurs in the translation unit. In general, the
1387 * lexical parent for a given entity can change without affecting the semantics
1388 * of the program, and the lexical parent of different declarations of the
1389 * same entity may be different. Changing the semantic parent of a declaration,
1390 * on the other hand, can have a major impact on semantics, and redeclarations
1391 * of a particular entity should all have the same semantic context.
1392 *
1393 * In the example above, both declarations of \c C::f have \c C as their
1394 * semantic context, while the lexical context of the first \c C::f is \c C
1395 * and the lexical context of the second \c C::f is the translation unit.
1396 */
1397CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1398
1399/**
1400 * \brief Determine the lexical parent of the given cursor.
1401 *
1402 * The lexical parent of a cursor is the cursor in which the given \p cursor
1403 * was actually written. For many declarations, the lexical and semantic parents
1404 * are equivalent (the semantic parent is returned by
1405 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1406 * definitions are provided out-of-line. For example:
1407 *
1408 * \code
1409 * class C {
1410 * void f();
1411 * };
1412 *
1413 * void C::f() { }
1414 * \endcode
1415 *
1416 * In the out-of-line definition of \c C::f, the semantic parent is the
1417 * the class \c C, of which this function is a member. The lexical parent is
1418 * the place where the declaration actually occurs in the source code; in this
1419 * case, the definition occurs in the translation unit. In general, the
1420 * lexical parent for a given entity can change without affecting the semantics
1421 * of the program, and the lexical parent of different declarations of the
1422 * same entity may be different. Changing the semantic parent of a declaration,
1423 * on the other hand, can have a major impact on semantics, and redeclarations
1424 * of a particular entity should all have the same semantic context.
1425 *
1426 * In the example above, both declarations of \c C::f have \c C as their
1427 * semantic context, while the lexical context of the first \c C::f is \c C
1428 * and the lexical context of the second \c C::f is the translation unit.
1429 */
1430CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001431
1432/**
1433 * \brief Determine the set of methods that are overridden by the given
1434 * method.
1435 *
1436 * In both Objective-C and C++, a method (aka virtual member function,
1437 * in C++) can override a virtual method in a base class. For
1438 * Objective-C, a method is said to override any method in the class's
1439 * interface (if we're coming from an implementation), its protocols,
1440 * or its categories, that has the same selector and is of the same
1441 * kind (class or instance). If no such method exists, the search
1442 * continues to the class's superclass, its protocols, and its
1443 * categories, and so on.
1444 *
1445 * For C++, a virtual member function overrides any virtual member
1446 * function with the same signature that occurs in its base
1447 * classes. With multiple inheritance, a virtual member function can
1448 * override several virtual member functions coming from different
1449 * base classes.
1450 *
1451 * In all cases, this function determines the immediate overridden
1452 * method, rather than all of the overridden methods. For example, if
1453 * a method is originally declared in a class A, then overridden in B
1454 * (which in inherits from A) and also in C (which inherited from B),
1455 * then the only overridden method returned from this function when
1456 * invoked on C's method will be B's method. The client may then
1457 * invoke this function again, given the previously-found overridden
1458 * methods, to map out the complete method-override set.
1459 *
1460 * \param cursor A cursor representing an Objective-C or C++
1461 * method. This routine will compute the set of methods that this
1462 * method overrides.
1463 *
1464 * \param overridden A pointer whose pointee will be replaced with a
1465 * pointer to an array of cursors, representing the set of overridden
1466 * methods. If there are no overridden methods, the pointee will be
1467 * set to NULL. The pointee must be freed via a call to
1468 * \c clang_disposeOverriddenCursors().
1469 *
1470 * \param num_overridden A pointer to the number of overridden
1471 * functions, will be set to the number of overridden functions in the
1472 * array pointed to by \p overridden.
1473 */
1474CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1475 CXCursor **overridden,
1476 unsigned *num_overridden);
1477
1478/**
1479 * \brief Free the set of overridden cursors returned by \c
1480 * clang_getOverriddenCursors().
1481 */
1482CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1483
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001484/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001485 * \brief Retrieve the file that is included by the given inclusion directive
1486 * cursor.
1487 */
1488CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1489
1490/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001491 * @}
1492 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001493
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001494/**
1495 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1496 *
1497 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1498 * routines help map between cursors and the physical locations where the
1499 * described entities occur in the source code. The mapping is provided in
1500 * both directions, so one can map from source code to the AST and back.
1501 *
1502 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001503 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001504
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001505/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001506 * \brief Map a source location to the cursor that describes the entity at that
1507 * location in the source code.
1508 *
1509 * clang_getCursor() maps an arbitrary source location within a translation
1510 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001511 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001512 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001513 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001514 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1515 * will return a cursor referring to the "+" expression.
1516 *
1517 * \returns a cursor representing the entity at the given source location, or
1518 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001519 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001520CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001521
Douglas Gregor98258af2010-01-18 22:46:11 +00001522/**
1523 * \brief Retrieve the physical location of the source constructor referenced
1524 * by the given cursor.
1525 *
1526 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001527 * declaration, where the name of that declaration would occur if it is
1528 * unnamed, or some keyword that introduces that particular declaration.
1529 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001530 * source code.
1531 */
1532CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001533
Douglas Gregorb6998662010-01-19 19:34:47 +00001534/**
1535 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001536 * the given cursor.
1537 *
1538 * The extent of a cursor starts with the file/line/column pointing at the
1539 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001540 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001541 * declaration, the extent covers the declaration itself. For a reference,
1542 * the extent covers the location of the reference (e.g., where the referenced
1543 * entity was actually used).
1544 */
1545CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001546
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001547/**
1548 * @}
1549 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001550
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001551/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001552 * \defgroup CINDEX_TYPES Type information for CXCursors
1553 *
1554 * @{
1555 */
1556
1557/**
1558 * \brief Describes the kind of type
1559 */
1560enum CXTypeKind {
1561 /**
1562 * \brief Reprents an invalid type (e.g., where no type is available).
1563 */
1564 CXType_Invalid = 0,
1565
1566 /**
1567 * \brief A type whose specific kind is not exposed via this
1568 * interface.
1569 */
1570 CXType_Unexposed = 1,
1571
1572 /* Builtin types */
1573 CXType_Void = 2,
1574 CXType_Bool = 3,
1575 CXType_Char_U = 4,
1576 CXType_UChar = 5,
1577 CXType_Char16 = 6,
1578 CXType_Char32 = 7,
1579 CXType_UShort = 8,
1580 CXType_UInt = 9,
1581 CXType_ULong = 10,
1582 CXType_ULongLong = 11,
1583 CXType_UInt128 = 12,
1584 CXType_Char_S = 13,
1585 CXType_SChar = 14,
1586 CXType_WChar = 15,
1587 CXType_Short = 16,
1588 CXType_Int = 17,
1589 CXType_Long = 18,
1590 CXType_LongLong = 19,
1591 CXType_Int128 = 20,
1592 CXType_Float = 21,
1593 CXType_Double = 22,
1594 CXType_LongDouble = 23,
1595 CXType_NullPtr = 24,
1596 CXType_Overload = 25,
1597 CXType_Dependent = 26,
1598 CXType_ObjCId = 27,
1599 CXType_ObjCClass = 28,
1600 CXType_ObjCSel = 29,
1601 CXType_FirstBuiltin = CXType_Void,
1602 CXType_LastBuiltin = CXType_ObjCSel,
1603
1604 CXType_Complex = 100,
1605 CXType_Pointer = 101,
1606 CXType_BlockPointer = 102,
1607 CXType_LValueReference = 103,
1608 CXType_RValueReference = 104,
1609 CXType_Record = 105,
1610 CXType_Enum = 106,
1611 CXType_Typedef = 107,
1612 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001613 CXType_ObjCObjectPointer = 109,
1614 CXType_FunctionNoProto = 110,
1615 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001616};
1617
1618/**
1619 * \brief The type of an element in the abstract syntax tree.
1620 *
1621 */
1622typedef struct {
1623 enum CXTypeKind kind;
1624 void *data[2];
1625} CXType;
1626
1627/**
1628 * \brief Retrieve the type of a CXCursor (if any).
1629 */
1630CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1631
1632/**
1633 * \determine Determine whether two CXTypes represent the same type.
1634 *
1635 * \returns non-zero if the CXTypes represent the same type and
1636 zero otherwise.
1637 */
1638CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1639
1640/**
1641 * \brief Return the canonical type for a CXType.
1642 *
1643 * Clang's type system explicitly models typedefs and all the ways
1644 * a specific type can be represented. The canonical type is the underlying
1645 * type with all the "sugar" removed. For example, if 'T' is a typedef
1646 * for 'int', the canonical type for 'T' would be 'int'.
1647 */
1648CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1649
1650/**
1651 * \brief For pointer types, returns the type of the pointee.
1652 *
1653 */
1654CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1655
1656/**
1657 * \brief Return the cursor for the declaration of the given type.
1658 */
1659CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1660
1661
1662/**
1663 * \brief Retrieve the spelling of a given CXTypeKind.
1664 */
1665CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1666
1667/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001668 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001669 */
1670CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1671
1672/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001673 * \brief Retrieve the result type associated with a given cursor. This only
1674 * returns a valid type of the cursor refers to a function or method.
1675 */
1676CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1677
1678/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001679 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1680 * otherwise.
1681 */
1682CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1683
1684/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001685 * \brief Returns 1 if the base class specified by the cursor with kind
1686 * CX_CXXBaseSpecifier is virtual.
1687 */
1688CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1689
1690/**
1691 * \brief Represents the C++ access control level to a base class for a
1692 * cursor with kind CX_CXXBaseSpecifier.
1693 */
1694enum CX_CXXAccessSpecifier {
1695 CX_CXXInvalidAccessSpecifier,
1696 CX_CXXPublic,
1697 CX_CXXProtected,
1698 CX_CXXPrivate
1699};
1700
1701/**
1702 * \brief Returns the access control level for the C++ base specifier
1703 * represented by a cursor with kind CX_CXXBaseSpecifier.
1704 */
1705CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
1706
1707/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001708 * \brief Determine the number of overloaded declarations referenced by a
1709 * \c CXCursor_OverloadedDeclRef cursor.
1710 *
1711 * \param cursor The cursor whose overloaded declarations are being queried.
1712 *
1713 * \returns The number of overloaded declarations referenced by \c cursor. If it
1714 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
1715 */
1716CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
1717
1718/**
1719 * \brief Retrieve a cursor for one of the overloaded declarations referenced
1720 * by a \c CXCursor_OverloadedDeclRef cursor.
1721 *
1722 * \param cursor The cursor whose overloaded declarations are being queried.
1723 *
1724 * \param index The zero-based index into the set of overloaded declarations in
1725 * the cursor.
1726 *
1727 * \returns A cursor representing the declaration referenced by the given
1728 * \c cursor at the specified \c index. If the cursor does not have an
1729 * associated set of overloaded declarations, or if the index is out of bounds,
1730 * returns \c clang_getNullCursor();
1731 */
1732CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
1733 unsigned index);
1734
1735/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001736 * @}
1737 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001738
1739/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00001740 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00001741 *
1742 * @{
1743 */
1744
1745
1746/**
1747 * \brief For cursors representing an iboutletcollection attribute,
1748 * this function returns the collection element type.
1749 *
1750 */
1751CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
1752
1753/**
1754 * @}
1755 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001756
1757/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001758 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
1759 *
1760 * These routines provide the ability to traverse the abstract syntax tree
1761 * using cursors.
1762 *
1763 * @{
1764 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001765
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001766/**
1767 * \brief Describes how the traversal of the children of a particular
1768 * cursor should proceed after visiting a particular child cursor.
1769 *
1770 * A value of this enumeration type should be returned by each
1771 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
1772 */
1773enum CXChildVisitResult {
1774 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001775 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001776 */
1777 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001778 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001779 * \brief Continues the cursor traversal with the next sibling of
1780 * the cursor just visited, without visiting its children.
1781 */
1782 CXChildVisit_Continue,
1783 /**
1784 * \brief Recursively traverse the children of this cursor, using
1785 * the same visitor and client data.
1786 */
1787 CXChildVisit_Recurse
1788};
1789
1790/**
1791 * \brief Visitor invoked for each cursor found by a traversal.
1792 *
1793 * This visitor function will be invoked for each cursor found by
1794 * clang_visitCursorChildren(). Its first argument is the cursor being
1795 * visited, its second argument is the parent visitor for that cursor,
1796 * and its third argument is the client data provided to
1797 * clang_visitCursorChildren().
1798 *
1799 * The visitor should return one of the \c CXChildVisitResult values
1800 * to direct clang_visitCursorChildren().
1801 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001802typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
1803 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001804 CXClientData client_data);
1805
1806/**
1807 * \brief Visit the children of a particular cursor.
1808 *
1809 * This function visits all the direct children of the given cursor,
1810 * invoking the given \p visitor function with the cursors of each
1811 * visited child. The traversal may be recursive, if the visitor returns
1812 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
1813 * the visitor returns \c CXChildVisit_Break.
1814 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001815 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00001816 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001817 * definition, have no children).
1818 *
1819 * \param visitor the visitor function that will be invoked for each
1820 * child of \p parent.
1821 *
1822 * \param client_data pointer data supplied by the client, which will
1823 * be passed to the visitor each time it is invoked.
1824 *
1825 * \returns a non-zero value if the traversal was terminated
1826 * prematurely by the visitor returning \c CXChildVisit_Break.
1827 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001828CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001829 CXCursorVisitor visitor,
1830 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00001831#ifdef __has_feature
1832# if __has_feature(blocks)
1833/**
1834 * \brief Visitor invoked for each cursor found by a traversal.
1835 *
1836 * This visitor block will be invoked for each cursor found by
1837 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
1838 * visited, its second argument is the parent visitor for that cursor.
1839 *
1840 * The visitor should return one of the \c CXChildVisitResult values
1841 * to direct clang_visitChildrenWithBlock().
1842 */
1843typedef enum CXChildVisitResult
1844 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
1845
1846/**
1847 * Visits the children of a cursor using the specified block. Behaves
1848 * identically to clang_visitChildren() in all other respects.
1849 */
1850unsigned clang_visitChildrenWithBlock(CXCursor parent,
1851 CXCursorVisitorBlock block);
1852# endif
1853#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001854
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001855/**
1856 * @}
1857 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001858
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001859/**
1860 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1861 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001862 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001863 * across translation units, by providing the names of the entities referenced
1864 * by cursors, follow reference cursors to the declarations they reference,
1865 * and associate declarations with their definitions.
1866 *
1867 * @{
1868 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001869
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001870/**
1871 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1872 * by the given cursor.
1873 *
1874 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1875 * entity (function, class, variable, etc.) within a program. USRs can be
1876 * compared across translation units to determine, e.g., when references in
1877 * one translation refer to an entity defined in another translation unit.
1878 */
1879CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1880
1881/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00001882 * \brief Construct a USR for a specified Objective-C class.
1883 */
1884CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
1885
1886/**
1887 * \brief Construct a USR for a specified Objective-C category.
1888 */
1889CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00001890 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001891 const char *category_name);
1892
1893/**
1894 * \brief Construct a USR for a specified Objective-C protocol.
1895 */
1896CINDEX_LINKAGE CXString
1897 clang_constructUSR_ObjCProtocol(const char *protocol_name);
1898
1899
1900/**
1901 * \brief Construct a USR for a specified Objective-C instance variable and
1902 * the USR for its containing class.
1903 */
1904CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
1905 CXString classUSR);
1906
1907/**
1908 * \brief Construct a USR for a specified Objective-C method and
1909 * the USR for its containing class.
1910 */
1911CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
1912 unsigned isInstanceMethod,
1913 CXString classUSR);
1914
1915/**
1916 * \brief Construct a USR for a specified Objective-C property and the USR
1917 * for its containing class.
1918 */
1919CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
1920 CXString classUSR);
1921
1922/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001923 * \brief Retrieve a name for the entity referenced by this cursor.
1924 */
1925CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1926
Douglas Gregor358559d2010-10-02 22:49:11 +00001927/**
1928 * \brief Retrieve the display name for the entity referenced by this cursor.
1929 *
1930 * The display name contains extra information that helps identify the cursor,
1931 * such as the parameters of a function or template or the arguments of a
1932 * class template specialization.
1933 */
1934CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
1935
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001936/** \brief For a cursor that is a reference, retrieve a cursor representing the
1937 * entity that it references.
1938 *
1939 * Reference cursors refer to other entities in the AST. For example, an
1940 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001941 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001942 * cursor for the superclass reference. If the input cursor is a declaration or
1943 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001944 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001945 */
1946CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001947
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001948/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001949 * \brief For a cursor that is either a reference to or a declaration
1950 * of some entity, retrieve a cursor that describes the definition of
1951 * that entity.
1952 *
1953 * Some entities can be declared multiple times within a translation
1954 * unit, but only one of those declarations can also be a
1955 * definition. For example, given:
1956 *
1957 * \code
1958 * int f(int, int);
1959 * int g(int x, int y) { return f(x, y); }
1960 * int f(int a, int b) { return a + b; }
1961 * int f(int, int);
1962 * \endcode
1963 *
1964 * there are three declarations of the function "f", but only the
1965 * second one is a definition. The clang_getCursorDefinition()
1966 * function will take any cursor pointing to a declaration of "f"
1967 * (the first or fourth lines of the example) or a cursor referenced
1968 * that uses "f" (the call to "f' inside "g") and will return a
1969 * declaration cursor pointing to the definition (the second "f"
1970 * declaration).
1971 *
1972 * If given a cursor for which there is no corresponding definition,
1973 * e.g., because there is no definition of that entity within this
1974 * translation unit, returns a NULL cursor.
1975 */
1976CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1977
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001978/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001979 * \brief Determine whether the declaration pointed to by this cursor
1980 * is also a definition of that entity.
1981 */
1982CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1983
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001984/**
1985 * @}
1986 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001987
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001988/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00001989 * \defgroup CINDEX_CPP C++ AST introspection
1990 *
1991 * The routines in this group provide access information in the ASTs specific
1992 * to C++ language features.
1993 *
1994 * @{
1995 */
1996
1997/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00001998 * \brief Determine if a C++ member function or member function template is
1999 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002000 */
2001CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2002
2003/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002004 * \brief Given a cursor that represents a template, determine
2005 * the cursor kind of the specializations would be generated by instantiating
2006 * the template.
2007 *
2008 * This routine can be used to determine what flavor of function template,
2009 * class template, or class template partial specialization is stored in the
2010 * cursor. For example, it can describe whether a class template cursor is
2011 * declared with "struct", "class" or "union".
2012 *
2013 * \param C The cursor to query. This cursor should represent a template
2014 * declaration.
2015 *
2016 * \returns The cursor kind of the specializations that would be generated
2017 * by instantiating the template \p C. If \p C is not a template, returns
2018 * \c CXCursor_NoDeclFound.
2019 */
2020CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2021
2022/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002023 * \brief Given a cursor that may represent a specialization or instantiation
2024 * of a template, retrieve the cursor that represents the template that it
2025 * specializes or from which it was instantiated.
2026 *
2027 * This routine determines the template involved both for explicit
2028 * specializations of templates and for implicit instantiations of the template,
2029 * both of which are referred to as "specializations". For a class template
2030 * specialization (e.g., \c std::vector<bool>), this routine will return
2031 * either the primary template (\c std::vector) or, if the specialization was
2032 * instantiated from a class template partial specialization, the class template
2033 * partial specialization. For a class template partial specialization and a
2034 * function template specialization (including instantiations), this
2035 * this routine will return the specialized template.
2036 *
2037 * For members of a class template (e.g., member functions, member classes, or
2038 * static data members), returns the specialized or instantiated member.
2039 * Although not strictly "templates" in the C++ language, members of class
2040 * templates have the same notions of specializations and instantiations that
2041 * templates do, so this routine treats them similarly.
2042 *
2043 * \param C A cursor that may be a specialization of a template or a member
2044 * of a template.
2045 *
2046 * \returns If the given cursor is a specialization or instantiation of a
2047 * template or a member thereof, the template or member that it specializes or
2048 * from which it was instantiated. Otherwise, returns a NULL cursor.
2049 */
2050CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
2051
2052/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002053 * @}
2054 */
2055
2056/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002057 * \defgroup CINDEX_LEX Token extraction and manipulation
2058 *
2059 * The routines in this group provide access to the tokens within a
2060 * translation unit, along with a semantic mapping of those tokens to
2061 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002062 *
2063 * @{
2064 */
2065
2066/**
2067 * \brief Describes a kind of token.
2068 */
2069typedef enum CXTokenKind {
2070 /**
2071 * \brief A token that contains some kind of punctuation.
2072 */
2073 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002074
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002075 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002076 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002077 */
2078 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002079
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002080 /**
2081 * \brief An identifier (that is not a keyword).
2082 */
2083 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002084
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002085 /**
2086 * \brief A numeric, string, or character literal.
2087 */
2088 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002089
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002090 /**
2091 * \brief A comment.
2092 */
2093 CXToken_Comment
2094} CXTokenKind;
2095
2096/**
2097 * \brief Describes a single preprocessing token.
2098 */
2099typedef struct {
2100 unsigned int_data[4];
2101 void *ptr_data;
2102} CXToken;
2103
2104/**
2105 * \brief Determine the kind of the given token.
2106 */
2107CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002108
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002109/**
2110 * \brief Determine the spelling of the given token.
2111 *
2112 * The spelling of a token is the textual representation of that token, e.g.,
2113 * the text of an identifier or keyword.
2114 */
2115CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002116
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002117/**
2118 * \brief Retrieve the source location of the given token.
2119 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002120CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002121 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002122
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002123/**
2124 * \brief Retrieve a source range that covers the given token.
2125 */
2126CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2127
2128/**
2129 * \brief Tokenize the source code described by the given range into raw
2130 * lexical tokens.
2131 *
2132 * \param TU the translation unit whose text is being tokenized.
2133 *
2134 * \param Range the source range in which text should be tokenized. All of the
2135 * tokens produced by tokenization will fall within this source range,
2136 *
2137 * \param Tokens this pointer will be set to point to the array of tokens
2138 * that occur within the given source range. The returned pointer must be
2139 * freed with clang_disposeTokens() before the translation unit is destroyed.
2140 *
2141 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2142 * array.
2143 *
2144 */
2145CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2146 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002147
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002148/**
2149 * \brief Annotate the given set of tokens by providing cursors for each token
2150 * that can be mapped to a specific entity within the abstract syntax tree.
2151 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002152 * This token-annotation routine is equivalent to invoking
2153 * clang_getCursor() for the source locations of each of the
2154 * tokens. The cursors provided are filtered, so that only those
2155 * cursors that have a direct correspondence to the token are
2156 * accepted. For example, given a function call \c f(x),
2157 * clang_getCursor() would provide the following cursors:
2158 *
2159 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2160 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2161 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2162 *
2163 * Only the first and last of these cursors will occur within the
2164 * annotate, since the tokens "f" and "x' directly refer to a function
2165 * and a variable, respectively, but the parentheses are just a small
2166 * part of the full syntax of the function call expression, which is
2167 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002168 *
2169 * \param TU the translation unit that owns the given tokens.
2170 *
2171 * \param Tokens the set of tokens to annotate.
2172 *
2173 * \param NumTokens the number of tokens in \p Tokens.
2174 *
2175 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2176 * replaced with the cursors corresponding to each token.
2177 */
2178CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2179 CXToken *Tokens, unsigned NumTokens,
2180 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002181
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002182/**
2183 * \brief Free the given set of tokens.
2184 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002185CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002186 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002187
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002188/**
2189 * @}
2190 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002191
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002192/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002193 * \defgroup CINDEX_DEBUG Debugging facilities
2194 *
2195 * These routines are used for testing and debugging, only, and should not
2196 * be relied upon.
2197 *
2198 * @{
2199 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002200
Steve Naroff4ade6d62009-09-23 17:52:52 +00002201/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002202CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002203CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2204 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002205 const char **endBuf,
2206 unsigned *startLine,
2207 unsigned *startColumn,
2208 unsigned *endLine,
2209 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002210CINDEX_LINKAGE void clang_enableStackTraces(void);
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002211/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002212 * @}
2213 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002214
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002215/**
2216 * \defgroup CINDEX_CODE_COMPLET Code completion
2217 *
2218 * Code completion involves taking an (incomplete) source file, along with
2219 * knowledge of where the user is actively editing that file, and suggesting
2220 * syntactically- and semantically-valid constructs that the user might want to
2221 * use at that particular point in the source code. These data structures and
2222 * routines provide support for code completion.
2223 *
2224 * @{
2225 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002226
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002227/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002228 * \brief A semantic string that describes a code-completion result.
2229 *
2230 * A semantic string that describes the formatting of a code-completion
2231 * result as a single "template" of text that should be inserted into the
2232 * source buffer when a particular code-completion result is selected.
2233 * Each semantic string is made up of some number of "chunks", each of which
2234 * contains some text along with a description of what that text means, e.g.,
2235 * the name of the entity being referenced, whether the text chunk is part of
2236 * the template, or whether it is a "placeholder" that the user should replace
2237 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002238 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002239 */
2240typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002241
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002242/**
2243 * \brief A single result of code completion.
2244 */
2245typedef struct {
2246 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002247 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002248 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002249 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002250 * *Decl cursor kinds), describing the entity that the completion is
2251 * referring to.
2252 *
2253 * \todo In the future, we would like to provide a full cursor, to allow
2254 * the client to extract additional information from declaration.
2255 */
2256 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002257
2258 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002259 * \brief The code-completion string that describes how to insert this
2260 * code-completion result into the editing buffer.
2261 */
2262 CXCompletionString CompletionString;
2263} CXCompletionResult;
2264
2265/**
2266 * \brief Describes a single piece of text within a code-completion string.
2267 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002268 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2269 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002270 * should be interpreted by the client or is another completion string.
2271 */
2272enum CXCompletionChunkKind {
2273 /**
2274 * \brief A code-completion string that describes "optional" text that
2275 * could be a part of the template (but is not required).
2276 *
2277 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002278 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002279 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2280 * describes an additional part of the template that is completely optional.
2281 * For example, optional chunks can be used to describe the placeholders for
2282 * arguments that match up with defaulted function parameters, e.g. given:
2283 *
2284 * \code
2285 * void f(int x, float y = 3.14, double z = 2.71828);
2286 * \endcode
2287 *
2288 * The code-completion string for this function would contain:
2289 * - a TypedText chunk for "f".
2290 * - a LeftParen chunk for "(".
2291 * - a Placeholder chunk for "int x"
2292 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2293 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002294 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002295 * - an Optional chunk containing the last defaulted argument:
2296 * - a Comma chunk for ","
2297 * - a Placeholder chunk for "double z"
2298 * - a RightParen chunk for ")"
2299 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002300 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002301 * - Completely ignore optional chunks, in which case the template for the
2302 * function "f" would only include the first parameter ("int x").
2303 * - Fully expand all optional chunks, in which case the template for the
2304 * function "f" would have all of the parameters.
2305 */
2306 CXCompletionChunk_Optional,
2307 /**
2308 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002309 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002310 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002311 * There will be exactly one "typed text" chunk in a semantic string, which
2312 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002313 * declaration that could be used at the current code point. Clients are
2314 * expected to filter the code-completion results based on the text in this
2315 * chunk.
2316 */
2317 CXCompletionChunk_TypedText,
2318 /**
2319 * \brief Text that should be inserted as part of a code-completion result.
2320 *
2321 * A "text" chunk represents text that is part of the template to be
2322 * inserted into user code should this particular code-completion result
2323 * be selected.
2324 */
2325 CXCompletionChunk_Text,
2326 /**
2327 * \brief Placeholder text that should be replaced by the user.
2328 *
2329 * A "placeholder" chunk marks a place where the user should insert text
2330 * into the code-completion template. For example, placeholders might mark
2331 * the function parameters for a function declaration, to indicate that the
2332 * user should provide arguments for each of those parameters. The actual
2333 * text in a placeholder is a suggestion for the text to display before
2334 * the user replaces the placeholder with real code.
2335 */
2336 CXCompletionChunk_Placeholder,
2337 /**
2338 * \brief Informative text that should be displayed but never inserted as
2339 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002340 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002341 * An "informative" chunk contains annotations that can be displayed to
2342 * help the user decide whether a particular code-completion result is the
2343 * right option, but which is not part of the actual template to be inserted
2344 * by code completion.
2345 */
2346 CXCompletionChunk_Informative,
2347 /**
2348 * \brief Text that describes the current parameter when code-completion is
2349 * referring to function call, message send, or template specialization.
2350 *
2351 * A "current parameter" chunk occurs when code-completion is providing
2352 * information about a parameter corresponding to the argument at the
2353 * code-completion point. For example, given a function
2354 *
2355 * \code
2356 * int add(int x, int y);
2357 * \endcode
2358 *
2359 * and the source code \c add(, where the code-completion point is after the
2360 * "(", the code-completion string will contain a "current parameter" chunk
2361 * for "int x", indicating that the current argument will initialize that
2362 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002363 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002364 * "current paremeter" chunk to "int y".
2365 */
2366 CXCompletionChunk_CurrentParameter,
2367 /**
2368 * \brief A left parenthesis ('('), used to initiate a function call or
2369 * signal the beginning of a function parameter list.
2370 */
2371 CXCompletionChunk_LeftParen,
2372 /**
2373 * \brief A right parenthesis (')'), used to finish a function call or
2374 * signal the end of a function parameter list.
2375 */
2376 CXCompletionChunk_RightParen,
2377 /**
2378 * \brief A left bracket ('[').
2379 */
2380 CXCompletionChunk_LeftBracket,
2381 /**
2382 * \brief A right bracket (']').
2383 */
2384 CXCompletionChunk_RightBracket,
2385 /**
2386 * \brief A left brace ('{').
2387 */
2388 CXCompletionChunk_LeftBrace,
2389 /**
2390 * \brief A right brace ('}').
2391 */
2392 CXCompletionChunk_RightBrace,
2393 /**
2394 * \brief A left angle bracket ('<').
2395 */
2396 CXCompletionChunk_LeftAngle,
2397 /**
2398 * \brief A right angle bracket ('>').
2399 */
2400 CXCompletionChunk_RightAngle,
2401 /**
2402 * \brief A comma separator (',').
2403 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002404 CXCompletionChunk_Comma,
2405 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002406 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002407 *
2408 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002409 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002410 * expression using the given completion string would have.
2411 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002412 CXCompletionChunk_ResultType,
2413 /**
2414 * \brief A colon (':').
2415 */
2416 CXCompletionChunk_Colon,
2417 /**
2418 * \brief A semicolon (';').
2419 */
2420 CXCompletionChunk_SemiColon,
2421 /**
2422 * \brief An '=' sign.
2423 */
2424 CXCompletionChunk_Equal,
2425 /**
2426 * Horizontal space (' ').
2427 */
2428 CXCompletionChunk_HorizontalSpace,
2429 /**
2430 * Vertical space ('\n'), after which it is generally a good idea to
2431 * perform indentation.
2432 */
2433 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002434};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002435
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002436/**
2437 * \brief Determine the kind of a particular chunk within a completion string.
2438 *
2439 * \param completion_string the completion string to query.
2440 *
2441 * \param chunk_number the 0-based index of the chunk in the completion string.
2442 *
2443 * \returns the kind of the chunk at the index \c chunk_number.
2444 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002445CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002446clang_getCompletionChunkKind(CXCompletionString completion_string,
2447 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002448
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002449/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002450 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002451 * completion string.
2452 *
2453 * \param completion_string the completion string to query.
2454 *
2455 * \param chunk_number the 0-based index of the chunk in the completion string.
2456 *
2457 * \returns the text associated with the chunk at index \c chunk_number.
2458 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002459CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002460clang_getCompletionChunkText(CXCompletionString completion_string,
2461 unsigned chunk_number);
2462
2463/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002464 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002465 * within a completion string.
2466 *
2467 * \param completion_string the completion string to query.
2468 *
2469 * \param chunk_number the 0-based index of the chunk in the completion string.
2470 *
2471 * \returns the completion string associated with the chunk at index
2472 * \c chunk_number, or NULL if that chunk is not represented by a completion
2473 * string.
2474 */
2475CINDEX_LINKAGE CXCompletionString
2476clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2477 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002478
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002479/**
2480 * \brief Retrieve the number of chunks in the given code-completion string.
2481 */
2482CINDEX_LINKAGE unsigned
2483clang_getNumCompletionChunks(CXCompletionString completion_string);
2484
2485/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002486 * \brief Determine the priority of this code completion.
2487 *
2488 * The priority of a code completion indicates how likely it is that this
2489 * particular completion is the completion that the user will select. The
2490 * priority is selected by various internal heuristics.
2491 *
2492 * \param completion_string The completion string to query.
2493 *
2494 * \returns The priority of this completion string. Smaller values indicate
2495 * higher-priority (more likely) completions.
2496 */
2497CINDEX_LINKAGE unsigned
2498clang_getCompletionPriority(CXCompletionString completion_string);
2499
2500/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002501 * \brief Determine the availability of the entity that this code-completion
2502 * string refers to.
2503 *
2504 * \param completion_string The completion string to query.
2505 *
2506 * \returns The availability of the completion string.
2507 */
2508CINDEX_LINKAGE enum CXAvailabilityKind
2509clang_getCompletionAvailability(CXCompletionString completion_string);
2510
2511/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002512 * \brief Contains the results of code-completion.
2513 *
2514 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002515 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002516 * \c clang_disposeCodeCompleteResults.
2517 */
2518typedef struct {
2519 /**
2520 * \brief The code-completion results.
2521 */
2522 CXCompletionResult *Results;
2523
2524 /**
2525 * \brief The number of code-completion results stored in the
2526 * \c Results array.
2527 */
2528 unsigned NumResults;
2529} CXCodeCompleteResults;
2530
2531/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002532 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2533 * modify its behavior.
2534 *
2535 * The enumerators in this enumeration can be bitwise-OR'd together to
2536 * provide multiple options to \c clang_codeCompleteAt().
2537 */
2538enum CXCodeComplete_Flags {
2539 /**
2540 * \brief Whether to include macros within the set of code
2541 * completions returned.
2542 */
2543 CXCodeComplete_IncludeMacros = 0x01,
2544
2545 /**
2546 * \brief Whether to include code patterns for language constructs
2547 * within the set of code completions, e.g., for loops.
2548 */
2549 CXCodeComplete_IncludeCodePatterns = 0x02
2550};
2551
2552/**
2553 * \brief Returns a default set of code-completion options that can be
2554 * passed to\c clang_codeCompleteAt().
2555 */
2556CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
2557
2558/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002559 * \brief Perform code completion at a given location in a translation unit.
2560 *
2561 * This function performs code completion at a particular file, line, and
2562 * column within source code, providing results that suggest potential
2563 * code snippets based on the context of the completion. The basic model
2564 * for code completion is that Clang will parse a complete source file,
2565 * performing syntax checking up to the location where code-completion has
2566 * been requested. At that point, a special code-completion token is passed
2567 * to the parser, which recognizes this token and determines, based on the
2568 * current location in the C/Objective-C/C++ grammar and the state of
2569 * semantic analysis, what completions to provide. These completions are
2570 * returned via a new \c CXCodeCompleteResults structure.
2571 *
2572 * Code completion itself is meant to be triggered by the client when the
2573 * user types punctuation characters or whitespace, at which point the
2574 * code-completion location will coincide with the cursor. For example, if \c p
2575 * is a pointer, code-completion might be triggered after the "-" and then
2576 * after the ">" in \c p->. When the code-completion location is afer the ">",
2577 * the completion results will provide, e.g., the members of the struct that
2578 * "p" points to. The client is responsible for placing the cursor at the
2579 * beginning of the token currently being typed, then filtering the results
2580 * based on the contents of the token. For example, when code-completing for
2581 * the expression \c p->get, the client should provide the location just after
2582 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
2583 * client can filter the results based on the current token text ("get"), only
2584 * showing those results that start with "get". The intent of this interface
2585 * is to separate the relatively high-latency acquisition of code-completion
2586 * results from the filtering of results on a per-character basis, which must
2587 * have a lower latency.
2588 *
2589 * \param TU The translation unit in which code-completion should
2590 * occur. The source files for this translation unit need not be
2591 * completely up-to-date (and the contents of those source files may
2592 * be overridden via \p unsaved_files). Cursors referring into the
2593 * translation unit may be invalidated by this invocation.
2594 *
2595 * \param complete_filename The name of the source file where code
2596 * completion should be performed. This filename may be any file
2597 * included in the translation unit.
2598 *
2599 * \param complete_line The line at which code-completion should occur.
2600 *
2601 * \param complete_column The column at which code-completion should occur.
2602 * Note that the column should point just after the syntactic construct that
2603 * initiated code completion, and not in the middle of a lexical token.
2604 *
2605 * \param unsaved_files the Tiles that have not yet been saved to disk
2606 * but may be required for parsing or code completion, including the
2607 * contents of those files. The contents and name of these files (as
2608 * specified by CXUnsavedFile) are copied when necessary, so the
2609 * client only needs to guarantee their validity until the call to
2610 * this function returns.
2611 *
2612 * \param num_unsaved_files The number of unsaved file entries in \p
2613 * unsaved_files.
2614 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00002615 * \param options Extra options that control the behavior of code
2616 * completion, expressed as a bitwise OR of the enumerators of the
2617 * CXCodeComplete_Flags enumeration. The
2618 * \c clang_defaultCodeCompleteOptions() function returns a default set
2619 * of code-completion options.
2620 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002621 * \returns If successful, a new \c CXCodeCompleteResults structure
2622 * containing code-completion results, which should eventually be
2623 * freed with \c clang_disposeCodeCompleteResults(). If code
2624 * completion fails, returns NULL.
2625 */
2626CINDEX_LINKAGE
2627CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
2628 const char *complete_filename,
2629 unsigned complete_line,
2630 unsigned complete_column,
2631 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00002632 unsigned num_unsaved_files,
2633 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002634
2635/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00002636 * \brief Sort the code-completion results in case-insensitive alphabetical
2637 * order.
2638 *
2639 * \param Results The set of results to sort.
2640 * \param NumResults The number of results in \p Results.
2641 */
2642CINDEX_LINKAGE
2643void clang_sortCodeCompletionResults(CXCompletionResult *Results,
2644 unsigned NumResults);
2645
2646/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002647 * \brief Free the given set of code-completion results.
2648 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002649CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00002650void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00002651
Douglas Gregor20d416c2010-01-20 01:10:47 +00002652/**
Douglas Gregora88084b2010-02-18 18:08:43 +00002653 * \brief Determine the number of diagnostics produced prior to the
2654 * location where code completion was performed.
2655 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002656CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002657unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
2658
2659/**
2660 * \brief Retrieve a diagnostic associated with the given code completion.
2661 *
2662 * \param Result the code completion results to query.
2663 * \param Index the zero-based diagnostic number to retrieve.
2664 *
2665 * \returns the requested diagnostic. This diagnostic must be freed
2666 * via a call to \c clang_disposeDiagnostic().
2667 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002668CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002669CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
2670 unsigned Index);
2671
2672/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00002673 * @}
2674 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002675
2676
Ted Kremenek04bb7162010-01-22 22:44:15 +00002677/**
2678 * \defgroup CINDEX_MISC Miscellaneous utility functions
2679 *
2680 * @{
2681 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00002682
2683/**
2684 * \brief Return a version string, suitable for showing to a user, but not
2685 * intended to be parsed (the format is not guaranteed to be stable).
2686 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00002687CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00002688
2689/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00002690 * \brief Return a version string, suitable for showing to a user, but not
2691 * intended to be parsed (the format is not guaranteed to be stable).
2692 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002693
2694
Ted Kremenek16b55a72010-01-26 19:31:51 +00002695 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002696 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00002697 * (used with clang_getInclusions()).
2698 *
2699 * This visitor function will be invoked by clang_getInclusions() for each
2700 * file included (either at the top-level or by #include directives) within
2701 * a translation unit. The first argument is the file being included, and
2702 * the second and third arguments provide the inclusion stack. The
2703 * array is sorted in order of immediate inclusion. For example,
2704 * the first element refers to the location that included 'included_file'.
2705 */
2706typedef void (*CXInclusionVisitor)(CXFile included_file,
2707 CXSourceLocation* inclusion_stack,
2708 unsigned include_len,
2709 CXClientData client_data);
2710
2711/**
2712 * \brief Visit the set of preprocessor inclusions in a translation unit.
2713 * The visitor function is called with the provided data for every included
2714 * file. This does not include headers included by the PCH file (unless one
2715 * is inspecting the inclusions in the PCH file itself).
2716 */
2717CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
2718 CXInclusionVisitor visitor,
2719 CXClientData client_data);
2720
2721/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00002722 * @}
2723 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002724
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002725/**
2726 * @}
2727 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002728
Ted Kremenekd2fa5662009-08-26 22:36:44 +00002729#ifdef __cplusplus
2730}
2731#endif
2732#endif
2733