Index.h revision c42fefa51f7555bb3644a7cde2ca4bfd0d848d74
1d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
3d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                     The LLVM Compiler Infrastructure                       *|
4d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
5d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This file is distributed under the University of Illinois Open Source      *|
6d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* License. See LICENSE.TXT for details.                                      *|
7d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
8d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*===----------------------------------------------------------------------===*|
9d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
10d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This header provides a public inferface to a Clang library for extracting  *|
11d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* high-level symbol information from source files without exposing the full  *|
12d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* Clang C++ API.                                                             *|
13d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
14d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek\*===----------------------------------------------------------------------===*/
15d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
16d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifndef CLANG_C_INDEX_H
17d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#define CLANG_C_INDEX_H
18d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
1988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff#include <sys/stat.h>
203d31560343856c573376a04558a7111e7afad4f7Chandler Carruth#include <time.h>
2188145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
22d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
23d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenekextern "C" {
24d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
25d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
2688145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/* MSVC DLL import/export. */
272e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#ifdef _MSC_VER
282e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #ifdef _CINDEX_LIB_
292e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllexport)
302e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #else
312e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllimport)
322e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #endif
332e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#else
342e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #define CINDEX_LINKAGE
352e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#endif
362e06fc877a633abea3b40a64950c7316dac29ca8John Thompson
3720d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/** \defgroup CINDEX C Interface to Clang
3820d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor *
39f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * The C Interface to Clang provides a relatively small API that exposes
40f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities for parsing source code into an abstract syntax tree (AST),
41f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * loading already-parsed ASTs, traversing the AST, associating
42f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * physical source locations with elements within the AST, and other
43f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities that support Clang-based development tools.
44f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
45f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * This C interface to Clang will never provide all of the information
46f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * representation stored in Clang's C++ AST, nor should it: the intent is to
47f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * maintain an API that is relatively stable from one release to the next,
48f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * providing only the basic functionality needed to support development tools.
49f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
50f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * To avoid namespace pollution, data types are prefixed with "CX" and
51f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * functions are prefixed with "clang_".
5220d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor *
5320d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @{
5420d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */
557f17376e0931a337d544b75d9030bc92763be287Douglas Gregor
567f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
577f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief An "index" that consists of a set of translation units that would
587f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * typically be linked together into an executable or library.
597f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
607f17376e0931a337d544b75d9030bc92763be287Douglas Gregortypedef void *CXIndex;
61600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
627f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
637f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A single translation unit, which resides in an index.
647f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
6550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXTranslationUnit;  /* A translation unit instance. */
66600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
677f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
68c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Opaque pointer representing client data that will be passed through
69c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to various callbacks and visitors.
707f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
71c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef void *CXClientData;
72c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
73735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor/**
74735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief Provides the contents of a file that has not yet been saved to disk.
75735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
76735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * Each CXUnsavedFile instance provides the name of a file on the
77735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * system along with the current contents of that file that have not
78735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * yet been saved to disk.
79735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */
80735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregorstruct CXUnsavedFile {
81735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
82735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief The file whose contents have not yet been saved.
83735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   *
84735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * This file must already exist in the file system.
85735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
86735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Filename;
87735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
88735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
89735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief A null-terminated buffer containing the unsaved contents
90735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * of this file.
91735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
92735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Contents;
93735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
94735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
95735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief The length of the unsaved contents of this buffer, not
96735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * counting the NULL at the end of the buffer.
97735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
98735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  unsigned long Length;
99735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor};
100735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
1017f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1027f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \defgroup CINDEX_STRING String manipulation routines
1037f17376e0931a337d544b75d9030bc92763be287Douglas Gregor *
1047f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @{
1057f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
1067f17376e0931a337d544b75d9030bc92763be287Douglas Gregor
1077f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1087f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A character string.
1097f17376e0931a337d544b75d9030bc92763be287Douglas Gregor *
1107f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * The \c CXString type is used to return strings from the interface when
1117f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * the ownership of that string might different from one call to the next.
1127f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * Use \c clang_getCString() to retrieve the string data and, once finished
1137f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * with the string data, call \c clang_disposeString() to free the string.
114ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */
115ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct {
116ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  const char *Spelling;
117ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  /* A 1 value indicates the clang_ indexing API needed to allocate the string
118ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff     (and it must be freed by clang_disposeString()). */
119ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  int MustFreeString;
120ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString;
121ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1227f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1237f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Retrieve the character data associated with the given string.
1247f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
125ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string);
126ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1277f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1287f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Free the given string,
1297f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
130ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string);
131ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1327f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1337f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @}
1347f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
1357f17376e0931a337d544b75d9030bc92763be287Douglas Gregor
136e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/**
137e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating
138e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options:
139e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
140e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
141e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration
142e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * is one that belongs in the translation unit itself and not in a precompiled
143e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations
144e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated.
145e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
146e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - displayDiagnostics: when non-zero, diagnostics will be output. If zero,
147e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * diagnostics will be ignored.
148b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
149b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example:
150b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
151b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // excludeDeclsFromPCH = 1, displayDiagnostics = 1
152b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   Idx = clang_createIndex(1, 1);
153b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
154b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // IndexTest.pch was produced with the following command:
155b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
156b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
157b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
158b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.pch'
159b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
160002a528ab0189fc60cfbf9328962c96ccbe567eeDouglas Gregor *                       TranslationUnitVisitor, 0);
161b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
162b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
163b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.c', excluding symbols
164b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // from 'IndexTest.pch'.
165b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch", 0 };
166b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args);
167b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
168b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *                       TranslationUnitVisitor, 0);
169b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
170b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
171b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via
172b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
173b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler).
174e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
1752e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
176e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff                          int displayDiagnostics);
1778506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
1788506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXString
1798506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbarclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1808506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar
1817f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1828506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \brief Request that AST's be generated external for API calls which parse
1838506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
1848506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
1858506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later
1868506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date.
1878506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
1888506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update.
1898506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value.
1908506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */
1918506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
1928506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                                      int value);
193af08ddc8f1c53fed8d8d0ad82aa2a0bb7d654bd1Steve Naroff
1947f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
195e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Create a translation unit from an AST file (-emit-ast).
196e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
1972e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
198e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  CXIndex, const char *ast_filename
199600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff);
2008506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar
2011374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
2021374598619f83e6b2de91341a326eae564ece2cbTed Kremenek * \brief Destroy the specified CXTranslationUnit object.
2031374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
2042e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
2051374598619f83e6b2de91341a326eae564ece2cbTed Kremenek
2061374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
207e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Return the CXTranslationUnit for a given source file and the provided
208e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * command line arguments one would pass to the compiler.
209e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
2108506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: The 'source_filename' argument is optional.  If the caller provides a
2118506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * NULL pointer, the name of the source file is expected to reside in the
2128506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * specified command line arguments.
213139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
2148506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: When encountered in 'clang_command_line_args', the following options
2158506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * are ignored:
216139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
217139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-c'
218139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-emit-ast'
219139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-fsyntax-only'
220139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
221139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
2228506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2238506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename - The name of the source file to load, or NULL if the
2248506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in clang_command_line_args.
2251374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
2262e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
2278506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  CXIndex CIdx,
2288506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  const char *source_filename,
2295b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff  int num_clang_command_line_args,
230e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  const char **clang_command_line_args
2315b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff);
232600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
233f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
234c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_FILES File manipulation routines
235f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
236f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{
237f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
238f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
239f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
240f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief A particular source file that is part of a translation unit.
241f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
242f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregortypedef void *CXFile;
243f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
244f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
245f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
246f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the complete file and path name of the given file.
24788145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */
24808b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE const char *clang_getFileName(CXFile SFile);
249f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
250f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
251f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the last modification time of the given file.
252f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
25308b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
25488145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
2553c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/**
256b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a file handle within the given translation unit.
257b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
258b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param tu the translation unit
259b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
260b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param file_name the name of the file.
261b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
262b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns the file handle for the named file in the translation unit \p tu,
263b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * or a NULL file handle if the file was not a part of this translation unit.
264b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
265b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
266b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                    const char *file_name);
267b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor
268b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
269f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @}
270f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
271f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
272f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
273f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \defgroup CINDEX_LOCATIONS Physical source locations
274f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
275f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * Clang represents physical source locations in its abstract syntax tree in
276f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * great detail, with file, line, and column information for the majority of
277f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * the tokens parsed in the source code. These data types and functions are
278f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * used to represent source location information, either for a particular
279f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * point in the program or for a range of points in the program, and extract
280f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * specific location information from those data types.
281f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
282f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{
283f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
284f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
285f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
2861db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a specific source location within a translation
2871db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * unit.
2881db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
2891db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getInstantiationLocation() to map a source location to a
2901db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * particular file, line, and column.
2913c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */
2923c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct {
2931db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  void *ptr_data;
2941db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned int_data;
2953c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceLocation;
296fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
2973c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/**
2981db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a range of source locations in the source code.
2993c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor *
3001db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
3011db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * starting and end locations from a source range, respectively.
3023c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */
3033c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct {
3041db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  void *ptr_data;
3051db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned begin_int_data;
3061db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned end_int_data;
3073c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceRange;
308fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
3091db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
310b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a NULL (invalid) source location.
311b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
312b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
313b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor
314b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
315b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \determine Determine whether two source locations, which must refer into
316b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * the same translation unit, refer to exactly the same point in the source
317b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * code.
318b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
319b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns non-zero if the source locations refer to the same location, zero
320b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * if they refer to different locations.
321b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
322b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
323b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                             CXSourceLocation loc2);
324b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor
325b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
326b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieves the source location associated with a given
327b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * file/line/column in a particular translation unit.
328b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
329b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
330b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  CXFile file,
331b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  unsigned line,
332b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  unsigned column);
333b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor
334b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
335b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a source range given the beginning and ending source
336b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * locations.
337b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
338b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
339b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                            CXSourceLocation end);
340b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor
341b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
3421db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Retrieve the file, line, and column represented by the
3431db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * given source location.
3441db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3451db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \param location the location within a source file that will be
3461db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * decomposed into its parts.
3471db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3481db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \param file if non-NULL, will be set to the file to which the given
3491db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points.
3501db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3511db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \param line if non-NULL, will be set to the line to which the given
3521db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points.
3531db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3541db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \param column if non-NULL, will be set to the column to which the
3551db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * given source location points.
3561db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3571db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
3581db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   CXFile *file,
3591db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   unsigned *line,
3601db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   unsigned *column);
3611db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
3621db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
3631db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Retrieve a source location representing the first
3641db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * character within a source range.
3651db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3661db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
3671db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
3681db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
3691db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Retrieve a source location representing the last
3701db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * character within a source range.
3711db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3721db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
3731db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
374f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
375f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @}
376f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
377c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
378c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
379c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes the kind of entity that a cursor refers to.
380c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
381c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXCursorKind {
382c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Declarations */
383c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstDecl                     = 1,
384c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
385c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A declaration whose specific kind is not exposed via this
386c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * interface.
387c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
388c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed declarations have the same operations as any other kind
389c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of declaration; one can extract their location information,
390c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * spelling, find their definitions, etc. However, the specific kind
391c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of the declaration is not reported.
392c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
393c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedDecl                 = 1,
394c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C or C++ struct. */
395c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_StructDecl                    = 2,
396c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C or C++ union. */
397c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnionDecl                     = 3,
398c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C++ class. */
399c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ClassDecl                     = 4,
400c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An enumeration. */
401c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_EnumDecl                      = 5,
402c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
403c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A field (in C) or non-static data member (in C++) in a
404c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * struct, union, or C++ class.
405c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
406c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FieldDecl                     = 6,
407c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An enumerator constant. */
408c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_EnumConstantDecl              = 7,
409c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A function. */
410c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FunctionDecl                  = 8,
411c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A variable. */
412c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_VarDecl                       = 9,
413c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A function or method parameter. */
414c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ParmDecl                      = 10,
415c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @interface. */
416c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCInterfaceDecl             = 11,
417c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @interface for a category. */
418c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCCategoryDecl              = 12,
419c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @protocol declaration. */
420c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCProtocolDecl              = 13,
421c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @property declaration. */
422c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCPropertyDecl              = 14,
423c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C instance variable. */
424c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCIvarDecl                  = 15,
425c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C instance method. */
426c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCInstanceMethodDecl        = 16,
427c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C class method. */
428c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCClassMethodDecl           = 17,
429c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @implementation. */
430c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCImplementationDecl        = 18,
431c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @implementation for a category. */
432c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCCategoryImplDecl          = 19,
433c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A typedef */
434c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TypedefDecl                   = 20,
435c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastDecl                      = 20,
436c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
437c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* References */
438c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstRef                      = 40, /* Decl references */
439c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCSuperClassRef             = 40,
440c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCProtocolRef               = 41,
441c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCClassRef                  = 42,
442c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
443c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A reference to a type declaration.
444c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
445c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * A type reference occurs anywhere where a type is named but not
446c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * declared. For example, given:
447c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
448c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \code
449c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * typedef unsigned size_type;
450c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * size_type size;
451c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \endcode
452c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
453c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
454c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * while the type of the variable "size" is referenced. The cursor
455c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * referenced by the type of size is the typedef for size_type.
456c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
457c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TypeRef                       = 43,
458c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastRef                       = 43,
459c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
460c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Error conditions */
461c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstInvalid                  = 70,
462c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_InvalidFile                   = 70,
463c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_NoDeclFound                   = 71,
464c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_NotImplemented                = 72,
465c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastInvalid                   = 72,
466c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
467c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Expressions */
468c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstExpr                     = 100,
469c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
470c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
471c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression whose specific kind is not exposed via this
472c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * interface.
473c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
474c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed expressions have the same operations as any other kind
475c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of expression; one can extract their location information,
476c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * spelling, children, etc. However, the specific kind of the
477c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * expression is not reported.
478c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
479c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedExpr                 = 100,
480c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
481c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
482c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression that refers to some value declaration, such
483c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * as a function, varible, or enumerator.
484c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
485c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_DeclRefExpr                   = 101,
486c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
487c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
488c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression that refers to a member of a struct, union,
489c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * class, Objective-C class, etc.
490c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
491c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_MemberRefExpr                 = 102,
492c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
493c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An expression that calls a function. */
494c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_CallExpr                      = 103,
495c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
496c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An expression that sends a message to an Objective-C
497c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   object or class. */
498c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCMessageExpr               = 104,
499c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastExpr                      = 104,
500c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
501c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Statements */
502c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstStmt                     = 200,
503c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
504c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A statement whose specific kind is not exposed via this
505c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * interface.
506c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
507c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed statements have the same operations as any other kind of
508c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * statement; one can extract their location information, spelling,
509c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * children, etc. However, the specific kind of the statement is not
510c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * reported.
511c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
512c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedStmt                 = 200,
513c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastStmt                      = 200,
514c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
515c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
516c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Cursor that represents the translation unit itself.
517c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
518c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * The translation unit cursor exists primarily to act as the root
519c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * cursor for traversing the contents of a translation unit.
520c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
521c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TranslationUnit               = 300
522c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor};
523c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
524c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
525c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A cursor representing some element in the abstract syntax tree for
526c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a translation unit.
527c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
528c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The cursor abstraction unifies the different kinds of entities in a
529c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * program--declaration, statements, expressions, references to declarations,
530c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * etc.--under a single "cursor" abstraction with a common set of operations.
531c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Common operation for a cursor include: getting the physical location in
532c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a source file where the cursor points, getting the name associated with a
533c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor, and retrieving cursors for any child nodes of a particular cursor.
534c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
535c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors can be produced in two specific ways.
536c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
537c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * from which one can use clang_visitChildren() to explore the rest of the
538c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * translation unit. clang_getCursor() maps from a physical source location
539c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to the entity that resides at that location, allowing one to map from the
540c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * source code into the AST.
541c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
542c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef struct {
543c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  enum CXCursorKind kind;
544c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  void *data[3];
545c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor} CXCursor;
546c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
547c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
548c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
549c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
550c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
551c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
552c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
553c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
554c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the NULL cursor, which represents no entity.
555c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
556c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getNullCursor(void);
557c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
558c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
559c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the cursor that represents the given translation unit.
560c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
561c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor can be used to start traversing the
562c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * various declarations within the given translation unit.
563c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
564c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
565c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
566c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
567c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether two cursors are equivalent.
568c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
569c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
570c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
571c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
572c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the kind of the given cursor.
573c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
574c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
575c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
576c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
577c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a declaration.
578c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
579c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
580c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
581c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
582c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a simple
583c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reference.
584c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
585c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Note that other kinds of cursors (such as expressions) can also refer to
586c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * other cursors. Use clang_getCursorReferenced() to determine whether a
587c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * particular cursor refers to another entity.
588c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
589c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
590c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
591c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
592c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents an expression.
593c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
594c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
595c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
596c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
597c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a statement.
598c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
599c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
600c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
601c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
602c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents an invalid
603c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor.
604c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
605c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
606c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
607c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
608c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a translation
609c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * unit.
610c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
611c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
612c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
613c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
614c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
615c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
616f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
617c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
618c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
619c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
620c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors represent a location within the Abstract Syntax Tree (AST). These
621c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines help map between cursors and the physical locations where the
622c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * described entities occur in the source code. The mapping is provided in
623c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * both directions, so one can map from source code to the AST and back.
624c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
625c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
62650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
627b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor
6286a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
629b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Map a source location to the cursor that describes the entity at that
630b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * location in the source code.
631b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
632b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() maps an arbitrary source location within a translation
633b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * unit down to the most specific cursor that describes the entity at that
634b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * location. For example, given an expression \c x + y, invoking
635b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() with a source location pointing to "x" will return the
636b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * cursor for "x"; similarly for "y". If the cursor points anywhere between
637b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
638b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * will return a cursor referring to the "+" expression.
639b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
640b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns a cursor representing the entity at the given source location, or
641b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * a NULL cursor if no such entity can be found.
6426a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
643b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
644c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
64598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor/**
64698258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * \brief Retrieve the physical location of the source constructor referenced
64798258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * by the given cursor.
64898258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor *
64998258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * The location of a declaration is typically the location of the name of that
65098258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * declaration, where the name of that declaration would occur if it is
65198258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * unnamed, or some keyword that introduces that particular declaration.
65298258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * The location of a reference is where that reference occurs within the
65398258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * source code.
65498258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor */
65598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
656c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
657b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/**
658b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Retrieve the physical extent of the source construct referenced by
659a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the given cursor.
660a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor *
661a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * The extent of a cursor starts with the file/line/column pointing at the
662a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * first character within the source construct that the cursor refers to and
663a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * ends with the last character withinin that source construct. For a
664a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * declaration, the extent covers the declaration itself. For a reference,
665a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the extent covers the location of the reference (e.g., where the referenced
666a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * entity was actually used).
667a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor */
668a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
669c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor
670c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
671c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
672c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
673c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
674c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
675c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
676c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
677c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines provide the ability to traverse the abstract syntax tree
678c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * using cursors.
679c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
680c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
681c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
682c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
683c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
684c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes how the traversal of the children of a particular
685c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor should proceed after visiting a particular child cursor.
686c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
687c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A value of this enumeration type should be returned by each
688c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
689c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
690c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXChildVisitResult {
691c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
692c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Terminates the cursor traversal.
693c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
694c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Break,
695c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
696c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Continues the cursor traversal with the next sibling of
697c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * the cursor just visited, without visiting its children.
698c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
699c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Continue,
700c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
701c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Recursively traverse the children of this cursor, using
702c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * the same visitor and client data.
703c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
704c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Recurse
705c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor};
706c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
707c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
708c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visitor invoked for each cursor found by a traversal.
709c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
710c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This visitor function will be invoked for each cursor found by
711c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). Its first argument is the cursor being
712c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited, its second argument is the parent visitor for that cursor,
713c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and its third argument is the client data provided to
714c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren().
715c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
716c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The visitor should return one of the \c CXChildVisitResult values
717c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to direct clang_visitCursorChildren().
718c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
719c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
720c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                                   CXCursor parent,
721c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                                   CXClientData client_data);
722c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
723c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
724c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visit the children of a particular cursor.
725c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
726c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This function visits all the direct children of the given cursor,
727c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * invoking the given \p visitor function with the cursors of each
728c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited child. The traversal may be recursive, if the visitor returns
729c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
730c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the visitor returns \c CXChildVisit_Break.
731c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
732c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param tu the translation unit into which the cursor refers.
733c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
734c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param parent the cursor whose child may be visited. All kinds of
735c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursors can be visited, including invalid visitors (which, by
736c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * definition, have no children).
737c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
738c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param visitor the visitor function that will be invoked for each
739c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * child of \p parent.
740c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
741c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param client_data pointer data supplied by the client, which will
742c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be passed to the visitor each time it is invoked.
743c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
744c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \returns a non-zero value if the traversal was terminated
745c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * prematurely by the visitor returning \c CXChildVisit_Break.
746c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
747c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
748c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                            CXCursorVisitor visitor,
749c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                            CXClientData client_data);
750c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
751c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
752c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
753c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
754c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
755c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
756c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
757c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
758c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines provide the ability to determine references within and
759c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * across translation units, by providing the names of the entities referenced
760c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by cursors, follow reference cursors to the declarations they reference,
761c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and associate declarations with their definitions.
762c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
763c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
764c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
765c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
766c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
767c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
768c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by the given cursor.
769c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
770c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A Unified Symbol Resolution (USR) is a string that identifies a particular
771c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * entity (function, class, variable, etc.) within a program. USRs can be
772c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * compared across translation units to determine, e.g., when references in
773c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * one translation refer to an entity defined in another translation unit.
774c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
775c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
776c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
777c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
778c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a name for the entity referenced by this cursor.
779c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
780c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
781c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
782c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor/** \brief For a cursor that is a reference, retrieve a cursor representing the
783c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * entity that it references.
784c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor *
785c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Reference cursors refer to other entities in the AST. For example, an
786c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Objective-C superclass reference cursor refers to an Objective-C class.
787c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * This function produces the cursor for the Objective-C class from the
788c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * cursor for the superclass reference. If the input cursor is a declaration or
789c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * definition, it returns that declaration or definition unchanged.
790c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Othewise, returns the NULL cursor.
791c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor */
792c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
793b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
794b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/**
795b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \brief For a cursor that is either a reference to or a declaration
796b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  of some entity, retrieve a cursor that describes the definition of
797b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  that entity.
798b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
799b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  Some entities can be declared multiple times within a translation
800b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  unit, but only one of those declarations can also be a
801b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  definition. For example, given:
802b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
803b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \code
804b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int, int);
805b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int g(int x, int y) { return f(x, y); }
806b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int a, int b) { return a + b; }
807b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int, int);
808b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \endcode
809b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
810b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  there are three declarations of the function "f", but only the
811b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  second one is a definition. The clang_getCursorDefinition()
812b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  function will take any cursor pointing to a declaration of "f"
813b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  (the first or fourth lines of the example) or a cursor referenced
814b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  that uses "f" (the call to "f' inside "g") and will return a
815b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  declaration cursor pointing to the definition (the second "f"
816b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  declaration).
817b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
818b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  If given a cursor for which there is no corresponding definition,
819b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  e.g., because there is no definition of that entity within this
820b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  translation unit, returns a NULL cursor.
821b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */
822b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
823b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
824b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/**
825b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Determine whether the declaration pointed to by this cursor
826b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * is also a definition of that entity.
827b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */
828b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
829b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
830c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
831c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
832c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
833c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
834c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
835c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_DEBUG Debugging facilities
836c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
837c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines are used for testing and debugging, only, and should not
838c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be relied upon.
839c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
840c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
841c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
842c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
8434ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
8442e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
8452e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
8464ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **startBuf,
8474ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
8484ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
8494ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
8504ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
8514ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
852600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
8530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
854c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
855c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
856c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
857c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
858c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CODE_COMPLET Code completion
859c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
860c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Code completion involves taking an (incomplete) source file, along with
861c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * knowledge of where the user is actively editing that file, and suggesting
862c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * syntactically- and semantically-valid constructs that the user might want to
863c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * use at that particular point in the source code. These data structures and
864c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines provide support for code completion.
865c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
866c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
867c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
868c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
869c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
8700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result.
8710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
8720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion
8730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the
8740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected.
8750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which
8760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g.,
8770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of
8780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace
8790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
8800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * description of the different kinds of chunks.
8810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
8820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString;
8830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
8840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
8850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion.
8860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
8870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct {
8880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
8890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The kind of entity that this completion refers to.
8900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
8910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The cursor kind will be a macro, keyword, or a declaration (one of the
8920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * *Decl cursor kinds), describing the entity that the completion is
8930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to.
8940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
8950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \todo In the future, we would like to provide a full cursor, to allow
8960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the client to extract additional information from declaration.
8970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
8980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  enum CXCursorKind CursorKind;
8990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
9000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The code-completion string that describes how to insert this
9020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result into the editing buffer.
9030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
9040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionString CompletionString;
9050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult;
9060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
9070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
9080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string.
9090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
9100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each "chunk" within a code-completion string (\c CXCompletionString) is
9110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * either a piece of text with a specific "kind" that describes how that text
9120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string.
9130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
9140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind {
9150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A code-completion string that describes "optional" text that
9170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * could be a part of the template (but is not required).
9180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The Optional chunk is the only kind of chunk that has a code-completion
9200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * string for its representation, which is accessible via
9210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \c clang_getCompletionChunkCompletionString(). The code-completion string
9220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * describes an additional part of the template that is completely optional.
9230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * For example, optional chunks can be used to describe the placeholders for
9240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * arguments that match up with defaulted function parameters, e.g. given:
9250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
9270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * void f(int x, float y = 3.14, double z = 2.71828);
9280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
9290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The code-completion string for this function would contain:
9310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a TypedText chunk for "f".
9320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a LeftParen chunk for "(".
9330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a Placeholder chunk for "int x"
9340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
9350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Comma chunk for ","
9360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Placeholder chunk for "float x"
9370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - an Optional chunk containing the last defaulted argument:
9380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Comma chunk for ","
9390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Placeholder chunk for "double z"
9400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a RightParen chunk for ")"
9410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There are many ways two handle Optional chunks. Two simple approaches are:
9430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Completely ignore optional chunks, in which case the template for the
9440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would only include the first parameter ("int x").
9450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Fully expand all optional chunks, in which case the template for the
9460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would have all of the parameters.
9470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
9480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Optional,
9490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that a user would be expected to type to get this
9510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result.
9520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There will be exactly one "typed text" chunk in a semantic string, which
9540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * will typically provide the spelling of a keyword or the name of a
9550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * declaration that could be used at the current code point. Clients are
9560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * expected to filter the code-completion results based on the text in this
9570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * chunk.
9580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
9590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_TypedText,
9600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that should be inserted as part of a code-completion result.
9620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "text" chunk represents text that is part of the template to be
9640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * inserted into user code should this particular code-completion result
9650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * be selected.
9660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
9670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Text,
9680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Placeholder text that should be replaced by the user.
9700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "placeholder" chunk marks a place where the user should insert text
9720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * into the code-completion template. For example, placeholders might mark
9730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the function parameters for a function declaration, to indicate that the
9740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * user should provide arguments for each of those parameters. The actual
9750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * text in a placeholder is a suggestion for the text to display before
9760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the user replaces the placeholder with real code.
9770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
9780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Placeholder,
9790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Informative text that should be displayed but never inserted as
9810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * part of the template.
9820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * An "informative" chunk contains annotations that can be displayed to
9840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * help the user decide whether a particular code-completion result is the
9850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * right option, but which is not part of the actual template to be inserted
9860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * by code completion.
9870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
9880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Informative,
9890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
9900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that describes the current parameter when code-completion is
9910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to function call, message send, or template specialization.
9920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "current parameter" chunk occurs when code-completion is providing
9940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * information about a parameter corresponding to the argument at the
9950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion point. For example, given a function
9960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
9970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
9980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * int add(int x, int y);
9990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
10000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
10010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * and the source code \c add(, where the code-completion point is after the
10020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "(", the code-completion string will contain a "current parameter" chunk
10030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * for "int x", indicating that the current argument will initialize that
10040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * parameter. After typing further, to \c add(17, (where the code-completion
10050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * point is after the ","), the code-completion string will contain a
10060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "current paremeter" chunk to "int y".
10070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_CurrentParameter,
10090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left parenthesis ('('), used to initiate a function call or
10110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the beginning of a function parameter list.
10120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftParen,
10140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right parenthesis (')'), used to finish a function call or
10160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the end of a function parameter list.
10170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightParen,
10190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left bracket ('[').
10210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBracket,
10230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right bracket (']').
10250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBracket,
10270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left brace ('{').
10290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBrace,
10310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right brace ('}').
10330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBrace,
10350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left angle bracket ('<').
10370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftAngle,
10390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right angle bracket ('>').
10410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
10420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightAngle,
10430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
10440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A comma separator (',').
10450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
1046ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  CXCompletionChunk_Comma,
1047ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  /**
1048ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * \brief Text that specifies the result type of a given result.
1049ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   *
1050ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * This special kind of informative chunk is not meant to be inserted into
1051ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * the text buffer. Rather, it is meant to illustrate the type that an
1052ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * expression using the given completion string would have.
1053ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   */
105401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_ResultType,
105501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
105601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A colon (':').
105701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
105801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Colon,
105901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
106001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A semicolon (';').
106101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
106201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_SemiColon,
106301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
106401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief An '=' sign.
106501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
106601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Equal,
106701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
106801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Horizontal space (' ').
106901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
107001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_HorizontalSpace,
107101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
107201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Vertical space ('\n'), after which it is generally a good idea to
107301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * perform indentation.
107401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
107501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_VerticalSpace
10760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor};
10770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
10780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
10790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string.
10800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
10810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
10820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
10830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
10840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
10850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number.
10860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
10870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE enum CXCompletionChunkKind
10880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string,
10890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
10900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
10910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
10920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the text associated with a particular chunk within a
10930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string.
10940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
10950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
10960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
10970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
10980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
10990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number.
11000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
11010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE const char *
11020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string,
11030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
11040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
11050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
11060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the completion string associated with a particular chunk
11070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string.
11080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
11100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
11120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index
11140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion
11150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string.
11160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
11170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString
11180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string,
11190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                                         unsigned chunk_number);
11200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
11210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
11220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string.
11230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
11240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned
11250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string);
11260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
11270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
1128ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion.
1129ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor *
1130ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as
1131ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * produced by \c clang_codeComplete. Its contents must be freed by
1132ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults.
1133ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
1134ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct {
1135ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
1136ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The code-completion results.
1137ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
1138ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  CXCompletionResult *Results;
1139ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1140ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
1141ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The number of code-completion results stored in the
1142ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \c Results array.
1143ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
1144ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  unsigned NumResults;
1145ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults;
1146ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1147ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
11480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file.
11490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and
11510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential
11520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model
11530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file,
11540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has
11550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed
11560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the
11570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * current location in the C/Objective-C/C++ grammar and the state of
11580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are
1159ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure.
11600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the
11620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * user types punctuation characters or whitespace, at which point the
11630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p
11640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then
11650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">",
11660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that
11670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the
11680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results
11690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for
11700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after
11710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
11720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only
11730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface
1174ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion
11750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must
11760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency.
11770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code
11790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion.
11800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11818506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to
11828506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the
11838506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results
11848506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced.  NOTE: One can also specify NULL for this argument if the
11858506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args.
11860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in
11880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args.
11890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
11900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang
11910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * compiler to build the given source file. This should include all of the
11920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header
11930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * includes, etc., but should not include any information specific to
11940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion.
11950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
1196735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
1197735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files.
1198735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
1199735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
1200735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of
1201735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files.
1202735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
12030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion
12040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the
12050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source filename. However, the completion filename may also be a file
12060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * included by the source file, which is required when producing
12070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header.
12080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
12090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur.
12100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
12110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_column the column at which code-completion should occur.
12120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that
12130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token.
12140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
1215ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure
1216ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be
1217ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code
1218ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL.
1219ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
1220ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
1221ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
1222ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *source_filename,
1223ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          int num_command_line_args,
1224ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char **command_line_args,
1225ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned num_unsaved_files,
1226ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          struct CXUnsavedFile *unsaved_files,
1227ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *complete_filename,
1228ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_line,
1229ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_column);
1230ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1231ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
1232ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results.
12330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
1234ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
1235ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
12360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
123720d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/**
123820d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @}
123920d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */
1240c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1241c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1242c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1243c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1244c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1245d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
1246d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
1247d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
1248d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
1249d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
1250