blob: e26dff1eb18a5b0f7bbada1c618a465b79948bb4 [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 *
146 * - displayDiagnostics: when non-zero, diagnostics will be output. If zero,
147 * diagnostics will be ignored.
Steve Naroffb4ece632009-10-20 16:36:34 +0000148 *
149 * Here is an example:
150 *
151 * // excludeDeclsFromPCH = 1, displayDiagnostics = 1
152 * Idx = clang_createIndex(1, 1);
153 *
154 * // IndexTest.pch was produced with the following command:
155 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
156 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
157 *
158 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000159 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000160 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000161 * clang_disposeTranslationUnit(TU);
162 *
163 * // This will load all the symbols from 'IndexTest.c', excluding symbols
164 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000165 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
166 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
167 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000168 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
169 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000170 * clang_disposeTranslationUnit(TU);
171 *
172 * This process of creating the 'pch', loading it separately, and using it (via
173 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
174 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000175 */
John Thompson2e06fc82009-10-27 13:42:56 +0000176CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000177 int displayDiagnostics);
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000178CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000179
180/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000181 * \brief Request that AST's be generated externally for API calls which parse
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000182 * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
183 *
184 * Note: This is for debugging purposes only, and may be removed at a later
185 * date.
186 *
187 * \param index - The index to update.
188 * \param value - The new flag value.
189 */
190CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
191 int value);
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +0000192/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000193 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000194 *
195 * @{
196 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000197
Douglas Gregorf5525442010-01-20 22:45:41 +0000198/**
199 * \brief A particular source file that is part of a translation unit.
200 */
201typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000202
Douglas Gregorf5525442010-01-20 22:45:41 +0000203
204/**
205 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000206 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000207CINDEX_LINKAGE const char *clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000208
Douglas Gregorf5525442010-01-20 22:45:41 +0000209/**
210 * \brief Retrieve the last modification time of the given file.
211 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000212CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000213
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000214/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000215 * \brief Retrieve a file handle within the given translation unit.
216 *
217 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000218 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000219 * \param file_name the name of the file.
220 *
221 * \returns the file handle for the named file in the translation unit \p tu,
222 * or a NULL file handle if the file was not a part of this translation unit.
223 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000224CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000225 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000226
Douglas Gregorb9790342010-01-22 21:44:22 +0000227/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000228 * @}
229 */
230
231/**
232 * \defgroup CINDEX_LOCATIONS Physical source locations
233 *
234 * Clang represents physical source locations in its abstract syntax tree in
235 * great detail, with file, line, and column information for the majority of
236 * the tokens parsed in the source code. These data types and functions are
237 * used to represent source location information, either for a particular
238 * point in the program or for a range of points in the program, and extract
239 * specific location information from those data types.
240 *
241 * @{
242 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000243
Douglas Gregorf5525442010-01-20 22:45:41 +0000244/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000245 * \brief Identifies a specific source location within a translation
246 * unit.
247 *
248 * Use clang_getInstantiationLocation() to map a source location to a
249 * particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000250 */
251typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000252 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000253 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000254} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000255
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000256/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000257 * \brief Identifies a range of source locations in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000258 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000259 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
260 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000261 */
262typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000263 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000264 unsigned begin_int_data;
265 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000266} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000267
Douglas Gregor1db19de2010-01-19 21:36:55 +0000268/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000269 * \brief Retrieve a NULL (invalid) source location.
270 */
271CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000272
Douglas Gregorb9790342010-01-22 21:44:22 +0000273/**
274 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000275 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000276 * code.
277 *
278 * \returns non-zero if the source locations refer to the same location, zero
279 * if they refer to different locations.
280 */
281CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
282 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000283
Douglas Gregorb9790342010-01-22 21:44:22 +0000284/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000285 * \brief Retrieves the source location associated with a given file/line/column
286 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000287 */
288CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
289 CXFile file,
290 unsigned line,
291 unsigned column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000292
Douglas Gregorb9790342010-01-22 21:44:22 +0000293/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000294 * \brief Retrieve a NULL (invalid) source range.
295 */
296CINDEX_LINKAGE CXSourceRange clang_getNullRange();
297
298/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000299 * \brief Retrieve a source range given the beginning and ending source
300 * locations.
301 */
302CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
303 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000304
Douglas Gregorb9790342010-01-22 21:44:22 +0000305/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000306 * \brief Retrieve the file, line, column, and offset represented by
307 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000308 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000309 * \param location the location within a source file that will be decomposed
310 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000311 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000312 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000313 * source location points.
314 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000315 * \param line [out] if non-NULL, will be set to the line 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 column [out] if non-NULL, will be set to the column to which the given
319 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000320 *
321 * \param offset [out] if non-NULL, will be set to the offset into the
322 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000323 */
324CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
325 CXFile *file,
326 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000327 unsigned *column,
328 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000329
330/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000331 * \brief Retrieve a source location representing the first character within a
332 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000333 */
334CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
335
336/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000337 * \brief Retrieve a source location representing the last character within a
338 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000339 */
340CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
341
Douglas Gregorf5525442010-01-20 22:45:41 +0000342/**
343 * @}
344 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000345
346/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000347 * \defgroup CINDEX_DIAG Diagnostic reporting
348 *
349 * @{
350 */
351
352/**
353 * \brief Describes the severity of a particular diagnostic.
354 */
355enum CXDiagnosticSeverity {
356 /**
357 * \brief A diagnostic that has been suppressed, e.g., by a command-line
358 * option.
359 */
360 CXDiagnostic_Ignored = 0,
361
362 /**
363 * \brief This diagnostic is a note that should be attached to the
364 * previous (non-note) diagnostic.
365 */
366 CXDiagnostic_Note = 1,
367
368 /**
369 * \brief This diagnostic indicates suspicious code that may not be
370 * wrong.
371 */
372 CXDiagnostic_Warning = 2,
373
374 /**
375 * \brief This diagnostic indicates that the code is ill-formed.
376 */
377 CXDiagnostic_Error = 3,
378
379 /**
380 * \brief This diagnostic indicates that the code is ill-formed such
381 * that future parser recovery is unlikely to produce useful
382 * results.
383 */
384 CXDiagnostic_Fatal = 4
385};
386
387/**
388 * \brief Describes the kind of fix-it hint expressed within a
389 * diagnostic.
390 */
391enum CXFixItKind {
392 /**
393 * \brief A fix-it hint that inserts code at a particular position.
394 */
395 CXFixIt_Insertion = 0,
396
397 /**
398 * \brief A fix-it hint that removes code within a range.
399 */
400 CXFixIt_Removal = 1,
401
402 /**
403 * \brief A fix-it hint that replaces the code within a range with another
404 * string.
405 */
406 CXFixIt_Replacement = 2
407};
408
409/**
410 * \brief A single diagnostic, containing the diagnostic's severity,
411 * location, text, source ranges, and fix-it hints.
412 */
413typedef void *CXDiagnostic;
414
415/**
416 * \brief Callback function invoked for each diagnostic emitted during
417 * translation.
418 *
419 * \param Diagnostic the diagnostic emitted during translation. This
420 * diagnostic pointer is only valid during the execution of the
421 * callback.
422 *
423 * \param ClientData the callback client data.
424 */
425typedef void (*CXDiagnosticCallback)(CXDiagnostic Diagnostic,
426 CXClientData ClientData);
427
428/**
429 * \brief Determine the severity of the given diagnostic.
430 */
431CINDEX_LINKAGE enum CXDiagnosticSeverity
432clang_getDiagnosticSeverity(CXDiagnostic);
433
434/**
435 * \brief Retrieve the source location of the given diagnostic.
436 *
437 * This location is where Clang would print the caret ('^') when
438 * displaying the diagnostic on the command line.
439 */
440CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
441
442/**
443 * \brief Retrieve the text of the given diagnostic.
444 */
445CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
446
447/**
448 * \brief Retrieve the source ranges associated with the diagnostic.
449 *
450 * These source ranges highlight important elements in the source
451 * code. On the command line, Clang displays source ranges by
452 * underlining them with '~' characters.
453 *
454 * \param Diagnostic the diagnostic whose ranges are being extracted.
455 *
456 * \param Ranges [out] will be set to a newly-allocated array
457 * containing the source ranges of this diagnostic. These ranges must
458 * be freed with \c clang_disposeDiagnosticRanges().
459 *
460 * \param NumRanges [out] will be set to the number of source ranges
461 * in the \p Ranges array.
462 */
463CINDEX_LINKAGE void clang_getDiagnosticRanges(CXDiagnostic Diagnostic,
464 CXSourceRange **Ranges,
465 unsigned *NumRanges);
466
467/**
468 * \brief Free the source ranges returned by \c clang_getDiagnosticRanges().
469 */
470CINDEX_LINKAGE void clang_disposeDiagnosticRanges(CXSourceRange *Ranges,
471 unsigned NumRanges);
472
473/**
474 * \brief Determine the number of fix-it hints associated with the
475 * given diagnostic.
476 */
477CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
478
479/**
480 * \brief Retrieve the kind of the given fix-it.
481 *
482 * \param Diagnostic the diagnostic whose fix-its are being queried.
483 *
484 * \param FixIt the zero-based index of the fix-it to query.
485 */
486CINDEX_LINKAGE enum CXFixItKind
487clang_getDiagnosticFixItKind(CXDiagnostic Diagnostic, unsigned FixIt);
488
489/**
490 * \brief Retrieve the insertion information for an insertion fix-it.
491 *
492 * For a fix-it that describes an insertion into a text buffer,
493 * retrieve the source location where the text should be inserted and
494 * the text to be inserted.
495 *
496 * \param Diagnostic the diagnostic whose fix-its are being queried.
497 *
498 * \param FixIt the zero-based index of the insertion fix-it.
499 *
500 * \param Location will be set to the location where text should be
501 * inserted.
502 *
503 * \returns the text string to insert at the given location.
504 */
505CINDEX_LINKAGE CXString
506clang_getDiagnosticFixItInsertion(CXDiagnostic Diagnostic, unsigned FixIt,
507 CXSourceLocation *Location);
508
509/**
510 * \brief Retrieve the removal information for a removal fix-it.
511 *
512 * For a fix-it that describes a removal from a text buffer, retrieve
513 * the source range that should be removed.
514 *
515 * \param Diagnostic the diagnostic whose fix-its are being queried.
516 *
517 * \param FixIt the zero-based index of the removal fix-it.
518 *
519 * \returns a source range describing the text that should be removed
520 * from the buffer.
521 */
522CINDEX_LINKAGE CXSourceRange
523clang_getDiagnosticFixItRemoval(CXDiagnostic Diagnostic, unsigned FixIt);
524
525/**
526 * \brief Retrieve the replacement information for an replacement fix-it.
527 *
528 * For a fix-it that describes replacement of text in the text buffer
529 * with alternative text.
530 *
531 * \param Diagnostic the diagnostic whose fix-its are being queried.
532 *
533 * \param FixIt the zero-based index of the replacement fix-it.
534 *
535 * \param Range will be set to the source range whose text should be
536 * replaced with the returned text.
537 *
538 * \returns the text string to use as replacement text.
539 */
540CINDEX_LINKAGE CXString
541clang_getDiagnosticFixItReplacement(CXDiagnostic Diagnostic, unsigned FixIt,
542 CXSourceRange *Range);
543
544/**
545 * @}
546 */
547
548/**
549 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
550 *
551 * The routines in this group provide the ability to create and destroy
552 * translation units from files, either by parsing the contents of the files or
553 * by reading in a serialized representation of a translation unit.
554 *
555 * @{
556 */
557
558/**
559 * \brief Get the original translation unit source file name.
560 */
561CINDEX_LINKAGE CXString
562clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
563
564/**
565 * \brief Return the CXTranslationUnit for a given source file and the provided
566 * command line arguments one would pass to the compiler.
567 *
568 * Note: The 'source_filename' argument is optional. If the caller provides a
569 * NULL pointer, the name of the source file is expected to reside in the
570 * specified command line arguments.
571 *
572 * Note: When encountered in 'clang_command_line_args', the following options
573 * are ignored:
574 *
575 * '-c'
576 * '-emit-ast'
577 * '-fsyntax-only'
578 * '-o <output file>' (both '-o' and '<output file>' are ignored)
579 *
580 *
581 * \param source_filename - The name of the source file to load, or NULL if the
582 * source file is included in clang_command_line_args.
583 *
584 * \param num_unsaved_files the number of unsaved file entries in \p
585 * unsaved_files.
586 *
587 * \param unsaved_files the files that have not yet been saved to disk
588 * but may be required for code completion, including the contents of
589 * those files.
590 *
591 * \param diag_callback callback function that will receive any diagnostics
592 * emitted while processing this source file. If NULL, diagnostics will be
593 * suppressed.
594 *
595 * \param diag_client_data client data that will be passed to the diagnostic
596 * callback function.
597 */
598CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
599 CXIndex CIdx,
600 const char *source_filename,
601 int num_clang_command_line_args,
602 const char **clang_command_line_args,
603 unsigned num_unsaved_files,
604 struct CXUnsavedFile *unsaved_files,
605 CXDiagnosticCallback diag_callback,
606 CXClientData diag_client_data);
607
608/**
609 * \brief Create a translation unit from an AST file (-emit-ast).
610 */
611CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
612 const char *ast_filename,
613 CXDiagnosticCallback diag_callback,
614 CXClientData diag_client_data);
615
616/**
617 * \brief Destroy the specified CXTranslationUnit object.
618 */
619CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
620
621/**
622 * @}
623 */
624
625/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000626 * \brief Describes the kind of entity that a cursor refers to.
627 */
628enum CXCursorKind {
629 /* Declarations */
630 CXCursor_FirstDecl = 1,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000631 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000632 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000633 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000634 *
635 * Unexposed declarations have the same operations as any other kind
636 * of declaration; one can extract their location information,
637 * spelling, find their definitions, etc. However, the specific kind
638 * of the declaration is not reported.
639 */
640 CXCursor_UnexposedDecl = 1,
641 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000642 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000643 /** \brief A C or C++ union. */
644 CXCursor_UnionDecl = 3,
645 /** \brief A C++ class. */
646 CXCursor_ClassDecl = 4,
647 /** \brief An enumeration. */
648 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000649 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000650 * \brief A field (in C) or non-static data member (in C++) in a
651 * struct, union, or C++ class.
652 */
653 CXCursor_FieldDecl = 6,
654 /** \brief An enumerator constant. */
655 CXCursor_EnumConstantDecl = 7,
656 /** \brief A function. */
657 CXCursor_FunctionDecl = 8,
658 /** \brief A variable. */
659 CXCursor_VarDecl = 9,
660 /** \brief A function or method parameter. */
661 CXCursor_ParmDecl = 10,
662 /** \brief An Objective-C @interface. */
663 CXCursor_ObjCInterfaceDecl = 11,
664 /** \brief An Objective-C @interface for a category. */
665 CXCursor_ObjCCategoryDecl = 12,
666 /** \brief An Objective-C @protocol declaration. */
667 CXCursor_ObjCProtocolDecl = 13,
668 /** \brief An Objective-C @property declaration. */
669 CXCursor_ObjCPropertyDecl = 14,
670 /** \brief An Objective-C instance variable. */
671 CXCursor_ObjCIvarDecl = 15,
672 /** \brief An Objective-C instance method. */
673 CXCursor_ObjCInstanceMethodDecl = 16,
674 /** \brief An Objective-C class method. */
675 CXCursor_ObjCClassMethodDecl = 17,
676 /** \brief An Objective-C @implementation. */
677 CXCursor_ObjCImplementationDecl = 18,
678 /** \brief An Objective-C @implementation for a category. */
679 CXCursor_ObjCCategoryImplDecl = 19,
680 /** \brief A typedef */
681 CXCursor_TypedefDecl = 20,
682 CXCursor_LastDecl = 20,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000683
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000684 /* References */
685 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000686 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000687 CXCursor_ObjCProtocolRef = 41,
688 CXCursor_ObjCClassRef = 42,
689 /**
690 * \brief A reference to a type declaration.
691 *
692 * A type reference occurs anywhere where a type is named but not
693 * declared. For example, given:
694 *
695 * \code
696 * typedef unsigned size_type;
697 * size_type size;
698 * \endcode
699 *
700 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
701 * while the type of the variable "size" is referenced. The cursor
702 * referenced by the type of size is the typedef for size_type.
703 */
704 CXCursor_TypeRef = 43,
705 CXCursor_LastRef = 43,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000706
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000707 /* Error conditions */
708 CXCursor_FirstInvalid = 70,
709 CXCursor_InvalidFile = 70,
710 CXCursor_NoDeclFound = 71,
711 CXCursor_NotImplemented = 72,
712 CXCursor_LastInvalid = 72,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000713
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000714 /* Expressions */
715 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000716
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000717 /**
718 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000719 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000720 *
721 * Unexposed expressions have the same operations as any other kind
722 * of expression; one can extract their location information,
723 * spelling, children, etc. However, the specific kind of the
724 * expression is not reported.
725 */
726 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000727
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000728 /**
729 * \brief An expression that refers to some value declaration, such
730 * as a function, varible, or enumerator.
731 */
732 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000733
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000734 /**
735 * \brief An expression that refers to a member of a struct, union,
736 * class, Objective-C class, etc.
737 */
738 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000739
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000740 /** \brief An expression that calls a function. */
741 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000742
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000743 /** \brief An expression that sends a message to an Objective-C
744 object or class. */
745 CXCursor_ObjCMessageExpr = 104,
746 CXCursor_LastExpr = 104,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000747
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000748 /* Statements */
749 CXCursor_FirstStmt = 200,
750 /**
751 * \brief A statement whose specific kind is not exposed via this
752 * interface.
753 *
754 * Unexposed statements have the same operations as any other kind of
755 * statement; one can extract their location information, spelling,
756 * children, etc. However, the specific kind of the statement is not
757 * reported.
758 */
759 CXCursor_UnexposedStmt = 200,
760 CXCursor_LastStmt = 200,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000761
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000762 /**
763 * \brief Cursor that represents the translation unit itself.
764 *
765 * The translation unit cursor exists primarily to act as the root
766 * cursor for traversing the contents of a translation unit.
767 */
768 CXCursor_TranslationUnit = 300
769};
770
771/**
772 * \brief A cursor representing some element in the abstract syntax tree for
773 * a translation unit.
774 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000775 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000776 * program--declaration, statements, expressions, references to declarations,
777 * etc.--under a single "cursor" abstraction with a common set of operations.
778 * Common operation for a cursor include: getting the physical location in
779 * a source file where the cursor points, getting the name associated with a
780 * cursor, and retrieving cursors for any child nodes of a particular cursor.
781 *
782 * Cursors can be produced in two specific ways.
783 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
784 * from which one can use clang_visitChildren() to explore the rest of the
785 * translation unit. clang_getCursor() maps from a physical source location
786 * to the entity that resides at that location, allowing one to map from the
787 * source code into the AST.
788 */
789typedef struct {
790 enum CXCursorKind kind;
791 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000792} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000793
794/**
795 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
796 *
797 * @{
798 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000799
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000800/**
801 * \brief Retrieve the NULL cursor, which represents no entity.
802 */
803CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000804
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000805/**
806 * \brief Retrieve the cursor that represents the given translation unit.
807 *
808 * The translation unit cursor can be used to start traversing the
809 * various declarations within the given translation unit.
810 */
811CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
812
813/**
814 * \brief Determine whether two cursors are equivalent.
815 */
816CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000817
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000818/**
819 * \brief Retrieve the kind of the given cursor.
820 */
821CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
822
823/**
824 * \brief Determine whether the given cursor kind represents a declaration.
825 */
826CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
827
828/**
829 * \brief Determine whether the given cursor kind represents a simple
830 * reference.
831 *
832 * Note that other kinds of cursors (such as expressions) can also refer to
833 * other cursors. Use clang_getCursorReferenced() to determine whether a
834 * particular cursor refers to another entity.
835 */
836CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
837
838/**
839 * \brief Determine whether the given cursor kind represents an expression.
840 */
841CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
842
843/**
844 * \brief Determine whether the given cursor kind represents a statement.
845 */
846CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
847
848/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000849 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000850 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000851 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000852CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
853
854/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000855 * \brief Determine whether the given cursor kind represents a translation
856 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000857 */
858CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000859
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000860/**
861 * @}
862 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000863
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000864/**
865 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
866 *
867 * Cursors represent a location within the Abstract Syntax Tree (AST). These
868 * routines help map between cursors and the physical locations where the
869 * described entities occur in the source code. The mapping is provided in
870 * both directions, so one can map from source code to the AST and back.
871 *
872 * @{
Steve Naroff50398192009-08-28 15:28:48 +0000873 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000874
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000875/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000876 * \brief Map a source location to the cursor that describes the entity at that
877 * location in the source code.
878 *
879 * clang_getCursor() maps an arbitrary source location within a translation
880 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000881 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +0000882 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000883 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +0000884 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
885 * will return a cursor referring to the "+" expression.
886 *
887 * \returns a cursor representing the entity at the given source location, or
888 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000889 */
Douglas Gregorb9790342010-01-22 21:44:22 +0000890CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000891
Douglas Gregor98258af2010-01-18 22:46:11 +0000892/**
893 * \brief Retrieve the physical location of the source constructor referenced
894 * by the given cursor.
895 *
896 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000897 * declaration, where the name of that declaration would occur if it is
898 * unnamed, or some keyword that introduces that particular declaration.
899 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +0000900 * source code.
901 */
902CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000903
Douglas Gregorb6998662010-01-19 19:34:47 +0000904/**
905 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +0000906 * the given cursor.
907 *
908 * The extent of a cursor starts with the file/line/column pointing at the
909 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000910 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +0000911 * declaration, the extent covers the declaration itself. For a reference,
912 * the extent covers the location of the reference (e.g., where the referenced
913 * entity was actually used).
914 */
915CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +0000916
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000917/**
918 * @}
919 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000920
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000921/**
922 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
923 *
924 * These routines provide the ability to traverse the abstract syntax tree
925 * using cursors.
926 *
927 * @{
928 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000929
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000930/**
931 * \brief Describes how the traversal of the children of a particular
932 * cursor should proceed after visiting a particular child cursor.
933 *
934 * A value of this enumeration type should be returned by each
935 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
936 */
937enum CXChildVisitResult {
938 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000939 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000940 */
941 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000942 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000943 * \brief Continues the cursor traversal with the next sibling of
944 * the cursor just visited, without visiting its children.
945 */
946 CXChildVisit_Continue,
947 /**
948 * \brief Recursively traverse the children of this cursor, using
949 * the same visitor and client data.
950 */
951 CXChildVisit_Recurse
952};
953
954/**
955 * \brief Visitor invoked for each cursor found by a traversal.
956 *
957 * This visitor function will be invoked for each cursor found by
958 * clang_visitCursorChildren(). Its first argument is the cursor being
959 * visited, its second argument is the parent visitor for that cursor,
960 * and its third argument is the client data provided to
961 * clang_visitCursorChildren().
962 *
963 * The visitor should return one of the \c CXChildVisitResult values
964 * to direct clang_visitCursorChildren().
965 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000966typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
967 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000968 CXClientData client_data);
969
970/**
971 * \brief Visit the children of a particular cursor.
972 *
973 * This function visits all the direct children of the given cursor,
974 * invoking the given \p visitor function with the cursors of each
975 * visited child. The traversal may be recursive, if the visitor returns
976 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
977 * the visitor returns \c CXChildVisit_Break.
978 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000979 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +0000980 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000981 * definition, have no children).
982 *
983 * \param visitor the visitor function that will be invoked for each
984 * child of \p parent.
985 *
986 * \param client_data pointer data supplied by the client, which will
987 * be passed to the visitor each time it is invoked.
988 *
989 * \returns a non-zero value if the traversal was terminated
990 * prematurely by the visitor returning \c CXChildVisit_Break.
991 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000992CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000993 CXCursorVisitor visitor,
994 CXClientData client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000995
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000996/**
997 * @}
998 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000999
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001000/**
1001 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1002 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001003 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001004 * across translation units, by providing the names of the entities referenced
1005 * by cursors, follow reference cursors to the declarations they reference,
1006 * and associate declarations with their definitions.
1007 *
1008 * @{
1009 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001010
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001011/**
1012 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1013 * by the given cursor.
1014 *
1015 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1016 * entity (function, class, variable, etc.) within a program. USRs can be
1017 * compared across translation units to determine, e.g., when references in
1018 * one translation refer to an entity defined in another translation unit.
1019 */
1020CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1021
1022/**
1023 * \brief Retrieve a name for the entity referenced by this cursor.
1024 */
1025CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1026
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001027/** \brief For a cursor that is a reference, retrieve a cursor representing the
1028 * entity that it references.
1029 *
1030 * Reference cursors refer to other entities in the AST. For example, an
1031 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001032 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001033 * cursor for the superclass reference. If the input cursor is a declaration or
1034 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001035 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001036 */
1037CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001038
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001039/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001040 * \brief For a cursor that is either a reference to or a declaration
1041 * of some entity, retrieve a cursor that describes the definition of
1042 * that entity.
1043 *
1044 * Some entities can be declared multiple times within a translation
1045 * unit, but only one of those declarations can also be a
1046 * definition. For example, given:
1047 *
1048 * \code
1049 * int f(int, int);
1050 * int g(int x, int y) { return f(x, y); }
1051 * int f(int a, int b) { return a + b; }
1052 * int f(int, int);
1053 * \endcode
1054 *
1055 * there are three declarations of the function "f", but only the
1056 * second one is a definition. The clang_getCursorDefinition()
1057 * function will take any cursor pointing to a declaration of "f"
1058 * (the first or fourth lines of the example) or a cursor referenced
1059 * that uses "f" (the call to "f' inside "g") and will return a
1060 * declaration cursor pointing to the definition (the second "f"
1061 * declaration).
1062 *
1063 * If given a cursor for which there is no corresponding definition,
1064 * e.g., because there is no definition of that entity within this
1065 * translation unit, returns a NULL cursor.
1066 */
1067CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1068
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001069/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001070 * \brief Determine whether the declaration pointed to by this cursor
1071 * is also a definition of that entity.
1072 */
1073CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1074
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001075/**
1076 * @}
1077 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001078
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001079/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001080 * \defgroup CINDEX_LEX Token extraction and manipulation
1081 *
1082 * The routines in this group provide access to the tokens within a
1083 * translation unit, along with a semantic mapping of those tokens to
1084 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001085 *
1086 * @{
1087 */
1088
1089/**
1090 * \brief Describes a kind of token.
1091 */
1092typedef enum CXTokenKind {
1093 /**
1094 * \brief A token that contains some kind of punctuation.
1095 */
1096 CXToken_Punctuation,
1097
1098 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001099 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001100 */
1101 CXToken_Keyword,
1102
1103 /**
1104 * \brief An identifier (that is not a keyword).
1105 */
1106 CXToken_Identifier,
1107
1108 /**
1109 * \brief A numeric, string, or character literal.
1110 */
1111 CXToken_Literal,
1112
1113 /**
1114 * \brief A comment.
1115 */
1116 CXToken_Comment
1117} CXTokenKind;
1118
1119/**
1120 * \brief Describes a single preprocessing token.
1121 */
1122typedef struct {
1123 unsigned int_data[4];
1124 void *ptr_data;
1125} CXToken;
1126
1127/**
1128 * \brief Determine the kind of the given token.
1129 */
1130CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
1131
1132/**
1133 * \brief Determine the spelling of the given token.
1134 *
1135 * The spelling of a token is the textual representation of that token, e.g.,
1136 * the text of an identifier or keyword.
1137 */
1138CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
1139
1140/**
1141 * \brief Retrieve the source location of the given token.
1142 */
1143CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
1144 CXToken);
1145
1146/**
1147 * \brief Retrieve a source range that covers the given token.
1148 */
1149CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
1150
1151/**
1152 * \brief Tokenize the source code described by the given range into raw
1153 * lexical tokens.
1154 *
1155 * \param TU the translation unit whose text is being tokenized.
1156 *
1157 * \param Range the source range in which text should be tokenized. All of the
1158 * tokens produced by tokenization will fall within this source range,
1159 *
1160 * \param Tokens this pointer will be set to point to the array of tokens
1161 * that occur within the given source range. The returned pointer must be
1162 * freed with clang_disposeTokens() before the translation unit is destroyed.
1163 *
1164 * \param NumTokens will be set to the number of tokens in the \c *Tokens
1165 * array.
1166 *
1167 */
1168CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
1169 CXToken **Tokens, unsigned *NumTokens);
1170
1171/**
1172 * \brief Annotate the given set of tokens by providing cursors for each token
1173 * that can be mapped to a specific entity within the abstract syntax tree.
1174 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001175 * This token-annotation routine is equivalent to invoking
1176 * clang_getCursor() for the source locations of each of the
1177 * tokens. The cursors provided are filtered, so that only those
1178 * cursors that have a direct correspondence to the token are
1179 * accepted. For example, given a function call \c f(x),
1180 * clang_getCursor() would provide the following cursors:
1181 *
1182 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
1183 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
1184 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
1185 *
1186 * Only the first and last of these cursors will occur within the
1187 * annotate, since the tokens "f" and "x' directly refer to a function
1188 * and a variable, respectively, but the parentheses are just a small
1189 * part of the full syntax of the function call expression, which is
1190 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001191 *
1192 * \param TU the translation unit that owns the given tokens.
1193 *
1194 * \param Tokens the set of tokens to annotate.
1195 *
1196 * \param NumTokens the number of tokens in \p Tokens.
1197 *
1198 * \param Cursors an array of \p NumTokens cursors, whose contents will be
1199 * replaced with the cursors corresponding to each token.
1200 */
1201CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
1202 CXToken *Tokens, unsigned NumTokens,
1203 CXCursor *Cursors);
1204
1205/**
1206 * \brief Free the given set of tokens.
1207 */
1208CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
1209 CXToken *Tokens, unsigned NumTokens);
1210
1211/**
1212 * @}
1213 */
1214
1215/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001216 * \defgroup CINDEX_DEBUG Debugging facilities
1217 *
1218 * These routines are used for testing and debugging, only, and should not
1219 * be relied upon.
1220 *
1221 * @{
1222 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001223
Steve Naroff4ade6d62009-09-23 17:52:52 +00001224/* for debug/testing */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001225CINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
1226CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
1227 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00001228 const char **endBuf,
1229 unsigned *startLine,
1230 unsigned *startColumn,
1231 unsigned *endLine,
1232 unsigned *endColumn);
Steve Naroff600866c2009-08-27 19:51:58 +00001233
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001234/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001235 * @}
1236 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001237
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001238/**
1239 * \defgroup CINDEX_CODE_COMPLET Code completion
1240 *
1241 * Code completion involves taking an (incomplete) source file, along with
1242 * knowledge of where the user is actively editing that file, and suggesting
1243 * syntactically- and semantically-valid constructs that the user might want to
1244 * use at that particular point in the source code. These data structures and
1245 * routines provide support for code completion.
1246 *
1247 * @{
1248 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001249
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001250/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001251 * \brief A semantic string that describes a code-completion result.
1252 *
1253 * A semantic string that describes the formatting of a code-completion
1254 * result as a single "template" of text that should be inserted into the
1255 * source buffer when a particular code-completion result is selected.
1256 * Each semantic string is made up of some number of "chunks", each of which
1257 * contains some text along with a description of what that text means, e.g.,
1258 * the name of the entity being referenced, whether the text chunk is part of
1259 * the template, or whether it is a "placeholder" that the user should replace
1260 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001261 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001262 */
1263typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001264
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001265/**
1266 * \brief A single result of code completion.
1267 */
1268typedef struct {
1269 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001270 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001271 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001272 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001273 * *Decl cursor kinds), describing the entity that the completion is
1274 * referring to.
1275 *
1276 * \todo In the future, we would like to provide a full cursor, to allow
1277 * the client to extract additional information from declaration.
1278 */
1279 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001280
1281 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001282 * \brief The code-completion string that describes how to insert this
1283 * code-completion result into the editing buffer.
1284 */
1285 CXCompletionString CompletionString;
1286} CXCompletionResult;
1287
1288/**
1289 * \brief Describes a single piece of text within a code-completion string.
1290 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001291 * Each "chunk" within a code-completion string (\c CXCompletionString) is
1292 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001293 * should be interpreted by the client or is another completion string.
1294 */
1295enum CXCompletionChunkKind {
1296 /**
1297 * \brief A code-completion string that describes "optional" text that
1298 * could be a part of the template (but is not required).
1299 *
1300 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001301 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001302 * \c clang_getCompletionChunkCompletionString(). The code-completion string
1303 * describes an additional part of the template that is completely optional.
1304 * For example, optional chunks can be used to describe the placeholders for
1305 * arguments that match up with defaulted function parameters, e.g. given:
1306 *
1307 * \code
1308 * void f(int x, float y = 3.14, double z = 2.71828);
1309 * \endcode
1310 *
1311 * The code-completion string for this function would contain:
1312 * - a TypedText chunk for "f".
1313 * - a LeftParen chunk for "(".
1314 * - a Placeholder chunk for "int x"
1315 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
1316 * - a Comma chunk for ","
1317 * - a Placeholder chunk for "float x"
1318 * - an Optional chunk containing the last defaulted argument:
1319 * - a Comma chunk for ","
1320 * - a Placeholder chunk for "double z"
1321 * - a RightParen chunk for ")"
1322 *
1323 * There are many ways two handle Optional chunks. Two simple approaches are:
1324 * - Completely ignore optional chunks, in which case the template for the
1325 * function "f" would only include the first parameter ("int x").
1326 * - Fully expand all optional chunks, in which case the template for the
1327 * function "f" would have all of the parameters.
1328 */
1329 CXCompletionChunk_Optional,
1330 /**
1331 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001332 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001333 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001334 * There will be exactly one "typed text" chunk in a semantic string, which
1335 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001336 * declaration that could be used at the current code point. Clients are
1337 * expected to filter the code-completion results based on the text in this
1338 * chunk.
1339 */
1340 CXCompletionChunk_TypedText,
1341 /**
1342 * \brief Text that should be inserted as part of a code-completion result.
1343 *
1344 * A "text" chunk represents text that is part of the template to be
1345 * inserted into user code should this particular code-completion result
1346 * be selected.
1347 */
1348 CXCompletionChunk_Text,
1349 /**
1350 * \brief Placeholder text that should be replaced by the user.
1351 *
1352 * A "placeholder" chunk marks a place where the user should insert text
1353 * into the code-completion template. For example, placeholders might mark
1354 * the function parameters for a function declaration, to indicate that the
1355 * user should provide arguments for each of those parameters. The actual
1356 * text in a placeholder is a suggestion for the text to display before
1357 * the user replaces the placeholder with real code.
1358 */
1359 CXCompletionChunk_Placeholder,
1360 /**
1361 * \brief Informative text that should be displayed but never inserted as
1362 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001363 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001364 * An "informative" chunk contains annotations that can be displayed to
1365 * help the user decide whether a particular code-completion result is the
1366 * right option, but which is not part of the actual template to be inserted
1367 * by code completion.
1368 */
1369 CXCompletionChunk_Informative,
1370 /**
1371 * \brief Text that describes the current parameter when code-completion is
1372 * referring to function call, message send, or template specialization.
1373 *
1374 * A "current parameter" chunk occurs when code-completion is providing
1375 * information about a parameter corresponding to the argument at the
1376 * code-completion point. For example, given a function
1377 *
1378 * \code
1379 * int add(int x, int y);
1380 * \endcode
1381 *
1382 * and the source code \c add(, where the code-completion point is after the
1383 * "(", the code-completion string will contain a "current parameter" chunk
1384 * for "int x", indicating that the current argument will initialize that
1385 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001386 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001387 * "current paremeter" chunk to "int y".
1388 */
1389 CXCompletionChunk_CurrentParameter,
1390 /**
1391 * \brief A left parenthesis ('('), used to initiate a function call or
1392 * signal the beginning of a function parameter list.
1393 */
1394 CXCompletionChunk_LeftParen,
1395 /**
1396 * \brief A right parenthesis (')'), used to finish a function call or
1397 * signal the end of a function parameter list.
1398 */
1399 CXCompletionChunk_RightParen,
1400 /**
1401 * \brief A left bracket ('[').
1402 */
1403 CXCompletionChunk_LeftBracket,
1404 /**
1405 * \brief A right bracket (']').
1406 */
1407 CXCompletionChunk_RightBracket,
1408 /**
1409 * \brief A left brace ('{').
1410 */
1411 CXCompletionChunk_LeftBrace,
1412 /**
1413 * \brief A right brace ('}').
1414 */
1415 CXCompletionChunk_RightBrace,
1416 /**
1417 * \brief A left angle bracket ('<').
1418 */
1419 CXCompletionChunk_LeftAngle,
1420 /**
1421 * \brief A right angle bracket ('>').
1422 */
1423 CXCompletionChunk_RightAngle,
1424 /**
1425 * \brief A comma separator (',').
1426 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001427 CXCompletionChunk_Comma,
1428 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001429 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001430 *
1431 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001432 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001433 * expression using the given completion string would have.
1434 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00001435 CXCompletionChunk_ResultType,
1436 /**
1437 * \brief A colon (':').
1438 */
1439 CXCompletionChunk_Colon,
1440 /**
1441 * \brief A semicolon (';').
1442 */
1443 CXCompletionChunk_SemiColon,
1444 /**
1445 * \brief An '=' sign.
1446 */
1447 CXCompletionChunk_Equal,
1448 /**
1449 * Horizontal space (' ').
1450 */
1451 CXCompletionChunk_HorizontalSpace,
1452 /**
1453 * Vertical space ('\n'), after which it is generally a good idea to
1454 * perform indentation.
1455 */
1456 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001457};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001458
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001459/**
1460 * \brief Determine the kind of a particular chunk within a completion string.
1461 *
1462 * \param completion_string the completion string to query.
1463 *
1464 * \param chunk_number the 0-based index of the chunk in the completion string.
1465 *
1466 * \returns the kind of the chunk at the index \c chunk_number.
1467 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001468CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001469clang_getCompletionChunkKind(CXCompletionString completion_string,
1470 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001471
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001472/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001473 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001474 * completion string.
1475 *
1476 * \param completion_string the completion string to query.
1477 *
1478 * \param chunk_number the 0-based index of the chunk in the completion string.
1479 *
1480 * \returns the text associated with the chunk at index \c chunk_number.
1481 */
1482CINDEX_LINKAGE const char *
1483clang_getCompletionChunkText(CXCompletionString completion_string,
1484 unsigned chunk_number);
1485
1486/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001487 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001488 * within a completion string.
1489 *
1490 * \param completion_string the completion string to query.
1491 *
1492 * \param chunk_number the 0-based index of the chunk in the completion string.
1493 *
1494 * \returns the completion string associated with the chunk at index
1495 * \c chunk_number, or NULL if that chunk is not represented by a completion
1496 * string.
1497 */
1498CINDEX_LINKAGE CXCompletionString
1499clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
1500 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001501
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001502/**
1503 * \brief Retrieve the number of chunks in the given code-completion string.
1504 */
1505CINDEX_LINKAGE unsigned
1506clang_getNumCompletionChunks(CXCompletionString completion_string);
1507
1508/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00001509 * \brief Contains the results of code-completion.
1510 *
1511 * This data structure contains the results of code completion, as
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001512 * produced by \c clang_codeComplete. Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00001513 * \c clang_disposeCodeCompleteResults.
1514 */
1515typedef struct {
1516 /**
1517 * \brief The code-completion results.
1518 */
1519 CXCompletionResult *Results;
1520
1521 /**
1522 * \brief The number of code-completion results stored in the
1523 * \c Results array.
1524 */
1525 unsigned NumResults;
1526} CXCodeCompleteResults;
1527
1528/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001529 * \brief Perform code completion at a given location in a source file.
1530 *
1531 * This function performs code completion at a particular file, line, and
1532 * column within source code, providing results that suggest potential
1533 * code snippets based on the context of the completion. The basic model
1534 * for code completion is that Clang will parse a complete source file,
1535 * performing syntax checking up to the location where code-completion has
1536 * been requested. At that point, a special code-completion token is passed
1537 * to the parser, which recognizes this token and determines, based on the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001538 * current location in the C/Objective-C/C++ grammar and the state of
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001539 * semantic analysis, what completions to provide. These completions are
Douglas Gregorec6762c2009-12-18 16:20:58 +00001540 * returned via a new \c CXCodeCompleteResults structure.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001541 *
1542 * Code completion itself is meant to be triggered by the client when the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001543 * user types punctuation characters or whitespace, at which point the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001544 * code-completion location will coincide with the cursor. For example, if \c p
1545 * is a pointer, code-completion might be triggered after the "-" and then
1546 * after the ">" in \c p->. When the code-completion location is afer the ">",
1547 * the completion results will provide, e.g., the members of the struct that
1548 * "p" points to. The client is responsible for placing the cursor at the
1549 * beginning of the token currently being typed, then filtering the results
1550 * based on the contents of the token. For example, when code-completing for
1551 * the expression \c p->get, the client should provide the location just after
1552 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
1553 * client can filter the results based on the current token text ("get"), only
1554 * showing those results that start with "get". The intent of this interface
Douglas Gregorec6762c2009-12-18 16:20:58 +00001555 * is to separate the relatively high-latency acquisition of code-completion
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001556 * results from the filtering of results on a per-character basis, which must
1557 * have a lower latency.
1558 *
1559 * \param CIdx the \c CXIndex instance that will be used to perform code
1560 * completion.
1561 *
Daniel Dunbar8506dde2009-12-03 01:54:28 +00001562 * \param source_filename the name of the source file that should be parsed to
1563 * perform code-completion. This source file must be the same as or include the
1564 * filename described by \p complete_filename, or no code-completion results
1565 * will be produced. NOTE: One can also specify NULL for this argument if the
1566 * source file is included in command_line_args.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001567 *
1568 * \param num_command_line_args the number of command-line arguments stored in
1569 * \p command_line_args.
1570 *
1571 * \param command_line_args the command-line arguments to pass to the Clang
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001572 * compiler to build the given source file. This should include all of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001573 * necessary include paths, language-dialect switches, precompiled header
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001574 * includes, etc., but should not include any information specific to
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001575 * code completion.
1576 *
Douglas Gregor735df882009-12-02 09:21:34 +00001577 * \param num_unsaved_files the number of unsaved file entries in \p
1578 * unsaved_files.
1579 *
1580 * \param unsaved_files the files that have not yet been saved to disk
1581 * but may be required for code completion, including the contents of
1582 * those files.
1583 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001584 * \param complete_filename the name of the source file where code completion
1585 * should be performed. In many cases, this name will be the same as the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001586 * source filename. However, the completion filename may also be a file
1587 * included by the source file, which is required when producing
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001588 * code-completion results for a header.
1589 *
1590 * \param complete_line the line at which code-completion should occur.
1591 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001592 * \param complete_column the column at which code-completion should occur.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001593 * Note that the column should point just after the syntactic construct that
1594 * initiated code completion, and not in the middle of a lexical token.
1595 *
Douglas Gregorec6762c2009-12-18 16:20:58 +00001596 * \returns if successful, a new CXCodeCompleteResults structure
1597 * containing code-completion results, which should eventually be
1598 * freed with \c clang_disposeCodeCompleteResults(). If code
1599 * completion fails, returns NULL.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001600 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001601CINDEX_LINKAGE
1602CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001603 const char *source_filename,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001604 int num_command_line_args,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001605 const char **command_line_args,
1606 unsigned num_unsaved_files,
1607 struct CXUnsavedFile *unsaved_files,
1608 const char *complete_filename,
1609 unsigned complete_line,
1610 unsigned complete_column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001611
Douglas Gregorec6762c2009-12-18 16:20:58 +00001612/**
1613 * \brief Free the given set of code-completion results.
1614 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001615CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00001616void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001617
Douglas Gregor20d416c2010-01-20 01:10:47 +00001618/**
1619 * @}
1620 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001621
1622
Ted Kremenek04bb7162010-01-22 22:44:15 +00001623/**
1624 * \defgroup CINDEX_MISC Miscellaneous utility functions
1625 *
1626 * @{
1627 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00001628
1629/**
1630 * \brief Return a version string, suitable for showing to a user, but not
1631 * intended to be parsed (the format is not guaranteed to be stable).
1632 */
Ted Kremenek04bb7162010-01-22 22:44:15 +00001633CINDEX_LINKAGE const char *clang_getClangVersion();
1634
1635/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00001636 * \brief Return a version string, suitable for showing to a user, but not
1637 * intended to be parsed (the format is not guaranteed to be stable).
1638 */
1639
1640
1641 /**
1642 * \brief Visitor invoked for each file in a translation unit
1643 * (used with clang_getInclusions()).
1644 *
1645 * This visitor function will be invoked by clang_getInclusions() for each
1646 * file included (either at the top-level or by #include directives) within
1647 * a translation unit. The first argument is the file being included, and
1648 * the second and third arguments provide the inclusion stack. The
1649 * array is sorted in order of immediate inclusion. For example,
1650 * the first element refers to the location that included 'included_file'.
1651 */
1652typedef void (*CXInclusionVisitor)(CXFile included_file,
1653 CXSourceLocation* inclusion_stack,
1654 unsigned include_len,
1655 CXClientData client_data);
1656
1657/**
1658 * \brief Visit the set of preprocessor inclusions in a translation unit.
1659 * The visitor function is called with the provided data for every included
1660 * file. This does not include headers included by the PCH file (unless one
1661 * is inspecting the inclusions in the PCH file itself).
1662 */
1663CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
1664 CXInclusionVisitor visitor,
1665 CXClientData client_data);
1666
1667/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00001668 * @}
1669 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001670
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001671/**
1672 * @}
1673 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001674
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001675#ifdef __cplusplus
1676}
1677#endif
1678#endif
1679