Index.h revision 0a812cf707da15dadd19fdeb0178b9707f4e01a6
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  /**
90735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief A null-terminated buffer containing the unsaved contents
91735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * of this file.
92735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
93735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Contents;
94735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
95735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
96735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief The length of the unsaved contents of this buffer, not
97735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * counting the NULL at the end of the buffer.
98735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
99735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  unsigned long Length;
100735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor};
101735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
1027f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1037f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \defgroup CINDEX_STRING String manipulation routines
1047f17376e0931a337d544b75d9030bc92763be287Douglas Gregor *
1057f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @{
1067f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
1071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1087f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1097f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A character string.
1107f17376e0931a337d544b75d9030bc92763be287Douglas Gregor *
1117f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * The \c CXString type is used to return strings from the interface when
1127f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * the ownership of that string might different from one call to the next.
1137f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * Use \c clang_getCString() to retrieve the string data and, once finished
1147f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * with the string data, call \c clang_disposeString() to free the string.
115ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */
116ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct {
117ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  const char *Spelling;
118ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  /* A 1 value indicates the clang_ indexing API needed to allocate the string
119ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff     (and it must be freed by clang_disposeString()). */
120ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  int MustFreeString;
121ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString;
122ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1237f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1247f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Retrieve the character data associated with the given string.
1257f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
126ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string);
127ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1287f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1297f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Free the given string,
1307f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
131ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string);
132ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
1337f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/**
1347f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @}
1357f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */
1361efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1371efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
138e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating
139e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options:
140e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
141e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
142e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration
1431efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * is one that belongs in the translation unit itself and not in a precompiled
144e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations
145e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated.
146e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
147b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example:
148b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
1490a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *   // excludeDeclsFromPCH = 1, displayDiagnostics=1
1500a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *   Idx = clang_createIndex(1, 1);
151b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
152b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // IndexTest.pch was produced with the following command:
153b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
154b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
155b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
156b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.pch'
1571efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
158002a528ab0189fc60cfbf9328962c96ccbe567eeDouglas Gregor *                       TranslationUnitVisitor, 0);
159b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
160b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
161b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.c', excluding symbols
162b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // from 'IndexTest.pch'.
163fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
164fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
165fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar *                                                  0, 0);
166b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
167b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor *                       TranslationUnitVisitor, 0);
168b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
169b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
170b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via
171b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
172b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler).
173e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
1740a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
1750a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor                                         int displayDiagnostics);
1760087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor
1770087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor/**
1780087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * \brief Destroy the given index.
1790087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor *
1800087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * The index must not be destroyed until all of the translation units created
1810087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * within that index have been destroyed.
1820087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor */
1838506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
1841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1851efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
1861efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Request that AST's be generated externally for API calls which parse
1878506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
1888506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
1898506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later
1908506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date.
1918506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
1928506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update.
1938506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value.
1948506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */
1958506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
1968506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                                      int value);
197f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
198c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_FILES File manipulation routines
199f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
200f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{
201f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
2021efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
203f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
204f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief A particular source file that is part of a translation unit.
205f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
206f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregortypedef void *CXFile;
2071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
208f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
209f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
210f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the complete file and path name of the given file.
21188145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */
21274844072411bae91d5dbb89955d200cbe1e0a1c8Ted KremenekCINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
2131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
214f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
215f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the last modification time of the given file.
216f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
21708b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
21888145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
2193c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/**
220b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a file handle within the given translation unit.
221b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
222b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param tu the translation unit
2231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar *
224b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param file_name the name of the file.
225b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
226b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns the file handle for the named file in the translation unit \p tu,
227b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * or a NULL file handle if the file was not a part of this translation unit.
228b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
2291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
230b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                    const char *file_name);
2311efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
232b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
233f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @}
234f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
235f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor
236f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
237f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \defgroup CINDEX_LOCATIONS Physical source locations
238f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
239f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * Clang represents physical source locations in its abstract syntax tree in
240f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * great detail, with file, line, and column information for the majority of
241f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * the tokens parsed in the source code. These data types and functions are
242f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * used to represent source location information, either for a particular
243f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * point in the program or for a range of points in the program, and extract
244f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * specific location information from those data types.
245f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor *
246f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{
247f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
2481efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
249f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
2501db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a specific source location within a translation
2511db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * unit.
2521db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
2531db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getInstantiationLocation() to map a source location to a
2541db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * particular file, line, and column.
2553c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */
2563c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct {
2575352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  void *ptr_data[2];
2581db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned int_data;
2593c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceLocation;
260fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
2613c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/**
262d52864bd33c66aacc84133460d8c9c0dfcdd5c18Daniel Dunbar * \brief Identifies a half-open character range in the source code.
2633c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor *
2641db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
2651db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * starting and end locations from a source range, respectively.
2663c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */
2673c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct {
2685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  void *ptr_data[2];
2691db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned begin_int_data;
2701db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor  unsigned end_int_data;
2713c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceRange;
272fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
2731db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
274b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a NULL (invalid) source location.
275b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
276b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
2771efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
278b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
279b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \determine Determine whether two source locations, which must refer into
2801efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * the same translation unit, refer to exactly the same point in the source
281b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * code.
282b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
283b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns non-zero if the source locations refer to the same location, zero
284b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * if they refer to different locations.
285b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
286b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
287b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                             CXSourceLocation loc2);
2881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
289b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
2901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieves the source location associated with a given file/line/column
2911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * in a particular translation unit.
292b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
293b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
294b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  CXFile file,
295b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  unsigned line,
296b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                                  unsigned column);
2971efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
298b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
2995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve a NULL (invalid) source range.
3005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getNullRange();
3025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
304b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a source range given the beginning and ending source
305b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * locations.
306b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */
307b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
308b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor                                            CXSourceLocation end);
3091efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
310b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/**
31146766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * \brief Retrieve the file, line, column, and offset represented by
31246766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * the given source location.
3131db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3141efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param location the location within a source file that will be decomposed
3151efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * into its parts.
3161db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3171efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param file [out] if non-NULL, will be set to the file to which the given
3181db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points.
3191db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3201efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param line [out] if non-NULL, will be set to the line to which the given
3211db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points.
3221db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor *
3231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param column [out] if non-NULL, will be set to the column to which the given
3241efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source location points.
32546766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor *
32646766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * \param offset [out] if non-NULL, will be set to the offset into the
32746766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * buffer to which the given source location points.
3281db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3291db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
3301db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   CXFile *file,
3311db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor                                                   unsigned *line,
33246766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor                                                   unsigned *column,
33346766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor                                                   unsigned *offset);
334e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor
335e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor/**
3361efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the first character within a
3371efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range.
3381db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3391db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
3401db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
3411db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/**
3421efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the last character within a
3431efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range.
3441db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */
3451db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
3461db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor
347f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/**
348f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @}
349f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */
350c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
351c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
3525352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \defgroup CINDEX_DIAG Diagnostic reporting
3535352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
3545352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @{
3555352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3565352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3575352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
3585352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Describes the severity of a particular diagnostic.
3595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3605352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorenum CXDiagnosticSeverity {
3615352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief A diagnostic that has been suppressed, e.g., by a command-line
3635352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * option.
3645352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3655352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Ignored = 0,
3665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic is a note that should be attached to the
3695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * previous (non-note) diagnostic.
3705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Note    = 1,
3725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic indicates suspicious code that may not be
3755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * wrong.
3765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Warning = 2,
3785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3805352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic indicates that the code is ill-formed.
3815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Error   = 3,
3835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief This diagnostic indicates that the code is ill-formed such
3865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * that future parser recovery is unlikely to produce useful
3875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * results.
3885352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
3895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXDiagnostic_Fatal   = 4
3905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor};
3915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
3925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
3935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Describes the kind of fix-it hint expressed within a
3945352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * diagnostic.
3955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
3965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorenum CXFixItKind {
3975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
3985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief A fix-it hint that inserts code at a particular position.
3995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
4005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXFixIt_Insertion   = 0,
4015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
4035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief A fix-it hint that removes code within a range.
4045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
4055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXFixIt_Removal     = 1,
4065352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  /**
4085352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * \brief A fix-it hint that replaces the code within a range with another
4095352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   * string.
4105352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor   */
4115352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor  CXFixIt_Replacement = 2
4125352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor};
4135352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4145352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
4155352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief A single diagnostic, containing the diagnostic's severity,
4165352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * location, text, source ranges, and fix-it hints.
4175352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
4185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregortypedef void *CXDiagnostic;
4195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
421a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Determine the number of diagnostics produced for the given
422a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * translation unit.
423a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
424a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
425a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
426a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
427a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Retrieve a diagnostic associated with the given translation unit.
4285352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
429a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Unit the translation unit to query.
430a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Index the zero-based diagnostic number to retrieve.
4315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
432a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \returns the requested diagnostic. This diagnostic must be freed
433a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * via a call to \c clang_disposeDiagnostic().
4345352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
435a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
436a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                                unsigned Index);
437a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
438a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
439a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Destroy a diagnostic.
440a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
441a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
4425352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
4435352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
4440a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Options to control the display of diagnostics.
4450a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4460a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * The values in this enum are meant to be combined to customize the
4470a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * behavior of \c clang_displayDiagnostic().
4480a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
4490a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregorenum CXDiagnosticDisplayOptions {
4500a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  /**
4510a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \brief Display the source-location information where the
4520a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * diagnostic was located.
4530a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4540a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * When set, diagnostics will be prefixed by the file, line, and
4550a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * (optionally) column to which the diagnostic refers. For example,
4560a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4570a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \code
4580a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * test.c:28: warning: extra tokens at end of #endif directive
4590a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \endcode
4600a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4610a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * This option corresponds to the clang flag \c -fshow-source-location.
4620a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   */
4630a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  CXDiagnostic_DisplaySourceLocation = 0x01,
4640a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4650a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  /**
4660a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \brief If displaying the source-location information of the
4670a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * diagnostic, also include the column number.
4680a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4690a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * This option corresponds to the clang flag \c -fshow-column.
4700a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   */
4710a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  CXDiagnostic_DisplayColumn = 0x02,
4720a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4730a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  /**
4740a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \brief If displaying the source-location information of the
4750a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * diagnostic, also include information about source ranges in a
4760a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * machine-parsable format.
4770a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   *
4780a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * This option corresponds to the clang flag
4790a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   * \c -fdiagnostics-print-source-range-info.
4800a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor   */
4810a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor  CXDiagnostic_DisplaySourceRanges = 0x04
4820a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor};
4830a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
4840a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
4850a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Display the given diagnostic by printing it to the given file.
4860a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4870a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * This routine will display the given diagnostic to a file, rendering
4880a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * the diagnostic according to the various options given. The
4890a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
4900a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * options that most closely mimics the behavior of the clang compiler.
4910a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4920a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \param Diagnostic The diagnostic to print.
4930a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4940a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \param File The file to print to (e.g., \c stderr).
4950a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
4960a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \param Options A set of options that control the diagnostic display,
4970a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * created by combining \c CXDiagnosticDisplayOptions values.
4980a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
4990a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE void clang_displayDiagnostic(CXDiagnostic Diagnostic,
5000a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor                                            FILE *File,
5010a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor                                            unsigned Options);
5020a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
5030a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
5040a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Retrieve the set of display options most similar to the
5050a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * default behavior of the clang compiler.
5060a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor *
5070a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \returns A set of display options suitable for use with \c
5080a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * clang_displayDiagnostic().
5090a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
5100a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
5110a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
5120a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
5130a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Print a diagnostic to the given file.
5140a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */
5150a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor
5160a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/**
5175352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Determine the severity of the given diagnostic.
5185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE enum CXDiagnosticSeverity
5205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticSeverity(CXDiagnostic);
5215352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5225352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5235352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the source location of the given diagnostic.
5245352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5255352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * This location is where Clang would print the caret ('^') when
5265352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * displaying the diagnostic on the command line.
5275352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5285352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
5295352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5305352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the text of the given diagnostic.
5325352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5335352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
534a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor
535a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor/**
536a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \brief Determine the number of source ranges associated with the given
537a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * diagnostic.
538a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor */
539a3890baf1256ff26081306c7fef70202f8223f41Douglas GregorCINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
5405352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5415352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
542a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \brief Retrieve a source range associated with the diagnostic.
5435352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
544a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * A diagnostic's source ranges highlight important elements in the source
5455352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * code. On the command line, Clang displays source ranges by
5465352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * underlining them with '~' characters.
5475352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
548a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \param Diagnostic the diagnostic whose range is being extracted.
5495352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
550a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \param Range the zero-based index specifying which range to
5515352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
552a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \returns the requested source range.
5535352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
554a3890baf1256ff26081306c7fef70202f8223f41Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
555a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor                                                      unsigned Range);
5565352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5575352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5585352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Determine the number of fix-it hints associated with the
5595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * given diagnostic.
5605352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5615352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
5625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5635352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5645352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the kind of the given fix-it.
5655352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param Diagnostic the diagnostic whose fix-its are being queried.
5675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param FixIt the zero-based index of the fix-it to query.
5695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE enum CXFixItKind
5715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticFixItKind(CXDiagnostic Diagnostic, unsigned FixIt);
5725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the insertion information for an insertion fix-it.
5755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * For a fix-it that describes an insertion into a text buffer,
5775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * retrieve the source location where the text should be inserted and
5785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * the text to be inserted.
5795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5805352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param Diagnostic the diagnostic whose fix-its are being queried.
5815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param FixIt the zero-based index of the insertion fix-it.
5835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param Location will be set to the location where text should be
5855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * inserted.
5865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \returns the text string to insert at the given location.
5885352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
5895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString
5905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticFixItInsertion(CXDiagnostic Diagnostic, unsigned FixIt,
5915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                  CXSourceLocation *Location);
5925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
5935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
5945352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the removal information for a removal fix-it.
5955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * For a fix-it that describes a removal from a text buffer, retrieve
5975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * the source range that should be removed.
5985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
5995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param Diagnostic the diagnostic whose fix-its are being queried.
6005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param FixIt the zero-based index of the removal fix-it.
6025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \returns a source range describing the text that should be removed
6045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * from the buffer.
6055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6065352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceRange
6075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticFixItRemoval(CXDiagnostic Diagnostic, unsigned FixIt);
6085352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6095352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6105352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the replacement information for an replacement fix-it.
6115352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6125352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * For a fix-it that describes replacement of text in the text buffer
6135352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * with alternative text.
6145352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6155352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param Diagnostic the diagnostic whose fix-its are being queried.
6165352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6175352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param FixIt the zero-based index of the replacement fix-it.
6185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param Range will be set to the source range whose text should be
6205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * replaced with the returned text.
6215352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6225352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \returns the text string to use as replacement text.
6235352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6245352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString
6255352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticFixItReplacement(CXDiagnostic Diagnostic, unsigned FixIt,
6265352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                    CXSourceRange *Range);
6275352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6285352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6295352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @}
6305352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6325352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6335352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
6345352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6355352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * The routines in this group provide the ability to create and destroy
6365352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * translation units from files, either by parsing the contents of the files or
6375352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * by reading in a serialized representation of a translation unit.
6385352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6395352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @{
6405352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6415352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6425352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6435352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Get the original translation unit source file name.
6445352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6455352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString
6465352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
6475352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6485352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6495352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Return the CXTranslationUnit for a given source file and the provided
6505352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * command line arguments one would pass to the compiler.
6515352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6525352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * Note: The 'source_filename' argument is optional.  If the caller provides a
6535352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * NULL pointer, the name of the source file is expected to reside in the
6545352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * specified command line arguments.
6555352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6565352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * Note: When encountered in 'clang_command_line_args', the following options
6575352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * are ignored:
6585352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-c'
6605352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-emit-ast'
6615352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-fsyntax-only'
6625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
6635352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6645352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6655352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param source_filename - The name of the source file to load, or NULL if the
6665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * source file is included in clang_command_line_args.
6675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
6695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * unsaved_files.
6705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
6725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * but may be required for code completion, including the contents of
6735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * those files.
6745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param diag_callback callback function that will receive any diagnostics
6765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * emitted while processing this source file. If NULL, diagnostics will be
6775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * suppressed.
6785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor *
6795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param diag_client_data client data that will be passed to the diagnostic
6805352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * callback function.
6815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
6835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         CXIndex CIdx,
6845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         const char *source_filename,
6855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         int num_clang_command_line_args,
6865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         const char **clang_command_line_args,
6875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor                                         unsigned num_unsaved_files,
688a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                         struct CXUnsavedFile *unsaved_files);
6895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Create a translation unit from an AST file (-emit-ast).
6925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
694a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                             const char *ast_filename);
6955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
6965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
6975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Destroy the specified CXTranslationUnit object.
6985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
6995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
7005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
7015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
7025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @}
7035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */
7045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor
7055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/**
706c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes the kind of entity that a cursor refers to.
707c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
708c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXCursorKind {
709c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Declarations */
710c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstDecl                     = 1,
7111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
712c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A declaration whose specific kind is not exposed via this
7131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * interface.
714c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
715c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed declarations have the same operations as any other kind
716c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of declaration; one can extract their location information,
717c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * spelling, find their definitions, etc. However, the specific kind
718c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of the declaration is not reported.
719c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
720c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedDecl                 = 1,
721c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C or C++ struct. */
7221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  CXCursor_StructDecl                    = 2,
723c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C or C++ union. */
724c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnionDecl                     = 3,
725c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A C++ class. */
726c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ClassDecl                     = 4,
727c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An enumeration. */
728c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_EnumDecl                      = 5,
7291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
730c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A field (in C) or non-static data member (in C++) in a
731c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * struct, union, or C++ class.
732c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
733c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FieldDecl                     = 6,
734c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An enumerator constant. */
735c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_EnumConstantDecl              = 7,
736c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A function. */
737c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FunctionDecl                  = 8,
738c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A variable. */
739c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_VarDecl                       = 9,
740c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A function or method parameter. */
741c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ParmDecl                      = 10,
742c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @interface. */
743c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCInterfaceDecl             = 11,
744c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @interface for a category. */
745c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCCategoryDecl              = 12,
746c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @protocol declaration. */
747c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCProtocolDecl              = 13,
748c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @property declaration. */
749c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCPropertyDecl              = 14,
750c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C instance variable. */
751c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCIvarDecl                  = 15,
752c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C instance method. */
753c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCInstanceMethodDecl        = 16,
754c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C class method. */
755c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCClassMethodDecl           = 17,
756c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @implementation. */
757c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCImplementationDecl        = 18,
758c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An Objective-C @implementation for a category. */
759c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCCategoryImplDecl          = 19,
760c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief A typedef */
761c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TypedefDecl                   = 20,
762c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastDecl                      = 20,
7631efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
764c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* References */
765c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstRef                      = 40, /* Decl references */
7661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  CXCursor_ObjCSuperClassRef             = 40,
767c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCProtocolRef               = 41,
768c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCClassRef                  = 42,
769c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
770c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A reference to a type declaration.
771c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
772c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * A type reference occurs anywhere where a type is named but not
773c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * declared. For example, given:
774c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
775c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \code
776c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * typedef unsigned size_type;
777c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * size_type size;
778c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \endcode
779c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
780c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
781c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * while the type of the variable "size" is referenced. The cursor
782c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * referenced by the type of size is the typedef for size_type.
783c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
784c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_TypeRef                       = 43,
785c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastRef                       = 43,
7861efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
787c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Error conditions */
788c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstInvalid                  = 70,
789c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_InvalidFile                   = 70,
790c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_NoDeclFound                   = 71,
791c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_NotImplemented                = 72,
792c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastInvalid                   = 72,
7931efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
794c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Expressions */
795c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstExpr                     = 100,
7961efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
797c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
798c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression whose specific kind is not exposed via this
7991efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * interface.
800c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
801c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed expressions have the same operations as any other kind
802c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * of expression; one can extract their location information,
803c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * spelling, children, etc. However, the specific kind of the
804c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * expression is not reported.
805c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
806c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedExpr                 = 100,
8071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
808c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
809c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression that refers to some value declaration, such
810c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * as a function, varible, or enumerator.
811c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
812c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_DeclRefExpr                   = 101,
8131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
814c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
815c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief An expression that refers to a member of a struct, union,
816c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * class, Objective-C class, etc.
817c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
818c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_MemberRefExpr                 = 102,
8191efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
820c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An expression that calls a function. */
821c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_CallExpr                      = 103,
8221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
823c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /** \brief An expression that sends a message to an Objective-C
824c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   object or class. */
825c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_ObjCMessageExpr               = 104,
826c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastExpr                      = 104,
8271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
828c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /* Statements */
829c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_FirstStmt                     = 200,
830c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
831c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief A statement whose specific kind is not exposed via this
832c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * interface.
833c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
834c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * Unexposed statements have the same operations as any other kind of
835c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * statement; one can extract their location information, spelling,
836c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * children, etc. However, the specific kind of the statement is not
837c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * reported.
838c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
839c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_UnexposedStmt                 = 200,
840c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXCursor_LastStmt                      = 200,
8411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
842c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
843c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Cursor that represents the translation unit itself.
844c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   *
845c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * The translation unit cursor exists primarily to act as the root
846c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * cursor for traversing the contents of a translation unit.
847c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
848e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_TranslationUnit               = 300,
849e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
850e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  /* Attributes */
851e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_FirstAttr                     = 400,
852e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  /**
853e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek   * \brief An attribute whose specific kind is not exposed via this
854e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek   * interface.
855e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek   */
856e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_UnexposedAttr                 = 400,
857e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
858e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_IBActionAttr                  = 401,
859e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_IBOutletAttr                  = 402,
860e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor_LastAttr                      = CXCursor_IBOutletAttr
861c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor};
862c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
863c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
864c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A cursor representing some element in the abstract syntax tree for
865c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a translation unit.
866c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
8671efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The cursor abstraction unifies the different kinds of entities in a
868c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * program--declaration, statements, expressions, references to declarations,
869c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * etc.--under a single "cursor" abstraction with a common set of operations.
870c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Common operation for a cursor include: getting the physical location in
871c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a source file where the cursor points, getting the name associated with a
872c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor, and retrieving cursors for any child nodes of a particular cursor.
873c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
874c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors can be produced in two specific ways.
875c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
876c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * from which one can use clang_visitChildren() to explore the rest of the
877c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * translation unit. clang_getCursor() maps from a physical source location
878c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to the entity that resides at that location, allowing one to map from the
879c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * source code into the AST.
880c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
881c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef struct {
882c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  enum CXCursorKind kind;
883c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  void *data[3];
8841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar} CXCursor;
885c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
886c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
887c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
888c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
889c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
890c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
8911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
892c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
893c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the NULL cursor, which represents no entity.
894c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
895c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getNullCursor(void);
8961efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
897c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
898c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the cursor that represents the given translation unit.
899c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
900c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor can be used to start traversing the
901c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * various declarations within the given translation unit.
902c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
903c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
904c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
905c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
906c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether two cursors are equivalent.
907c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
908c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
9091efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
910c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
911c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the kind of the given cursor.
912c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
913c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
914c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
915c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
916c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a declaration.
917c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
918c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
919c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
920c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
921c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a simple
922c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reference.
923c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
924c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Note that other kinds of cursors (such as expressions) can also refer to
925c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * other cursors. Use clang_getCursorReferenced() to determine whether a
926c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * particular cursor refers to another entity.
927c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
928c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
929c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
930c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
931c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents an expression.
932c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
933c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
934c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
935c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
936c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a statement.
937c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
938c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
939c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
940c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
9411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents an invalid
942c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor.
9431efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar */
944c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
945c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
946c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
9471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents a translation
9481efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unit.
949c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
950c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
9511efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
952c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
953c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
954c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
9551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
956c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
957c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
958c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
959c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors represent a location within the Abstract Syntax Tree (AST). These
960c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines help map between cursors and the physical locations where the
961c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * described entities occur in the source code. The mapping is provided in
962c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * both directions, so one can map from source code to the AST and back.
963c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
964c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
96550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
9661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
9676a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
968b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Map a source location to the cursor that describes the entity at that
969b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * location in the source code.
970b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
971b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() maps an arbitrary source location within a translation
972b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * unit down to the most specific cursor that describes the entity at that
9731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * location. For example, given an expression \c x + y, invoking
974b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() with a source location pointing to "x" will return the
9751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * cursor for "x"; similarly for "y". If the cursor points anywhere between
976b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
977b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * will return a cursor referring to the "+" expression.
978b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor *
979b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns a cursor representing the entity at the given source location, or
980b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * a NULL cursor if no such entity can be found.
9816a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
982b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
9831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
98498258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor/**
98598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * \brief Retrieve the physical location of the source constructor referenced
98698258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * by the given cursor.
98798258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor *
98898258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * The location of a declaration is typically the location of the name of that
9891efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * declaration, where the name of that declaration would occur if it is
9901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unnamed, or some keyword that introduces that particular declaration.
9911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The location of a reference is where that reference occurs within the
99298258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * source code.
99398258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor */
99498258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
995c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
996b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/**
997b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Retrieve the physical extent of the source construct referenced by
998a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the given cursor.
999a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor *
1000a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * The extent of a cursor starts with the file/line/column pointing at the
1001a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * first character within the source construct that the cursor refers to and
10021efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * ends with the last character withinin that source construct. For a
1003a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * declaration, the extent covers the declaration itself. For a reference,
1004a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the extent covers the location of the reference (e.g., where the referenced
1005a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * entity was actually used).
1006a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor */
1007a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
1008c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor
1009c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1010c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1011c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1013c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1014c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
1015c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1016c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines provide the ability to traverse the abstract syntax tree
1017c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * using cursors.
1018c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1019c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1020c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1022c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1023c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes how the traversal of the children of a particular
1024c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor should proceed after visiting a particular child cursor.
1025c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1026c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A value of this enumeration type should be returned by each
1027c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
1028c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1029c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXChildVisitResult {
1030c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
10311efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief Terminates the cursor traversal.
1032c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
1033c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Break,
10341efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
1035c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Continues the cursor traversal with the next sibling of
1036c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * the cursor just visited, without visiting its children.
1037c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
1038c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Continue,
1039c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  /**
1040c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * \brief Recursively traverse the children of this cursor, using
1041c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   * the same visitor and client data.
1042c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor   */
1043c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor  CXChildVisit_Recurse
1044c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor};
1045c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1046c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1047c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visitor invoked for each cursor found by a traversal.
1048c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1049c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This visitor function will be invoked for each cursor found by
1050c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). Its first argument is the cursor being
1051c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited, its second argument is the parent visitor for that cursor,
1052c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and its third argument is the client data provided to
1053c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren().
1054c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1055c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The visitor should return one of the \c CXChildVisitResult values
1056c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to direct clang_visitCursorChildren().
1057c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10581efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbartypedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
10591efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar                                                   CXCursor parent,
1060c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                                   CXClientData client_data);
1061c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1062c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1063c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visit the children of a particular cursor.
1064c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1065c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This function visits all the direct children of the given cursor,
1066c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * invoking the given \p visitor function with the cursors of each
1067c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited child. The traversal may be recursive, if the visitor returns
1068c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
1069c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the visitor returns \c CXChildVisit_Break.
1070c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1071c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param parent the cursor whose child may be visited. All kinds of
1072a57259e9d7b30bcce93f0a62eee0488738026172Daniel Dunbar * cursors can be visited, including invalid cursors (which, by
1073c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * definition, have no children).
1074c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1075c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param visitor the visitor function that will be invoked for each
1076c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * child of \p parent.
1077c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1078c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param client_data pointer data supplied by the client, which will
1079c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be passed to the visitor each time it is invoked.
1080c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1081c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \returns a non-zero value if the traversal was terminated
1082c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * prematurely by the visitor returning \c CXChildVisit_Break.
1083c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
1085c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                            CXCursorVisitor visitor,
1086c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor                                            CXClientData client_data);
10871efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1088c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1089c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1090c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
10911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1092c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1093c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
1094c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
10951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * These routines provide the ability to determine references within and
1096c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * across translation units, by providing the names of the entities referenced
1097c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by cursors, follow reference cursors to the declarations they reference,
1098c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and associate declarations with their definitions.
1099c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1100c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1101c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
11021efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1103c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1104c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
1105c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by the given cursor.
1106c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1107c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A Unified Symbol Resolution (USR) is a string that identifies a particular
1108c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * entity (function, class, variable, etc.) within a program. USRs can be
1109c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * compared across translation units to determine, e.g., when references in
1110c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * one translation refer to an entity defined in another translation unit.
1111c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1112c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
1113c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1114c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1115c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a name for the entity referenced by this cursor.
1116c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
1117c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
1118c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor
1119c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor/** \brief For a cursor that is a reference, retrieve a cursor representing the
1120c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * entity that it references.
1121c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor *
1122c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Reference cursors refer to other entities in the AST. For example, an
1123c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Objective-C superclass reference cursor refers to an Objective-C class.
11241efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This function produces the cursor for the Objective-C class from the
1125c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * cursor for the superclass reference. If the input cursor is a declaration or
1126c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * definition, it returns that declaration or definition unchanged.
11271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Otherwise, returns the NULL cursor.
1128c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor */
1129c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
1130b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
11311efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
1132b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \brief For a cursor that is either a reference to or a declaration
1133b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  of some entity, retrieve a cursor that describes the definition of
1134b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  that entity.
1135b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1136b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  Some entities can be declared multiple times within a translation
1137b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  unit, but only one of those declarations can also be a
1138b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  definition. For example, given:
1139b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1140b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \code
1141b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int, int);
1142b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int g(int x, int y) { return f(x, y); }
1143b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int a, int b) { return a + b; }
1144b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  int f(int, int);
1145b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  \endcode
1146b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1147b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  there are three declarations of the function "f", but only the
1148b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  second one is a definition. The clang_getCursorDefinition()
1149b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  function will take any cursor pointing to a declaration of "f"
1150b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  (the first or fourth lines of the example) or a cursor referenced
1151b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  that uses "f" (the call to "f' inside "g") and will return a
1152b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  declaration cursor pointing to the definition (the second "f"
1153b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  declaration).
1154b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *
1155b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  If given a cursor for which there is no corresponding definition,
1156b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  e.g., because there is no definition of that entity within this
1157b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor *  translation unit, returns a NULL cursor.
1158b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */
1159b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
1160b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
11611efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/**
1162b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Determine whether the declaration pointed to by this cursor
1163b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * is also a definition of that entity.
1164b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */
1165b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
1166b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor
1167c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1168c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1169c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
11701efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1171c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
11720045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * \defgroup CINDEX_LEX Token extraction and manipulation
11730045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *
11740045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * The routines in this group provide access to the tokens within a
11750045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * translation unit, along with a semantic mapping of those tokens to
11760045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * their corresponding cursors.
1177fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1178fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @{
1179fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1180fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1181fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1182fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a kind of token.
1183fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1184fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef enum CXTokenKind {
1185fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1186fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief A token that contains some kind of punctuation.
1187fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1188fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Punctuation,
1189fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1190fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
11910045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor   * \brief A language keyword.
1192fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1193fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Keyword,
1194fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1195fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1196fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief An identifier (that is not a keyword).
1197fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1198fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Identifier,
1199fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1200fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1201fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief A numeric, string, or character literal.
1202fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1203fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Literal,
1204fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1205fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  /**
1206fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   * \brief A comment.
1207fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor   */
1208fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  CXToken_Comment
1209fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXTokenKind;
1210fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1211fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1212fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a single preprocessing token.
1213fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1214fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef struct {
1215fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  unsigned int_data[4];
1216fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor  void *ptr_data;
1217fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXToken;
1218fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1219fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1220fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the kind of the given token.
1221fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1222fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
1223fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1224fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1225fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the spelling of the given token.
1226fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1227fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * The spelling of a token is the textual representation of that token, e.g.,
1228fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * the text of an identifier or keyword.
1229fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1230fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
1231fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1232fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1233fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve the source location of the given token.
1234fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1235fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
1236fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                                       CXToken);
1237fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1238fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1239fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve a source range that covers the given token.
1240fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1241fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
1242fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1243fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1244fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Tokenize the source code described by the given range into raw
1245fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * lexical tokens.
1246fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1247fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit whose text is being tokenized.
1248fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1249fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Range the source range in which text should be tokenized. All of the
1250fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * tokens produced by tokenization will fall within this source range,
1251fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1252fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens this pointer will be set to point to the array of tokens
1253fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that occur within the given source range. The returned pointer must be
1254fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * freed with clang_disposeTokens() before the translation unit is destroyed.
1255fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1256fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens will be set to the number of tokens in the \c *Tokens
1257fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * array.
1258fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1259fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1260fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
1261fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                   CXToken **Tokens, unsigned *NumTokens);
1262fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1263fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1264fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Annotate the given set of tokens by providing cursors for each token
1265fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that can be mapped to a specific entity within the abstract syntax tree.
1266fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
12670045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * This token-annotation routine is equivalent to invoking
12680045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() for the source locations of each of the
12690045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * tokens. The cursors provided are filtered, so that only those
12700045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * cursors that have a direct correspondence to the token are
12710045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * accepted. For example, given a function call \c f(x),
12720045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() would provide the following cursors:
12730045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *
12740045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *   * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
12750045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *   * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
12760045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *   * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
12770045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor *
12780045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * Only the first and last of these cursors will occur within the
12790045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * annotate, since the tokens "f" and "x' directly refer to a function
12800045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * and a variable, respectively, but the parentheses are just a small
12810045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * part of the full syntax of the function call expression, which is
12820045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * not provided as an annotation.
1283fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1284fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit that owns the given tokens.
1285fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1286fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens the set of tokens to annotate.
1287fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1288fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens the number of tokens in \p Tokens.
1289fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor *
1290fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Cursors an array of \p NumTokens cursors, whose contents will be
1291fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * replaced with the cursors corresponding to each token.
1292fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1293fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
1294fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                         CXToken *Tokens, unsigned NumTokens,
1295fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                         CXCursor *Cursors);
1296fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1297fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1298fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Free the given set of tokens.
1299fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1300fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
1301fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor                                        CXToken *Tokens, unsigned NumTokens);
1302fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1303fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1304fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @}
1305fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */
1306fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor
1307fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/**
1308c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_DEBUG Debugging facilities
1309c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1310c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines are used for testing and debugging, only, and should not
1311c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be relied upon.
1312c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1313c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1314c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
13151efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
13164ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
1317e68fff6fc083c6270d835216a3de0b82c6ef0310Ted KremenekCINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
13181efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
13191efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar                                          const char **startBuf,
13204ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
13214ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
13224ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
13234ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
13244ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
13250a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE void clang_enableStackTraces(void);
13260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
1327c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1328c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
13291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1330c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1331c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CODE_COMPLET Code completion
1332c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1333c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Code completion involves taking an (incomplete) source file, along with
1334c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * knowledge of where the user is actively editing that file, and suggesting
1335c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * syntactically- and semantically-valid constructs that the user might want to
1336c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * use at that particular point in the source code. These data structures and
1337c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines provide support for code completion.
1338c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor *
1339c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{
1340c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
13411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1342c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
13430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result.
13440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
13450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion
13460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the
13470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected.
13480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which
13490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g.,
13500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of
13510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace
13520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
13531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * description of the different kinds of chunks.
13540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
13550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString;
13561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
13570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
13580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion.
13590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
13600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct {
13610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
13621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief The kind of entity that this completion refers to.
13630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
13641efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * The cursor kind will be a macro, keyword, or a declaration (one of the
13650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * *Decl cursor kinds), describing the entity that the completion is
13660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to.
13670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
13680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \todo In the future, we would like to provide a full cursor, to allow
13690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the client to extract additional information from declaration.
13700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
13710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  enum CXCursorKind CursorKind;
13721efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
13731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar  /**
13740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The code-completion string that describes how to insert this
13750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result into the editing buffer.
13760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
13770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionString CompletionString;
13780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult;
13790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
13800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
13810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string.
13820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
13831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Each "chunk" within a code-completion string (\c CXCompletionString) is
13841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * either a piece of text with a specific "kind" that describes how that text
13850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string.
13860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
13870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind {
13880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
13890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A code-completion string that describes "optional" text that
13900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * could be a part of the template (but is not required).
13910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
13920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The Optional chunk is the only kind of chunk that has a code-completion
13931efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * string for its representation, which is accessible via
13940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \c clang_getCompletionChunkCompletionString(). The code-completion string
13950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * describes an additional part of the template that is completely optional.
13960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * For example, optional chunks can be used to describe the placeholders for
13970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * arguments that match up with defaulted function parameters, e.g. given:
13980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
13990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
14000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * void f(int x, float y = 3.14, double z = 2.71828);
14010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
14020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The code-completion string for this function would contain:
14040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a TypedText chunk for "f".
14050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a LeftParen chunk for "(".
14060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a Placeholder chunk for "int x"
14070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
14080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Comma chunk for ","
140971570182471d502a97f7f175aa527152544c75f2Daniel Dunbar   *       - a Placeholder chunk for "float y"
14100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - an Optional chunk containing the last defaulted argument:
14110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Comma chunk for ","
14120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Placeholder chunk for "double z"
14130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a RightParen chunk for ")"
14140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
141571570182471d502a97f7f175aa527152544c75f2Daniel Dunbar   * There are many ways to handle Optional chunks. Two simple approaches are:
14160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Completely ignore optional chunks, in which case the template for the
14170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would only include the first parameter ("int x").
14180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Fully expand all optional chunks, in which case the template for the
14190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would have all of the parameters.
14200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Optional,
14220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that a user would be expected to type to get this
14241efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * code-completion result.
14250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * There will be exactly one "typed text" chunk in a semantic string, which
14271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * will typically provide the spelling of a keyword or the name of a
14280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * declaration that could be used at the current code point. Clients are
14290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * expected to filter the code-completion results based on the text in this
14300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * chunk.
14310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_TypedText,
14330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that should be inserted as part of a code-completion result.
14350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "text" chunk represents text that is part of the template to be
14370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * inserted into user code should this particular code-completion result
14380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * be selected.
14390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Text,
14410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Placeholder text that should be replaced by the user.
14430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "placeholder" chunk marks a place where the user should insert text
14450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * into the code-completion template. For example, placeholders might mark
14460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the function parameters for a function declaration, to indicate that the
14470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * user should provide arguments for each of those parameters. The actual
14480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * text in a placeholder is a suggestion for the text to display before
14490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the user replaces the placeholder with real code.
14500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Placeholder,
14520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Informative text that should be displayed but never inserted as
14540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * part of the template.
14551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   *
14560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * An "informative" chunk contains annotations that can be displayed to
14570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * help the user decide whether a particular code-completion result is the
14580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * right option, but which is not part of the actual template to be inserted
14590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * by code completion.
14600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Informative,
14620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that describes the current parameter when code-completion is
14640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to function call, message send, or template specialization.
14650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "current parameter" chunk occurs when code-completion is providing
14670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * information about a parameter corresponding to the argument at the
14680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion point. For example, given a function
14690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
14710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * int add(int x, int y);
14720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
14730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
14740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * and the source code \c add(, where the code-completion point is after the
14750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "(", the code-completion string will contain a "current parameter" chunk
14760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * for "int x", indicating that the current argument will initialize that
14770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * parameter. After typing further, to \c add(17, (where the code-completion
14781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * point is after the ","), the code-completion string will contain a
14790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "current paremeter" chunk to "int y".
14800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_CurrentParameter,
14820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left parenthesis ('('), used to initiate a function call or
14840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the beginning of a function parameter list.
14850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftParen,
14870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right parenthesis (')'), used to finish a function call or
14890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the end of a function parameter list.
14900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightParen,
14920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left bracket ('[').
14940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBracket,
14960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
14970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right bracket (']').
14980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
14990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBracket,
15000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left brace ('{').
15020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBrace,
15040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right brace ('}').
15060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBrace,
15080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left angle bracket ('<').
15100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftAngle,
15120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right angle bracket ('>').
15140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
15150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightAngle,
15160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
15170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A comma separator (',').
15180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
1519ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  CXCompletionChunk_Comma,
1520ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  /**
15211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * \brief Text that specifies the result type of a given result.
1522ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   *
1523ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * This special kind of informative chunk is not meant to be inserted into
15241efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar   * the text buffer. Rather, it is meant to illustrate the type that an
1525ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * expression using the given completion string would have.
1526ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   */
152701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_ResultType,
152801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
152901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A colon (':').
153001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
153101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Colon,
153201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
153301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A semicolon (';').
153401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
153501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_SemiColon,
153601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
153701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief An '=' sign.
153801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
153901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Equal,
154001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
154101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Horizontal space (' ').
154201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
154301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_HorizontalSpace,
154401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
154501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Vertical space ('\n'), after which it is generally a good idea to
154601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * perform indentation.
154701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
154801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_VerticalSpace
15490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor};
15501efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
15510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string.
15530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
15550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
15570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number.
15590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
15601efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE enum CXCompletionChunkKind
15610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string,
15620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
15631efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
15640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15651efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the text associated with a particular chunk within a
15660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string.
15670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
15690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
15710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number.
15730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
15742ef6f8f5a35a60870594c5b04e0aa2bf22c6886fTed KremenekCINDEX_LINKAGE CXString
15750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string,
15760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
15770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
15780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15791efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the completion string associated with a particular chunk
15800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string.
15810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
15830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
15850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
15860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index
15870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion
15880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string.
15890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
15900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString
15910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string,
15920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                                         unsigned chunk_number);
15931efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
15940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
15950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string.
15960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
15970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned
15980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string);
15990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
16000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
1601ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion.
1602ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor *
1603ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as
16041efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * produced by \c clang_codeComplete. Its contents must be freed by
1605ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults.
1606ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
1607ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct {
1608ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
1609ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The code-completion results.
1610ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
1611ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  CXCompletionResult *Results;
1612ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1613ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
1614ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The number of code-completion results stored in the
1615ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \c Results array.
1616ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
1617ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  unsigned NumResults;
1618ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults;
1619ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
1620ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
16210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file.
16220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and
16240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential
16250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model
16260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file,
16270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has
16280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed
16290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the
16301efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * current location in the C/Objective-C/C++ grammar and the state of
16310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are
1632ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure.
16330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the
16351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * user types punctuation characters or whitespace, at which point the
16360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p
16370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then
16380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">",
16390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that
16400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the
16410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results
16420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for
16430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after
16440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
16450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only
16460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface
1647ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion
16480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must
16490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency.
16500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code
16520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion.
16530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16548506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to
16558506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the
16568506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results
16578506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced.  NOTE: One can also specify NULL for this argument if the
16588506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args.
16590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in
16610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args.
16620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang
16641efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * compiler to build the given source file. This should include all of the
16650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header
16661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * includes, etc., but should not include any information specific to
16670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion.
16680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
1669735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
1670735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files.
1671735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
1672735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
1673735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of
1674735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files.
1675735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
16760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion
16770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the
16781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source filename. However, the completion filename may also be a file
16791efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * included by the source file, which is required when producing
16800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header.
16810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur.
16830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
16841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param complete_column the column at which code-completion should occur.
16850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that
16860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token.
16870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
1688936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * \param diag_callback callback function that will receive any diagnostics
1689936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * emitted while processing this source file. If NULL, diagnostics will be
1690936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * suppressed.
1691936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor *
1692936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * \param diag_client_data client data that will be passed to the diagnostic
1693936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * callback function.
1694936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor *
1695ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure
1696ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be
1697ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code
1698ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL.
1699ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
17001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE
17011efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
1702ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *source_filename,
17031efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar                                          int num_command_line_args,
1704ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char **command_line_args,
1705ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned num_unsaved_files,
1706ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          struct CXUnsavedFile *unsaved_files,
1707ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *complete_filename,
1708ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_line,
1709a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                          unsigned complete_column);
17101efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1711ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
1712ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results.
17130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
17141efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE
1715ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
17161efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
171720d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/**
1718a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Determine the number of diagnostics produced prior to the
1719a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * location where code completion was performed.
1720a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
1721a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE
1722a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorunsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
1723a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1724a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
1725a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Retrieve a diagnostic associated with the given code completion.
1726a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor *
1727a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Result the code completion results to query.
1728a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Index the zero-based diagnostic number to retrieve.
1729a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor *
1730a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \returns the requested diagnostic. This diagnostic must be freed
1731a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * via a call to \c clang_disposeDiagnostic().
1732a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
1733a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE
1734a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
1735a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor                                             unsigned Index);
1736a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1737a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
173820d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @}
173920d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */
17401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
17411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
174204bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/**
174304bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * \defgroup CINDEX_MISC Miscellaneous utility functions
174404bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek *
174504bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @{
174604bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */
174723e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek
174823e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek/**
174923e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek * \brief Return a version string, suitable for showing to a user, but not
175023e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek *        intended to be parsed (the format is not guaranteed to be stable).
175123e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek */
1752a2a9d6e4e5b6001b86b7dfc5db1ea296ce29a3d3Ted KremenekCINDEX_LINKAGE CXString clang_getClangVersion();
175304bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek
175404bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/**
175516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * \brief Return a version string, suitable for showing to a user, but not
175616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *        intended to be parsed (the format is not guaranteed to be stable).
175716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */
175816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek
175916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek
176016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek /**
176116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * \brief Visitor invoked for each file in a translation unit
176216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  *        (used with clang_getInclusions()).
176316b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  *
176416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * This visitor function will be invoked by clang_getInclusions() for each
176516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * file included (either at the top-level or by #include directives) within
176616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * a translation unit.  The first argument is the file being included, and
176716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * the second and third arguments provide the inclusion stack.  The
176816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * array is sorted in order of immediate inclusion.  For example,
176916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  * the first element refers to the location that included 'included_file'.
177016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek  */
177116b55a71695a33c094383295cc7b7a2080e098daTed Kremenektypedef void (*CXInclusionVisitor)(CXFile included_file,
177216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                   CXSourceLocation* inclusion_stack,
177316b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                   unsigned include_len,
177416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                   CXClientData client_data);
177516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek
177616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek/**
177716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * \brief Visit the set of preprocessor inclusions in a translation unit.
177816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *   The visitor function is called with the provided data for every included
177916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *   file.  This does not include headers included by the PCH file (unless one
178016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek *   is inspecting the inclusions in the PCH file itself).
178116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */
178216b55a71695a33c094383295cc7b7a2080e098daTed KremenekCINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
178316b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                        CXInclusionVisitor visitor,
178416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek                                        CXClientData client_data);
178516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek
178616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek/**
178704bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @}
178804bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */
17891efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1790c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/**
1791c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @}
1792c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */
17931efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar
1794d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
1795d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
1796d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
1797d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
1798d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
1799