blob: 7f569d288344fa37ab07c2459f65fdcdb4bddb5c [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 */
716 CXTranslationUnit_CacheCompletionResults = 0x08
Douglas Gregor5a430212010-07-21 18:52:53 +0000717};
718
719/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000720 * \brief Returns the set of flags that is suitable for parsing a translation
721 * unit that is being edited.
722 *
723 * The set of flags returned provide options for \c clang_parseTranslationUnit()
724 * to indicate that the translation unit is likely to be reparsed many times,
725 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
726 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
727 * set contains an unspecified set of optimizations (e.g., the precompiled
728 * preamble) geared toward improving the performance of these routines. The
729 * set of optimizations enabled may change from one version to the next.
730 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000731CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000732
733/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000734 * \brief Parse the given source file and the translation unit corresponding
735 * to that file.
736 *
737 * This routine is the main entry point for the Clang C API, providing the
738 * ability to parse a source file into a translation unit that can then be
739 * queried by other functions in the API. This routine accepts a set of
740 * command-line arguments so that the compilation can be configured in the same
741 * way that the compiler is configured on the command line.
742 *
743 * \param CIdx The index object with which the translation unit will be
744 * associated.
745 *
746 * \param source_filename The name of the source file to load, or NULL if the
747 * source file is included in \p clang_command_line_args.
748 *
749 * \param command_line_args The command-line arguments that would be
750 * passed to the \c clang executable if it were being invoked out-of-process.
751 * These command-line options will be parsed and will affect how the translation
752 * unit is parsed. Note that the following options are ignored: '-c',
753 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
754 *
755 * \param num_command_line_args The number of command-line arguments in
756 * \p command_line_args.
757 *
758 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000759 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000760 * those files. The contents and name of these files (as specified by
761 * CXUnsavedFile) are copied when necessary, so the client only needs to
762 * guarantee their validity until the call to this function returns.
763 *
764 * \param num_unsaved_files the number of unsaved file entries in \p
765 * unsaved_files.
766 *
767 * \param options A bitmask of options that affects how the translation unit
768 * is managed but not its compilation. This should be a bitwise OR of the
769 * CXTranslationUnit_XXX flags.
770 *
771 * \returns A new translation unit describing the parsed code and containing
772 * any diagnostics produced by the compiler. If there is a failure from which
773 * the compiler cannot recover, returns NULL.
774 */
775CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
776 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000777 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000778 int num_command_line_args,
779 struct CXUnsavedFile *unsaved_files,
780 unsigned num_unsaved_files,
781 unsigned options);
782
Douglas Gregor5352ac02010-01-28 00:27:43 +0000783/**
Douglas Gregor19998442010-08-13 15:35:05 +0000784 * \brief Flags that control how translation units are saved.
785 *
786 * The enumerators in this enumeration type are meant to be bitwise
787 * ORed together to specify which options should be used when
788 * saving the translation unit.
789 */
790enum CXSaveTranslationUnit_Flags {
791 /**
792 * \brief Used to indicate that no special saving options are needed.
793 */
794 CXSaveTranslationUnit_None = 0x0
795};
796
797/**
798 * \brief Returns the set of flags that is suitable for saving a translation
799 * unit.
800 *
801 * The set of flags returned provide options for
802 * \c clang_saveTranslationUnit() by default. The returned flag
803 * set contains an unspecified set of options that save translation units with
804 * the most commonly-requested data.
805 */
806CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
807
808/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000809 * \brief Saves a translation unit into a serialized representation of
810 * that translation unit on disk.
811 *
812 * Any translation unit that was parsed without error can be saved
813 * into a file. The translation unit can then be deserialized into a
814 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
815 * if it is an incomplete translation unit that corresponds to a
816 * header, used as a precompiled header when parsing other translation
817 * units.
818 *
819 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +0000820 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000821 * \param FileName The file to which the translation unit will be saved.
822 *
Douglas Gregor19998442010-08-13 15:35:05 +0000823 * \param options A bitmask of options that affects how the translation unit
824 * is saved. This should be a bitwise OR of the
825 * CXSaveTranslationUnit_XXX flags.
826 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000827 * \returns Zero if the translation unit was saved successfully, a
828 * non-zero value otherwise.
829 */
830CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +0000831 const char *FileName,
832 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +0000833
834/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000835 * \brief Destroy the specified CXTranslationUnit object.
836 */
837CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000838
Douglas Gregor5352ac02010-01-28 00:27:43 +0000839/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000840 * \brief Flags that control the reparsing of translation units.
841 *
842 * The enumerators in this enumeration type are meant to be bitwise
843 * ORed together to specify which options should be used when
844 * reparsing the translation unit.
845 */
846enum CXReparse_Flags {
847 /**
848 * \brief Used to indicate that no special reparsing options are needed.
849 */
850 CXReparse_None = 0x0
851};
852
853/**
854 * \brief Returns the set of flags that is suitable for reparsing a translation
855 * unit.
856 *
857 * The set of flags returned provide options for
858 * \c clang_reparseTranslationUnit() by default. The returned flag
859 * set contains an unspecified set of optimizations geared toward common uses
860 * of reparsing. The set of optimizations enabled may change from one version
861 * to the next.
862 */
863CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
864
865/**
Douglas Gregorabc563f2010-07-19 21:46:24 +0000866 * \brief Reparse the source files that produced this translation unit.
867 *
868 * This routine can be used to re-parse the source files that originally
869 * created the given translation unit, for example because those source files
870 * have changed (either on disk or as passed via \p unsaved_files). The
871 * source code will be reparsed with the same command-line options as it
872 * was originally parsed.
873 *
874 * Reparsing a translation unit invalidates all cursors and source locations
875 * that refer into that translation unit. This makes reparsing a translation
876 * unit semantically equivalent to destroying the translation unit and then
877 * creating a new translation unit with the same command-line arguments.
878 * However, it may be more efficient to reparse a translation
879 * unit using this routine.
880 *
881 * \param TU The translation unit whose contents will be re-parsed. The
882 * translation unit must originally have been built with
883 * \c clang_createTranslationUnitFromSourceFile().
884 *
885 * \param num_unsaved_files The number of unsaved file entries in \p
886 * unsaved_files.
887 *
888 * \param unsaved_files The files that have not yet been saved to disk
889 * but may be required for parsing, including the contents of
890 * those files. The contents and name of these files (as specified by
891 * CXUnsavedFile) are copied when necessary, so the client only needs to
892 * guarantee their validity until the call to this function returns.
893 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000894 * \param options A bitset of options composed of the flags in CXReparse_Flags.
895 * The function \c clang_defaultReparseOptions() produces a default set of
896 * options recommended for most uses, based on the translation unit.
897 *
Douglas Gregorabc563f2010-07-19 21:46:24 +0000898 * \returns 0 if the sources could be reparsed. A non-zero value will be
899 * returned if reparsing was impossible, such that the translation unit is
900 * invalid. In such cases, the only valid call for \p TU is
901 * \c clang_disposeTranslationUnit(TU).
902 */
903CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
904 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000905 struct CXUnsavedFile *unsaved_files,
906 unsigned options);
Douglas Gregorabc563f2010-07-19 21:46:24 +0000907
908/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000909 * @}
910 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000911
Douglas Gregor5352ac02010-01-28 00:27:43 +0000912/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000913 * \brief Describes the kind of entity that a cursor refers to.
914 */
915enum CXCursorKind {
916 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000917 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000918 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000919 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000920 *
921 * Unexposed declarations have the same operations as any other kind
922 * of declaration; one can extract their location information,
923 * spelling, find their definitions, etc. However, the specific kind
924 * of the declaration is not reported.
925 */
926 CXCursor_UnexposedDecl = 1,
927 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000928 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000929 /** \brief A C or C++ union. */
930 CXCursor_UnionDecl = 3,
931 /** \brief A C++ class. */
932 CXCursor_ClassDecl = 4,
933 /** \brief An enumeration. */
934 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000935 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000936 * \brief A field (in C) or non-static data member (in C++) in a
937 * struct, union, or C++ class.
938 */
939 CXCursor_FieldDecl = 6,
940 /** \brief An enumerator constant. */
941 CXCursor_EnumConstantDecl = 7,
942 /** \brief A function. */
943 CXCursor_FunctionDecl = 8,
944 /** \brief A variable. */
945 CXCursor_VarDecl = 9,
946 /** \brief A function or method parameter. */
947 CXCursor_ParmDecl = 10,
948 /** \brief An Objective-C @interface. */
949 CXCursor_ObjCInterfaceDecl = 11,
950 /** \brief An Objective-C @interface for a category. */
951 CXCursor_ObjCCategoryDecl = 12,
952 /** \brief An Objective-C @protocol declaration. */
953 CXCursor_ObjCProtocolDecl = 13,
954 /** \brief An Objective-C @property declaration. */
955 CXCursor_ObjCPropertyDecl = 14,
956 /** \brief An Objective-C instance variable. */
957 CXCursor_ObjCIvarDecl = 15,
958 /** \brief An Objective-C instance method. */
959 CXCursor_ObjCInstanceMethodDecl = 16,
960 /** \brief An Objective-C class method. */
961 CXCursor_ObjCClassMethodDecl = 17,
962 /** \brief An Objective-C @implementation. */
963 CXCursor_ObjCImplementationDecl = 18,
964 /** \brief An Objective-C @implementation for a category. */
965 CXCursor_ObjCCategoryImplDecl = 19,
966 /** \brief A typedef */
967 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +0000968 /** \brief A C++ class method. */
969 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +0000970 /** \brief A C++ namespace. */
971 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +0000972 /** \brief A linkage specification, e.g. 'extern "C"'. */
973 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +0000974 /** \brief A C++ constructor. */
975 CXCursor_Constructor = 24,
976 /** \brief A C++ destructor. */
977 CXCursor_Destructor = 25,
978 /** \brief A C++ conversion function. */
979 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000980 /** \brief A C++ template type parameter. */
981 CXCursor_TemplateTypeParameter = 27,
982 /** \brief A C++ non-type template parameter. */
983 CXCursor_NonTypeTemplateParameter = 28,
984 /** \brief A C++ template template parameter. */
985 CXCursor_TemplateTemplateParameter = 29,
986 /** \brief A C++ function template. */
987 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +0000988 /** \brief A C++ class template. */
989 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +0000990 /** \brief A C++ class template partial specialization. */
991 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +0000992 /** \brief A C++ namespace alias declaration. */
993 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +0000994 /** \brief A C++ using directive. */
995 CXCursor_UsingDirective = 34,
Douglas Gregor7e242562010-09-01 19:52:22 +0000996 /** \brief A using declaration. */
997 CXCursor_UsingDeclaration = 35,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +0000998 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor7e242562010-09-01 19:52:22 +0000999 CXCursor_LastDecl = CXCursor_UsingDeclaration,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001000
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001001 /* References */
1002 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001003 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001004 CXCursor_ObjCProtocolRef = 41,
1005 CXCursor_ObjCClassRef = 42,
1006 /**
1007 * \brief A reference to a type declaration.
1008 *
1009 * A type reference occurs anywhere where a type is named but not
1010 * declared. For example, given:
1011 *
1012 * \code
1013 * typedef unsigned size_type;
1014 * size_type size;
1015 * \endcode
1016 *
1017 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1018 * while the type of the variable "size" is referenced. The cursor
1019 * referenced by the type of size is the typedef for size_type.
1020 */
1021 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001022 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001023 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001024 * \brief A reference to a class template, function template, template
1025 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001026 */
1027 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001028 /**
1029 * \brief A reference to a namespace or namespace alias.
1030 */
1031 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001032 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001033 * \brief A reference to a member of a struct, union, or class that occurs in
1034 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001035 */
1036 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001037 /**
1038 * \brief A reference to a labeled statement.
1039 *
1040 * This cursor kind is used to describe the jump to "start_over" in the
1041 * goto statement in the following example:
1042 *
1043 * \code
1044 * start_over:
1045 * ++counter;
1046 *
1047 * goto start_over;
1048 * \endcode
1049 *
1050 * A label reference cursor refers to a label statement.
1051 */
1052 CXCursor_LabelRef = 48,
1053
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001054 /**
1055 * \brief A reference to a set of overloaded functions or function templates
1056 * that has not yet been resolved to a specific function or function template.
1057 *
1058 * An overloaded declaration reference cursor occurs in C++ templates where
1059 * a dependent name refers to a function. For example:
1060 *
1061 * \code
1062 * template<typename T> void swap(T&, T&);
1063 *
1064 * struct X { ... };
1065 * void swap(X&, X&);
1066 *
1067 * template<typename T>
1068 * void reverse(T* first, T* last) {
1069 * while (first < last - 1) {
1070 * swap(*first, *--last);
1071 * ++first;
1072 * }
1073 * }
1074 *
1075 * struct Y { };
1076 * void swap(Y&, Y&);
1077 * \endcode
1078 *
1079 * Here, the identifier "swap" is associated with an overloaded declaration
1080 * reference. In the template definition, "swap" refers to either of the two
1081 * "swap" functions declared above, so both results will be available. At
1082 * instantiation time, "swap" may also refer to other functions found via
1083 * argument-dependent lookup (e.g., the "swap" function at the end of the
1084 * example).
1085 *
1086 * The functions \c clang_getNumOverloadedDecls() and
1087 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1088 * referenced by this cursor.
1089 */
1090 CXCursor_OverloadedDeclRef = 49,
1091
1092 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001093
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001094 /* Error conditions */
1095 CXCursor_FirstInvalid = 70,
1096 CXCursor_InvalidFile = 70,
1097 CXCursor_NoDeclFound = 71,
1098 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001099 CXCursor_InvalidCode = 73,
1100 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001101
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001102 /* Expressions */
1103 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001104
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001105 /**
1106 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001107 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001108 *
1109 * Unexposed expressions have the same operations as any other kind
1110 * of expression; one can extract their location information,
1111 * spelling, children, etc. However, the specific kind of the
1112 * expression is not reported.
1113 */
1114 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001115
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001116 /**
1117 * \brief An expression that refers to some value declaration, such
1118 * as a function, varible, or enumerator.
1119 */
1120 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001121
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001122 /**
1123 * \brief An expression that refers to a member of a struct, union,
1124 * class, Objective-C class, etc.
1125 */
1126 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001127
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001128 /** \brief An expression that calls a function. */
1129 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001130
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001131 /** \brief An expression that sends a message to an Objective-C
1132 object or class. */
1133 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001134
1135 /** \brief An expression that represents a block literal. */
1136 CXCursor_BlockExpr = 105,
1137
1138 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001139
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001140 /* Statements */
1141 CXCursor_FirstStmt = 200,
1142 /**
1143 * \brief A statement whose specific kind is not exposed via this
1144 * interface.
1145 *
1146 * Unexposed statements have the same operations as any other kind of
1147 * statement; one can extract their location information, spelling,
1148 * children, etc. However, the specific kind of the statement is not
1149 * reported.
1150 */
1151 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001152
1153 /** \brief A labelled statement in a function.
1154 *
1155 * This cursor kind is used to describe the "start_over:" label statement in
1156 * the following example:
1157 *
1158 * \code
1159 * start_over:
1160 * ++counter;
1161 * \endcode
1162 *
1163 */
1164 CXCursor_LabelStmt = 201,
1165
1166 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001167
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001168 /**
1169 * \brief Cursor that represents the translation unit itself.
1170 *
1171 * The translation unit cursor exists primarily to act as the root
1172 * cursor for traversing the contents of a translation unit.
1173 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001174 CXCursor_TranslationUnit = 300,
1175
1176 /* Attributes */
1177 CXCursor_FirstAttr = 400,
1178 /**
1179 * \brief An attribute whose specific kind is not exposed via this
1180 * interface.
1181 */
1182 CXCursor_UnexposedAttr = 400,
1183
1184 CXCursor_IBActionAttr = 401,
1185 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001186 CXCursor_IBOutletCollectionAttr = 403,
1187 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001188
1189 /* Preprocessing */
1190 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001191 CXCursor_MacroDefinition = 501,
1192 CXCursor_MacroInstantiation = 502,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001193 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001194 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001195 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001196};
1197
1198/**
1199 * \brief A cursor representing some element in the abstract syntax tree for
1200 * a translation unit.
1201 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001202 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001203 * program--declaration, statements, expressions, references to declarations,
1204 * etc.--under a single "cursor" abstraction with a common set of operations.
1205 * Common operation for a cursor include: getting the physical location in
1206 * a source file where the cursor points, getting the name associated with a
1207 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1208 *
1209 * Cursors can be produced in two specific ways.
1210 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1211 * from which one can use clang_visitChildren() to explore the rest of the
1212 * translation unit. clang_getCursor() maps from a physical source location
1213 * to the entity that resides at that location, allowing one to map from the
1214 * source code into the AST.
1215 */
1216typedef struct {
1217 enum CXCursorKind kind;
1218 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001219} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001220
1221/**
1222 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1223 *
1224 * @{
1225 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001226
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001227/**
1228 * \brief Retrieve the NULL cursor, which represents no entity.
1229 */
1230CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001231
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001232/**
1233 * \brief Retrieve the cursor that represents the given translation unit.
1234 *
1235 * The translation unit cursor can be used to start traversing the
1236 * various declarations within the given translation unit.
1237 */
1238CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1239
1240/**
1241 * \brief Determine whether two cursors are equivalent.
1242 */
1243CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001244
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001245/**
1246 * \brief Retrieve the kind of the given cursor.
1247 */
1248CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1249
1250/**
1251 * \brief Determine whether the given cursor kind represents a declaration.
1252 */
1253CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1254
1255/**
1256 * \brief Determine whether the given cursor kind represents a simple
1257 * reference.
1258 *
1259 * Note that other kinds of cursors (such as expressions) can also refer to
1260 * other cursors. Use clang_getCursorReferenced() to determine whether a
1261 * particular cursor refers to another entity.
1262 */
1263CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1264
1265/**
1266 * \brief Determine whether the given cursor kind represents an expression.
1267 */
1268CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1269
1270/**
1271 * \brief Determine whether the given cursor kind represents a statement.
1272 */
1273CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1274
1275/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001276 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001277 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001278 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001279CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1280
1281/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001282 * \brief Determine whether the given cursor kind represents a translation
1283 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001284 */
1285CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001286
Ted Kremenekad6eff62010-03-08 21:17:29 +00001287/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001288 * \brief Determine whether the given cursor represents a preprocessing
1289 * element, such as a preprocessor directive or macro instantiation.
1290 */
1291CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1292
1293/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001294 * \brief Determine whether the given cursor represents a currently
1295 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1296 */
1297CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1298
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001299/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001300 * \brief Describe the linkage of the entity referred to by a cursor.
1301 */
1302enum CXLinkageKind {
1303 /** \brief This value indicates that no linkage information is available
1304 * for a provided CXCursor. */
1305 CXLinkage_Invalid,
1306 /**
1307 * \brief This is the linkage for variables, parameters, and so on that
1308 * have automatic storage. This covers normal (non-extern) local variables.
1309 */
1310 CXLinkage_NoLinkage,
1311 /** \brief This is the linkage for static variables and static functions. */
1312 CXLinkage_Internal,
1313 /** \brief This is the linkage for entities with external linkage that live
1314 * in C++ anonymous namespaces.*/
1315 CXLinkage_UniqueExternal,
1316 /** \brief This is the linkage for entities with true, external linkage. */
1317 CXLinkage_External
1318};
1319
1320/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001321 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001322 */
1323CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1324
1325/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001326 * \brief Determine the availability of the entity that this cursor refers to.
1327 *
1328 * \param cursor The cursor to query.
1329 *
1330 * \returns The availability of the cursor.
1331 */
1332CINDEX_LINKAGE enum CXAvailabilityKind
1333clang_getCursorAvailability(CXCursor cursor);
1334
1335/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001336 * \brief Describe the "language" of the entity referred to by a cursor.
1337 */
1338CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001339 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001340 CXLanguage_C,
1341 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001342 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001343};
1344
1345/**
1346 * \brief Determine the "language" of the entity referred to by a given cursor.
1347 */
1348CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1349
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001350
1351/**
1352 * \brief Determine the semantic parent of the given cursor.
1353 *
1354 * The semantic parent of a cursor is the cursor that semantically contains
1355 * the given \p cursor. For many declarations, the lexical and semantic parents
1356 * are equivalent (the lexical parent is returned by
1357 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1358 * definitions are provided out-of-line. For example:
1359 *
1360 * \code
1361 * class C {
1362 * void f();
1363 * };
1364 *
1365 * void C::f() { }
1366 * \endcode
1367 *
1368 * In the out-of-line definition of \c C::f, the semantic parent is the
1369 * the class \c C, of which this function is a member. The lexical parent is
1370 * the place where the declaration actually occurs in the source code; in this
1371 * case, the definition occurs in the translation unit. In general, the
1372 * lexical parent for a given entity can change without affecting the semantics
1373 * of the program, and the lexical parent of different declarations of the
1374 * same entity may be different. Changing the semantic parent of a declaration,
1375 * on the other hand, can have a major impact on semantics, and redeclarations
1376 * of a particular entity should all have the same semantic context.
1377 *
1378 * In the example above, both declarations of \c C::f have \c C as their
1379 * semantic context, while the lexical context of the first \c C::f is \c C
1380 * and the lexical context of the second \c C::f is the translation unit.
1381 */
1382CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1383
1384/**
1385 * \brief Determine the lexical parent of the given cursor.
1386 *
1387 * The lexical parent of a cursor is the cursor in which the given \p cursor
1388 * was actually written. For many declarations, the lexical and semantic parents
1389 * are equivalent (the semantic parent is returned by
1390 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1391 * definitions are provided out-of-line. For example:
1392 *
1393 * \code
1394 * class C {
1395 * void f();
1396 * };
1397 *
1398 * void C::f() { }
1399 * \endcode
1400 *
1401 * In the out-of-line definition of \c C::f, the semantic parent is the
1402 * the class \c C, of which this function is a member. The lexical parent is
1403 * the place where the declaration actually occurs in the source code; in this
1404 * case, the definition occurs in the translation unit. In general, the
1405 * lexical parent for a given entity can change without affecting the semantics
1406 * of the program, and the lexical parent of different declarations of the
1407 * same entity may be different. Changing the semantic parent of a declaration,
1408 * on the other hand, can have a major impact on semantics, and redeclarations
1409 * of a particular entity should all have the same semantic context.
1410 *
1411 * In the example above, both declarations of \c C::f have \c C as their
1412 * semantic context, while the lexical context of the first \c C::f is \c C
1413 * and the lexical context of the second \c C::f is the translation unit.
1414 */
1415CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001416
1417/**
1418 * \brief Determine the set of methods that are overridden by the given
1419 * method.
1420 *
1421 * In both Objective-C and C++, a method (aka virtual member function,
1422 * in C++) can override a virtual method in a base class. For
1423 * Objective-C, a method is said to override any method in the class's
1424 * interface (if we're coming from an implementation), its protocols,
1425 * or its categories, that has the same selector and is of the same
1426 * kind (class or instance). If no such method exists, the search
1427 * continues to the class's superclass, its protocols, and its
1428 * categories, and so on.
1429 *
1430 * For C++, a virtual member function overrides any virtual member
1431 * function with the same signature that occurs in its base
1432 * classes. With multiple inheritance, a virtual member function can
1433 * override several virtual member functions coming from different
1434 * base classes.
1435 *
1436 * In all cases, this function determines the immediate overridden
1437 * method, rather than all of the overridden methods. For example, if
1438 * a method is originally declared in a class A, then overridden in B
1439 * (which in inherits from A) and also in C (which inherited from B),
1440 * then the only overridden method returned from this function when
1441 * invoked on C's method will be B's method. The client may then
1442 * invoke this function again, given the previously-found overridden
1443 * methods, to map out the complete method-override set.
1444 *
1445 * \param cursor A cursor representing an Objective-C or C++
1446 * method. This routine will compute the set of methods that this
1447 * method overrides.
1448 *
1449 * \param overridden A pointer whose pointee will be replaced with a
1450 * pointer to an array of cursors, representing the set of overridden
1451 * methods. If there are no overridden methods, the pointee will be
1452 * set to NULL. The pointee must be freed via a call to
1453 * \c clang_disposeOverriddenCursors().
1454 *
1455 * \param num_overridden A pointer to the number of overridden
1456 * functions, will be set to the number of overridden functions in the
1457 * array pointed to by \p overridden.
1458 */
1459CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1460 CXCursor **overridden,
1461 unsigned *num_overridden);
1462
1463/**
1464 * \brief Free the set of overridden cursors returned by \c
1465 * clang_getOverriddenCursors().
1466 */
1467CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1468
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001469/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001470 * \brief Retrieve the file that is included by the given inclusion directive
1471 * cursor.
1472 */
1473CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1474
1475/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001476 * @}
1477 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001478
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001479/**
1480 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1481 *
1482 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1483 * routines help map between cursors and the physical locations where the
1484 * described entities occur in the source code. The mapping is provided in
1485 * both directions, so one can map from source code to the AST and back.
1486 *
1487 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001488 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001489
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001490/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001491 * \brief Map a source location to the cursor that describes the entity at that
1492 * location in the source code.
1493 *
1494 * clang_getCursor() maps an arbitrary source location within a translation
1495 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001496 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001497 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001498 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001499 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1500 * will return a cursor referring to the "+" expression.
1501 *
1502 * \returns a cursor representing the entity at the given source location, or
1503 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001504 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001505CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001506
Douglas Gregor98258af2010-01-18 22:46:11 +00001507/**
1508 * \brief Retrieve the physical location of the source constructor referenced
1509 * by the given cursor.
1510 *
1511 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001512 * declaration, where the name of that declaration would occur if it is
1513 * unnamed, or some keyword that introduces that particular declaration.
1514 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001515 * source code.
1516 */
1517CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001518
Douglas Gregorb6998662010-01-19 19:34:47 +00001519/**
1520 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001521 * the given cursor.
1522 *
1523 * The extent of a cursor starts with the file/line/column pointing at the
1524 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001525 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001526 * declaration, the extent covers the declaration itself. For a reference,
1527 * the extent covers the location of the reference (e.g., where the referenced
1528 * entity was actually used).
1529 */
1530CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001531
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001532/**
1533 * @}
1534 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001535
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001536/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001537 * \defgroup CINDEX_TYPES Type information for CXCursors
1538 *
1539 * @{
1540 */
1541
1542/**
1543 * \brief Describes the kind of type
1544 */
1545enum CXTypeKind {
1546 /**
1547 * \brief Reprents an invalid type (e.g., where no type is available).
1548 */
1549 CXType_Invalid = 0,
1550
1551 /**
1552 * \brief A type whose specific kind is not exposed via this
1553 * interface.
1554 */
1555 CXType_Unexposed = 1,
1556
1557 /* Builtin types */
1558 CXType_Void = 2,
1559 CXType_Bool = 3,
1560 CXType_Char_U = 4,
1561 CXType_UChar = 5,
1562 CXType_Char16 = 6,
1563 CXType_Char32 = 7,
1564 CXType_UShort = 8,
1565 CXType_UInt = 9,
1566 CXType_ULong = 10,
1567 CXType_ULongLong = 11,
1568 CXType_UInt128 = 12,
1569 CXType_Char_S = 13,
1570 CXType_SChar = 14,
1571 CXType_WChar = 15,
1572 CXType_Short = 16,
1573 CXType_Int = 17,
1574 CXType_Long = 18,
1575 CXType_LongLong = 19,
1576 CXType_Int128 = 20,
1577 CXType_Float = 21,
1578 CXType_Double = 22,
1579 CXType_LongDouble = 23,
1580 CXType_NullPtr = 24,
1581 CXType_Overload = 25,
1582 CXType_Dependent = 26,
1583 CXType_ObjCId = 27,
1584 CXType_ObjCClass = 28,
1585 CXType_ObjCSel = 29,
1586 CXType_FirstBuiltin = CXType_Void,
1587 CXType_LastBuiltin = CXType_ObjCSel,
1588
1589 CXType_Complex = 100,
1590 CXType_Pointer = 101,
1591 CXType_BlockPointer = 102,
1592 CXType_LValueReference = 103,
1593 CXType_RValueReference = 104,
1594 CXType_Record = 105,
1595 CXType_Enum = 106,
1596 CXType_Typedef = 107,
1597 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001598 CXType_ObjCObjectPointer = 109,
1599 CXType_FunctionNoProto = 110,
1600 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001601};
1602
1603/**
1604 * \brief The type of an element in the abstract syntax tree.
1605 *
1606 */
1607typedef struct {
1608 enum CXTypeKind kind;
1609 void *data[2];
1610} CXType;
1611
1612/**
1613 * \brief Retrieve the type of a CXCursor (if any).
1614 */
1615CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1616
1617/**
1618 * \determine Determine whether two CXTypes represent the same type.
1619 *
1620 * \returns non-zero if the CXTypes represent the same type and
1621 zero otherwise.
1622 */
1623CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1624
1625/**
1626 * \brief Return the canonical type for a CXType.
1627 *
1628 * Clang's type system explicitly models typedefs and all the ways
1629 * a specific type can be represented. The canonical type is the underlying
1630 * type with all the "sugar" removed. For example, if 'T' is a typedef
1631 * for 'int', the canonical type for 'T' would be 'int'.
1632 */
1633CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1634
1635/**
1636 * \brief For pointer types, returns the type of the pointee.
1637 *
1638 */
1639CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1640
1641/**
1642 * \brief Return the cursor for the declaration of the given type.
1643 */
1644CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1645
1646
1647/**
1648 * \brief Retrieve the spelling of a given CXTypeKind.
1649 */
1650CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1651
1652/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001653 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001654 */
1655CINDEX_LINKAGE CXType clang_getResultType(CXType T);
1656
1657/**
Ted Kremenek9a140842010-06-21 20:48:56 +00001658 * \brief Retrieve the result type associated with a given cursor. This only
1659 * returns a valid type of the cursor refers to a function or method.
1660 */
1661CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
1662
1663/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00001664 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
1665 * otherwise.
1666 */
1667CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
1668
1669/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00001670 * \brief Returns 1 if the base class specified by the cursor with kind
1671 * CX_CXXBaseSpecifier is virtual.
1672 */
1673CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
1674
1675/**
1676 * \brief Represents the C++ access control level to a base class for a
1677 * cursor with kind CX_CXXBaseSpecifier.
1678 */
1679enum CX_CXXAccessSpecifier {
1680 CX_CXXInvalidAccessSpecifier,
1681 CX_CXXPublic,
1682 CX_CXXProtected,
1683 CX_CXXPrivate
1684};
1685
1686/**
1687 * \brief Returns the access control level for the C++ base specifier
1688 * represented by a cursor with kind CX_CXXBaseSpecifier.
1689 */
1690CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
1691
1692/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001693 * \brief Determine the number of overloaded declarations referenced by a
1694 * \c CXCursor_OverloadedDeclRef cursor.
1695 *
1696 * \param cursor The cursor whose overloaded declarations are being queried.
1697 *
1698 * \returns The number of overloaded declarations referenced by \c cursor. If it
1699 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
1700 */
1701CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
1702
1703/**
1704 * \brief Retrieve a cursor for one of the overloaded declarations referenced
1705 * by a \c CXCursor_OverloadedDeclRef cursor.
1706 *
1707 * \param cursor The cursor whose overloaded declarations are being queried.
1708 *
1709 * \param index The zero-based index into the set of overloaded declarations in
1710 * the cursor.
1711 *
1712 * \returns A cursor representing the declaration referenced by the given
1713 * \c cursor at the specified \c index. If the cursor does not have an
1714 * associated set of overloaded declarations, or if the index is out of bounds,
1715 * returns \c clang_getNullCursor();
1716 */
1717CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
1718 unsigned index);
1719
1720/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001721 * @}
1722 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001723
1724/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00001725 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00001726 *
1727 * @{
1728 */
1729
1730
1731/**
1732 * \brief For cursors representing an iboutletcollection attribute,
1733 * this function returns the collection element type.
1734 *
1735 */
1736CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
1737
1738/**
1739 * @}
1740 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001741
1742/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001743 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
1744 *
1745 * These routines provide the ability to traverse the abstract syntax tree
1746 * using cursors.
1747 *
1748 * @{
1749 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001750
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001751/**
1752 * \brief Describes how the traversal of the children of a particular
1753 * cursor should proceed after visiting a particular child cursor.
1754 *
1755 * A value of this enumeration type should be returned by each
1756 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
1757 */
1758enum CXChildVisitResult {
1759 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001760 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001761 */
1762 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001763 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001764 * \brief Continues the cursor traversal with the next sibling of
1765 * the cursor just visited, without visiting its children.
1766 */
1767 CXChildVisit_Continue,
1768 /**
1769 * \brief Recursively traverse the children of this cursor, using
1770 * the same visitor and client data.
1771 */
1772 CXChildVisit_Recurse
1773};
1774
1775/**
1776 * \brief Visitor invoked for each cursor found by a traversal.
1777 *
1778 * This visitor function will be invoked for each cursor found by
1779 * clang_visitCursorChildren(). Its first argument is the cursor being
1780 * visited, its second argument is the parent visitor for that cursor,
1781 * and its third argument is the client data provided to
1782 * clang_visitCursorChildren().
1783 *
1784 * The visitor should return one of the \c CXChildVisitResult values
1785 * to direct clang_visitCursorChildren().
1786 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001787typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
1788 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001789 CXClientData client_data);
1790
1791/**
1792 * \brief Visit the children of a particular cursor.
1793 *
1794 * This function visits all the direct children of the given cursor,
1795 * invoking the given \p visitor function with the cursors of each
1796 * visited child. The traversal may be recursive, if the visitor returns
1797 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
1798 * the visitor returns \c CXChildVisit_Break.
1799 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001800 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00001801 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001802 * definition, have no children).
1803 *
1804 * \param visitor the visitor function that will be invoked for each
1805 * child of \p parent.
1806 *
1807 * \param client_data pointer data supplied by the client, which will
1808 * be passed to the visitor each time it is invoked.
1809 *
1810 * \returns a non-zero value if the traversal was terminated
1811 * prematurely by the visitor returning \c CXChildVisit_Break.
1812 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001813CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001814 CXCursorVisitor visitor,
1815 CXClientData client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001816
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001817/**
1818 * @}
1819 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001820
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001821/**
1822 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1823 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001824 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001825 * across translation units, by providing the names of the entities referenced
1826 * by cursors, follow reference cursors to the declarations they reference,
1827 * and associate declarations with their definitions.
1828 *
1829 * @{
1830 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001831
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001832/**
1833 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1834 * by the given cursor.
1835 *
1836 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1837 * entity (function, class, variable, etc.) within a program. USRs can be
1838 * compared across translation units to determine, e.g., when references in
1839 * one translation refer to an entity defined in another translation unit.
1840 */
1841CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1842
1843/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00001844 * \brief Construct a USR for a specified Objective-C class.
1845 */
1846CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
1847
1848/**
1849 * \brief Construct a USR for a specified Objective-C category.
1850 */
1851CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00001852 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001853 const char *category_name);
1854
1855/**
1856 * \brief Construct a USR for a specified Objective-C protocol.
1857 */
1858CINDEX_LINKAGE CXString
1859 clang_constructUSR_ObjCProtocol(const char *protocol_name);
1860
1861
1862/**
1863 * \brief Construct a USR for a specified Objective-C instance variable and
1864 * the USR for its containing class.
1865 */
1866CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
1867 CXString classUSR);
1868
1869/**
1870 * \brief Construct a USR for a specified Objective-C method and
1871 * the USR for its containing class.
1872 */
1873CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
1874 unsigned isInstanceMethod,
1875 CXString classUSR);
1876
1877/**
1878 * \brief Construct a USR for a specified Objective-C property and the USR
1879 * for its containing class.
1880 */
1881CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
1882 CXString classUSR);
1883
1884/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001885 * \brief Retrieve a name for the entity referenced by this cursor.
1886 */
1887CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1888
Douglas Gregor358559d2010-10-02 22:49:11 +00001889/**
1890 * \brief Retrieve the display name for the entity referenced by this cursor.
1891 *
1892 * The display name contains extra information that helps identify the cursor,
1893 * such as the parameters of a function or template or the arguments of a
1894 * class template specialization.
1895 */
1896CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
1897
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001898/** \brief For a cursor that is a reference, retrieve a cursor representing the
1899 * entity that it references.
1900 *
1901 * Reference cursors refer to other entities in the AST. For example, an
1902 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001903 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001904 * cursor for the superclass reference. If the input cursor is a declaration or
1905 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001906 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001907 */
1908CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001909
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001910/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001911 * \brief For a cursor that is either a reference to or a declaration
1912 * of some entity, retrieve a cursor that describes the definition of
1913 * that entity.
1914 *
1915 * Some entities can be declared multiple times within a translation
1916 * unit, but only one of those declarations can also be a
1917 * definition. For example, given:
1918 *
1919 * \code
1920 * int f(int, int);
1921 * int g(int x, int y) { return f(x, y); }
1922 * int f(int a, int b) { return a + b; }
1923 * int f(int, int);
1924 * \endcode
1925 *
1926 * there are three declarations of the function "f", but only the
1927 * second one is a definition. The clang_getCursorDefinition()
1928 * function will take any cursor pointing to a declaration of "f"
1929 * (the first or fourth lines of the example) or a cursor referenced
1930 * that uses "f" (the call to "f' inside "g") and will return a
1931 * declaration cursor pointing to the definition (the second "f"
1932 * declaration).
1933 *
1934 * If given a cursor for which there is no corresponding definition,
1935 * e.g., because there is no definition of that entity within this
1936 * translation unit, returns a NULL cursor.
1937 */
1938CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1939
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001940/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001941 * \brief Determine whether the declaration pointed to by this cursor
1942 * is also a definition of that entity.
1943 */
1944CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1945
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001946/**
1947 * @}
1948 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001949
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001950/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00001951 * \defgroup CINDEX_CPP C++ AST introspection
1952 *
1953 * The routines in this group provide access information in the ASTs specific
1954 * to C++ language features.
1955 *
1956 * @{
1957 */
1958
1959/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00001960 * \brief Determine if a C++ member function or member function template is
1961 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00001962 */
1963CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
1964
1965/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00001966 * \brief Given a cursor that represents a template, determine
1967 * the cursor kind of the specializations would be generated by instantiating
1968 * the template.
1969 *
1970 * This routine can be used to determine what flavor of function template,
1971 * class template, or class template partial specialization is stored in the
1972 * cursor. For example, it can describe whether a class template cursor is
1973 * declared with "struct", "class" or "union".
1974 *
1975 * \param C The cursor to query. This cursor should represent a template
1976 * declaration.
1977 *
1978 * \returns The cursor kind of the specializations that would be generated
1979 * by instantiating the template \p C. If \p C is not a template, returns
1980 * \c CXCursor_NoDeclFound.
1981 */
1982CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
1983
1984/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00001985 * \brief Given a cursor that may represent a specialization or instantiation
1986 * of a template, retrieve the cursor that represents the template that it
1987 * specializes or from which it was instantiated.
1988 *
1989 * This routine determines the template involved both for explicit
1990 * specializations of templates and for implicit instantiations of the template,
1991 * both of which are referred to as "specializations". For a class template
1992 * specialization (e.g., \c std::vector<bool>), this routine will return
1993 * either the primary template (\c std::vector) or, if the specialization was
1994 * instantiated from a class template partial specialization, the class template
1995 * partial specialization. For a class template partial specialization and a
1996 * function template specialization (including instantiations), this
1997 * this routine will return the specialized template.
1998 *
1999 * For members of a class template (e.g., member functions, member classes, or
2000 * static data members), returns the specialized or instantiated member.
2001 * Although not strictly "templates" in the C++ language, members of class
2002 * templates have the same notions of specializations and instantiations that
2003 * templates do, so this routine treats them similarly.
2004 *
2005 * \param C A cursor that may be a specialization of a template or a member
2006 * of a template.
2007 *
2008 * \returns If the given cursor is a specialization or instantiation of a
2009 * template or a member thereof, the template or member that it specializes or
2010 * from which it was instantiated. Otherwise, returns a NULL cursor.
2011 */
2012CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
2013
2014/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002015 * @}
2016 */
2017
2018/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002019 * \defgroup CINDEX_LEX Token extraction and manipulation
2020 *
2021 * The routines in this group provide access to the tokens within a
2022 * translation unit, along with a semantic mapping of those tokens to
2023 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002024 *
2025 * @{
2026 */
2027
2028/**
2029 * \brief Describes a kind of token.
2030 */
2031typedef enum CXTokenKind {
2032 /**
2033 * \brief A token that contains some kind of punctuation.
2034 */
2035 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002036
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002037 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002038 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002039 */
2040 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002041
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002042 /**
2043 * \brief An identifier (that is not a keyword).
2044 */
2045 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002046
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002047 /**
2048 * \brief A numeric, string, or character literal.
2049 */
2050 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002051
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002052 /**
2053 * \brief A comment.
2054 */
2055 CXToken_Comment
2056} CXTokenKind;
2057
2058/**
2059 * \brief Describes a single preprocessing token.
2060 */
2061typedef struct {
2062 unsigned int_data[4];
2063 void *ptr_data;
2064} CXToken;
2065
2066/**
2067 * \brief Determine the kind of the given token.
2068 */
2069CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002070
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002071/**
2072 * \brief Determine the spelling of the given token.
2073 *
2074 * The spelling of a token is the textual representation of that token, e.g.,
2075 * the text of an identifier or keyword.
2076 */
2077CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002078
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002079/**
2080 * \brief Retrieve the source location of the given token.
2081 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002082CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002083 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002084
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002085/**
2086 * \brief Retrieve a source range that covers the given token.
2087 */
2088CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2089
2090/**
2091 * \brief Tokenize the source code described by the given range into raw
2092 * lexical tokens.
2093 *
2094 * \param TU the translation unit whose text is being tokenized.
2095 *
2096 * \param Range the source range in which text should be tokenized. All of the
2097 * tokens produced by tokenization will fall within this source range,
2098 *
2099 * \param Tokens this pointer will be set to point to the array of tokens
2100 * that occur within the given source range. The returned pointer must be
2101 * freed with clang_disposeTokens() before the translation unit is destroyed.
2102 *
2103 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2104 * array.
2105 *
2106 */
2107CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2108 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002109
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002110/**
2111 * \brief Annotate the given set of tokens by providing cursors for each token
2112 * that can be mapped to a specific entity within the abstract syntax tree.
2113 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002114 * This token-annotation routine is equivalent to invoking
2115 * clang_getCursor() for the source locations of each of the
2116 * tokens. The cursors provided are filtered, so that only those
2117 * cursors that have a direct correspondence to the token are
2118 * accepted. For example, given a function call \c f(x),
2119 * clang_getCursor() would provide the following cursors:
2120 *
2121 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2122 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2123 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2124 *
2125 * Only the first and last of these cursors will occur within the
2126 * annotate, since the tokens "f" and "x' directly refer to a function
2127 * and a variable, respectively, but the parentheses are just a small
2128 * part of the full syntax of the function call expression, which is
2129 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002130 *
2131 * \param TU the translation unit that owns the given tokens.
2132 *
2133 * \param Tokens the set of tokens to annotate.
2134 *
2135 * \param NumTokens the number of tokens in \p Tokens.
2136 *
2137 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2138 * replaced with the cursors corresponding to each token.
2139 */
2140CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2141 CXToken *Tokens, unsigned NumTokens,
2142 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002143
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002144/**
2145 * \brief Free the given set of tokens.
2146 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002147CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002148 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002149
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002150/**
2151 * @}
2152 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002153
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002154/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002155 * \defgroup CINDEX_DEBUG Debugging facilities
2156 *
2157 * These routines are used for testing and debugging, only, and should not
2158 * be relied upon.
2159 *
2160 * @{
2161 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002162
Steve Naroff4ade6d62009-09-23 17:52:52 +00002163/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002164CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002165CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2166 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002167 const char **endBuf,
2168 unsigned *startLine,
2169 unsigned *startColumn,
2170 unsigned *endLine,
2171 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002172CINDEX_LINKAGE void clang_enableStackTraces(void);
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002173/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002174 * @}
2175 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002176
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002177/**
2178 * \defgroup CINDEX_CODE_COMPLET Code completion
2179 *
2180 * Code completion involves taking an (incomplete) source file, along with
2181 * knowledge of where the user is actively editing that file, and suggesting
2182 * syntactically- and semantically-valid constructs that the user might want to
2183 * use at that particular point in the source code. These data structures and
2184 * routines provide support for code completion.
2185 *
2186 * @{
2187 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002188
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002189/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002190 * \brief A semantic string that describes a code-completion result.
2191 *
2192 * A semantic string that describes the formatting of a code-completion
2193 * result as a single "template" of text that should be inserted into the
2194 * source buffer when a particular code-completion result is selected.
2195 * Each semantic string is made up of some number of "chunks", each of which
2196 * contains some text along with a description of what that text means, e.g.,
2197 * the name of the entity being referenced, whether the text chunk is part of
2198 * the template, or whether it is a "placeholder" that the user should replace
2199 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002200 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002201 */
2202typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002203
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002204/**
2205 * \brief A single result of code completion.
2206 */
2207typedef struct {
2208 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002209 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002210 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002211 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002212 * *Decl cursor kinds), describing the entity that the completion is
2213 * referring to.
2214 *
2215 * \todo In the future, we would like to provide a full cursor, to allow
2216 * the client to extract additional information from declaration.
2217 */
2218 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002219
2220 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002221 * \brief The code-completion string that describes how to insert this
2222 * code-completion result into the editing buffer.
2223 */
2224 CXCompletionString CompletionString;
2225} CXCompletionResult;
2226
2227/**
2228 * \brief Describes a single piece of text within a code-completion string.
2229 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002230 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2231 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002232 * should be interpreted by the client or is another completion string.
2233 */
2234enum CXCompletionChunkKind {
2235 /**
2236 * \brief A code-completion string that describes "optional" text that
2237 * could be a part of the template (but is not required).
2238 *
2239 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002240 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002241 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2242 * describes an additional part of the template that is completely optional.
2243 * For example, optional chunks can be used to describe the placeholders for
2244 * arguments that match up with defaulted function parameters, e.g. given:
2245 *
2246 * \code
2247 * void f(int x, float y = 3.14, double z = 2.71828);
2248 * \endcode
2249 *
2250 * The code-completion string for this function would contain:
2251 * - a TypedText chunk for "f".
2252 * - a LeftParen chunk for "(".
2253 * - a Placeholder chunk for "int x"
2254 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2255 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002256 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002257 * - an Optional chunk containing the last defaulted argument:
2258 * - a Comma chunk for ","
2259 * - a Placeholder chunk for "double z"
2260 * - a RightParen chunk for ")"
2261 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002262 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002263 * - Completely ignore optional chunks, in which case the template for the
2264 * function "f" would only include the first parameter ("int x").
2265 * - Fully expand all optional chunks, in which case the template for the
2266 * function "f" would have all of the parameters.
2267 */
2268 CXCompletionChunk_Optional,
2269 /**
2270 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002271 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002272 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002273 * There will be exactly one "typed text" chunk in a semantic string, which
2274 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002275 * declaration that could be used at the current code point. Clients are
2276 * expected to filter the code-completion results based on the text in this
2277 * chunk.
2278 */
2279 CXCompletionChunk_TypedText,
2280 /**
2281 * \brief Text that should be inserted as part of a code-completion result.
2282 *
2283 * A "text" chunk represents text that is part of the template to be
2284 * inserted into user code should this particular code-completion result
2285 * be selected.
2286 */
2287 CXCompletionChunk_Text,
2288 /**
2289 * \brief Placeholder text that should be replaced by the user.
2290 *
2291 * A "placeholder" chunk marks a place where the user should insert text
2292 * into the code-completion template. For example, placeholders might mark
2293 * the function parameters for a function declaration, to indicate that the
2294 * user should provide arguments for each of those parameters. The actual
2295 * text in a placeholder is a suggestion for the text to display before
2296 * the user replaces the placeholder with real code.
2297 */
2298 CXCompletionChunk_Placeholder,
2299 /**
2300 * \brief Informative text that should be displayed but never inserted as
2301 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002302 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002303 * An "informative" chunk contains annotations that can be displayed to
2304 * help the user decide whether a particular code-completion result is the
2305 * right option, but which is not part of the actual template to be inserted
2306 * by code completion.
2307 */
2308 CXCompletionChunk_Informative,
2309 /**
2310 * \brief Text that describes the current parameter when code-completion is
2311 * referring to function call, message send, or template specialization.
2312 *
2313 * A "current parameter" chunk occurs when code-completion is providing
2314 * information about a parameter corresponding to the argument at the
2315 * code-completion point. For example, given a function
2316 *
2317 * \code
2318 * int add(int x, int y);
2319 * \endcode
2320 *
2321 * and the source code \c add(, where the code-completion point is after the
2322 * "(", the code-completion string will contain a "current parameter" chunk
2323 * for "int x", indicating that the current argument will initialize that
2324 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002325 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002326 * "current paremeter" chunk to "int y".
2327 */
2328 CXCompletionChunk_CurrentParameter,
2329 /**
2330 * \brief A left parenthesis ('('), used to initiate a function call or
2331 * signal the beginning of a function parameter list.
2332 */
2333 CXCompletionChunk_LeftParen,
2334 /**
2335 * \brief A right parenthesis (')'), used to finish a function call or
2336 * signal the end of a function parameter list.
2337 */
2338 CXCompletionChunk_RightParen,
2339 /**
2340 * \brief A left bracket ('[').
2341 */
2342 CXCompletionChunk_LeftBracket,
2343 /**
2344 * \brief A right bracket (']').
2345 */
2346 CXCompletionChunk_RightBracket,
2347 /**
2348 * \brief A left brace ('{').
2349 */
2350 CXCompletionChunk_LeftBrace,
2351 /**
2352 * \brief A right brace ('}').
2353 */
2354 CXCompletionChunk_RightBrace,
2355 /**
2356 * \brief A left angle bracket ('<').
2357 */
2358 CXCompletionChunk_LeftAngle,
2359 /**
2360 * \brief A right angle bracket ('>').
2361 */
2362 CXCompletionChunk_RightAngle,
2363 /**
2364 * \brief A comma separator (',').
2365 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002366 CXCompletionChunk_Comma,
2367 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002368 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002369 *
2370 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002371 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002372 * expression using the given completion string would have.
2373 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002374 CXCompletionChunk_ResultType,
2375 /**
2376 * \brief A colon (':').
2377 */
2378 CXCompletionChunk_Colon,
2379 /**
2380 * \brief A semicolon (';').
2381 */
2382 CXCompletionChunk_SemiColon,
2383 /**
2384 * \brief An '=' sign.
2385 */
2386 CXCompletionChunk_Equal,
2387 /**
2388 * Horizontal space (' ').
2389 */
2390 CXCompletionChunk_HorizontalSpace,
2391 /**
2392 * Vertical space ('\n'), after which it is generally a good idea to
2393 * perform indentation.
2394 */
2395 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002396};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002397
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002398/**
2399 * \brief Determine the kind of a particular chunk within a completion string.
2400 *
2401 * \param completion_string the completion string to query.
2402 *
2403 * \param chunk_number the 0-based index of the chunk in the completion string.
2404 *
2405 * \returns the kind of the chunk at the index \c chunk_number.
2406 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002407CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002408clang_getCompletionChunkKind(CXCompletionString completion_string,
2409 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002410
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002411/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002412 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002413 * completion string.
2414 *
2415 * \param completion_string the completion string to query.
2416 *
2417 * \param chunk_number the 0-based index of the chunk in the completion string.
2418 *
2419 * \returns the text associated with the chunk at index \c chunk_number.
2420 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002421CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002422clang_getCompletionChunkText(CXCompletionString completion_string,
2423 unsigned chunk_number);
2424
2425/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002426 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002427 * within a completion string.
2428 *
2429 * \param completion_string the completion string to query.
2430 *
2431 * \param chunk_number the 0-based index of the chunk in the completion string.
2432 *
2433 * \returns the completion string associated with the chunk at index
2434 * \c chunk_number, or NULL if that chunk is not represented by a completion
2435 * string.
2436 */
2437CINDEX_LINKAGE CXCompletionString
2438clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2439 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002440
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002441/**
2442 * \brief Retrieve the number of chunks in the given code-completion string.
2443 */
2444CINDEX_LINKAGE unsigned
2445clang_getNumCompletionChunks(CXCompletionString completion_string);
2446
2447/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002448 * \brief Determine the priority of this code completion.
2449 *
2450 * The priority of a code completion indicates how likely it is that this
2451 * particular completion is the completion that the user will select. The
2452 * priority is selected by various internal heuristics.
2453 *
2454 * \param completion_string The completion string to query.
2455 *
2456 * \returns The priority of this completion string. Smaller values indicate
2457 * higher-priority (more likely) completions.
2458 */
2459CINDEX_LINKAGE unsigned
2460clang_getCompletionPriority(CXCompletionString completion_string);
2461
2462/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002463 * \brief Determine the availability of the entity that this code-completion
2464 * string refers to.
2465 *
2466 * \param completion_string The completion string to query.
2467 *
2468 * \returns The availability of the completion string.
2469 */
2470CINDEX_LINKAGE enum CXAvailabilityKind
2471clang_getCompletionAvailability(CXCompletionString completion_string);
2472
2473/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002474 * \brief Contains the results of code-completion.
2475 *
2476 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002477 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002478 * \c clang_disposeCodeCompleteResults.
2479 */
2480typedef struct {
2481 /**
2482 * \brief The code-completion results.
2483 */
2484 CXCompletionResult *Results;
2485
2486 /**
2487 * \brief The number of code-completion results stored in the
2488 * \c Results array.
2489 */
2490 unsigned NumResults;
2491} CXCodeCompleteResults;
2492
2493/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00002494 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
2495 * modify its behavior.
2496 *
2497 * The enumerators in this enumeration can be bitwise-OR'd together to
2498 * provide multiple options to \c clang_codeCompleteAt().
2499 */
2500enum CXCodeComplete_Flags {
2501 /**
2502 * \brief Whether to include macros within the set of code
2503 * completions returned.
2504 */
2505 CXCodeComplete_IncludeMacros = 0x01,
2506
2507 /**
2508 * \brief Whether to include code patterns for language constructs
2509 * within the set of code completions, e.g., for loops.
2510 */
2511 CXCodeComplete_IncludeCodePatterns = 0x02
2512};
2513
2514/**
2515 * \brief Returns a default set of code-completion options that can be
2516 * passed to\c clang_codeCompleteAt().
2517 */
2518CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
2519
2520/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002521 * \brief Perform code completion at a given location in a translation unit.
2522 *
2523 * This function performs code completion at a particular file, line, and
2524 * column within source code, providing results that suggest potential
2525 * code snippets based on the context of the completion. The basic model
2526 * for code completion is that Clang will parse a complete source file,
2527 * performing syntax checking up to the location where code-completion has
2528 * been requested. At that point, a special code-completion token is passed
2529 * to the parser, which recognizes this token and determines, based on the
2530 * current location in the C/Objective-C/C++ grammar and the state of
2531 * semantic analysis, what completions to provide. These completions are
2532 * returned via a new \c CXCodeCompleteResults structure.
2533 *
2534 * Code completion itself is meant to be triggered by the client when the
2535 * user types punctuation characters or whitespace, at which point the
2536 * code-completion location will coincide with the cursor. For example, if \c p
2537 * is a pointer, code-completion might be triggered after the "-" and then
2538 * after the ">" in \c p->. When the code-completion location is afer the ">",
2539 * the completion results will provide, e.g., the members of the struct that
2540 * "p" points to. The client is responsible for placing the cursor at the
2541 * beginning of the token currently being typed, then filtering the results
2542 * based on the contents of the token. For example, when code-completing for
2543 * the expression \c p->get, the client should provide the location just after
2544 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
2545 * client can filter the results based on the current token text ("get"), only
2546 * showing those results that start with "get". The intent of this interface
2547 * is to separate the relatively high-latency acquisition of code-completion
2548 * results from the filtering of results on a per-character basis, which must
2549 * have a lower latency.
2550 *
2551 * \param TU The translation unit in which code-completion should
2552 * occur. The source files for this translation unit need not be
2553 * completely up-to-date (and the contents of those source files may
2554 * be overridden via \p unsaved_files). Cursors referring into the
2555 * translation unit may be invalidated by this invocation.
2556 *
2557 * \param complete_filename The name of the source file where code
2558 * completion should be performed. This filename may be any file
2559 * included in the translation unit.
2560 *
2561 * \param complete_line The line at which code-completion should occur.
2562 *
2563 * \param complete_column The column at which code-completion should occur.
2564 * Note that the column should point just after the syntactic construct that
2565 * initiated code completion, and not in the middle of a lexical token.
2566 *
2567 * \param unsaved_files the Tiles that have not yet been saved to disk
2568 * but may be required for parsing or code completion, including the
2569 * contents of those files. The contents and name of these files (as
2570 * specified by CXUnsavedFile) are copied when necessary, so the
2571 * client only needs to guarantee their validity until the call to
2572 * this function returns.
2573 *
2574 * \param num_unsaved_files The number of unsaved file entries in \p
2575 * unsaved_files.
2576 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00002577 * \param options Extra options that control the behavior of code
2578 * completion, expressed as a bitwise OR of the enumerators of the
2579 * CXCodeComplete_Flags enumeration. The
2580 * \c clang_defaultCodeCompleteOptions() function returns a default set
2581 * of code-completion options.
2582 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002583 * \returns If successful, a new \c CXCodeCompleteResults structure
2584 * containing code-completion results, which should eventually be
2585 * freed with \c clang_disposeCodeCompleteResults(). If code
2586 * completion fails, returns NULL.
2587 */
2588CINDEX_LINKAGE
2589CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
2590 const char *complete_filename,
2591 unsigned complete_line,
2592 unsigned complete_column,
2593 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00002594 unsigned num_unsaved_files,
2595 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00002596
2597/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00002598 * \brief Sort the code-completion results in case-insensitive alphabetical
2599 * order.
2600 *
2601 * \param Results The set of results to sort.
2602 * \param NumResults The number of results in \p Results.
2603 */
2604CINDEX_LINKAGE
2605void clang_sortCodeCompletionResults(CXCompletionResult *Results,
2606 unsigned NumResults);
2607
2608/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002609 * \brief Free the given set of code-completion results.
2610 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002611CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00002612void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00002613
Douglas Gregor20d416c2010-01-20 01:10:47 +00002614/**
Douglas Gregora88084b2010-02-18 18:08:43 +00002615 * \brief Determine the number of diagnostics produced prior to the
2616 * location where code completion was performed.
2617 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002618CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002619unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
2620
2621/**
2622 * \brief Retrieve a diagnostic associated with the given code completion.
2623 *
2624 * \param Result the code completion results to query.
2625 * \param Index the zero-based diagnostic number to retrieve.
2626 *
2627 * \returns the requested diagnostic. This diagnostic must be freed
2628 * via a call to \c clang_disposeDiagnostic().
2629 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002630CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00002631CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
2632 unsigned Index);
2633
2634/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00002635 * @}
2636 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002637
2638
Ted Kremenek04bb7162010-01-22 22:44:15 +00002639/**
2640 * \defgroup CINDEX_MISC Miscellaneous utility functions
2641 *
2642 * @{
2643 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00002644
2645/**
2646 * \brief Return a version string, suitable for showing to a user, but not
2647 * intended to be parsed (the format is not guaranteed to be stable).
2648 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00002649CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00002650
2651/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00002652 * \brief Return a version string, suitable for showing to a user, but not
2653 * intended to be parsed (the format is not guaranteed to be stable).
2654 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002655
2656
Ted Kremenek16b55a72010-01-26 19:31:51 +00002657 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002658 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00002659 * (used with clang_getInclusions()).
2660 *
2661 * This visitor function will be invoked by clang_getInclusions() for each
2662 * file included (either at the top-level or by #include directives) within
2663 * a translation unit. The first argument is the file being included, and
2664 * the second and third arguments provide the inclusion stack. The
2665 * array is sorted in order of immediate inclusion. For example,
2666 * the first element refers to the location that included 'included_file'.
2667 */
2668typedef void (*CXInclusionVisitor)(CXFile included_file,
2669 CXSourceLocation* inclusion_stack,
2670 unsigned include_len,
2671 CXClientData client_data);
2672
2673/**
2674 * \brief Visit the set of preprocessor inclusions in a translation unit.
2675 * The visitor function is called with the provided data for every included
2676 * file. This does not include headers included by the PCH file (unless one
2677 * is inspecting the inclusions in the PCH file itself).
2678 */
2679CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
2680 CXInclusionVisitor visitor,
2681 CXClientData client_data);
2682
2683/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00002684 * @}
2685 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002686
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002687/**
2688 * @}
2689 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002690
Ted Kremenekd2fa5662009-08-26 22:36:44 +00002691#ifdef __cplusplus
2692}
2693#endif
2694#endif
2695