Index.h revision 66ccaec73706f3623d2e7d191fe2c944feedcc2b
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>
210a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor#include <stdio.h>
2288145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
23d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
24d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenekextern "C" {
25d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
26d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
2788145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/* MSVC DLL import/export. */
282e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#ifdef _MSC_VER
292e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #ifdef _CINDEX_LIB_
302e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllexport)
312e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #else
322e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllimport)
332e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #endif
342e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#else
352e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #define CINDEX_LINKAGE
362e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#endif
372e06fc877a633abea3b40a64950c7316dac29ca8John Thompson
3820d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/** \defgroup CINDEX C Interface to Clang
3920d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor *
401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The C Interface to Clang provides a relatively small API that exposes
41f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities for parsing source code into an abstract syntax tree (AST),
42f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * loading already-parsed ASTs, traversing the AST, associating
43f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * physical source locations with elements within the AST, and other
44f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities that support Clang-based development tools.
45f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This C interface to Clang will never provide all of the information
47f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * representation stored in Clang's C++ AST, nor should it: the intent is to
48f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * maintain an API that is relatively stable from one release to the next,
49f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * providing only the basic functionality needed to support development tools.
501efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar *
511efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * To avoid namespace pollution, data types are prefixed with "CX" and
52f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * functions are prefixed with "clang_".
5320d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor *
5420d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @{
5520d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */
561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
577f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
587f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief An "index" that consists of a set of translation units that would
597f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * typically be linked together into an executable or library.
607f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
617f17376e0931a337d544b75d9030bc92763be287Douglas Gregortypedef void *CXIndex;
62600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
637f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
647f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A single translation unit, which resides in an index.
657f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
6650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXTranslationUnit;  /* A translation unit instance. */
67600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
687f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
69c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Opaque pointer representing client data that will be passed through
70c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to various callbacks and visitors.
717f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
72c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef void *CXClientData;
731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
74735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor/**
75735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief Provides the contents of a file that has not yet been saved to disk.
76735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
77735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * Each CXUnsavedFile instance provides the name of a file on the
78735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * system along with the current contents of that file that have not
79735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * yet been saved to disk.
80735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */
81735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregorstruct CXUnsavedFile {
821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief The file whose contents have not yet been saved.
84735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   *
85735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * This file must already exist in the file system.
86735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
87735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Filename;
88735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
891efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
90c8dfe5ece04e683106eb96c58a2999f70b53ac21Douglas Gregor   * \brief A buffer containing the unsaved contents of this file.
91735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
92735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Contents;
93735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
94735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
95c8dfe5ece04e683106eb96c58a2999f70b53ac21Douglas Gregor   * \brief The length of the unsaved contents of this buffer.
96735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
97735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  unsigned long Length;
98735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor};
99735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
1007f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1017f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \defgroup CINDEX_STRING String manipulation routines
1027f17376e0931a337d544b75d9030bc92763be287Douglas Gregor *
1037f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @{
1047f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
1051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1067f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1077f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A character string.
1087f17376e0931a337d544b75d9030bc92763be287Douglas Gregor *
1097f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * The \c CXString type is used to return strings from the interface when
1107f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * the ownership of that string might different from one call to the next.
1117f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * Use \c clang_getCString() to retrieve the string data and, once finished
1127f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * with the string data, call \c clang_disposeString() to free the string.
113ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */
114ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct {
115ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  const char *Spelling;
116ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  /* A 1 value indicates the clang_ indexing API needed to allocate the string
117ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff     (and it must be freed by clang_disposeString()). */
118ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  int MustFreeString;
119ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString;
120ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1217f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1227f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Retrieve the character data associated with the given string.
1237f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
124ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string);
125ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1267f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1277f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Free the given string,
1287f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
129ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string);
130ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1317f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1327f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @}
1337f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
1341efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
136e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating
137e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options:
138e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
139e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
140e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration
1411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * is one that belongs in the translation unit itself and not in a precompiled
142e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations
143e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated.
144e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
145b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example:
146b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
1470a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *   // excludeDeclsFromPCH = 1, displayDiagnostics=1
1480a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *   Idx = clang_createIndex(1, 1);
149b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
150b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // IndexTest.pch was produced with the following command:
151b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
152b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
153b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
154b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.pch'
1551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
156002a528ab0189fc60cfbf9328962c96ccbe567eeDouglas Gregor *                       TranslationUnitVisitor, 0);
157b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
158b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
159b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.c', excluding symbols
160b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // from 'IndexTest.pch'.
161fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
162fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
163fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar *                                                  0, 0);
164b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
165b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *                       TranslationUnitVisitor, 0);
166b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
167b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
168b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via
169b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
170b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler).
171e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
1720a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
1730a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor                                         int displayDiagnostics);
174896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1750087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor/**
1760087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * \brief Destroy the given index.
1770087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor *
1780087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * The index must not be destroyed until all of the translation units created
1790087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * within that index have been destroyed.
1800087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor */
1818506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
1821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
1841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Request that AST's be generated externally for API calls which parse
1858506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
1868506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
1878506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later
1888506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date.
1898506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
1908506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update.
1918506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value.
1928506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */
1938506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
1948506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                                      int value);
195f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
196c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_FILES File manipulation routines
197f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
198f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{
199f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
2001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
201f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
202f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief A particular source file that is part of a translation unit.
203f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
204f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregortypedef void *CXFile;
2051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
206f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
207f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
208f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the complete file and path name of the given file.
20988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */
21074844072411bae91d5dbb89955d200cbe1e0a1c8Ted KremenekCINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
2111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
212f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
213f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the last modification time of the given file.
214f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
21508b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
21688145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
2173c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/**
218b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a file handle within the given translation unit.
219b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
220b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param tu the translation unit
2211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar *
222b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param file_name the name of the file.
223b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
224b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns the file handle for the named file in the translation unit \p tu,
225b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * or a NULL file handle if the file was not a part of this translation unit.
226b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
2271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
228b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                    const char *file_name);
2291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
230b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
231f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @}
232f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
233f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
234f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
235f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \defgroup CINDEX_LOCATIONS Physical source locations
236f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
237f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * Clang represents physical source locations in its abstract syntax tree in
238f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * great detail, with file, line, and column information for the majority of
239f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * the tokens parsed in the source code. These data types and functions are
240f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * used to represent source location information, either for a particular
241f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * point in the program or for a range of points in the program, and extract
242f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * specific location information from those data types.
243f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
244f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{
245f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
2461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
247f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
2481db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a specific source location within a translation
2491db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * unit.
2501db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
2511db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getInstantiationLocation() to map a source location to a
2521db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * particular file, line, and column.
2533c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */
2543c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct {
2555352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  void *ptr_data[2];
2561db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned int_data;
2573c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceLocation;
258fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
2593c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/**
260d52864bd33c66aacc84133460d8c9c0dfcdd5c18Daniel Dunbar * \brief Identifies a half-open character range in the source code.
2613c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor *
2621db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
2631db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * starting and end locations from a source range, respectively.
2643c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */
2653c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct {
2665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  void *ptr_data[2];
2671db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned begin_int_data;
2681db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned end_int_data;
2693c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceRange;
270fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
2711db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
272b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a NULL (invalid) source location.
273b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
274b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
2751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
276b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
277b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \determine Determine whether two source locations, which must refer into
2781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * the same translation unit, refer to exactly the same point in the source
279b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * code.
280b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
281b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns non-zero if the source locations refer to the same location, zero
282b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * if they refer to different locations.
283b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
284b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
285b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                             CXSourceLocation loc2);
2861efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
287b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
2881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieves the source location associated with a given file/line/column
2891efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * in a particular translation unit.
290b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
291b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
292b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  CXFile file,
293b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  unsigned line,
294b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  unsigned column);
2951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
296b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
2975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve a NULL (invalid) source range.
2985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
2995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getNullRange();
300896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
3015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
302b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a source range given the beginning and ending source
303b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * locations.
304b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
305b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
306b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                            CXSourceLocation end);
3071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
308b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
30946766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * \brief Retrieve the file, line, column, and offset represented by
31046766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * the given source location.
3111db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param location the location within a source file that will be decomposed
3131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * into its parts.
3141db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3151efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param file [out] if non-NULL, will be set to the file to which the given
3161db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points.
3171db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3181efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param line [out] if non-NULL, will be set to the line to which the given
3191db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points.
3201db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param column [out] if non-NULL, will be set to the column to which the given
3221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source location points.
32346766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor *
32446766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * \param offset [out] if non-NULL, will be set to the offset into the
32546766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * buffer to which the given source location points.
3261db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3271db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
3281db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   CXFile *file,
3291db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   unsigned *line,
33046766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor                                                   unsigned *column,
33146766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor                                                   unsigned *offset);
332e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor
333e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor/**
3341efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the first character within a
3351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range.
3361db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3371db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
3381db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
3391db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
3401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the last character within a
3411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range.
3421db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3431db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
3441db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
345f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
346f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @}
347f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
348c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
349c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
3505352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \defgroup CINDEX_DIAG Diagnostic reporting
3515352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
3525352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @{
3535352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3545352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3555352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
3565352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Describes the severity of a particular diagnostic.
3575352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3585352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorenum CXDiagnosticSeverity {
3595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
360896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek   * \brief A diagnostic that has been suppressed, e.g., by a command-line
3615352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * option.
3625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3635352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Ignored = 0,
364896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
3655352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic is a note that should be attached to the
3675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * previous (non-note) diagnostic.
3685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Note    = 1,
3705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic indicates suspicious code that may not be
3735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * wrong.
3745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Warning = 2,
3765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic indicates that the code is ill-formed.
3795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3805352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Error   = 3,
3815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic indicates that the code is ill-formed such
3845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * that future parser recovery is unlikely to produce useful
3855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * results.
3865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Fatal   = 4
3885352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor};
3895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
3915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief A single diagnostic, containing the diagnostic's severity,
3925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * location, text, source ranges, and fix-it hints.
3935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3945352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregortypedef void *CXDiagnostic;
3955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
397a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Determine the number of diagnostics produced for the given
398a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * translation unit.
399a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
400a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
401a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
402a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
403a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Retrieve a diagnostic associated with the given translation unit.
4045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
405a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Unit the translation unit to query.
406a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Index the zero-based diagnostic number to retrieve.
4075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
408a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \returns the requested diagnostic. This diagnostic must be freed
409a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * via a call to \c clang_disposeDiagnostic().
4105352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
411a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
412a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                                unsigned Index);
413a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
414a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
415a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Destroy a diagnostic.
416a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
417a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
4185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
4200a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Options to control the display of diagnostics.
4210a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4220a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * The values in this enum are meant to be combined to customize the
4230a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * behavior of \c clang_displayDiagnostic().
4240a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
4250a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregorenum CXDiagnosticDisplayOptions {
4260a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  /**
4270a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \brief Display the source-location information where the
4280a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * diagnostic was located.
4290a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4300a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * When set, diagnostics will be prefixed by the file, line, and
4310a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * (optionally) column to which the diagnostic refers. For example,
4320a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4330a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \code
4340a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * test.c:28: warning: extra tokens at end of #endif directive
4350a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \endcode
4360a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4370a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * This option corresponds to the clang flag \c -fshow-source-location.
4380a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   */
4390a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  CXDiagnostic_DisplaySourceLocation = 0x01,
4400a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4410a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  /**
4420a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \brief If displaying the source-location information of the
4430a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * diagnostic, also include the column number.
4440a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4450a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * This option corresponds to the clang flag \c -fshow-column.
4460a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   */
4470a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  CXDiagnostic_DisplayColumn = 0x02,
4480a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4490a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  /**
4500a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \brief If displaying the source-location information of the
4510a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * diagnostic, also include information about source ranges in a
4520a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * machine-parsable format.
4530a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
454896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek   * This option corresponds to the clang flag
4550a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \c -fdiagnostics-print-source-range-info.
4560a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   */
4570a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  CXDiagnostic_DisplaySourceRanges = 0x04
4580a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor};
4590a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4600a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
461274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * \brief Format the given diagnostic in a manner that is suitable for display.
4620a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
463274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * This routine will format the given diagnostic to a string, rendering
464896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * the diagnostic according to the various options given. The
465896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
4660a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * options that most closely mimics the behavior of the clang compiler.
4670a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4680a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \param Diagnostic The diagnostic to print.
4690a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
470896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \param Options A set of options that control the diagnostic display,
4710a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * created by combining \c CXDiagnosticDisplayOptions values.
472274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor *
473274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * \returns A new string containing for formatted diagnostic.
4740a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
475274f1906f12ebf8fcc179701deeda6d3271120c1Douglas GregorCINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
476274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor                                               unsigned Options);
4770a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4780a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
4790a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Retrieve the set of display options most similar to the
4800a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * default behavior of the clang compiler.
4810a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4820a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \returns A set of display options suitable for use with \c
4830a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * clang_displayDiagnostic().
4840a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
4850a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
4860a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4870a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
4880a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Print a diagnostic to the given file.
4890a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
4900a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4910a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
4925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Determine the severity of the given diagnostic.
4935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
494896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE enum CXDiagnosticSeverity
4955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticSeverity(CXDiagnostic);
4965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
4985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the source location of the given diagnostic.
4995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * This location is where Clang would print the caret ('^') when
5015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * displaying the diagnostic on the command line.
5025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
5045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5065352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the text of the given diagnostic.
5075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5085352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
509a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor
510a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor/**
511a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \brief Determine the number of source ranges associated with the given
512a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * diagnostic.
513a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor */
514a3890baf1256ff26081306c7fef70202f8223f41Douglas GregorCINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
515896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
5165352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
517a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \brief Retrieve a source range associated with the diagnostic.
5185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
519a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * A diagnostic's source ranges highlight important elements in the source
5205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * code. On the command line, Clang displays source ranges by
521896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * underlining them with '~' characters.
5225352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
523a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \param Diagnostic the diagnostic whose range is being extracted.
5245352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
525896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \param Range the zero-based index specifying which range to
5265352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
527a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \returns the requested source range.
5285352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
529896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
530a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor                                                      unsigned Range);
5315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5325352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5335352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Determine the number of fix-it hints associated with the
5345352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * given diagnostic.
5355352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5365352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
5375352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5385352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
539473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \brief Retrieve the replacement information for a given fix-it.
5405352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
541473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * Fix-its are described in terms of a source range whose contents
542473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * should be replaced by a string. This approach generalizes over
543473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * three kinds of operations: removal of source code (the range covers
544473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * the code to be removed and the replacement string is empty),
545473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replacement of source code (the range covers the code to be
546473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replaced and the replacement string provides the new code), and
547473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * insertion (both the start and end of the range point at the
548473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * insertion location, and the replacement string provides the text to
549473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * insert).
5505352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
551473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \param Diagnostic The diagnostic whose fix-its are being queried.
5525352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
553473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \param FixIt The zero-based index of the fix-it.
5545352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
555473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \param ReplacementRange The source range whose contents will be
556473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replaced with the returned replacement string. Note that source
557473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * ranges are half-open ranges [a, b), so the source code should be
558473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replaced from a and up to (but not including) b.
5595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
560473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \returns A string containing text that should be replace the source
561473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * code indicated by the \c ReplacementRange.
5625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
563896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
564473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor                                                 unsigned FixIt,
565473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor                                               CXSourceRange *ReplacementRange);
5665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @}
5695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
5735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * The routines in this group provide the ability to create and destroy
5755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * translation units from files, either by parsing the contents of the files or
5765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * by reading in a serialized representation of a translation unit.
5775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @{
5795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
580896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
5815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Get the original translation unit source file name.
5835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString
5855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
5865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5885352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Return the CXTranslationUnit for a given source file and the provided
5895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * command line arguments one would pass to the compiler.
5905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * Note: The 'source_filename' argument is optional.  If the caller provides a
5925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * NULL pointer, the name of the source file is expected to reside in the
5935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * specified command line arguments.
5945352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * Note: When encountered in 'clang_command_line_args', the following options
5965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * are ignored:
5975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-c'
5995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-emit-ast'
6005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-fsyntax-only'
6015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
6025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param source_filename - The name of the source file to load, or NULL if the
6055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * source file is included in clang_command_line_args.
6065352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
6085352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * unsaved_files.
6095352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6105352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
6115352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * but may be required for code completion, including the contents of
6125352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * those files.
6135352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6145352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param diag_callback callback function that will receive any diagnostics
6155352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * emitted while processing this source file. If NULL, diagnostics will be
6165352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * suppressed.
6175352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param diag_client_data client data that will be passed to the diagnostic
6195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * callback function.
6205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6215352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
6225352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         CXIndex CIdx,
6235352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         const char *source_filename,
6245352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         int num_clang_command_line_args,
6255352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         const char **clang_command_line_args,
6265352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         unsigned num_unsaved_files,
627a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                         struct CXUnsavedFile *unsaved_files);
628896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
6295352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6305352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Create a translation unit from an AST file (-emit-ast).
6315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
632896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
633a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                             const char *ast_filename);
6345352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6355352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6365352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Destroy the specified CXTranslationUnit object.
6375352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6385352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
639896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
6405352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6415352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @}
6425352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
643896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
6445352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
645c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes the kind of entity that a cursor refers to.
646c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
647c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXCursorKind {
648c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Declarations */
649c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstDecl                     = 1,
6501efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
651c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A declaration whose specific kind is not exposed via this
6521efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * interface.
653c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
654c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed declarations have the same operations as any other kind
655c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of declaration; one can extract their location information,
656c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * spelling, find their definitions, etc. However, the specific kind
657c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of the declaration is not reported.
658c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
659c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedDecl                 = 1,
660c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C or C++ struct. */
6611efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  CXCursor_StructDecl                    = 2,
662c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C or C++ union. */
663c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnionDecl                     = 3,
664c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C++ class. */
665c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ClassDecl                     = 4,
666c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An enumeration. */
667c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_EnumDecl                      = 5,
6681efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
669c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A field (in C) or non-static data member (in C++) in a
670c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * struct, union, or C++ class.
671c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
672c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FieldDecl                     = 6,
673c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An enumerator constant. */
674c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_EnumConstantDecl              = 7,
675c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A function. */
676c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FunctionDecl                  = 8,
677c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A variable. */
678c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_VarDecl                       = 9,
679c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A function or method parameter. */
680c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ParmDecl                      = 10,
681c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @interface. */
682c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCInterfaceDecl             = 11,
683c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @interface for a category. */
684c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCCategoryDecl              = 12,
685c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @protocol declaration. */
686c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCProtocolDecl              = 13,
687c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @property declaration. */
688c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCPropertyDecl              = 14,
689c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C instance variable. */
690c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCIvarDecl                  = 15,
691c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C instance method. */
692c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCInstanceMethodDecl        = 16,
693c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C class method. */
694c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCClassMethodDecl           = 17,
695c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @implementation. */
696c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCImplementationDecl        = 18,
697c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @implementation for a category. */
698c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCCategoryImplDecl          = 19,
699c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A typedef */
700c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TypedefDecl                   = 20,
701c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastDecl                      = 20,
7021efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
703c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* References */
704c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstRef                      = 40, /* Decl references */
7051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  CXCursor_ObjCSuperClassRef             = 40,
706c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCProtocolRef               = 41,
707c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCClassRef                  = 42,
708c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
709c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A reference to a type declaration.
710c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
711c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * A type reference occurs anywhere where a type is named but not
712c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * declared. For example, given:
713c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
714c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \code
715c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * typedef unsigned size_type;
716c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * size_type size;
717c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \endcode
718c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
719c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
720c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * while the type of the variable "size" is referenced. The cursor
721c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * referenced by the type of size is the typedef for size_type.
722c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
723c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TypeRef                       = 43,
724c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastRef                       = 43,
7251efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
726c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Error conditions */
727c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstInvalid                  = 70,
728c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_InvalidFile                   = 70,
729c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_NoDeclFound                   = 71,
730c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_NotImplemented                = 72,
731c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastInvalid                   = 72,
7321efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
733c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Expressions */
734c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstExpr                     = 100,
7351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
736c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
737c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression whose specific kind is not exposed via this
7381efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * interface.
739c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
740c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed expressions have the same operations as any other kind
741c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of expression; one can extract their location information,
742c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * spelling, children, etc. However, the specific kind of the
743c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * expression is not reported.
744c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
745c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedExpr                 = 100,
7461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
747c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
748c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression that refers to some value declaration, such
749c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * as a function, varible, or enumerator.
750c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
751c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_DeclRefExpr                   = 101,
7521efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
753c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
754c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression that refers to a member of a struct, union,
755c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * class, Objective-C class, etc.
756c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
757c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_MemberRefExpr                 = 102,
7581efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
759c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An expression that calls a function. */
760c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_CallExpr                      = 103,
7611efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
762c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An expression that sends a message to an Objective-C
763c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   object or class. */
764c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCMessageExpr               = 104,
765c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastExpr                      = 104,
7661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
767c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Statements */
768c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstStmt                     = 200,
769c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
770c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A statement whose specific kind is not exposed via this
771c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * interface.
772c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
773c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed statements have the same operations as any other kind of
774c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * statement; one can extract their location information, spelling,
775c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * children, etc. However, the specific kind of the statement is not
776c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * reported.
777c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
778c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedStmt                 = 200,
779c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastStmt                      = 200,
7801efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
781c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
782c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Cursor that represents the translation unit itself.
783c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
784c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * The translation unit cursor exists primarily to act as the root
785c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * cursor for traversing the contents of a translation unit.
786c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
787e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_TranslationUnit               = 300,
788e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
789e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  /* Attributes */
790e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_FirstAttr                     = 400,
791e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  /**
792e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek   * \brief An attribute whose specific kind is not exposed via this
793e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek   * interface.
794e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek   */
795e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_UnexposedAttr                 = 400,
796e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
797e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_IBActionAttr                  = 401,
798e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_IBOutletAttr                  = 402,
799e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_LastAttr                      = CXCursor_IBOutletAttr
800c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor};
801c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
802c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
803c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A cursor representing some element in the abstract syntax tree for
804c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a translation unit.
805c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
8061efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The cursor abstraction unifies the different kinds of entities in a
807c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * program--declaration, statements, expressions, references to declarations,
808c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * etc.--under a single "cursor" abstraction with a common set of operations.
809c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Common operation for a cursor include: getting the physical location in
810c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a source file where the cursor points, getting the name associated with a
811c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor, and retrieving cursors for any child nodes of a particular cursor.
812c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
813c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors can be produced in two specific ways.
814c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
815c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * from which one can use clang_visitChildren() to explore the rest of the
816c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * translation unit. clang_getCursor() maps from a physical source location
817c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to the entity that resides at that location, allowing one to map from the
818c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * source code into the AST.
819c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
820c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef struct {
821c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  enum CXCursorKind kind;
822c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  void *data[3];
8231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar} CXCursor;
824c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
825c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
826c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
827c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
828c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
829c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
8301efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
831c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
832c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the NULL cursor, which represents no entity.
833c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
834c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getNullCursor(void);
8351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
836c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
837c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the cursor that represents the given translation unit.
838c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
839c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor can be used to start traversing the
840c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * various declarations within the given translation unit.
841c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
842c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
843c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
844c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
845c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether two cursors are equivalent.
846c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
847c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
8481efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
849c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
850c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the kind of the given cursor.
851c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
852c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
853c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
854c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
855c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a declaration.
856c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
857c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
858c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
859c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
860c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a simple
861c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reference.
862c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
863c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Note that other kinds of cursors (such as expressions) can also refer to
864c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * other cursors. Use clang_getCursorReferenced() to determine whether a
865c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * particular cursor refers to another entity.
866c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
867c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
868c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
869c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
870c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents an expression.
871c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
872c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
873c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
874c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
875c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a statement.
876c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
877c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
878c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
879c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
8801efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents an invalid
881c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor.
8821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar */
883c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
884c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
885c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
8861efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents a translation
8871efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unit.
888c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
889c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
8901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
891ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek/***
892ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek * \brief Determine whether the given cursor represents a currently
893ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek *  unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
894ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek */
895ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted KremenekCINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
896ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek
897c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
89816b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * \brief Describe the linkage of the entity referred to by a cursor.
89916b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek */
90016b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenekenum CXLinkageKind {
90116b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  /** \brief This value indicates that no linkage information is available
90216b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek   * for a provided CXCursor. */
90316b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  CXLinkage_Invalid,
90416b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  /**
90516b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek   * \brief This is the linkage for variables, parameters, and so on that
90616b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek   *  have automatic storage.  This covers normal (non-extern) local variables.
90716b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek   */
90816b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  CXLinkage_NoLinkage,
90916b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  /** \brief This is the linkage for static variables and static functions. */
91016b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  CXLinkage_Internal,
91116b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  /** \brief This is the linkage for entities with external linkage that live
91216b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek   * in C++ anonymous namespaces.*/
91316b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  CXLinkage_UniqueExternal,
91416b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  /** \brief This is the linkage for entities with true, external linkage. */
91516b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek  CXLinkage_External
91616b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek};
91716b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek
91816b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek/**
91916b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * \brief Determine the linkage of the entity referred to be a given cursor.
92016b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek */
92116b4259aecaa22b642d35d36fd89965ed700c1e0Ted KremenekCINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
92216b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek
92316b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek/**
924c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
925c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
9261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
927c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
928c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
929c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
930c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors represent a location within the Abstract Syntax Tree (AST). These
931c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines help map between cursors and the physical locations where the
932c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * described entities occur in the source code. The mapping is provided in
933c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * both directions, so one can map from source code to the AST and back.
934c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
935c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
93650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
9371efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
9386a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
939b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Map a source location to the cursor that describes the entity at that
940b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * location in the source code.
941b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
942b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() maps an arbitrary source location within a translation
943b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * unit down to the most specific cursor that describes the entity at that
9441efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * location. For example, given an expression \c x + y, invoking
945b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() with a source location pointing to "x" will return the
9461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * cursor for "x"; similarly for "y". If the cursor points anywhere between
947b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
948b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * will return a cursor referring to the "+" expression.
949b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
950b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns a cursor representing the entity at the given source location, or
951b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * a NULL cursor if no such entity can be found.
9526a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
953b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
9541efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
95598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor/**
95698258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * \brief Retrieve the physical location of the source constructor referenced
95798258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * by the given cursor.
95898258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor *
95998258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * The location of a declaration is typically the location of the name of that
9601efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * declaration, where the name of that declaration would occur if it is
9611efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unnamed, or some keyword that introduces that particular declaration.
9621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The location of a reference is where that reference occurs within the
96398258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * source code.
96498258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor */
96598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
966c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
967b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/**
968b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Retrieve the physical extent of the source construct referenced by
969a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the given cursor.
970a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor *
971a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * The extent of a cursor starts with the file/line/column pointing at the
972a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * first character within the source construct that the cursor refers to and
9731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * ends with the last character withinin that source construct. For a
974a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * declaration, the extent covers the declaration itself. For a reference,
975a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the extent covers the location of the reference (e.g., where the referenced
976a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * entity was actually used).
977a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor */
978a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
979c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor
980c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
981c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
982c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
9831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
984c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
985c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
986c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
987c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines provide the ability to traverse the abstract syntax tree
988c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * using cursors.
989c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
990c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
991c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
9921efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
993c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
994c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes how the traversal of the children of a particular
995c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor should proceed after visiting a particular child cursor.
996c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
997c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A value of this enumeration type should be returned by each
998c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
999c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1000c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXChildVisitResult {
1001c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
10021efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief Terminates the cursor traversal.
1003c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
1004c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Break,
10051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
1006c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Continues the cursor traversal with the next sibling of
1007c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * the cursor just visited, without visiting its children.
1008c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
1009c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Continue,
1010c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
1011c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Recursively traverse the children of this cursor, using
1012c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * the same visitor and client data.
1013c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
1014c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Recurse
1015c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor};
1016c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1017c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1018c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visitor invoked for each cursor found by a traversal.
1019c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1020c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This visitor function will be invoked for each cursor found by
1021c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). Its first argument is the cursor being
1022c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited, its second argument is the parent visitor for that cursor,
1023c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and its third argument is the client data provided to
1024c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren().
1025c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1026c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The visitor should return one of the \c CXChildVisitResult values
1027c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to direct clang_visitCursorChildren().
1028c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbartypedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
10301efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar                                                   CXCursor parent,
1031c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                                   CXClientData client_data);
1032c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1033c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1034c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visit the children of a particular cursor.
1035c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1036c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This function visits all the direct children of the given cursor,
1037c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * invoking the given \p visitor function with the cursors of each
1038c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited child. The traversal may be recursive, if the visitor returns
1039c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
1040c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the visitor returns \c CXChildVisit_Break.
1041c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1042c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param parent the cursor whose child may be visited. All kinds of
1043a57259e9d7b30bcce93f0a62eee0488738026172Daniel Dunbar * cursors can be visited, including invalid cursors (which, by
1044c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * definition, have no children).
1045c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1046c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param visitor the visitor function that will be invoked for each
1047c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * child of \p parent.
1048c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1049c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param client_data pointer data supplied by the client, which will
1050c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be passed to the visitor each time it is invoked.
1051c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1052c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \returns a non-zero value if the traversal was terminated
1053c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * prematurely by the visitor returning \c CXChildVisit_Break.
1054c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
1056c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                            CXCursorVisitor visitor,
1057c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                            CXClientData client_data);
10581efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1059c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1060c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1061c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1063c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1064c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1065c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
10661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * These routines provide the ability to determine references within and
1067c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * across translation units, by providing the names of the entities referenced
1068c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by cursors, follow reference cursors to the declarations they reference,
1069c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and associate declarations with their definitions.
1070c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1071c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1072c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1074c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1075c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1076c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by the given cursor.
1077c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1078c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A Unified Symbol Resolution (USR) is a string that identifies a particular
1079c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * entity (function, class, variable, etc.) within a program. USRs can be
1080c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * compared across translation units to determine, e.g., when references in
1081c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * one translation refer to an entity defined in another translation unit.
1082c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1083c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1084c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1085c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1086896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C class.
1087896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */
1088896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
1089896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1090896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/**
1091896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C category.
1092896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */
1093896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString
109466ccaec73706f3623d2e7d191fe2c944feedcc2bTed Kremenek  clang_constructUSR_ObjCCategory(const char *class_name,
1095896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek                                 const char *category_name);
1096896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1097896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/**
1098896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C protocol.
1099896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */
1100896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString
1101896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek  clang_constructUSR_ObjCProtocol(const char *protocol_name);
1102896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1103896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1104896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/**
1105896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C instance variable and
1106896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek *   the USR for its containing class.
1107896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */
1108896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
1109896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek                                                    CXString classUSR);
1110896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1111896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/**
1112896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C method and
1113896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek *   the USR for its containing class.
1114896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */
1115896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
1116896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek                                                      unsigned isInstanceMethod,
1117896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek                                                      CXString classUSR);
1118896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1119896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/**
1120896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C property and the USR
1121896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek *  for its containing class.
1122896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */
1123896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
1124896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek                                                        CXString classUSR);
1125896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1126896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/**
1127c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a name for the entity referenced by this cursor.
1128c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1129c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1130c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1131c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor/** \brief For a cursor that is a reference, retrieve a cursor representing the
1132c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * entity that it references.
1133c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor *
1134c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Reference cursors refer to other entities in the AST. For example, an
1135c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Objective-C superclass reference cursor refers to an Objective-C class.
11361efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This function produces the cursor for the Objective-C class from the
1137c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * cursor for the superclass reference. If the input cursor is a declaration or
1138c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * definition, it returns that declaration or definition unchanged.
11391efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Otherwise, returns the NULL cursor.
1140c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor */
1141c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
1142b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
11431efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
1144b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \brief For a cursor that is either a reference to or a declaration
1145b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  of some entity, retrieve a cursor that describes the definition of
1146b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  that entity.
1147b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1148b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  Some entities can be declared multiple times within a translation
1149b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  unit, but only one of those declarations can also be a
1150b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  definition. For example, given:
1151b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1152b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \code
1153b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int, int);
1154b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int g(int x, int y) { return f(x, y); }
1155b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int a, int b) { return a + b; }
1156b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int, int);
1157b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \endcode
1158b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1159b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  there are three declarations of the function "f", but only the
1160b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  second one is a definition. The clang_getCursorDefinition()
1161b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  function will take any cursor pointing to a declaration of "f"
1162b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  (the first or fourth lines of the example) or a cursor referenced
1163b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  that uses "f" (the call to "f' inside "g") and will return a
1164b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  declaration cursor pointing to the definition (the second "f"
1165b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  declaration).
1166b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1167b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  If given a cursor for which there is no corresponding definition,
1168b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  e.g., because there is no definition of that entity within this
1169b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  translation unit, returns a NULL cursor.
1170b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */
1171b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1172b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
11731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
1174b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Determine whether the declaration pointed to by this cursor
1175b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * is also a definition of that entity.
1176b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */
1177b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1178b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
1179c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1180c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1181c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
11821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1183c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
11840045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * \defgroup CINDEX_LEX Token extraction and manipulation
11850045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *
11860045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * The routines in this group provide access to the tokens within a
11870045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * translation unit, along with a semantic mapping of those tokens to
11880045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * their corresponding cursors.
1189fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1190fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @{
1191fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1192fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1193fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1194fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a kind of token.
1195fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1196fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef enum CXTokenKind {
1197fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1198fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief A token that contains some kind of punctuation.
1199fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1200fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Punctuation,
1201896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1202fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
12030045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor   * \brief A language keyword.
1204fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1205fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Keyword,
1206896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1207fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1208fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief An identifier (that is not a keyword).
1209fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1210fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Identifier,
1211896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1212fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1213fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief A numeric, string, or character literal.
1214fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1215fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Literal,
1216896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1217fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1218fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief A comment.
1219fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1220fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Comment
1221fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXTokenKind;
1222fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1223fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1224fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a single preprocessing token.
1225fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1226fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef struct {
1227fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  unsigned int_data[4];
1228fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  void *ptr_data;
1229fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXToken;
1230fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1231fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1232fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the kind of the given token.
1233fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1234fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
1235896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1236fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1237fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the spelling of the given token.
1238fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1239fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * The spelling of a token is the textual representation of that token, e.g.,
1240fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * the text of an identifier or keyword.
1241fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1242fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
1243896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1244fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1245fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve the source location of the given token.
1246fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1247896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
1248fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                                       CXToken);
1249896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1250fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1251fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve a source range that covers the given token.
1252fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1253fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
1254fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1255fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1256fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Tokenize the source code described by the given range into raw
1257fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * lexical tokens.
1258fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1259fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit whose text is being tokenized.
1260fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1261fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Range the source range in which text should be tokenized. All of the
1262fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * tokens produced by tokenization will fall within this source range,
1263fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1264fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens this pointer will be set to point to the array of tokens
1265fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that occur within the given source range. The returned pointer must be
1266fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * freed with clang_disposeTokens() before the translation unit is destroyed.
1267fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1268fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens will be set to the number of tokens in the \c *Tokens
1269fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * array.
1270fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1271fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1272fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
1273fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                   CXToken **Tokens, unsigned *NumTokens);
1274896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1275fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1276fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Annotate the given set of tokens by providing cursors for each token
1277fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that can be mapped to a specific entity within the abstract syntax tree.
1278fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
12790045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * This token-annotation routine is equivalent to invoking
12800045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() for the source locations of each of the
12810045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * tokens. The cursors provided are filtered, so that only those
12820045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * cursors that have a direct correspondence to the token are
12830045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * accepted. For example, given a function call \c f(x),
12840045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() would provide the following cursors:
12850045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *
12860045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *   * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
12870045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *   * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
12880045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *   * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
12890045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *
12900045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * Only the first and last of these cursors will occur within the
12910045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * annotate, since the tokens "f" and "x' directly refer to a function
12920045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * and a variable, respectively, but the parentheses are just a small
12930045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * part of the full syntax of the function call expression, which is
12940045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * not provided as an annotation.
1295fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1296fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit that owns the given tokens.
1297fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1298fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens the set of tokens to annotate.
1299fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1300fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens the number of tokens in \p Tokens.
1301fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1302fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Cursors an array of \p NumTokens cursors, whose contents will be
1303fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * replaced with the cursors corresponding to each token.
1304fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1305fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
1306fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                         CXToken *Tokens, unsigned NumTokens,
1307fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                         CXCursor *Cursors);
1308896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1309fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1310fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Free the given set of tokens.
1311fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1312896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
1313fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                        CXToken *Tokens, unsigned NumTokens);
1314896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1315fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1316fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @}
1317fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1318896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1319fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1320c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_DEBUG Debugging facilities
1321c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1322c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines are used for testing and debugging, only, and should not
1323c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be relied upon.
1324c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1325c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1326c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
13271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
13284ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
1329e68fff6fc083c6270d835216a3de0b82c6ef0310Ted KremenekCINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
13301efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
13311efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar                                          const char **startBuf,
13324ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
13334ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
13344ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
13354ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
13364ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
13370a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE void clang_enableStackTraces(void);
13380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
1339c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1340c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
13411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1342c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1343c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CODE_COMPLET Code completion
1344c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1345c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Code completion involves taking an (incomplete) source file, along with
1346c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * knowledge of where the user is actively editing that file, and suggesting
1347c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * syntactically- and semantically-valid constructs that the user might want to
1348c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * use at that particular point in the source code. These data structures and
1349c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines provide support for code completion.
1350c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1351c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1352c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
13531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1354c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
13550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result.
13560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
13570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion
13580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the
13590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected.
13600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which
13610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g.,
13620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of
13630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace
13640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
13651efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * description of the different kinds of chunks.
13660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
13670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString;
13681efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
13690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
13700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion.
13710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
13720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct {
13730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
13741efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief The kind of entity that this completion refers to.
13750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
13761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * The cursor kind will be a macro, keyword, or a declaration (one of the
13770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * *Decl cursor kinds), describing the entity that the completion is
13780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to.
13790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
13800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \todo In the future, we would like to provide a full cursor, to allow
13810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the client to extract additional information from declaration.
13820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
13830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  enum CXCursorKind CursorKind;
13841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
13851efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
13860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The code-completion string that describes how to insert this
13870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result into the editing buffer.
13880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
13890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionString CompletionString;
13900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult;
13910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
13920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
13930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string.
13940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
13951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Each "chunk" within a code-completion string (\c CXCompletionString) is
13961efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * either a piece of text with a specific "kind" that describes how that text
13970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string.
13980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
13990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind {
14000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A code-completion string that describes "optional" text that
14020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * could be a part of the template (but is not required).
14030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The Optional chunk is the only kind of chunk that has a code-completion
14051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * string for its representation, which is accessible via
14060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \c clang_getCompletionChunkCompletionString(). The code-completion string
14070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * describes an additional part of the template that is completely optional.
14080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * For example, optional chunks can be used to describe the placeholders for
14090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * arguments that match up with defaulted function parameters, e.g. given:
14100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
14120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * void f(int x, float y = 3.14, double z = 2.71828);
14130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
14140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The code-completion string for this function would contain:
14160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a TypedText chunk for "f".
14170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a LeftParen chunk for "(".
14180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a Placeholder chunk for "int x"
14190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
14200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Comma chunk for ","
142171570182471d502a97f7f175aa527152544c75f2Daniel Dunbar   *       - a Placeholder chunk for "float y"
14220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - an Optional chunk containing the last defaulted argument:
14230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Comma chunk for ","
14240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Placeholder chunk for "double z"
14250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a RightParen chunk for ")"
14260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
142771570182471d502a97f7f175aa527152544c75f2Daniel Dunbar   * There are many ways to handle Optional chunks. Two simple approaches are:
14280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Completely ignore optional chunks, in which case the template for the
14290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would only include the first parameter ("int x").
14300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Fully expand all optional chunks, in which case the template for the
14310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would have all of the parameters.
14320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Optional,
14340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that a user would be expected to type to get this
14361efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * code-completion result.
14370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14381efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * There will be exactly one "typed text" chunk in a semantic string, which
14391efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * will typically provide the spelling of a keyword or the name of a
14400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * declaration that could be used at the current code point. Clients are
14410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * expected to filter the code-completion results based on the text in this
14420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * chunk.
14430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_TypedText,
14450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that should be inserted as part of a code-completion result.
14470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "text" chunk represents text that is part of the template to be
14490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * inserted into user code should this particular code-completion result
14500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * be selected.
14510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Text,
14530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Placeholder text that should be replaced by the user.
14550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "placeholder" chunk marks a place where the user should insert text
14570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * into the code-completion template. For example, placeholders might mark
14580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the function parameters for a function declaration, to indicate that the
14590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * user should provide arguments for each of those parameters. The actual
14600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * text in a placeholder is a suggestion for the text to display before
14610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the user replaces the placeholder with real code.
14620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Placeholder,
14640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Informative text that should be displayed but never inserted as
14660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * part of the template.
14671efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   *
14680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * An "informative" chunk contains annotations that can be displayed to
14690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * help the user decide whether a particular code-completion result is the
14700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * right option, but which is not part of the actual template to be inserted
14710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * by code completion.
14720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Informative,
14740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that describes the current parameter when code-completion is
14760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to function call, message send, or template specialization.
14770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "current parameter" chunk occurs when code-completion is providing
14790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * information about a parameter corresponding to the argument at the
14800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion point. For example, given a function
14810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
14830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * int add(int x, int y);
14840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
14850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * and the source code \c add(, where the code-completion point is after the
14870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "(", the code-completion string will contain a "current parameter" chunk
14880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * for "int x", indicating that the current argument will initialize that
14890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * parameter. After typing further, to \c add(17, (where the code-completion
14901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * point is after the ","), the code-completion string will contain a
14910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "current paremeter" chunk to "int y".
14920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_CurrentParameter,
14940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left parenthesis ('('), used to initiate a function call or
14960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the beginning of a function parameter list.
14970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftParen,
14990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right parenthesis (')'), used to finish a function call or
15010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the end of a function parameter list.
15020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightParen,
15040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left bracket ('[').
15060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBracket,
15080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right bracket (']').
15100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBracket,
15120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left brace ('{').
15140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBrace,
15160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right brace ('}').
15180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBrace,
15200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left angle bracket ('<').
15220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftAngle,
15240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right angle bracket ('>').
15260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightAngle,
15280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A comma separator (',').
15300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
1531ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  CXCompletionChunk_Comma,
1532ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  /**
15331efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief Text that specifies the result type of a given result.
1534ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   *
1535ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * This special kind of informative chunk is not meant to be inserted into
15361efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * the text buffer. Rather, it is meant to illustrate the type that an
1537ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * expression using the given completion string would have.
1538ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   */
153901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_ResultType,
154001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
154101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A colon (':').
154201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
154301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Colon,
154401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
154501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A semicolon (';').
154601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
154701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_SemiColon,
154801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
154901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief An '=' sign.
155001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
155101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Equal,
155201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
155301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Horizontal space (' ').
155401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
155501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_HorizontalSpace,
155601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
155701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Vertical space ('\n'), after which it is generally a good idea to
155801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * perform indentation.
155901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
156001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_VerticalSpace
15610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor};
15621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
15630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string.
15650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
15670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
15690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number.
15710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
15721efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE enum CXCompletionChunkKind
15730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string,
15740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
15751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
15760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15771efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the text associated with a particular chunk within a
15780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string.
15790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
15810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
15830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number.
15850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
15862ef6f8f5a35a60870594c5b04e0aa2bf22c6886fTed KremenekCINDEX_LINKAGE CXString
15870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string,
15880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
15890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
15900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the completion string associated with a particular chunk
15920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string.
15930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
15950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
15970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index
15990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion
16000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string.
16010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
16020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString
16030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string,
16040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                                         unsigned chunk_number);
16051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
16060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
16070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string.
16080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
16090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned
16100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string);
16110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
16120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
1613ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion.
1614ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor *
1615ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as
16161efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * produced by \c clang_codeComplete. Its contents must be freed by
1617ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults.
1618ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
1619ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct {
1620ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
1621ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The code-completion results.
1622ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
1623ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  CXCompletionResult *Results;
1624ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1625ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
1626ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The number of code-completion results stored in the
1627ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \c Results array.
1628ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
1629ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  unsigned NumResults;
1630ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults;
1631ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1632ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
16330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file.
16340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and
16360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential
16370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model
16380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file,
16390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has
16400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed
16410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the
16421efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * current location in the C/Objective-C/C++ grammar and the state of
16430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are
1644ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure.
16450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the
16471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * user types punctuation characters or whitespace, at which point the
16480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p
16490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then
16500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">",
16510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that
16520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the
16530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results
16540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for
16550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after
16560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
16570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only
16580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface
1659ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion
16600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must
16610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency.
16620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code
16640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion.
16650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16668506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to
16678506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the
16688506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results
16698506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced.  NOTE: One can also specify NULL for this argument if the
16708506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args.
16710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in
16730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args.
16740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang
16761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * compiler to build the given source file. This should include all of the
16770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header
16781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * includes, etc., but should not include any information specific to
16790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion.
16800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
1681735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
1682735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files.
1683735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
1684735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
1685735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of
1686735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files.
1687735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
16880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion
16890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the
16901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source filename. However, the completion filename may also be a file
16911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * included by the source file, which is required when producing
16920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header.
16930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur.
16950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16961efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param complete_column the column at which code-completion should occur.
16970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that
16980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token.
16990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
1700936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * \param diag_callback callback function that will receive any diagnostics
1701936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * emitted while processing this source file. If NULL, diagnostics will be
1702936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * suppressed.
1703936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor *
1704936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * \param diag_client_data client data that will be passed to the diagnostic
1705936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * callback function.
1706936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor *
1707ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure
1708ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be
1709ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code
1710ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL.
1711ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
17121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE
17131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
1714ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *source_filename,
17151efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar                                          int num_command_line_args,
1716ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char **command_line_args,
1717ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned num_unsaved_files,
1718ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          struct CXUnsavedFile *unsaved_files,
1719ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *complete_filename,
1720ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_line,
1721a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                          unsigned complete_column);
17221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1723ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
1724ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results.
17250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
17261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE
1727ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
17281efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
172920d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/**
1730a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Determine the number of diagnostics produced prior to the
1731a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * location where code completion was performed.
1732a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
1733896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE
1734a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorunsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
1735a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1736a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
1737a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Retrieve a diagnostic associated with the given code completion.
1738a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor *
1739a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Result the code completion results to query.
1740a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Index the zero-based diagnostic number to retrieve.
1741a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor *
1742a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \returns the requested diagnostic. This diagnostic must be freed
1743a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * via a call to \c clang_disposeDiagnostic().
1744a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
1745896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE
1746a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
1747a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                             unsigned Index);
1748a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1749a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
175020d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @}
175120d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */
17521efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
17531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
175404bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/**
175504bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * \defgroup CINDEX_MISC Miscellaneous utility functions
175604bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek *
175704bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @{
175804bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */
175923e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek
176023e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek/**
176123e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek * \brief Return a version string, suitable for showing to a user, but not
176223e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek *        intended to be parsed (the format is not guaranteed to be stable).
176323e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek */
1764a2a9d6e4e5b6001b86b7dfc5db1ea296ce29a3d3Ted KremenekCINDEX_LINKAGE CXString clang_getClangVersion();
176504bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek
176604bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/**
176716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * \brief Return a version string, suitable for showing to a user, but not
176816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *        intended to be parsed (the format is not guaranteed to be stable).
176916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */
1770896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
1771896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek
177216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek /**
1773896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek  * \brief Visitor invoked for each file in a translation unit
177416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  *        (used with clang_getInclusions()).
177516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  *
177616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * This visitor function will be invoked by clang_getInclusions() for each
177716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * file included (either at the top-level or by #include directives) within
177816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * a translation unit.  The first argument is the file being included, and
177916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * the second and third arguments provide the inclusion stack.  The
178016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * array is sorted in order of immediate inclusion.  For example,
178116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * the first element refers to the location that included 'included_file'.
178216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  */
178316b55a71695a33c094383295cc7b7a2080e098daTed Kremenektypedef void (*CXInclusionVisitor)(CXFile included_file,
178416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                   CXSourceLocation* inclusion_stack,
178516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                   unsigned include_len,
178616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                   CXClientData client_data);
178716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek
178816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek/**
178916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * \brief Visit the set of preprocessor inclusions in a translation unit.
179016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *   The visitor function is called with the provided data for every included
179116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *   file.  This does not include headers included by the PCH file (unless one
179216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *   is inspecting the inclusions in the PCH file itself).
179316b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */
179416b55a71695a33c094383295cc7b7a2080e098daTed KremenekCINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
179516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                        CXInclusionVisitor visitor,
179616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                        CXClientData client_data);
179716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek
179816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek/**
179904bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @}
180004bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */
18011efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1802c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1803c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1804c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
18051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1806d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
1807d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
1808d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
1809d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
1810d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
1811