blob: d9b4b0906bed97db0c7c5872af5a51df593b400a [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 Gregor936ea3b2010-01-28 00:56:43 +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 Gregor936ea3b2010-01-28 00:56:43 +0000173CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH);
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000174CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000175
176/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000177 * \brief Request that AST's be generated externally for API calls which parse
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000178 * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
179 *
180 * Note: This is for debugging purposes only, and may be removed at a later
181 * date.
182 *
183 * \param index - The index to update.
184 * \param value - The new flag value.
185 */
186CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
187 int value);
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +0000188/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000189 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000190 *
191 * @{
192 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000193
Douglas Gregorf5525442010-01-20 22:45:41 +0000194/**
195 * \brief A particular source file that is part of a translation unit.
196 */
197typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000198
Douglas Gregorf5525442010-01-20 22:45:41 +0000199
200/**
201 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000202 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000203CINDEX_LINKAGE const char *clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000204
Douglas Gregorf5525442010-01-20 22:45:41 +0000205/**
206 * \brief Retrieve the last modification time of the given file.
207 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000208CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000209
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000210/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000211 * \brief Retrieve a file handle within the given translation unit.
212 *
213 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000214 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000215 * \param file_name the name of the file.
216 *
217 * \returns the file handle for the named file in the translation unit \p tu,
218 * or a NULL file handle if the file was not a part of this translation unit.
219 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000220CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000221 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000222
Douglas Gregorb9790342010-01-22 21:44:22 +0000223/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000224 * @}
225 */
226
227/**
228 * \defgroup CINDEX_LOCATIONS Physical source locations
229 *
230 * Clang represents physical source locations in its abstract syntax tree in
231 * great detail, with file, line, and column information for the majority of
232 * the tokens parsed in the source code. These data types and functions are
233 * used to represent source location information, either for a particular
234 * point in the program or for a range of points in the program, and extract
235 * specific location information from those data types.
236 *
237 * @{
238 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000239
Douglas Gregorf5525442010-01-20 22:45:41 +0000240/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000241 * \brief Identifies a specific source location within a translation
242 * unit.
243 *
244 * Use clang_getInstantiationLocation() to map a source location to a
245 * particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000246 */
247typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000248 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000249 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000250} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000251
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000252/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000253 * \brief Identifies a range of source locations in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000254 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000255 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
256 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000257 */
258typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000259 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000260 unsigned begin_int_data;
261 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000262} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000263
Douglas Gregor1db19de2010-01-19 21:36:55 +0000264/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000265 * \brief Retrieve a NULL (invalid) source location.
266 */
267CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000268
Douglas Gregorb9790342010-01-22 21:44:22 +0000269/**
270 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000271 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000272 * code.
273 *
274 * \returns non-zero if the source locations refer to the same location, zero
275 * if they refer to different locations.
276 */
277CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
278 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000279
Douglas Gregorb9790342010-01-22 21:44:22 +0000280/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000281 * \brief Retrieves the source location associated with a given file/line/column
282 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000283 */
284CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
285 CXFile file,
286 unsigned line,
287 unsigned column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000288
Douglas Gregorb9790342010-01-22 21:44:22 +0000289/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000290 * \brief Retrieve a NULL (invalid) source range.
291 */
292CINDEX_LINKAGE CXSourceRange clang_getNullRange();
293
294/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000295 * \brief Retrieve a source range given the beginning and ending source
296 * locations.
297 */
298CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
299 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000300
Douglas Gregorb9790342010-01-22 21:44:22 +0000301/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000302 * \brief Retrieve the file, line, column, and offset represented by
303 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000304 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000305 * \param location the location within a source file that will be decomposed
306 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000307 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000308 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000309 * source location points.
310 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000311 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000312 * source location points.
313 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000314 * \param column [out] if non-NULL, will be set to the column to which the given
315 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000316 *
317 * \param offset [out] if non-NULL, will be set to the offset into the
318 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000319 */
320CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
321 CXFile *file,
322 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000323 unsigned *column,
324 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000325
326/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000327 * \brief Retrieve a source location representing the first character within a
328 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000329 */
330CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
331
332/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000333 * \brief Retrieve a source location representing the last character within a
334 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000335 */
336CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
337
Douglas Gregorf5525442010-01-20 22:45:41 +0000338/**
339 * @}
340 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000341
342/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000343 * \defgroup CINDEX_DIAG Diagnostic reporting
344 *
345 * @{
346 */
347
348/**
349 * \brief Describes the severity of a particular diagnostic.
350 */
351enum CXDiagnosticSeverity {
352 /**
353 * \brief A diagnostic that has been suppressed, e.g., by a command-line
354 * option.
355 */
356 CXDiagnostic_Ignored = 0,
357
358 /**
359 * \brief This diagnostic is a note that should be attached to the
360 * previous (non-note) diagnostic.
361 */
362 CXDiagnostic_Note = 1,
363
364 /**
365 * \brief This diagnostic indicates suspicious code that may not be
366 * wrong.
367 */
368 CXDiagnostic_Warning = 2,
369
370 /**
371 * \brief This diagnostic indicates that the code is ill-formed.
372 */
373 CXDiagnostic_Error = 3,
374
375 /**
376 * \brief This diagnostic indicates that the code is ill-formed such
377 * that future parser recovery is unlikely to produce useful
378 * results.
379 */
380 CXDiagnostic_Fatal = 4
381};
382
383/**
384 * \brief Describes the kind of fix-it hint expressed within a
385 * diagnostic.
386 */
387enum CXFixItKind {
388 /**
389 * \brief A fix-it hint that inserts code at a particular position.
390 */
391 CXFixIt_Insertion = 0,
392
393 /**
394 * \brief A fix-it hint that removes code within a range.
395 */
396 CXFixIt_Removal = 1,
397
398 /**
399 * \brief A fix-it hint that replaces the code within a range with another
400 * string.
401 */
402 CXFixIt_Replacement = 2
403};
404
405/**
406 * \brief A single diagnostic, containing the diagnostic's severity,
407 * location, text, source ranges, and fix-it hints.
408 */
409typedef void *CXDiagnostic;
410
411/**
412 * \brief Callback function invoked for each diagnostic emitted during
413 * translation.
414 *
415 * \param Diagnostic the diagnostic emitted during translation. This
416 * diagnostic pointer is only valid during the execution of the
417 * callback.
418 *
419 * \param ClientData the callback client data.
420 */
421typedef void (*CXDiagnosticCallback)(CXDiagnostic Diagnostic,
422 CXClientData ClientData);
423
424/**
425 * \brief Determine the severity of the given diagnostic.
426 */
427CINDEX_LINKAGE enum CXDiagnosticSeverity
428clang_getDiagnosticSeverity(CXDiagnostic);
429
430/**
431 * \brief Retrieve the source location of the given diagnostic.
432 *
433 * This location is where Clang would print the caret ('^') when
434 * displaying the diagnostic on the command line.
435 */
436CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
437
438/**
439 * \brief Retrieve the text of the given diagnostic.
440 */
441CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
442
443/**
444 * \brief Retrieve the source ranges associated with the diagnostic.
445 *
446 * These source ranges highlight important elements in the source
447 * code. On the command line, Clang displays source ranges by
448 * underlining them with '~' characters.
449 *
450 * \param Diagnostic the diagnostic whose ranges are being extracted.
451 *
452 * \param Ranges [out] will be set to a newly-allocated array
453 * containing the source ranges of this diagnostic. These ranges must
454 * be freed with \c clang_disposeDiagnosticRanges().
455 *
456 * \param NumRanges [out] will be set to the number of source ranges
457 * in the \p Ranges array.
458 */
459CINDEX_LINKAGE void clang_getDiagnosticRanges(CXDiagnostic Diagnostic,
460 CXSourceRange **Ranges,
461 unsigned *NumRanges);
462
463/**
464 * \brief Free the source ranges returned by \c clang_getDiagnosticRanges().
465 */
466CINDEX_LINKAGE void clang_disposeDiagnosticRanges(CXSourceRange *Ranges,
467 unsigned NumRanges);
468
469/**
470 * \brief Determine the number of fix-it hints associated with the
471 * given diagnostic.
472 */
473CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
474
475/**
476 * \brief Retrieve the kind of the given fix-it.
477 *
478 * \param Diagnostic the diagnostic whose fix-its are being queried.
479 *
480 * \param FixIt the zero-based index of the fix-it to query.
481 */
482CINDEX_LINKAGE enum CXFixItKind
483clang_getDiagnosticFixItKind(CXDiagnostic Diagnostic, unsigned FixIt);
484
485/**
486 * \brief Retrieve the insertion information for an insertion fix-it.
487 *
488 * For a fix-it that describes an insertion into a text buffer,
489 * retrieve the source location where the text should be inserted and
490 * the text to be inserted.
491 *
492 * \param Diagnostic the diagnostic whose fix-its are being queried.
493 *
494 * \param FixIt the zero-based index of the insertion fix-it.
495 *
496 * \param Location will be set to the location where text should be
497 * inserted.
498 *
499 * \returns the text string to insert at the given location.
500 */
501CINDEX_LINKAGE CXString
502clang_getDiagnosticFixItInsertion(CXDiagnostic Diagnostic, unsigned FixIt,
503 CXSourceLocation *Location);
504
505/**
506 * \brief Retrieve the removal information for a removal fix-it.
507 *
508 * For a fix-it that describes a removal from a text buffer, retrieve
509 * the source range that should be removed.
510 *
511 * \param Diagnostic the diagnostic whose fix-its are being queried.
512 *
513 * \param FixIt the zero-based index of the removal fix-it.
514 *
515 * \returns a source range describing the text that should be removed
516 * from the buffer.
517 */
518CINDEX_LINKAGE CXSourceRange
519clang_getDiagnosticFixItRemoval(CXDiagnostic Diagnostic, unsigned FixIt);
520
521/**
522 * \brief Retrieve the replacement information for an replacement fix-it.
523 *
524 * For a fix-it that describes replacement of text in the text buffer
525 * with alternative text.
526 *
527 * \param Diagnostic the diagnostic whose fix-its are being queried.
528 *
529 * \param FixIt the zero-based index of the replacement fix-it.
530 *
531 * \param Range will be set to the source range whose text should be
532 * replaced with the returned text.
533 *
534 * \returns the text string to use as replacement text.
535 */
536CINDEX_LINKAGE CXString
537clang_getDiagnosticFixItReplacement(CXDiagnostic Diagnostic, unsigned FixIt,
538 CXSourceRange *Range);
539
540/**
541 * @}
542 */
543
544/**
545 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
546 *
547 * The routines in this group provide the ability to create and destroy
548 * translation units from files, either by parsing the contents of the files or
549 * by reading in a serialized representation of a translation unit.
550 *
551 * @{
552 */
553
554/**
555 * \brief Get the original translation unit source file name.
556 */
557CINDEX_LINKAGE CXString
558clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
559
560/**
561 * \brief Return the CXTranslationUnit for a given source file and the provided
562 * command line arguments one would pass to the compiler.
563 *
564 * Note: The 'source_filename' argument is optional. If the caller provides a
565 * NULL pointer, the name of the source file is expected to reside in the
566 * specified command line arguments.
567 *
568 * Note: When encountered in 'clang_command_line_args', the following options
569 * are ignored:
570 *
571 * '-c'
572 * '-emit-ast'
573 * '-fsyntax-only'
574 * '-o <output file>' (both '-o' and '<output file>' are ignored)
575 *
576 *
577 * \param source_filename - The name of the source file to load, or NULL if the
578 * source file is included in clang_command_line_args.
579 *
580 * \param num_unsaved_files the number of unsaved file entries in \p
581 * unsaved_files.
582 *
583 * \param unsaved_files the files that have not yet been saved to disk
584 * but may be required for code completion, including the contents of
585 * those files.
586 *
587 * \param diag_callback callback function that will receive any diagnostics
588 * emitted while processing this source file. If NULL, diagnostics will be
589 * suppressed.
590 *
591 * \param diag_client_data client data that will be passed to the diagnostic
592 * callback function.
593 */
594CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
595 CXIndex CIdx,
596 const char *source_filename,
597 int num_clang_command_line_args,
598 const char **clang_command_line_args,
599 unsigned num_unsaved_files,
600 struct CXUnsavedFile *unsaved_files,
601 CXDiagnosticCallback diag_callback,
602 CXClientData diag_client_data);
603
604/**
605 * \brief Create a translation unit from an AST file (-emit-ast).
606 */
607CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
608 const char *ast_filename,
609 CXDiagnosticCallback diag_callback,
610 CXClientData diag_client_data);
611
612/**
613 * \brief Destroy the specified CXTranslationUnit object.
614 */
615CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
616
617/**
618 * @}
619 */
620
621/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000622 * \brief Describes the kind of entity that a cursor refers to.
623 */
624enum CXCursorKind {
625 /* Declarations */
626 CXCursor_FirstDecl = 1,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000627 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000628 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000629 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000630 *
631 * Unexposed declarations have the same operations as any other kind
632 * of declaration; one can extract their location information,
633 * spelling, find their definitions, etc. However, the specific kind
634 * of the declaration is not reported.
635 */
636 CXCursor_UnexposedDecl = 1,
637 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000638 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000639 /** \brief A C or C++ union. */
640 CXCursor_UnionDecl = 3,
641 /** \brief A C++ class. */
642 CXCursor_ClassDecl = 4,
643 /** \brief An enumeration. */
644 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000645 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000646 * \brief A field (in C) or non-static data member (in C++) in a
647 * struct, union, or C++ class.
648 */
649 CXCursor_FieldDecl = 6,
650 /** \brief An enumerator constant. */
651 CXCursor_EnumConstantDecl = 7,
652 /** \brief A function. */
653 CXCursor_FunctionDecl = 8,
654 /** \brief A variable. */
655 CXCursor_VarDecl = 9,
656 /** \brief A function or method parameter. */
657 CXCursor_ParmDecl = 10,
658 /** \brief An Objective-C @interface. */
659 CXCursor_ObjCInterfaceDecl = 11,
660 /** \brief An Objective-C @interface for a category. */
661 CXCursor_ObjCCategoryDecl = 12,
662 /** \brief An Objective-C @protocol declaration. */
663 CXCursor_ObjCProtocolDecl = 13,
664 /** \brief An Objective-C @property declaration. */
665 CXCursor_ObjCPropertyDecl = 14,
666 /** \brief An Objective-C instance variable. */
667 CXCursor_ObjCIvarDecl = 15,
668 /** \brief An Objective-C instance method. */
669 CXCursor_ObjCInstanceMethodDecl = 16,
670 /** \brief An Objective-C class method. */
671 CXCursor_ObjCClassMethodDecl = 17,
672 /** \brief An Objective-C @implementation. */
673 CXCursor_ObjCImplementationDecl = 18,
674 /** \brief An Objective-C @implementation for a category. */
675 CXCursor_ObjCCategoryImplDecl = 19,
676 /** \brief A typedef */
677 CXCursor_TypedefDecl = 20,
678 CXCursor_LastDecl = 20,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000679
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000680 /* References */
681 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000682 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000683 CXCursor_ObjCProtocolRef = 41,
684 CXCursor_ObjCClassRef = 42,
685 /**
686 * \brief A reference to a type declaration.
687 *
688 * A type reference occurs anywhere where a type is named but not
689 * declared. For example, given:
690 *
691 * \code
692 * typedef unsigned size_type;
693 * size_type size;
694 * \endcode
695 *
696 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
697 * while the type of the variable "size" is referenced. The cursor
698 * referenced by the type of size is the typedef for size_type.
699 */
700 CXCursor_TypeRef = 43,
701 CXCursor_LastRef = 43,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000702
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000703 /* Error conditions */
704 CXCursor_FirstInvalid = 70,
705 CXCursor_InvalidFile = 70,
706 CXCursor_NoDeclFound = 71,
707 CXCursor_NotImplemented = 72,
708 CXCursor_LastInvalid = 72,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000709
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000710 /* Expressions */
711 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000712
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000713 /**
714 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000715 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000716 *
717 * Unexposed expressions have the same operations as any other kind
718 * of expression; one can extract their location information,
719 * spelling, children, etc. However, the specific kind of the
720 * expression is not reported.
721 */
722 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000723
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000724 /**
725 * \brief An expression that refers to some value declaration, such
726 * as a function, varible, or enumerator.
727 */
728 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000729
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000730 /**
731 * \brief An expression that refers to a member of a struct, union,
732 * class, Objective-C class, etc.
733 */
734 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000735
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000736 /** \brief An expression that calls a function. */
737 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000738
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000739 /** \brief An expression that sends a message to an Objective-C
740 object or class. */
741 CXCursor_ObjCMessageExpr = 104,
742 CXCursor_LastExpr = 104,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000743
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000744 /* Statements */
745 CXCursor_FirstStmt = 200,
746 /**
747 * \brief A statement whose specific kind is not exposed via this
748 * interface.
749 *
750 * Unexposed statements have the same operations as any other kind of
751 * statement; one can extract their location information, spelling,
752 * children, etc. However, the specific kind of the statement is not
753 * reported.
754 */
755 CXCursor_UnexposedStmt = 200,
756 CXCursor_LastStmt = 200,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000757
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000758 /**
759 * \brief Cursor that represents the translation unit itself.
760 *
761 * The translation unit cursor exists primarily to act as the root
762 * cursor for traversing the contents of a translation unit.
763 */
764 CXCursor_TranslationUnit = 300
765};
766
767/**
768 * \brief A cursor representing some element in the abstract syntax tree for
769 * a translation unit.
770 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000771 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000772 * program--declaration, statements, expressions, references to declarations,
773 * etc.--under a single "cursor" abstraction with a common set of operations.
774 * Common operation for a cursor include: getting the physical location in
775 * a source file where the cursor points, getting the name associated with a
776 * cursor, and retrieving cursors for any child nodes of a particular cursor.
777 *
778 * Cursors can be produced in two specific ways.
779 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
780 * from which one can use clang_visitChildren() to explore the rest of the
781 * translation unit. clang_getCursor() maps from a physical source location
782 * to the entity that resides at that location, allowing one to map from the
783 * source code into the AST.
784 */
785typedef struct {
786 enum CXCursorKind kind;
787 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000788} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000789
790/**
791 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
792 *
793 * @{
794 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000795
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000796/**
797 * \brief Retrieve the NULL cursor, which represents no entity.
798 */
799CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000800
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000801/**
802 * \brief Retrieve the cursor that represents the given translation unit.
803 *
804 * The translation unit cursor can be used to start traversing the
805 * various declarations within the given translation unit.
806 */
807CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
808
809/**
810 * \brief Determine whether two cursors are equivalent.
811 */
812CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000813
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000814/**
815 * \brief Retrieve the kind of the given cursor.
816 */
817CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
818
819/**
820 * \brief Determine whether the given cursor kind represents a declaration.
821 */
822CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
823
824/**
825 * \brief Determine whether the given cursor kind represents a simple
826 * reference.
827 *
828 * Note that other kinds of cursors (such as expressions) can also refer to
829 * other cursors. Use clang_getCursorReferenced() to determine whether a
830 * particular cursor refers to another entity.
831 */
832CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
833
834/**
835 * \brief Determine whether the given cursor kind represents an expression.
836 */
837CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
838
839/**
840 * \brief Determine whether the given cursor kind represents a statement.
841 */
842CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
843
844/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000845 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000846 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000847 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000848CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
849
850/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000851 * \brief Determine whether the given cursor kind represents a translation
852 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000853 */
854CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000855
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000856/**
857 * @}
858 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000859
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000860/**
861 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
862 *
863 * Cursors represent a location within the Abstract Syntax Tree (AST). These
864 * routines help map between cursors and the physical locations where the
865 * described entities occur in the source code. The mapping is provided in
866 * both directions, so one can map from source code to the AST and back.
867 *
868 * @{
Steve Naroff50398192009-08-28 15:28:48 +0000869 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000870
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000871/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000872 * \brief Map a source location to the cursor that describes the entity at that
873 * location in the source code.
874 *
875 * clang_getCursor() maps an arbitrary source location within a translation
876 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000877 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +0000878 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000879 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +0000880 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
881 * will return a cursor referring to the "+" expression.
882 *
883 * \returns a cursor representing the entity at the given source location, or
884 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000885 */
Douglas Gregorb9790342010-01-22 21:44:22 +0000886CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000887
Douglas Gregor98258af2010-01-18 22:46:11 +0000888/**
889 * \brief Retrieve the physical location of the source constructor referenced
890 * by the given cursor.
891 *
892 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000893 * declaration, where the name of that declaration would occur if it is
894 * unnamed, or some keyword that introduces that particular declaration.
895 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +0000896 * source code.
897 */
898CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000899
Douglas Gregorb6998662010-01-19 19:34:47 +0000900/**
901 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +0000902 * the given cursor.
903 *
904 * The extent of a cursor starts with the file/line/column pointing at the
905 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000906 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +0000907 * declaration, the extent covers the declaration itself. For a reference,
908 * the extent covers the location of the reference (e.g., where the referenced
909 * entity was actually used).
910 */
911CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +0000912
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000913/**
914 * @}
915 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000916
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000917/**
918 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
919 *
920 * These routines provide the ability to traverse the abstract syntax tree
921 * using cursors.
922 *
923 * @{
924 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000925
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000926/**
927 * \brief Describes how the traversal of the children of a particular
928 * cursor should proceed after visiting a particular child cursor.
929 *
930 * A value of this enumeration type should be returned by each
931 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
932 */
933enum CXChildVisitResult {
934 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000935 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000936 */
937 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000938 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000939 * \brief Continues the cursor traversal with the next sibling of
940 * the cursor just visited, without visiting its children.
941 */
942 CXChildVisit_Continue,
943 /**
944 * \brief Recursively traverse the children of this cursor, using
945 * the same visitor and client data.
946 */
947 CXChildVisit_Recurse
948};
949
950/**
951 * \brief Visitor invoked for each cursor found by a traversal.
952 *
953 * This visitor function will be invoked for each cursor found by
954 * clang_visitCursorChildren(). Its first argument is the cursor being
955 * visited, its second argument is the parent visitor for that cursor,
956 * and its third argument is the client data provided to
957 * clang_visitCursorChildren().
958 *
959 * The visitor should return one of the \c CXChildVisitResult values
960 * to direct clang_visitCursorChildren().
961 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000962typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
963 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000964 CXClientData client_data);
965
966/**
967 * \brief Visit the children of a particular cursor.
968 *
969 * This function visits all the direct children of the given cursor,
970 * invoking the given \p visitor function with the cursors of each
971 * visited child. The traversal may be recursive, if the visitor returns
972 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
973 * the visitor returns \c CXChildVisit_Break.
974 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000975 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +0000976 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000977 * definition, have no children).
978 *
979 * \param visitor the visitor function that will be invoked for each
980 * child of \p parent.
981 *
982 * \param client_data pointer data supplied by the client, which will
983 * be passed to the visitor each time it is invoked.
984 *
985 * \returns a non-zero value if the traversal was terminated
986 * prematurely by the visitor returning \c CXChildVisit_Break.
987 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000988CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000989 CXCursorVisitor visitor,
990 CXClientData client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000991
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000992/**
993 * @}
994 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000995
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000996/**
997 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
998 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000999 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001000 * across translation units, by providing the names of the entities referenced
1001 * by cursors, follow reference cursors to the declarations they reference,
1002 * and associate declarations with their definitions.
1003 *
1004 * @{
1005 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001006
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001007/**
1008 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1009 * by the given cursor.
1010 *
1011 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1012 * entity (function, class, variable, etc.) within a program. USRs can be
1013 * compared across translation units to determine, e.g., when references in
1014 * one translation refer to an entity defined in another translation unit.
1015 */
1016CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1017
1018/**
1019 * \brief Retrieve a name for the entity referenced by this cursor.
1020 */
1021CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1022
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001023/** \brief For a cursor that is a reference, retrieve a cursor representing the
1024 * entity that it references.
1025 *
1026 * Reference cursors refer to other entities in the AST. For example, an
1027 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001028 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001029 * cursor for the superclass reference. If the input cursor is a declaration or
1030 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001031 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001032 */
1033CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001034
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001035/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001036 * \brief For a cursor that is either a reference to or a declaration
1037 * of some entity, retrieve a cursor that describes the definition of
1038 * that entity.
1039 *
1040 * Some entities can be declared multiple times within a translation
1041 * unit, but only one of those declarations can also be a
1042 * definition. For example, given:
1043 *
1044 * \code
1045 * int f(int, int);
1046 * int g(int x, int y) { return f(x, y); }
1047 * int f(int a, int b) { return a + b; }
1048 * int f(int, int);
1049 * \endcode
1050 *
1051 * there are three declarations of the function "f", but only the
1052 * second one is a definition. The clang_getCursorDefinition()
1053 * function will take any cursor pointing to a declaration of "f"
1054 * (the first or fourth lines of the example) or a cursor referenced
1055 * that uses "f" (the call to "f' inside "g") and will return a
1056 * declaration cursor pointing to the definition (the second "f"
1057 * declaration).
1058 *
1059 * If given a cursor for which there is no corresponding definition,
1060 * e.g., because there is no definition of that entity within this
1061 * translation unit, returns a NULL cursor.
1062 */
1063CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1064
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001065/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001066 * \brief Determine whether the declaration pointed to by this cursor
1067 * is also a definition of that entity.
1068 */
1069CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1070
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001071/**
1072 * @}
1073 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001074
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001075/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001076 * \defgroup CINDEX_LEX Token extraction and manipulation
1077 *
1078 * The routines in this group provide access to the tokens within a
1079 * translation unit, along with a semantic mapping of those tokens to
1080 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001081 *
1082 * @{
1083 */
1084
1085/**
1086 * \brief Describes a kind of token.
1087 */
1088typedef enum CXTokenKind {
1089 /**
1090 * \brief A token that contains some kind of punctuation.
1091 */
1092 CXToken_Punctuation,
1093
1094 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001095 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001096 */
1097 CXToken_Keyword,
1098
1099 /**
1100 * \brief An identifier (that is not a keyword).
1101 */
1102 CXToken_Identifier,
1103
1104 /**
1105 * \brief A numeric, string, or character literal.
1106 */
1107 CXToken_Literal,
1108
1109 /**
1110 * \brief A comment.
1111 */
1112 CXToken_Comment
1113} CXTokenKind;
1114
1115/**
1116 * \brief Describes a single preprocessing token.
1117 */
1118typedef struct {
1119 unsigned int_data[4];
1120 void *ptr_data;
1121} CXToken;
1122
1123/**
1124 * \brief Determine the kind of the given token.
1125 */
1126CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
1127
1128/**
1129 * \brief Determine the spelling of the given token.
1130 *
1131 * The spelling of a token is the textual representation of that token, e.g.,
1132 * the text of an identifier or keyword.
1133 */
1134CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
1135
1136/**
1137 * \brief Retrieve the source location of the given token.
1138 */
1139CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
1140 CXToken);
1141
1142/**
1143 * \brief Retrieve a source range that covers the given token.
1144 */
1145CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
1146
1147/**
1148 * \brief Tokenize the source code described by the given range into raw
1149 * lexical tokens.
1150 *
1151 * \param TU the translation unit whose text is being tokenized.
1152 *
1153 * \param Range the source range in which text should be tokenized. All of the
1154 * tokens produced by tokenization will fall within this source range,
1155 *
1156 * \param Tokens this pointer will be set to point to the array of tokens
1157 * that occur within the given source range. The returned pointer must be
1158 * freed with clang_disposeTokens() before the translation unit is destroyed.
1159 *
1160 * \param NumTokens will be set to the number of tokens in the \c *Tokens
1161 * array.
1162 *
1163 */
1164CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
1165 CXToken **Tokens, unsigned *NumTokens);
1166
1167/**
1168 * \brief Annotate the given set of tokens by providing cursors for each token
1169 * that can be mapped to a specific entity within the abstract syntax tree.
1170 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001171 * This token-annotation routine is equivalent to invoking
1172 * clang_getCursor() for the source locations of each of the
1173 * tokens. The cursors provided are filtered, so that only those
1174 * cursors that have a direct correspondence to the token are
1175 * accepted. For example, given a function call \c f(x),
1176 * clang_getCursor() would provide the following cursors:
1177 *
1178 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
1179 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
1180 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
1181 *
1182 * Only the first and last of these cursors will occur within the
1183 * annotate, since the tokens "f" and "x' directly refer to a function
1184 * and a variable, respectively, but the parentheses are just a small
1185 * part of the full syntax of the function call expression, which is
1186 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001187 *
1188 * \param TU the translation unit that owns the given tokens.
1189 *
1190 * \param Tokens the set of tokens to annotate.
1191 *
1192 * \param NumTokens the number of tokens in \p Tokens.
1193 *
1194 * \param Cursors an array of \p NumTokens cursors, whose contents will be
1195 * replaced with the cursors corresponding to each token.
1196 */
1197CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
1198 CXToken *Tokens, unsigned NumTokens,
1199 CXCursor *Cursors);
1200
1201/**
1202 * \brief Free the given set of tokens.
1203 */
1204CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
1205 CXToken *Tokens, unsigned NumTokens);
1206
1207/**
1208 * @}
1209 */
1210
1211/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001212 * \defgroup CINDEX_DEBUG Debugging facilities
1213 *
1214 * These routines are used for testing and debugging, only, and should not
1215 * be relied upon.
1216 *
1217 * @{
1218 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001219
Steve Naroff4ade6d62009-09-23 17:52:52 +00001220/* for debug/testing */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001221CINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
1222CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
1223 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00001224 const char **endBuf,
1225 unsigned *startLine,
1226 unsigned *startColumn,
1227 unsigned *endLine,
1228 unsigned *endColumn);
Steve Naroff600866c2009-08-27 19:51:58 +00001229
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001230/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001231 * @}
1232 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001233
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001234/**
1235 * \defgroup CINDEX_CODE_COMPLET Code completion
1236 *
1237 * Code completion involves taking an (incomplete) source file, along with
1238 * knowledge of where the user is actively editing that file, and suggesting
1239 * syntactically- and semantically-valid constructs that the user might want to
1240 * use at that particular point in the source code. These data structures and
1241 * routines provide support for code completion.
1242 *
1243 * @{
1244 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001245
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001246/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001247 * \brief A semantic string that describes a code-completion result.
1248 *
1249 * A semantic string that describes the formatting of a code-completion
1250 * result as a single "template" of text that should be inserted into the
1251 * source buffer when a particular code-completion result is selected.
1252 * Each semantic string is made up of some number of "chunks", each of which
1253 * contains some text along with a description of what that text means, e.g.,
1254 * the name of the entity being referenced, whether the text chunk is part of
1255 * the template, or whether it is a "placeholder" that the user should replace
1256 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001257 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001258 */
1259typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001260
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001261/**
1262 * \brief A single result of code completion.
1263 */
1264typedef struct {
1265 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001266 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001267 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001268 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001269 * *Decl cursor kinds), describing the entity that the completion is
1270 * referring to.
1271 *
1272 * \todo In the future, we would like to provide a full cursor, to allow
1273 * the client to extract additional information from declaration.
1274 */
1275 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001276
1277 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001278 * \brief The code-completion string that describes how to insert this
1279 * code-completion result into the editing buffer.
1280 */
1281 CXCompletionString CompletionString;
1282} CXCompletionResult;
1283
1284/**
1285 * \brief Describes a single piece of text within a code-completion string.
1286 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001287 * Each "chunk" within a code-completion string (\c CXCompletionString) is
1288 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001289 * should be interpreted by the client or is another completion string.
1290 */
1291enum CXCompletionChunkKind {
1292 /**
1293 * \brief A code-completion string that describes "optional" text that
1294 * could be a part of the template (but is not required).
1295 *
1296 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001297 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001298 * \c clang_getCompletionChunkCompletionString(). The code-completion string
1299 * describes an additional part of the template that is completely optional.
1300 * For example, optional chunks can be used to describe the placeholders for
1301 * arguments that match up with defaulted function parameters, e.g. given:
1302 *
1303 * \code
1304 * void f(int x, float y = 3.14, double z = 2.71828);
1305 * \endcode
1306 *
1307 * The code-completion string for this function would contain:
1308 * - a TypedText chunk for "f".
1309 * - a LeftParen chunk for "(".
1310 * - a Placeholder chunk for "int x"
1311 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
1312 * - a Comma chunk for ","
1313 * - a Placeholder chunk for "float x"
1314 * - an Optional chunk containing the last defaulted argument:
1315 * - a Comma chunk for ","
1316 * - a Placeholder chunk for "double z"
1317 * - a RightParen chunk for ")"
1318 *
1319 * There are many ways two handle Optional chunks. Two simple approaches are:
1320 * - Completely ignore optional chunks, in which case the template for the
1321 * function "f" would only include the first parameter ("int x").
1322 * - Fully expand all optional chunks, in which case the template for the
1323 * function "f" would have all of the parameters.
1324 */
1325 CXCompletionChunk_Optional,
1326 /**
1327 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001328 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001329 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001330 * There will be exactly one "typed text" chunk in a semantic string, which
1331 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001332 * declaration that could be used at the current code point. Clients are
1333 * expected to filter the code-completion results based on the text in this
1334 * chunk.
1335 */
1336 CXCompletionChunk_TypedText,
1337 /**
1338 * \brief Text that should be inserted as part of a code-completion result.
1339 *
1340 * A "text" chunk represents text that is part of the template to be
1341 * inserted into user code should this particular code-completion result
1342 * be selected.
1343 */
1344 CXCompletionChunk_Text,
1345 /**
1346 * \brief Placeholder text that should be replaced by the user.
1347 *
1348 * A "placeholder" chunk marks a place where the user should insert text
1349 * into the code-completion template. For example, placeholders might mark
1350 * the function parameters for a function declaration, to indicate that the
1351 * user should provide arguments for each of those parameters. The actual
1352 * text in a placeholder is a suggestion for the text to display before
1353 * the user replaces the placeholder with real code.
1354 */
1355 CXCompletionChunk_Placeholder,
1356 /**
1357 * \brief Informative text that should be displayed but never inserted as
1358 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001359 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001360 * An "informative" chunk contains annotations that can be displayed to
1361 * help the user decide whether a particular code-completion result is the
1362 * right option, but which is not part of the actual template to be inserted
1363 * by code completion.
1364 */
1365 CXCompletionChunk_Informative,
1366 /**
1367 * \brief Text that describes the current parameter when code-completion is
1368 * referring to function call, message send, or template specialization.
1369 *
1370 * A "current parameter" chunk occurs when code-completion is providing
1371 * information about a parameter corresponding to the argument at the
1372 * code-completion point. For example, given a function
1373 *
1374 * \code
1375 * int add(int x, int y);
1376 * \endcode
1377 *
1378 * and the source code \c add(, where the code-completion point is after the
1379 * "(", the code-completion string will contain a "current parameter" chunk
1380 * for "int x", indicating that the current argument will initialize that
1381 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001382 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001383 * "current paremeter" chunk to "int y".
1384 */
1385 CXCompletionChunk_CurrentParameter,
1386 /**
1387 * \brief A left parenthesis ('('), used to initiate a function call or
1388 * signal the beginning of a function parameter list.
1389 */
1390 CXCompletionChunk_LeftParen,
1391 /**
1392 * \brief A right parenthesis (')'), used to finish a function call or
1393 * signal the end of a function parameter list.
1394 */
1395 CXCompletionChunk_RightParen,
1396 /**
1397 * \brief A left bracket ('[').
1398 */
1399 CXCompletionChunk_LeftBracket,
1400 /**
1401 * \brief A right bracket (']').
1402 */
1403 CXCompletionChunk_RightBracket,
1404 /**
1405 * \brief A left brace ('{').
1406 */
1407 CXCompletionChunk_LeftBrace,
1408 /**
1409 * \brief A right brace ('}').
1410 */
1411 CXCompletionChunk_RightBrace,
1412 /**
1413 * \brief A left angle bracket ('<').
1414 */
1415 CXCompletionChunk_LeftAngle,
1416 /**
1417 * \brief A right angle bracket ('>').
1418 */
1419 CXCompletionChunk_RightAngle,
1420 /**
1421 * \brief A comma separator (',').
1422 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001423 CXCompletionChunk_Comma,
1424 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001425 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001426 *
1427 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001428 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001429 * expression using the given completion string would have.
1430 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00001431 CXCompletionChunk_ResultType,
1432 /**
1433 * \brief A colon (':').
1434 */
1435 CXCompletionChunk_Colon,
1436 /**
1437 * \brief A semicolon (';').
1438 */
1439 CXCompletionChunk_SemiColon,
1440 /**
1441 * \brief An '=' sign.
1442 */
1443 CXCompletionChunk_Equal,
1444 /**
1445 * Horizontal space (' ').
1446 */
1447 CXCompletionChunk_HorizontalSpace,
1448 /**
1449 * Vertical space ('\n'), after which it is generally a good idea to
1450 * perform indentation.
1451 */
1452 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001453};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001454
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001455/**
1456 * \brief Determine the kind of a particular chunk within a completion string.
1457 *
1458 * \param completion_string the completion string to query.
1459 *
1460 * \param chunk_number the 0-based index of the chunk in the completion string.
1461 *
1462 * \returns the kind of the chunk at the index \c chunk_number.
1463 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001464CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001465clang_getCompletionChunkKind(CXCompletionString completion_string,
1466 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001467
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001468/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001469 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001470 * completion string.
1471 *
1472 * \param completion_string the completion string to query.
1473 *
1474 * \param chunk_number the 0-based index of the chunk in the completion string.
1475 *
1476 * \returns the text associated with the chunk at index \c chunk_number.
1477 */
1478CINDEX_LINKAGE const char *
1479clang_getCompletionChunkText(CXCompletionString completion_string,
1480 unsigned chunk_number);
1481
1482/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001483 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001484 * within a completion string.
1485 *
1486 * \param completion_string the completion string to query.
1487 *
1488 * \param chunk_number the 0-based index of the chunk in the completion string.
1489 *
1490 * \returns the completion string associated with the chunk at index
1491 * \c chunk_number, or NULL if that chunk is not represented by a completion
1492 * string.
1493 */
1494CINDEX_LINKAGE CXCompletionString
1495clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
1496 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001497
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001498/**
1499 * \brief Retrieve the number of chunks in the given code-completion string.
1500 */
1501CINDEX_LINKAGE unsigned
1502clang_getNumCompletionChunks(CXCompletionString completion_string);
1503
1504/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00001505 * \brief Contains the results of code-completion.
1506 *
1507 * This data structure contains the results of code completion, as
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001508 * produced by \c clang_codeComplete. Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00001509 * \c clang_disposeCodeCompleteResults.
1510 */
1511typedef struct {
1512 /**
1513 * \brief The code-completion results.
1514 */
1515 CXCompletionResult *Results;
1516
1517 /**
1518 * \brief The number of code-completion results stored in the
1519 * \c Results array.
1520 */
1521 unsigned NumResults;
1522} CXCodeCompleteResults;
1523
1524/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001525 * \brief Perform code completion at a given location in a source file.
1526 *
1527 * This function performs code completion at a particular file, line, and
1528 * column within source code, providing results that suggest potential
1529 * code snippets based on the context of the completion. The basic model
1530 * for code completion is that Clang will parse a complete source file,
1531 * performing syntax checking up to the location where code-completion has
1532 * been requested. At that point, a special code-completion token is passed
1533 * to the parser, which recognizes this token and determines, based on the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001534 * current location in the C/Objective-C/C++ grammar and the state of
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001535 * semantic analysis, what completions to provide. These completions are
Douglas Gregorec6762c2009-12-18 16:20:58 +00001536 * returned via a new \c CXCodeCompleteResults structure.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001537 *
1538 * Code completion itself is meant to be triggered by the client when the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001539 * user types punctuation characters or whitespace, at which point the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001540 * code-completion location will coincide with the cursor. For example, if \c p
1541 * is a pointer, code-completion might be triggered after the "-" and then
1542 * after the ">" in \c p->. When the code-completion location is afer the ">",
1543 * the completion results will provide, e.g., the members of the struct that
1544 * "p" points to. The client is responsible for placing the cursor at the
1545 * beginning of the token currently being typed, then filtering the results
1546 * based on the contents of the token. For example, when code-completing for
1547 * the expression \c p->get, the client should provide the location just after
1548 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
1549 * client can filter the results based on the current token text ("get"), only
1550 * showing those results that start with "get". The intent of this interface
Douglas Gregorec6762c2009-12-18 16:20:58 +00001551 * is to separate the relatively high-latency acquisition of code-completion
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001552 * results from the filtering of results on a per-character basis, which must
1553 * have a lower latency.
1554 *
1555 * \param CIdx the \c CXIndex instance that will be used to perform code
1556 * completion.
1557 *
Daniel Dunbar8506dde2009-12-03 01:54:28 +00001558 * \param source_filename the name of the source file that should be parsed to
1559 * perform code-completion. This source file must be the same as or include the
1560 * filename described by \p complete_filename, or no code-completion results
1561 * will be produced. NOTE: One can also specify NULL for this argument if the
1562 * source file is included in command_line_args.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001563 *
1564 * \param num_command_line_args the number of command-line arguments stored in
1565 * \p command_line_args.
1566 *
1567 * \param command_line_args the command-line arguments to pass to the Clang
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001568 * compiler to build the given source file. This should include all of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001569 * necessary include paths, language-dialect switches, precompiled header
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001570 * includes, etc., but should not include any information specific to
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001571 * code completion.
1572 *
Douglas Gregor735df882009-12-02 09:21:34 +00001573 * \param num_unsaved_files the number of unsaved file entries in \p
1574 * unsaved_files.
1575 *
1576 * \param unsaved_files the files that have not yet been saved to disk
1577 * but may be required for code completion, including the contents of
1578 * those files.
1579 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001580 * \param complete_filename the name of the source file where code completion
1581 * should be performed. In many cases, this name will be the same as the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001582 * source filename. However, the completion filename may also be a file
1583 * included by the source file, which is required when producing
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001584 * code-completion results for a header.
1585 *
1586 * \param complete_line the line at which code-completion should occur.
1587 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001588 * \param complete_column the column at which code-completion should occur.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001589 * Note that the column should point just after the syntactic construct that
1590 * initiated code completion, and not in the middle of a lexical token.
1591 *
Douglas Gregor936ea3b2010-01-28 00:56:43 +00001592 * \param diag_callback callback function that will receive any diagnostics
1593 * emitted while processing this source file. If NULL, diagnostics will be
1594 * suppressed.
1595 *
1596 * \param diag_client_data client data that will be passed to the diagnostic
1597 * callback function.
1598 *
Douglas Gregorec6762c2009-12-18 16:20:58 +00001599 * \returns if successful, a new CXCodeCompleteResults structure
1600 * containing code-completion results, which should eventually be
1601 * freed with \c clang_disposeCodeCompleteResults(). If code
1602 * completion fails, returns NULL.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001603 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001604CINDEX_LINKAGE
1605CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001606 const char *source_filename,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001607 int num_command_line_args,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001608 const char **command_line_args,
1609 unsigned num_unsaved_files,
1610 struct CXUnsavedFile *unsaved_files,
1611 const char *complete_filename,
1612 unsigned complete_line,
Douglas Gregor936ea3b2010-01-28 00:56:43 +00001613 unsigned complete_column,
1614 CXDiagnosticCallback diag_callback,
1615 CXClientData diag_client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001616
Douglas Gregorec6762c2009-12-18 16:20:58 +00001617/**
1618 * \brief Free the given set of code-completion results.
1619 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001620CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00001621void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001622
Douglas Gregor20d416c2010-01-20 01:10:47 +00001623/**
1624 * @}
1625 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001626
1627
Ted Kremenek04bb7162010-01-22 22:44:15 +00001628/**
1629 * \defgroup CINDEX_MISC Miscellaneous utility functions
1630 *
1631 * @{
1632 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00001633
1634/**
1635 * \brief Return a version string, suitable for showing to a user, but not
1636 * intended to be parsed (the format is not guaranteed to be stable).
1637 */
Ted Kremenek04bb7162010-01-22 22:44:15 +00001638CINDEX_LINKAGE const char *clang_getClangVersion();
1639
1640/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00001641 * \brief Return a version string, suitable for showing to a user, but not
1642 * intended to be parsed (the format is not guaranteed to be stable).
1643 */
1644
1645
1646 /**
1647 * \brief Visitor invoked for each file in a translation unit
1648 * (used with clang_getInclusions()).
1649 *
1650 * This visitor function will be invoked by clang_getInclusions() for each
1651 * file included (either at the top-level or by #include directives) within
1652 * a translation unit. The first argument is the file being included, and
1653 * the second and third arguments provide the inclusion stack. The
1654 * array is sorted in order of immediate inclusion. For example,
1655 * the first element refers to the location that included 'included_file'.
1656 */
1657typedef void (*CXInclusionVisitor)(CXFile included_file,
1658 CXSourceLocation* inclusion_stack,
1659 unsigned include_len,
1660 CXClientData client_data);
1661
1662/**
1663 * \brief Visit the set of preprocessor inclusions in a translation unit.
1664 * The visitor function is called with the provided data for every included
1665 * file. This does not include headers included by the PCH file (unless one
1666 * is inspecting the inclusions in the PCH file itself).
1667 */
1668CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
1669 CXInclusionVisitor visitor,
1670 CXClientData client_data);
1671
1672/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00001673 * @}
1674 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001675
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001676/**
1677 * @}
1678 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001679
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001680#ifdef __cplusplus
1681}
1682#endif
1683#endif
1684