blob: 663737a0f36b3b04f022a5200e82ee194c5ba975 [file] [log] [blame]
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
Steve Naroff88145032009-10-27 14:35:18 +000019#include <sys/stat.h>
Chandler Carruth3d315602009-12-17 09:27:29 +000020#include <time.h>
Douglas Gregor0a812cf2010-02-18 23:07:20 +000021#include <stdio.h>
Steve Naroff88145032009-10-27 14:35:18 +000022
Ted Kremenekd2fa5662009-08-26 22:36:44 +000023#ifdef __cplusplus
24extern "C" {
25#endif
26
Steve Naroff88145032009-10-27 14:35:18 +000027/* MSVC DLL import/export. */
John Thompson2e06fc82009-10-27 13:42:56 +000028#ifdef _MSC_VER
29 #ifdef _CINDEX_LIB_
30 #define CINDEX_LINKAGE __declspec(dllexport)
31 #else
32 #define CINDEX_LINKAGE __declspec(dllimport)
33 #endif
34#else
35 #define CINDEX_LINKAGE
36#endif
37
Douglas Gregor20d416c2010-01-20 01:10:47 +000038/** \defgroup CINDEX C Interface to Clang
39 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000040 * The C Interface to Clang provides a relatively small API that exposes
Douglas Gregorf5525442010-01-20 22:45:41 +000041 * facilities for parsing source code into an abstract syntax tree (AST),
42 * loading already-parsed ASTs, traversing the AST, associating
43 * physical source locations with elements within the AST, and other
44 * facilities that support Clang-based development tools.
Douglas Gregor20d416c2010-01-20 01:10:47 +000045 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000046 * This C interface to Clang will never provide all of the information
Douglas Gregorf5525442010-01-20 22:45:41 +000047 * representation stored in Clang's C++ AST, nor should it: the intent is to
48 * maintain an API that is relatively stable from one release to the next,
49 * providing only the basic functionality needed to support development tools.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000050 *
51 * To avoid namespace pollution, data types are prefixed with "CX" and
Douglas Gregorf5525442010-01-20 22:45:41 +000052 * functions are prefixed with "clang_".
Douglas Gregor20d416c2010-01-20 01:10:47 +000053 *
54 * @{
55 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000056
Douglas Gregor7f173762010-01-20 22:28:27 +000057/**
58 * \brief An "index" that consists of a set of translation units that would
59 * typically be linked together into an executable or library.
60 */
61typedef void *CXIndex;
Steve Naroff600866c2009-08-27 19:51:58 +000062
Douglas Gregor7f173762010-01-20 22:28:27 +000063/**
64 * \brief A single translation unit, which resides in an index.
65 */
Steve Naroff50398192009-08-28 15:28:48 +000066typedef void *CXTranslationUnit; /* A translation unit instance. */
Steve Naroff600866c2009-08-27 19:51:58 +000067
Douglas Gregor7f173762010-01-20 22:28:27 +000068/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000069 * \brief Opaque pointer representing client data that will be passed through
70 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000071 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000072typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000073
Douglas Gregor735df882009-12-02 09:21:34 +000074/**
75 * \brief Provides the contents of a file that has not yet been saved to disk.
76 *
77 * Each CXUnsavedFile instance provides the name of a file on the
78 * system along with the current contents of that file that have not
79 * yet been saved to disk.
80 */
81struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000082 /**
83 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000084 *
85 * This file must already exist in the file system.
86 */
87 const char *Filename;
88
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000089 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000090 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +000091 */
92 const char *Contents;
93
94 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000095 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +000096 */
97 unsigned long Length;
98};
99
Douglas Gregor7f173762010-01-20 22:28:27 +0000100/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000101 * \defgroup CINDEX_STRING String manipulation routines
102 *
103 * @{
104 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000105
Douglas Gregor7f173762010-01-20 22:28:27 +0000106/**
107 * \brief A character string.
108 *
109 * The \c CXString type is used to return strings from the interface when
110 * the ownership of that string might different from one call to the next.
111 * Use \c clang_getCString() to retrieve the string data and, once finished
112 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000113 */
114typedef struct {
115 const char *Spelling;
116 /* A 1 value indicates the clang_ indexing API needed to allocate the string
117 (and it must be freed by clang_disposeString()). */
118 int MustFreeString;
119} CXString;
120
Douglas Gregor7f173762010-01-20 22:28:27 +0000121/**
122 * \brief Retrieve the character data associated with the given string.
123 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000124CINDEX_LINKAGE const char *clang_getCString(CXString string);
125
Douglas Gregor7f173762010-01-20 22:28:27 +0000126/**
127 * \brief Free the given string,
128 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000129CINDEX_LINKAGE void clang_disposeString(CXString string);
130
Douglas Gregor7f173762010-01-20 22:28:27 +0000131/**
132 * @}
133 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000134
135/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000136 * \brief clang_createIndex() provides a shared context for creating
137 * translation units. It provides two options:
138 *
139 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
140 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000141 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000142 * header that was used by the translation unit. If zero, all declarations
143 * will be enumerated.
144 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000145 * Here is an example:
146 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000147 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
148 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000149 *
150 * // IndexTest.pch was produced with the following command:
151 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
152 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
153 *
154 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000155 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000156 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000157 * clang_disposeTranslationUnit(TU);
158 *
159 * // This will load all the symbols from 'IndexTest.c', excluding symbols
160 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000161 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
162 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
163 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000164 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
165 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000166 * clang_disposeTranslationUnit(TU);
167 *
168 * This process of creating the 'pch', loading it separately, and using it (via
169 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
170 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000171 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000172CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
173 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000174
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000175/**
176 * \brief Destroy the given index.
177 *
178 * The index must not be destroyed until all of the translation units created
179 * within that index have been destroyed.
180 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000181CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000182
183/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000184 * \brief Request that AST's be generated externally for API calls which parse
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000185 * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
186 *
187 * Note: This is for debugging purposes only, and may be removed at a later
188 * date.
189 *
190 * \param index - The index to update.
191 * \param value - The new flag value.
192 */
193CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
194 int value);
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +0000195/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000196 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000197 *
198 * @{
199 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000200
Douglas Gregorf5525442010-01-20 22:45:41 +0000201/**
202 * \brief A particular source file that is part of a translation unit.
203 */
204typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000205
Douglas Gregorf5525442010-01-20 22:45:41 +0000206
207/**
208 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000209 */
Ted Kremenek74844072010-02-17 00:41:20 +0000210CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000211
Douglas Gregorf5525442010-01-20 22:45:41 +0000212/**
213 * \brief Retrieve the last modification time of the given file.
214 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000215CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000216
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000217/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000218 * \brief Retrieve a file handle within the given translation unit.
219 *
220 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000221 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000222 * \param file_name the name of the file.
223 *
224 * \returns the file handle for the named file in the translation unit \p tu,
225 * or a NULL file handle if the file was not a part of this translation unit.
226 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000227CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000228 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000229
Douglas Gregorb9790342010-01-22 21:44:22 +0000230/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000231 * @}
232 */
233
234/**
235 * \defgroup CINDEX_LOCATIONS Physical source locations
236 *
237 * Clang represents physical source locations in its abstract syntax tree in
238 * great detail, with file, line, and column information for the majority of
239 * the tokens parsed in the source code. These data types and functions are
240 * used to represent source location information, either for a particular
241 * point in the program or for a range of points in the program, and extract
242 * specific location information from those data types.
243 *
244 * @{
245 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000246
Douglas Gregorf5525442010-01-20 22:45:41 +0000247/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000248 * \brief Identifies a specific source location within a translation
249 * unit.
250 *
251 * Use clang_getInstantiationLocation() to map a source location to a
252 * particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000253 */
254typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000255 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000256 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000257} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000258
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000259/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000260 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000261 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000262 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
263 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000264 */
265typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000266 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000267 unsigned begin_int_data;
268 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000269} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000270
Douglas Gregor1db19de2010-01-19 21:36:55 +0000271/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000272 * \brief Retrieve a NULL (invalid) source location.
273 */
274CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000275
Douglas Gregorb9790342010-01-22 21:44:22 +0000276/**
277 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000278 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000279 * code.
280 *
281 * \returns non-zero if the source locations refer to the same location, zero
282 * if they refer to different locations.
283 */
284CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
285 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000286
Douglas Gregorb9790342010-01-22 21:44:22 +0000287/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000288 * \brief Retrieves the source location associated with a given file/line/column
289 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000290 */
291CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
292 CXFile file,
293 unsigned line,
294 unsigned column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000295
Douglas Gregorb9790342010-01-22 21:44:22 +0000296/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000297 * \brief Retrieve a NULL (invalid) source range.
298 */
299CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000300
Douglas Gregor5352ac02010-01-28 00:27:43 +0000301/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000302 * \brief Retrieve a source range given the beginning and ending source
303 * locations.
304 */
305CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
306 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000307
Douglas Gregorb9790342010-01-22 21:44:22 +0000308/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000309 * \brief Retrieve the file, line, column, and offset represented by
310 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000311 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000312 * \param location the location within a source file that will be decomposed
313 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000314 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000315 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000316 * source location points.
317 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000318 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000319 * source location points.
320 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000321 * \param column [out] if non-NULL, will be set to the column to which the given
322 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000323 *
324 * \param offset [out] if non-NULL, will be set to the offset into the
325 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000326 */
327CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
328 CXFile *file,
329 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000330 unsigned *column,
331 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000332
333/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000334 * \brief Retrieve a source location representing the first character within a
335 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000336 */
337CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
338
339/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000340 * \brief Retrieve a source location representing the last character within a
341 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000342 */
343CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
344
Douglas Gregorf5525442010-01-20 22:45:41 +0000345/**
346 * @}
347 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000348
349/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000350 * \defgroup CINDEX_DIAG Diagnostic reporting
351 *
352 * @{
353 */
354
355/**
356 * \brief Describes the severity of a particular diagnostic.
357 */
358enum CXDiagnosticSeverity {
359 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000360 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000361 * option.
362 */
363 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000364
Douglas Gregor5352ac02010-01-28 00:27:43 +0000365 /**
366 * \brief This diagnostic is a note that should be attached to the
367 * previous (non-note) diagnostic.
368 */
369 CXDiagnostic_Note = 1,
370
371 /**
372 * \brief This diagnostic indicates suspicious code that may not be
373 * wrong.
374 */
375 CXDiagnostic_Warning = 2,
376
377 /**
378 * \brief This diagnostic indicates that the code is ill-formed.
379 */
380 CXDiagnostic_Error = 3,
381
382 /**
383 * \brief This diagnostic indicates that the code is ill-formed such
384 * that future parser recovery is unlikely to produce useful
385 * results.
386 */
387 CXDiagnostic_Fatal = 4
388};
389
390/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000391 * \brief A single diagnostic, containing the diagnostic's severity,
392 * location, text, source ranges, and fix-it hints.
393 */
394typedef void *CXDiagnostic;
395
396/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000397 * \brief Determine the number of diagnostics produced for the given
398 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000399 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000400CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
401
402/**
403 * \brief Retrieve a diagnostic associated with the given translation unit.
404 *
405 * \param Unit the translation unit to query.
406 * \param Index the zero-based diagnostic number to retrieve.
407 *
408 * \returns the requested diagnostic. This diagnostic must be freed
409 * via a call to \c clang_disposeDiagnostic().
410 */
411CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
412 unsigned Index);
413
414/**
415 * \brief Destroy a diagnostic.
416 */
417CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000418
419/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000420 * \brief Options to control the display of diagnostics.
421 *
422 * The values in this enum are meant to be combined to customize the
423 * behavior of \c clang_displayDiagnostic().
424 */
425enum CXDiagnosticDisplayOptions {
426 /**
427 * \brief Display the source-location information where the
428 * diagnostic was located.
429 *
430 * When set, diagnostics will be prefixed by the file, line, and
431 * (optionally) column to which the diagnostic refers. For example,
432 *
433 * \code
434 * test.c:28: warning: extra tokens at end of #endif directive
435 * \endcode
436 *
437 * This option corresponds to the clang flag \c -fshow-source-location.
438 */
439 CXDiagnostic_DisplaySourceLocation = 0x01,
440
441 /**
442 * \brief If displaying the source-location information of the
443 * diagnostic, also include the column number.
444 *
445 * This option corresponds to the clang flag \c -fshow-column.
446 */
447 CXDiagnostic_DisplayColumn = 0x02,
448
449 /**
450 * \brief If displaying the source-location information of the
451 * diagnostic, also include information about source ranges in a
452 * machine-parsable format.
453 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000454 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000455 * \c -fdiagnostics-print-source-range-info.
456 */
457 CXDiagnostic_DisplaySourceRanges = 0x04
458};
459
460/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000461 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000462 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000463 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000464 * the diagnostic according to the various options given. The
465 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000466 * options that most closely mimics the behavior of the clang compiler.
467 *
468 * \param Diagnostic The diagnostic to print.
469 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000470 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000471 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000472 *
473 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000474 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000475CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
476 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000477
478/**
479 * \brief Retrieve the set of display options most similar to the
480 * default behavior of the clang compiler.
481 *
482 * \returns A set of display options suitable for use with \c
483 * clang_displayDiagnostic().
484 */
485CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
486
487/**
488 * \brief Print a diagnostic to the given file.
489 */
490
491/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000492 * \brief Determine the severity of the given diagnostic.
493 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000494CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000495clang_getDiagnosticSeverity(CXDiagnostic);
496
497/**
498 * \brief Retrieve the source location of the given diagnostic.
499 *
500 * This location is where Clang would print the caret ('^') when
501 * displaying the diagnostic on the command line.
502 */
503CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
504
505/**
506 * \brief Retrieve the text of the given diagnostic.
507 */
508CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000509
510/**
511 * \brief Determine the number of source ranges associated with the given
512 * diagnostic.
513 */
514CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000515
Douglas Gregor5352ac02010-01-28 00:27:43 +0000516/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000517 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000518 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000519 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000520 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000521 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000522 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000523 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000524 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000525 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000526 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000527 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000528 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000529CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000530 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000531
532/**
533 * \brief Determine the number of fix-it hints associated with the
534 * given diagnostic.
535 */
536CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
537
538/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000539 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000540 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000541 * Fix-its are described in terms of a source range whose contents
542 * should be replaced by a string. This approach generalizes over
543 * three kinds of operations: removal of source code (the range covers
544 * the code to be removed and the replacement string is empty),
545 * replacement of source code (the range covers the code to be
546 * replaced and the replacement string provides the new code), and
547 * insertion (both the start and end of the range point at the
548 * insertion location, and the replacement string provides the text to
549 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000550 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000551 * \param Diagnostic The diagnostic whose fix-its are being queried.
552 *
553 * \param FixIt The zero-based index of the fix-it.
554 *
555 * \param ReplacementRange The source range whose contents will be
556 * replaced with the returned replacement string. Note that source
557 * ranges are half-open ranges [a, b), so the source code should be
558 * replaced from a and up to (but not including) b.
559 *
560 * \returns A string containing text that should be replace the source
561 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000562 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000563CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000564 unsigned FixIt,
565 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000566
567/**
568 * @}
569 */
570
571/**
572 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
573 *
574 * The routines in this group provide the ability to create and destroy
575 * translation units from files, either by parsing the contents of the files or
576 * by reading in a serialized representation of a translation unit.
577 *
578 * @{
579 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000580
Douglas Gregor5352ac02010-01-28 00:27:43 +0000581/**
582 * \brief Get the original translation unit source file name.
583 */
584CINDEX_LINKAGE CXString
585clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
586
587/**
588 * \brief Return the CXTranslationUnit for a given source file and the provided
589 * command line arguments one would pass to the compiler.
590 *
591 * Note: The 'source_filename' argument is optional. If the caller provides a
592 * NULL pointer, the name of the source file is expected to reside in the
593 * specified command line arguments.
594 *
595 * Note: When encountered in 'clang_command_line_args', the following options
596 * are ignored:
597 *
598 * '-c'
599 * '-emit-ast'
600 * '-fsyntax-only'
601 * '-o <output file>' (both '-o' and '<output file>' are ignored)
602 *
603 *
604 * \param source_filename - The name of the source file to load, or NULL if the
605 * source file is included in clang_command_line_args.
606 *
607 * \param num_unsaved_files the number of unsaved file entries in \p
608 * unsaved_files.
609 *
610 * \param unsaved_files the files that have not yet been saved to disk
611 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000612 * those files. The contents and name of these files (as specified by
613 * CXUnsavedFile) are copied when necessary, so the client only needs to
614 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000615 *
616 * \param diag_callback callback function that will receive any diagnostics
617 * emitted while processing this source file. If NULL, diagnostics will be
618 * suppressed.
619 *
620 * \param diag_client_data client data that will be passed to the diagnostic
621 * callback function.
622 */
623CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
624 CXIndex CIdx,
625 const char *source_filename,
626 int num_clang_command_line_args,
627 const char **clang_command_line_args,
628 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000629 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000630
Douglas Gregor5352ac02010-01-28 00:27:43 +0000631/**
632 * \brief Create a translation unit from an AST file (-emit-ast).
633 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000634CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000635 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000636
637/**
638 * \brief Destroy the specified CXTranslationUnit object.
639 */
640CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000641
Douglas Gregor5352ac02010-01-28 00:27:43 +0000642/**
643 * @}
644 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000645
Douglas Gregor5352ac02010-01-28 00:27:43 +0000646/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000647 * \brief Describes the kind of entity that a cursor refers to.
648 */
649enum CXCursorKind {
650 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000651 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000652 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000653 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000654 *
655 * Unexposed declarations have the same operations as any other kind
656 * of declaration; one can extract their location information,
657 * spelling, find their definitions, etc. However, the specific kind
658 * of the declaration is not reported.
659 */
660 CXCursor_UnexposedDecl = 1,
661 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000662 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000663 /** \brief A C or C++ union. */
664 CXCursor_UnionDecl = 3,
665 /** \brief A C++ class. */
666 CXCursor_ClassDecl = 4,
667 /** \brief An enumeration. */
668 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000669 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000670 * \brief A field (in C) or non-static data member (in C++) in a
671 * struct, union, or C++ class.
672 */
673 CXCursor_FieldDecl = 6,
674 /** \brief An enumerator constant. */
675 CXCursor_EnumConstantDecl = 7,
676 /** \brief A function. */
677 CXCursor_FunctionDecl = 8,
678 /** \brief A variable. */
679 CXCursor_VarDecl = 9,
680 /** \brief A function or method parameter. */
681 CXCursor_ParmDecl = 10,
682 /** \brief An Objective-C @interface. */
683 CXCursor_ObjCInterfaceDecl = 11,
684 /** \brief An Objective-C @interface for a category. */
685 CXCursor_ObjCCategoryDecl = 12,
686 /** \brief An Objective-C @protocol declaration. */
687 CXCursor_ObjCProtocolDecl = 13,
688 /** \brief An Objective-C @property declaration. */
689 CXCursor_ObjCPropertyDecl = 14,
690 /** \brief An Objective-C instance variable. */
691 CXCursor_ObjCIvarDecl = 15,
692 /** \brief An Objective-C instance method. */
693 CXCursor_ObjCInstanceMethodDecl = 16,
694 /** \brief An Objective-C class method. */
695 CXCursor_ObjCClassMethodDecl = 17,
696 /** \brief An Objective-C @implementation. */
697 CXCursor_ObjCImplementationDecl = 18,
698 /** \brief An Objective-C @implementation for a category. */
699 CXCursor_ObjCCategoryImplDecl = 19,
700 /** \brief A typedef */
701 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +0000702 /** \brief A C++ class method. */
703 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +0000704 /** \brief A C++ namespace. */
705 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +0000706 /** \brief A linkage specification, e.g. 'extern "C"'. */
707 CXCursor_LinkageSpec = 23,
Ted Kremenek8bd5a692010-04-13 23:39:06 +0000708
Ted Kremenek50aa6ac2010-05-19 21:51:10 +0000709 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Ted Kremeneka0536d82010-05-07 01:04:29 +0000710 CXCursor_LastDecl = CXCursor_LinkageSpec,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000711
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000712 /* References */
713 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000714 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000715 CXCursor_ObjCProtocolRef = 41,
716 CXCursor_ObjCClassRef = 42,
717 /**
718 * \brief A reference to a type declaration.
719 *
720 * A type reference occurs anywhere where a type is named but not
721 * declared. For example, given:
722 *
723 * \code
724 * typedef unsigned size_type;
725 * size_type size;
726 * \endcode
727 *
728 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
729 * while the type of the variable "size" is referenced. The cursor
730 * referenced by the type of size is the typedef for size_type.
731 */
732 CXCursor_TypeRef = 43,
733 CXCursor_LastRef = 43,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000734
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000735 /* Error conditions */
736 CXCursor_FirstInvalid = 70,
737 CXCursor_InvalidFile = 70,
738 CXCursor_NoDeclFound = 71,
739 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +0000740 CXCursor_InvalidCode = 73,
741 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000742
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000743 /* Expressions */
744 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000745
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000746 /**
747 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000748 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000749 *
750 * Unexposed expressions have the same operations as any other kind
751 * of expression; one can extract their location information,
752 * spelling, children, etc. However, the specific kind of the
753 * expression is not reported.
754 */
755 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000756
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000757 /**
758 * \brief An expression that refers to some value declaration, such
759 * as a function, varible, or enumerator.
760 */
761 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000762
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000763 /**
764 * \brief An expression that refers to a member of a struct, union,
765 * class, Objective-C class, etc.
766 */
767 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000768
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000769 /** \brief An expression that calls a function. */
770 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000771
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000772 /** \brief An expression that sends a message to an Objective-C
773 object or class. */
774 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +0000775
776 /** \brief An expression that represents a block literal. */
777 CXCursor_BlockExpr = 105,
778
779 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000780
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000781 /* Statements */
782 CXCursor_FirstStmt = 200,
783 /**
784 * \brief A statement whose specific kind is not exposed via this
785 * interface.
786 *
787 * Unexposed statements have the same operations as any other kind of
788 * statement; one can extract their location information, spelling,
789 * children, etc. However, the specific kind of the statement is not
790 * reported.
791 */
792 CXCursor_UnexposedStmt = 200,
793 CXCursor_LastStmt = 200,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000794
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000795 /**
796 * \brief Cursor that represents the translation unit itself.
797 *
798 * The translation unit cursor exists primarily to act as the root
799 * cursor for traversing the contents of a translation unit.
800 */
Ted Kremeneke77f4432010-02-18 03:09:07 +0000801 CXCursor_TranslationUnit = 300,
802
803 /* Attributes */
804 CXCursor_FirstAttr = 400,
805 /**
806 * \brief An attribute whose specific kind is not exposed via this
807 * interface.
808 */
809 CXCursor_UnexposedAttr = 400,
810
811 CXCursor_IBActionAttr = 401,
812 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +0000813 CXCursor_IBOutletCollectionAttr = 403,
814 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000815
816 /* Preprocessing */
817 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +0000818 CXCursor_MacroDefinition = 501,
819 CXCursor_MacroInstantiation = 502,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000820 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregor48072312010-03-18 15:23:44 +0000821 CXCursor_LastPreprocessing = CXCursor_MacroInstantiation
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000822};
823
824/**
825 * \brief A cursor representing some element in the abstract syntax tree for
826 * a translation unit.
827 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000828 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000829 * program--declaration, statements, expressions, references to declarations,
830 * etc.--under a single "cursor" abstraction with a common set of operations.
831 * Common operation for a cursor include: getting the physical location in
832 * a source file where the cursor points, getting the name associated with a
833 * cursor, and retrieving cursors for any child nodes of a particular cursor.
834 *
835 * Cursors can be produced in two specific ways.
836 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
837 * from which one can use clang_visitChildren() to explore the rest of the
838 * translation unit. clang_getCursor() maps from a physical source location
839 * to the entity that resides at that location, allowing one to map from the
840 * source code into the AST.
841 */
842typedef struct {
843 enum CXCursorKind kind;
844 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000845} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000846
847/**
848 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
849 *
850 * @{
851 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000852
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000853/**
854 * \brief Retrieve the NULL cursor, which represents no entity.
855 */
856CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000857
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000858/**
859 * \brief Retrieve the cursor that represents the given translation unit.
860 *
861 * The translation unit cursor can be used to start traversing the
862 * various declarations within the given translation unit.
863 */
864CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
865
866/**
867 * \brief Determine whether two cursors are equivalent.
868 */
869CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000870
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000871/**
872 * \brief Retrieve the kind of the given cursor.
873 */
874CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
875
876/**
877 * \brief Determine whether the given cursor kind represents a declaration.
878 */
879CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
880
881/**
882 * \brief Determine whether the given cursor kind represents a simple
883 * reference.
884 *
885 * Note that other kinds of cursors (such as expressions) can also refer to
886 * other cursors. Use clang_getCursorReferenced() to determine whether a
887 * particular cursor refers to another entity.
888 */
889CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
890
891/**
892 * \brief Determine whether the given cursor kind represents an expression.
893 */
894CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
895
896/**
897 * \brief Determine whether the given cursor kind represents a statement.
898 */
899CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
900
901/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000902 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000903 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000904 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000905CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
906
907/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000908 * \brief Determine whether the given cursor kind represents a translation
909 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000910 */
911CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000912
Ted Kremenekad6eff62010-03-08 21:17:29 +0000913/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000914 * \brief Determine whether the given cursor represents a preprocessing
915 * element, such as a preprocessor directive or macro instantiation.
916 */
917CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
918
919/***
Ted Kremenekad6eff62010-03-08 21:17:29 +0000920 * \brief Determine whether the given cursor represents a currently
921 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
922 */
923CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
924
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000925/**
Ted Kremenek16b42592010-03-03 06:36:57 +0000926 * \brief Describe the linkage of the entity referred to by a cursor.
927 */
928enum CXLinkageKind {
929 /** \brief This value indicates that no linkage information is available
930 * for a provided CXCursor. */
931 CXLinkage_Invalid,
932 /**
933 * \brief This is the linkage for variables, parameters, and so on that
934 * have automatic storage. This covers normal (non-extern) local variables.
935 */
936 CXLinkage_NoLinkage,
937 /** \brief This is the linkage for static variables and static functions. */
938 CXLinkage_Internal,
939 /** \brief This is the linkage for entities with external linkage that live
940 * in C++ anonymous namespaces.*/
941 CXLinkage_UniqueExternal,
942 /** \brief This is the linkage for entities with true, external linkage. */
943 CXLinkage_External
944};
945
946/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +0000947 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +0000948 */
949CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
950
951/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +0000952 * \brief Describe the "language" of the entity referred to by a cursor.
953 */
954CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +0000955 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +0000956 CXLanguage_C,
957 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +0000958 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +0000959};
960
961/**
962 * \brief Determine the "language" of the entity referred to by a given cursor.
963 */
964CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
965
966/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000967 * @}
968 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000969
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000970/**
971 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
972 *
973 * Cursors represent a location within the Abstract Syntax Tree (AST). These
974 * routines help map between cursors and the physical locations where the
975 * described entities occur in the source code. The mapping is provided in
976 * both directions, so one can map from source code to the AST and back.
977 *
978 * @{
Steve Naroff50398192009-08-28 15:28:48 +0000979 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000980
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000981/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000982 * \brief Map a source location to the cursor that describes the entity at that
983 * location in the source code.
984 *
985 * clang_getCursor() maps an arbitrary source location within a translation
986 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000987 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +0000988 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000989 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +0000990 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
991 * will return a cursor referring to the "+" expression.
992 *
993 * \returns a cursor representing the entity at the given source location, or
994 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +0000995 */
Douglas Gregorb9790342010-01-22 21:44:22 +0000996CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000997
Douglas Gregor98258af2010-01-18 22:46:11 +0000998/**
999 * \brief Retrieve the physical location of the source constructor referenced
1000 * by the given cursor.
1001 *
1002 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001003 * declaration, where the name of that declaration would occur if it is
1004 * unnamed, or some keyword that introduces that particular declaration.
1005 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001006 * source code.
1007 */
1008CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001009
Douglas Gregorb6998662010-01-19 19:34:47 +00001010/**
1011 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001012 * the given cursor.
1013 *
1014 * The extent of a cursor starts with the file/line/column pointing at the
1015 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001016 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001017 * declaration, the extent covers the declaration itself. For a reference,
1018 * the extent covers the location of the reference (e.g., where the referenced
1019 * entity was actually used).
1020 */
1021CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001022
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001023/**
1024 * @}
1025 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001026
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001027/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001028 * \defgroup CINDEX_TYPES Type information for CXCursors
1029 *
1030 * @{
1031 */
1032
1033/**
1034 * \brief Describes the kind of type
1035 */
1036enum CXTypeKind {
1037 /**
1038 * \brief Reprents an invalid type (e.g., where no type is available).
1039 */
1040 CXType_Invalid = 0,
1041
1042 /**
1043 * \brief A type whose specific kind is not exposed via this
1044 * interface.
1045 */
1046 CXType_Unexposed = 1,
1047
1048 /* Builtin types */
1049 CXType_Void = 2,
1050 CXType_Bool = 3,
1051 CXType_Char_U = 4,
1052 CXType_UChar = 5,
1053 CXType_Char16 = 6,
1054 CXType_Char32 = 7,
1055 CXType_UShort = 8,
1056 CXType_UInt = 9,
1057 CXType_ULong = 10,
1058 CXType_ULongLong = 11,
1059 CXType_UInt128 = 12,
1060 CXType_Char_S = 13,
1061 CXType_SChar = 14,
1062 CXType_WChar = 15,
1063 CXType_Short = 16,
1064 CXType_Int = 17,
1065 CXType_Long = 18,
1066 CXType_LongLong = 19,
1067 CXType_Int128 = 20,
1068 CXType_Float = 21,
1069 CXType_Double = 22,
1070 CXType_LongDouble = 23,
1071 CXType_NullPtr = 24,
1072 CXType_Overload = 25,
1073 CXType_Dependent = 26,
1074 CXType_ObjCId = 27,
1075 CXType_ObjCClass = 28,
1076 CXType_ObjCSel = 29,
1077 CXType_FirstBuiltin = CXType_Void,
1078 CXType_LastBuiltin = CXType_ObjCSel,
1079
1080 CXType_Complex = 100,
1081 CXType_Pointer = 101,
1082 CXType_BlockPointer = 102,
1083 CXType_LValueReference = 103,
1084 CXType_RValueReference = 104,
1085 CXType_Record = 105,
1086 CXType_Enum = 106,
1087 CXType_Typedef = 107,
1088 CXType_ObjCInterface = 108,
1089 CXType_ObjCObjectPointer = 109
1090};
1091
1092/**
1093 * \brief The type of an element in the abstract syntax tree.
1094 *
1095 */
1096typedef struct {
1097 enum CXTypeKind kind;
1098 void *data[2];
1099} CXType;
1100
1101/**
1102 * \brief Retrieve the type of a CXCursor (if any).
1103 */
1104CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1105
1106/**
1107 * \determine Determine whether two CXTypes represent the same type.
1108 *
1109 * \returns non-zero if the CXTypes represent the same type and
1110 zero otherwise.
1111 */
1112CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1113
1114/**
1115 * \brief Return the canonical type for a CXType.
1116 *
1117 * Clang's type system explicitly models typedefs and all the ways
1118 * a specific type can be represented. The canonical type is the underlying
1119 * type with all the "sugar" removed. For example, if 'T' is a typedef
1120 * for 'int', the canonical type for 'T' would be 'int'.
1121 */
1122CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
1123
1124/**
1125 * \brief For pointer types, returns the type of the pointee.
1126 *
1127 */
1128CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
1129
1130/**
1131 * \brief Return the cursor for the declaration of the given type.
1132 */
1133CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
1134
1135
1136/**
1137 * \brief Retrieve the spelling of a given CXTypeKind.
1138 */
1139CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
1140
1141/**
1142 * @}
1143 */
1144
1145/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001146 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
1147 *
1148 * These routines provide the ability to traverse the abstract syntax tree
1149 * using cursors.
1150 *
1151 * @{
1152 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001153
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001154/**
1155 * \brief Describes how the traversal of the children of a particular
1156 * cursor should proceed after visiting a particular child cursor.
1157 *
1158 * A value of this enumeration type should be returned by each
1159 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
1160 */
1161enum CXChildVisitResult {
1162 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001163 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001164 */
1165 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001166 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001167 * \brief Continues the cursor traversal with the next sibling of
1168 * the cursor just visited, without visiting its children.
1169 */
1170 CXChildVisit_Continue,
1171 /**
1172 * \brief Recursively traverse the children of this cursor, using
1173 * the same visitor and client data.
1174 */
1175 CXChildVisit_Recurse
1176};
1177
1178/**
1179 * \brief Visitor invoked for each cursor found by a traversal.
1180 *
1181 * This visitor function will be invoked for each cursor found by
1182 * clang_visitCursorChildren(). Its first argument is the cursor being
1183 * visited, its second argument is the parent visitor for that cursor,
1184 * and its third argument is the client data provided to
1185 * clang_visitCursorChildren().
1186 *
1187 * The visitor should return one of the \c CXChildVisitResult values
1188 * to direct clang_visitCursorChildren().
1189 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001190typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
1191 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001192 CXClientData client_data);
1193
1194/**
1195 * \brief Visit the children of a particular cursor.
1196 *
1197 * This function visits all the direct children of the given cursor,
1198 * invoking the given \p visitor function with the cursors of each
1199 * visited child. The traversal may be recursive, if the visitor returns
1200 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
1201 * the visitor returns \c CXChildVisit_Break.
1202 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001203 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00001204 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001205 * definition, have no children).
1206 *
1207 * \param visitor the visitor function that will be invoked for each
1208 * child of \p parent.
1209 *
1210 * \param client_data pointer data supplied by the client, which will
1211 * be passed to the visitor each time it is invoked.
1212 *
1213 * \returns a non-zero value if the traversal was terminated
1214 * prematurely by the visitor returning \c CXChildVisit_Break.
1215 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001216CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001217 CXCursorVisitor visitor,
1218 CXClientData client_data);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001219
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001220/**
1221 * @}
1222 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001223
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001224/**
1225 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1226 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001227 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001228 * across translation units, by providing the names of the entities referenced
1229 * by cursors, follow reference cursors to the declarations they reference,
1230 * and associate declarations with their definitions.
1231 *
1232 * @{
1233 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001234
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001235/**
1236 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1237 * by the given cursor.
1238 *
1239 * A Unified Symbol Resolution (USR) is a string that identifies a particular
1240 * entity (function, class, variable, etc.) within a program. USRs can be
1241 * compared across translation units to determine, e.g., when references in
1242 * one translation refer to an entity defined in another translation unit.
1243 */
1244CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1245
1246/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00001247 * \brief Construct a USR for a specified Objective-C class.
1248 */
1249CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
1250
1251/**
1252 * \brief Construct a USR for a specified Objective-C category.
1253 */
1254CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00001255 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001256 const char *category_name);
1257
1258/**
1259 * \brief Construct a USR for a specified Objective-C protocol.
1260 */
1261CINDEX_LINKAGE CXString
1262 clang_constructUSR_ObjCProtocol(const char *protocol_name);
1263
1264
1265/**
1266 * \brief Construct a USR for a specified Objective-C instance variable and
1267 * the USR for its containing class.
1268 */
1269CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
1270 CXString classUSR);
1271
1272/**
1273 * \brief Construct a USR for a specified Objective-C method and
1274 * the USR for its containing class.
1275 */
1276CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
1277 unsigned isInstanceMethod,
1278 CXString classUSR);
1279
1280/**
1281 * \brief Construct a USR for a specified Objective-C property and the USR
1282 * for its containing class.
1283 */
1284CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
1285 CXString classUSR);
1286
1287/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001288 * \brief Retrieve a name for the entity referenced by this cursor.
1289 */
1290CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1291
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001292/** \brief For a cursor that is a reference, retrieve a cursor representing the
1293 * entity that it references.
1294 *
1295 * Reference cursors refer to other entities in the AST. For example, an
1296 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001297 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001298 * cursor for the superclass reference. If the input cursor is a declaration or
1299 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001300 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001301 */
1302CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00001303
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001304/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001305 * \brief For a cursor that is either a reference to or a declaration
1306 * of some entity, retrieve a cursor that describes the definition of
1307 * that entity.
1308 *
1309 * Some entities can be declared multiple times within a translation
1310 * unit, but only one of those declarations can also be a
1311 * definition. For example, given:
1312 *
1313 * \code
1314 * int f(int, int);
1315 * int g(int x, int y) { return f(x, y); }
1316 * int f(int a, int b) { return a + b; }
1317 * int f(int, int);
1318 * \endcode
1319 *
1320 * there are three declarations of the function "f", but only the
1321 * second one is a definition. The clang_getCursorDefinition()
1322 * function will take any cursor pointing to a declaration of "f"
1323 * (the first or fourth lines of the example) or a cursor referenced
1324 * that uses "f" (the call to "f' inside "g") and will return a
1325 * declaration cursor pointing to the definition (the second "f"
1326 * declaration).
1327 *
1328 * If given a cursor for which there is no corresponding definition,
1329 * e.g., because there is no definition of that entity within this
1330 * translation unit, returns a NULL cursor.
1331 */
1332CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1333
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001334/**
Douglas Gregorb6998662010-01-19 19:34:47 +00001335 * \brief Determine whether the declaration pointed to by this cursor
1336 * is also a definition of that entity.
1337 */
1338CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1339
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001340/**
1341 * @}
1342 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001343
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001344/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00001345 * \defgroup CINDEX_CPP C++ AST introspection
1346 *
1347 * The routines in this group provide access information in the ASTs specific
1348 * to C++ language features.
1349 *
1350 * @{
1351 */
1352
1353/**
1354 * \brief Determine if a C++ member function is declared 'static'.
1355 */
1356CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
1357
1358/**
1359 * @}
1360 */
1361
1362/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001363 * \defgroup CINDEX_LEX Token extraction and manipulation
1364 *
1365 * The routines in this group provide access to the tokens within a
1366 * translation unit, along with a semantic mapping of those tokens to
1367 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001368 *
1369 * @{
1370 */
1371
1372/**
1373 * \brief Describes a kind of token.
1374 */
1375typedef enum CXTokenKind {
1376 /**
1377 * \brief A token that contains some kind of punctuation.
1378 */
1379 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001380
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001381 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001382 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001383 */
1384 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001385
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001386 /**
1387 * \brief An identifier (that is not a keyword).
1388 */
1389 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001390
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001391 /**
1392 * \brief A numeric, string, or character literal.
1393 */
1394 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00001395
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001396 /**
1397 * \brief A comment.
1398 */
1399 CXToken_Comment
1400} CXTokenKind;
1401
1402/**
1403 * \brief Describes a single preprocessing token.
1404 */
1405typedef struct {
1406 unsigned int_data[4];
1407 void *ptr_data;
1408} CXToken;
1409
1410/**
1411 * \brief Determine the kind of the given token.
1412 */
1413CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001414
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001415/**
1416 * \brief Determine the spelling of the given token.
1417 *
1418 * The spelling of a token is the textual representation of that token, e.g.,
1419 * the text of an identifier or keyword.
1420 */
1421CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001422
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001423/**
1424 * \brief Retrieve the source location of the given token.
1425 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001426CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001427 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001428
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001429/**
1430 * \brief Retrieve a source range that covers the given token.
1431 */
1432CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
1433
1434/**
1435 * \brief Tokenize the source code described by the given range into raw
1436 * lexical tokens.
1437 *
1438 * \param TU the translation unit whose text is being tokenized.
1439 *
1440 * \param Range the source range in which text should be tokenized. All of the
1441 * tokens produced by tokenization will fall within this source range,
1442 *
1443 * \param Tokens this pointer will be set to point to the array of tokens
1444 * that occur within the given source range. The returned pointer must be
1445 * freed with clang_disposeTokens() before the translation unit is destroyed.
1446 *
1447 * \param NumTokens will be set to the number of tokens in the \c *Tokens
1448 * array.
1449 *
1450 */
1451CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
1452 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001453
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001454/**
1455 * \brief Annotate the given set of tokens by providing cursors for each token
1456 * that can be mapped to a specific entity within the abstract syntax tree.
1457 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00001458 * This token-annotation routine is equivalent to invoking
1459 * clang_getCursor() for the source locations of each of the
1460 * tokens. The cursors provided are filtered, so that only those
1461 * cursors that have a direct correspondence to the token are
1462 * accepted. For example, given a function call \c f(x),
1463 * clang_getCursor() would provide the following cursors:
1464 *
1465 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
1466 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
1467 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
1468 *
1469 * Only the first and last of these cursors will occur within the
1470 * annotate, since the tokens "f" and "x' directly refer to a function
1471 * and a variable, respectively, but the parentheses are just a small
1472 * part of the full syntax of the function call expression, which is
1473 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001474 *
1475 * \param TU the translation unit that owns the given tokens.
1476 *
1477 * \param Tokens the set of tokens to annotate.
1478 *
1479 * \param NumTokens the number of tokens in \p Tokens.
1480 *
1481 * \param Cursors an array of \p NumTokens cursors, whose contents will be
1482 * replaced with the cursors corresponding to each token.
1483 */
1484CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
1485 CXToken *Tokens, unsigned NumTokens,
1486 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001487
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001488/**
1489 * \brief Free the given set of tokens.
1490 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001491CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001492 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001493
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001494/**
1495 * @}
1496 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001497
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001498/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001499 * \defgroup CINDEX_DEBUG Debugging facilities
1500 *
1501 * These routines are used for testing and debugging, only, and should not
1502 * be relied upon.
1503 *
1504 * @{
1505 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001506
Steve Naroff4ade6d62009-09-23 17:52:52 +00001507/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00001508CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001509CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
1510 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00001511 const char **endBuf,
1512 unsigned *startLine,
1513 unsigned *startColumn,
1514 unsigned *endLine,
1515 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00001516CINDEX_LINKAGE void clang_enableStackTraces(void);
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001517/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001518 * @}
1519 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001520
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001521/**
1522 * \defgroup CINDEX_CODE_COMPLET Code completion
1523 *
1524 * Code completion involves taking an (incomplete) source file, along with
1525 * knowledge of where the user is actively editing that file, and suggesting
1526 * syntactically- and semantically-valid constructs that the user might want to
1527 * use at that particular point in the source code. These data structures and
1528 * routines provide support for code completion.
1529 *
1530 * @{
1531 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001532
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001533/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001534 * \brief A semantic string that describes a code-completion result.
1535 *
1536 * A semantic string that describes the formatting of a code-completion
1537 * result as a single "template" of text that should be inserted into the
1538 * source buffer when a particular code-completion result is selected.
1539 * Each semantic string is made up of some number of "chunks", each of which
1540 * contains some text along with a description of what that text means, e.g.,
1541 * the name of the entity being referenced, whether the text chunk is part of
1542 * the template, or whether it is a "placeholder" that the user should replace
1543 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001544 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001545 */
1546typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001547
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001548/**
1549 * \brief A single result of code completion.
1550 */
1551typedef struct {
1552 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001553 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001554 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001555 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001556 * *Decl cursor kinds), describing the entity that the completion is
1557 * referring to.
1558 *
1559 * \todo In the future, we would like to provide a full cursor, to allow
1560 * the client to extract additional information from declaration.
1561 */
1562 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001563
1564 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001565 * \brief The code-completion string that describes how to insert this
1566 * code-completion result into the editing buffer.
1567 */
1568 CXCompletionString CompletionString;
1569} CXCompletionResult;
1570
1571/**
1572 * \brief Describes a single piece of text within a code-completion string.
1573 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001574 * Each "chunk" within a code-completion string (\c CXCompletionString) is
1575 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001576 * should be interpreted by the client or is another completion string.
1577 */
1578enum CXCompletionChunkKind {
1579 /**
1580 * \brief A code-completion string that describes "optional" text that
1581 * could be a part of the template (but is not required).
1582 *
1583 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001584 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001585 * \c clang_getCompletionChunkCompletionString(). The code-completion string
1586 * describes an additional part of the template that is completely optional.
1587 * For example, optional chunks can be used to describe the placeholders for
1588 * arguments that match up with defaulted function parameters, e.g. given:
1589 *
1590 * \code
1591 * void f(int x, float y = 3.14, double z = 2.71828);
1592 * \endcode
1593 *
1594 * The code-completion string for this function would contain:
1595 * - a TypedText chunk for "f".
1596 * - a LeftParen chunk for "(".
1597 * - a Placeholder chunk for "int x"
1598 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
1599 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00001600 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001601 * - an Optional chunk containing the last defaulted argument:
1602 * - a Comma chunk for ","
1603 * - a Placeholder chunk for "double z"
1604 * - a RightParen chunk for ")"
1605 *
Daniel Dunbar71570182010-02-17 08:07:44 +00001606 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001607 * - Completely ignore optional chunks, in which case the template for the
1608 * function "f" would only include the first parameter ("int x").
1609 * - Fully expand all optional chunks, in which case the template for the
1610 * function "f" would have all of the parameters.
1611 */
1612 CXCompletionChunk_Optional,
1613 /**
1614 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001615 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001616 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001617 * There will be exactly one "typed text" chunk in a semantic string, which
1618 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001619 * declaration that could be used at the current code point. Clients are
1620 * expected to filter the code-completion results based on the text in this
1621 * chunk.
1622 */
1623 CXCompletionChunk_TypedText,
1624 /**
1625 * \brief Text that should be inserted as part of a code-completion result.
1626 *
1627 * A "text" chunk represents text that is part of the template to be
1628 * inserted into user code should this particular code-completion result
1629 * be selected.
1630 */
1631 CXCompletionChunk_Text,
1632 /**
1633 * \brief Placeholder text that should be replaced by the user.
1634 *
1635 * A "placeholder" chunk marks a place where the user should insert text
1636 * into the code-completion template. For example, placeholders might mark
1637 * the function parameters for a function declaration, to indicate that the
1638 * user should provide arguments for each of those parameters. The actual
1639 * text in a placeholder is a suggestion for the text to display before
1640 * the user replaces the placeholder with real code.
1641 */
1642 CXCompletionChunk_Placeholder,
1643 /**
1644 * \brief Informative text that should be displayed but never inserted as
1645 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001646 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001647 * An "informative" chunk contains annotations that can be displayed to
1648 * help the user decide whether a particular code-completion result is the
1649 * right option, but which is not part of the actual template to be inserted
1650 * by code completion.
1651 */
1652 CXCompletionChunk_Informative,
1653 /**
1654 * \brief Text that describes the current parameter when code-completion is
1655 * referring to function call, message send, or template specialization.
1656 *
1657 * A "current parameter" chunk occurs when code-completion is providing
1658 * information about a parameter corresponding to the argument at the
1659 * code-completion point. For example, given a function
1660 *
1661 * \code
1662 * int add(int x, int y);
1663 * \endcode
1664 *
1665 * and the source code \c add(, where the code-completion point is after the
1666 * "(", the code-completion string will contain a "current parameter" chunk
1667 * for "int x", indicating that the current argument will initialize that
1668 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001669 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001670 * "current paremeter" chunk to "int y".
1671 */
1672 CXCompletionChunk_CurrentParameter,
1673 /**
1674 * \brief A left parenthesis ('('), used to initiate a function call or
1675 * signal the beginning of a function parameter list.
1676 */
1677 CXCompletionChunk_LeftParen,
1678 /**
1679 * \brief A right parenthesis (')'), used to finish a function call or
1680 * signal the end of a function parameter list.
1681 */
1682 CXCompletionChunk_RightParen,
1683 /**
1684 * \brief A left bracket ('[').
1685 */
1686 CXCompletionChunk_LeftBracket,
1687 /**
1688 * \brief A right bracket (']').
1689 */
1690 CXCompletionChunk_RightBracket,
1691 /**
1692 * \brief A left brace ('{').
1693 */
1694 CXCompletionChunk_LeftBrace,
1695 /**
1696 * \brief A right brace ('}').
1697 */
1698 CXCompletionChunk_RightBrace,
1699 /**
1700 * \brief A left angle bracket ('<').
1701 */
1702 CXCompletionChunk_LeftAngle,
1703 /**
1704 * \brief A right angle bracket ('>').
1705 */
1706 CXCompletionChunk_RightAngle,
1707 /**
1708 * \brief A comma separator (',').
1709 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001710 CXCompletionChunk_Comma,
1711 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001712 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001713 *
1714 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001715 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00001716 * expression using the given completion string would have.
1717 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00001718 CXCompletionChunk_ResultType,
1719 /**
1720 * \brief A colon (':').
1721 */
1722 CXCompletionChunk_Colon,
1723 /**
1724 * \brief A semicolon (';').
1725 */
1726 CXCompletionChunk_SemiColon,
1727 /**
1728 * \brief An '=' sign.
1729 */
1730 CXCompletionChunk_Equal,
1731 /**
1732 * Horizontal space (' ').
1733 */
1734 CXCompletionChunk_HorizontalSpace,
1735 /**
1736 * Vertical space ('\n'), after which it is generally a good idea to
1737 * perform indentation.
1738 */
1739 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001740};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001741
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001742/**
1743 * \brief Determine the kind of a particular chunk within a completion string.
1744 *
1745 * \param completion_string the completion string to query.
1746 *
1747 * \param chunk_number the 0-based index of the chunk in the completion string.
1748 *
1749 * \returns the kind of the chunk at the index \c chunk_number.
1750 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001751CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001752clang_getCompletionChunkKind(CXCompletionString completion_string,
1753 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001754
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001755/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001756 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001757 * completion string.
1758 *
1759 * \param completion_string the completion string to query.
1760 *
1761 * \param chunk_number the 0-based index of the chunk in the completion string.
1762 *
1763 * \returns the text associated with the chunk at index \c chunk_number.
1764 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00001765CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001766clang_getCompletionChunkText(CXCompletionString completion_string,
1767 unsigned chunk_number);
1768
1769/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001770 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001771 * within a completion string.
1772 *
1773 * \param completion_string the completion string to query.
1774 *
1775 * \param chunk_number the 0-based index of the chunk in the completion string.
1776 *
1777 * \returns the completion string associated with the chunk at index
1778 * \c chunk_number, or NULL if that chunk is not represented by a completion
1779 * string.
1780 */
1781CINDEX_LINKAGE CXCompletionString
1782clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
1783 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001784
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001785/**
1786 * \brief Retrieve the number of chunks in the given code-completion string.
1787 */
1788CINDEX_LINKAGE unsigned
1789clang_getNumCompletionChunks(CXCompletionString completion_string);
1790
1791/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00001792 * \brief Contains the results of code-completion.
1793 *
1794 * This data structure contains the results of code completion, as
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001795 * produced by \c clang_codeComplete. Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00001796 * \c clang_disposeCodeCompleteResults.
1797 */
1798typedef struct {
1799 /**
1800 * \brief The code-completion results.
1801 */
1802 CXCompletionResult *Results;
1803
1804 /**
1805 * \brief The number of code-completion results stored in the
1806 * \c Results array.
1807 */
1808 unsigned NumResults;
1809} CXCodeCompleteResults;
1810
1811/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001812 * \brief Perform code completion at a given location in a source file.
1813 *
1814 * This function performs code completion at a particular file, line, and
1815 * column within source code, providing results that suggest potential
1816 * code snippets based on the context of the completion. The basic model
1817 * for code completion is that Clang will parse a complete source file,
1818 * performing syntax checking up to the location where code-completion has
1819 * been requested. At that point, a special code-completion token is passed
1820 * to the parser, which recognizes this token and determines, based on the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001821 * current location in the C/Objective-C/C++ grammar and the state of
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001822 * semantic analysis, what completions to provide. These completions are
Douglas Gregorec6762c2009-12-18 16:20:58 +00001823 * returned via a new \c CXCodeCompleteResults structure.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001824 *
1825 * Code completion itself is meant to be triggered by the client when the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001826 * user types punctuation characters or whitespace, at which point the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001827 * code-completion location will coincide with the cursor. For example, if \c p
1828 * is a pointer, code-completion might be triggered after the "-" and then
1829 * after the ">" in \c p->. When the code-completion location is afer the ">",
1830 * the completion results will provide, e.g., the members of the struct that
1831 * "p" points to. The client is responsible for placing the cursor at the
1832 * beginning of the token currently being typed, then filtering the results
1833 * based on the contents of the token. For example, when code-completing for
1834 * the expression \c p->get, the client should provide the location just after
1835 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
1836 * client can filter the results based on the current token text ("get"), only
1837 * showing those results that start with "get". The intent of this interface
Douglas Gregorec6762c2009-12-18 16:20:58 +00001838 * is to separate the relatively high-latency acquisition of code-completion
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001839 * results from the filtering of results on a per-character basis, which must
1840 * have a lower latency.
1841 *
1842 * \param CIdx the \c CXIndex instance that will be used to perform code
1843 * completion.
1844 *
Daniel Dunbar8506dde2009-12-03 01:54:28 +00001845 * \param source_filename the name of the source file that should be parsed to
1846 * perform code-completion. This source file must be the same as or include the
1847 * filename described by \p complete_filename, or no code-completion results
1848 * will be produced. NOTE: One can also specify NULL for this argument if the
1849 * source file is included in command_line_args.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001850 *
1851 * \param num_command_line_args the number of command-line arguments stored in
1852 * \p command_line_args.
1853 *
1854 * \param command_line_args the command-line arguments to pass to the Clang
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001855 * compiler to build the given source file. This should include all of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001856 * necessary include paths, language-dialect switches, precompiled header
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001857 * includes, etc., but should not include any information specific to
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001858 * code completion.
1859 *
Douglas Gregor735df882009-12-02 09:21:34 +00001860 * \param num_unsaved_files the number of unsaved file entries in \p
1861 * unsaved_files.
1862 *
1863 * \param unsaved_files the files that have not yet been saved to disk
1864 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +00001865 * those files. The contents and name of these files (as specified by
1866 * CXUnsavedFile) are copied when necessary, so the client only needs to
1867 * guarantee their validity until the call to this function returns.
Douglas Gregor735df882009-12-02 09:21:34 +00001868 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001869 * \param complete_filename the name of the source file where code completion
1870 * should be performed. In many cases, this name will be the same as the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001871 * source filename. However, the completion filename may also be a file
1872 * included by the source file, which is required when producing
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001873 * code-completion results for a header.
1874 *
1875 * \param complete_line the line at which code-completion should occur.
1876 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001877 * \param complete_column the column at which code-completion should occur.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001878 * Note that the column should point just after the syntactic construct that
1879 * initiated code completion, and not in the middle of a lexical token.
1880 *
Douglas Gregor936ea3b2010-01-28 00:56:43 +00001881 * \param diag_callback callback function that will receive any diagnostics
1882 * emitted while processing this source file. If NULL, diagnostics will be
1883 * suppressed.
1884 *
1885 * \param diag_client_data client data that will be passed to the diagnostic
1886 * callback function.
1887 *
Douglas Gregorec6762c2009-12-18 16:20:58 +00001888 * \returns if successful, a new CXCodeCompleteResults structure
1889 * containing code-completion results, which should eventually be
1890 * freed with \c clang_disposeCodeCompleteResults(). If code
1891 * completion fails, returns NULL.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00001892 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001893CINDEX_LINKAGE
1894CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001895 const char *source_filename,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001896 int num_command_line_args,
Douglas Gregorec6762c2009-12-18 16:20:58 +00001897 const char **command_line_args,
1898 unsigned num_unsaved_files,
1899 struct CXUnsavedFile *unsaved_files,
1900 const char *complete_filename,
1901 unsigned complete_line,
Douglas Gregora88084b2010-02-18 18:08:43 +00001902 unsigned complete_column);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001903
Douglas Gregorec6762c2009-12-18 16:20:58 +00001904/**
1905 * \brief Free the given set of code-completion results.
1906 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001907CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00001908void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001909
Douglas Gregor20d416c2010-01-20 01:10:47 +00001910/**
Douglas Gregora88084b2010-02-18 18:08:43 +00001911 * \brief Determine the number of diagnostics produced prior to the
1912 * location where code completion was performed.
1913 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001914CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00001915unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
1916
1917/**
1918 * \brief Retrieve a diagnostic associated with the given code completion.
1919 *
1920 * \param Result the code completion results to query.
1921 * \param Index the zero-based diagnostic number to retrieve.
1922 *
1923 * \returns the requested diagnostic. This diagnostic must be freed
1924 * via a call to \c clang_disposeDiagnostic().
1925 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001926CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00001927CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
1928 unsigned Index);
1929
1930/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00001931 * @}
1932 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001933
1934
Ted Kremenek04bb7162010-01-22 22:44:15 +00001935/**
1936 * \defgroup CINDEX_MISC Miscellaneous utility functions
1937 *
1938 * @{
1939 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00001940
1941/**
1942 * \brief Return a version string, suitable for showing to a user, but not
1943 * intended to be parsed (the format is not guaranteed to be stable).
1944 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00001945CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00001946
1947/**
Ted Kremenek16b55a72010-01-26 19:31:51 +00001948 * \brief Return a version string, suitable for showing to a user, but not
1949 * intended to be parsed (the format is not guaranteed to be stable).
1950 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001951
1952
Ted Kremenek16b55a72010-01-26 19:31:51 +00001953 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00001954 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00001955 * (used with clang_getInclusions()).
1956 *
1957 * This visitor function will be invoked by clang_getInclusions() for each
1958 * file included (either at the top-level or by #include directives) within
1959 * a translation unit. The first argument is the file being included, and
1960 * the second and third arguments provide the inclusion stack. The
1961 * array is sorted in order of immediate inclusion. For example,
1962 * the first element refers to the location that included 'included_file'.
1963 */
1964typedef void (*CXInclusionVisitor)(CXFile included_file,
1965 CXSourceLocation* inclusion_stack,
1966 unsigned include_len,
1967 CXClientData client_data);
1968
1969/**
1970 * \brief Visit the set of preprocessor inclusions in a translation unit.
1971 * The visitor function is called with the provided data for every included
1972 * file. This does not include headers included by the PCH file (unless one
1973 * is inspecting the inclusions in the PCH file itself).
1974 */
1975CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
1976 CXInclusionVisitor visitor,
1977 CXClientData client_data);
1978
1979/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00001980 * @}
1981 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001982
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001983/**
1984 * @}
1985 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001986
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001987#ifdef __cplusplus
1988}
1989#endif
1990#endif
1991