Index.h revision 0045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0
1d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\ 2d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 3d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* The LLVM Compiler Infrastructure *| 4d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 5d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This file is distributed under the University of Illinois Open Source *| 6d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* License. See LICENSE.TXT for details. *| 7d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 8d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*===----------------------------------------------------------------------===*| 9d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 10d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This header provides a public inferface to a Clang library for extracting *| 11d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* high-level symbol information from source files without exposing the full *| 12d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* Clang C++ API. *| 13d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 14d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek\*===----------------------------------------------------------------------===*/ 15d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 16d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifndef CLANG_C_INDEX_H 17d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#define CLANG_C_INDEX_H 18d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 1988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff#include <sys/stat.h> 203d31560343856c573376a04558a7111e7afad4f7Chandler Carruth#include <time.h> 2188145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff 22d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus 23d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenekextern "C" { 24d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif 25d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 2688145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/* MSVC DLL import/export. */ 272e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#ifdef _MSC_VER 282e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #ifdef _CINDEX_LIB_ 292e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #define CINDEX_LINKAGE __declspec(dllexport) 302e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #else 312e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #define CINDEX_LINKAGE __declspec(dllimport) 322e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #endif 332e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#else 342e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #define CINDEX_LINKAGE 352e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#endif 362e06fc877a633abea3b40a64950c7316dac29ca8John Thompson 3720d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/** \defgroup CINDEX C Interface to Clang 3820d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * 391efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The C Interface to Clang provides a relatively small API that exposes 40f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities for parsing source code into an abstract syntax tree (AST), 41f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * loading already-parsed ASTs, traversing the AST, associating 42f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * physical source locations with elements within the AST, and other 43f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities that support Clang-based development tools. 44f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 451efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This C interface to Clang will never provide all of the information 46f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * representation stored in Clang's C++ AST, nor should it: the intent is to 47f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * maintain an API that is relatively stable from one release to the next, 48f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * providing only the basic functionality needed to support development tools. 491efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * 501efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * To avoid namespace pollution, data types are prefixed with "CX" and 51f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * functions are prefixed with "clang_". 5220d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * 5320d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @{ 5420d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */ 551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 567f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 577f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief An "index" that consists of a set of translation units that would 587f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * typically be linked together into an executable or library. 597f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 607f17376e0931a337d544b75d9030bc92763be287Douglas Gregortypedef void *CXIndex; 61600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff 627f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 637f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A single translation unit, which resides in an index. 647f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 6550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXTranslationUnit; /* A translation unit instance. */ 66600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff 677f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 68c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Opaque pointer representing client data that will be passed through 69c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to various callbacks and visitors. 707f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 71c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef void *CXClientData; 721efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 73735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor/** 74735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief Provides the contents of a file that has not yet been saved to disk. 75735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 76735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * Each CXUnsavedFile instance provides the name of a file on the 77735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * system along with the current contents of that file that have not 78735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * yet been saved to disk. 79735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 80735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregorstruct CXUnsavedFile { 811efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief The file whose contents have not yet been saved. 83735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 84735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * This file must already exist in the file system. 85735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 86735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor const char *Filename; 87735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor 881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 89735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief A null-terminated buffer containing the unsaved contents 90735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * of this file. 91735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 92735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor const char *Contents; 93735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor 94735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor /** 95735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief The length of the unsaved contents of this buffer, not 96735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * counting the NULL at the end of the buffer. 97735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 98735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor unsigned long Length; 99735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor}; 100735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor 1017f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1027f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \defgroup CINDEX_STRING String manipulation routines 1037f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * 1047f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @{ 1057f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 1061efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1077f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1087f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A character string. 1097f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * 1107f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * The \c CXString type is used to return strings from the interface when 1117f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * the ownership of that string might different from one call to the next. 1127f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * Use \c clang_getCString() to retrieve the string data and, once finished 1137f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * with the string data, call \c clang_disposeString() to free the string. 114ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */ 115ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct { 116ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff const char *Spelling; 117ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff /* A 1 value indicates the clang_ indexing API needed to allocate the string 118ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff (and it must be freed by clang_disposeString()). */ 119ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff int MustFreeString; 120ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString; 121ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff 1227f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1237f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Retrieve the character data associated with the given string. 1247f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 125ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string); 126ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff 1277f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1287f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Free the given string, 1297f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 130ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string); 131ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff 1327f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1337f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @} 1347f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 1351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1361efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 137e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating 138e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options: 139e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * 140e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 141e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration 1421efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * is one that belongs in the translation unit itself and not in a precompiled 143e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations 144e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated. 145e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * 146e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - displayDiagnostics: when non-zero, diagnostics will be output. If zero, 147e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * diagnostics will be ignored. 148b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 149b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example: 150b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 151b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // excludeDeclsFromPCH = 1, displayDiagnostics = 1 152b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Idx = clang_createIndex(1, 1); 153b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 154b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // IndexTest.pch was produced with the following command: 155b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 156b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 157b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 158b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // This will load all the symbols from 'IndexTest.pch' 1591efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * clang_visitChildren(clang_getTranslationUnitCursor(TU), 160002a528ab0189fc60cfbf9328962c96ccbe567eeDouglas Gregor * TranslationUnitVisitor, 0); 161b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * clang_disposeTranslationUnit(TU); 162b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 163b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // This will load all the symbols from 'IndexTest.c', excluding symbols 164b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // from 'IndexTest.pch'. 165fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 166fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 167fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar * 0, 0); 168b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor * clang_visitChildren(clang_getTranslationUnitCursor(TU), 169b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor * TranslationUnitVisitor, 0); 170b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * clang_disposeTranslationUnit(TU); 171b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 172b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via 173b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 174b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler). 175e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */ 1762e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, 177e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff int displayDiagnostics); 1788506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index); 1791efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1801efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 1811efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Get the original translation unit source file name. 1821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar */ 1838506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXString 1848506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbarclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 1858506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar 1867f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1871efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Request that AST's be generated externally for API calls which parse 1888506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile. 1898506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * 1908506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later 1918506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date. 1928506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * 1938506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update. 1948506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value. 1958506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */ 1968506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index, 1978506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar int value); 198af08ddc8f1c53fed8d8d0ad82aa2a0bb7d654bd1Steve Naroff 1997f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 200e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Create a translation unit from an AST file (-emit-ast). 201e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */ 2022e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit( 203e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff CXIndex, const char *ast_filename 204600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff); 2058506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar 2061374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/** 2071374598619f83e6b2de91341a326eae564ece2cbTed Kremenek * \brief Destroy the specified CXTranslationUnit object. 2081efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar */ 2092e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); 2101374598619f83e6b2de91341a326eae564ece2cbTed Kremenek 2111374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/** 212e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Return the CXTranslationUnit for a given source file and the provided 213e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * command line arguments one would pass to the compiler. 214e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * 2158506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: The 'source_filename' argument is optional. If the caller provides a 2168506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * NULL pointer, the name of the source file is expected to reside in the 2178506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * specified command line arguments. 218139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * 2198506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: When encountered in 'clang_command_line_args', the following options 2208506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * are ignored: 221139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * 222139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * '-c' 223139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * '-emit-ast' 224139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * '-fsyntax-only' 225139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * '-o <output file>' (both '-o' and '<output file>' are ignored) 226139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * 2278506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * 2288506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename - The name of the source file to load, or NULL if the 2298506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in clang_command_line_args. 2304db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * 2314db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p 2324db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * unsaved_files. 2334db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * 2344db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * \param unsaved_files the files that have not yet been saved to disk 2354db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * but may be required for code completion, including the contents of 2364db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor * those files. 2371374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */ 2382e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( 2394db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor CXIndex CIdx, 2404db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor const char *source_filename, 2411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar int num_clang_command_line_args, 2424db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor const char **clang_command_line_args, 2434db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor unsigned num_unsaved_files, 2444db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor struct CXUnsavedFile *unsaved_files); 245600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff 246f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 247c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_FILES File manipulation routines 248f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 249f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{ 250f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 2511efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 252f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 253f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief A particular source file that is part of a translation unit. 254f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 255f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregortypedef void *CXFile; 2561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 257f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor 258f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 259f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the complete file and path name of the given file. 26088145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */ 26108b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE const char *clang_getFileName(CXFile SFile); 2621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 263f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 264f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the last modification time of the given file. 265f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 26608b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); 26788145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff 2683c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/** 269b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a file handle within the given translation unit. 270b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 271b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param tu the translation unit 2721efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * 273b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param file_name the name of the file. 274b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 275b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns the file handle for the named file in the translation unit \p tu, 276b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * or a NULL file handle if the file was not a part of this translation unit. 277b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 2781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, 279b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor const char *file_name); 2801efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 281b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 282f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @} 283f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 284f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor 285f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 286f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \defgroup CINDEX_LOCATIONS Physical source locations 287f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 288f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * Clang represents physical source locations in its abstract syntax tree in 289f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * great detail, with file, line, and column information for the majority of 290f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * the tokens parsed in the source code. These data types and functions are 291f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * used to represent source location information, either for a particular 292f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * point in the program or for a range of points in the program, and extract 293f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * specific location information from those data types. 294f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 295f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{ 296f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 2971efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 298f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 2991db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a specific source location within a translation 3001db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * unit. 3011db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3021db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getInstantiationLocation() to map a source location to a 3031db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * particular file, line, and column. 3043c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */ 3053c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct { 3061db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor void *ptr_data; 3071db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned int_data; 3083c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceLocation; 309fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek 3103c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/** 3111db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a range of source locations in the source code. 3123c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor * 3131db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 3141db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * starting and end locations from a source range, respectively. 3153c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */ 3163c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct { 3171db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor void *ptr_data; 3181db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned begin_int_data; 3191db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned end_int_data; 3203c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceRange; 321fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek 3221db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/** 323b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a NULL (invalid) source location. 324b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 325b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); 3261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 327b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 328b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \determine Determine whether two source locations, which must refer into 3291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * the same translation unit, refer to exactly the same point in the source 330b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * code. 331b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 332b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns non-zero if the source locations refer to the same location, zero 333b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * if they refer to different locations. 334b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 335b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, 336b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor CXSourceLocation loc2); 3371efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 338b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 3391efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieves the source location associated with a given file/line/column 3401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * in a particular translation unit. 341b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 342b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, 343b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor CXFile file, 344b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor unsigned line, 345b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor unsigned column); 3461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 347b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 348b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a source range given the beginning and ending source 349b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * locations. 350b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 351b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, 352b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor CXSourceLocation end); 3531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 354b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 3551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the file, line, and column represented by the given source 3561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * location. 3571db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3581efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param location the location within a source file that will be decomposed 3591efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * into its parts. 3601db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3611efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param file [out] if non-NULL, will be set to the file to which the given 3621db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points. 3631db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3641efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param line [out] if non-NULL, will be set to the line to which the given 3651db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points. 3661db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3671efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param column [out] if non-NULL, will be set to the column to which the given 3681efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source location points. 3691db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */ 3701db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, 3711db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor CXFile *file, 3721db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned *line, 3731db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned *column); 3741db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor 3751db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/** 376e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * \brief Retrieve the file and offset within that file represented by 377e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * the given source location. 378e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * 379e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * \param location the location within a source file that will be decomposed 380e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * into its parts. 381e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * 382e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * \param file [out] if non-NULL, will be set to the file to which the 383e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * given source location points. 384e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * 385e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * \param offset [out] if non-NULL, will be set to the offset into the 386e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor * \p file to which the given source location points. 387e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor */ 388e69517ce61638f12c9abe4605753a45275ac4e37Douglas GregorCINDEX_LINKAGE void clang_getInstantiationLocationOffset( 389e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor CXSourceLocation location, 390e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor CXFile *File, 391e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor unsigned *Offset); 392e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor 393e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor/** 3941efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the first character within a 3951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range. 3961db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */ 3971db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); 3981db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor 3991db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/** 4001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the last character within a 4011efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range. 4021db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */ 4031db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); 4041db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor 405f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 406f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @} 407f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 408c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 409c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 410c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes the kind of entity that a cursor refers to. 411c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 412c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXCursorKind { 413c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Declarations */ 414c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstDecl = 1, 4151efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 416c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A declaration whose specific kind is not exposed via this 4171efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * interface. 418c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 419c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Unexposed declarations have the same operations as any other kind 420c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * of declaration; one can extract their location information, 421c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * spelling, find their definitions, etc. However, the specific kind 422c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * of the declaration is not reported. 423c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 424c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnexposedDecl = 1, 425c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A C or C++ struct. */ 4261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar CXCursor_StructDecl = 2, 427c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A C or C++ union. */ 428c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnionDecl = 3, 429c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A C++ class. */ 430c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ClassDecl = 4, 431c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An enumeration. */ 432c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_EnumDecl = 5, 4331efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 434c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A field (in C) or non-static data member (in C++) in a 435c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * struct, union, or C++ class. 436c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 437c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FieldDecl = 6, 438c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An enumerator constant. */ 439c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_EnumConstantDecl = 7, 440c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A function. */ 441c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FunctionDecl = 8, 442c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A variable. */ 443c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_VarDecl = 9, 444c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A function or method parameter. */ 445c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ParmDecl = 10, 446c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @interface. */ 447c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCInterfaceDecl = 11, 448c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @interface for a category. */ 449c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCCategoryDecl = 12, 450c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @protocol declaration. */ 451c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCProtocolDecl = 13, 452c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @property declaration. */ 453c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCPropertyDecl = 14, 454c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C instance variable. */ 455c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCIvarDecl = 15, 456c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C instance method. */ 457c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCInstanceMethodDecl = 16, 458c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C class method. */ 459c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCClassMethodDecl = 17, 460c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @implementation. */ 461c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCImplementationDecl = 18, 462c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @implementation for a category. */ 463c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCCategoryImplDecl = 19, 464c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A typedef */ 465c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_TypedefDecl = 20, 466c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastDecl = 20, 4671efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 468c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* References */ 469c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstRef = 40, /* Decl references */ 4701efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar CXCursor_ObjCSuperClassRef = 40, 471c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCProtocolRef = 41, 472c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCClassRef = 42, 473c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 474c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A reference to a type declaration. 475c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 476c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A type reference occurs anywhere where a type is named but not 477c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * declared. For example, given: 478c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 479c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \code 480c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * typedef unsigned size_type; 481c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * size_type size; 482c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \endcode 483c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 484c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 485c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * while the type of the variable "size" is referenced. The cursor 486c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * referenced by the type of size is the typedef for size_type. 487c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 488c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_TypeRef = 43, 489c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastRef = 43, 4901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 491c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Error conditions */ 492c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstInvalid = 70, 493c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_InvalidFile = 70, 494c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_NoDeclFound = 71, 495c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_NotImplemented = 72, 496c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastInvalid = 72, 4971efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 498c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Expressions */ 499c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstExpr = 100, 5001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 501c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 502c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief An expression whose specific kind is not exposed via this 5031efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * interface. 504c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 505c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Unexposed expressions have the same operations as any other kind 506c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * of expression; one can extract their location information, 507c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * spelling, children, etc. However, the specific kind of the 508c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * expression is not reported. 509c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 510c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnexposedExpr = 100, 5111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 512c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 513c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief An expression that refers to some value declaration, such 514c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * as a function, varible, or enumerator. 515c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 516c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_DeclRefExpr = 101, 5171efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 518c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 519c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief An expression that refers to a member of a struct, union, 520c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * class, Objective-C class, etc. 521c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 522c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_MemberRefExpr = 102, 5231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 524c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An expression that calls a function. */ 525c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_CallExpr = 103, 5261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 527c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An expression that sends a message to an Objective-C 528c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor object or class. */ 529c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCMessageExpr = 104, 530c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastExpr = 104, 5311efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 532c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Statements */ 533c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstStmt = 200, 534c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 535c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A statement whose specific kind is not exposed via this 536c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * interface. 537c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 538c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Unexposed statements have the same operations as any other kind of 539c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * statement; one can extract their location information, spelling, 540c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * children, etc. However, the specific kind of the statement is not 541c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reported. 542c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 543c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnexposedStmt = 200, 544c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastStmt = 200, 5451efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 546c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 547c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Cursor that represents the translation unit itself. 548c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 549c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor exists primarily to act as the root 550c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor for traversing the contents of a translation unit. 551c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 552c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_TranslationUnit = 300 553c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor}; 554c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 555c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 556c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A cursor representing some element in the abstract syntax tree for 557c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a translation unit. 558c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 5591efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The cursor abstraction unifies the different kinds of entities in a 560c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * program--declaration, statements, expressions, references to declarations, 561c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * etc.--under a single "cursor" abstraction with a common set of operations. 562c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Common operation for a cursor include: getting the physical location in 563c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a source file where the cursor points, getting the name associated with a 564c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor, and retrieving cursors for any child nodes of a particular cursor. 565c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 566c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors can be produced in two specific ways. 567c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 568c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * from which one can use clang_visitChildren() to explore the rest of the 569c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * translation unit. clang_getCursor() maps from a physical source location 570c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to the entity that resides at that location, allowing one to map from the 571c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * source code into the AST. 572c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 573c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef struct { 574c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor enum CXCursorKind kind; 575c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor void *data[3]; 5761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar} CXCursor; 577c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 578c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 579c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 580c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 581c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 582c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 5831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 584c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 585c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the NULL cursor, which represents no entity. 586c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 587c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getNullCursor(void); 5881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 589c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 590c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the cursor that represents the given translation unit. 591c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 592c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor can be used to start traversing the 593c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * various declarations within the given translation unit. 594c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 595c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 596c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 597c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 598c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether two cursors are equivalent. 599c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 600c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); 6011efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 602c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 603c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the kind of the given cursor. 604c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 605c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); 606c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 607c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 608c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a declaration. 609c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 610c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); 611c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 612c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 613c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a simple 614c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reference. 615c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 616c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Note that other kinds of cursors (such as expressions) can also refer to 617c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * other cursors. Use clang_getCursorReferenced() to determine whether a 618c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * particular cursor refers to another entity. 619c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 620c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); 621c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 622c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 623c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents an expression. 624c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 625c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); 626c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 627c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 628c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a statement. 629c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 630c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); 631c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 632c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 6331efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents an invalid 634c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor. 6351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar */ 636c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); 637c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 638c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 6391efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents a translation 6401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unit. 641c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 642c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); 6431efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 644c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 645c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 646c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 6471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 648c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 649c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 650c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 651c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors represent a location within the Abstract Syntax Tree (AST). These 652c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines help map between cursors and the physical locations where the 653c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * described entities occur in the source code. The mapping is provided in 654c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * both directions, so one can map from source code to the AST and back. 655c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 656c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 65750398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */ 6581efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 6596a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/** 660b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Map a source location to the cursor that describes the entity at that 661b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * location in the source code. 662b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 663b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() maps an arbitrary source location within a translation 664b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * unit down to the most specific cursor that describes the entity at that 6651efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * location. For example, given an expression \c x + y, invoking 666b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() with a source location pointing to "x" will return the 6671efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * cursor for "x"; similarly for "y". If the cursor points anywhere between 668b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 669b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * will return a cursor referring to the "+" expression. 670b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 671b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns a cursor representing the entity at the given source location, or 672b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * a NULL cursor if no such entity can be found. 6736a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */ 674b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 6751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 67698258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor/** 67798258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * \brief Retrieve the physical location of the source constructor referenced 67898258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * by the given cursor. 67998258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * 68098258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * The location of a declaration is typically the location of the name of that 6811efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * declaration, where the name of that declaration would occur if it is 6821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unnamed, or some keyword that introduces that particular declaration. 6831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The location of a reference is where that reference occurs within the 68498258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * source code. 68598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor */ 68698258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); 687c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 688b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/** 689b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Retrieve the physical extent of the source construct referenced by 690a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the given cursor. 691a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * 692a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * The extent of a cursor starts with the file/line/column pointing at the 693a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * first character within the source construct that the cursor refers to and 6941efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * ends with the last character withinin that source construct. For a 695a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * declaration, the extent covers the declaration itself. For a reference, 696a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the extent covers the location of the reference (e.g., where the referenced 697a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * entity was actually used). 698a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor */ 699a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); 700c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor 701c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 702c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 703c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 7041efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 705c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 706c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 707c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 708c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines provide the ability to traverse the abstract syntax tree 709c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * using cursors. 710c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 711c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 712c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 7131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 714c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 715c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes how the traversal of the children of a particular 716c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor should proceed after visiting a particular child cursor. 717c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 718c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A value of this enumeration type should be returned by each 719c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 720c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 721c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXChildVisitResult { 722c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 7231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Terminates the cursor traversal. 724c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 725c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXChildVisit_Break, 7261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 727c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Continues the cursor traversal with the next sibling of 728c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the cursor just visited, without visiting its children. 729c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 730c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXChildVisit_Continue, 731c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 732c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Recursively traverse the children of this cursor, using 733c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the same visitor and client data. 734c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 735c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXChildVisit_Recurse 736c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor}; 737c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 738c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 739c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visitor invoked for each cursor found by a traversal. 740c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 741c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This visitor function will be invoked for each cursor found by 742c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). Its first argument is the cursor being 743c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited, its second argument is the parent visitor for that cursor, 744c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and its third argument is the client data provided to 745c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). 746c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 747c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The visitor should return one of the \c CXChildVisitResult values 748c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to direct clang_visitCursorChildren(). 749c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 7501efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbartypedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, 7511efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar CXCursor parent, 752c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXClientData client_data); 753c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 754c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 755c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visit the children of a particular cursor. 756c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 757c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This function visits all the direct children of the given cursor, 758c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * invoking the given \p visitor function with the cursors of each 759c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited child. The traversal may be recursive, if the visitor returns 760c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 761c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the visitor returns \c CXChildVisit_Break. 762c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 763c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param parent the cursor whose child may be visited. All kinds of 764a57259e9d7b30bcce93f0a62eee0488738026172Daniel Dunbar * cursors can be visited, including invalid cursors (which, by 765c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * definition, have no children). 766c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 767c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param visitor the visitor function that will be invoked for each 768c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * child of \p parent. 769c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 770c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param client_data pointer data supplied by the client, which will 771c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be passed to the visitor each time it is invoked. 772c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 773c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \returns a non-zero value if the traversal was terminated 774c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * prematurely by the visitor returning \c CXChildVisit_Break. 775c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 7761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, 777c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursorVisitor visitor, 778c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXClientData client_data); 7791efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 780c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 781c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 782c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 7831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 784c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 785c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 786c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 7871efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * These routines provide the ability to determine references within and 788c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * across translation units, by providing the names of the entities referenced 789c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by cursors, follow reference cursors to the declarations they reference, 790c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and associate declarations with their definitions. 791c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 792c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 793c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 7941efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 795c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 796c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 797c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by the given cursor. 798c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 799c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A Unified Symbol Resolution (USR) is a string that identifies a particular 800c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * entity (function, class, variable, etc.) within a program. USRs can be 801c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * compared across translation units to determine, e.g., when references in 802c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * one translation refer to an entity defined in another translation unit. 803c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 804c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); 805c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 806c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 807c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a name for the entity referenced by this cursor. 808c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 809c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); 810c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 811c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor/** \brief For a cursor that is a reference, retrieve a cursor representing the 812c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * entity that it references. 813c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * 814c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Reference cursors refer to other entities in the AST. For example, an 815c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Objective-C superclass reference cursor refers to an Objective-C class. 8161efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This function produces the cursor for the Objective-C class from the 817c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * cursor for the superclass reference. If the input cursor is a declaration or 818c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * definition, it returns that declaration or definition unchanged. 8191efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Otherwise, returns the NULL cursor. 820c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor */ 821c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); 822b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor 8231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 824b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief For a cursor that is either a reference to or a declaration 825b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * of some entity, retrieve a cursor that describes the definition of 826b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * that entity. 827b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 828b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * Some entities can be declared multiple times within a translation 829b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * unit, but only one of those declarations can also be a 830b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * definition. For example, given: 831b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 832b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \code 833b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int f(int, int); 834b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int g(int x, int y) { return f(x, y); } 835b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int f(int a, int b) { return a + b; } 836b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int f(int, int); 837b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \endcode 838b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 839b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * there are three declarations of the function "f", but only the 840b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * second one is a definition. The clang_getCursorDefinition() 841b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * function will take any cursor pointing to a declaration of "f" 842b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * (the first or fourth lines of the example) or a cursor referenced 843b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * that uses "f" (the call to "f' inside "g") and will return a 844b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * declaration cursor pointing to the definition (the second "f" 845b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * declaration). 846b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 847b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * If given a cursor for which there is no corresponding definition, 848b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * e.g., because there is no definition of that entity within this 849b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * translation unit, returns a NULL cursor. 850b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */ 851b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); 852b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor 8531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 854b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Determine whether the declaration pointed to by this cursor 855b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * is also a definition of that entity. 856b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */ 857b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); 858b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor 859c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 860c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 861c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 8621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 863c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 8640045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * \defgroup CINDEX_LEX Token extraction and manipulation 8650045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * 8660045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * The routines in this group provide access to the tokens within a 8670045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * translation unit, along with a semantic mapping of those tokens to 8680045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * their corresponding cursors. 869fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 870fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @{ 871fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 872fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 873fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 874fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a kind of token. 875fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 876fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef enum CXTokenKind { 877fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 878fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief A token that contains some kind of punctuation. 879fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 880fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Punctuation, 881fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 882fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 8830045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * \brief A language keyword. 884fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 885fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Keyword, 886fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 887fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 888fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief An identifier (that is not a keyword). 889fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 890fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Identifier, 891fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 892fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 893fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief A numeric, string, or character literal. 894fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 895fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Literal, 896fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 897fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 898fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief A comment. 899fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 900fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Comment 901fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXTokenKind; 902fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 903fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 904fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a single preprocessing token. 905fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 906fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef struct { 907fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor unsigned int_data[4]; 908fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor void *ptr_data; 909fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXToken; 910fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 911fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 912fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the kind of the given token. 913fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 914fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); 915fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 916fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 917fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the spelling of the given token. 918fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 919fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * The spelling of a token is the textual representation of that token, e.g., 920fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * the text of an identifier or keyword. 921fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 922fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 923fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 924fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 925fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve the source location of the given token. 926fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 927fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, 928fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken); 929fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 930fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 931fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve a source range that covers the given token. 932fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 933fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 934fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 935fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 936fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Tokenize the source code described by the given range into raw 937fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * lexical tokens. 938fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 939fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit whose text is being tokenized. 940fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 941fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Range the source range in which text should be tokenized. All of the 942fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * tokens produced by tokenization will fall within this source range, 943fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 944fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens this pointer will be set to point to the array of tokens 945fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that occur within the given source range. The returned pointer must be 946fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * freed with clang_disposeTokens() before the translation unit is destroyed. 947fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 948fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens will be set to the number of tokens in the \c *Tokens 949fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * array. 950fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 951fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 952fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, 953fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken **Tokens, unsigned *NumTokens); 954fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 955fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 956fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Annotate the given set of tokens by providing cursors for each token 957fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that can be mapped to a specific entity within the abstract syntax tree. 958fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 9590045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * This token-annotation routine is equivalent to invoking 9600045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() for the source locations of each of the 9610045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * tokens. The cursors provided are filtered, so that only those 9620045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * cursors that have a direct correspondence to the token are 9630045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * accepted. For example, given a function call \c f(x), 9640045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() would provide the following cursors: 9650045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * 9660045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 9670045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 9680045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 9690045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * 9700045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * Only the first and last of these cursors will occur within the 9710045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * annotate, since the tokens "f" and "x' directly refer to a function 9720045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * and a variable, respectively, but the parentheses are just a small 9730045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * part of the full syntax of the function call expression, which is 9740045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * not provided as an annotation. 975fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 976fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit that owns the given tokens. 977fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 978fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens the set of tokens to annotate. 979fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 980fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens the number of tokens in \p Tokens. 981fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 982fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Cursors an array of \p NumTokens cursors, whose contents will be 983fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * replaced with the cursors corresponding to each token. 984fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 985fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, 986fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken *Tokens, unsigned NumTokens, 987fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXCursor *Cursors); 988fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 989fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 990fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Free the given set of tokens. 991fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 992fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, 993fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken *Tokens, unsigned NumTokens); 994fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 995fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 996fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @} 997fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 998fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 999fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1000c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_DEBUG Debugging facilities 1001c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1002c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines are used for testing and debugging, only, and should not 1003c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be relied upon. 1004c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1005c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 1006c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 10071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 10084ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */ 10091efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind); 10101efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, 10111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar const char **startBuf, 10124ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff const char **endBuf, 10134ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *startLine, 10144ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *startColumn, 10154ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *endLine, 10164ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *endColumn); 1017600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff 10180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 1019c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1020c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 10211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1022c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1023c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CODE_COMPLET Code completion 1024c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1025c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Code completion involves taking an (incomplete) source file, along with 1026c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * knowledge of where the user is actively editing that file, and suggesting 1027c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * syntactically- and semantically-valid constructs that the user might want to 1028c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * use at that particular point in the source code. These data structures and 1029c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines provide support for code completion. 1030c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1031c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 1032c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 10331efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1034c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 10350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result. 10360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion 10380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the 10390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected. 10400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which 10410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g., 10420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of 10430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace 10440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 10451efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * description of the different kinds of chunks. 10460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 10470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString; 10481efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 10490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 10500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion. 10510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 10520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct { 10530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 10541efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief The kind of entity that this completion refers to. 10550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The cursor kind will be a macro, keyword, or a declaration (one of the 10570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * *Decl cursor kinds), describing the entity that the completion is 10580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * referring to. 10590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \todo In the future, we would like to provide a full cursor, to allow 10610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the client to extract additional information from declaration. 10620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 10630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor enum CXCursorKind CursorKind; 10641efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 10651efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 10660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief The code-completion string that describes how to insert this 10670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion result into the editing buffer. 10680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 10690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionString CompletionString; 10700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult; 10710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor 10720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 10730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string. 10740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Each "chunk" within a code-completion string (\c CXCompletionString) is 10761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * either a piece of text with a specific "kind" that describes how that text 10770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string. 10780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 10790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind { 10800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 10810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A code-completion string that describes "optional" text that 10820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * could be a part of the template (but is not required). 10830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * The Optional chunk is the only kind of chunk that has a code-completion 10851efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * string for its representation, which is accessible via 10860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c clang_getCompletionChunkCompletionString(). The code-completion string 10870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * describes an additional part of the template that is completely optional. 10880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * For example, optional chunks can be used to describe the placeholders for 10890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * arguments that match up with defaulted function parameters, e.g. given: 10900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \code 10920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * void f(int x, float y = 3.14, double z = 2.71828); 10930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \endcode 10940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 10950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * The code-completion string for this function would contain: 10960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a TypedText chunk for "f". 10970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a LeftParen chunk for "(". 10980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Placeholder chunk for "int x" 10990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - an Optional chunk containing the remaining defaulted arguments, e.g., 11000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Comma chunk for "," 11010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Placeholder chunk for "float x" 11020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - an Optional chunk containing the last defaulted argument: 11030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Comma chunk for "," 11040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Placeholder chunk for "double z" 11050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a RightParen chunk for ")" 11060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * There are many ways two handle Optional chunks. Two simple approaches are: 11080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - Completely ignore optional chunks, in which case the template for the 11090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * function "f" would only include the first parameter ("int x"). 11100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - Fully expand all optional chunks, in which case the template for the 11110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * function "f" would have all of the parameters. 11120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Optional, 11140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Text that a user would be expected to type to get this 11161efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * code-completion result. 11170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11181efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * There will be exactly one "typed text" chunk in a semantic string, which 11191efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * will typically provide the spelling of a keyword or the name of a 11200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * declaration that could be used at the current code point. Clients are 11210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * expected to filter the code-completion results based on the text in this 11220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * chunk. 11230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_TypedText, 11250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Text that should be inserted as part of a code-completion result. 11270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A "text" chunk represents text that is part of the template to be 11290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * inserted into user code should this particular code-completion result 11300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * be selected. 11310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Text, 11330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Placeholder text that should be replaced by the user. 11350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A "placeholder" chunk marks a place where the user should insert text 11370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * into the code-completion template. For example, placeholders might mark 11380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the function parameters for a function declaration, to indicate that the 11390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * user should provide arguments for each of those parameters. The actual 11400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * text in a placeholder is a suggestion for the text to display before 11410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the user replaces the placeholder with real code. 11420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Placeholder, 11440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Informative text that should be displayed but never inserted as 11460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * part of the template. 11471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * 11480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * An "informative" chunk contains annotations that can be displayed to 11490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * help the user decide whether a particular code-completion result is the 11500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * right option, but which is not part of the actual template to be inserted 11510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * by code completion. 11520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Informative, 11540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Text that describes the current parameter when code-completion is 11560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * referring to function call, message send, or template specialization. 11570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A "current parameter" chunk occurs when code-completion is providing 11590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * information about a parameter corresponding to the argument at the 11600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion point. For example, given a function 11610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \code 11630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * int add(int x, int y); 11640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \endcode 11650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 11660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * and the source code \c add(, where the code-completion point is after the 11670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "(", the code-completion string will contain a "current parameter" chunk 11680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for "int x", indicating that the current argument will initialize that 11690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * parameter. After typing further, to \c add(17, (where the code-completion 11701efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * point is after the ","), the code-completion string will contain a 11710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "current paremeter" chunk to "int y". 11720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_CurrentParameter, 11740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left parenthesis ('('), used to initiate a function call or 11760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * signal the beginning of a function parameter list. 11770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftParen, 11790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right parenthesis (')'), used to finish a function call or 11810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * signal the end of a function parameter list. 11820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightParen, 11840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left bracket ('['). 11860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftBracket, 11880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right bracket (']'). 11900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightBracket, 11920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left brace ('{'). 11940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftBrace, 11960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 11970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right brace ('}'). 11980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 11990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightBrace, 12000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 12010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left angle bracket ('<'). 12020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 12030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftAngle, 12040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 12050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right angle bracket ('>'). 12060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 12070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightAngle, 12080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 12090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A comma separator (','). 12100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 1211ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor CXCompletionChunk_Comma, 1212ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor /** 12131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Text that specifies the result type of a given result. 1214ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor * 1215ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor * This special kind of informative chunk is not meant to be inserted into 12161efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * the text buffer. Rather, it is meant to illustrate the type that an 1217ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor * expression using the given completion string would have. 1218ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor */ 121901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_ResultType, 122001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 122101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * \brief A colon (':'). 122201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 122301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_Colon, 122401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 122501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * \brief A semicolon (';'). 122601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 122701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_SemiColon, 122801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 122901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * \brief An '=' sign. 123001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 123101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_Equal, 123201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 123301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * Horizontal space (' '). 123401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 123501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_HorizontalSpace, 123601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 123701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * Vertical space ('\n'), after which it is generally a good idea to 123801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * perform indentation. 123901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 124001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_VerticalSpace 12410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor}; 12421efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 12430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 12440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string. 12450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query. 12470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string. 12490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number. 12510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 12521efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE enum CXCompletionChunkKind 12530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string, 12540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor unsigned chunk_number); 12551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 12560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 12571efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the text associated with a particular chunk within a 12580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string. 12590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query. 12610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string. 12630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number. 12650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 12660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE const char * 12670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string, 12680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor unsigned chunk_number); 12690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor 12700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 12711efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the completion string associated with a particular chunk 12720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string. 12730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query. 12750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string. 12770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 12780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index 12790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion 12800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string. 12810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 12820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString 12830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string, 12840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor unsigned chunk_number); 12851efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 12860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 12870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string. 12880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 12890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned 12900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string); 12910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor 12920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 1293ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion. 1294ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * 1295ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as 12961efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * produced by \c clang_codeComplete. Its contents must be freed by 1297ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults. 1298ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 1299ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct { 1300ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor /** 1301ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief The code-completion results. 1302ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 1303ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor CXCompletionResult *Results; 1304ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor 1305ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor /** 1306ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief The number of code-completion results stored in the 1307ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c Results array. 1308ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 1309ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned NumResults; 1310ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults; 1311ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor 1312ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/** 13130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file. 13140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and 13160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential 13170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model 13180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file, 13190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has 13200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed 13210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the 13221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * current location in the C/Objective-C/C++ grammar and the state of 13230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are 1324ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure. 13250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the 13271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * user types punctuation characters or whitespace, at which point the 13280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p 13290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then 13300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">", 13310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that 13320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the 13330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results 13340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for 13350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after 13360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 13370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only 13380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface 1339ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion 13400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must 13410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency. 13420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code 13440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion. 13450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13468506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to 13478506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the 13488506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results 13498506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced. NOTE: One can also specify NULL for this argument if the 13508506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args. 13510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in 13530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args. 13540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang 13561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * compiler to build the given source file. This should include all of the 13570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header 13581efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * includes, etc., but should not include any information specific to 13590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion. 13600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 1361735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p 1362735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files. 1363735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 1364735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk 1365735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of 1366735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files. 1367735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 13680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion 13690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the 13701efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source filename. However, the completion filename may also be a file 13711efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * included by the source file, which is required when producing 13720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header. 13730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur. 13750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 13761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param complete_column the column at which code-completion should occur. 13770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that 13780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token. 13790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 1380ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure 1381ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be 1382ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code 1383ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL. 1384ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 13851efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE 13861efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, 1387ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor const char *source_filename, 13881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar int num_command_line_args, 1389ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor const char **command_line_args, 1390ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned num_unsaved_files, 1391ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor struct CXUnsavedFile *unsaved_files, 1392ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor const char *complete_filename, 1393ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned complete_line, 1394ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned complete_column); 13951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1396ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/** 1397ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results. 13980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 13991efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE 1400ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); 14011efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 140220d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/** 140320d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @} 140420d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */ 14051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 14061efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 140704bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/** 140804bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * \defgroup CINDEX_MISC Miscellaneous utility functions 140904bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * 141004bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @{ 141104bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */ 141223e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek 141323e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek/** 141423e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek * \brief Return a version string, suitable for showing to a user, but not 141523e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek * intended to be parsed (the format is not guaranteed to be stable). 141623e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek */ 141704bb716aea8fd2372ac10b0c640cabc5e5caa615Ted KremenekCINDEX_LINKAGE const char *clang_getClangVersion(); 141804bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek 141904bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/** 142004bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @} 142104bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */ 14221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1423c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1424c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1425c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 14261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1427d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus 1428d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek} 1429d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif 1430d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif 1431d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 1432