blob: 6bd0286d6ecf8a6b2ca616a24d5f4327624ff446 [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 Gregor87fb9402011-02-23 17:45:25 +000038/** \defgroup CINDEX libclang: C Interface to Clang
Douglas Gregor20d416c2010-01-20 01:10:47 +000039 *
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 */
Ted Kremenek0a90d322010-11-17 23:24:11 +000066typedef struct CXTranslationUnitImpl *CXTranslationUnit;
Steve Naroff600866c2009-08-27 19:51:58 +000067
Douglas Gregor7f173762010-01-20 22:28:27 +000068/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +000069 * \brief Opaque pointer representing client data that will be passed through
70 * to various callbacks and visitors.
Douglas Gregor7f173762010-01-20 22:28:27 +000071 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +000072typedef void *CXClientData;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000073
Douglas Gregor735df882009-12-02 09:21:34 +000074/**
75 * \brief Provides the contents of a file that has not yet been saved to disk.
76 *
77 * Each CXUnsavedFile instance provides the name of a file on the
78 * system along with the current contents of that file that have not
79 * yet been saved to disk.
80 */
81struct CXUnsavedFile {
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000082 /**
83 * \brief The file whose contents have not yet been saved.
Douglas Gregor735df882009-12-02 09:21:34 +000084 *
85 * This file must already exist in the file system.
86 */
87 const char *Filename;
88
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +000089 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000090 * \brief A buffer containing the unsaved contents of this file.
Douglas Gregor735df882009-12-02 09:21:34 +000091 */
92 const char *Contents;
93
94 /**
Douglas Gregorc8dfe5e2010-02-27 01:32:48 +000095 * \brief The length of the unsaved contents of this buffer.
Douglas Gregor735df882009-12-02 09:21:34 +000096 */
97 unsigned long Length;
98};
99
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000100/**
101 * \brief Describes the availability of a particular entity, which indicates
102 * whether the use of this entity will result in a warning or error due to
103 * it being deprecated or unavailable.
104 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000105enum CXAvailabilityKind {
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000106 /**
107 * \brief The entity is available.
108 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000109 CXAvailability_Available,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000110 /**
111 * \brief The entity is available, but has been deprecated (and its use is
112 * not recommended).
113 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000114 CXAvailability_Deprecated,
Peter Collingbourne076c22a2010-08-24 00:31:37 +0000115 /**
116 * \brief The entity is not available; any use of it will be an error.
117 */
Douglas Gregor58ddb602010-08-23 23:00:57 +0000118 CXAvailability_NotAvailable
119};
120
Douglas Gregor7f173762010-01-20 22:28:27 +0000121/**
Douglas Gregor7f173762010-01-20 22:28:27 +0000122 * \defgroup CINDEX_STRING String manipulation routines
123 *
124 * @{
125 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000126
Douglas Gregor7f173762010-01-20 22:28:27 +0000127/**
128 * \brief A character string.
129 *
130 * The \c CXString type is used to return strings from the interface when
131 * the ownership of that string might different from one call to the next.
132 * Use \c clang_getCString() to retrieve the string data and, once finished
133 * with the string data, call \c clang_disposeString() to free the string.
Steve Naroffef0cef62009-11-09 17:45:52 +0000134 */
135typedef struct {
Ted Kremeneka60ed472010-11-16 08:15:36 +0000136 void *data;
Ted Kremeneked122732010-11-16 01:56:27 +0000137 unsigned private_flags;
Steve Naroffef0cef62009-11-09 17:45:52 +0000138} CXString;
139
Douglas Gregor7f173762010-01-20 22:28:27 +0000140/**
141 * \brief Retrieve the character data associated with the given string.
142 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000143CINDEX_LINKAGE const char *clang_getCString(CXString string);
144
Douglas Gregor7f173762010-01-20 22:28:27 +0000145/**
146 * \brief Free the given string,
147 */
Steve Naroffef0cef62009-11-09 17:45:52 +0000148CINDEX_LINKAGE void clang_disposeString(CXString string);
149
Douglas Gregor7f173762010-01-20 22:28:27 +0000150/**
151 * @}
152 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000153
154/**
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000155 * \brief clang_createIndex() provides a shared context for creating
156 * translation units. It provides two options:
157 *
158 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
159 * declarations (when loading any new translation units). A "local" declaration
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000160 * is one that belongs in the translation unit itself and not in a precompiled
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000161 * header that was used by the translation unit. If zero, all declarations
162 * will be enumerated.
163 *
Steve Naroffb4ece632009-10-20 16:36:34 +0000164 * Here is an example:
165 *
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000166 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
167 * Idx = clang_createIndex(1, 1);
Steve Naroffb4ece632009-10-20 16:36:34 +0000168 *
169 * // IndexTest.pch was produced with the following command:
170 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
171 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
172 *
173 * // This will load all the symbols from 'IndexTest.pch'
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000174 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
Douglas Gregor002a5282010-01-20 21:37:00 +0000175 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000176 * clang_disposeTranslationUnit(TU);
177 *
178 * // This will load all the symbols from 'IndexTest.c', excluding symbols
179 * // from 'IndexTest.pch'.
Daniel Dunbarfd9f2342010-01-25 00:43:14 +0000180 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
181 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
182 * 0, 0);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000183 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
184 * TranslationUnitVisitor, 0);
Steve Naroffb4ece632009-10-20 16:36:34 +0000185 * clang_disposeTranslationUnit(TU);
186 *
187 * This process of creating the 'pch', loading it separately, and using it (via
188 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
189 * (which gives the indexer the same performance benefit as the compiler).
Steve Naroffe56b4ba2009-10-20 14:46:24 +0000190 */
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000191CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
192 int displayDiagnostics);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000193
Douglas Gregor0087e1a2010-02-08 23:03:06 +0000194/**
195 * \brief Destroy the given index.
196 *
197 * The index must not be destroyed until all of the translation units created
198 * within that index have been destroyed.
199 */
Daniel Dunbar8506dde2009-12-03 01:54:28 +0000200CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000201
202/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000203 * \defgroup CINDEX_FILES File manipulation routines
Douglas Gregorf5525442010-01-20 22:45:41 +0000204 *
205 * @{
206 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000207
Douglas Gregorf5525442010-01-20 22:45:41 +0000208/**
209 * \brief A particular source file that is part of a translation unit.
210 */
211typedef void *CXFile;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000212
Douglas Gregorf5525442010-01-20 22:45:41 +0000213
214/**
215 * \brief Retrieve the complete file and path name of the given file.
Steve Naroff88145032009-10-27 14:35:18 +0000216 */
Ted Kremenek74844072010-02-17 00:41:20 +0000217CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000218
Douglas Gregorf5525442010-01-20 22:45:41 +0000219/**
220 * \brief Retrieve the last modification time of the given file.
221 */
Douglas Gregor08b0e8d2009-10-31 15:48:08 +0000222CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
Steve Naroff88145032009-10-27 14:35:18 +0000223
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000224/**
Douglas Gregordd3e5542011-05-04 00:14:37 +0000225 * \brief Determine whether the given header is guarded against
226 * multiple inclusions, either with the conventional
227 * #ifndef/#define/#endif macro guards or with #pragma once.
228 */
229CINDEX_LINKAGE unsigned
230clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
231
232/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000233 * \brief Retrieve a file handle within the given translation unit.
234 *
235 * \param tu the translation unit
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000236 *
Douglas Gregorb9790342010-01-22 21:44:22 +0000237 * \param file_name the name of the file.
238 *
239 * \returns the file handle for the named file in the translation unit \p tu,
240 * or a NULL file handle if the file was not a part of this translation unit.
241 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000242CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
Douglas Gregorb9790342010-01-22 21:44:22 +0000243 const char *file_name);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000244
Douglas Gregorb9790342010-01-22 21:44:22 +0000245/**
Douglas Gregorf5525442010-01-20 22:45:41 +0000246 * @}
247 */
248
249/**
250 * \defgroup CINDEX_LOCATIONS Physical source locations
251 *
252 * Clang represents physical source locations in its abstract syntax tree in
253 * great detail, with file, line, and column information for the majority of
254 * the tokens parsed in the source code. These data types and functions are
255 * used to represent source location information, either for a particular
256 * point in the program or for a range of points in the program, and extract
257 * specific location information from those data types.
258 *
259 * @{
260 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000261
Douglas Gregorf5525442010-01-20 22:45:41 +0000262/**
Douglas Gregor1db19de2010-01-19 21:36:55 +0000263 * \brief Identifies a specific source location within a translation
264 * unit.
265 *
Chandler Carruth20174222011-08-31 16:53:37 +0000266 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
Douglas Gregora9b06d42010-11-09 06:24:54 +0000267 * to map a source location to a particular file, line, and column.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000268 */
269typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000270 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000271 unsigned int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000272} CXSourceLocation;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000273
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000274/**
Daniel Dunbard52864b2010-02-14 10:02:57 +0000275 * \brief Identifies a half-open character range in the source code.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000276 *
Douglas Gregor1db19de2010-01-19 21:36:55 +0000277 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
278 * starting and end locations from a source range, respectively.
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000279 */
280typedef struct {
Douglas Gregor5352ac02010-01-28 00:27:43 +0000281 void *ptr_data[2];
Douglas Gregor1db19de2010-01-19 21:36:55 +0000282 unsigned begin_int_data;
283 unsigned end_int_data;
Douglas Gregor3c7313d2010-01-18 22:13:09 +0000284} CXSourceRange;
Ted Kremenekfe6fd3d2010-01-05 23:18:49 +0000285
Douglas Gregor1db19de2010-01-19 21:36:55 +0000286/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000287 * \brief Retrieve a NULL (invalid) source location.
288 */
289CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000290
Douglas Gregorb9790342010-01-22 21:44:22 +0000291/**
292 * \determine Determine whether two source locations, which must refer into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000293 * the same translation unit, refer to exactly the same point in the source
Douglas Gregorb9790342010-01-22 21:44:22 +0000294 * code.
295 *
296 * \returns non-zero if the source locations refer to the same location, zero
297 * if they refer to different locations.
298 */
299CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
300 CXSourceLocation loc2);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000301
Douglas Gregorb9790342010-01-22 21:44:22 +0000302/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000303 * \brief Retrieves the source location associated with a given file/line/column
304 * in a particular translation unit.
Douglas Gregorb9790342010-01-22 21:44:22 +0000305 */
306CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
307 CXFile file,
308 unsigned line,
309 unsigned column);
David Chisnall83889a72010-10-15 17:07:39 +0000310/**
311 * \brief Retrieves the source location associated with a given character offset
312 * in a particular translation unit.
313 */
314CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
315 CXFile file,
316 unsigned offset);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000317
Douglas Gregorb9790342010-01-22 21:44:22 +0000318/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000319 * \brief Retrieve a NULL (invalid) source range.
320 */
321CINDEX_LINKAGE CXSourceRange clang_getNullRange();
Ted Kremenek896b70f2010-03-13 02:50:34 +0000322
Douglas Gregor5352ac02010-01-28 00:27:43 +0000323/**
Douglas Gregorb9790342010-01-22 21:44:22 +0000324 * \brief Retrieve a source range given the beginning and ending source
325 * locations.
326 */
327CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
328 CXSourceLocation end);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000329
Douglas Gregorb9790342010-01-22 21:44:22 +0000330/**
Douglas Gregorab4e83b2011-07-23 19:35:14 +0000331 * \brief Determine whether two ranges are equivalent.
332 *
333 * \returns non-zero if the ranges are the same, zero if they differ.
334 */
335CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
336 CXSourceRange range2);
337
338/**
Douglas Gregor46766dc2010-01-26 19:19:08 +0000339 * \brief Retrieve the file, line, column, and offset represented by
340 * the given source location.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000341 *
Chandler Carruth20174222011-08-31 16:53:37 +0000342 * If the location refers into a macro expansion, retrieves the
343 * location of the macro expansion.
Douglas Gregora9b06d42010-11-09 06:24:54 +0000344 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000345 * \param location the location within a source file that will be decomposed
346 * into its parts.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000347 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000348 * \param file [out] if non-NULL, will be set to the file to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000349 * source location points.
350 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000351 * \param line [out] if non-NULL, will be set to the line to which the given
Douglas Gregor1db19de2010-01-19 21:36:55 +0000352 * source location points.
353 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000354 * \param column [out] if non-NULL, will be set to the column to which the given
355 * source location points.
Douglas Gregor46766dc2010-01-26 19:19:08 +0000356 *
357 * \param offset [out] if non-NULL, will be set to the offset into the
358 * buffer to which the given source location points.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000359 */
Chandler Carruth20174222011-08-31 16:53:37 +0000360CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
361 CXFile *file,
362 unsigned *line,
363 unsigned *column,
364 unsigned *offset);
365
366/**
Argyrios Kyrtzidise6be34d2011-09-13 21:49:08 +0000367 * \brief Retrieve the file, line, column, and offset represented by
368 * the given source location, as specified in a # line directive.
369 *
370 * Example: given the following source code in a file somefile.c
371 *
372 * #123 "dummy.c" 1
373 *
374 * static int func(void)
375 * {
376 * return 0;
377 * }
378 *
379 * the location information returned by this function would be
380 *
381 * File: dummy.c Line: 124 Column: 12
382 *
383 * whereas clang_getExpansionLocation would have returned
384 *
385 * File: somefile.c Line: 3 Column: 12
386 *
387 * \param location the location within a source file that will be decomposed
388 * into its parts.
389 *
390 * \param filename [out] if non-NULL, will be set to the filename of the
391 * source location. Note that filenames returned will be for "virtual" files,
392 * which don't necessarily exist on the machine running clang - e.g. when
393 * parsing preprocessed output obtained from a different environment. If
394 * a non-NULL value is passed in, remember to dispose of the returned value
395 * using \c clang_disposeString() once you've finished with it. For an invalid
396 * source location, an empty string is returned.
397 *
398 * \param line [out] if non-NULL, will be set to the line number of the
399 * source location. For an invalid source location, zero is returned.
400 *
401 * \param column [out] if non-NULL, will be set to the column number of the
402 * source location. For an invalid source location, zero is returned.
403 */
404CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
405 CXString *filename,
406 unsigned *line,
407 unsigned *column);
408
409/**
Chandler Carruth20174222011-08-31 16:53:37 +0000410 * \brief Legacy API to retrieve the file, line, column, and offset represented
411 * by the given source location.
412 *
413 * This interface has been replaced by the newer interface
414 * \see clang_getExpansionLocation(). See that interface's documentation for
415 * details.
416 */
Douglas Gregor1db19de2010-01-19 21:36:55 +0000417CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
418 CXFile *file,
419 unsigned *line,
Douglas Gregor46766dc2010-01-26 19:19:08 +0000420 unsigned *column,
421 unsigned *offset);
Douglas Gregore69517c2010-01-26 03:07:15 +0000422
423/**
Douglas Gregora9b06d42010-11-09 06:24:54 +0000424 * \brief Retrieve the file, line, column, and offset represented by
425 * the given source location.
426 *
427 * If the location refers into a macro instantiation, return where the
428 * location was originally spelled in the source file.
429 *
430 * \param location the location within a source file that will be decomposed
431 * into its parts.
432 *
433 * \param file [out] if non-NULL, will be set to the file to which the given
434 * source location points.
435 *
436 * \param line [out] if non-NULL, will be set to the line to which the given
437 * source location points.
438 *
439 * \param column [out] if non-NULL, will be set to the column to which the given
440 * source location points.
441 *
442 * \param offset [out] if non-NULL, will be set to the offset into the
443 * buffer to which the given source location points.
444 */
445CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
446 CXFile *file,
447 unsigned *line,
448 unsigned *column,
449 unsigned *offset);
450
451/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000452 * \brief Retrieve a source location representing the first character within a
453 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000454 */
455CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
456
457/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +0000458 * \brief Retrieve a source location representing the last character within a
459 * source range.
Douglas Gregor1db19de2010-01-19 21:36:55 +0000460 */
461CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
462
Douglas Gregorf5525442010-01-20 22:45:41 +0000463/**
464 * @}
465 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +0000466
467/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000468 * \defgroup CINDEX_DIAG Diagnostic reporting
469 *
470 * @{
471 */
472
473/**
474 * \brief Describes the severity of a particular diagnostic.
475 */
476enum CXDiagnosticSeverity {
477 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +0000478 * \brief A diagnostic that has been suppressed, e.g., by a command-line
Douglas Gregor5352ac02010-01-28 00:27:43 +0000479 * option.
480 */
481 CXDiagnostic_Ignored = 0,
Ted Kremenek896b70f2010-03-13 02:50:34 +0000482
Douglas Gregor5352ac02010-01-28 00:27:43 +0000483 /**
484 * \brief This diagnostic is a note that should be attached to the
485 * previous (non-note) diagnostic.
486 */
487 CXDiagnostic_Note = 1,
488
489 /**
490 * \brief This diagnostic indicates suspicious code that may not be
491 * wrong.
492 */
493 CXDiagnostic_Warning = 2,
494
495 /**
496 * \brief This diagnostic indicates that the code is ill-formed.
497 */
498 CXDiagnostic_Error = 3,
499
500 /**
501 * \brief This diagnostic indicates that the code is ill-formed such
502 * that future parser recovery is unlikely to produce useful
503 * results.
504 */
505 CXDiagnostic_Fatal = 4
506};
507
508/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000509 * \brief A single diagnostic, containing the diagnostic's severity,
510 * location, text, source ranges, and fix-it hints.
511 */
512typedef void *CXDiagnostic;
513
514/**
Douglas Gregora88084b2010-02-18 18:08:43 +0000515 * \brief Determine the number of diagnostics produced for the given
516 * translation unit.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000517 */
Douglas Gregora88084b2010-02-18 18:08:43 +0000518CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
519
520/**
521 * \brief Retrieve a diagnostic associated with the given translation unit.
522 *
523 * \param Unit the translation unit to query.
524 * \param Index the zero-based diagnostic number to retrieve.
525 *
526 * \returns the requested diagnostic. This diagnostic must be freed
527 * via a call to \c clang_disposeDiagnostic().
528 */
529CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
530 unsigned Index);
531
532/**
533 * \brief Destroy a diagnostic.
534 */
535CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000536
537/**
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000538 * \brief Options to control the display of diagnostics.
539 *
540 * The values in this enum are meant to be combined to customize the
541 * behavior of \c clang_displayDiagnostic().
542 */
543enum CXDiagnosticDisplayOptions {
544 /**
545 * \brief Display the source-location information where the
546 * diagnostic was located.
547 *
548 * When set, diagnostics will be prefixed by the file, line, and
549 * (optionally) column to which the diagnostic refers. For example,
550 *
551 * \code
552 * test.c:28: warning: extra tokens at end of #endif directive
553 * \endcode
554 *
555 * This option corresponds to the clang flag \c -fshow-source-location.
556 */
557 CXDiagnostic_DisplaySourceLocation = 0x01,
558
559 /**
560 * \brief If displaying the source-location information of the
561 * diagnostic, also include the column number.
562 *
563 * This option corresponds to the clang flag \c -fshow-column.
564 */
565 CXDiagnostic_DisplayColumn = 0x02,
566
567 /**
568 * \brief If displaying the source-location information of the
569 * diagnostic, also include information about source ranges in a
570 * machine-parsable format.
571 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000572 * This option corresponds to the clang flag
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000573 * \c -fdiagnostics-print-source-range-info.
574 */
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000575 CXDiagnostic_DisplaySourceRanges = 0x04,
576
577 /**
578 * \brief Display the option name associated with this diagnostic, if any.
579 *
580 * The option name displayed (e.g., -Wconversion) will be placed in brackets
581 * after the diagnostic text. This option corresponds to the clang flag
582 * \c -fdiagnostics-show-option.
583 */
584 CXDiagnostic_DisplayOption = 0x08,
585
586 /**
587 * \brief Display the category number associated with this diagnostic, if any.
588 *
589 * The category number is displayed within brackets after the diagnostic text.
590 * This option corresponds to the clang flag
591 * \c -fdiagnostics-show-category=id.
592 */
593 CXDiagnostic_DisplayCategoryId = 0x10,
594
595 /**
596 * \brief Display the category name associated with this diagnostic, if any.
597 *
598 * The category name is displayed within brackets after the diagnostic text.
599 * This option corresponds to the clang flag
600 * \c -fdiagnostics-show-category=name.
601 */
602 CXDiagnostic_DisplayCategoryName = 0x20
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000603};
604
605/**
Douglas Gregor274f1902010-02-22 23:17:23 +0000606 * \brief Format the given diagnostic in a manner that is suitable for display.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000607 *
Douglas Gregor274f1902010-02-22 23:17:23 +0000608 * This routine will format the given diagnostic to a string, rendering
Ted Kremenek896b70f2010-03-13 02:50:34 +0000609 * the diagnostic according to the various options given. The
610 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000611 * options that most closely mimics the behavior of the clang compiler.
612 *
613 * \param Diagnostic The diagnostic to print.
614 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000615 * \param Options A set of options that control the diagnostic display,
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000616 * created by combining \c CXDiagnosticDisplayOptions values.
Douglas Gregor274f1902010-02-22 23:17:23 +0000617 *
618 * \returns A new string containing for formatted diagnostic.
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000619 */
Douglas Gregor274f1902010-02-22 23:17:23 +0000620CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
621 unsigned Options);
Douglas Gregor0a812cf2010-02-18 23:07:20 +0000622
623/**
624 * \brief Retrieve the set of display options most similar to the
625 * default behavior of the clang compiler.
626 *
627 * \returns A set of display options suitable for use with \c
628 * clang_displayDiagnostic().
629 */
630CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
631
632/**
Douglas Gregor5352ac02010-01-28 00:27:43 +0000633 * \brief Determine the severity of the given diagnostic.
634 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000635CINDEX_LINKAGE enum CXDiagnosticSeverity
Douglas Gregor5352ac02010-01-28 00:27:43 +0000636clang_getDiagnosticSeverity(CXDiagnostic);
637
638/**
639 * \brief Retrieve the source location of the given diagnostic.
640 *
641 * This location is where Clang would print the caret ('^') when
642 * displaying the diagnostic on the command line.
643 */
644CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
645
646/**
647 * \brief Retrieve the text of the given diagnostic.
648 */
649CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
Douglas Gregora3890ba2010-02-08 23:11:56 +0000650
651/**
Douglas Gregoraa5f1352010-11-19 16:18:16 +0000652 * \brief Retrieve the name of the command-line option that enabled this
653 * diagnostic.
654 *
655 * \param Diag The diagnostic to be queried.
656 *
657 * \param Disable If non-NULL, will be set to the option that disables this
658 * diagnostic (if any).
659 *
660 * \returns A string that contains the command-line option used to enable this
661 * warning, such as "-Wconversion" or "-pedantic".
662 */
663CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
664 CXString *Disable);
665
666/**
667 * \brief Retrieve the category number for this diagnostic.
668 *
669 * Diagnostics can be categorized into groups along with other, related
670 * diagnostics (e.g., diagnostics under the same warning flag). This routine
671 * retrieves the category number for the given diagnostic.
672 *
673 * \returns The number of the category that contains this diagnostic, or zero
674 * if this diagnostic is uncategorized.
675 */
676CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
677
678/**
679 * \brief Retrieve the name of a particular diagnostic category.
680 *
681 * \param Category A diagnostic category number, as returned by
682 * \c clang_getDiagnosticCategory().
683 *
684 * \returns The name of the given diagnostic category.
685 */
686CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
687
688/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000689 * \brief Determine the number of source ranges associated with the given
690 * diagnostic.
691 */
692CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000693
Douglas Gregor5352ac02010-01-28 00:27:43 +0000694/**
Douglas Gregora3890ba2010-02-08 23:11:56 +0000695 * \brief Retrieve a source range associated with the diagnostic.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000696 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000697 * A diagnostic's source ranges highlight important elements in the source
Douglas Gregor5352ac02010-01-28 00:27:43 +0000698 * code. On the command line, Clang displays source ranges by
Ted Kremenek896b70f2010-03-13 02:50:34 +0000699 * underlining them with '~' characters.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000700 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000701 * \param Diagnostic the diagnostic whose range is being extracted.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000702 *
Ted Kremenek896b70f2010-03-13 02:50:34 +0000703 * \param Range the zero-based index specifying which range to
Douglas Gregor5352ac02010-01-28 00:27:43 +0000704 *
Douglas Gregora3890ba2010-02-08 23:11:56 +0000705 * \returns the requested source range.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000706 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000707CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
Douglas Gregora3890ba2010-02-08 23:11:56 +0000708 unsigned Range);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000709
710/**
711 * \brief Determine the number of fix-it hints associated with the
712 * given diagnostic.
713 */
714CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
715
716/**
Douglas Gregor473d7012010-02-19 18:16:06 +0000717 * \brief Retrieve the replacement information for a given fix-it.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000718 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000719 * Fix-its are described in terms of a source range whose contents
720 * should be replaced by a string. This approach generalizes over
721 * three kinds of operations: removal of source code (the range covers
722 * the code to be removed and the replacement string is empty),
723 * replacement of source code (the range covers the code to be
724 * replaced and the replacement string provides the new code), and
725 * insertion (both the start and end of the range point at the
726 * insertion location, and the replacement string provides the text to
727 * insert).
Douglas Gregor5352ac02010-01-28 00:27:43 +0000728 *
Douglas Gregor473d7012010-02-19 18:16:06 +0000729 * \param Diagnostic The diagnostic whose fix-its are being queried.
730 *
731 * \param FixIt The zero-based index of the fix-it.
732 *
733 * \param ReplacementRange The source range whose contents will be
734 * replaced with the returned replacement string. Note that source
735 * ranges are half-open ranges [a, b), so the source code should be
736 * replaced from a and up to (but not including) b.
737 *
738 * \returns A string containing text that should be replace the source
739 * code indicated by the \c ReplacementRange.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000740 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000741CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
Douglas Gregor473d7012010-02-19 18:16:06 +0000742 unsigned FixIt,
743 CXSourceRange *ReplacementRange);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000744
745/**
746 * @}
747 */
748
749/**
750 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
751 *
752 * The routines in this group provide the ability to create and destroy
753 * translation units from files, either by parsing the contents of the files or
754 * by reading in a serialized representation of a translation unit.
755 *
756 * @{
757 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000758
Douglas Gregor5352ac02010-01-28 00:27:43 +0000759/**
760 * \brief Get the original translation unit source file name.
761 */
762CINDEX_LINKAGE CXString
763clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
764
765/**
766 * \brief Return the CXTranslationUnit for a given source file and the provided
767 * command line arguments one would pass to the compiler.
768 *
769 * Note: The 'source_filename' argument is optional. If the caller provides a
770 * NULL pointer, the name of the source file is expected to reside in the
771 * specified command line arguments.
772 *
773 * Note: When encountered in 'clang_command_line_args', the following options
774 * are ignored:
775 *
776 * '-c'
777 * '-emit-ast'
778 * '-fsyntax-only'
779 * '-o <output file>' (both '-o' and '<output file>' are ignored)
780 *
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000781 * \param CIdx The index object with which the translation unit will be
782 * associated.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000783 *
784 * \param source_filename - The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000785 * source file is included in \p clang_command_line_args.
786 *
787 * \param num_clang_command_line_args The number of command-line arguments in
788 * \p clang_command_line_args.
789 *
790 * \param clang_command_line_args The command-line arguments that would be
791 * passed to the \c clang executable if it were being invoked out-of-process.
792 * These command-line options will be parsed and will affect how the translation
793 * unit is parsed. Note that the following options are ignored: '-c',
794 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000795 *
796 * \param num_unsaved_files the number of unsaved file entries in \p
797 * unsaved_files.
798 *
799 * \param unsaved_files the files that have not yet been saved to disk
800 * but may be required for code completion, including the contents of
Ted Kremenekc6f530d2010-04-12 18:47:26 +0000801 * those files. The contents and name of these files (as specified by
802 * CXUnsavedFile) are copied when necessary, so the client only needs to
803 * guarantee their validity until the call to this function returns.
Douglas Gregor5352ac02010-01-28 00:27:43 +0000804 */
805CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
806 CXIndex CIdx,
807 const char *source_filename,
808 int num_clang_command_line_args,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000809 const char * const *clang_command_line_args,
Douglas Gregor5352ac02010-01-28 00:27:43 +0000810 unsigned num_unsaved_files,
Douglas Gregora88084b2010-02-18 18:08:43 +0000811 struct CXUnsavedFile *unsaved_files);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000812
Douglas Gregor5352ac02010-01-28 00:27:43 +0000813/**
814 * \brief Create a translation unit from an AST file (-emit-ast).
815 */
Ted Kremenek896b70f2010-03-13 02:50:34 +0000816CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
Douglas Gregora88084b2010-02-18 18:08:43 +0000817 const char *ast_filename);
Douglas Gregor5352ac02010-01-28 00:27:43 +0000818
Douglas Gregor44c181a2010-07-23 00:33:23 +0000819/**
820 * \brief Flags that control the creation of translation units.
821 *
822 * The enumerators in this enumeration type are meant to be bitwise
823 * ORed together to specify which options should be used when
824 * constructing the translation unit.
825 */
Douglas Gregor5a430212010-07-21 18:52:53 +0000826enum CXTranslationUnit_Flags {
827 /**
828 * \brief Used to indicate that no special translation-unit options are
829 * needed.
830 */
831 CXTranslationUnit_None = 0x0,
832
833 /**
834 * \brief Used to indicate that the parser should construct a "detailed"
835 * preprocessing record, including all macro definitions and instantiations.
836 *
837 * Constructing a detailed preprocessing record requires more memory
838 * and time to parse, since the information contained in the record
839 * is usually not retained. However, it can be useful for
840 * applications that require more detailed information about the
841 * behavior of the preprocessor.
842 */
Douglas Gregor44c181a2010-07-23 00:33:23 +0000843 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
844
845 /**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000846 * \brief Used to indicate that the translation unit is incomplete.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000847 *
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000848 * When a translation unit is considered "incomplete", semantic
849 * analysis that is typically performed at the end of the
850 * translation unit will be suppressed. For example, this suppresses
851 * the completion of tentative declarations in C and of
852 * instantiation of implicitly-instantiation function templates in
853 * C++. This option is typically used when parsing a header with the
854 * intent of producing a precompiled header.
Douglas Gregor44c181a2010-07-23 00:33:23 +0000855 */
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000856 CXTranslationUnit_Incomplete = 0x02,
Douglas Gregor44c181a2010-07-23 00:33:23 +0000857
858 /**
859 * \brief Used to indicate that the translation unit should be built with an
860 * implicit precompiled header for the preamble.
861 *
862 * An implicit precompiled header is used as an optimization when a
863 * particular translation unit is likely to be reparsed many times
864 * when the sources aren't changing that often. In this case, an
865 * implicit precompiled header will be built containing all of the
866 * initial includes at the top of the main file (what we refer to as
867 * the "preamble" of the file). In subsequent parses, if the
868 * preamble or the files in it have not changed, \c
869 * clang_reparseTranslationUnit() will re-use the implicit
870 * precompiled header to improve parsing performance.
871 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000872 CXTranslationUnit_PrecompiledPreamble = 0x04,
873
874 /**
875 * \brief Used to indicate that the translation unit should cache some
876 * code-completion results with each reparse of the source file.
877 *
878 * Caching of code-completion results is a performance optimization that
879 * introduces some overhead to reparsing but improves the performance of
880 * code-completion operations.
881 */
Douglas Gregor99ba2022010-10-27 17:24:53 +0000882 CXTranslationUnit_CacheCompletionResults = 0x08,
883 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +0000884 * \brief DEPRECATED: Enable precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000885 *
886 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +0000887 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000888 */
889 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
890
891 /**
Douglas Gregorb5af8432011-08-25 22:54:01 +0000892 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000893 *
894 * Note: this is a *temporary* option that is available only while
Douglas Gregorb5af8432011-08-25 22:54:01 +0000895 * we are testing C++ precompiled preamble support. It is deprecated.
Douglas Gregor99ba2022010-10-27 17:24:53 +0000896 */
Douglas Gregordca8ee82011-05-06 16:33:08 +0000897 CXTranslationUnit_CXXChainedPCH = 0x20,
898
899 /**
900 * \brief Used to indicate that the "detailed" preprocessing record,
Chandler Carruthfd14e912011-07-14 16:08:00 +0000901 * if requested, should also contain nested macro expansions.
Douglas Gregordca8ee82011-05-06 16:33:08 +0000902 *
Chandler Carruthfd14e912011-07-14 16:08:00 +0000903 * Nested macro expansions (i.e., macro expansions that occur
904 * inside another macro expansion) can, in some code bases, require
Douglas Gregordca8ee82011-05-06 16:33:08 +0000905 * a large amount of storage to due preprocessor metaprogramming. Moreover,
906 * its fairly rare that this information is useful for libclang clients.
907 */
Chandler Carruthba7537f2011-07-14 09:02:10 +0000908 CXTranslationUnit_NestedMacroExpansions = 0x40,
909
910 /**
911 * \brief Legacy name to indicate that the "detailed" preprocessing record,
Chandler Carruthfd14e912011-07-14 16:08:00 +0000912 * if requested, should contain nested macro expansions.
Chandler Carruthba7537f2011-07-14 09:02:10 +0000913 *
914 * \see CXTranslationUnit_NestedMacroExpansions for the current name for this
915 * value, and its semantics. This is just an alias.
916 */
917 CXTranslationUnit_NestedMacroInstantiations =
918 CXTranslationUnit_NestedMacroExpansions
Douglas Gregor5a430212010-07-21 18:52:53 +0000919};
920
921/**
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000922 * \brief Returns the set of flags that is suitable for parsing a translation
923 * unit that is being edited.
924 *
925 * The set of flags returned provide options for \c clang_parseTranslationUnit()
926 * to indicate that the translation unit is likely to be reparsed many times,
927 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
928 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
929 * set contains an unspecified set of optimizations (e.g., the precompiled
930 * preamble) geared toward improving the performance of these routines. The
931 * set of optimizations enabled may change from one version to the next.
932 */
Douglas Gregore1e13bf2010-08-11 15:58:42 +0000933CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
Douglas Gregorb1c031b2010-08-09 22:28:58 +0000934
935/**
Douglas Gregor5a430212010-07-21 18:52:53 +0000936 * \brief Parse the given source file and the translation unit corresponding
937 * to that file.
938 *
939 * This routine is the main entry point for the Clang C API, providing the
940 * ability to parse a source file into a translation unit that can then be
941 * queried by other functions in the API. This routine accepts a set of
942 * command-line arguments so that the compilation can be configured in the same
943 * way that the compiler is configured on the command line.
944 *
945 * \param CIdx The index object with which the translation unit will be
946 * associated.
947 *
948 * \param source_filename The name of the source file to load, or NULL if the
Ted Kremenek1ddb02c2010-11-08 04:28:51 +0000949 * source file is included in \p command_line_args.
Douglas Gregor5a430212010-07-21 18:52:53 +0000950 *
951 * \param command_line_args The command-line arguments that would be
952 * passed to the \c clang executable if it were being invoked out-of-process.
953 * These command-line options will be parsed and will affect how the translation
954 * unit is parsed. Note that the following options are ignored: '-c',
955 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
956 *
957 * \param num_command_line_args The number of command-line arguments in
958 * \p command_line_args.
959 *
960 * \param unsaved_files the files that have not yet been saved to disk
Douglas Gregor1abc6bc2010-08-04 16:47:14 +0000961 * but may be required for parsing, including the contents of
Douglas Gregor5a430212010-07-21 18:52:53 +0000962 * those files. The contents and name of these files (as specified by
963 * CXUnsavedFile) are copied when necessary, so the client only needs to
964 * guarantee their validity until the call to this function returns.
965 *
966 * \param num_unsaved_files the number of unsaved file entries in \p
967 * unsaved_files.
968 *
969 * \param options A bitmask of options that affects how the translation unit
970 * is managed but not its compilation. This should be a bitwise OR of the
971 * CXTranslationUnit_XXX flags.
972 *
973 * \returns A new translation unit describing the parsed code and containing
974 * any diagnostics produced by the compiler. If there is a failure from which
975 * the compiler cannot recover, returns NULL.
976 */
977CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
978 const char *source_filename,
Douglas Gregor2ef69442010-09-01 16:43:19 +0000979 const char * const *command_line_args,
Douglas Gregor5a430212010-07-21 18:52:53 +0000980 int num_command_line_args,
981 struct CXUnsavedFile *unsaved_files,
982 unsigned num_unsaved_files,
983 unsigned options);
984
Douglas Gregor5352ac02010-01-28 00:27:43 +0000985/**
Douglas Gregor19998442010-08-13 15:35:05 +0000986 * \brief Flags that control how translation units are saved.
987 *
988 * The enumerators in this enumeration type are meant to be bitwise
989 * ORed together to specify which options should be used when
990 * saving the translation unit.
991 */
992enum CXSaveTranslationUnit_Flags {
993 /**
994 * \brief Used to indicate that no special saving options are needed.
995 */
996 CXSaveTranslationUnit_None = 0x0
997};
998
999/**
1000 * \brief Returns the set of flags that is suitable for saving a translation
1001 * unit.
1002 *
1003 * The set of flags returned provide options for
1004 * \c clang_saveTranslationUnit() by default. The returned flag
1005 * set contains an unspecified set of options that save translation units with
1006 * the most commonly-requested data.
1007 */
1008CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1009
1010/**
Douglas Gregor39c411f2011-07-06 16:43:36 +00001011 * \brief Describes the kind of error that occurred (if any) in a call to
1012 * \c clang_saveTranslationUnit().
1013 */
1014enum CXSaveError {
1015 /**
1016 * \brief Indicates that no error occurred while saving a translation unit.
1017 */
1018 CXSaveError_None = 0,
1019
1020 /**
1021 * \brief Indicates that an unknown error occurred while attempting to save
1022 * the file.
1023 *
1024 * This error typically indicates that file I/O failed when attempting to
1025 * write the file.
1026 */
1027 CXSaveError_Unknown = 1,
1028
1029 /**
1030 * \brief Indicates that errors during translation prevented this attempt
1031 * to save the translation unit.
1032 *
1033 * Errors that prevent the translation unit from being saved can be
1034 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1035 */
1036 CXSaveError_TranslationErrors = 2,
1037
1038 /**
1039 * \brief Indicates that the translation unit to be saved was somehow
1040 * invalid (e.g., NULL).
1041 */
1042 CXSaveError_InvalidTU = 3
1043};
1044
1045/**
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001046 * \brief Saves a translation unit into a serialized representation of
1047 * that translation unit on disk.
1048 *
1049 * Any translation unit that was parsed without error can be saved
1050 * into a file. The translation unit can then be deserialized into a
1051 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1052 * if it is an incomplete translation unit that corresponds to a
1053 * header, used as a precompiled header when parsing other translation
1054 * units.
1055 *
1056 * \param TU The translation unit to save.
Douglas Gregor19998442010-08-13 15:35:05 +00001057 *
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001058 * \param FileName The file to which the translation unit will be saved.
1059 *
Douglas Gregor19998442010-08-13 15:35:05 +00001060 * \param options A bitmask of options that affects how the translation unit
1061 * is saved. This should be a bitwise OR of the
1062 * CXSaveTranslationUnit_XXX flags.
1063 *
Douglas Gregor39c411f2011-07-06 16:43:36 +00001064 * \returns A value that will match one of the enumerators of the CXSaveError
1065 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1066 * saved successfully, while a non-zero value indicates that a problem occurred.
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001067 */
1068CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
Douglas Gregor19998442010-08-13 15:35:05 +00001069 const char *FileName,
1070 unsigned options);
Douglas Gregor7ae2faa2010-08-13 05:36:37 +00001071
1072/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001073 * \brief Destroy the specified CXTranslationUnit object.
1074 */
1075CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
Ted Kremenek896b70f2010-03-13 02:50:34 +00001076
Douglas Gregor5352ac02010-01-28 00:27:43 +00001077/**
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001078 * \brief Flags that control the reparsing of translation units.
1079 *
1080 * The enumerators in this enumeration type are meant to be bitwise
1081 * ORed together to specify which options should be used when
1082 * reparsing the translation unit.
1083 */
1084enum CXReparse_Flags {
1085 /**
1086 * \brief Used to indicate that no special reparsing options are needed.
1087 */
1088 CXReparse_None = 0x0
1089};
1090
1091/**
1092 * \brief Returns the set of flags that is suitable for reparsing a translation
1093 * unit.
1094 *
1095 * The set of flags returned provide options for
1096 * \c clang_reparseTranslationUnit() by default. The returned flag
1097 * set contains an unspecified set of optimizations geared toward common uses
1098 * of reparsing. The set of optimizations enabled may change from one version
1099 * to the next.
1100 */
1101CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1102
1103/**
Douglas Gregorabc563f2010-07-19 21:46:24 +00001104 * \brief Reparse the source files that produced this translation unit.
1105 *
1106 * This routine can be used to re-parse the source files that originally
1107 * created the given translation unit, for example because those source files
1108 * have changed (either on disk or as passed via \p unsaved_files). The
1109 * source code will be reparsed with the same command-line options as it
1110 * was originally parsed.
1111 *
1112 * Reparsing a translation unit invalidates all cursors and source locations
1113 * that refer into that translation unit. This makes reparsing a translation
1114 * unit semantically equivalent to destroying the translation unit and then
1115 * creating a new translation unit with the same command-line arguments.
1116 * However, it may be more efficient to reparse a translation
1117 * unit using this routine.
1118 *
1119 * \param TU The translation unit whose contents will be re-parsed. The
1120 * translation unit must originally have been built with
1121 * \c clang_createTranslationUnitFromSourceFile().
1122 *
1123 * \param num_unsaved_files The number of unsaved file entries in \p
1124 * unsaved_files.
1125 *
1126 * \param unsaved_files The files that have not yet been saved to disk
1127 * but may be required for parsing, including the contents of
1128 * those files. The contents and name of these files (as specified by
1129 * CXUnsavedFile) are copied when necessary, so the client only needs to
1130 * guarantee their validity until the call to this function returns.
1131 *
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001132 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1133 * The function \c clang_defaultReparseOptions() produces a default set of
1134 * options recommended for most uses, based on the translation unit.
1135 *
Douglas Gregorabc563f2010-07-19 21:46:24 +00001136 * \returns 0 if the sources could be reparsed. A non-zero value will be
1137 * returned if reparsing was impossible, such that the translation unit is
1138 * invalid. In such cases, the only valid call for \p TU is
1139 * \c clang_disposeTranslationUnit(TU).
1140 */
1141CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1142 unsigned num_unsaved_files,
Douglas Gregore1e13bf2010-08-11 15:58:42 +00001143 struct CXUnsavedFile *unsaved_files,
1144 unsigned options);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001145
1146/**
1147 * \brief Categorizes how memory is being used by a translation unit.
1148 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001149enum CXTUResourceUsageKind {
1150 CXTUResourceUsage_AST = 1,
1151 CXTUResourceUsage_Identifiers = 2,
1152 CXTUResourceUsage_Selectors = 3,
1153 CXTUResourceUsage_GlobalCompletionResults = 4,
Ted Kremenek457aaf02011-04-28 04:10:31 +00001154 CXTUResourceUsage_SourceManagerContentCache = 5,
Ted Kremenekba29bd22011-04-28 04:53:38 +00001155 CXTUResourceUsage_AST_SideTables = 6,
Ted Kremenekf61b8312011-04-28 20:36:42 +00001156 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
Ted Kremeneke9b5f3d2011-04-28 23:46:20 +00001157 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1158 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1159 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
Ted Kremenek5e1db6a2011-05-04 01:38:46 +00001160 CXTUResourceUsage_Preprocessor = 11,
1161 CXTUResourceUsage_PreprocessingRecord = 12,
Ted Kremenekca7dc2b2011-07-26 23:46:06 +00001162 CXTUResourceUsage_SourceManager_DataStructures = 13,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001163 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
Ted Kremenekf7870022011-04-20 16:41:07 +00001164 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1165 CXTUResourceUsage_MEMORY_IN_BYTES_END =
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001166 CXTUResourceUsage_Preprocessor_HeaderSearch,
Ted Kremenekf7870022011-04-20 16:41:07 +00001167
1168 CXTUResourceUsage_First = CXTUResourceUsage_AST,
Ted Kremenekd1194fb2011-07-26 23:46:11 +00001169 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001170};
1171
1172/**
1173 * \brief Returns the human-readable null-terminated C string that represents
Ted Kremenekf7870022011-04-20 16:41:07 +00001174 * the name of the memory category. This string should never be freed.
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001175 */
1176CINDEX_LINKAGE
Ted Kremenekf7870022011-04-20 16:41:07 +00001177const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001178
Ted Kremenekf7870022011-04-20 16:41:07 +00001179typedef struct CXTUResourceUsageEntry {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001180 /* \brief The memory usage category. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001181 enum CXTUResourceUsageKind kind;
1182 /* \brief Amount of resources used.
1183 The units will depend on the resource kind. */
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001184 unsigned long amount;
Ted Kremenekf7870022011-04-20 16:41:07 +00001185} CXTUResourceUsageEntry;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001186
1187/**
1188 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1189 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001190typedef struct CXTUResourceUsage {
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001191 /* \brief Private data member, used for queries. */
1192 void *data;
1193
1194 /* \brief The number of entries in the 'entries' array. */
1195 unsigned numEntries;
1196
1197 /* \brief An array of key-value pairs, representing the breakdown of memory
1198 usage. */
Ted Kremenekf7870022011-04-20 16:41:07 +00001199 CXTUResourceUsageEntry *entries;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001200
Ted Kremenekf7870022011-04-20 16:41:07 +00001201} CXTUResourceUsage;
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001202
1203/**
1204 * \brief Return the memory usage of a translation unit. This object
Ted Kremenekf7870022011-04-20 16:41:07 +00001205 * should be released with clang_disposeCXTUResourceUsage().
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001206 */
Ted Kremenekf7870022011-04-20 16:41:07 +00001207CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001208
Ted Kremenekf7870022011-04-20 16:41:07 +00001209CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
Ted Kremenek59fc1e52011-04-18 22:47:10 +00001210
Douglas Gregorabc563f2010-07-19 21:46:24 +00001211/**
Douglas Gregor5352ac02010-01-28 00:27:43 +00001212 * @}
1213 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00001214
Douglas Gregor5352ac02010-01-28 00:27:43 +00001215/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001216 * \brief Describes the kind of entity that a cursor refers to.
1217 */
1218enum CXCursorKind {
1219 /* Declarations */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001220 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001221 * \brief A declaration whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001222 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001223 *
1224 * Unexposed declarations have the same operations as any other kind
1225 * of declaration; one can extract their location information,
1226 * spelling, find their definitions, etc. However, the specific kind
1227 * of the declaration is not reported.
1228 */
1229 CXCursor_UnexposedDecl = 1,
1230 /** \brief A C or C++ struct. */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001231 CXCursor_StructDecl = 2,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001232 /** \brief A C or C++ union. */
1233 CXCursor_UnionDecl = 3,
1234 /** \brief A C++ class. */
1235 CXCursor_ClassDecl = 4,
1236 /** \brief An enumeration. */
1237 CXCursor_EnumDecl = 5,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001238 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001239 * \brief A field (in C) or non-static data member (in C++) in a
1240 * struct, union, or C++ class.
1241 */
1242 CXCursor_FieldDecl = 6,
1243 /** \brief An enumerator constant. */
1244 CXCursor_EnumConstantDecl = 7,
1245 /** \brief A function. */
1246 CXCursor_FunctionDecl = 8,
1247 /** \brief A variable. */
1248 CXCursor_VarDecl = 9,
1249 /** \brief A function or method parameter. */
1250 CXCursor_ParmDecl = 10,
1251 /** \brief An Objective-C @interface. */
1252 CXCursor_ObjCInterfaceDecl = 11,
1253 /** \brief An Objective-C @interface for a category. */
1254 CXCursor_ObjCCategoryDecl = 12,
1255 /** \brief An Objective-C @protocol declaration. */
1256 CXCursor_ObjCProtocolDecl = 13,
1257 /** \brief An Objective-C @property declaration. */
1258 CXCursor_ObjCPropertyDecl = 14,
1259 /** \brief An Objective-C instance variable. */
1260 CXCursor_ObjCIvarDecl = 15,
1261 /** \brief An Objective-C instance method. */
1262 CXCursor_ObjCInstanceMethodDecl = 16,
1263 /** \brief An Objective-C class method. */
1264 CXCursor_ObjCClassMethodDecl = 17,
1265 /** \brief An Objective-C @implementation. */
1266 CXCursor_ObjCImplementationDecl = 18,
1267 /** \brief An Objective-C @implementation for a category. */
1268 CXCursor_ObjCCategoryImplDecl = 19,
1269 /** \brief A typedef */
1270 CXCursor_TypedefDecl = 20,
Ted Kremenek8bd5a692010-04-13 23:39:06 +00001271 /** \brief A C++ class method. */
1272 CXCursor_CXXMethod = 21,
Ted Kremenek8f06e0e2010-05-06 23:38:21 +00001273 /** \brief A C++ namespace. */
1274 CXCursor_Namespace = 22,
Ted Kremeneka0536d82010-05-07 01:04:29 +00001275 /** \brief A linkage specification, e.g. 'extern "C"'. */
1276 CXCursor_LinkageSpec = 23,
Douglas Gregor01829d32010-08-31 14:41:23 +00001277 /** \brief A C++ constructor. */
1278 CXCursor_Constructor = 24,
1279 /** \brief A C++ destructor. */
1280 CXCursor_Destructor = 25,
1281 /** \brief A C++ conversion function. */
1282 CXCursor_ConversionFunction = 26,
Douglas Gregorfe72e9c2010-08-31 17:01:39 +00001283 /** \brief A C++ template type parameter. */
1284 CXCursor_TemplateTypeParameter = 27,
1285 /** \brief A C++ non-type template parameter. */
1286 CXCursor_NonTypeTemplateParameter = 28,
1287 /** \brief A C++ template template parameter. */
1288 CXCursor_TemplateTemplateParameter = 29,
1289 /** \brief A C++ function template. */
1290 CXCursor_FunctionTemplate = 30,
Douglas Gregor39d6f072010-08-31 19:02:00 +00001291 /** \brief A C++ class template. */
1292 CXCursor_ClassTemplate = 31,
Douglas Gregor74dbe642010-08-31 19:31:58 +00001293 /** \brief A C++ class template partial specialization. */
1294 CXCursor_ClassTemplatePartialSpecialization = 32,
Douglas Gregor69319002010-08-31 23:48:11 +00001295 /** \brief A C++ namespace alias declaration. */
1296 CXCursor_NamespaceAlias = 33,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001297 /** \brief A C++ using directive. */
1298 CXCursor_UsingDirective = 34,
Richard Smith162e1c12011-04-15 14:24:37 +00001299 /** \brief A C++ using declaration. */
Douglas Gregor7e242562010-09-01 19:52:22 +00001300 CXCursor_UsingDeclaration = 35,
Richard Smith162e1c12011-04-15 14:24:37 +00001301 /** \brief A C++ alias declaration */
1302 CXCursor_TypeAliasDecl = 36,
Douglas Gregor352697a2011-06-03 23:08:58 +00001303 /** \brief An Objective-C @synthesize definition. */
1304 CXCursor_ObjCSynthesizeDecl = 37,
1305 /** \brief An Objective-C @dynamic definition. */
1306 CXCursor_ObjCDynamicDecl = 38,
Ted Kremenek50aa6ac2010-05-19 21:51:10 +00001307 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
Douglas Gregor352697a2011-06-03 23:08:58 +00001308 CXCursor_LastDecl = CXCursor_ObjCDynamicDecl,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001309
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001310 /* References */
1311 CXCursor_FirstRef = 40, /* Decl references */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001312 CXCursor_ObjCSuperClassRef = 40,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001313 CXCursor_ObjCProtocolRef = 41,
1314 CXCursor_ObjCClassRef = 42,
1315 /**
1316 * \brief A reference to a type declaration.
1317 *
1318 * A type reference occurs anywhere where a type is named but not
1319 * declared. For example, given:
1320 *
1321 * \code
1322 * typedef unsigned size_type;
1323 * size_type size;
1324 * \endcode
1325 *
1326 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1327 * while the type of the variable "size" is referenced. The cursor
1328 * referenced by the type of size is the typedef for size_type.
1329 */
1330 CXCursor_TypeRef = 43,
Ted Kremenek3064ef92010-08-27 21:34:58 +00001331 CXCursor_CXXBaseSpecifier = 44,
Douglas Gregor0b36e612010-08-31 20:37:03 +00001332 /**
Douglas Gregora67e03f2010-09-09 21:42:20 +00001333 * \brief A reference to a class template, function template, template
1334 * template parameter, or class template partial specialization.
Douglas Gregor0b36e612010-08-31 20:37:03 +00001335 */
1336 CXCursor_TemplateRef = 45,
Douglas Gregor69319002010-08-31 23:48:11 +00001337 /**
1338 * \brief A reference to a namespace or namespace alias.
1339 */
1340 CXCursor_NamespaceRef = 46,
Douglas Gregora67e03f2010-09-09 21:42:20 +00001341 /**
Douglas Gregor36897b02010-09-10 00:22:18 +00001342 * \brief A reference to a member of a struct, union, or class that occurs in
1343 * some non-expression context, e.g., a designated initializer.
Douglas Gregora67e03f2010-09-09 21:42:20 +00001344 */
1345 CXCursor_MemberRef = 47,
Douglas Gregor36897b02010-09-10 00:22:18 +00001346 /**
1347 * \brief A reference to a labeled statement.
1348 *
1349 * This cursor kind is used to describe the jump to "start_over" in the
1350 * goto statement in the following example:
1351 *
1352 * \code
1353 * start_over:
1354 * ++counter;
1355 *
1356 * goto start_over;
1357 * \endcode
1358 *
1359 * A label reference cursor refers to a label statement.
1360 */
1361 CXCursor_LabelRef = 48,
1362
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00001363 /**
1364 * \brief A reference to a set of overloaded functions or function templates
1365 * that has not yet been resolved to a specific function or function template.
1366 *
1367 * An overloaded declaration reference cursor occurs in C++ templates where
1368 * a dependent name refers to a function. For example:
1369 *
1370 * \code
1371 * template<typename T> void swap(T&, T&);
1372 *
1373 * struct X { ... };
1374 * void swap(X&, X&);
1375 *
1376 * template<typename T>
1377 * void reverse(T* first, T* last) {
1378 * while (first < last - 1) {
1379 * swap(*first, *--last);
1380 * ++first;
1381 * }
1382 * }
1383 *
1384 * struct Y { };
1385 * void swap(Y&, Y&);
1386 * \endcode
1387 *
1388 * Here, the identifier "swap" is associated with an overloaded declaration
1389 * reference. In the template definition, "swap" refers to either of the two
1390 * "swap" functions declared above, so both results will be available. At
1391 * instantiation time, "swap" may also refer to other functions found via
1392 * argument-dependent lookup (e.g., the "swap" function at the end of the
1393 * example).
1394 *
1395 * The functions \c clang_getNumOverloadedDecls() and
1396 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1397 * referenced by this cursor.
1398 */
1399 CXCursor_OverloadedDeclRef = 49,
1400
1401 CXCursor_LastRef = CXCursor_OverloadedDeclRef,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001402
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001403 /* Error conditions */
1404 CXCursor_FirstInvalid = 70,
1405 CXCursor_InvalidFile = 70,
1406 CXCursor_NoDeclFound = 71,
1407 CXCursor_NotImplemented = 72,
Ted Kremenekebfa3392010-03-19 20:39:03 +00001408 CXCursor_InvalidCode = 73,
1409 CXCursor_LastInvalid = CXCursor_InvalidCode,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001410
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001411 /* Expressions */
1412 CXCursor_FirstExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001413
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001414 /**
1415 * \brief An expression whose specific kind is not exposed via this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001416 * interface.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001417 *
1418 * Unexposed expressions have the same operations as any other kind
1419 * of expression; one can extract their location information,
1420 * spelling, children, etc. However, the specific kind of the
1421 * expression is not reported.
1422 */
1423 CXCursor_UnexposedExpr = 100,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001424
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001425 /**
1426 * \brief An expression that refers to some value declaration, such
1427 * as a function, varible, or enumerator.
1428 */
1429 CXCursor_DeclRefExpr = 101,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001430
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001431 /**
1432 * \brief An expression that refers to a member of a struct, union,
1433 * class, Objective-C class, etc.
1434 */
1435 CXCursor_MemberRefExpr = 102,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001436
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001437 /** \brief An expression that calls a function. */
1438 CXCursor_CallExpr = 103,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001439
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001440 /** \brief An expression that sends a message to an Objective-C
1441 object or class. */
1442 CXCursor_ObjCMessageExpr = 104,
Ted Kremenek1ee6cad2010-04-11 21:47:37 +00001443
1444 /** \brief An expression that represents a block literal. */
1445 CXCursor_BlockExpr = 105,
1446
1447 CXCursor_LastExpr = 105,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001448
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001449 /* Statements */
1450 CXCursor_FirstStmt = 200,
1451 /**
1452 * \brief A statement whose specific kind is not exposed via this
1453 * interface.
1454 *
1455 * Unexposed statements have the same operations as any other kind of
1456 * statement; one can extract their location information, spelling,
1457 * children, etc. However, the specific kind of the statement is not
1458 * reported.
1459 */
1460 CXCursor_UnexposedStmt = 200,
Douglas Gregor36897b02010-09-10 00:22:18 +00001461
1462 /** \brief A labelled statement in a function.
1463 *
1464 * This cursor kind is used to describe the "start_over:" label statement in
1465 * the following example:
1466 *
1467 * \code
1468 * start_over:
1469 * ++counter;
1470 * \endcode
1471 *
1472 */
1473 CXCursor_LabelStmt = 201,
1474
1475 CXCursor_LastStmt = CXCursor_LabelStmt,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001476
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001477 /**
1478 * \brief Cursor that represents the translation unit itself.
1479 *
1480 * The translation unit cursor exists primarily to act as the root
1481 * cursor for traversing the contents of a translation unit.
1482 */
Ted Kremeneke77f4432010-02-18 03:09:07 +00001483 CXCursor_TranslationUnit = 300,
1484
1485 /* Attributes */
1486 CXCursor_FirstAttr = 400,
1487 /**
1488 * \brief An attribute whose specific kind is not exposed via this
1489 * interface.
1490 */
1491 CXCursor_UnexposedAttr = 400,
1492
1493 CXCursor_IBActionAttr = 401,
1494 CXCursor_IBOutletAttr = 402,
Ted Kremenek857e9182010-05-19 17:38:06 +00001495 CXCursor_IBOutletCollectionAttr = 403,
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +00001496 CXCursor_CXXFinalAttr = 404,
1497 CXCursor_CXXOverrideAttr = 405,
1498 CXCursor_LastAttr = CXCursor_CXXOverrideAttr,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001499
1500 /* Preprocessing */
1501 CXCursor_PreprocessingDirective = 500,
Douglas Gregor572feb22010-03-18 18:04:21 +00001502 CXCursor_MacroDefinition = 501,
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +00001503 CXCursor_MacroExpansion = 502,
1504 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001505 CXCursor_InclusionDirective = 503,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001506 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
Douglas Gregorecdcb882010-10-20 22:00:55 +00001507 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001508};
1509
1510/**
1511 * \brief A cursor representing some element in the abstract syntax tree for
1512 * a translation unit.
1513 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001514 * The cursor abstraction unifies the different kinds of entities in a
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001515 * program--declaration, statements, expressions, references to declarations,
1516 * etc.--under a single "cursor" abstraction with a common set of operations.
1517 * Common operation for a cursor include: getting the physical location in
1518 * a source file where the cursor points, getting the name associated with a
1519 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1520 *
1521 * Cursors can be produced in two specific ways.
1522 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1523 * from which one can use clang_visitChildren() to explore the rest of the
1524 * translation unit. clang_getCursor() maps from a physical source location
1525 * to the entity that resides at that location, allowing one to map from the
1526 * source code into the AST.
1527 */
1528typedef struct {
1529 enum CXCursorKind kind;
1530 void *data[3];
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001531} CXCursor;
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001532
1533/**
1534 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1535 *
1536 * @{
1537 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001538
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001539/**
1540 * \brief Retrieve the NULL cursor, which represents no entity.
1541 */
1542CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001543
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001544/**
1545 * \brief Retrieve the cursor that represents the given translation unit.
1546 *
1547 * The translation unit cursor can be used to start traversing the
1548 * various declarations within the given translation unit.
1549 */
1550CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1551
1552/**
1553 * \brief Determine whether two cursors are equivalent.
1554 */
1555CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001556
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001557/**
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001558 * \brief Returns non-zero if \arg cursor is null.
1559 */
1560static inline int clang_Cursor_isNull(CXCursor cursor) {
1561 return clang_equalCursors(cursor, clang_getNullCursor());
1562}
1563
1564/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001565 * \brief Compute a hash value for the given cursor.
1566 */
1567CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1568
1569/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001570 * \brief Retrieve the kind of the given cursor.
1571 */
1572CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1573
1574/**
1575 * \brief Determine whether the given cursor kind represents a declaration.
1576 */
1577CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1578
1579/**
1580 * \brief Determine whether the given cursor kind represents a simple
1581 * reference.
1582 *
1583 * Note that other kinds of cursors (such as expressions) can also refer to
1584 * other cursors. Use clang_getCursorReferenced() to determine whether a
1585 * particular cursor refers to another entity.
1586 */
1587CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1588
1589/**
1590 * \brief Determine whether the given cursor kind represents an expression.
1591 */
1592CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1593
1594/**
1595 * \brief Determine whether the given cursor kind represents a statement.
1596 */
1597CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1598
1599/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00001600 * \brief Determine whether the given cursor kind represents an attribute.
1601 */
1602CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
1603
1604/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001605 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001606 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001607 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001608CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1609
1610/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001611 * \brief Determine whether the given cursor kind represents a translation
1612 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001613 */
1614CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001615
Ted Kremenekad6eff62010-03-08 21:17:29 +00001616/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001617 * \brief Determine whether the given cursor represents a preprocessing
1618 * element, such as a preprocessor directive or macro instantiation.
1619 */
1620CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1621
1622/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001623 * \brief Determine whether the given cursor represents a currently
1624 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1625 */
1626CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1627
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001628/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001629 * \brief Describe the linkage of the entity referred to by a cursor.
1630 */
1631enum CXLinkageKind {
1632 /** \brief This value indicates that no linkage information is available
1633 * for a provided CXCursor. */
1634 CXLinkage_Invalid,
1635 /**
1636 * \brief This is the linkage for variables, parameters, and so on that
1637 * have automatic storage. This covers normal (non-extern) local variables.
1638 */
1639 CXLinkage_NoLinkage,
1640 /** \brief This is the linkage for static variables and static functions. */
1641 CXLinkage_Internal,
1642 /** \brief This is the linkage for entities with external linkage that live
1643 * in C++ anonymous namespaces.*/
1644 CXLinkage_UniqueExternal,
1645 /** \brief This is the linkage for entities with true, external linkage. */
1646 CXLinkage_External
1647};
1648
1649/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001650 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001651 */
1652CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1653
1654/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001655 * \brief Determine the availability of the entity that this cursor refers to.
1656 *
1657 * \param cursor The cursor to query.
1658 *
1659 * \returns The availability of the cursor.
1660 */
1661CINDEX_LINKAGE enum CXAvailabilityKind
1662clang_getCursorAvailability(CXCursor cursor);
1663
1664/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001665 * \brief Describe the "language" of the entity referred to by a cursor.
1666 */
1667CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001668 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001669 CXLanguage_C,
1670 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001671 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001672};
1673
1674/**
1675 * \brief Determine the "language" of the entity referred to by a given cursor.
1676 */
1677CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1678
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001679/**
1680 * \brief Returns the translation unit that a cursor originated from.
1681 */
1682CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
1683
Ted Kremenekeca099b2010-12-08 23:43:14 +00001684
1685/**
1686 * \brief A fast container representing a set of CXCursors.
1687 */
1688typedef struct CXCursorSetImpl *CXCursorSet;
1689
1690/**
1691 * \brief Creates an empty CXCursorSet.
1692 */
1693CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
1694
1695/**
1696 * \brief Disposes a CXCursorSet and releases its associated memory.
1697 */
1698CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
1699
1700/**
1701 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
1702 *
1703 * \returns non-zero if the set contains the specified cursor.
1704*/
1705CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
1706 CXCursor cursor);
1707
1708/**
1709 * \brief Inserts a CXCursor into a CXCursorSet.
1710 *
1711 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
1712*/
1713CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
1714 CXCursor cursor);
1715
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001716/**
1717 * \brief Determine the semantic parent of the given cursor.
1718 *
1719 * The semantic parent of a cursor is the cursor that semantically contains
1720 * the given \p cursor. For many declarations, the lexical and semantic parents
1721 * are equivalent (the lexical parent is returned by
1722 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1723 * definitions are provided out-of-line. For example:
1724 *
1725 * \code
1726 * class C {
1727 * void f();
1728 * };
1729 *
1730 * void C::f() { }
1731 * \endcode
1732 *
1733 * In the out-of-line definition of \c C::f, the semantic parent is the
1734 * the class \c C, of which this function is a member. The lexical parent is
1735 * the place where the declaration actually occurs in the source code; in this
1736 * case, the definition occurs in the translation unit. In general, the
1737 * lexical parent for a given entity can change without affecting the semantics
1738 * of the program, and the lexical parent of different declarations of the
1739 * same entity may be different. Changing the semantic parent of a declaration,
1740 * on the other hand, can have a major impact on semantics, and redeclarations
1741 * of a particular entity should all have the same semantic context.
1742 *
1743 * In the example above, both declarations of \c C::f have \c C as their
1744 * semantic context, while the lexical context of the first \c C::f is \c C
1745 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001746 *
1747 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001748 */
1749CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1750
1751/**
1752 * \brief Determine the lexical parent of the given cursor.
1753 *
1754 * The lexical parent of a cursor is the cursor in which the given \p cursor
1755 * was actually written. For many declarations, the lexical and semantic parents
1756 * are equivalent (the semantic parent is returned by
1757 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1758 * definitions are provided out-of-line. For example:
1759 *
1760 * \code
1761 * class C {
1762 * void f();
1763 * };
1764 *
1765 * void C::f() { }
1766 * \endcode
1767 *
1768 * In the out-of-line definition of \c C::f, the semantic parent is the
1769 * the class \c C, of which this function is a member. The lexical parent is
1770 * the place where the declaration actually occurs in the source code; in this
1771 * case, the definition occurs in the translation unit. In general, the
1772 * lexical parent for a given entity can change without affecting the semantics
1773 * of the program, and the lexical parent of different declarations of the
1774 * same entity may be different. Changing the semantic parent of a declaration,
1775 * on the other hand, can have a major impact on semantics, and redeclarations
1776 * of a particular entity should all have the same semantic context.
1777 *
1778 * In the example above, both declarations of \c C::f have \c C as their
1779 * semantic context, while the lexical context of the first \c C::f is \c C
1780 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001781 *
1782 * For declarations written in the global scope, the lexical parent is
1783 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001784 */
1785CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001786
1787/**
1788 * \brief Determine the set of methods that are overridden by the given
1789 * method.
1790 *
1791 * In both Objective-C and C++, a method (aka virtual member function,
1792 * in C++) can override a virtual method in a base class. For
1793 * Objective-C, a method is said to override any method in the class's
1794 * interface (if we're coming from an implementation), its protocols,
1795 * or its categories, that has the same selector and is of the same
1796 * kind (class or instance). If no such method exists, the search
1797 * continues to the class's superclass, its protocols, and its
1798 * categories, and so on.
1799 *
1800 * For C++, a virtual member function overrides any virtual member
1801 * function with the same signature that occurs in its base
1802 * classes. With multiple inheritance, a virtual member function can
1803 * override several virtual member functions coming from different
1804 * base classes.
1805 *
1806 * In all cases, this function determines the immediate overridden
1807 * method, rather than all of the overridden methods. For example, if
1808 * a method is originally declared in a class A, then overridden in B
1809 * (which in inherits from A) and also in C (which inherited from B),
1810 * then the only overridden method returned from this function when
1811 * invoked on C's method will be B's method. The client may then
1812 * invoke this function again, given the previously-found overridden
1813 * methods, to map out the complete method-override set.
1814 *
1815 * \param cursor A cursor representing an Objective-C or C++
1816 * method. This routine will compute the set of methods that this
1817 * method overrides.
1818 *
1819 * \param overridden A pointer whose pointee will be replaced with a
1820 * pointer to an array of cursors, representing the set of overridden
1821 * methods. If there are no overridden methods, the pointee will be
1822 * set to NULL. The pointee must be freed via a call to
1823 * \c clang_disposeOverriddenCursors().
1824 *
1825 * \param num_overridden A pointer to the number of overridden
1826 * functions, will be set to the number of overridden functions in the
1827 * array pointed to by \p overridden.
1828 */
1829CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1830 CXCursor **overridden,
1831 unsigned *num_overridden);
1832
1833/**
1834 * \brief Free the set of overridden cursors returned by \c
1835 * clang_getOverriddenCursors().
1836 */
1837CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1838
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001839/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001840 * \brief Retrieve the file that is included by the given inclusion directive
1841 * cursor.
1842 */
1843CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1844
1845/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001846 * @}
1847 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001848
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001849/**
1850 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1851 *
1852 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1853 * routines help map between cursors and the physical locations where the
1854 * described entities occur in the source code. The mapping is provided in
1855 * both directions, so one can map from source code to the AST and back.
1856 *
1857 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001858 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001859
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001860/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001861 * \brief Map a source location to the cursor that describes the entity at that
1862 * location in the source code.
1863 *
1864 * clang_getCursor() maps an arbitrary source location within a translation
1865 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001866 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001867 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001868 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001869 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1870 * will return a cursor referring to the "+" expression.
1871 *
1872 * \returns a cursor representing the entity at the given source location, or
1873 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001874 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001875CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001876
Douglas Gregor98258af2010-01-18 22:46:11 +00001877/**
1878 * \brief Retrieve the physical location of the source constructor referenced
1879 * by the given cursor.
1880 *
1881 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001882 * declaration, where the name of that declaration would occur if it is
1883 * unnamed, or some keyword that introduces that particular declaration.
1884 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001885 * source code.
1886 */
1887CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001888
Douglas Gregorb6998662010-01-19 19:34:47 +00001889/**
1890 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001891 * the given cursor.
1892 *
1893 * The extent of a cursor starts with the file/line/column pointing at the
1894 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001895 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001896 * declaration, the extent covers the declaration itself. For a reference,
1897 * the extent covers the location of the reference (e.g., where the referenced
1898 * entity was actually used).
1899 */
1900CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001901
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001902/**
1903 * @}
1904 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001905
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001906/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001907 * \defgroup CINDEX_TYPES Type information for CXCursors
1908 *
1909 * @{
1910 */
1911
1912/**
1913 * \brief Describes the kind of type
1914 */
1915enum CXTypeKind {
1916 /**
1917 * \brief Reprents an invalid type (e.g., where no type is available).
1918 */
1919 CXType_Invalid = 0,
1920
1921 /**
1922 * \brief A type whose specific kind is not exposed via this
1923 * interface.
1924 */
1925 CXType_Unexposed = 1,
1926
1927 /* Builtin types */
1928 CXType_Void = 2,
1929 CXType_Bool = 3,
1930 CXType_Char_U = 4,
1931 CXType_UChar = 5,
1932 CXType_Char16 = 6,
1933 CXType_Char32 = 7,
1934 CXType_UShort = 8,
1935 CXType_UInt = 9,
1936 CXType_ULong = 10,
1937 CXType_ULongLong = 11,
1938 CXType_UInt128 = 12,
1939 CXType_Char_S = 13,
1940 CXType_SChar = 14,
1941 CXType_WChar = 15,
1942 CXType_Short = 16,
1943 CXType_Int = 17,
1944 CXType_Long = 18,
1945 CXType_LongLong = 19,
1946 CXType_Int128 = 20,
1947 CXType_Float = 21,
1948 CXType_Double = 22,
1949 CXType_LongDouble = 23,
1950 CXType_NullPtr = 24,
1951 CXType_Overload = 25,
1952 CXType_Dependent = 26,
1953 CXType_ObjCId = 27,
1954 CXType_ObjCClass = 28,
1955 CXType_ObjCSel = 29,
1956 CXType_FirstBuiltin = CXType_Void,
1957 CXType_LastBuiltin = CXType_ObjCSel,
1958
1959 CXType_Complex = 100,
1960 CXType_Pointer = 101,
1961 CXType_BlockPointer = 102,
1962 CXType_LValueReference = 103,
1963 CXType_RValueReference = 104,
1964 CXType_Record = 105,
1965 CXType_Enum = 106,
1966 CXType_Typedef = 107,
1967 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001968 CXType_ObjCObjectPointer = 109,
1969 CXType_FunctionNoProto = 110,
1970 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001971};
1972
1973/**
1974 * \brief The type of an element in the abstract syntax tree.
1975 *
1976 */
1977typedef struct {
1978 enum CXTypeKind kind;
1979 void *data[2];
1980} CXType;
1981
1982/**
1983 * \brief Retrieve the type of a CXCursor (if any).
1984 */
1985CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1986
1987/**
1988 * \determine Determine whether two CXTypes represent the same type.
1989 *
1990 * \returns non-zero if the CXTypes represent the same type and
1991 zero otherwise.
1992 */
1993CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1994
1995/**
1996 * \brief Return the canonical type for a CXType.
1997 *
1998 * Clang's type system explicitly models typedefs and all the ways
1999 * a specific type can be represented. The canonical type is the underlying
2000 * type with all the "sugar" removed. For example, if 'T' is a typedef
2001 * for 'int', the canonical type for 'T' would be 'int'.
2002 */
2003CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2004
2005/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002006 * \determine Determine whether a CXType has the "const" qualifier set,
2007 * without looking through typedefs that may have added "const" at a different level.
2008 */
2009CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2010
2011/**
2012 * \determine Determine whether a CXType has the "volatile" qualifier set,
2013 * without looking through typedefs that may have added "volatile" at a different level.
2014 */
2015CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2016
2017/**
2018 * \determine Determine whether a CXType has the "restrict" qualifier set,
2019 * without looking through typedefs that may have added "restrict" at a different level.
2020 */
2021CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2022
2023/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002024 * \brief For pointer types, returns the type of the pointee.
2025 *
2026 */
2027CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2028
2029/**
2030 * \brief Return the cursor for the declaration of the given type.
2031 */
2032CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2033
David Chisnall5389f482010-12-30 14:05:53 +00002034/**
2035 * Returns the Objective-C type encoding for the specified declaration.
2036 */
2037CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002038
2039/**
2040 * \brief Retrieve the spelling of a given CXTypeKind.
2041 */
2042CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2043
2044/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002045 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002046 */
2047CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2048
2049/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002050 * \brief Retrieve the result type associated with a given cursor. This only
2051 * returns a valid type of the cursor refers to a function or method.
2052 */
2053CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2054
2055/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002056 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2057 * otherwise.
2058 */
2059CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2060
2061/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002062 * \brief Returns 1 if the base class specified by the cursor with kind
2063 * CX_CXXBaseSpecifier is virtual.
2064 */
2065CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2066
2067/**
2068 * \brief Represents the C++ access control level to a base class for a
2069 * cursor with kind CX_CXXBaseSpecifier.
2070 */
2071enum CX_CXXAccessSpecifier {
2072 CX_CXXInvalidAccessSpecifier,
2073 CX_CXXPublic,
2074 CX_CXXProtected,
2075 CX_CXXPrivate
2076};
2077
2078/**
2079 * \brief Returns the access control level for the C++ base specifier
2080 * represented by a cursor with kind CX_CXXBaseSpecifier.
2081 */
2082CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2083
2084/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002085 * \brief Determine the number of overloaded declarations referenced by a
2086 * \c CXCursor_OverloadedDeclRef cursor.
2087 *
2088 * \param cursor The cursor whose overloaded declarations are being queried.
2089 *
2090 * \returns The number of overloaded declarations referenced by \c cursor. If it
2091 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2092 */
2093CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2094
2095/**
2096 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2097 * by a \c CXCursor_OverloadedDeclRef cursor.
2098 *
2099 * \param cursor The cursor whose overloaded declarations are being queried.
2100 *
2101 * \param index The zero-based index into the set of overloaded declarations in
2102 * the cursor.
2103 *
2104 * \returns A cursor representing the declaration referenced by the given
2105 * \c cursor at the specified \c index. If the cursor does not have an
2106 * associated set of overloaded declarations, or if the index is out of bounds,
2107 * returns \c clang_getNullCursor();
2108 */
2109CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2110 unsigned index);
2111
2112/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002113 * @}
2114 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002115
2116/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002117 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002118 *
2119 * @{
2120 */
2121
2122
2123/**
2124 * \brief For cursors representing an iboutletcollection attribute,
2125 * this function returns the collection element type.
2126 *
2127 */
2128CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2129
2130/**
2131 * @}
2132 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002133
2134/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002135 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2136 *
2137 * These routines provide the ability to traverse the abstract syntax tree
2138 * using cursors.
2139 *
2140 * @{
2141 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002142
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002143/**
2144 * \brief Describes how the traversal of the children of a particular
2145 * cursor should proceed after visiting a particular child cursor.
2146 *
2147 * A value of this enumeration type should be returned by each
2148 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2149 */
2150enum CXChildVisitResult {
2151 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002152 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002153 */
2154 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002155 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002156 * \brief Continues the cursor traversal with the next sibling of
2157 * the cursor just visited, without visiting its children.
2158 */
2159 CXChildVisit_Continue,
2160 /**
2161 * \brief Recursively traverse the children of this cursor, using
2162 * the same visitor and client data.
2163 */
2164 CXChildVisit_Recurse
2165};
2166
2167/**
2168 * \brief Visitor invoked for each cursor found by a traversal.
2169 *
2170 * This visitor function will be invoked for each cursor found by
2171 * clang_visitCursorChildren(). Its first argument is the cursor being
2172 * visited, its second argument is the parent visitor for that cursor,
2173 * and its third argument is the client data provided to
2174 * clang_visitCursorChildren().
2175 *
2176 * The visitor should return one of the \c CXChildVisitResult values
2177 * to direct clang_visitCursorChildren().
2178 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002179typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2180 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002181 CXClientData client_data);
2182
2183/**
2184 * \brief Visit the children of a particular cursor.
2185 *
2186 * This function visits all the direct children of the given cursor,
2187 * invoking the given \p visitor function with the cursors of each
2188 * visited child. The traversal may be recursive, if the visitor returns
2189 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2190 * the visitor returns \c CXChildVisit_Break.
2191 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002192 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002193 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002194 * definition, have no children).
2195 *
2196 * \param visitor the visitor function that will be invoked for each
2197 * child of \p parent.
2198 *
2199 * \param client_data pointer data supplied by the client, which will
2200 * be passed to the visitor each time it is invoked.
2201 *
2202 * \returns a non-zero value if the traversal was terminated
2203 * prematurely by the visitor returning \c CXChildVisit_Break.
2204 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002205CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002206 CXCursorVisitor visitor,
2207 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002208#ifdef __has_feature
2209# if __has_feature(blocks)
2210/**
2211 * \brief Visitor invoked for each cursor found by a traversal.
2212 *
2213 * This visitor block will be invoked for each cursor found by
2214 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2215 * visited, its second argument is the parent visitor for that cursor.
2216 *
2217 * The visitor should return one of the \c CXChildVisitResult values
2218 * to direct clang_visitChildrenWithBlock().
2219 */
2220typedef enum CXChildVisitResult
2221 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2222
2223/**
2224 * Visits the children of a cursor using the specified block. Behaves
2225 * identically to clang_visitChildren() in all other respects.
2226 */
2227unsigned clang_visitChildrenWithBlock(CXCursor parent,
2228 CXCursorVisitorBlock block);
2229# endif
2230#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002231
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002232/**
2233 * @}
2234 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002235
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002236/**
2237 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2238 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002239 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002240 * across translation units, by providing the names of the entities referenced
2241 * by cursors, follow reference cursors to the declarations they reference,
2242 * and associate declarations with their definitions.
2243 *
2244 * @{
2245 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002246
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002247/**
2248 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2249 * by the given cursor.
2250 *
2251 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2252 * entity (function, class, variable, etc.) within a program. USRs can be
2253 * compared across translation units to determine, e.g., when references in
2254 * one translation refer to an entity defined in another translation unit.
2255 */
2256CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2257
2258/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002259 * \brief Construct a USR for a specified Objective-C class.
2260 */
2261CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2262
2263/**
2264 * \brief Construct a USR for a specified Objective-C category.
2265 */
2266CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002267 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002268 const char *category_name);
2269
2270/**
2271 * \brief Construct a USR for a specified Objective-C protocol.
2272 */
2273CINDEX_LINKAGE CXString
2274 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2275
2276
2277/**
2278 * \brief Construct a USR for a specified Objective-C instance variable and
2279 * the USR for its containing class.
2280 */
2281CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2282 CXString classUSR);
2283
2284/**
2285 * \brief Construct a USR for a specified Objective-C method and
2286 * the USR for its containing class.
2287 */
2288CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2289 unsigned isInstanceMethod,
2290 CXString classUSR);
2291
2292/**
2293 * \brief Construct a USR for a specified Objective-C property and the USR
2294 * for its containing class.
2295 */
2296CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2297 CXString classUSR);
2298
2299/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002300 * \brief Retrieve a name for the entity referenced by this cursor.
2301 */
2302CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2303
Douglas Gregor358559d2010-10-02 22:49:11 +00002304/**
2305 * \brief Retrieve the display name for the entity referenced by this cursor.
2306 *
2307 * The display name contains extra information that helps identify the cursor,
2308 * such as the parameters of a function or template or the arguments of a
2309 * class template specialization.
2310 */
2311CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2312
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002313/** \brief For a cursor that is a reference, retrieve a cursor representing the
2314 * entity that it references.
2315 *
2316 * Reference cursors refer to other entities in the AST. For example, an
2317 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002318 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002319 * cursor for the superclass reference. If the input cursor is a declaration or
2320 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002321 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002322 */
2323CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002324
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002325/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002326 * \brief For a cursor that is either a reference to or a declaration
2327 * of some entity, retrieve a cursor that describes the definition of
2328 * that entity.
2329 *
2330 * Some entities can be declared multiple times within a translation
2331 * unit, but only one of those declarations can also be a
2332 * definition. For example, given:
2333 *
2334 * \code
2335 * int f(int, int);
2336 * int g(int x, int y) { return f(x, y); }
2337 * int f(int a, int b) { return a + b; }
2338 * int f(int, int);
2339 * \endcode
2340 *
2341 * there are three declarations of the function "f", but only the
2342 * second one is a definition. The clang_getCursorDefinition()
2343 * function will take any cursor pointing to a declaration of "f"
2344 * (the first or fourth lines of the example) or a cursor referenced
2345 * that uses "f" (the call to "f' inside "g") and will return a
2346 * declaration cursor pointing to the definition (the second "f"
2347 * declaration).
2348 *
2349 * If given a cursor for which there is no corresponding definition,
2350 * e.g., because there is no definition of that entity within this
2351 * translation unit, returns a NULL cursor.
2352 */
2353CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2354
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002355/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002356 * \brief Determine whether the declaration pointed to by this cursor
2357 * is also a definition of that entity.
2358 */
2359CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2360
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002361/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002362 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2363 *
2364 * In the C family of languages, many kinds of entities can be declared several
2365 * times within a single translation unit. For example, a structure type can
2366 * be forward-declared (possibly multiple times) and later defined:
2367 *
2368 * \code
2369 * struct X;
2370 * struct X;
2371 * struct X {
2372 * int member;
2373 * };
2374 * \endcode
2375 *
2376 * The declarations and the definition of \c X are represented by three
2377 * different cursors, all of which are declarations of the same underlying
2378 * entity. One of these cursor is considered the "canonical" cursor, which
2379 * is effectively the representative for the underlying entity. One can
2380 * determine if two cursors are declarations of the same underlying entity by
2381 * comparing their canonical cursors.
2382 *
2383 * \returns The canonical cursor for the entity referred to by the given cursor.
2384 */
2385CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2386
2387/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002388 * @}
2389 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002390
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002391/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002392 * \defgroup CINDEX_CPP C++ AST introspection
2393 *
2394 * The routines in this group provide access information in the ASTs specific
2395 * to C++ language features.
2396 *
2397 * @{
2398 */
2399
2400/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002401 * \brief Determine if a C++ member function or member function template is
2402 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002403 */
2404CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2405
2406/**
Douglas Gregor211924b2011-05-12 15:17:24 +00002407 * \brief Determine if a C++ member function or member function template is
2408 * explicitly declared 'virtual' or if it overrides a virtual method from
2409 * one of the base classes.
2410 */
2411CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2412
2413/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002414 * \brief Given a cursor that represents a template, determine
2415 * the cursor kind of the specializations would be generated by instantiating
2416 * the template.
2417 *
2418 * This routine can be used to determine what flavor of function template,
2419 * class template, or class template partial specialization is stored in the
2420 * cursor. For example, it can describe whether a class template cursor is
2421 * declared with "struct", "class" or "union".
2422 *
2423 * \param C The cursor to query. This cursor should represent a template
2424 * declaration.
2425 *
2426 * \returns The cursor kind of the specializations that would be generated
2427 * by instantiating the template \p C. If \p C is not a template, returns
2428 * \c CXCursor_NoDeclFound.
2429 */
2430CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2431
2432/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002433 * \brief Given a cursor that may represent a specialization or instantiation
2434 * of a template, retrieve the cursor that represents the template that it
2435 * specializes or from which it was instantiated.
2436 *
2437 * This routine determines the template involved both for explicit
2438 * specializations of templates and for implicit instantiations of the template,
2439 * both of which are referred to as "specializations". For a class template
2440 * specialization (e.g., \c std::vector<bool>), this routine will return
2441 * either the primary template (\c std::vector) or, if the specialization was
2442 * instantiated from a class template partial specialization, the class template
2443 * partial specialization. For a class template partial specialization and a
2444 * function template specialization (including instantiations), this
2445 * this routine will return the specialized template.
2446 *
2447 * For members of a class template (e.g., member functions, member classes, or
2448 * static data members), returns the specialized or instantiated member.
2449 * Although not strictly "templates" in the C++ language, members of class
2450 * templates have the same notions of specializations and instantiations that
2451 * templates do, so this routine treats them similarly.
2452 *
2453 * \param C A cursor that may be a specialization of a template or a member
2454 * of a template.
2455 *
2456 * \returns If the given cursor is a specialization or instantiation of a
2457 * template or a member thereof, the template or member that it specializes or
2458 * from which it was instantiated. Otherwise, returns a NULL cursor.
2459 */
2460CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00002461
2462/**
2463 * \brief Given a cursor that references something else, return the source range
2464 * covering that reference.
2465 *
2466 * \param C A cursor pointing to a member reference, a declaration reference, or
2467 * an operator call.
2468 * \param NameFlags A bitset with three independent flags:
2469 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
2470 * CXNameRange_WantSinglePiece.
2471 * \param PieceIndex For contiguous names or when passing the flag
2472 * CXNameRange_WantSinglePiece, only one piece with index 0 is
2473 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
2474 * non-contiguous names, this index can be used to retreive the individual
2475 * pieces of the name. See also CXNameRange_WantSinglePiece.
2476 *
2477 * \returns The piece of the name pointed to by the given cursor. If there is no
2478 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
2479 */
Francois Pichet48a8d142011-07-25 22:00:44 +00002480CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
2481 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00002482 unsigned PieceIndex);
2483
2484enum CXNameRefFlags {
2485 /**
2486 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
2487 * range.
2488 */
2489 CXNameRange_WantQualifier = 0x1,
2490
2491 /**
2492 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
2493 * the range.
2494 */
2495 CXNameRange_WantTemplateArgs = 0x2,
2496
2497 /**
2498 * \brief If the name is non-contiguous, return the full spanning range.
2499 *
2500 * Non-contiguous names occur in Objective-C when a selector with two or more
2501 * parameters is used, or in C++ when using an operator:
2502 * \code
2503 * [object doSomething:here withValue:there]; // ObjC
2504 * return some_vector[1]; // C++
2505 * \endcode
2506 */
2507 CXNameRange_WantSinglePiece = 0x4
2508};
Douglas Gregore0329ac2010-09-02 00:07:54 +00002509
2510/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002511 * @}
2512 */
2513
2514/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002515 * \defgroup CINDEX_LEX Token extraction and manipulation
2516 *
2517 * The routines in this group provide access to the tokens within a
2518 * translation unit, along with a semantic mapping of those tokens to
2519 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002520 *
2521 * @{
2522 */
2523
2524/**
2525 * \brief Describes a kind of token.
2526 */
2527typedef enum CXTokenKind {
2528 /**
2529 * \brief A token that contains some kind of punctuation.
2530 */
2531 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002532
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002533 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002534 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002535 */
2536 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002537
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002538 /**
2539 * \brief An identifier (that is not a keyword).
2540 */
2541 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002542
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002543 /**
2544 * \brief A numeric, string, or character literal.
2545 */
2546 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002547
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002548 /**
2549 * \brief A comment.
2550 */
2551 CXToken_Comment
2552} CXTokenKind;
2553
2554/**
2555 * \brief Describes a single preprocessing token.
2556 */
2557typedef struct {
2558 unsigned int_data[4];
2559 void *ptr_data;
2560} CXToken;
2561
2562/**
2563 * \brief Determine the kind of the given token.
2564 */
2565CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002566
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002567/**
2568 * \brief Determine the spelling of the given token.
2569 *
2570 * The spelling of a token is the textual representation of that token, e.g.,
2571 * the text of an identifier or keyword.
2572 */
2573CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002574
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002575/**
2576 * \brief Retrieve the source location of the given token.
2577 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002578CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002579 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002580
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002581/**
2582 * \brief Retrieve a source range that covers the given token.
2583 */
2584CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2585
2586/**
2587 * \brief Tokenize the source code described by the given range into raw
2588 * lexical tokens.
2589 *
2590 * \param TU the translation unit whose text is being tokenized.
2591 *
2592 * \param Range the source range in which text should be tokenized. All of the
2593 * tokens produced by tokenization will fall within this source range,
2594 *
2595 * \param Tokens this pointer will be set to point to the array of tokens
2596 * that occur within the given source range. The returned pointer must be
2597 * freed with clang_disposeTokens() before the translation unit is destroyed.
2598 *
2599 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2600 * array.
2601 *
2602 */
2603CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2604 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002605
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002606/**
2607 * \brief Annotate the given set of tokens by providing cursors for each token
2608 * that can be mapped to a specific entity within the abstract syntax tree.
2609 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002610 * This token-annotation routine is equivalent to invoking
2611 * clang_getCursor() for the source locations of each of the
2612 * tokens. The cursors provided are filtered, so that only those
2613 * cursors that have a direct correspondence to the token are
2614 * accepted. For example, given a function call \c f(x),
2615 * clang_getCursor() would provide the following cursors:
2616 *
2617 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2618 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2619 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2620 *
2621 * Only the first and last of these cursors will occur within the
2622 * annotate, since the tokens "f" and "x' directly refer to a function
2623 * and a variable, respectively, but the parentheses are just a small
2624 * part of the full syntax of the function call expression, which is
2625 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002626 *
2627 * \param TU the translation unit that owns the given tokens.
2628 *
2629 * \param Tokens the set of tokens to annotate.
2630 *
2631 * \param NumTokens the number of tokens in \p Tokens.
2632 *
2633 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2634 * replaced with the cursors corresponding to each token.
2635 */
2636CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2637 CXToken *Tokens, unsigned NumTokens,
2638 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002639
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002640/**
2641 * \brief Free the given set of tokens.
2642 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002643CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002644 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002645
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002646/**
2647 * @}
2648 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002649
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002650/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002651 * \defgroup CINDEX_DEBUG Debugging facilities
2652 *
2653 * These routines are used for testing and debugging, only, and should not
2654 * be relied upon.
2655 *
2656 * @{
2657 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002658
Steve Naroff4ade6d62009-09-23 17:52:52 +00002659/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002660CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002661CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2662 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002663 const char **endBuf,
2664 unsigned *startLine,
2665 unsigned *startColumn,
2666 unsigned *endLine,
2667 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002668CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00002669CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
2670 unsigned stack_size);
2671
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002672/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002673 * @}
2674 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002675
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002676/**
2677 * \defgroup CINDEX_CODE_COMPLET Code completion
2678 *
2679 * Code completion involves taking an (incomplete) source file, along with
2680 * knowledge of where the user is actively editing that file, and suggesting
2681 * syntactically- and semantically-valid constructs that the user might want to
2682 * use at that particular point in the source code. These data structures and
2683 * routines provide support for code completion.
2684 *
2685 * @{
2686 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002687
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002688/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002689 * \brief A semantic string that describes a code-completion result.
2690 *
2691 * A semantic string that describes the formatting of a code-completion
2692 * result as a single "template" of text that should be inserted into the
2693 * source buffer when a particular code-completion result is selected.
2694 * Each semantic string is made up of some number of "chunks", each of which
2695 * contains some text along with a description of what that text means, e.g.,
2696 * the name of the entity being referenced, whether the text chunk is part of
2697 * the template, or whether it is a "placeholder" that the user should replace
2698 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002699 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002700 */
2701typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002702
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002703/**
2704 * \brief A single result of code completion.
2705 */
2706typedef struct {
2707 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002708 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002709 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002710 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002711 * *Decl cursor kinds), describing the entity that the completion is
2712 * referring to.
2713 *
2714 * \todo In the future, we would like to provide a full cursor, to allow
2715 * the client to extract additional information from declaration.
2716 */
2717 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002718
2719 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002720 * \brief The code-completion string that describes how to insert this
2721 * code-completion result into the editing buffer.
2722 */
2723 CXCompletionString CompletionString;
2724} CXCompletionResult;
2725
2726/**
2727 * \brief Describes a single piece of text within a code-completion string.
2728 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002729 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2730 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002731 * should be interpreted by the client or is another completion string.
2732 */
2733enum CXCompletionChunkKind {
2734 /**
2735 * \brief A code-completion string that describes "optional" text that
2736 * could be a part of the template (but is not required).
2737 *
2738 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002739 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002740 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2741 * describes an additional part of the template that is completely optional.
2742 * For example, optional chunks can be used to describe the placeholders for
2743 * arguments that match up with defaulted function parameters, e.g. given:
2744 *
2745 * \code
2746 * void f(int x, float y = 3.14, double z = 2.71828);
2747 * \endcode
2748 *
2749 * The code-completion string for this function would contain:
2750 * - a TypedText chunk for "f".
2751 * - a LeftParen chunk for "(".
2752 * - a Placeholder chunk for "int x"
2753 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2754 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002755 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002756 * - an Optional chunk containing the last defaulted argument:
2757 * - a Comma chunk for ","
2758 * - a Placeholder chunk for "double z"
2759 * - a RightParen chunk for ")"
2760 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002761 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002762 * - Completely ignore optional chunks, in which case the template for the
2763 * function "f" would only include the first parameter ("int x").
2764 * - Fully expand all optional chunks, in which case the template for the
2765 * function "f" would have all of the parameters.
2766 */
2767 CXCompletionChunk_Optional,
2768 /**
2769 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002770 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002771 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002772 * There will be exactly one "typed text" chunk in a semantic string, which
2773 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002774 * declaration that could be used at the current code point. Clients are
2775 * expected to filter the code-completion results based on the text in this
2776 * chunk.
2777 */
2778 CXCompletionChunk_TypedText,
2779 /**
2780 * \brief Text that should be inserted as part of a code-completion result.
2781 *
2782 * A "text" chunk represents text that is part of the template to be
2783 * inserted into user code should this particular code-completion result
2784 * be selected.
2785 */
2786 CXCompletionChunk_Text,
2787 /**
2788 * \brief Placeholder text that should be replaced by the user.
2789 *
2790 * A "placeholder" chunk marks a place where the user should insert text
2791 * into the code-completion template. For example, placeholders might mark
2792 * the function parameters for a function declaration, to indicate that the
2793 * user should provide arguments for each of those parameters. The actual
2794 * text in a placeholder is a suggestion for the text to display before
2795 * the user replaces the placeholder with real code.
2796 */
2797 CXCompletionChunk_Placeholder,
2798 /**
2799 * \brief Informative text that should be displayed but never inserted as
2800 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002801 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002802 * An "informative" chunk contains annotations that can be displayed to
2803 * help the user decide whether a particular code-completion result is the
2804 * right option, but which is not part of the actual template to be inserted
2805 * by code completion.
2806 */
2807 CXCompletionChunk_Informative,
2808 /**
2809 * \brief Text that describes the current parameter when code-completion is
2810 * referring to function call, message send, or template specialization.
2811 *
2812 * A "current parameter" chunk occurs when code-completion is providing
2813 * information about a parameter corresponding to the argument at the
2814 * code-completion point. For example, given a function
2815 *
2816 * \code
2817 * int add(int x, int y);
2818 * \endcode
2819 *
2820 * and the source code \c add(, where the code-completion point is after the
2821 * "(", the code-completion string will contain a "current parameter" chunk
2822 * for "int x", indicating that the current argument will initialize that
2823 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002824 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002825 * "current paremeter" chunk to "int y".
2826 */
2827 CXCompletionChunk_CurrentParameter,
2828 /**
2829 * \brief A left parenthesis ('('), used to initiate a function call or
2830 * signal the beginning of a function parameter list.
2831 */
2832 CXCompletionChunk_LeftParen,
2833 /**
2834 * \brief A right parenthesis (')'), used to finish a function call or
2835 * signal the end of a function parameter list.
2836 */
2837 CXCompletionChunk_RightParen,
2838 /**
2839 * \brief A left bracket ('[').
2840 */
2841 CXCompletionChunk_LeftBracket,
2842 /**
2843 * \brief A right bracket (']').
2844 */
2845 CXCompletionChunk_RightBracket,
2846 /**
2847 * \brief A left brace ('{').
2848 */
2849 CXCompletionChunk_LeftBrace,
2850 /**
2851 * \brief A right brace ('}').
2852 */
2853 CXCompletionChunk_RightBrace,
2854 /**
2855 * \brief A left angle bracket ('<').
2856 */
2857 CXCompletionChunk_LeftAngle,
2858 /**
2859 * \brief A right angle bracket ('>').
2860 */
2861 CXCompletionChunk_RightAngle,
2862 /**
2863 * \brief A comma separator (',').
2864 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002865 CXCompletionChunk_Comma,
2866 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002867 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002868 *
2869 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002870 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002871 * expression using the given completion string would have.
2872 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002873 CXCompletionChunk_ResultType,
2874 /**
2875 * \brief A colon (':').
2876 */
2877 CXCompletionChunk_Colon,
2878 /**
2879 * \brief A semicolon (';').
2880 */
2881 CXCompletionChunk_SemiColon,
2882 /**
2883 * \brief An '=' sign.
2884 */
2885 CXCompletionChunk_Equal,
2886 /**
2887 * Horizontal space (' ').
2888 */
2889 CXCompletionChunk_HorizontalSpace,
2890 /**
2891 * Vertical space ('\n'), after which it is generally a good idea to
2892 * perform indentation.
2893 */
2894 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002895};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002896
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002897/**
2898 * \brief Determine the kind of a particular chunk within a completion string.
2899 *
2900 * \param completion_string the completion string to query.
2901 *
2902 * \param chunk_number the 0-based index of the chunk in the completion string.
2903 *
2904 * \returns the kind of the chunk at the index \c chunk_number.
2905 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002906CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002907clang_getCompletionChunkKind(CXCompletionString completion_string,
2908 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002909
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002910/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002911 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002912 * completion string.
2913 *
2914 * \param completion_string the completion string to query.
2915 *
2916 * \param chunk_number the 0-based index of the chunk in the completion string.
2917 *
2918 * \returns the text associated with the chunk at index \c chunk_number.
2919 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002920CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002921clang_getCompletionChunkText(CXCompletionString completion_string,
2922 unsigned chunk_number);
2923
2924/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002925 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002926 * within a completion string.
2927 *
2928 * \param completion_string the completion string to query.
2929 *
2930 * \param chunk_number the 0-based index of the chunk in the completion string.
2931 *
2932 * \returns the completion string associated with the chunk at index
2933 * \c chunk_number, or NULL if that chunk is not represented by a completion
2934 * string.
2935 */
2936CINDEX_LINKAGE CXCompletionString
2937clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2938 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002939
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002940/**
2941 * \brief Retrieve the number of chunks in the given code-completion string.
2942 */
2943CINDEX_LINKAGE unsigned
2944clang_getNumCompletionChunks(CXCompletionString completion_string);
2945
2946/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002947 * \brief Determine the priority of this code completion.
2948 *
2949 * The priority of a code completion indicates how likely it is that this
2950 * particular completion is the completion that the user will select. The
2951 * priority is selected by various internal heuristics.
2952 *
2953 * \param completion_string The completion string to query.
2954 *
2955 * \returns The priority of this completion string. Smaller values indicate
2956 * higher-priority (more likely) completions.
2957 */
2958CINDEX_LINKAGE unsigned
2959clang_getCompletionPriority(CXCompletionString completion_string);
2960
2961/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002962 * \brief Determine the availability of the entity that this code-completion
2963 * string refers to.
2964 *
2965 * \param completion_string The completion string to query.
2966 *
2967 * \returns The availability of the completion string.
2968 */
2969CINDEX_LINKAGE enum CXAvailabilityKind
2970clang_getCompletionAvailability(CXCompletionString completion_string);
2971
2972/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00002973 * \brief Retrieve a completion string for an arbitrary declaration or macro
2974 * definition cursor.
2975 *
2976 * \param cursor The cursor to query.
2977 *
2978 * \returns A non-context-sensitive completion string for declaration and macro
2979 * definition cursors, or NULL for other kinds of cursors.
2980 */
2981CINDEX_LINKAGE CXCompletionString
2982clang_getCursorCompletionString(CXCursor cursor);
2983
2984/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002985 * \brief Contains the results of code-completion.
2986 *
2987 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002988 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002989 * \c clang_disposeCodeCompleteResults.
2990 */
2991typedef struct {
2992 /**
2993 * \brief The code-completion results.
2994 */
2995 CXCompletionResult *Results;
2996
2997 /**
2998 * \brief The number of code-completion results stored in the
2999 * \c Results array.
3000 */
3001 unsigned NumResults;
3002} CXCodeCompleteResults;
3003
3004/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003005 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3006 * modify its behavior.
3007 *
3008 * The enumerators in this enumeration can be bitwise-OR'd together to
3009 * provide multiple options to \c clang_codeCompleteAt().
3010 */
3011enum CXCodeComplete_Flags {
3012 /**
3013 * \brief Whether to include macros within the set of code
3014 * completions returned.
3015 */
3016 CXCodeComplete_IncludeMacros = 0x01,
3017
3018 /**
3019 * \brief Whether to include code patterns for language constructs
3020 * within the set of code completions, e.g., for loops.
3021 */
3022 CXCodeComplete_IncludeCodePatterns = 0x02
3023};
3024
3025/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003026 * \brief Bits that represent the context under which completion is occurring.
3027 *
3028 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3029 * contexts are occurring simultaneously.
3030 */
3031enum CXCompletionContext {
3032 /**
3033 * \brief The context for completions is unexposed, as only Clang results
3034 * should be included. (This is equivalent to having no context bits set.)
3035 */
3036 CXCompletionContext_Unexposed = 0,
3037
3038 /**
3039 * \brief Completions for any possible type should be included in the results.
3040 */
3041 CXCompletionContext_AnyType = 1 << 0,
3042
3043 /**
3044 * \brief Completions for any possible value (variables, function calls, etc.)
3045 * should be included in the results.
3046 */
3047 CXCompletionContext_AnyValue = 1 << 1,
3048 /**
3049 * \brief Completions for values that resolve to an Objective-C object should
3050 * be included in the results.
3051 */
3052 CXCompletionContext_ObjCObjectValue = 1 << 2,
3053 /**
3054 * \brief Completions for values that resolve to an Objective-C selector
3055 * should be included in the results.
3056 */
3057 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3058 /**
3059 * \brief Completions for values that resolve to a C++ class type should be
3060 * included in the results.
3061 */
3062 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3063
3064 /**
3065 * \brief Completions for fields of the member being accessed using the dot
3066 * operator should be included in the results.
3067 */
3068 CXCompletionContext_DotMemberAccess = 1 << 5,
3069 /**
3070 * \brief Completions for fields of the member being accessed using the arrow
3071 * operator should be included in the results.
3072 */
3073 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3074 /**
3075 * \brief Completions for properties of the Objective-C object being accessed
3076 * using the dot operator should be included in the results.
3077 */
3078 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3079
3080 /**
3081 * \brief Completions for enum tags should be included in the results.
3082 */
3083 CXCompletionContext_EnumTag = 1 << 8,
3084 /**
3085 * \brief Completions for union tags should be included in the results.
3086 */
3087 CXCompletionContext_UnionTag = 1 << 9,
3088 /**
3089 * \brief Completions for struct tags should be included in the results.
3090 */
3091 CXCompletionContext_StructTag = 1 << 10,
3092
3093 /**
3094 * \brief Completions for C++ class names should be included in the results.
3095 */
3096 CXCompletionContext_ClassTag = 1 << 11,
3097 /**
3098 * \brief Completions for C++ namespaces and namespace aliases should be
3099 * included in the results.
3100 */
3101 CXCompletionContext_Namespace = 1 << 12,
3102 /**
3103 * \brief Completions for C++ nested name specifiers should be included in
3104 * the results.
3105 */
3106 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3107
3108 /**
3109 * \brief Completions for Objective-C interfaces (classes) should be included
3110 * in the results.
3111 */
3112 CXCompletionContext_ObjCInterface = 1 << 14,
3113 /**
3114 * \brief Completions for Objective-C protocols should be included in
3115 * the results.
3116 */
3117 CXCompletionContext_ObjCProtocol = 1 << 15,
3118 /**
3119 * \brief Completions for Objective-C categories should be included in
3120 * the results.
3121 */
3122 CXCompletionContext_ObjCCategory = 1 << 16,
3123 /**
3124 * \brief Completions for Objective-C instance messages should be included
3125 * in the results.
3126 */
3127 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3128 /**
3129 * \brief Completions for Objective-C class messages should be included in
3130 * the results.
3131 */
3132 CXCompletionContext_ObjCClassMessage = 1 << 18,
3133 /**
3134 * \brief Completions for Objective-C selector names should be included in
3135 * the results.
3136 */
3137 CXCompletionContext_ObjCSelectorName = 1 << 19,
3138
3139 /**
3140 * \brief Completions for preprocessor macro names should be included in
3141 * the results.
3142 */
3143 CXCompletionContext_MacroName = 1 << 20,
3144
3145 /**
3146 * \brief Natural language completions should be included in the results.
3147 */
3148 CXCompletionContext_NaturalLanguage = 1 << 21,
3149
3150 /**
3151 * \brief The current context is unknown, so set all contexts.
3152 */
3153 CXCompletionContext_Unknown = ((1 << 22) - 1)
3154};
3155
3156/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003157 * \brief Returns a default set of code-completion options that can be
3158 * passed to\c clang_codeCompleteAt().
3159 */
3160CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3161
3162/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003163 * \brief Perform code completion at a given location in a translation unit.
3164 *
3165 * This function performs code completion at a particular file, line, and
3166 * column within source code, providing results that suggest potential
3167 * code snippets based on the context of the completion. The basic model
3168 * for code completion is that Clang will parse a complete source file,
3169 * performing syntax checking up to the location where code-completion has
3170 * been requested. At that point, a special code-completion token is passed
3171 * to the parser, which recognizes this token and determines, based on the
3172 * current location in the C/Objective-C/C++ grammar and the state of
3173 * semantic analysis, what completions to provide. These completions are
3174 * returned via a new \c CXCodeCompleteResults structure.
3175 *
3176 * Code completion itself is meant to be triggered by the client when the
3177 * user types punctuation characters or whitespace, at which point the
3178 * code-completion location will coincide with the cursor. For example, if \c p
3179 * is a pointer, code-completion might be triggered after the "-" and then
3180 * after the ">" in \c p->. When the code-completion location is afer the ">",
3181 * the completion results will provide, e.g., the members of the struct that
3182 * "p" points to. The client is responsible for placing the cursor at the
3183 * beginning of the token currently being typed, then filtering the results
3184 * based on the contents of the token. For example, when code-completing for
3185 * the expression \c p->get, the client should provide the location just after
3186 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3187 * client can filter the results based on the current token text ("get"), only
3188 * showing those results that start with "get". The intent of this interface
3189 * is to separate the relatively high-latency acquisition of code-completion
3190 * results from the filtering of results on a per-character basis, which must
3191 * have a lower latency.
3192 *
3193 * \param TU The translation unit in which code-completion should
3194 * occur. The source files for this translation unit need not be
3195 * completely up-to-date (and the contents of those source files may
3196 * be overridden via \p unsaved_files). Cursors referring into the
3197 * translation unit may be invalidated by this invocation.
3198 *
3199 * \param complete_filename The name of the source file where code
3200 * completion should be performed. This filename may be any file
3201 * included in the translation unit.
3202 *
3203 * \param complete_line The line at which code-completion should occur.
3204 *
3205 * \param complete_column The column at which code-completion should occur.
3206 * Note that the column should point just after the syntactic construct that
3207 * initiated code completion, and not in the middle of a lexical token.
3208 *
3209 * \param unsaved_files the Tiles that have not yet been saved to disk
3210 * but may be required for parsing or code completion, including the
3211 * contents of those files. The contents and name of these files (as
3212 * specified by CXUnsavedFile) are copied when necessary, so the
3213 * client only needs to guarantee their validity until the call to
3214 * this function returns.
3215 *
3216 * \param num_unsaved_files The number of unsaved file entries in \p
3217 * unsaved_files.
3218 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00003219 * \param options Extra options that control the behavior of code
3220 * completion, expressed as a bitwise OR of the enumerators of the
3221 * CXCodeComplete_Flags enumeration. The
3222 * \c clang_defaultCodeCompleteOptions() function returns a default set
3223 * of code-completion options.
3224 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003225 * \returns If successful, a new \c CXCodeCompleteResults structure
3226 * containing code-completion results, which should eventually be
3227 * freed with \c clang_disposeCodeCompleteResults(). If code
3228 * completion fails, returns NULL.
3229 */
3230CINDEX_LINKAGE
3231CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3232 const char *complete_filename,
3233 unsigned complete_line,
3234 unsigned complete_column,
3235 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00003236 unsigned num_unsaved_files,
3237 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003238
3239/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00003240 * \brief Sort the code-completion results in case-insensitive alphabetical
3241 * order.
3242 *
3243 * \param Results The set of results to sort.
3244 * \param NumResults The number of results in \p Results.
3245 */
3246CINDEX_LINKAGE
3247void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3248 unsigned NumResults);
3249
3250/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003251 * \brief Free the given set of code-completion results.
3252 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003253CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00003254void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00003255
Douglas Gregor20d416c2010-01-20 01:10:47 +00003256/**
Douglas Gregora88084b2010-02-18 18:08:43 +00003257 * \brief Determine the number of diagnostics produced prior to the
3258 * location where code completion was performed.
3259 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003260CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003261unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3262
3263/**
3264 * \brief Retrieve a diagnostic associated with the given code completion.
3265 *
3266 * \param Result the code completion results to query.
3267 * \param Index the zero-based diagnostic number to retrieve.
3268 *
3269 * \returns the requested diagnostic. This diagnostic must be freed
3270 * via a call to \c clang_disposeDiagnostic().
3271 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003272CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003273CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3274 unsigned Index);
3275
3276/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003277 * \brief Determines what compeltions are appropriate for the context
3278 * the given code completion.
3279 *
3280 * \param Results the code completion results to query
3281 *
3282 * \returns the kinds of completions that are appropriate for use
3283 * along with the given code completion results.
3284 */
3285CINDEX_LINKAGE
3286unsigned long long clang_codeCompleteGetContexts(
3287 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00003288
3289/**
3290 * \brief Returns the cursor kind for the container for the current code
3291 * completion context. The container is only guaranteed to be set for
3292 * contexts where a container exists (i.e. member accesses or Objective-C
3293 * message sends); if there is not a container, this function will return
3294 * CXCursor_InvalidCode.
3295 *
3296 * \param Results the code completion results to query
3297 *
3298 * \param IsIncomplete on return, this value will be false if Clang has complete
3299 * information about the container. If Clang does not have complete
3300 * information, this value will be true.
3301 *
3302 * \returns the container kind, or CXCursor_InvalidCode if there is not a
3303 * container
3304 */
3305CINDEX_LINKAGE
3306enum CXCursorKind clang_codeCompleteGetContainerKind(
3307 CXCodeCompleteResults *Results,
3308 unsigned *IsIncomplete);
3309
3310/**
3311 * \brief Returns the USR for the container for the current code completion
3312 * context. If there is not a container for the current context, this
3313 * function will return the empty string.
3314 *
3315 * \param Results the code completion results to query
3316 *
3317 * \returns the USR for the container
3318 */
3319CINDEX_LINKAGE
3320CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00003321
Douglas Gregor0a47d692011-07-26 15:24:30 +00003322
3323/**
3324 * \brief Returns the currently-entered selector for an Objective-C message
3325 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
3326 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
3327 * CXCompletionContext_ObjCClassMessage.
3328 *
3329 * \param Results the code completion results to query
3330 *
3331 * \returns the selector (or partial selector) that has been entered thus far
3332 * for an Objective-C message send.
3333 */
3334CINDEX_LINKAGE
3335CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
3336
Douglas Gregor3da626b2011-07-07 16:03:39 +00003337/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00003338 * @}
3339 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003340
3341
Ted Kremenek04bb7162010-01-22 22:44:15 +00003342/**
3343 * \defgroup CINDEX_MISC Miscellaneous utility functions
3344 *
3345 * @{
3346 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00003347
3348/**
3349 * \brief Return a version string, suitable for showing to a user, but not
3350 * intended to be parsed (the format is not guaranteed to be stable).
3351 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00003352CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00003353
Ted Kremenekd2427dd2011-03-18 23:05:39 +00003354
3355/**
3356 * \brief Enable/disable crash recovery.
3357 *
3358 * \param Flag to indicate if crash recovery is enabled. A non-zero value
3359 * enables crash recovery, while 0 disables it.
3360 */
3361CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
3362
Ted Kremenek16b55a72010-01-26 19:31:51 +00003363 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003364 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00003365 * (used with clang_getInclusions()).
3366 *
3367 * This visitor function will be invoked by clang_getInclusions() for each
3368 * file included (either at the top-level or by #include directives) within
3369 * a translation unit. The first argument is the file being included, and
3370 * the second and third arguments provide the inclusion stack. The
3371 * array is sorted in order of immediate inclusion. For example,
3372 * the first element refers to the location that included 'included_file'.
3373 */
3374typedef void (*CXInclusionVisitor)(CXFile included_file,
3375 CXSourceLocation* inclusion_stack,
3376 unsigned include_len,
3377 CXClientData client_data);
3378
3379/**
3380 * \brief Visit the set of preprocessor inclusions in a translation unit.
3381 * The visitor function is called with the provided data for every included
3382 * file. This does not include headers included by the PCH file (unless one
3383 * is inspecting the inclusions in the PCH file itself).
3384 */
3385CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3386 CXInclusionVisitor visitor,
3387 CXClientData client_data);
3388
3389/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00003390 * @}
3391 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003392
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00003393/** \defgroup CINDEX_REMAPPING Remapping functions
3394 *
3395 * @{
3396 */
3397
3398/**
3399 * \brief A remapping of original source files and their translated files.
3400 */
3401typedef void *CXRemapping;
3402
3403/**
3404 * \brief Retrieve a remapping.
3405 *
3406 * \param path the path that contains metadata about remappings.
3407 *
3408 * \returns the requested remapping. This remapping must be freed
3409 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3410 */
3411CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
3412
3413/**
3414 * \brief Determine the number of remappings.
3415 */
3416CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
3417
3418/**
3419 * \brief Get the original and the associated filename from the remapping.
3420 *
3421 * \param original If non-NULL, will be set to the original filename.
3422 *
3423 * \param transformed If non-NULL, will be set to the filename that the original
3424 * is associated with.
3425 */
3426CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
3427 CXString *original, CXString *transformed);
3428
3429/**
3430 * \brief Dispose the remapping.
3431 */
3432CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
3433
3434/**
3435 * @}
3436 */
3437
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003438/**
3439 * @}
3440 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003441
Ted Kremenekd2fa5662009-08-26 22:36:44 +00003442#ifdef __cplusplus
3443}
3444#endif
3445#endif
3446