blob: fbeb14d365707805927833a35a0f8721ced83c5d [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 */
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +00001560int clang_Cursor_isNull(CXCursor);
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001561
1562/**
Douglas Gregor9ce55842010-11-20 00:09:34 +00001563 * \brief Compute a hash value for the given cursor.
1564 */
1565CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1566
1567/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001568 * \brief Retrieve the kind of the given cursor.
1569 */
1570CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1571
1572/**
1573 * \brief Determine whether the given cursor kind represents a declaration.
1574 */
1575CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
1576
1577/**
1578 * \brief Determine whether the given cursor kind represents a simple
1579 * reference.
1580 *
1581 * Note that other kinds of cursors (such as expressions) can also refer to
1582 * other cursors. Use clang_getCursorReferenced() to determine whether a
1583 * particular cursor refers to another entity.
1584 */
1585CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
1586
1587/**
1588 * \brief Determine whether the given cursor kind represents an expression.
1589 */
1590CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
1591
1592/**
1593 * \brief Determine whether the given cursor kind represents a statement.
1594 */
1595CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
1596
1597/**
Douglas Gregor8be80e12011-07-06 03:00:34 +00001598 * \brief Determine whether the given cursor kind represents an attribute.
1599 */
1600CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
1601
1602/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001603 * \brief Determine whether the given cursor kind represents an invalid
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001604 * cursor.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001605 */
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001606CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
1607
1608/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001609 * \brief Determine whether the given cursor kind represents a translation
1610 * unit.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001611 */
1612CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001613
Ted Kremenekad6eff62010-03-08 21:17:29 +00001614/***
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00001615 * \brief Determine whether the given cursor represents a preprocessing
1616 * element, such as a preprocessor directive or macro instantiation.
1617 */
1618CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
1619
1620/***
Ted Kremenekad6eff62010-03-08 21:17:29 +00001621 * \brief Determine whether the given cursor represents a currently
1622 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
1623 */
1624CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
1625
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001626/**
Ted Kremenek16b42592010-03-03 06:36:57 +00001627 * \brief Describe the linkage of the entity referred to by a cursor.
1628 */
1629enum CXLinkageKind {
1630 /** \brief This value indicates that no linkage information is available
1631 * for a provided CXCursor. */
1632 CXLinkage_Invalid,
1633 /**
1634 * \brief This is the linkage for variables, parameters, and so on that
1635 * have automatic storage. This covers normal (non-extern) local variables.
1636 */
1637 CXLinkage_NoLinkage,
1638 /** \brief This is the linkage for static variables and static functions. */
1639 CXLinkage_Internal,
1640 /** \brief This is the linkage for entities with external linkage that live
1641 * in C++ anonymous namespaces.*/
1642 CXLinkage_UniqueExternal,
1643 /** \brief This is the linkage for entities with true, external linkage. */
1644 CXLinkage_External
1645};
1646
1647/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001648 * \brief Determine the linkage of the entity referred to by a given cursor.
Ted Kremenek16b42592010-03-03 06:36:57 +00001649 */
1650CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
1651
1652/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00001653 * \brief Determine the availability of the entity that this cursor refers to.
1654 *
1655 * \param cursor The cursor to query.
1656 *
1657 * \returns The availability of the cursor.
1658 */
1659CINDEX_LINKAGE enum CXAvailabilityKind
1660clang_getCursorAvailability(CXCursor cursor);
1661
1662/**
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001663 * \brief Describe the "language" of the entity referred to by a cursor.
1664 */
1665CINDEX_LINKAGE enum CXLanguageKind {
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001666 CXLanguage_Invalid = 0,
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001667 CXLanguage_C,
1668 CXLanguage_ObjC,
Ted Kremenek6cd1e7c2010-04-14 20:58:32 +00001669 CXLanguage_CPlusPlus
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001670};
1671
1672/**
1673 * \brief Determine the "language" of the entity referred to by a given cursor.
1674 */
1675CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
1676
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001677/**
1678 * \brief Returns the translation unit that a cursor originated from.
1679 */
1680CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
1681
Ted Kremenekeca099b2010-12-08 23:43:14 +00001682
1683/**
1684 * \brief A fast container representing a set of CXCursors.
1685 */
1686typedef struct CXCursorSetImpl *CXCursorSet;
1687
1688/**
1689 * \brief Creates an empty CXCursorSet.
1690 */
1691CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
1692
1693/**
1694 * \brief Disposes a CXCursorSet and releases its associated memory.
1695 */
1696CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
1697
1698/**
1699 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
1700 *
1701 * \returns non-zero if the set contains the specified cursor.
1702*/
1703CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
1704 CXCursor cursor);
1705
1706/**
1707 * \brief Inserts a CXCursor into a CXCursorSet.
1708 *
1709 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
1710*/
1711CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
1712 CXCursor cursor);
1713
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001714/**
1715 * \brief Determine the semantic parent of the given cursor.
1716 *
1717 * The semantic parent of a cursor is the cursor that semantically contains
1718 * the given \p cursor. For many declarations, the lexical and semantic parents
1719 * are equivalent (the lexical parent is returned by
1720 * \c clang_getCursorLexicalParent()). They diverge when declarations or
1721 * definitions are provided out-of-line. For example:
1722 *
1723 * \code
1724 * class C {
1725 * void f();
1726 * };
1727 *
1728 * void C::f() { }
1729 * \endcode
1730 *
1731 * In the out-of-line definition of \c C::f, the semantic parent is the
1732 * the class \c C, of which this function is a member. The lexical parent is
1733 * the place where the declaration actually occurs in the source code; in this
1734 * case, the definition occurs in the translation unit. In general, the
1735 * lexical parent for a given entity can change without affecting the semantics
1736 * of the program, and the lexical parent of different declarations of the
1737 * same entity may be different. Changing the semantic parent of a declaration,
1738 * on the other hand, can have a major impact on semantics, and redeclarations
1739 * of a particular entity should all have the same semantic context.
1740 *
1741 * In the example above, both declarations of \c C::f have \c C as their
1742 * semantic context, while the lexical context of the first \c C::f is \c C
1743 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001744 *
1745 * For global declarations, the semantic parent is the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001746 */
1747CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
1748
1749/**
1750 * \brief Determine the lexical parent of the given cursor.
1751 *
1752 * The lexical parent of a cursor is the cursor in which the given \p cursor
1753 * was actually written. For many declarations, the lexical and semantic parents
1754 * are equivalent (the semantic parent is returned by
1755 * \c clang_getCursorSemanticParent()). They diverge when declarations or
1756 * definitions are provided out-of-line. For example:
1757 *
1758 * \code
1759 * class C {
1760 * void f();
1761 * };
1762 *
1763 * void C::f() { }
1764 * \endcode
1765 *
1766 * In the out-of-line definition of \c C::f, the semantic parent is the
1767 * the class \c C, of which this function is a member. The lexical parent is
1768 * the place where the declaration actually occurs in the source code; in this
1769 * case, the definition occurs in the translation unit. In general, the
1770 * lexical parent for a given entity can change without affecting the semantics
1771 * of the program, and the lexical parent of different declarations of the
1772 * same entity may be different. Changing the semantic parent of a declaration,
1773 * on the other hand, can have a major impact on semantics, and redeclarations
1774 * of a particular entity should all have the same semantic context.
1775 *
1776 * In the example above, both declarations of \c C::f have \c C as their
1777 * semantic context, while the lexical context of the first \c C::f is \c C
1778 * and the lexical context of the second \c C::f is the translation unit.
Douglas Gregor3910cfd2010-12-21 07:55:45 +00001779 *
1780 * For declarations written in the global scope, the lexical parent is
1781 * the translation unit.
Douglas Gregor2be5bc92010-09-22 21:22:29 +00001782 */
1783CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
Douglas Gregor9f592342010-10-01 20:25:15 +00001784
1785/**
1786 * \brief Determine the set of methods that are overridden by the given
1787 * method.
1788 *
1789 * In both Objective-C and C++, a method (aka virtual member function,
1790 * in C++) can override a virtual method in a base class. For
1791 * Objective-C, a method is said to override any method in the class's
1792 * interface (if we're coming from an implementation), its protocols,
1793 * or its categories, that has the same selector and is of the same
1794 * kind (class or instance). If no such method exists, the search
1795 * continues to the class's superclass, its protocols, and its
1796 * categories, and so on.
1797 *
1798 * For C++, a virtual member function overrides any virtual member
1799 * function with the same signature that occurs in its base
1800 * classes. With multiple inheritance, a virtual member function can
1801 * override several virtual member functions coming from different
1802 * base classes.
1803 *
1804 * In all cases, this function determines the immediate overridden
1805 * method, rather than all of the overridden methods. For example, if
1806 * a method is originally declared in a class A, then overridden in B
1807 * (which in inherits from A) and also in C (which inherited from B),
1808 * then the only overridden method returned from this function when
1809 * invoked on C's method will be B's method. The client may then
1810 * invoke this function again, given the previously-found overridden
1811 * methods, to map out the complete method-override set.
1812 *
1813 * \param cursor A cursor representing an Objective-C or C++
1814 * method. This routine will compute the set of methods that this
1815 * method overrides.
1816 *
1817 * \param overridden A pointer whose pointee will be replaced with a
1818 * pointer to an array of cursors, representing the set of overridden
1819 * methods. If there are no overridden methods, the pointee will be
1820 * set to NULL. The pointee must be freed via a call to
1821 * \c clang_disposeOverriddenCursors().
1822 *
1823 * \param num_overridden A pointer to the number of overridden
1824 * functions, will be set to the number of overridden functions in the
1825 * array pointed to by \p overridden.
1826 */
1827CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
1828 CXCursor **overridden,
1829 unsigned *num_overridden);
1830
1831/**
1832 * \brief Free the set of overridden cursors returned by \c
1833 * clang_getOverriddenCursors().
1834 */
1835CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
1836
Ted Kremenek45e1dae2010-04-12 21:22:16 +00001837/**
Douglas Gregorecdcb882010-10-20 22:00:55 +00001838 * \brief Retrieve the file that is included by the given inclusion directive
1839 * cursor.
1840 */
1841CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
1842
1843/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001844 * @}
1845 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001846
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001847/**
1848 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
1849 *
1850 * Cursors represent a location within the Abstract Syntax Tree (AST). These
1851 * routines help map between cursors and the physical locations where the
1852 * described entities occur in the source code. The mapping is provided in
1853 * both directions, so one can map from source code to the AST and back.
1854 *
1855 * @{
Steve Naroff50398192009-08-28 15:28:48 +00001856 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001857
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001858/**
Douglas Gregorb9790342010-01-22 21:44:22 +00001859 * \brief Map a source location to the cursor that describes the entity at that
1860 * location in the source code.
1861 *
1862 * clang_getCursor() maps an arbitrary source location within a translation
1863 * unit down to the most specific cursor that describes the entity at that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001864 * location. For example, given an expression \c x + y, invoking
Douglas Gregorb9790342010-01-22 21:44:22 +00001865 * clang_getCursor() with a source location pointing to "x" will return the
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001866 * cursor for "x"; similarly for "y". If the cursor points anywhere between
Douglas Gregorb9790342010-01-22 21:44:22 +00001867 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
1868 * will return a cursor referring to the "+" expression.
1869 *
1870 * \returns a cursor representing the entity at the given source location, or
1871 * a NULL cursor if no such entity can be found.
Steve Naroff6a6de8b2009-10-21 13:56:23 +00001872 */
Douglas Gregorb9790342010-01-22 21:44:22 +00001873CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001874
Douglas Gregor98258af2010-01-18 22:46:11 +00001875/**
1876 * \brief Retrieve the physical location of the source constructor referenced
1877 * by the given cursor.
1878 *
1879 * The location of a declaration is typically the location of the name of that
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001880 * declaration, where the name of that declaration would occur if it is
1881 * unnamed, or some keyword that introduces that particular declaration.
1882 * The location of a reference is where that reference occurs within the
Douglas Gregor98258af2010-01-18 22:46:11 +00001883 * source code.
1884 */
1885CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001886
Douglas Gregorb6998662010-01-19 19:34:47 +00001887/**
1888 * \brief Retrieve the physical extent of the source construct referenced by
Douglas Gregora7bde202010-01-19 00:34:46 +00001889 * the given cursor.
1890 *
1891 * The extent of a cursor starts with the file/line/column pointing at the
1892 * first character within the source construct that the cursor refers to and
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00001893 * ends with the last character withinin that source construct. For a
Douglas Gregora7bde202010-01-19 00:34:46 +00001894 * declaration, the extent covers the declaration itself. For a reference,
1895 * the extent covers the location of the reference (e.g., where the referenced
1896 * entity was actually used).
1897 */
1898CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
Douglas Gregorc5d1e932010-01-19 01:20:04 +00001899
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001900/**
1901 * @}
1902 */
Ted Kremenek95f33552010-08-26 01:42:22 +00001903
Douglas Gregorc42fefa2010-01-22 22:29:16 +00001904/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001905 * \defgroup CINDEX_TYPES Type information for CXCursors
1906 *
1907 * @{
1908 */
1909
1910/**
1911 * \brief Describes the kind of type
1912 */
1913enum CXTypeKind {
1914 /**
1915 * \brief Reprents an invalid type (e.g., where no type is available).
1916 */
1917 CXType_Invalid = 0,
1918
1919 /**
1920 * \brief A type whose specific kind is not exposed via this
1921 * interface.
1922 */
1923 CXType_Unexposed = 1,
1924
1925 /* Builtin types */
1926 CXType_Void = 2,
1927 CXType_Bool = 3,
1928 CXType_Char_U = 4,
1929 CXType_UChar = 5,
1930 CXType_Char16 = 6,
1931 CXType_Char32 = 7,
1932 CXType_UShort = 8,
1933 CXType_UInt = 9,
1934 CXType_ULong = 10,
1935 CXType_ULongLong = 11,
1936 CXType_UInt128 = 12,
1937 CXType_Char_S = 13,
1938 CXType_SChar = 14,
1939 CXType_WChar = 15,
1940 CXType_Short = 16,
1941 CXType_Int = 17,
1942 CXType_Long = 18,
1943 CXType_LongLong = 19,
1944 CXType_Int128 = 20,
1945 CXType_Float = 21,
1946 CXType_Double = 22,
1947 CXType_LongDouble = 23,
1948 CXType_NullPtr = 24,
1949 CXType_Overload = 25,
1950 CXType_Dependent = 26,
1951 CXType_ObjCId = 27,
1952 CXType_ObjCClass = 28,
1953 CXType_ObjCSel = 29,
1954 CXType_FirstBuiltin = CXType_Void,
1955 CXType_LastBuiltin = CXType_ObjCSel,
1956
1957 CXType_Complex = 100,
1958 CXType_Pointer = 101,
1959 CXType_BlockPointer = 102,
1960 CXType_LValueReference = 103,
1961 CXType_RValueReference = 104,
1962 CXType_Record = 105,
1963 CXType_Enum = 106,
1964 CXType_Typedef = 107,
1965 CXType_ObjCInterface = 108,
Ted Kremenek04c3cf32010-06-21 20:15:39 +00001966 CXType_ObjCObjectPointer = 109,
1967 CXType_FunctionNoProto = 110,
1968 CXType_FunctionProto = 111
Ted Kremenek8e0ac172010-05-14 21:29:26 +00001969};
1970
1971/**
1972 * \brief The type of an element in the abstract syntax tree.
1973 *
1974 */
1975typedef struct {
1976 enum CXTypeKind kind;
1977 void *data[2];
1978} CXType;
1979
1980/**
1981 * \brief Retrieve the type of a CXCursor (if any).
1982 */
1983CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
1984
1985/**
1986 * \determine Determine whether two CXTypes represent the same type.
1987 *
1988 * \returns non-zero if the CXTypes represent the same type and
1989 zero otherwise.
1990 */
1991CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
1992
1993/**
1994 * \brief Return the canonical type for a CXType.
1995 *
1996 * Clang's type system explicitly models typedefs and all the ways
1997 * a specific type can be represented. The canonical type is the underlying
1998 * type with all the "sugar" removed. For example, if 'T' is a typedef
1999 * for 'int', the canonical type for 'T' would be 'int'.
2000 */
2001CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2002
2003/**
Douglas Gregore72fb6f2011-01-27 16:27:11 +00002004 * \determine Determine whether a CXType has the "const" qualifier set,
2005 * without looking through typedefs that may have added "const" at a different level.
2006 */
2007CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2008
2009/**
2010 * \determine Determine whether a CXType has the "volatile" qualifier set,
2011 * without looking through typedefs that may have added "volatile" at a different level.
2012 */
2013CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2014
2015/**
2016 * \determine Determine whether a CXType has the "restrict" qualifier set,
2017 * without looking through typedefs that may have added "restrict" at a different level.
2018 */
2019CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2020
2021/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002022 * \brief For pointer types, returns the type of the pointee.
2023 *
2024 */
2025CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2026
2027/**
2028 * \brief Return the cursor for the declaration of the given type.
2029 */
2030CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2031
David Chisnall5389f482010-12-30 14:05:53 +00002032/**
2033 * Returns the Objective-C type encoding for the specified declaration.
2034 */
2035CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002036
2037/**
2038 * \brief Retrieve the spelling of a given CXTypeKind.
2039 */
2040CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2041
2042/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002043 * \brief Retrieve the result type associated with a function type.
Ted Kremenek04c3cf32010-06-21 20:15:39 +00002044 */
2045CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2046
2047/**
Ted Kremenek9a140842010-06-21 20:48:56 +00002048 * \brief Retrieve the result type associated with a given cursor. This only
2049 * returns a valid type of the cursor refers to a function or method.
2050 */
2051CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2052
2053/**
Ted Kremenek3ce9e7d2010-07-30 00:14:11 +00002054 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2055 * otherwise.
2056 */
2057CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2058
2059/**
Ted Kremenek3064ef92010-08-27 21:34:58 +00002060 * \brief Returns 1 if the base class specified by the cursor with kind
2061 * CX_CXXBaseSpecifier is virtual.
2062 */
2063CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2064
2065/**
2066 * \brief Represents the C++ access control level to a base class for a
2067 * cursor with kind CX_CXXBaseSpecifier.
2068 */
2069enum CX_CXXAccessSpecifier {
2070 CX_CXXInvalidAccessSpecifier,
2071 CX_CXXPublic,
2072 CX_CXXProtected,
2073 CX_CXXPrivate
2074};
2075
2076/**
2077 * \brief Returns the access control level for the C++ base specifier
2078 * represented by a cursor with kind CX_CXXBaseSpecifier.
2079 */
2080CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2081
2082/**
Douglas Gregor1f60d9e2010-09-13 22:52:57 +00002083 * \brief Determine the number of overloaded declarations referenced by a
2084 * \c CXCursor_OverloadedDeclRef cursor.
2085 *
2086 * \param cursor The cursor whose overloaded declarations are being queried.
2087 *
2088 * \returns The number of overloaded declarations referenced by \c cursor. If it
2089 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2090 */
2091CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2092
2093/**
2094 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2095 * by a \c CXCursor_OverloadedDeclRef cursor.
2096 *
2097 * \param cursor The cursor whose overloaded declarations are being queried.
2098 *
2099 * \param index The zero-based index into the set of overloaded declarations in
2100 * the cursor.
2101 *
2102 * \returns A cursor representing the declaration referenced by the given
2103 * \c cursor at the specified \c index. If the cursor does not have an
2104 * associated set of overloaded declarations, or if the index is out of bounds,
2105 * returns \c clang_getNullCursor();
2106 */
2107CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2108 unsigned index);
2109
2110/**
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002111 * @}
2112 */
Ted Kremenek95f33552010-08-26 01:42:22 +00002113
2114/**
Ted Kremenekad72f4d2010-08-27 21:34:51 +00002115 * \defgroup CINDEX_ATTRIBUTES Information for attributes
Ted Kremenek95f33552010-08-26 01:42:22 +00002116 *
2117 * @{
2118 */
2119
2120
2121/**
2122 * \brief For cursors representing an iboutletcollection attribute,
2123 * this function returns the collection element type.
2124 *
2125 */
2126CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2127
2128/**
2129 * @}
2130 */
Ted Kremenek8e0ac172010-05-14 21:29:26 +00002131
2132/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002133 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2134 *
2135 * These routines provide the ability to traverse the abstract syntax tree
2136 * using cursors.
2137 *
2138 * @{
2139 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002140
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002141/**
2142 * \brief Describes how the traversal of the children of a particular
2143 * cursor should proceed after visiting a particular child cursor.
2144 *
2145 * A value of this enumeration type should be returned by each
2146 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2147 */
2148enum CXChildVisitResult {
2149 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002150 * \brief Terminates the cursor traversal.
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002151 */
2152 CXChildVisit_Break,
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002153 /**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002154 * \brief Continues the cursor traversal with the next sibling of
2155 * the cursor just visited, without visiting its children.
2156 */
2157 CXChildVisit_Continue,
2158 /**
2159 * \brief Recursively traverse the children of this cursor, using
2160 * the same visitor and client data.
2161 */
2162 CXChildVisit_Recurse
2163};
2164
2165/**
2166 * \brief Visitor invoked for each cursor found by a traversal.
2167 *
2168 * This visitor function will be invoked for each cursor found by
2169 * clang_visitCursorChildren(). Its first argument is the cursor being
2170 * visited, its second argument is the parent visitor for that cursor,
2171 * and its third argument is the client data provided to
2172 * clang_visitCursorChildren().
2173 *
2174 * The visitor should return one of the \c CXChildVisitResult values
2175 * to direct clang_visitCursorChildren().
2176 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002177typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2178 CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002179 CXClientData client_data);
2180
2181/**
2182 * \brief Visit the children of a particular cursor.
2183 *
2184 * This function visits all the direct children of the given cursor,
2185 * invoking the given \p visitor function with the cursors of each
2186 * visited child. The traversal may be recursive, if the visitor returns
2187 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2188 * the visitor returns \c CXChildVisit_Break.
2189 *
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002190 * \param parent the cursor whose child may be visited. All kinds of
Daniel Dunbara57259e2010-01-24 04:10:31 +00002191 * cursors can be visited, including invalid cursors (which, by
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002192 * definition, have no children).
2193 *
2194 * \param visitor the visitor function that will be invoked for each
2195 * child of \p parent.
2196 *
2197 * \param client_data pointer data supplied by the client, which will
2198 * be passed to the visitor each time it is invoked.
2199 *
2200 * \returns a non-zero value if the traversal was terminated
2201 * prematurely by the visitor returning \c CXChildVisit_Break.
2202 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002203CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002204 CXCursorVisitor visitor,
2205 CXClientData client_data);
David Chisnall3387c652010-11-03 14:12:26 +00002206#ifdef __has_feature
2207# if __has_feature(blocks)
2208/**
2209 * \brief Visitor invoked for each cursor found by a traversal.
2210 *
2211 * This visitor block will be invoked for each cursor found by
2212 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2213 * visited, its second argument is the parent visitor for that cursor.
2214 *
2215 * The visitor should return one of the \c CXChildVisitResult values
2216 * to direct clang_visitChildrenWithBlock().
2217 */
2218typedef enum CXChildVisitResult
2219 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2220
2221/**
2222 * Visits the children of a cursor using the specified block. Behaves
2223 * identically to clang_visitChildren() in all other respects.
2224 */
2225unsigned clang_visitChildrenWithBlock(CXCursor parent,
2226 CXCursorVisitorBlock block);
2227# endif
2228#endif
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002229
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002230/**
2231 * @}
2232 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002233
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002234/**
2235 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2236 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002237 * These routines provide the ability to determine references within and
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002238 * across translation units, by providing the names of the entities referenced
2239 * by cursors, follow reference cursors to the declarations they reference,
2240 * and associate declarations with their definitions.
2241 *
2242 * @{
2243 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002244
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002245/**
2246 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2247 * by the given cursor.
2248 *
2249 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2250 * entity (function, class, variable, etc.) within a program. USRs can be
2251 * compared across translation units to determine, e.g., when references in
2252 * one translation refer to an entity defined in another translation unit.
2253 */
2254CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2255
2256/**
Ted Kremenek896b70f2010-03-13 02:50:34 +00002257 * \brief Construct a USR for a specified Objective-C class.
2258 */
2259CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2260
2261/**
2262 * \brief Construct a USR for a specified Objective-C category.
2263 */
2264CINDEX_LINKAGE CXString
Ted Kremenek66ccaec2010-03-15 17:38:58 +00002265 clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002266 const char *category_name);
2267
2268/**
2269 * \brief Construct a USR for a specified Objective-C protocol.
2270 */
2271CINDEX_LINKAGE CXString
2272 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2273
2274
2275/**
2276 * \brief Construct a USR for a specified Objective-C instance variable and
2277 * the USR for its containing class.
2278 */
2279CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2280 CXString classUSR);
2281
2282/**
2283 * \brief Construct a USR for a specified Objective-C method and
2284 * the USR for its containing class.
2285 */
2286CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2287 unsigned isInstanceMethod,
2288 CXString classUSR);
2289
2290/**
2291 * \brief Construct a USR for a specified Objective-C property and the USR
2292 * for its containing class.
2293 */
2294CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2295 CXString classUSR);
2296
2297/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002298 * \brief Retrieve a name for the entity referenced by this cursor.
2299 */
2300CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2301
Douglas Gregor358559d2010-10-02 22:49:11 +00002302/**
2303 * \brief Retrieve the display name for the entity referenced by this cursor.
2304 *
2305 * The display name contains extra information that helps identify the cursor,
2306 * such as the parameters of a function or template or the arguments of a
2307 * class template specialization.
2308 */
2309CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2310
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002311/** \brief For a cursor that is a reference, retrieve a cursor representing the
2312 * entity that it references.
2313 *
2314 * Reference cursors refer to other entities in the AST. For example, an
2315 * Objective-C superclass reference cursor refers to an Objective-C class.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002316 * This function produces the cursor for the Objective-C class from the
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002317 * cursor for the superclass reference. If the input cursor is a declaration or
2318 * definition, it returns that declaration or definition unchanged.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002319 * Otherwise, returns the NULL cursor.
Douglas Gregorc5d1e932010-01-19 01:20:04 +00002320 */
2321CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
Douglas Gregorb6998662010-01-19 19:34:47 +00002322
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002323/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002324 * \brief For a cursor that is either a reference to or a declaration
2325 * of some entity, retrieve a cursor that describes the definition of
2326 * that entity.
2327 *
2328 * Some entities can be declared multiple times within a translation
2329 * unit, but only one of those declarations can also be a
2330 * definition. For example, given:
2331 *
2332 * \code
2333 * int f(int, int);
2334 * int g(int x, int y) { return f(x, y); }
2335 * int f(int a, int b) { return a + b; }
2336 * int f(int, int);
2337 * \endcode
2338 *
2339 * there are three declarations of the function "f", but only the
2340 * second one is a definition. The clang_getCursorDefinition()
2341 * function will take any cursor pointing to a declaration of "f"
2342 * (the first or fourth lines of the example) or a cursor referenced
2343 * that uses "f" (the call to "f' inside "g") and will return a
2344 * declaration cursor pointing to the definition (the second "f"
2345 * declaration).
2346 *
2347 * If given a cursor for which there is no corresponding definition,
2348 * e.g., because there is no definition of that entity within this
2349 * translation unit, returns a NULL cursor.
2350 */
2351CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2352
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002353/**
Douglas Gregorb6998662010-01-19 19:34:47 +00002354 * \brief Determine whether the declaration pointed to by this cursor
2355 * is also a definition of that entity.
2356 */
2357CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2358
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002359/**
Douglas Gregor1a9d0502010-11-19 23:44:15 +00002360 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2361 *
2362 * In the C family of languages, many kinds of entities can be declared several
2363 * times within a single translation unit. For example, a structure type can
2364 * be forward-declared (possibly multiple times) and later defined:
2365 *
2366 * \code
2367 * struct X;
2368 * struct X;
2369 * struct X {
2370 * int member;
2371 * };
2372 * \endcode
2373 *
2374 * The declarations and the definition of \c X are represented by three
2375 * different cursors, all of which are declarations of the same underlying
2376 * entity. One of these cursor is considered the "canonical" cursor, which
2377 * is effectively the representative for the underlying entity. One can
2378 * determine if two cursors are declarations of the same underlying entity by
2379 * comparing their canonical cursors.
2380 *
2381 * \returns The canonical cursor for the entity referred to by the given cursor.
2382 */
2383CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2384
2385/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002386 * @}
2387 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002388
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002389/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002390 * \defgroup CINDEX_CPP C++ AST introspection
2391 *
2392 * The routines in this group provide access information in the ASTs specific
2393 * to C++ language features.
2394 *
2395 * @{
2396 */
2397
2398/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002399 * \brief Determine if a C++ member function or member function template is
2400 * declared 'static'.
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002401 */
2402CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2403
2404/**
Douglas Gregor211924b2011-05-12 15:17:24 +00002405 * \brief Determine if a C++ member function or member function template is
2406 * explicitly declared 'virtual' or if it overrides a virtual method from
2407 * one of the base classes.
2408 */
2409CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2410
2411/**
Douglas Gregor49f6f542010-08-31 22:12:17 +00002412 * \brief Given a cursor that represents a template, determine
2413 * the cursor kind of the specializations would be generated by instantiating
2414 * the template.
2415 *
2416 * This routine can be used to determine what flavor of function template,
2417 * class template, or class template partial specialization is stored in the
2418 * cursor. For example, it can describe whether a class template cursor is
2419 * declared with "struct", "class" or "union".
2420 *
2421 * \param C The cursor to query. This cursor should represent a template
2422 * declaration.
2423 *
2424 * \returns The cursor kind of the specializations that would be generated
2425 * by instantiating the template \p C. If \p C is not a template, returns
2426 * \c CXCursor_NoDeclFound.
2427 */
2428CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2429
2430/**
Douglas Gregore0329ac2010-09-02 00:07:54 +00002431 * \brief Given a cursor that may represent a specialization or instantiation
2432 * of a template, retrieve the cursor that represents the template that it
2433 * specializes or from which it was instantiated.
2434 *
2435 * This routine determines the template involved both for explicit
2436 * specializations of templates and for implicit instantiations of the template,
2437 * both of which are referred to as "specializations". For a class template
2438 * specialization (e.g., \c std::vector<bool>), this routine will return
2439 * either the primary template (\c std::vector) or, if the specialization was
2440 * instantiated from a class template partial specialization, the class template
2441 * partial specialization. For a class template partial specialization and a
2442 * function template specialization (including instantiations), this
2443 * this routine will return the specialized template.
2444 *
2445 * For members of a class template (e.g., member functions, member classes, or
2446 * static data members), returns the specialized or instantiated member.
2447 * Although not strictly "templates" in the C++ language, members of class
2448 * templates have the same notions of specializations and instantiations that
2449 * templates do, so this routine treats them similarly.
2450 *
2451 * \param C A cursor that may be a specialization of a template or a member
2452 * of a template.
2453 *
2454 * \returns If the given cursor is a specialization or instantiation of a
2455 * template or a member thereof, the template or member that it specializes or
2456 * from which it was instantiated. Otherwise, returns a NULL cursor.
2457 */
2458CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
Douglas Gregor430d7a12011-07-25 17:48:11 +00002459
2460/**
2461 * \brief Given a cursor that references something else, return the source range
2462 * covering that reference.
2463 *
2464 * \param C A cursor pointing to a member reference, a declaration reference, or
2465 * an operator call.
2466 * \param NameFlags A bitset with three independent flags:
2467 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
2468 * CXNameRange_WantSinglePiece.
2469 * \param PieceIndex For contiguous names or when passing the flag
2470 * CXNameRange_WantSinglePiece, only one piece with index 0 is
2471 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
2472 * non-contiguous names, this index can be used to retreive the individual
2473 * pieces of the name. See also CXNameRange_WantSinglePiece.
2474 *
2475 * \returns The piece of the name pointed to by the given cursor. If there is no
2476 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
2477 */
Francois Pichet48a8d142011-07-25 22:00:44 +00002478CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
2479 unsigned NameFlags,
Douglas Gregor430d7a12011-07-25 17:48:11 +00002480 unsigned PieceIndex);
2481
2482enum CXNameRefFlags {
2483 /**
2484 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
2485 * range.
2486 */
2487 CXNameRange_WantQualifier = 0x1,
2488
2489 /**
2490 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
2491 * the range.
2492 */
2493 CXNameRange_WantTemplateArgs = 0x2,
2494
2495 /**
2496 * \brief If the name is non-contiguous, return the full spanning range.
2497 *
2498 * Non-contiguous names occur in Objective-C when a selector with two or more
2499 * parameters is used, or in C++ when using an operator:
2500 * \code
2501 * [object doSomething:here withValue:there]; // ObjC
2502 * return some_vector[1]; // C++
2503 * \endcode
2504 */
2505 CXNameRange_WantSinglePiece = 0x4
2506};
Douglas Gregore0329ac2010-09-02 00:07:54 +00002507
2508/**
Ted Kremenek9ada39a2010-05-17 20:06:56 +00002509 * @}
2510 */
2511
2512/**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002513 * \defgroup CINDEX_LEX Token extraction and manipulation
2514 *
2515 * The routines in this group provide access to the tokens within a
2516 * translation unit, along with a semantic mapping of those tokens to
2517 * their corresponding cursors.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002518 *
2519 * @{
2520 */
2521
2522/**
2523 * \brief Describes a kind of token.
2524 */
2525typedef enum CXTokenKind {
2526 /**
2527 * \brief A token that contains some kind of punctuation.
2528 */
2529 CXToken_Punctuation,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002530
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002531 /**
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002532 * \brief A language keyword.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002533 */
2534 CXToken_Keyword,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002535
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002536 /**
2537 * \brief An identifier (that is not a keyword).
2538 */
2539 CXToken_Identifier,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002540
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002541 /**
2542 * \brief A numeric, string, or character literal.
2543 */
2544 CXToken_Literal,
Ted Kremenek896b70f2010-03-13 02:50:34 +00002545
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002546 /**
2547 * \brief A comment.
2548 */
2549 CXToken_Comment
2550} CXTokenKind;
2551
2552/**
2553 * \brief Describes a single preprocessing token.
2554 */
2555typedef struct {
2556 unsigned int_data[4];
2557 void *ptr_data;
2558} CXToken;
2559
2560/**
2561 * \brief Determine the kind of the given token.
2562 */
2563CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002564
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002565/**
2566 * \brief Determine the spelling of the given token.
2567 *
2568 * The spelling of a token is the textual representation of that token, e.g.,
2569 * the text of an identifier or keyword.
2570 */
2571CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002572
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002573/**
2574 * \brief Retrieve the source location of the given token.
2575 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002576CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002577 CXToken);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002578
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002579/**
2580 * \brief Retrieve a source range that covers the given token.
2581 */
2582CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
2583
2584/**
2585 * \brief Tokenize the source code described by the given range into raw
2586 * lexical tokens.
2587 *
2588 * \param TU the translation unit whose text is being tokenized.
2589 *
2590 * \param Range the source range in which text should be tokenized. All of the
2591 * tokens produced by tokenization will fall within this source range,
2592 *
2593 * \param Tokens this pointer will be set to point to the array of tokens
2594 * that occur within the given source range. The returned pointer must be
2595 * freed with clang_disposeTokens() before the translation unit is destroyed.
2596 *
2597 * \param NumTokens will be set to the number of tokens in the \c *Tokens
2598 * array.
2599 *
2600 */
2601CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
2602 CXToken **Tokens, unsigned *NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002603
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002604/**
2605 * \brief Annotate the given set of tokens by providing cursors for each token
2606 * that can be mapped to a specific entity within the abstract syntax tree.
2607 *
Douglas Gregor0045e9f2010-01-26 18:31:56 +00002608 * This token-annotation routine is equivalent to invoking
2609 * clang_getCursor() for the source locations of each of the
2610 * tokens. The cursors provided are filtered, so that only those
2611 * cursors that have a direct correspondence to the token are
2612 * accepted. For example, given a function call \c f(x),
2613 * clang_getCursor() would provide the following cursors:
2614 *
2615 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
2616 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
2617 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
2618 *
2619 * Only the first and last of these cursors will occur within the
2620 * annotate, since the tokens "f" and "x' directly refer to a function
2621 * and a variable, respectively, but the parentheses are just a small
2622 * part of the full syntax of the function call expression, which is
2623 * not provided as an annotation.
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002624 *
2625 * \param TU the translation unit that owns the given tokens.
2626 *
2627 * \param Tokens the set of tokens to annotate.
2628 *
2629 * \param NumTokens the number of tokens in \p Tokens.
2630 *
2631 * \param Cursors an array of \p NumTokens cursors, whose contents will be
2632 * replaced with the cursors corresponding to each token.
2633 */
2634CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
2635 CXToken *Tokens, unsigned NumTokens,
2636 CXCursor *Cursors);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002637
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002638/**
2639 * \brief Free the given set of tokens.
2640 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002641CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002642 CXToken *Tokens, unsigned NumTokens);
Ted Kremenek896b70f2010-03-13 02:50:34 +00002643
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002644/**
2645 * @}
2646 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00002647
Douglas Gregorfc8ea232010-01-26 17:06:03 +00002648/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002649 * \defgroup CINDEX_DEBUG Debugging facilities
2650 *
2651 * These routines are used for testing and debugging, only, and should not
2652 * be relied upon.
2653 *
2654 * @{
2655 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002656
Steve Naroff4ade6d62009-09-23 17:52:52 +00002657/* for debug/testing */
Ted Kremeneke68fff62010-02-17 00:41:32 +00002658CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002659CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2660 const char **startBuf,
Steve Naroff4ade6d62009-09-23 17:52:52 +00002661 const char **endBuf,
2662 unsigned *startLine,
2663 unsigned *startColumn,
2664 unsigned *endLine,
2665 unsigned *endColumn);
Douglas Gregor0a812cf2010-02-18 23:07:20 +00002666CINDEX_LINKAGE void clang_enableStackTraces(void);
Daniel Dunbar995aaf92010-11-04 01:26:29 +00002667CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
2668 unsigned stack_size);
2669
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002670/**
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002671 * @}
2672 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002673
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002674/**
2675 * \defgroup CINDEX_CODE_COMPLET Code completion
2676 *
2677 * Code completion involves taking an (incomplete) source file, along with
2678 * knowledge of where the user is actively editing that file, and suggesting
2679 * syntactically- and semantically-valid constructs that the user might want to
2680 * use at that particular point in the source code. These data structures and
2681 * routines provide support for code completion.
2682 *
2683 * @{
2684 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002685
Douglas Gregorc42fefa2010-01-22 22:29:16 +00002686/**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002687 * \brief A semantic string that describes a code-completion result.
2688 *
2689 * A semantic string that describes the formatting of a code-completion
2690 * result as a single "template" of text that should be inserted into the
2691 * source buffer when a particular code-completion result is selected.
2692 * Each semantic string is made up of some number of "chunks", each of which
2693 * contains some text along with a description of what that text means, e.g.,
2694 * the name of the entity being referenced, whether the text chunk is part of
2695 * the template, or whether it is a "placeholder" that the user should replace
2696 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002697 * description of the different kinds of chunks.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002698 */
2699typedef void *CXCompletionString;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002700
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002701/**
2702 * \brief A single result of code completion.
2703 */
2704typedef struct {
2705 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002706 * \brief The kind of entity that this completion refers to.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002707 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002708 * The cursor kind will be a macro, keyword, or a declaration (one of the
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002709 * *Decl cursor kinds), describing the entity that the completion is
2710 * referring to.
2711 *
2712 * \todo In the future, we would like to provide a full cursor, to allow
2713 * the client to extract additional information from declaration.
2714 */
2715 enum CXCursorKind CursorKind;
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002716
2717 /**
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002718 * \brief The code-completion string that describes how to insert this
2719 * code-completion result into the editing buffer.
2720 */
2721 CXCompletionString CompletionString;
2722} CXCompletionResult;
2723
2724/**
2725 * \brief Describes a single piece of text within a code-completion string.
2726 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002727 * Each "chunk" within a code-completion string (\c CXCompletionString) is
2728 * either a piece of text with a specific "kind" that describes how that text
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002729 * should be interpreted by the client or is another completion string.
2730 */
2731enum CXCompletionChunkKind {
2732 /**
2733 * \brief A code-completion string that describes "optional" text that
2734 * could be a part of the template (but is not required).
2735 *
2736 * The Optional chunk is the only kind of chunk that has a code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002737 * string for its representation, which is accessible via
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002738 * \c clang_getCompletionChunkCompletionString(). The code-completion string
2739 * describes an additional part of the template that is completely optional.
2740 * For example, optional chunks can be used to describe the placeholders for
2741 * arguments that match up with defaulted function parameters, e.g. given:
2742 *
2743 * \code
2744 * void f(int x, float y = 3.14, double z = 2.71828);
2745 * \endcode
2746 *
2747 * The code-completion string for this function would contain:
2748 * - a TypedText chunk for "f".
2749 * - a LeftParen chunk for "(".
2750 * - a Placeholder chunk for "int x"
2751 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
2752 * - a Comma chunk for ","
Daniel Dunbar71570182010-02-17 08:07:44 +00002753 * - a Placeholder chunk for "float y"
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002754 * - an Optional chunk containing the last defaulted argument:
2755 * - a Comma chunk for ","
2756 * - a Placeholder chunk for "double z"
2757 * - a RightParen chunk for ")"
2758 *
Daniel Dunbar71570182010-02-17 08:07:44 +00002759 * There are many ways to handle Optional chunks. Two simple approaches are:
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002760 * - Completely ignore optional chunks, in which case the template for the
2761 * function "f" would only include the first parameter ("int x").
2762 * - Fully expand all optional chunks, in which case the template for the
2763 * function "f" would have all of the parameters.
2764 */
2765 CXCompletionChunk_Optional,
2766 /**
2767 * \brief Text that a user would be expected to type to get this
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002768 * code-completion result.
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002769 *
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002770 * There will be exactly one "typed text" chunk in a semantic string, which
2771 * will typically provide the spelling of a keyword or the name of a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002772 * declaration that could be used at the current code point. Clients are
2773 * expected to filter the code-completion results based on the text in this
2774 * chunk.
2775 */
2776 CXCompletionChunk_TypedText,
2777 /**
2778 * \brief Text that should be inserted as part of a code-completion result.
2779 *
2780 * A "text" chunk represents text that is part of the template to be
2781 * inserted into user code should this particular code-completion result
2782 * be selected.
2783 */
2784 CXCompletionChunk_Text,
2785 /**
2786 * \brief Placeholder text that should be replaced by the user.
2787 *
2788 * A "placeholder" chunk marks a place where the user should insert text
2789 * into the code-completion template. For example, placeholders might mark
2790 * the function parameters for a function declaration, to indicate that the
2791 * user should provide arguments for each of those parameters. The actual
2792 * text in a placeholder is a suggestion for the text to display before
2793 * the user replaces the placeholder with real code.
2794 */
2795 CXCompletionChunk_Placeholder,
2796 /**
2797 * \brief Informative text that should be displayed but never inserted as
2798 * part of the template.
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002799 *
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002800 * An "informative" chunk contains annotations that can be displayed to
2801 * help the user decide whether a particular code-completion result is the
2802 * right option, but which is not part of the actual template to be inserted
2803 * by code completion.
2804 */
2805 CXCompletionChunk_Informative,
2806 /**
2807 * \brief Text that describes the current parameter when code-completion is
2808 * referring to function call, message send, or template specialization.
2809 *
2810 * A "current parameter" chunk occurs when code-completion is providing
2811 * information about a parameter corresponding to the argument at the
2812 * code-completion point. For example, given a function
2813 *
2814 * \code
2815 * int add(int x, int y);
2816 * \endcode
2817 *
2818 * and the source code \c add(, where the code-completion point is after the
2819 * "(", the code-completion string will contain a "current parameter" chunk
2820 * for "int x", indicating that the current argument will initialize that
2821 * parameter. After typing further, to \c add(17, (where the code-completion
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002822 * point is after the ","), the code-completion string will contain a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002823 * "current paremeter" chunk to "int y".
2824 */
2825 CXCompletionChunk_CurrentParameter,
2826 /**
2827 * \brief A left parenthesis ('('), used to initiate a function call or
2828 * signal the beginning of a function parameter list.
2829 */
2830 CXCompletionChunk_LeftParen,
2831 /**
2832 * \brief A right parenthesis (')'), used to finish a function call or
2833 * signal the end of a function parameter list.
2834 */
2835 CXCompletionChunk_RightParen,
2836 /**
2837 * \brief A left bracket ('[').
2838 */
2839 CXCompletionChunk_LeftBracket,
2840 /**
2841 * \brief A right bracket (']').
2842 */
2843 CXCompletionChunk_RightBracket,
2844 /**
2845 * \brief A left brace ('{').
2846 */
2847 CXCompletionChunk_LeftBrace,
2848 /**
2849 * \brief A right brace ('}').
2850 */
2851 CXCompletionChunk_RightBrace,
2852 /**
2853 * \brief A left angle bracket ('<').
2854 */
2855 CXCompletionChunk_LeftAngle,
2856 /**
2857 * \brief A right angle bracket ('>').
2858 */
2859 CXCompletionChunk_RightAngle,
2860 /**
2861 * \brief A comma separator (',').
2862 */
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002863 CXCompletionChunk_Comma,
2864 /**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002865 * \brief Text that specifies the result type of a given result.
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002866 *
2867 * This special kind of informative chunk is not meant to be inserted into
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002868 * the text buffer. Rather, it is meant to illustrate the type that an
Douglas Gregorff5ce6e2009-12-18 18:53:37 +00002869 * expression using the given completion string would have.
2870 */
Douglas Gregor01dfea02010-01-10 23:08:15 +00002871 CXCompletionChunk_ResultType,
2872 /**
2873 * \brief A colon (':').
2874 */
2875 CXCompletionChunk_Colon,
2876 /**
2877 * \brief A semicolon (';').
2878 */
2879 CXCompletionChunk_SemiColon,
2880 /**
2881 * \brief An '=' sign.
2882 */
2883 CXCompletionChunk_Equal,
2884 /**
2885 * Horizontal space (' ').
2886 */
2887 CXCompletionChunk_HorizontalSpace,
2888 /**
2889 * Vertical space ('\n'), after which it is generally a good idea to
2890 * perform indentation.
2891 */
2892 CXCompletionChunk_VerticalSpace
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002893};
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002894
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002895/**
2896 * \brief Determine the kind of a particular chunk within a completion string.
2897 *
2898 * \param completion_string the completion string to query.
2899 *
2900 * \param chunk_number the 0-based index of the chunk in the completion string.
2901 *
2902 * \returns the kind of the chunk at the index \c chunk_number.
2903 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002904CINDEX_LINKAGE enum CXCompletionChunkKind
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002905clang_getCompletionChunkKind(CXCompletionString completion_string,
2906 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002907
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002908/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002909 * \brief Retrieve the text associated with a particular chunk within a
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002910 * completion string.
2911 *
2912 * \param completion_string the completion string to query.
2913 *
2914 * \param chunk_number the 0-based index of the chunk in the completion string.
2915 *
2916 * \returns the text associated with the chunk at index \c chunk_number.
2917 */
Ted Kremenek2ef6f8f2010-02-17 01:42:24 +00002918CINDEX_LINKAGE CXString
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002919clang_getCompletionChunkText(CXCompletionString completion_string,
2920 unsigned chunk_number);
2921
2922/**
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002923 * \brief Retrieve the completion string associated with a particular chunk
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002924 * within a completion string.
2925 *
2926 * \param completion_string the completion string to query.
2927 *
2928 * \param chunk_number the 0-based index of the chunk in the completion string.
2929 *
2930 * \returns the completion string associated with the chunk at index
2931 * \c chunk_number, or NULL if that chunk is not represented by a completion
2932 * string.
2933 */
2934CINDEX_LINKAGE CXCompletionString
2935clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
2936 unsigned chunk_number);
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00002937
Douglas Gregor0c8296d2009-11-07 00:00:49 +00002938/**
2939 * \brief Retrieve the number of chunks in the given code-completion string.
2940 */
2941CINDEX_LINKAGE unsigned
2942clang_getNumCompletionChunks(CXCompletionString completion_string);
2943
2944/**
Douglas Gregor12e13132010-05-26 22:00:08 +00002945 * \brief Determine the priority of this code completion.
2946 *
2947 * The priority of a code completion indicates how likely it is that this
2948 * particular completion is the completion that the user will select. The
2949 * priority is selected by various internal heuristics.
2950 *
2951 * \param completion_string The completion string to query.
2952 *
2953 * \returns The priority of this completion string. Smaller values indicate
2954 * higher-priority (more likely) completions.
2955 */
2956CINDEX_LINKAGE unsigned
2957clang_getCompletionPriority(CXCompletionString completion_string);
2958
2959/**
Douglas Gregor58ddb602010-08-23 23:00:57 +00002960 * \brief Determine the availability of the entity that this code-completion
2961 * string refers to.
2962 *
2963 * \param completion_string The completion string to query.
2964 *
2965 * \returns The availability of the completion string.
2966 */
2967CINDEX_LINKAGE enum CXAvailabilityKind
2968clang_getCompletionAvailability(CXCompletionString completion_string);
2969
2970/**
Douglas Gregor8fa0a802011-08-04 20:04:59 +00002971 * \brief Retrieve a completion string for an arbitrary declaration or macro
2972 * definition cursor.
2973 *
2974 * \param cursor The cursor to query.
2975 *
2976 * \returns A non-context-sensitive completion string for declaration and macro
2977 * definition cursors, or NULL for other kinds of cursors.
2978 */
2979CINDEX_LINKAGE CXCompletionString
2980clang_getCursorCompletionString(CXCursor cursor);
2981
2982/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00002983 * \brief Contains the results of code-completion.
2984 *
2985 * This data structure contains the results of code completion, as
Douglas Gregore0cc52e2010-10-11 21:51:20 +00002986 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
Douglas Gregorec6762c2009-12-18 16:20:58 +00002987 * \c clang_disposeCodeCompleteResults.
2988 */
2989typedef struct {
2990 /**
2991 * \brief The code-completion results.
2992 */
2993 CXCompletionResult *Results;
2994
2995 /**
2996 * \brief The number of code-completion results stored in the
2997 * \c Results array.
2998 */
2999 unsigned NumResults;
3000} CXCodeCompleteResults;
3001
3002/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003003 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3004 * modify its behavior.
3005 *
3006 * The enumerators in this enumeration can be bitwise-OR'd together to
3007 * provide multiple options to \c clang_codeCompleteAt().
3008 */
3009enum CXCodeComplete_Flags {
3010 /**
3011 * \brief Whether to include macros within the set of code
3012 * completions returned.
3013 */
3014 CXCodeComplete_IncludeMacros = 0x01,
3015
3016 /**
3017 * \brief Whether to include code patterns for language constructs
3018 * within the set of code completions, e.g., for loops.
3019 */
3020 CXCodeComplete_IncludeCodePatterns = 0x02
3021};
3022
3023/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003024 * \brief Bits that represent the context under which completion is occurring.
3025 *
3026 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3027 * contexts are occurring simultaneously.
3028 */
3029enum CXCompletionContext {
3030 /**
3031 * \brief The context for completions is unexposed, as only Clang results
3032 * should be included. (This is equivalent to having no context bits set.)
3033 */
3034 CXCompletionContext_Unexposed = 0,
3035
3036 /**
3037 * \brief Completions for any possible type should be included in the results.
3038 */
3039 CXCompletionContext_AnyType = 1 << 0,
3040
3041 /**
3042 * \brief Completions for any possible value (variables, function calls, etc.)
3043 * should be included in the results.
3044 */
3045 CXCompletionContext_AnyValue = 1 << 1,
3046 /**
3047 * \brief Completions for values that resolve to an Objective-C object should
3048 * be included in the results.
3049 */
3050 CXCompletionContext_ObjCObjectValue = 1 << 2,
3051 /**
3052 * \brief Completions for values that resolve to an Objective-C selector
3053 * should be included in the results.
3054 */
3055 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3056 /**
3057 * \brief Completions for values that resolve to a C++ class type should be
3058 * included in the results.
3059 */
3060 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3061
3062 /**
3063 * \brief Completions for fields of the member being accessed using the dot
3064 * operator should be included in the results.
3065 */
3066 CXCompletionContext_DotMemberAccess = 1 << 5,
3067 /**
3068 * \brief Completions for fields of the member being accessed using the arrow
3069 * operator should be included in the results.
3070 */
3071 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3072 /**
3073 * \brief Completions for properties of the Objective-C object being accessed
3074 * using the dot operator should be included in the results.
3075 */
3076 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3077
3078 /**
3079 * \brief Completions for enum tags should be included in the results.
3080 */
3081 CXCompletionContext_EnumTag = 1 << 8,
3082 /**
3083 * \brief Completions for union tags should be included in the results.
3084 */
3085 CXCompletionContext_UnionTag = 1 << 9,
3086 /**
3087 * \brief Completions for struct tags should be included in the results.
3088 */
3089 CXCompletionContext_StructTag = 1 << 10,
3090
3091 /**
3092 * \brief Completions for C++ class names should be included in the results.
3093 */
3094 CXCompletionContext_ClassTag = 1 << 11,
3095 /**
3096 * \brief Completions for C++ namespaces and namespace aliases should be
3097 * included in the results.
3098 */
3099 CXCompletionContext_Namespace = 1 << 12,
3100 /**
3101 * \brief Completions for C++ nested name specifiers should be included in
3102 * the results.
3103 */
3104 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3105
3106 /**
3107 * \brief Completions for Objective-C interfaces (classes) should be included
3108 * in the results.
3109 */
3110 CXCompletionContext_ObjCInterface = 1 << 14,
3111 /**
3112 * \brief Completions for Objective-C protocols should be included in
3113 * the results.
3114 */
3115 CXCompletionContext_ObjCProtocol = 1 << 15,
3116 /**
3117 * \brief Completions for Objective-C categories should be included in
3118 * the results.
3119 */
3120 CXCompletionContext_ObjCCategory = 1 << 16,
3121 /**
3122 * \brief Completions for Objective-C instance messages should be included
3123 * in the results.
3124 */
3125 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3126 /**
3127 * \brief Completions for Objective-C class messages should be included in
3128 * the results.
3129 */
3130 CXCompletionContext_ObjCClassMessage = 1 << 18,
3131 /**
3132 * \brief Completions for Objective-C selector names should be included in
3133 * the results.
3134 */
3135 CXCompletionContext_ObjCSelectorName = 1 << 19,
3136
3137 /**
3138 * \brief Completions for preprocessor macro names should be included in
3139 * the results.
3140 */
3141 CXCompletionContext_MacroName = 1 << 20,
3142
3143 /**
3144 * \brief Natural language completions should be included in the results.
3145 */
3146 CXCompletionContext_NaturalLanguage = 1 << 21,
3147
3148 /**
3149 * \brief The current context is unknown, so set all contexts.
3150 */
3151 CXCompletionContext_Unknown = ((1 << 22) - 1)
3152};
3153
3154/**
Douglas Gregorcee235c2010-08-05 09:09:23 +00003155 * \brief Returns a default set of code-completion options that can be
3156 * passed to\c clang_codeCompleteAt().
3157 */
3158CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3159
3160/**
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003161 * \brief Perform code completion at a given location in a translation unit.
3162 *
3163 * This function performs code completion at a particular file, line, and
3164 * column within source code, providing results that suggest potential
3165 * code snippets based on the context of the completion. The basic model
3166 * for code completion is that Clang will parse a complete source file,
3167 * performing syntax checking up to the location where code-completion has
3168 * been requested. At that point, a special code-completion token is passed
3169 * to the parser, which recognizes this token and determines, based on the
3170 * current location in the C/Objective-C/C++ grammar and the state of
3171 * semantic analysis, what completions to provide. These completions are
3172 * returned via a new \c CXCodeCompleteResults structure.
3173 *
3174 * Code completion itself is meant to be triggered by the client when the
3175 * user types punctuation characters or whitespace, at which point the
3176 * code-completion location will coincide with the cursor. For example, if \c p
3177 * is a pointer, code-completion might be triggered after the "-" and then
3178 * after the ">" in \c p->. When the code-completion location is afer the ">",
3179 * the completion results will provide, e.g., the members of the struct that
3180 * "p" points to. The client is responsible for placing the cursor at the
3181 * beginning of the token currently being typed, then filtering the results
3182 * based on the contents of the token. For example, when code-completing for
3183 * the expression \c p->get, the client should provide the location just after
3184 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3185 * client can filter the results based on the current token text ("get"), only
3186 * showing those results that start with "get". The intent of this interface
3187 * is to separate the relatively high-latency acquisition of code-completion
3188 * results from the filtering of results on a per-character basis, which must
3189 * have a lower latency.
3190 *
3191 * \param TU The translation unit in which code-completion should
3192 * occur. The source files for this translation unit need not be
3193 * completely up-to-date (and the contents of those source files may
3194 * be overridden via \p unsaved_files). Cursors referring into the
3195 * translation unit may be invalidated by this invocation.
3196 *
3197 * \param complete_filename The name of the source file where code
3198 * completion should be performed. This filename may be any file
3199 * included in the translation unit.
3200 *
3201 * \param complete_line The line at which code-completion should occur.
3202 *
3203 * \param complete_column The column at which code-completion should occur.
3204 * Note that the column should point just after the syntactic construct that
3205 * initiated code completion, and not in the middle of a lexical token.
3206 *
3207 * \param unsaved_files the Tiles that have not yet been saved to disk
3208 * but may be required for parsing or code completion, including the
3209 * contents of those files. The contents and name of these files (as
3210 * specified by CXUnsavedFile) are copied when necessary, so the
3211 * client only needs to guarantee their validity until the call to
3212 * this function returns.
3213 *
3214 * \param num_unsaved_files The number of unsaved file entries in \p
3215 * unsaved_files.
3216 *
Douglas Gregorcee235c2010-08-05 09:09:23 +00003217 * \param options Extra options that control the behavior of code
3218 * completion, expressed as a bitwise OR of the enumerators of the
3219 * CXCodeComplete_Flags enumeration. The
3220 * \c clang_defaultCodeCompleteOptions() function returns a default set
3221 * of code-completion options.
3222 *
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003223 * \returns If successful, a new \c CXCodeCompleteResults structure
3224 * containing code-completion results, which should eventually be
3225 * freed with \c clang_disposeCodeCompleteResults(). If code
3226 * completion fails, returns NULL.
3227 */
3228CINDEX_LINKAGE
3229CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3230 const char *complete_filename,
3231 unsigned complete_line,
3232 unsigned complete_column,
3233 struct CXUnsavedFile *unsaved_files,
Douglas Gregorcee235c2010-08-05 09:09:23 +00003234 unsigned num_unsaved_files,
3235 unsigned options);
Douglas Gregor1abc6bc2010-08-04 16:47:14 +00003236
3237/**
Douglas Gregor1e5e6682010-08-26 13:48:20 +00003238 * \brief Sort the code-completion results in case-insensitive alphabetical
3239 * order.
3240 *
3241 * \param Results The set of results to sort.
3242 * \param NumResults The number of results in \p Results.
3243 */
3244CINDEX_LINKAGE
3245void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3246 unsigned NumResults);
3247
3248/**
Douglas Gregorec6762c2009-12-18 16:20:58 +00003249 * \brief Free the given set of code-completion results.
3250 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003251CINDEX_LINKAGE
Douglas Gregorec6762c2009-12-18 16:20:58 +00003252void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
Douglas Gregor58ddb602010-08-23 23:00:57 +00003253
Douglas Gregor20d416c2010-01-20 01:10:47 +00003254/**
Douglas Gregora88084b2010-02-18 18:08:43 +00003255 * \brief Determine the number of diagnostics produced prior to the
3256 * location where code completion was performed.
3257 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003258CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003259unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3260
3261/**
3262 * \brief Retrieve a diagnostic associated with the given code completion.
3263 *
3264 * \param Result the code completion results to query.
3265 * \param Index the zero-based diagnostic number to retrieve.
3266 *
3267 * \returns the requested diagnostic. This diagnostic must be freed
3268 * via a call to \c clang_disposeDiagnostic().
3269 */
Ted Kremenek896b70f2010-03-13 02:50:34 +00003270CINDEX_LINKAGE
Douglas Gregora88084b2010-02-18 18:08:43 +00003271CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3272 unsigned Index);
3273
3274/**
Douglas Gregor3da626b2011-07-07 16:03:39 +00003275 * \brief Determines what compeltions are appropriate for the context
3276 * the given code completion.
3277 *
3278 * \param Results the code completion results to query
3279 *
3280 * \returns the kinds of completions that are appropriate for use
3281 * along with the given code completion results.
3282 */
3283CINDEX_LINKAGE
3284unsigned long long clang_codeCompleteGetContexts(
3285 CXCodeCompleteResults *Results);
Douglas Gregore081a612011-07-21 01:05:26 +00003286
3287/**
3288 * \brief Returns the cursor kind for the container for the current code
3289 * completion context. The container is only guaranteed to be set for
3290 * contexts where a container exists (i.e. member accesses or Objective-C
3291 * message sends); if there is not a container, this function will return
3292 * CXCursor_InvalidCode.
3293 *
3294 * \param Results the code completion results to query
3295 *
3296 * \param IsIncomplete on return, this value will be false if Clang has complete
3297 * information about the container. If Clang does not have complete
3298 * information, this value will be true.
3299 *
3300 * \returns the container kind, or CXCursor_InvalidCode if there is not a
3301 * container
3302 */
3303CINDEX_LINKAGE
3304enum CXCursorKind clang_codeCompleteGetContainerKind(
3305 CXCodeCompleteResults *Results,
3306 unsigned *IsIncomplete);
3307
3308/**
3309 * \brief Returns the USR for the container for the current code completion
3310 * context. If there is not a container for the current context, this
3311 * function will return the empty string.
3312 *
3313 * \param Results the code completion results to query
3314 *
3315 * \returns the USR for the container
3316 */
3317CINDEX_LINKAGE
3318CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
Douglas Gregor3da626b2011-07-07 16:03:39 +00003319
Douglas Gregor0a47d692011-07-26 15:24:30 +00003320
3321/**
3322 * \brief Returns the currently-entered selector for an Objective-C message
3323 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
3324 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
3325 * CXCompletionContext_ObjCClassMessage.
3326 *
3327 * \param Results the code completion results to query
3328 *
3329 * \returns the selector (or partial selector) that has been entered thus far
3330 * for an Objective-C message send.
3331 */
3332CINDEX_LINKAGE
3333CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
3334
Douglas Gregor3da626b2011-07-07 16:03:39 +00003335/**
Douglas Gregor20d416c2010-01-20 01:10:47 +00003336 * @}
3337 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003338
3339
Ted Kremenek04bb7162010-01-22 22:44:15 +00003340/**
3341 * \defgroup CINDEX_MISC Miscellaneous utility functions
3342 *
3343 * @{
3344 */
Ted Kremenek23e1ad02010-01-23 17:51:23 +00003345
3346/**
3347 * \brief Return a version string, suitable for showing to a user, but not
3348 * intended to be parsed (the format is not guaranteed to be stable).
3349 */
Ted Kremeneka2a9d6e2010-02-12 22:54:40 +00003350CINDEX_LINKAGE CXString clang_getClangVersion();
Ted Kremenek04bb7162010-01-22 22:44:15 +00003351
Ted Kremenekd2427dd2011-03-18 23:05:39 +00003352
3353/**
3354 * \brief Enable/disable crash recovery.
3355 *
3356 * \param Flag to indicate if crash recovery is enabled. A non-zero value
3357 * enables crash recovery, while 0 disables it.
3358 */
3359CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
3360
Ted Kremenek16b55a72010-01-26 19:31:51 +00003361 /**
Ted Kremenek896b70f2010-03-13 02:50:34 +00003362 * \brief Visitor invoked for each file in a translation unit
Ted Kremenek16b55a72010-01-26 19:31:51 +00003363 * (used with clang_getInclusions()).
3364 *
3365 * This visitor function will be invoked by clang_getInclusions() for each
3366 * file included (either at the top-level or by #include directives) within
3367 * a translation unit. The first argument is the file being included, and
3368 * the second and third arguments provide the inclusion stack. The
3369 * array is sorted in order of immediate inclusion. For example,
3370 * the first element refers to the location that included 'included_file'.
3371 */
3372typedef void (*CXInclusionVisitor)(CXFile included_file,
3373 CXSourceLocation* inclusion_stack,
3374 unsigned include_len,
3375 CXClientData client_data);
3376
3377/**
3378 * \brief Visit the set of preprocessor inclusions in a translation unit.
3379 * The visitor function is called with the provided data for every included
3380 * file. This does not include headers included by the PCH file (unless one
3381 * is inspecting the inclusions in the PCH file itself).
3382 */
3383CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3384 CXInclusionVisitor visitor,
3385 CXClientData client_data);
3386
3387/**
Ted Kremenek04bb7162010-01-22 22:44:15 +00003388 * @}
3389 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003390
Argyrios Kyrtzidis97c337c2011-07-11 20:15:00 +00003391/** \defgroup CINDEX_REMAPPING Remapping functions
3392 *
3393 * @{
3394 */
3395
3396/**
3397 * \brief A remapping of original source files and their translated files.
3398 */
3399typedef void *CXRemapping;
3400
3401/**
3402 * \brief Retrieve a remapping.
3403 *
3404 * \param path the path that contains metadata about remappings.
3405 *
3406 * \returns the requested remapping. This remapping must be freed
3407 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3408 */
3409CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
3410
3411/**
3412 * \brief Determine the number of remappings.
3413 */
3414CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
3415
3416/**
3417 * \brief Get the original and the associated filename from the remapping.
3418 *
3419 * \param original If non-NULL, will be set to the original filename.
3420 *
3421 * \param transformed If non-NULL, will be set to the filename that the original
3422 * is associated with.
3423 */
3424CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
3425 CXString *original, CXString *transformed);
3426
3427/**
3428 * \brief Dispose the remapping.
3429 */
3430CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
3431
3432/**
3433 * @}
3434 */
3435
Douglas Gregorc42fefa2010-01-22 22:29:16 +00003436/**
3437 * @}
3438 */
Daniel Dunbar1efcf3d2010-01-24 02:54:26 +00003439
Ted Kremenekd2fa5662009-08-26 22:36:44 +00003440#ifdef __cplusplus
3441}
3442#endif
3443#endif
3444