blob: 99c129b2208f997ffeee27dabfdd408d5ef77726 [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>
Steve Naroff88145032009-10-27 14:35:18 +000021
Ted Kremenekd2fa5662009-08-26 22:36:44 +000022#ifdef __cplusplus
23extern "C" {
24#endif
25
Steve Naroff88145032009-10-27 14:35:18 +000026/* MSVC DLL import/export. */
John Thompson2e06fc82009-10-27 13:42:56 +000027#ifdef _MSC_VER
28 #ifdef _CINDEX_LIB_
29 #define CINDEX_LINKAGE __declspec(dllexport)
30 #else
31 #define CINDEX_LINKAGE __declspec(dllimport)
32 #endif
33#else
34 #define CINDEX_LINKAGE
35#endif
36
Douglas Gregor20d416c2010-01-20 01:10:47 +000037/** \defgroup CINDEX C Interface to Clang
38 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000039 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000040 * facilities for parsing source code into an abstract syntax tree (AST),
41 * loading already-parsed ASTs, traversing the AST, associating
42 * physical source locations with elements within the AST, and other
43 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000044 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000045 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000046 * representation stored in Clang's C++ AST, nor should it: the intent is to
47 * maintain an API that is relatively stable from one release to the next,
48 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000049 *
50 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000051 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000052 *
53 * @{
54 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000055
Douglas Gregor7f173762010-01-20 22:28:27 +000056/**
57 * \brief An "index" that consists of a set of translation units that would
58 * typically be linked together into an executable or library.
59 */
60typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000061
Douglas Gregor7f173762010-01-20 22:28:27 +000062/**
63 * \brief A single translation unit, which resides in an index.
64 */
Steve Naroff50398192009-08-28 15:28:48 +000065typedef void *CXTranslationUnit; /* A translation unit instance. */
Steve Naroff600866c2009-08-27 19:51:58 +000066
Douglas Gregor7f173762010-01-20 22:28:27 +000067/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000068 * \brief Opaque pointer representing client data that will be passed through
69 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000070 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000071typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000072
Douglas Gregor735df882009-12-02 09:21:34 +000073/**
74 * \brief Provides the contents of a file that has not yet been saved to disk.
75 *
76 * Each CXUnsavedFile instance provides the name of a file on the
77 * system along with the current contents of that file that have not
78 * yet been saved to disk.
79 */
80struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000081 /**
82 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000083 *
84 * This file must already exist in the file system.
85 */
86 const char *Filename;
87
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000088 /**
Douglas Gregor735df882009-12-02 09:21:34 +000089 * \brief A null-terminated buffer containing the unsaved contents
90 * of this file.
91 */
92 const char *Contents;
93
94 /**
95 * \brief The length of the unsaved contents of this buffer, not
96 * counting the NULL at the end of the buffer.
97 */
98 unsigned long Length;
99};
100
Douglas Gregor7f173762010-01-20 22:28:27 +0000101/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000102 * \defgroup CINDEX_STRING String manipulation routines
103 *
104 * @{
105 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000106
Douglas Gregor7f173762010-01-20 22:28:27 +0000107/**
108 * \brief A character string.
109 *
110 * The \c CXString type is used to return strings from the interface when
111 * the ownership of that string might different from one call to the next.
112 * Use \c clang_getCString() to retrieve the string data and, once finished
113 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000114 */
115typedef struct {
116 const char *Spelling;
117 /* A 1 value indicates the clang_ indexing API needed to allocate the string
118 (and it must be freed by clang_disposeString()). */
119 int MustFreeString;
120} CXString;
121
Douglas Gregor7f173762010-01-20 22:28:27 +0000122/**
123 * \brief Retrieve the character data associated with the given string.
124 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000125CINDEX_LINKAGE const char *clang_getCString(CXString string);
126
Douglas Gregor7f173762010-01-20 22:28:27 +0000127/**
128 * \brief Free the given string,
129 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000130CINDEX_LINKAGE void clang_disposeString(CXString string);
131
Douglas Gregor7f173762010-01-20 22:28:27 +0000132/**
133 * @}
134 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000135
136/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000137 * \brief clang_createIndex() provides a shared context for creating
138 * translation units. It provides two options:
139 *
140 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
141 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000142 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000143 * header that was used by the translation unit. If zero, all declarations
144 * will be enumerated.
145 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000146 * Here is an example:
147 *
Douglas Gregor436f3f02010-02-18 22:27:07 +0000148 * // excludeDeclsFromPCH = 1
149 * Idx = clang_createIndex(1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000150 *
151 * // IndexTest.pch was produced with the following command:
152 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
153 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
154 *
155 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000156 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000157 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000158 * clang_disposeTranslationUnit(TU);
159 *
160 * // This will load all the symbols from 'IndexTest.c', excluding symbols
161 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000162 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
163 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
164 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000165 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
166 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000167 * clang_disposeTranslationUnit(TU);
168 *
169 * This process of creating the 'pch', loading it separately, and using it (via
170 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
171 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000172 */
Douglas Gregor436f3f02010-02-18 22:27:07 +0000173CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH);
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000174
175/**
176 * \brief Destroy the given index.
177 *
178 * The index must not be destroyed until all of the translation units created
179 * within that index have been destroyed.
180 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000181CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000182
183/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000184 * \brief Request that AST's be generated externally for API calls which parse
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000185 * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
186 *
187 * Note: This is for debugging purposes only, and may be removed at a later
188 * date.
189 *
190 * \param index - The index to update.
191 * \param value - The new flag value.
192 */
193CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
194 int value);
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +0000195/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000196 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000197 *
198 * @{
199 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000200
Douglas Gregorf5525442010-01-20 22:45:41 +0000201/**
202 * \brief A particular source file that is part of a translation unit.
203 */
204typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000205
Douglas Gregorf5525442010-01-20 22:45:41 +0000206
207/**
208 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000209 */
Ted Kremenek74844072010-02-17 00:41:20 +0000210CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000211
Douglas Gregorf5525442010-01-20 22:45:41 +0000212/**
213 * \brief Retrieve the last modification time of the given file.
214 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000215CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000216
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000217/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000218 * \brief Retrieve a file handle within the given translation unit.
219 *
220 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000221 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000222 * \param file_name the name of the file.
223 *
224 * \returns the file handle for the named file in the translation unit \p tu,
225 * or a NULL file handle if the file was not a part of this translation unit.
226 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000227CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000228 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000229
Douglas Gregorb9790342010-01-22 21:44:22 +0000230/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000231 * @}
232 */
233
234/**
235 * \defgroup CINDEX_LOCATIONS Physical source locations
236 *
237 * Clang represents physical source locations in its abstract syntax tree in
238 * great detail, with file, line, and column information for the majority of
239 * the tokens parsed in the source code. These data types and functions are
240 * used to represent source location information, either for a particular
241 * point in the program or for a range of points in the program, and extract
242 * specific location information from those data types.
243 *
244 * @{
245 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000246
Douglas Gregorf5525442010-01-20 22:45:41 +0000247/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000248 * \brief Identifies a specific source location within a translation
249 * unit.
250 *
251 * Use clang_getInstantiationLocation() to map a source location to a
252 * particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000253 */
254typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000255 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000256 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000257} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000258
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000259/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000260 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000261 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000262 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
263 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000264 */
265typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000266 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000267 unsigned begin_int_data;
268 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000269} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000270
Douglas Gregor1db19de2010-01-19 21:36:55 +0000271/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000272 * \brief Retrieve a NULL (invalid) source location.
273 */
274CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000275
Douglas Gregorb9790342010-01-22 21:44:22 +0000276/**
277 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000278 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000279 * code.
280 *
281 * \returns non-zero if the source locations refer to the same location, zero
282 * if they refer to different locations.
283 */
284CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
285 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000286
Douglas Gregorb9790342010-01-22 21:44:22 +0000287/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000288 * \brief Retrieves the source location associated with a given file/line/column
289 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000290 */
291CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
292 CXFile file,
293 unsigned line,
294 unsigned column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000295
Douglas Gregorb9790342010-01-22 21:44:22 +0000296/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000297 * \brief Retrieve a NULL (invalid) source range.
298 */
299CINDEX_LINKAGE CXSourceRange clang_getNullRange();
300
301/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000302 * \brief Retrieve a source range given the beginning and ending source
303 * locations.
304 */
305CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
306 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000307
Douglas Gregorb9790342010-01-22 21:44:22 +0000308/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000309 * \brief Retrieve the file, line, column, and offset represented by
310 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000311 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000312 * \param location the location within a source file that will be decomposed
313 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000314 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000315 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000316 * source location points.
317 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000318 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000319 * source location points.
320 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000321 * \param column [out] if non-NULL, will be set to the column to which the given
322 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000323 *
324 * \param offset [out] if non-NULL, will be set to the offset into the
325 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000326 */
327CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
328 CXFile *file,
329 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000330 unsigned *column,
331 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000332
333/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000334 * \brief Retrieve a source location representing the first character within a
335 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000336 */
337CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
338
339/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000340 * \brief Retrieve a source location representing the last character within a
341 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000342 */
343CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
344
Douglas Gregorf5525442010-01-20 22:45:41 +0000345/**
346 * @}
347 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000348
349/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000350 * \defgroup CINDEX_DIAG Diagnostic reporting
351 *
352 * @{
353 */
354
355/**
356 * \brief Describes the severity of a particular diagnostic.
357 */
358enum CXDiagnosticSeverity {
359 /**
360 * \brief A diagnostic that has been suppressed, e.g., by a command-line
361 * option.
362 */
363 CXDiagnostic_Ignored = 0,
364
365 /**
366 * \brief This diagnostic is a note that should be attached to the
367 * previous (non-note) diagnostic.
368 */
369 CXDiagnostic_Note = 1,
370
371 /**
372 * \brief This diagnostic indicates suspicious code that may not be
373 * wrong.
374 */
375 CXDiagnostic_Warning = 2,
376
377 /**
378 * \brief This diagnostic indicates that the code is ill-formed.
379 */
380 CXDiagnostic_Error = 3,
381
382 /**
383 * \brief This diagnostic indicates that the code is ill-formed such
384 * that future parser recovery is unlikely to produce useful
385 * results.
386 */
387 CXDiagnostic_Fatal = 4
388};
389
390/**
391 * \brief Describes the kind of fix-it hint expressed within a
392 * diagnostic.
393 */
394enum CXFixItKind {
395 /**
396 * \brief A fix-it hint that inserts code at a particular position.
397 */
398 CXFixIt_Insertion = 0,
399
400 /**
401 * \brief A fix-it hint that removes code within a range.
402 */
403 CXFixIt_Removal = 1,
404
405 /**
406 * \brief A fix-it hint that replaces the code within a range with another
407 * string.
408 */
409 CXFixIt_Replacement = 2
410};
411
412/**
413 * \brief A single diagnostic, containing the diagnostic's severity,
414 * location, text, source ranges, and fix-it hints.
415 */
416typedef void *CXDiagnostic;
417
418/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000419 * \brief Determine the number of diagnostics produced for the given
420 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000421 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000422CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
423
424/**
425 * \brief Retrieve a diagnostic associated with the given translation unit.
426 *
427 * \param Unit the translation unit to query.
428 * \param Index the zero-based diagnostic number to retrieve.
429 *
430 * \returns the requested diagnostic. This diagnostic must be freed
431 * via a call to \c clang_disposeDiagnostic().
432 */
433CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
434 unsigned Index);
435
436/**
437 * \brief Destroy a diagnostic.
438 */
439CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000440
441/**
442 * \brief Determine the severity of the given diagnostic.
443 */
444CINDEX_LINKAGE enum CXDiagnosticSeverity
445clang_getDiagnosticSeverity(CXDiagnostic);
446
447/**
448 * \brief Retrieve the source location of the given diagnostic.
449 *
450 * This location is where Clang would print the caret ('^') when
451 * displaying the diagnostic on the command line.
452 */
453CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
454
455/**
456 * \brief Retrieve the text of the given diagnostic.
457 */
458CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000459
460/**
461 * \brief Determine the number of source ranges associated with the given
462 * diagnostic.
463 */
464CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000465
466/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000467 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000468 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000469 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000470 * code. On the command line, Clang displays source ranges by
471 * underlining them with '~' characters.
472 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000473 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000474 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000475 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000476 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000477 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000478 */
Douglas Gregora3890ba2010-02-08 23:11:56 +0000479CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
480 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000481
482/**
483 * \brief Determine the number of fix-it hints associated with the
484 * given diagnostic.
485 */
486CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
487
488/**
489 * \brief Retrieve the kind of the given fix-it.
490 *
491 * \param Diagnostic the diagnostic whose fix-its are being queried.
492 *
493 * \param FixIt the zero-based index of the fix-it to query.
494 */
495CINDEX_LINKAGE enum CXFixItKind
496clang_getDiagnosticFixItKind(CXDiagnostic Diagnostic, unsigned FixIt);
497
498/**
499 * \brief Retrieve the insertion information for an insertion fix-it.
500 *
501 * For a fix-it that describes an insertion into a text buffer,
502 * retrieve the source location where the text should be inserted and
503 * the text to be inserted.
504 *
505 * \param Diagnostic the diagnostic whose fix-its are being queried.
506 *
507 * \param FixIt the zero-based index of the insertion fix-it.
508 *
509 * \param Location will be set to the location where text should be
510 * inserted.
511 *
512 * \returns the text string to insert at the given location.
513 */
514CINDEX_LINKAGE CXString
515clang_getDiagnosticFixItInsertion(CXDiagnostic Diagnostic, unsigned FixIt,
516 CXSourceLocation *Location);
517
518/**
519 * \brief Retrieve the removal information for a removal fix-it.
520 *
521 * For a fix-it that describes a removal from a text buffer, retrieve
522 * the source range that should be removed.
523 *
524 * \param Diagnostic the diagnostic whose fix-its are being queried.
525 *
526 * \param FixIt the zero-based index of the removal fix-it.
527 *
528 * \returns a source range describing the text that should be removed
529 * from the buffer.
530 */
531CINDEX_LINKAGE CXSourceRange
532clang_getDiagnosticFixItRemoval(CXDiagnostic Diagnostic, unsigned FixIt);
533
534/**
535 * \brief Retrieve the replacement information for an replacement fix-it.
536 *
537 * For a fix-it that describes replacement of text in the text buffer
538 * with alternative text.
539 *
540 * \param Diagnostic the diagnostic whose fix-its are being queried.
541 *
542 * \param FixIt the zero-based index of the replacement fix-it.
543 *
544 * \param Range will be set to the source range whose text should be
545 * replaced with the returned text.
546 *
547 * \returns the text string to use as replacement text.
548 */
549CINDEX_LINKAGE CXString
550clang_getDiagnosticFixItReplacement(CXDiagnostic Diagnostic, unsigned FixIt,
551 CXSourceRange *Range);
552
553/**
554 * @}
555 */
556
557/**
558 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
559 *
560 * The routines in this group provide the ability to create and destroy
561 * translation units from files, either by parsing the contents of the files or
562 * by reading in a serialized representation of a translation unit.
563 *
564 * @{
565 */
566
567/**
568 * \brief Get the original translation unit source file name.
569 */
570CINDEX_LINKAGE CXString
571clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
572
573/**
574 * \brief Return the CXTranslationUnit for a given source file and the provided
575 * command line arguments one would pass to the compiler.
576 *
577 * Note: The 'source_filename' argument is optional. If the caller provides a
578 * NULL pointer, the name of the source file is expected to reside in the
579 * specified command line arguments.
580 *
581 * Note: When encountered in 'clang_command_line_args', the following options
582 * are ignored:
583 *
584 * '-c'
585 * '-emit-ast'
586 * '-fsyntax-only'
587 * '-o <output file>' (both '-o' and '<output file>' are ignored)
588 *
589 *
590 * \param source_filename - The name of the source file to load, or NULL if the
591 * source file is included in clang_command_line_args.
592 *
593 * \param num_unsaved_files the number of unsaved file entries in \p
594 * unsaved_files.
595 *
596 * \param unsaved_files the files that have not yet been saved to disk
597 * but may be required for code completion, including the contents of
598 * those files.
599 *
600 * \param diag_callback callback function that will receive any diagnostics
601 * emitted while processing this source file. If NULL, diagnostics will be
602 * suppressed.
603 *
604 * \param diag_client_data client data that will be passed to the diagnostic
605 * callback function.
606 */
607CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
608 CXIndex CIdx,
609 const char *source_filename,
610 int num_clang_command_line_args,
611 const char **clang_command_line_args,
612 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000613 struct CXUnsavedFile *unsaved_files);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000614
615/**
616 * \brief Create a translation unit from an AST file (-emit-ast).
617 */
618CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000619 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000620
621/**
622 * \brief Destroy the specified CXTranslationUnit object.
623 */
624CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
625
626/**
627 * @}
628 */
629
630/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000631 * \brief Describes the kind of entity that a cursor refers to.
632 */
633enum CXCursorKind {
634 /* Declarations */
635 CXCursor_FirstDecl = 1,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000636 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000637 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000638 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000639 *
640 * Unexposed declarations have the same operations as any other kind
641 * of declaration; one can extract their location information,
642 * spelling, find their definitions, etc. However, the specific kind
643 * of the declaration is not reported.
644 */
645 CXCursor_UnexposedDecl = 1,
646 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000647 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000648 /** \brief A C or C++ union. */
649 CXCursor_UnionDecl = 3,
650 /** \brief A C++ class. */
651 CXCursor_ClassDecl = 4,
652 /** \brief An enumeration. */
653 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000654 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000655 * \brief A field (in C) or non-static data member (in C++) in a
656 * struct, union, or C++ class.
657 */
658 CXCursor_FieldDecl = 6,
659 /** \brief An enumerator constant. */
660 CXCursor_EnumConstantDecl = 7,
661 /** \brief A function. */
662 CXCursor_FunctionDecl = 8,
663 /** \brief A variable. */
664 CXCursor_VarDecl = 9,
665 /** \brief A function or method parameter. */
666 CXCursor_ParmDecl = 10,
667 /** \brief An Objective-C @interface. */
668 CXCursor_ObjCInterfaceDecl = 11,
669 /** \brief An Objective-C @interface for a category. */
670 CXCursor_ObjCCategoryDecl = 12,
671 /** \brief An Objective-C @protocol declaration. */
672 CXCursor_ObjCProtocolDecl = 13,
673 /** \brief An Objective-C @property declaration. */
674 CXCursor_ObjCPropertyDecl = 14,
675 /** \brief An Objective-C instance variable. */
676 CXCursor_ObjCIvarDecl = 15,
677 /** \brief An Objective-C instance method. */
678 CXCursor_ObjCInstanceMethodDecl = 16,
679 /** \brief An Objective-C class method. */
680 CXCursor_ObjCClassMethodDecl = 17,
681 /** \brief An Objective-C @implementation. */
682 CXCursor_ObjCImplementationDecl = 18,
683 /** \brief An Objective-C @implementation for a category. */
684 CXCursor_ObjCCategoryImplDecl = 19,
685 /** \brief A typedef */
686 CXCursor_TypedefDecl = 20,
687 CXCursor_LastDecl = 20,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000688
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000689 /* References */
690 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000691 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000692 CXCursor_ObjCProtocolRef = 41,
693 CXCursor_ObjCClassRef = 42,
694 /**
695 * \brief A reference to a type declaration.
696 *
697 * A type reference occurs anywhere where a type is named but not
698 * declared. For example, given:
699 *
700 * \code
701 * typedef unsigned size_type;
702 * size_type size;
703 * \endcode
704 *
705 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
706 * while the type of the variable "size" is referenced. The cursor
707 * referenced by the type of size is the typedef for size_type.
708 */
709 CXCursor_TypeRef = 43,
710 CXCursor_LastRef = 43,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000711
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000712 /* Error conditions */
713 CXCursor_FirstInvalid = 70,
714 CXCursor_InvalidFile = 70,
715 CXCursor_NoDeclFound = 71,
716 CXCursor_NotImplemented = 72,
717 CXCursor_LastInvalid = 72,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000718
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000719 /* Expressions */
720 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000721
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000722 /**
723 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000724 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000725 *
726 * Unexposed expressions have the same operations as any other kind
727 * of expression; one can extract their location information,
728 * spelling, children, etc. However, the specific kind of the
729 * expression is not reported.
730 */
731 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000732
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000733 /**
734 * \brief An expression that refers to some value declaration, such
735 * as a function, varible, or enumerator.
736 */
737 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000738
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000739 /**
740 * \brief An expression that refers to a member of a struct, union,
741 * class, Objective-C class, etc.
742 */
743 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000744
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000745 /** \brief An expression that calls a function. */
746 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000747
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000748 /** \brief An expression that sends a message to an Objective-C
749 object or class. */
750 CXCursor_ObjCMessageExpr = 104,
751 CXCursor_LastExpr = 104,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000752
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000753 /* Statements */
754 CXCursor_FirstStmt = 200,
755 /**
756 * \brief A statement whose specific kind is not exposed via this
757 * interface.
758 *
759 * Unexposed statements have the same operations as any other kind of
760 * statement; one can extract their location information, spelling,
761 * children, etc. However, the specific kind of the statement is not
762 * reported.
763 */
764 CXCursor_UnexposedStmt = 200,
765 CXCursor_LastStmt = 200,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000766
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000767 /**
768 * \brief Cursor that represents the translation unit itself.
769 *
770 * The translation unit cursor exists primarily to act as the root
771 * cursor for traversing the contents of a translation unit.
772 */
Ted Kremeneke77f4432010-02-18 03:09:07 +0000773 CXCursor_TranslationUnit = 300,
774
775 /* Attributes */
776 CXCursor_FirstAttr = 400,
777 /**
778 * \brief An attribute whose specific kind is not exposed via this
779 * interface.
780 */
781 CXCursor_UnexposedAttr = 400,
782
783 CXCursor_IBActionAttr = 401,
784 CXCursor_IBOutletAttr = 402,
785 CXCursor_LastAttr = CXCursor_IBOutletAttr
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000786};
787
788/**
789 * \brief A cursor representing some element in the abstract syntax tree for
790 * a translation unit.
791 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000792 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000793 * program--declaration, statements, expressions, references to declarations,
794 * etc.--under a single "cursor" abstraction with a common set of operations.
795 * Common operation for a cursor include: getting the physical location in
796 * a source file where the cursor points, getting the name associated with a
797 * cursor, and retrieving cursors for any child nodes of a particular cursor.
798 *
799 * Cursors can be produced in two specific ways.
800 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
801 * from which one can use clang_visitChildren() to explore the rest of the
802 * translation unit. clang_getCursor() maps from a physical source location
803 * to the entity that resides at that location, allowing one to map from the
804 * source code into the AST.
805 */
806typedef struct {
807 enum CXCursorKind kind;
808 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000809} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000810
811/**
812 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
813 *
814 * @{
815 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000816
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000817/**
818 * \brief Retrieve the NULL cursor, which represents no entity.
819 */
820CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000821
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000822/**
823 * \brief Retrieve the cursor that represents the given translation unit.
824 *
825 * The translation unit cursor can be used to start traversing the
826 * various declarations within the given translation unit.
827 */
828CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
829
830/**
831 * \brief Determine whether two cursors are equivalent.
832 */
833CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000834
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000835/**
836 * \brief Retrieve the kind of the given cursor.
837 */
838CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
839
840/**
841 * \brief Determine whether the given cursor kind represents a declaration.
842 */
843CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
844
845/**
846 * \brief Determine whether the given cursor kind represents a simple
847 * reference.
848 *
849 * Note that other kinds of cursors (such as expressions) can also refer to
850 * other cursors. Use clang_getCursorReferenced() to determine whether a
851 * particular cursor refers to another entity.
852 */
853CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
854
855/**
856 * \brief Determine whether the given cursor kind represents an expression.
857 */
858CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
859
860/**
861 * \brief Determine whether the given cursor kind represents a statement.
862 */
863CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
864
865/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000866 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000867 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000868 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000869CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
870
871/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000872 * \brief Determine whether the given cursor kind represents a translation
873 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000874 */
875CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000876
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000877/**
878 * @}
879 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000880
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000881/**
882 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
883 *
884 * Cursors represent a location within the Abstract Syntax Tree (AST). These
885 * routines help map between cursors and the physical locations where the
886 * described entities occur in the source code. The mapping is provided in
887 * both directions, so one can map from source code to the AST and back.
888 *
889 * @{
Steve Naroff50398192009-08-28 15:28:48 +0000890 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000891
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000892/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000893 * \brief Map a source location to the cursor that describes the entity at that
894 * location in the source code.
895 *
896 * clang_getCursor() maps an arbitrary source location within a translation
897 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000898 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +0000899 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000900 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +0000901 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
902 * will return a cursor referring to the "+" expression.
903 *
904 * \returns a cursor representing the entity at the given source location, or
905 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000906 */
Douglas Gregorb9790342010-01-22 21:44:22 +0000907CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000908
Douglas Gregor98258af2010-01-18 22:46:11 +0000909/**
910 * \brief Retrieve the physical location of the source constructor referenced
911 * by the given cursor.
912 *
913 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000914 * declaration, where the name of that declaration would occur if it is
915 * unnamed, or some keyword that introduces that particular declaration.
916 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +0000917 * source code.
918 */
919CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000920
Douglas Gregorb6998662010-01-19 19:34:47 +0000921/**
922 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +0000923 * the given cursor.
924 *
925 * The extent of a cursor starts with the file/line/column pointing at the
926 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000927 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +0000928 * declaration, the extent covers the declaration itself. For a reference,
929 * the extent covers the location of the reference (e.g., where the referenced
930 * entity was actually used).
931 */
932CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +0000933
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000934/**
935 * @}
936 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000937
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000938/**
939 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
940 *
941 * These routines provide the ability to traverse the abstract syntax tree
942 * using cursors.
943 *
944 * @{
945 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000946
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000947/**
948 * \brief Describes how the traversal of the children of a particular
949 * cursor should proceed after visiting a particular child cursor.
950 *
951 * A value of this enumeration type should be returned by each
952 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
953 */
954enum CXChildVisitResult {
955 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000956 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000957 */
958 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000959 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000960 * \brief Continues the cursor traversal with the next sibling of
961 * the cursor just visited, without visiting its children.
962 */
963 CXChildVisit_Continue,
964 /**
965 * \brief Recursively traverse the children of this cursor, using
966 * the same visitor and client data.
967 */
968 CXChildVisit_Recurse
969};
970
971/**
972 * \brief Visitor invoked for each cursor found by a traversal.
973 *
974 * This visitor function will be invoked for each cursor found by
975 * clang_visitCursorChildren(). Its first argument is the cursor being
976 * visited, its second argument is the parent visitor for that cursor,
977 * and its third argument is the client data provided to
978 * clang_visitCursorChildren().
979 *
980 * The visitor should return one of the \c CXChildVisitResult values
981 * to direct clang_visitCursorChildren().
982 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000983typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
984 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000985 CXClientData client_data);
986
987/**
988 * \brief Visit the children of a particular cursor.
989 *
990 * This function visits all the direct children of the given cursor,
991 * invoking the given \p visitor function with the cursors of each
992 * visited child. The traversal may be recursive, if the visitor returns
993 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
994 * the visitor returns \c CXChildVisit_Break.
995 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000996 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +0000997 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000998 * definition, have no children).
999 *
1000 * \param visitor the visitor function that will be invoked for each
1001 * child of \p parent.
1002 *
1003 * \param client_data pointer data supplied by the client, which will
1004 * be passed to the visitor each time it is invoked.
1005 *
1006 * \returns a non-zero value if the traversal was terminated
1007 * prematurely by the visitor returning \c CXChildVisit_Break.
1008 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001009CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001010 CXCursorVisitor visitor,
1011 CXClientData client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001012
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001013/**
1014 * @}
1015 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001016
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001017/**
1018 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1019 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001020 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001021 * across translation units, by providing the names of the entities referenced
1022 * by cursors, follow reference cursors to the declarations they reference,
1023 * and associate declarations with their definitions.
1024 *
1025 * @{
1026 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001027
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001028/**
1029 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1030 * by the given cursor.
1031 *
1032 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1033 * entity (function, class, variable, etc.) within a program. USRs can be
1034 * compared across translation units to determine, e.g., when references in
1035 * one translation refer to an entity defined in another translation unit.
1036 */
1037CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1038
1039/**
1040 * \brief Retrieve a name for the entity referenced by this cursor.
1041 */
1042CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1043
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001044/** \brief For a cursor that is a reference, retrieve a cursor representing the
1045 * entity that it references.
1046 *
1047 * Reference cursors refer to other entities in the AST. For example, an
1048 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001049 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001050 * cursor for the superclass reference. If the input cursor is a declaration or
1051 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001052 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001053 */
1054CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001055
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001056/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001057 * \brief For a cursor that is either a reference to or a declaration
1058 * of some entity, retrieve a cursor that describes the definition of
1059 * that entity.
1060 *
1061 * Some entities can be declared multiple times within a translation
1062 * unit, but only one of those declarations can also be a
1063 * definition. For example, given:
1064 *
1065 * \code
1066 * int f(int, int);
1067 * int g(int x, int y) { return f(x, y); }
1068 * int f(int a, int b) { return a + b; }
1069 * int f(int, int);
1070 * \endcode
1071 *
1072 * there are three declarations of the function "f", but only the
1073 * second one is a definition. The clang_getCursorDefinition()
1074 * function will take any cursor pointing to a declaration of "f"
1075 * (the first or fourth lines of the example) or a cursor referenced
1076 * that uses "f" (the call to "f' inside "g") and will return a
1077 * declaration cursor pointing to the definition (the second "f"
1078 * declaration).
1079 *
1080 * If given a cursor for which there is no corresponding definition,
1081 * e.g., because there is no definition of that entity within this
1082 * translation unit, returns a NULL cursor.
1083 */
1084CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1085
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001086/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001087 * \brief Determine whether the declaration pointed to by this cursor
1088 * is also a definition of that entity.
1089 */
1090CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1091
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001092/**
1093 * @}
1094 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001095
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001096/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001097 * \defgroup CINDEX_LEX Token extraction and manipulation
1098 *
1099 * The routines in this group provide access to the tokens within a
1100 * translation unit, along with a semantic mapping of those tokens to
1101 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001102 *
1103 * @{
1104 */
1105
1106/**
1107 * \brief Describes a kind of token.
1108 */
1109typedef enum CXTokenKind {
1110 /**
1111 * \brief A token that contains some kind of punctuation.
1112 */
1113 CXToken_Punctuation,
1114
1115 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001116 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001117 */
1118 CXToken_Keyword,
1119
1120 /**
1121 * \brief An identifier (that is not a keyword).
1122 */
1123 CXToken_Identifier,
1124
1125 /**
1126 * \brief A numeric, string, or character literal.
1127 */
1128 CXToken_Literal,
1129
1130 /**
1131 * \brief A comment.
1132 */
1133 CXToken_Comment
1134} CXTokenKind;
1135
1136/**
1137 * \brief Describes a single preprocessing token.
1138 */
1139typedef struct {
1140 unsigned int_data[4];
1141 void *ptr_data;
1142} CXToken;
1143
1144/**
1145 * \brief Determine the kind of the given token.
1146 */
1147CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
1148
1149/**
1150 * \brief Determine the spelling of the given token.
1151 *
1152 * The spelling of a token is the textual representation of that token, e.g.,
1153 * the text of an identifier or keyword.
1154 */
1155CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
1156
1157/**
1158 * \brief Retrieve the source location of the given token.
1159 */
1160CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
1161 CXToken);
1162
1163/**
1164 * \brief Retrieve a source range that covers the given token.
1165 */
1166CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
1167
1168/**
1169 * \brief Tokenize the source code described by the given range into raw
1170 * lexical tokens.
1171 *
1172 * \param TU the translation unit whose text is being tokenized.
1173 *
1174 * \param Range the source range in which text should be tokenized. All of the
1175 * tokens produced by tokenization will fall within this source range,
1176 *
1177 * \param Tokens this pointer will be set to point to the array of tokens
1178 * that occur within the given source range. The returned pointer must be
1179 * freed with clang_disposeTokens() before the translation unit is destroyed.
1180 *
1181 * \param NumTokens will be set to the number of tokens in the \c *Tokens
1182 * array.
1183 *
1184 */
1185CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
1186 CXToken **Tokens, unsigned *NumTokens);
1187
1188/**
1189 * \brief Annotate the given set of tokens by providing cursors for each token
1190 * that can be mapped to a specific entity within the abstract syntax tree.
1191 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001192 * This token-annotation routine is equivalent to invoking
1193 * clang_getCursor() for the source locations of each of the
1194 * tokens. The cursors provided are filtered, so that only those
1195 * cursors that have a direct correspondence to the token are
1196 * accepted. For example, given a function call \c f(x),
1197 * clang_getCursor() would provide the following cursors:
1198 *
1199 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
1200 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
1201 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
1202 *
1203 * Only the first and last of these cursors will occur within the
1204 * annotate, since the tokens "f" and "x' directly refer to a function
1205 * and a variable, respectively, but the parentheses are just a small
1206 * part of the full syntax of the function call expression, which is
1207 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001208 *
1209 * \param TU the translation unit that owns the given tokens.
1210 *
1211 * \param Tokens the set of tokens to annotate.
1212 *
1213 * \param NumTokens the number of tokens in \p Tokens.
1214 *
1215 * \param Cursors an array of \p NumTokens cursors, whose contents will be
1216 * replaced with the cursors corresponding to each token.
1217 */
1218CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
1219 CXToken *Tokens, unsigned NumTokens,
1220 CXCursor *Cursors);
1221
1222/**
1223 * \brief Free the given set of tokens.
1224 */
1225CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
1226 CXToken *Tokens, unsigned NumTokens);
1227
1228/**
1229 * @}
1230 */
1231
1232/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001233 * \defgroup CINDEX_DEBUG Debugging facilities
1234 *
1235 * These routines are used for testing and debugging, only, and should not
1236 * be relied upon.
1237 *
1238 * @{
1239 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001240
Steve Naroff4ade6d62009-09-23 17:52:52 +00001241/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00001242CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001243CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
1244 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00001245 const char **endBuf,
1246 unsigned *startLine,
1247 unsigned *startColumn,
1248 unsigned *endLine,
1249 unsigned *endColumn);
Douglas Gregor436f3f02010-02-18 22:27:07 +00001250
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001251/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001252 * @}
1253 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001254
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001255/**
1256 * \defgroup CINDEX_CODE_COMPLET Code completion
1257 *
1258 * Code completion involves taking an (incomplete) source file, along with
1259 * knowledge of where the user is actively editing that file, and suggesting
1260 * syntactically- and semantically-valid constructs that the user might want to
1261 * use at that particular point in the source code. These data structures and
1262 * routines provide support for code completion.
1263 *
1264 * @{
1265 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001266
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001267/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001268 * \brief A semantic string that describes a code-completion result.
1269 *
1270 * A semantic string that describes the formatting of a code-completion
1271 * result as a single "template" of text that should be inserted into the
1272 * source buffer when a particular code-completion result is selected.
1273 * Each semantic string is made up of some number of "chunks", each of which
1274 * contains some text along with a description of what that text means, e.g.,
1275 * the name of the entity being referenced, whether the text chunk is part of
1276 * the template, or whether it is a "placeholder" that the user should replace
1277 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001278 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001279 */
1280typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001281
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001282/**
1283 * \brief A single result of code completion.
1284 */
1285typedef struct {
1286 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001287 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001288 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001289 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001290 * *Decl cursor kinds), describing the entity that the completion is
1291 * referring to.
1292 *
1293 * \todo In the future, we would like to provide a full cursor, to allow
1294 * the client to extract additional information from declaration.
1295 */
1296 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001297
1298 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001299 * \brief The code-completion string that describes how to insert this
1300 * code-completion result into the editing buffer.
1301 */
1302 CXCompletionString CompletionString;
1303} CXCompletionResult;
1304
1305/**
1306 * \brief Describes a single piece of text within a code-completion string.
1307 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001308 * Each "chunk" within a code-completion string (\c CXCompletionString) is
1309 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001310 * should be interpreted by the client or is another completion string.
1311 */
1312enum CXCompletionChunkKind {
1313 /**
1314 * \brief A code-completion string that describes "optional" text that
1315 * could be a part of the template (but is not required).
1316 *
1317 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001318 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001319 * \c clang_getCompletionChunkCompletionString(). The code-completion string
1320 * describes an additional part of the template that is completely optional.
1321 * For example, optional chunks can be used to describe the placeholders for
1322 * arguments that match up with defaulted function parameters, e.g. given:
1323 *
1324 * \code
1325 * void f(int x, float y = 3.14, double z = 2.71828);
1326 * \endcode
1327 *
1328 * The code-completion string for this function would contain:
1329 * - a TypedText chunk for "f".
1330 * - a LeftParen chunk for "(".
1331 * - a Placeholder chunk for "int x"
1332 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
1333 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00001334 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001335 * - an Optional chunk containing the last defaulted argument:
1336 * - a Comma chunk for ","
1337 * - a Placeholder chunk for "double z"
1338 * - a RightParen chunk for ")"
1339 *
Daniel Dunbar71570182010-02-17 08:07:44 +00001340 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001341 * - Completely ignore optional chunks, in which case the template for the
1342 * function "f" would only include the first parameter ("int x").
1343 * - Fully expand all optional chunks, in which case the template for the
1344 * function "f" would have all of the parameters.
1345 */
1346 CXCompletionChunk_Optional,
1347 /**
1348 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001349 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001350 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001351 * There will be exactly one "typed text" chunk in a semantic string, which
1352 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001353 * declaration that could be used at the current code point. Clients are
1354 * expected to filter the code-completion results based on the text in this
1355 * chunk.
1356 */
1357 CXCompletionChunk_TypedText,
1358 /**
1359 * \brief Text that should be inserted as part of a code-completion result.
1360 *
1361 * A "text" chunk represents text that is part of the template to be
1362 * inserted into user code should this particular code-completion result
1363 * be selected.
1364 */
1365 CXCompletionChunk_Text,
1366 /**
1367 * \brief Placeholder text that should be replaced by the user.
1368 *
1369 * A "placeholder" chunk marks a place where the user should insert text
1370 * into the code-completion template. For example, placeholders might mark
1371 * the function parameters for a function declaration, to indicate that the
1372 * user should provide arguments for each of those parameters. The actual
1373 * text in a placeholder is a suggestion for the text to display before
1374 * the user replaces the placeholder with real code.
1375 */
1376 CXCompletionChunk_Placeholder,
1377 /**
1378 * \brief Informative text that should be displayed but never inserted as
1379 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001380 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001381 * An "informative" chunk contains annotations that can be displayed to
1382 * help the user decide whether a particular code-completion result is the
1383 * right option, but which is not part of the actual template to be inserted
1384 * by code completion.
1385 */
1386 CXCompletionChunk_Informative,
1387 /**
1388 * \brief Text that describes the current parameter when code-completion is
1389 * referring to function call, message send, or template specialization.
1390 *
1391 * A "current parameter" chunk occurs when code-completion is providing
1392 * information about a parameter corresponding to the argument at the
1393 * code-completion point. For example, given a function
1394 *
1395 * \code
1396 * int add(int x, int y);
1397 * \endcode
1398 *
1399 * and the source code \c add(, where the code-completion point is after the
1400 * "(", the code-completion string will contain a "current parameter" chunk
1401 * for "int x", indicating that the current argument will initialize that
1402 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001403 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001404 * "current paremeter" chunk to "int y".
1405 */
1406 CXCompletionChunk_CurrentParameter,
1407 /**
1408 * \brief A left parenthesis ('('), used to initiate a function call or
1409 * signal the beginning of a function parameter list.
1410 */
1411 CXCompletionChunk_LeftParen,
1412 /**
1413 * \brief A right parenthesis (')'), used to finish a function call or
1414 * signal the end of a function parameter list.
1415 */
1416 CXCompletionChunk_RightParen,
1417 /**
1418 * \brief A left bracket ('[').
1419 */
1420 CXCompletionChunk_LeftBracket,
1421 /**
1422 * \brief A right bracket (']').
1423 */
1424 CXCompletionChunk_RightBracket,
1425 /**
1426 * \brief A left brace ('{').
1427 */
1428 CXCompletionChunk_LeftBrace,
1429 /**
1430 * \brief A right brace ('}').
1431 */
1432 CXCompletionChunk_RightBrace,
1433 /**
1434 * \brief A left angle bracket ('<').
1435 */
1436 CXCompletionChunk_LeftAngle,
1437 /**
1438 * \brief A right angle bracket ('>').
1439 */
1440 CXCompletionChunk_RightAngle,
1441 /**
1442 * \brief A comma separator (',').
1443 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001444 CXCompletionChunk_Comma,
1445 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001446 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001447 *
1448 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001449 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001450 * expression using the given completion string would have.
1451 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00001452 CXCompletionChunk_ResultType,
1453 /**
1454 * \brief A colon (':').
1455 */
1456 CXCompletionChunk_Colon,
1457 /**
1458 * \brief A semicolon (';').
1459 */
1460 CXCompletionChunk_SemiColon,
1461 /**
1462 * \brief An '=' sign.
1463 */
1464 CXCompletionChunk_Equal,
1465 /**
1466 * Horizontal space (' ').
1467 */
1468 CXCompletionChunk_HorizontalSpace,
1469 /**
1470 * Vertical space ('\n'), after which it is generally a good idea to
1471 * perform indentation.
1472 */
1473 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001474};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001475
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001476/**
1477 * \brief Determine the kind of a particular chunk within a completion string.
1478 *
1479 * \param completion_string the completion string to query.
1480 *
1481 * \param chunk_number the 0-based index of the chunk in the completion string.
1482 *
1483 * \returns the kind of the chunk at the index \c chunk_number.
1484 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001485CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001486clang_getCompletionChunkKind(CXCompletionString completion_string,
1487 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001488
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001489/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001490 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001491 * completion string.
1492 *
1493 * \param completion_string the completion string to query.
1494 *
1495 * \param chunk_number the 0-based index of the chunk in the completion string.
1496 *
1497 * \returns the text associated with the chunk at index \c chunk_number.
1498 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00001499CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001500clang_getCompletionChunkText(CXCompletionString completion_string,
1501 unsigned chunk_number);
1502
1503/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001504 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001505 * within a completion string.
1506 *
1507 * \param completion_string the completion string to query.
1508 *
1509 * \param chunk_number the 0-based index of the chunk in the completion string.
1510 *
1511 * \returns the completion string associated with the chunk at index
1512 * \c chunk_number, or NULL if that chunk is not represented by a completion
1513 * string.
1514 */
1515CINDEX_LINKAGE CXCompletionString
1516clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
1517 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001518
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001519/**
1520 * \brief Retrieve the number of chunks in the given code-completion string.
1521 */
1522CINDEX_LINKAGE unsigned
1523clang_getNumCompletionChunks(CXCompletionString completion_string);
1524
1525/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00001526 * \brief Contains the results of code-completion.
1527 *
1528 * This data structure contains the results of code completion, as
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001529 * produced by \c clang_codeComplete. Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00001530 * \c clang_disposeCodeCompleteResults.
1531 */
1532typedef struct {
1533 /**
1534 * \brief The code-completion results.
1535 */
1536 CXCompletionResult *Results;
1537
1538 /**
1539 * \brief The number of code-completion results stored in the
1540 * \c Results array.
1541 */
1542 unsigned NumResults;
1543} CXCodeCompleteResults;
1544
1545/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001546 * \brief Perform code completion at a given location in a source file.
1547 *
1548 * This function performs code completion at a particular file, line, and
1549 * column within source code, providing results that suggest potential
1550 * code snippets based on the context of the completion. The basic model
1551 * for code completion is that Clang will parse a complete source file,
1552 * performing syntax checking up to the location where code-completion has
1553 * been requested. At that point, a special code-completion token is passed
1554 * to the parser, which recognizes this token and determines, based on the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001555 * current location in the C/Objective-C/C++ grammar and the state of
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001556 * semantic analysis, what completions to provide. These completions are
Douglas Gregorec6762c2009-12-18 16:20:58 +00001557 * returned via a new \c CXCodeCompleteResults structure.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001558 *
1559 * Code completion itself is meant to be triggered by the client when the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001560 * user types punctuation characters or whitespace, at which point the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001561 * code-completion location will coincide with the cursor. For example, if \c p
1562 * is a pointer, code-completion might be triggered after the "-" and then
1563 * after the ">" in \c p->. When the code-completion location is afer the ">",
1564 * the completion results will provide, e.g., the members of the struct that
1565 * "p" points to. The client is responsible for placing the cursor at the
1566 * beginning of the token currently being typed, then filtering the results
1567 * based on the contents of the token. For example, when code-completing for
1568 * the expression \c p->get, the client should provide the location just after
1569 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
1570 * client can filter the results based on the current token text ("get"), only
1571 * showing those results that start with "get". The intent of this interface
Douglas Gregorec6762c2009-12-18 16:20:58 +00001572 * is to separate the relatively high-latency acquisition of code-completion
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001573 * results from the filtering of results on a per-character basis, which must
1574 * have a lower latency.
1575 *
1576 * \param CIdx the \c CXIndex instance that will be used to perform code
1577 * completion.
1578 *
Daniel Dunbar8506dde2009-12-03 01:54:28 +00001579 * \param source_filename the name of the source file that should be parsed to
1580 * perform code-completion. This source file must be the same as or include the
1581 * filename described by \p complete_filename, or no code-completion results
1582 * will be produced. NOTE: One can also specify NULL for this argument if the
1583 * source file is included in command_line_args.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001584 *
1585 * \param num_command_line_args the number of command-line arguments stored in
1586 * \p command_line_args.
1587 *
1588 * \param command_line_args the command-line arguments to pass to the Clang
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001589 * compiler to build the given source file. This should include all of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001590 * necessary include paths, language-dialect switches, precompiled header
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001591 * includes, etc., but should not include any information specific to
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001592 * code completion.
1593 *
Douglas Gregor735df882009-12-02 09:21:34 +00001594 * \param num_unsaved_files the number of unsaved file entries in \p
1595 * unsaved_files.
1596 *
1597 * \param unsaved_files the files that have not yet been saved to disk
1598 * but may be required for code completion, including the contents of
1599 * those files.
1600 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001601 * \param complete_filename the name of the source file where code completion
1602 * should be performed. In many cases, this name will be the same as the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001603 * source filename. However, the completion filename may also be a file
1604 * included by the source file, which is required when producing
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001605 * code-completion results for a header.
1606 *
1607 * \param complete_line the line at which code-completion should occur.
1608 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001609 * \param complete_column the column at which code-completion should occur.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001610 * Note that the column should point just after the syntactic construct that
1611 * initiated code completion, and not in the middle of a lexical token.
1612 *
Douglas Gregor936ea3b2010-01-28 00:56:43 +00001613 * \param diag_callback callback function that will receive any diagnostics
1614 * emitted while processing this source file. If NULL, diagnostics will be
1615 * suppressed.
1616 *
1617 * \param diag_client_data client data that will be passed to the diagnostic
1618 * callback function.
1619 *
Douglas Gregorec6762c2009-12-18 16:20:58 +00001620 * \returns if successful, a new CXCodeCompleteResults structure
1621 * containing code-completion results, which should eventually be
1622 * freed with \c clang_disposeCodeCompleteResults(). If code
1623 * completion fails, returns NULL.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001624 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001625CINDEX_LINKAGE
1626CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001627 const char *source_filename,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001628 int num_command_line_args,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001629 const char **command_line_args,
1630 unsigned num_unsaved_files,
1631 struct CXUnsavedFile *unsaved_files,
1632 const char *complete_filename,
1633 unsigned complete_line,
Douglas Gregora88084b2010-02-18 18:08:43 +00001634 unsigned complete_column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001635
Douglas Gregorec6762c2009-12-18 16:20:58 +00001636/**
1637 * \brief Free the given set of code-completion results.
1638 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001639CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00001640void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001641
Douglas Gregor20d416c2010-01-20 01:10:47 +00001642/**
Douglas Gregora88084b2010-02-18 18:08:43 +00001643 * \brief Determine the number of diagnostics produced prior to the
1644 * location where code completion was performed.
1645 */
1646CINDEX_LINKAGE
1647unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
1648
1649/**
1650 * \brief Retrieve a diagnostic associated with the given code completion.
1651 *
1652 * \param Result the code completion results to query.
1653 * \param Index the zero-based diagnostic number to retrieve.
1654 *
1655 * \returns the requested diagnostic. This diagnostic must be freed
1656 * via a call to \c clang_disposeDiagnostic().
1657 */
1658CINDEX_LINKAGE
1659CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
1660 unsigned Index);
1661
1662/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00001663 * @}
1664 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001665
1666
Ted Kremenek04bb7162010-01-22 22:44:15 +00001667/**
1668 * \defgroup CINDEX_MISC Miscellaneous utility functions
1669 *
1670 * @{
1671 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00001672
1673/**
1674 * \brief Return a version string, suitable for showing to a user, but not
1675 * intended to be parsed (the format is not guaranteed to be stable).
1676 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00001677CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00001678
1679/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00001680 * \brief Return a version string, suitable for showing to a user, but not
1681 * intended to be parsed (the format is not guaranteed to be stable).
1682 */
1683
1684
1685 /**
1686 * \brief Visitor invoked for each file in a translation unit
1687 * (used with clang_getInclusions()).
1688 *
1689 * This visitor function will be invoked by clang_getInclusions() for each
1690 * file included (either at the top-level or by #include directives) within
1691 * a translation unit. The first argument is the file being included, and
1692 * the second and third arguments provide the inclusion stack. The
1693 * array is sorted in order of immediate inclusion. For example,
1694 * the first element refers to the location that included 'included_file'.
1695 */
1696typedef void (*CXInclusionVisitor)(CXFile included_file,
1697 CXSourceLocation* inclusion_stack,
1698 unsigned include_len,
1699 CXClientData client_data);
1700
1701/**
1702 * \brief Visit the set of preprocessor inclusions in a translation unit.
1703 * The visitor function is called with the provided data for every included
1704 * file. This does not include headers included by the PCH file (unless one
1705 * is inspecting the inclusions in the PCH file itself).
1706 */
1707CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
1708 CXInclusionVisitor visitor,
1709 CXClientData client_data);
1710
1711/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00001712 * @}
1713 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001714
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001715/**
1716 * @}
1717 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001718
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001719#ifdef __cplusplus
1720}
1721#endif
1722#endif
1723