Index.h revision 44c181aec37789f25f6c15543c164416f72e562a
1d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\ 2d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 3d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* The LLVM Compiler Infrastructure *| 4d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 5d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This file is distributed under the University of Illinois Open Source *| 6d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* License. See LICENSE.TXT for details. *| 7d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 8d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*===----------------------------------------------------------------------===*| 9d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 10d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This header provides a public inferface to a Clang library for extracting *| 11d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* high-level symbol information from source files without exposing the full *| 12d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* Clang C++ API. *| 13d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* *| 14d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek\*===----------------------------------------------------------------------===*/ 15d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 16d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifndef CLANG_C_INDEX_H 17d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#define CLANG_C_INDEX_H 18d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 1988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff#include <sys/stat.h> 203d31560343856c573376a04558a7111e7afad4f7Chandler Carruth#include <time.h> 210a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor#include <stdio.h> 2288145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff 23d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus 24d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenekextern "C" { 25d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif 26d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 2788145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/* MSVC DLL import/export. */ 282e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#ifdef _MSC_VER 292e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #ifdef _CINDEX_LIB_ 302e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #define CINDEX_LINKAGE __declspec(dllexport) 312e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #else 322e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #define CINDEX_LINKAGE __declspec(dllimport) 332e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #endif 342e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#else 352e06fc877a633abea3b40a64950c7316dac29ca8John Thompson #define CINDEX_LINKAGE 362e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#endif 372e06fc877a633abea3b40a64950c7316dac29ca8John Thompson 3820d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/** \defgroup CINDEX C Interface to Clang 3920d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * 401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The C Interface to Clang provides a relatively small API that exposes 41f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities for parsing source code into an abstract syntax tree (AST), 42f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * loading already-parsed ASTs, traversing the AST, associating 43f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * physical source locations with elements within the AST, and other 44f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * facilities that support Clang-based development tools. 45f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This C interface to Clang will never provide all of the information 47f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * representation stored in Clang's C++ AST, nor should it: the intent is to 48f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * maintain an API that is relatively stable from one release to the next, 49f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * providing only the basic functionality needed to support development tools. 501efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * 511efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * To avoid namespace pollution, data types are prefixed with "CX" and 52f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * functions are prefixed with "clang_". 5320d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * 5420d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @{ 5520d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */ 561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 577f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 587f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief An "index" that consists of a set of translation units that would 597f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * typically be linked together into an executable or library. 607f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 617f17376e0931a337d544b75d9030bc92763be287Douglas Gregortypedef void *CXIndex; 62600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff 637f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 647f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A single translation unit, which resides in an index. 657f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 6650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXTranslationUnit; /* A translation unit instance. */ 67600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff 687f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 69c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Opaque pointer representing client data that will be passed through 70c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to various callbacks and visitors. 717f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 72c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef void *CXClientData; 731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 74735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor/** 75735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief Provides the contents of a file that has not yet been saved to disk. 76735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 77735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * Each CXUnsavedFile instance provides the name of a file on the 78735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * system along with the current contents of that file that have not 79735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * yet been saved to disk. 80735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 81735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregorstruct CXUnsavedFile { 821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief The file whose contents have not yet been saved. 84735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 85735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * This file must already exist in the file system. 86735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 87735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor const char *Filename; 88735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor 891efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 90c8dfe5ece04e683106eb96c58a2999f70b53ac21Douglas Gregor * \brief A buffer containing the unsaved contents of this file. 91735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 92735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor const char *Contents; 93735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor 94735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor /** 95c8dfe5ece04e683106eb96c58a2999f70b53ac21Douglas Gregor * \brief The length of the unsaved contents of this buffer. 96735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */ 97735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor unsigned long Length; 98735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor}; 99735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor 1007f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1017f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \defgroup CINDEX_STRING String manipulation routines 1027f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * 1037f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @{ 1047f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 1051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1067f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1077f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief A character string. 1087f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * 1097f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * The \c CXString type is used to return strings from the interface when 1107f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * the ownership of that string might different from one call to the next. 1117f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * Use \c clang_getCString() to retrieve the string data and, once finished 1127f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * with the string data, call \c clang_disposeString() to free the string. 113ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */ 114ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct { 115ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff const char *Spelling; 116ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff /* A 1 value indicates the clang_ indexing API needed to allocate the string 117ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff (and it must be freed by clang_disposeString()). */ 118ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff int MustFreeString; 119ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString; 120ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff 1217f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1227f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Retrieve the character data associated with the given string. 1237f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 124ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string); 125ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff 1267f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1277f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * \brief Free the given string, 1287f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 129ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string); 130ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff 1317f17376e0931a337d544b75d9030bc92763be287Douglas Gregor/** 1327f17376e0931a337d544b75d9030bc92763be287Douglas Gregor * @} 1337f17376e0931a337d544b75d9030bc92763be287Douglas Gregor */ 1341efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 136e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating 137e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options: 138e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * 139e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 140e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration 1411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * is one that belongs in the translation unit itself and not in a precompiled 142e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations 143e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated. 144e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * 145b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example: 146b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 1470a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * // excludeDeclsFromPCH = 1, displayDiagnostics=1 1480a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * Idx = clang_createIndex(1, 1); 149b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 150b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // IndexTest.pch was produced with the following command: 151b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 152b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 153b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 154b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // This will load all the symbols from 'IndexTest.pch' 1551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * clang_visitChildren(clang_getTranslationUnitCursor(TU), 156002a528ab0189fc60cfbf9328962c96ccbe567eeDouglas Gregor * TranslationUnitVisitor, 0); 157b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * clang_disposeTranslationUnit(TU); 158b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 159b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // This will load all the symbols from 'IndexTest.c', excluding symbols 160b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * // from 'IndexTest.pch'. 161fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 162fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 163fd9f23464bfd35314c87c4df410f3937d59eb96dDaniel Dunbar * 0, 0); 164b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor * clang_visitChildren(clang_getTranslationUnitCursor(TU), 165b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor * TranslationUnitVisitor, 0); 166b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * clang_disposeTranslationUnit(TU); 167b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * 168b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via 169b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 170b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler). 171e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */ 1720a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, 1730a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor int displayDiagnostics); 174896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1750087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor/** 1760087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * \brief Destroy the given index. 1770087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * 1780087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * The index must not be destroyed until all of the translation units created 1790087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor * within that index have been destroyed. 1800087e1a12b67b6bb032a72ea485a863daeccf55bDouglas Gregor */ 1818506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index); 1821efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 1841efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Request that AST's be generated externally for API calls which parse 1858506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile. 1868506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * 1878506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later 1888506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date. 1898506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * 1908506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update. 1918506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value. 1928506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */ 1938506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index, 1948506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar int value); 195f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 196c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_FILES File manipulation routines 197f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 198f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{ 199f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 2001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 201f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 202f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief A particular source file that is part of a translation unit. 203f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 204f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregortypedef void *CXFile; 2051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 206f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor 207f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 208f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the complete file and path name of the given file. 20988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */ 21074844072411bae91d5dbb89955d200cbe1e0a1c8Ted KremenekCINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); 2111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 212f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 213f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \brief Retrieve the last modification time of the given file. 214f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 21508b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); 21688145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff 2173c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/** 218b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a file handle within the given translation unit. 219b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 220b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param tu the translation unit 2211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * 222b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \param file_name the name of the file. 223b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 224b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns the file handle for the named file in the translation unit \p tu, 225b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * or a NULL file handle if the file was not a part of this translation unit. 226b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 2271efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, 228b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor const char *file_name); 2291efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 230b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 231f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @} 232f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 233f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor 234f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 235f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * \defgroup CINDEX_LOCATIONS Physical source locations 236f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 237f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * Clang represents physical source locations in its abstract syntax tree in 238f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * great detail, with file, line, and column information for the majority of 239f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * the tokens parsed in the source code. These data types and functions are 240f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * used to represent source location information, either for a particular 241f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * point in the program or for a range of points in the program, and extract 242f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * specific location information from those data types. 243f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * 244f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @{ 245f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 2461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 247f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 2481db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * \brief Identifies a specific source location within a translation 2491db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * unit. 2501db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 2511db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getInstantiationLocation() to map a source location to a 2521db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * particular file, line, and column. 2533c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */ 2543c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct { 2555352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor void *ptr_data[2]; 2561db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned int_data; 2573c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceLocation; 258fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek 2593c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor/** 260d52864bd33c66aacc84133460d8c9c0dfcdd5c18Daniel Dunbar * \brief Identifies a half-open character range in the source code. 2613c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor * 2621db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 2631db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * starting and end locations from a source range, respectively. 2643c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor */ 2653c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregortypedef struct { 2665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor void *ptr_data[2]; 2671db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned begin_int_data; 2681db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned end_int_data; 2693c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58fDouglas Gregor} CXSourceRange; 270fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek 2711db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/** 272b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a NULL (invalid) source location. 273b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 274b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); 2751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 276b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 277b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \determine Determine whether two source locations, which must refer into 2781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * the same translation unit, refer to exactly the same point in the source 279b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * code. 280b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 281b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns non-zero if the source locations refer to the same location, zero 282b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * if they refer to different locations. 283b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 284b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, 285b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor CXSourceLocation loc2); 2861efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 287b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 2881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieves the source location associated with a given file/line/column 2891efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * in a particular translation unit. 290b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 291b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, 292b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor CXFile file, 293b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor unsigned line, 294b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor unsigned column); 2951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 296b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 2975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve a NULL (invalid) source range. 2985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 2995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getNullRange(); 300896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 3015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 302b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Retrieve a source range given the beginning and ending source 303b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * locations. 304b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor */ 305b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, 306b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor CXSourceLocation end); 3071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 308b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor/** 30946766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * \brief Retrieve the file, line, column, and offset represented by 31046766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * the given source location. 3111db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param location the location within a source file that will be decomposed 3131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * into its parts. 3141db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3151efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param file [out] if non-NULL, will be set to the file to which the given 3161db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points. 3171db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3181efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param line [out] if non-NULL, will be set to the line to which the given 3191db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * source location points. 3201db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor * 3211efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param column [out] if non-NULL, will be set to the column to which the given 3221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source location points. 32346766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * 32446766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * \param offset [out] if non-NULL, will be set to the offset into the 32546766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor * buffer to which the given source location points. 3261db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */ 3271db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, 3281db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor CXFile *file, 3291db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor unsigned *line, 33046766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor unsigned *column, 33146766dc31c09d89024de5aba9e22112a56eadbdfDouglas Gregor unsigned *offset); 332e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor 333e69517ce61638f12c9abe4605753a45275ac4e37Douglas Gregor/** 3341efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the first character within a 3351efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range. 3361db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */ 3371db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); 3381db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor 3391db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor/** 3401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve a source location representing the last character within a 3411efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source range. 3421db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor */ 3431db19dea8d221f27be46332d668d1e2decb7f1abDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); 3441db19dea8d221f27be46332d668d1e2decb7f1abDouglas Gregor 345f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor/** 346f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor * @} 347f55254472e496340cbb4f0a24cff398e441475b5Douglas Gregor */ 348c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 349c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 3505352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \defgroup CINDEX_DIAG Diagnostic reporting 3515352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 3525352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @{ 3535352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3545352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 3555352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 3565352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Describes the severity of a particular diagnostic. 3575352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3585352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorenum CXDiagnosticSeverity { 3595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor /** 360896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief A diagnostic that has been suppressed, e.g., by a command-line 3615352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * option. 3625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3635352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor CXDiagnostic_Ignored = 0, 364896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 3655352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor /** 3665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief This diagnostic is a note that should be attached to the 3675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * previous (non-note) diagnostic. 3685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor CXDiagnostic_Note = 1, 3705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 3715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor /** 3725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief This diagnostic indicates suspicious code that may not be 3735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * wrong. 3745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor CXDiagnostic_Warning = 2, 3765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 3775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor /** 3785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief This diagnostic indicates that the code is ill-formed. 3795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3805352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor CXDiagnostic_Error = 3, 3815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 3825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor /** 3835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief This diagnostic indicates that the code is ill-formed such 3845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * that future parser recovery is unlikely to produce useful 3855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * results. 3865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor CXDiagnostic_Fatal = 4 3885352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor}; 3895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 3905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 3915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief A single diagnostic, containing the diagnostic's severity, 3925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * location, text, source ranges, and fix-it hints. 3935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 3945352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregortypedef void *CXDiagnostic; 3955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 3965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 397a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Determine the number of diagnostics produced for the given 398a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * translation unit. 399a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */ 400a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); 401a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 402a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/** 403a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Retrieve a diagnostic associated with the given translation unit. 4045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 405a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Unit the translation unit to query. 406a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Index the zero-based diagnostic number to retrieve. 4075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 408a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \returns the requested diagnostic. This diagnostic must be freed 409a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * via a call to \c clang_disposeDiagnostic(). 4105352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 411a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, 412a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned Index); 413a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 414a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/** 415a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Destroy a diagnostic. 416a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */ 417a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); 4185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 4195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 4200a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Options to control the display of diagnostics. 4210a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4220a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * The values in this enum are meant to be combined to customize the 4230a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * behavior of \c clang_displayDiagnostic(). 4240a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 4250a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregorenum CXDiagnosticDisplayOptions { 4260a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor /** 4270a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Display the source-location information where the 4280a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * diagnostic was located. 4290a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4300a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * When set, diagnostics will be prefixed by the file, line, and 4310a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * (optionally) column to which the diagnostic refers. For example, 4320a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4330a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \code 4340a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * test.c:28: warning: extra tokens at end of #endif directive 4350a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \endcode 4360a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4370a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * This option corresponds to the clang flag \c -fshow-source-location. 4380a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 4390a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor CXDiagnostic_DisplaySourceLocation = 0x01, 4400a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor 4410a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor /** 4420a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief If displaying the source-location information of the 4430a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * diagnostic, also include the column number. 4440a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4450a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * This option corresponds to the clang flag \c -fshow-column. 4460a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 4470a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor CXDiagnostic_DisplayColumn = 0x02, 4480a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor 4490a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor /** 4500a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief If displaying the source-location information of the 4510a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * diagnostic, also include information about source ranges in a 4520a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * machine-parsable format. 4530a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 454896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * This option corresponds to the clang flag 4550a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \c -fdiagnostics-print-source-range-info. 4560a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 4570a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor CXDiagnostic_DisplaySourceRanges = 0x04 4580a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor}; 4590a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor 4600a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/** 461274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * \brief Format the given diagnostic in a manner that is suitable for display. 4620a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 463274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * This routine will format the given diagnostic to a string, rendering 464896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * the diagnostic according to the various options given. The 465896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \c clang_defaultDiagnosticDisplayOptions() function returns the set of 4660a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * options that most closely mimics the behavior of the clang compiler. 4670a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4680a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \param Diagnostic The diagnostic to print. 4690a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 470896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \param Options A set of options that control the diagnostic display, 4710a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * created by combining \c CXDiagnosticDisplayOptions values. 472274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * 473274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor * \returns A new string containing for formatted diagnostic. 4740a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 475274f1906f12ebf8fcc179701deeda6d3271120c1Douglas GregorCINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, 476274f1906f12ebf8fcc179701deeda6d3271120c1Douglas Gregor unsigned Options); 4770a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor 4780a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/** 4790a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Retrieve the set of display options most similar to the 4800a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * default behavior of the clang compiler. 4810a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * 4820a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \returns A set of display options suitable for use with \c 4830a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * clang_displayDiagnostic(). 4840a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 4850a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); 4860a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor 4870a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/** 4880a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor * \brief Print a diagnostic to the given file. 4890a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor */ 4900a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor 4910a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas Gregor/** 4925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Determine the severity of the given diagnostic. 4935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 494896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE enum CXDiagnosticSeverity 4955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getDiagnosticSeverity(CXDiagnostic); 4965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 4975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 4985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the source location of the given diagnostic. 4995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 5005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * This location is where Clang would print the caret ('^') when 5015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * displaying the diagnostic on the command line. 5025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 5035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); 5045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 5055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 5065352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Retrieve the text of the given diagnostic. 5075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 5085352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); 509a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor 510a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor/** 511a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \brief Determine the number of source ranges associated with the given 512a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * diagnostic. 513a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor */ 514a3890baf1256ff26081306c7fef70202f8223f41Douglas GregorCINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); 515896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 5165352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 517a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \brief Retrieve a source range associated with the diagnostic. 5185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 519a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * A diagnostic's source ranges highlight important elements in the source 5205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * code. On the command line, Clang displays source ranges by 521896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * underlining them with '~' characters. 5225352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 523a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \param Diagnostic the diagnostic whose range is being extracted. 5245352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 525896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \param Range the zero-based index specifying which range to 5265352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 527a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor * \returns the requested source range. 5285352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 529896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, 530a3890baf1256ff26081306c7fef70202f8223f41Douglas Gregor unsigned Range); 5315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 5325352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 5335352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Determine the number of fix-it hints associated with the 5345352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * given diagnostic. 5355352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 5365352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); 5375352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 5385352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 539473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \brief Retrieve the replacement information for a given fix-it. 5405352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 541473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * Fix-its are described in terms of a source range whose contents 542473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * should be replaced by a string. This approach generalizes over 543473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * three kinds of operations: removal of source code (the range covers 544473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * the code to be removed and the replacement string is empty), 545473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replacement of source code (the range covers the code to be 546473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replaced and the replacement string provides the new code), and 547473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * insertion (both the start and end of the range point at the 548473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * insertion location, and the replacement string provides the text to 549473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * insert). 5505352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 551473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \param Diagnostic The diagnostic whose fix-its are being queried. 5525352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 553473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \param FixIt The zero-based index of the fix-it. 5545352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 555473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \param ReplacementRange The source range whose contents will be 556473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replaced with the returned replacement string. Note that source 557473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * ranges are half-open ranges [a, b), so the source code should be 558473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * replaced from a and up to (but not including) b. 5595352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 560473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * \returns A string containing text that should be replace the source 561473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor * code indicated by the \c ReplacementRange. 5625352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 563896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, 564473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor unsigned FixIt, 565473d7019bb54f8a2f0140dca9e9644a935cc6b20Douglas Gregor CXSourceRange *ReplacementRange); 5665352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 5675352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 5685352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @} 5695352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 5705352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 5715352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 5725352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation 5735352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 5745352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * The routines in this group provide the ability to create and destroy 5755352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * translation units from files, either by parsing the contents of the files or 5765352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * by reading in a serialized representation of a translation unit. 5775352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 5785352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @{ 5795352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 580896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 5815352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 5825352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Get the original translation unit source file name. 5835352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 5845352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXString 5855352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregorclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 5865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 5875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 5885352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Return the CXTranslationUnit for a given source file and the provided 5895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * command line arguments one would pass to the compiler. 5905352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 5915352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * Note: The 'source_filename' argument is optional. If the caller provides a 5925352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * NULL pointer, the name of the source file is expected to reside in the 5935352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * specified command line arguments. 5945352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 5955352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * Note: When encountered in 'clang_command_line_args', the following options 5965352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * are ignored: 5975352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 5985352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * '-c' 5995352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * '-emit-ast' 6005352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * '-fsyntax-only' 6015352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * '-o <output file>' (both '-o' and '<output file>' are ignored) 6025352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 6035352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 6045352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param source_filename - The name of the source file to load, or NULL if the 6055352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * source file is included in clang_command_line_args. 6065352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 6075352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p 6085352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * unsaved_files. 6095352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 6105352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk 6115352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * but may be required for code completion, including the contents of 612c6f530defd937faa1c00998e60deea6368526961Ted Kremenek * those files. The contents and name of these files (as specified by 613c6f530defd937faa1c00998e60deea6368526961Ted Kremenek * CXUnsavedFile) are copied when necessary, so the client only needs to 614c6f530defd937faa1c00998e60deea6368526961Ted Kremenek * guarantee their validity until the call to this function returns. 6155352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 6165352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param diag_callback callback function that will receive any diagnostics 6175352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * emitted while processing this source file. If NULL, diagnostics will be 6185352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * suppressed. 6195352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * 6205352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \param diag_client_data client data that will be passed to the diagnostic 6215352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * callback function. 6225352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 6235352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( 6245352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor CXIndex CIdx, 6255352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor const char *source_filename, 6265352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor int num_clang_command_line_args, 6275352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor const char **clang_command_line_args, 6285352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor unsigned num_unsaved_files, 629a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor struct CXUnsavedFile *unsaved_files); 630896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 6315352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 6325352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Create a translation unit from an AST file (-emit-ast). 6335352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 634896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, 635a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor const char *ast_filename); 6365352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor 63744c181aec37789f25f6c15543c164416f72e562aDouglas Gregor/** 63844c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * \brief Flags that control the creation of translation units. 63944c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * 64044c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * The enumerators in this enumeration type are meant to be bitwise 64144c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * ORed together to specify which options should be used when 64244c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * constructing the translation unit. 64344c181aec37789f25f6c15543c164416f72e562aDouglas Gregor */ 6445a43021ac491bf091494167127772a20d9a9bb48Douglas Gregorenum CXTranslationUnit_Flags { 6455a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor /** 6465a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \brief Used to indicate that no special translation-unit options are 6475a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * needed. 6485a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor */ 6495a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor CXTranslationUnit_None = 0x0, 6505a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor 6515a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor /** 6525a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \brief Used to indicate that the parser should construct a "detailed" 6535a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * preprocessing record, including all macro definitions and instantiations. 6545a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 6555a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * Constructing a detailed preprocessing record requires more memory 6565a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * and time to parse, since the information contained in the record 6575a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * is usually not retained. However, it can be useful for 6585a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * applications that require more detailed information about the 6595a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * behavior of the preprocessor. 6605a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor */ 66144c181aec37789f25f6c15543c164416f72e562aDouglas Gregor CXTranslationUnit_DetailedPreprocessingRecord = 0x01, 66244c181aec37789f25f6c15543c164416f72e562aDouglas Gregor 66344c181aec37789f25f6c15543c164416f72e562aDouglas Gregor /** 66444c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * \brief A flag that indicates that the intent of parsing the 66544c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * given translation unit is for live editing of the file. 66644c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * 66744c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * This flag is essentially a meta-flag that callers can use to indicate 66844c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * that the translation unit is being edited and, therefore, is likely to 66944c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * be reparsed many times. It enables an unspecified set of optimizations 67044c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * (e.g., the precompiled preamble) geared toward improving the performance 67144c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * of \c clang_reparseTranslationUnit(). 67244c181aec37789f25f6c15543c164416f72e562aDouglas Gregor */ 67344c181aec37789f25f6c15543c164416f72e562aDouglas Gregor CXTranslationUnit_Editing = 0x02, 67444c181aec37789f25f6c15543c164416f72e562aDouglas Gregor 67544c181aec37789f25f6c15543c164416f72e562aDouglas Gregor /** 67644c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * \brief Used to indicate that the translation unit should be built with an 67744c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * implicit precompiled header for the preamble. 67844c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * 67944c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * An implicit precompiled header is used as an optimization when a 68044c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * particular translation unit is likely to be reparsed many times 68144c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * when the sources aren't changing that often. In this case, an 68244c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * implicit precompiled header will be built containing all of the 68344c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * initial includes at the top of the main file (what we refer to as 68444c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * the "preamble" of the file). In subsequent parses, if the 68544c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * preamble or the files in it have not changed, \c 68644c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * clang_reparseTranslationUnit() will re-use the implicit 68744c181aec37789f25f6c15543c164416f72e562aDouglas Gregor * precompiled header to improve parsing performance. 68844c181aec37789f25f6c15543c164416f72e562aDouglas Gregor */ 68944c181aec37789f25f6c15543c164416f72e562aDouglas Gregor CXTranslationUnit_PrecompiledPreamble = 0x04 6905a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor}; 6915a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor 6925a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor/** 6935a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \brief Parse the given source file and the translation unit corresponding 6945a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * to that file. 6955a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 6965a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * This routine is the main entry point for the Clang C API, providing the 6975a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * ability to parse a source file into a translation unit that can then be 6985a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * queried by other functions in the API. This routine accepts a set of 6995a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * command-line arguments so that the compilation can be configured in the same 7005a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * way that the compiler is configured on the command line. 7015a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7025a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param CIdx The index object with which the translation unit will be 7035a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * associated. 7045a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7055a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param source_filename The name of the source file to load, or NULL if the 7065a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * source file is included in \p clang_command_line_args. 7075a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7085a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param command_line_args The command-line arguments that would be 7095a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * passed to the \c clang executable if it were being invoked out-of-process. 7105a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * These command-line options will be parsed and will affect how the translation 7115a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * unit is parsed. Note that the following options are ignored: '-c', 7125a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. 7135a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7145a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param num_command_line_args The number of command-line arguments in 7155a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \p command_line_args. 7165a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7175a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk 7185a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * but may be required for code completion, including the contents of 7195a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * those files. The contents and name of these files (as specified by 7205a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * CXUnsavedFile) are copied when necessary, so the client only needs to 7215a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * guarantee their validity until the call to this function returns. 7225a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7235a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p 7245a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * unsaved_files. 7255a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7265a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \param options A bitmask of options that affects how the translation unit 7275a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * is managed but not its compilation. This should be a bitwise OR of the 7285a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * CXTranslationUnit_XXX flags. 7295a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * 7305a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * \returns A new translation unit describing the parsed code and containing 7315a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * any diagnostics produced by the compiler. If there is a failure from which 7325a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor * the compiler cannot recover, returns NULL. 7335a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor */ 7345a43021ac491bf091494167127772a20d9a9bb48Douglas GregorCINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx, 7355a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor const char *source_filename, 7365a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor const char **command_line_args, 7375a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor int num_command_line_args, 7385a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor struct CXUnsavedFile *unsaved_files, 7395a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor unsigned num_unsaved_files, 7405a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor unsigned options); 7415a43021ac491bf091494167127772a20d9a9bb48Douglas Gregor 7425352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 7435352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * \brief Destroy the specified CXTranslationUnit object. 7445352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 7455352ac06d8f6194825bb2a99ffa009b61bafb503Douglas GregorCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); 746896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 7475352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 748abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \brief Reparse the source files that produced this translation unit. 749abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * 750abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * This routine can be used to re-parse the source files that originally 751abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * created the given translation unit, for example because those source files 752abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * have changed (either on disk or as passed via \p unsaved_files). The 753abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * source code will be reparsed with the same command-line options as it 754abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * was originally parsed. 755abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * 756abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * Reparsing a translation unit invalidates all cursors and source locations 757abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * that refer into that translation unit. This makes reparsing a translation 758abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * unit semantically equivalent to destroying the translation unit and then 759abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * creating a new translation unit with the same command-line arguments. 760abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * However, it may be more efficient to reparse a translation 761abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * unit using this routine. 762abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * 763abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \param TU The translation unit whose contents will be re-parsed. The 764abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * translation unit must originally have been built with 765abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \c clang_createTranslationUnitFromSourceFile(). 766abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * 767abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \param num_unsaved_files The number of unsaved file entries in \p 768abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * unsaved_files. 769abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * 770abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \param unsaved_files The files that have not yet been saved to disk 771abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * but may be required for parsing, including the contents of 772abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * those files. The contents and name of these files (as specified by 773abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * CXUnsavedFile) are copied when necessary, so the client only needs to 774abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * guarantee their validity until the call to this function returns. 775abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * 776abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \returns 0 if the sources could be reparsed. A non-zero value will be 777abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * returned if reparsing was impossible, such that the translation unit is 778abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * invalid. In such cases, the only valid call for \p TU is 779abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor * \c clang_disposeTranslationUnit(TU). 780abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor */ 781abc563f554951259bbe0315055cad92ee14d87e4Douglas GregorCINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, 782abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor unsigned num_unsaved_files, 783abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor struct CXUnsavedFile *unsaved_files); 784abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 785abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor/** 7865352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor * @} 7875352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor */ 788896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 7895352ac06d8f6194825bb2a99ffa009b61bafb503Douglas Gregor/** 790c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes the kind of entity that a cursor refers to. 791c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 792c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXCursorKind { 793c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Declarations */ 7941efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 795c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A declaration whose specific kind is not exposed via this 7961efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * interface. 797c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 798c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Unexposed declarations have the same operations as any other kind 799c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * of declaration; one can extract their location information, 800c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * spelling, find their definitions, etc. However, the specific kind 801c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * of the declaration is not reported. 802c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 803c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnexposedDecl = 1, 804c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A C or C++ struct. */ 8051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar CXCursor_StructDecl = 2, 806c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A C or C++ union. */ 807c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnionDecl = 3, 808c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A C++ class. */ 809c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ClassDecl = 4, 810c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An enumeration. */ 811c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_EnumDecl = 5, 8121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 813c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A field (in C) or non-static data member (in C++) in a 814c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * struct, union, or C++ class. 815c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 816c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FieldDecl = 6, 817c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An enumerator constant. */ 818c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_EnumConstantDecl = 7, 819c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A function. */ 820c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FunctionDecl = 8, 821c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A variable. */ 822c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_VarDecl = 9, 823c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A function or method parameter. */ 824c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ParmDecl = 10, 825c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @interface. */ 826c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCInterfaceDecl = 11, 827c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @interface for a category. */ 828c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCCategoryDecl = 12, 829c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @protocol declaration. */ 830c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCProtocolDecl = 13, 831c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @property declaration. */ 832c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCPropertyDecl = 14, 833c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C instance variable. */ 834c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCIvarDecl = 15, 835c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C instance method. */ 836c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCInstanceMethodDecl = 16, 837c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C class method. */ 838c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCClassMethodDecl = 17, 839c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @implementation. */ 840c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCImplementationDecl = 18, 841c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An Objective-C @implementation for a category. */ 842c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCCategoryImplDecl = 19, 843c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief A typedef */ 844c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_TypedefDecl = 20, 8458bd5a69999cfd06b6b5a58fdd04e4f802b2df5a4Ted Kremenek /** \brief A C++ class method. */ 8468bd5a69999cfd06b6b5a58fdd04e4f802b2df5a4Ted Kremenek CXCursor_CXXMethod = 21, 8478f06e0e9fec3ca501e5fb129f413adbfc88e82f8Ted Kremenek /** \brief A C++ namespace. */ 8488f06e0e9fec3ca501e5fb129f413adbfc88e82f8Ted Kremenek CXCursor_Namespace = 22, 849a0536d8dd900bb48ea886bd68d777b03b061c068Ted Kremenek /** \brief A linkage specification, e.g. 'extern "C"'. */ 850a0536d8dd900bb48ea886bd68d777b03b061c068Ted Kremenek CXCursor_LinkageSpec = 23, 8518bd5a69999cfd06b6b5a58fdd04e4f802b2df5a4Ted Kremenek 85250aa6acd0b8d40c8956372a69e0a73f0802a5494Ted Kremenek CXCursor_FirstDecl = CXCursor_UnexposedDecl, 853a0536d8dd900bb48ea886bd68d777b03b061c068Ted Kremenek CXCursor_LastDecl = CXCursor_LinkageSpec, 8541efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 855c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* References */ 856c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstRef = 40, /* Decl references */ 8571efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar CXCursor_ObjCSuperClassRef = 40, 858c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCProtocolRef = 41, 859c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCClassRef = 42, 860c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 861c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A reference to a type declaration. 862c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 863c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A type reference occurs anywhere where a type is named but not 864c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * declared. For example, given: 865c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 866c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \code 867c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * typedef unsigned size_type; 868c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * size_type size; 869c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \endcode 870c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 871c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 872c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * while the type of the variable "size" is referenced. The cursor 873c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * referenced by the type of size is the typedef for size_type. 874c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 875c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_TypeRef = 43, 876c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastRef = 43, 8771efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 878c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Error conditions */ 879c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstInvalid = 70, 880c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_InvalidFile = 70, 881c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_NoDeclFound = 71, 882c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_NotImplemented = 72, 883ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek CXCursor_InvalidCode = 73, 884ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek CXCursor_LastInvalid = CXCursor_InvalidCode, 8851efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 886c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Expressions */ 887c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstExpr = 100, 8881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 889c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 890c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief An expression whose specific kind is not exposed via this 8911efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * interface. 892c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 893c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Unexposed expressions have the same operations as any other kind 894c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * of expression; one can extract their location information, 895c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * spelling, children, etc. However, the specific kind of the 896c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * expression is not reported. 897c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 898c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnexposedExpr = 100, 8991efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 900c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 901c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief An expression that refers to some value declaration, such 902c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * as a function, varible, or enumerator. 903c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 904c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_DeclRefExpr = 101, 9051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 906c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 907c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief An expression that refers to a member of a struct, union, 908c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * class, Objective-C class, etc. 909c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 910c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_MemberRefExpr = 102, 9111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 912c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An expression that calls a function. */ 913c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_CallExpr = 103, 9141efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 915c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** \brief An expression that sends a message to an Objective-C 916c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor object or class. */ 917c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_ObjCMessageExpr = 104, 9181ee6cad59f017601ea54fbb4f62a6e8d69897e3eTed Kremenek 9191ee6cad59f017601ea54fbb4f62a6e8d69897e3eTed Kremenek /** \brief An expression that represents a block literal. */ 9201ee6cad59f017601ea54fbb4f62a6e8d69897e3eTed Kremenek CXCursor_BlockExpr = 105, 9211ee6cad59f017601ea54fbb4f62a6e8d69897e3eTed Kremenek 9221ee6cad59f017601ea54fbb4f62a6e8d69897e3eTed Kremenek CXCursor_LastExpr = 105, 9231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 924c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /* Statements */ 925c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_FirstStmt = 200, 926c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 927c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A statement whose specific kind is not exposed via this 928c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * interface. 929c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 930c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Unexposed statements have the same operations as any other kind of 931c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * statement; one can extract their location information, spelling, 932c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * children, etc. However, the specific kind of the statement is not 933c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reported. 934c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 935c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_UnexposedStmt = 200, 936c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursor_LastStmt = 200, 9371efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 938c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 939c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Cursor that represents the translation unit itself. 940c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 941c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor exists primarily to act as the root 942c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor for traversing the contents of a translation unit. 943c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 944e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek CXCursor_TranslationUnit = 300, 945e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 946e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek /* Attributes */ 947e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek CXCursor_FirstAttr = 400, 948e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek /** 949e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek * \brief An attribute whose specific kind is not exposed via this 950e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek * interface. 951e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek */ 952e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek CXCursor_UnexposedAttr = 400, 953e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 954e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek CXCursor_IBActionAttr = 401, 955e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek CXCursor_IBOutletAttr = 402, 956857e918a8a40deb128840308a318bf623d68295fTed Kremenek CXCursor_IBOutletCollectionAttr = 403, 957857e918a8a40deb128840308a318bf623d68295fTed Kremenek CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr, 9589f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor 9599f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor /* Preprocessing */ 9609f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor CXCursor_PreprocessingDirective = 500, 961572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor CXCursor_MacroDefinition = 501, 962572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor CXCursor_MacroInstantiation = 502, 9639f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, 9644807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor CXCursor_LastPreprocessing = CXCursor_MacroInstantiation 965c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor}; 966c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 967c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 968c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief A cursor representing some element in the abstract syntax tree for 969c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a translation unit. 970c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 9711efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The cursor abstraction unifies the different kinds of entities in a 972c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * program--declaration, statements, expressions, references to declarations, 973c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * etc.--under a single "cursor" abstraction with a common set of operations. 974c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Common operation for a cursor include: getting the physical location in 975c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * a source file where the cursor points, getting the name associated with a 976c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor, and retrieving cursors for any child nodes of a particular cursor. 977c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 978c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors can be produced in two specific ways. 979c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 980c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * from which one can use clang_visitChildren() to explore the rest of the 981c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * translation unit. clang_getCursor() maps from a physical source location 982c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to the entity that resides at that location, allowing one to map from the 983c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * source code into the AST. 984c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 985c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregortypedef struct { 986c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor enum CXCursorKind kind; 987c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor void *data[3]; 9881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar} CXCursor; 989c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 990c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 991c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 992c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 993c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 994c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 9951efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 996c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 997c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the NULL cursor, which represents no entity. 998c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 999c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getNullCursor(void); 10001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1001c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1002c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the cursor that represents the given translation unit. 1003c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1004c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The translation unit cursor can be used to start traversing the 1005c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * various declarations within the given translation unit. 1006c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1007c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 1008c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1009c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1010c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether two cursors are equivalent. 1011c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1012c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); 10131efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1014c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1015c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve the kind of the given cursor. 1016c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1017c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); 1018c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1019c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1020c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a declaration. 1021c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1022c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); 1023c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1024c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1025c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a simple 1026c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * reference. 1027c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1028c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Note that other kinds of cursors (such as expressions) can also refer to 1029c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * other cursors. Use clang_getCursorReferenced() to determine whether a 1030c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * particular cursor refers to another entity. 1031c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1032c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); 1033c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1034c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1035c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents an expression. 1036c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1037c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); 1038c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1039c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1040c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Determine whether the given cursor kind represents a statement. 1041c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1042c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); 1043c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1044c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 10451efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents an invalid 1046c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor. 10471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar */ 1048c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); 1049c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1050c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 10511efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Determine whether the given cursor kind represents a translation 10521efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unit. 1053c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1054c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); 10551efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1056ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek/*** 10579f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor * \brief Determine whether the given cursor represents a preprocessing 10589f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor * element, such as a preprocessor directive or macro instantiation. 10599f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor */ 10609f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorCINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); 10619f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor 10629f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor/*** 1063ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek * \brief Determine whether the given cursor represents a currently 1064ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). 1065ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek */ 1066ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted KremenekCINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); 1067ad6eff611a4391f89fd6c458db16993f76e7f5d0Ted Kremenek 1068c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 106916b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * \brief Describe the linkage of the entity referred to by a cursor. 107016b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek */ 107116b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenekenum CXLinkageKind { 107216b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek /** \brief This value indicates that no linkage information is available 107316b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * for a provided CXCursor. */ 107416b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek CXLinkage_Invalid, 107516b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek /** 107616b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * \brief This is the linkage for variables, parameters, and so on that 107716b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * have automatic storage. This covers normal (non-extern) local variables. 107816b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek */ 107916b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek CXLinkage_NoLinkage, 108016b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek /** \brief This is the linkage for static variables and static functions. */ 108116b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek CXLinkage_Internal, 108216b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek /** \brief This is the linkage for entities with external linkage that live 108316b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek * in C++ anonymous namespaces.*/ 108416b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek CXLinkage_UniqueExternal, 108516b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek /** \brief This is the linkage for entities with true, external linkage. */ 108616b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek CXLinkage_External 108716b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek}; 108816b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek 108916b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek/** 109045e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek * \brief Determine the linkage of the entity referred to by a given cursor. 109116b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek */ 109216b4259aecaa22b642d35d36fd89965ed700c1e0Ted KremenekCINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); 109316b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek 109416b4259aecaa22b642d35d36fd89965ed700c1e0Ted Kremenek/** 109545e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek * \brief Describe the "language" of the entity referred to by a cursor. 109645e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek */ 109745e1dae500bba7a9ef5b8206263a5609c07c6f03Ted KremenekCINDEX_LINKAGE enum CXLanguageKind { 10986cd1e7cb04d1da66e8b5675062152ff60bbc354fTed Kremenek CXLanguage_Invalid = 0, 109945e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek CXLanguage_C, 110045e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek CXLanguage_ObjC, 11016cd1e7cb04d1da66e8b5675062152ff60bbc354fTed Kremenek CXLanguage_CPlusPlus 110245e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek}; 110345e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek 110445e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek/** 110545e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek * \brief Determine the "language" of the entity referred to by a given cursor. 110645e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek */ 110745e1dae500bba7a9ef5b8206263a5609c07c6f03Ted KremenekCINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); 110845e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek 110945e1dae500bba7a9ef5b8206263a5609c07c6f03Ted Kremenek/** 1110c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1111c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 11121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1113c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1114c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 1115c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1116c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Cursors represent a location within the Abstract Syntax Tree (AST). These 1117c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines help map between cursors and the physical locations where the 1118c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * described entities occur in the source code. The mapping is provided in 1119c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * both directions, so one can map from source code to the AST and back. 1120c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1121c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 112250398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */ 11231efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 11246a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/** 1125b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \brief Map a source location to the cursor that describes the entity at that 1126b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * location in the source code. 1127b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 1128b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() maps an arbitrary source location within a translation 1129b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * unit down to the most specific cursor that describes the entity at that 11301efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * location. For example, given an expression \c x + y, invoking 1131b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * clang_getCursor() with a source location pointing to "x" will return the 11321efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * cursor for "x"; similarly for "y". If the cursor points anywhere between 1133b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 1134b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * will return a cursor referring to the "+" expression. 1135b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * 1136b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * \returns a cursor representing the entity at the given source location, or 1137b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas Gregor * a NULL cursor if no such entity can be found. 11386a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */ 1139b979034b100be14de2223f2b8f6cc7a3275cbe4fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 11401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 114198258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor/** 114298258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * \brief Retrieve the physical location of the source constructor referenced 114398258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * by the given cursor. 114498258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * 114598258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * The location of a declaration is typically the location of the name of that 11461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * declaration, where the name of that declaration would occur if it is 11471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * unnamed, or some keyword that introduces that particular declaration. 11481efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The location of a reference is where that reference occurs within the 114998258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor * source code. 115098258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas Gregor */ 115198258afae66bab39b0c57a3efb6b20d4fbb5746cDouglas GregorCINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); 1152c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1153b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor/** 1154b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Retrieve the physical extent of the source construct referenced by 1155a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the given cursor. 1156a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * 1157a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * The extent of a cursor starts with the file/line/column pointing at the 1158a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * first character within the source construct that the cursor refers to and 11591efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * ends with the last character withinin that source construct. For a 1160a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * declaration, the extent covers the declaration itself. For a reference, 1161a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * the extent covers the location of the reference (e.g., where the referenced 1162a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor * entity was actually used). 1163a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas Gregor */ 1164a7bde20f8c6334ccc3a7ef4dd77243d0921a8497Douglas GregorCINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); 1165c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor 1166c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1167c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1168c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 11691efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1170c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 11718e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \defgroup CINDEX_TYPES Type information for CXCursors 11728e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * 11738e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * @{ 11748e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 11758e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 11768e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 11778e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief Describes the kind of type 11788e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 11798e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenekenum CXTypeKind { 11808e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek /** 11818e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief Reprents an invalid type (e.g., where no type is available). 11828e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 11838e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Invalid = 0, 11848e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 11858e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek /** 11868e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief A type whose specific kind is not exposed via this 11878e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * interface. 11888e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 11898e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Unexposed = 1, 11908e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 11918e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek /* Builtin types */ 11928e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Void = 2, 11938e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Bool = 3, 11948e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Char_U = 4, 11958e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_UChar = 5, 11968e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Char16 = 6, 11978e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Char32 = 7, 11988e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_UShort = 8, 11998e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_UInt = 9, 12008e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_ULong = 10, 12018e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_ULongLong = 11, 12028e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_UInt128 = 12, 12038e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Char_S = 13, 12048e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_SChar = 14, 12058e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_WChar = 15, 12068e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Short = 16, 12078e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Int = 17, 12088e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Long = 18, 12098e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_LongLong = 19, 12108e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Int128 = 20, 12118e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Float = 21, 12128e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Double = 22, 12138e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_LongDouble = 23, 12148e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_NullPtr = 24, 12158e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Overload = 25, 12168e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Dependent = 26, 12178e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_ObjCId = 27, 12188e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_ObjCClass = 28, 12198e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_ObjCSel = 29, 12208e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_FirstBuiltin = CXType_Void, 12218e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_LastBuiltin = CXType_ObjCSel, 12228e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12238e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Complex = 100, 12248e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Pointer = 101, 12258e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_BlockPointer = 102, 12268e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_LValueReference = 103, 12278e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_RValueReference = 104, 12288e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Record = 105, 12298e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Enum = 106, 12308e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_Typedef = 107, 12318e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek CXType_ObjCInterface = 108, 123204c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted Kremenek CXType_ObjCObjectPointer = 109, 123304c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted Kremenek CXType_FunctionNoProto = 110, 123404c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted Kremenek CXType_FunctionProto = 111 12358e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek}; 12368e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12378e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12388e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief The type of an element in the abstract syntax tree. 12398e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * 12408e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12418e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenektypedef struct { 12428e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek enum CXTypeKind kind; 12438e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek void *data[2]; 12448e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek} CXType; 12458e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12468e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12478e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief Retrieve the type of a CXCursor (if any). 12488e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12498e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted KremenekCINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); 12508e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12518e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12528e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \determine Determine whether two CXTypes represent the same type. 12538e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * 12548e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \returns non-zero if the CXTypes represent the same type and 12558e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek zero otherwise. 12568e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12578e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted KremenekCINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); 12588e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12598e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12608e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief Return the canonical type for a CXType. 12618e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * 12628e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * Clang's type system explicitly models typedefs and all the ways 12638e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * a specific type can be represented. The canonical type is the underlying 12648e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * type with all the "sugar" removed. For example, if 'T' is a typedef 12658e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * for 'int', the canonical type for 'T' would be 'int'. 12668e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12678e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted KremenekCINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); 12688e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12698e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12708e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief For pointer types, returns the type of the pointee. 12718e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * 12728e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12738e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted KremenekCINDEX_LINKAGE CXType clang_getPointeeType(CXType T); 12748e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12758e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12768e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief Return the cursor for the declaration of the given type. 12778e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12788e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted KremenekCINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); 12798e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12808e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12818e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12828e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * \brief Retrieve the spelling of a given CXTypeKind. 12838e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 12848e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted KremenekCINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); 12858e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 12868e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 12879a140845438c2fc31e7d48a6dedbc695f4c83c68Ted Kremenek * \brief Retrieve the result type associated with a function type. 128804c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted Kremenek */ 128904c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted KremenekCINDEX_LINKAGE CXType clang_getResultType(CXType T); 129004c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted Kremenek 129104c3cf35a80c09ab78e519f2e71ecccd5c5d8da0Ted Kremenek/** 12929a140845438c2fc31e7d48a6dedbc695f4c83c68Ted Kremenek * \brief Retrieve the result type associated with a given cursor. This only 12939a140845438c2fc31e7d48a6dedbc695f4c83c68Ted Kremenek * returns a valid type of the cursor refers to a function or method. 12949a140845438c2fc31e7d48a6dedbc695f4c83c68Ted Kremenek */ 12959a140845438c2fc31e7d48a6dedbc695f4c83c68Ted KremenekCINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); 12969a140845438c2fc31e7d48a6dedbc695f4c83c68Ted Kremenek 12979a140845438c2fc31e7d48a6dedbc695f4c83c68Ted Kremenek/** 12988e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek * @} 12998e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek */ 13008e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek 13018e0ac174c8c8c980927b3e1447f16f62fbe2a2e4Ted Kremenek/** 1302c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 1303c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1304c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines provide the ability to traverse the abstract syntax tree 1305c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * using cursors. 1306c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1307c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 1308c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 13091efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1310c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1311c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Describes how the traversal of the children of a particular 1312c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * cursor should proceed after visiting a particular child cursor. 1313c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1314c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A value of this enumeration type should be returned by each 1315c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 1316c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1317c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregorenum CXChildVisitResult { 1318c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 13191efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Terminates the cursor traversal. 1320c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1321c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXChildVisit_Break, 13221efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 1323c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Continues the cursor traversal with the next sibling of 1324c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the cursor just visited, without visiting its children. 1325c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1326c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXChildVisit_Continue, 1327c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor /** 1328c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Recursively traverse the children of this cursor, using 1329c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the same visitor and client data. 1330c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1331c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXChildVisit_Recurse 1332c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor}; 1333c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1334c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1335c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visitor invoked for each cursor found by a traversal. 1336c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1337c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This visitor function will be invoked for each cursor found by 1338c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). Its first argument is the cursor being 1339c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited, its second argument is the parent visitor for that cursor, 1340c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and its third argument is the client data provided to 1341c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * clang_visitCursorChildren(). 1342c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1343c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * The visitor should return one of the \c CXChildVisitResult values 1344c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * to direct clang_visitCursorChildren(). 1345c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 13461efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbartypedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, 13471efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar CXCursor parent, 1348c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXClientData client_data); 1349c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1350c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1351c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Visit the children of a particular cursor. 1352c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1353c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * This function visits all the direct children of the given cursor, 1354c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * invoking the given \p visitor function with the cursors of each 1355c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * visited child. The traversal may be recursive, if the visitor returns 1356c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 1357c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * the visitor returns \c CXChildVisit_Break. 1358c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1359c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param parent the cursor whose child may be visited. All kinds of 1360a57259e9d7b30bcce93f0a62eee0488738026172Daniel Dunbar * cursors can be visited, including invalid cursors (which, by 1361c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * definition, have no children). 1362c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1363c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param visitor the visitor function that will be invoked for each 1364c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * child of \p parent. 1365c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1366c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \param client_data pointer data supplied by the client, which will 1367c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be passed to the visitor each time it is invoked. 1368c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1369c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \returns a non-zero value if the traversal was terminated 1370c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * prematurely by the visitor returning \c CXChildVisit_Break. 1371c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 13721efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, 1373c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXCursorVisitor visitor, 1374c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor CXClientData client_data); 13751efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1376c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1377c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1378c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 13791efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1380c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1381c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 1382c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 13831efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * These routines provide the ability to determine references within and 1384c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * across translation units, by providing the names of the entities referenced 1385c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by cursors, follow reference cursors to the declarations they reference, 1386c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * and associate declarations with their definitions. 1387c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1388c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 1389c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 13901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1391c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1392c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 1393c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * by the given cursor. 1394c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1395c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * A Unified Symbol Resolution (USR) is a string that identifies a particular 1396c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * entity (function, class, variable, etc.) within a program. USRs can be 1397c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * compared across translation units to determine, e.g., when references in 1398c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * one translation refer to an entity defined in another translation unit. 1399c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1400c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); 1401c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1402c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1403896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C class. 1404896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */ 1405896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); 1406896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1407896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/** 1408896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C category. 1409896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */ 1410896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString 141166ccaec73706f3623d2e7d191fe2c944feedcc2bTed Kremenek clang_constructUSR_ObjCCategory(const char *class_name, 1412896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek const char *category_name); 1413896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1414896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/** 1415896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C protocol. 1416896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */ 1417896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString 1418896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek clang_constructUSR_ObjCProtocol(const char *protocol_name); 1419896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1420896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1421896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/** 1422896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C instance variable and 1423896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * the USR for its containing class. 1424896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */ 1425896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, 1426896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek CXString classUSR); 1427896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1428896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/** 1429896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C method and 1430896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * the USR for its containing class. 1431896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */ 1432896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, 1433896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek unsigned isInstanceMethod, 1434896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek CXString classUSR); 1435896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1436896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/** 1437896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Construct a USR for a specified Objective-C property and the USR 1438896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * for its containing class. 1439896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek */ 1440896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, 1441896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek CXString classUSR); 1442896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1443896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek/** 1444c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \brief Retrieve a name for the entity referenced by this cursor. 1445c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 1446c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas GregorCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); 1447c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor 1448c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor/** \brief For a cursor that is a reference, retrieve a cursor representing the 1449c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * entity that it references. 1450c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * 1451c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Reference cursors refer to other entities in the AST. For example, an 1452c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * Objective-C superclass reference cursor refers to an Objective-C class. 14531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * This function produces the cursor for the Objective-C class from the 1454c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * cursor for the superclass reference. If the input cursor is a declaration or 1455c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor * definition, it returns that declaration or definition unchanged. 14561efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Otherwise, returns the NULL cursor. 1457c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas Gregor */ 1458c5d1e9375d71e66d22456e7cc52cc7c0a5c65c3fDouglas GregorCINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); 1459b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor 14601efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 1461b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief For a cursor that is either a reference to or a declaration 1462b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * of some entity, retrieve a cursor that describes the definition of 1463b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * that entity. 1464b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 1465b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * Some entities can be declared multiple times within a translation 1466b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * unit, but only one of those declarations can also be a 1467b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * definition. For example, given: 1468b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 1469b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \code 1470b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int f(int, int); 1471b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int g(int x, int y) { return f(x, y); } 1472b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int f(int a, int b) { return a + b; } 1473b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * int f(int, int); 1474b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \endcode 1475b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 1476b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * there are three declarations of the function "f", but only the 1477b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * second one is a definition. The clang_getCursorDefinition() 1478b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * function will take any cursor pointing to a declaration of "f" 1479b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * (the first or fourth lines of the example) or a cursor referenced 1480b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * that uses "f" (the call to "f' inside "g") and will return a 1481b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * declaration cursor pointing to the definition (the second "f" 1482b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * declaration). 1483b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * 1484b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * If given a cursor for which there is no corresponding definition, 1485b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * e.g., because there is no definition of that entity within this 1486b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * translation unit, returns a NULL cursor. 1487b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */ 1488b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); 1489b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor 14901efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar/** 1491b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * \brief Determine whether the declaration pointed to by this cursor 1492b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor * is also a definition of that entity. 1493b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor */ 1494b699866820102a69d83d6ac6941985c5ef4e8c40Douglas GregorCINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); 1495b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor 1496c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1497c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1498c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 14991efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1500c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 15019ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * \defgroup CINDEX_CPP C++ AST introspection 15029ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * 15039ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * The routines in this group provide access information in the ASTs specific 15049ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * to C++ language features. 15059ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * 15069ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * @{ 15079ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek */ 15089ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek 15099ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek/** 15109ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * \brief Determine if a C++ member function is declared 'static'. 15119ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek */ 15129ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed KremenekCINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); 15139ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek 15149ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek/** 15159ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek * @} 15169ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek */ 15179ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek 15189ada39a4ac82ff5f5087b0a7fa9ed0d32be55a3bTed Kremenek/** 15190045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * \defgroup CINDEX_LEX Token extraction and manipulation 15200045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * 15210045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * The routines in this group provide access to the tokens within a 15220045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * translation unit, along with a semantic mapping of those tokens to 15230045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * their corresponding cursors. 1524fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1525fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @{ 1526fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1527fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 1528fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1529fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a kind of token. 1530fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1531fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef enum CXTokenKind { 1532fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 1533fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief A token that contains some kind of punctuation. 1534fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1535fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Punctuation, 1536896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1537fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 15380045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * \brief A language keyword. 1539fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1540fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Keyword, 1541896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1542fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 1543fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief An identifier (that is not a keyword). 1544fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1545fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Identifier, 1546896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1547fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 1548fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief A numeric, string, or character literal. 1549fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1550fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Literal, 1551896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1552fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /** 1553fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief A comment. 1554fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1555fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken_Comment 1556fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXTokenKind; 1557fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 1558fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1559fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Describes a single preprocessing token. 1560fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1561fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregortypedef struct { 1562fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor unsigned int_data[4]; 1563fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor void *ptr_data; 1564fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor} CXToken; 1565fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 1566fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1567fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the kind of the given token. 1568fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1569fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); 1570896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1571fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1572fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Determine the spelling of the given token. 1573fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1574fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * The spelling of a token is the textual representation of that token, e.g., 1575fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * the text of an identifier or keyword. 1576fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1577fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 1578896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1579fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1580fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve the source location of the given token. 1581fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1582896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, 1583fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken); 1584896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1585fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1586fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Retrieve a source range that covers the given token. 1587fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1588fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 1589fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 1590fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1591fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Tokenize the source code described by the given range into raw 1592fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * lexical tokens. 1593fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1594fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit whose text is being tokenized. 1595fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1596fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Range the source range in which text should be tokenized. All of the 1597fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * tokens produced by tokenization will fall within this source range, 1598fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1599fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens this pointer will be set to point to the array of tokens 1600fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that occur within the given source range. The returned pointer must be 1601fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * freed with clang_disposeTokens() before the translation unit is destroyed. 1602fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1603fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens will be set to the number of tokens in the \c *Tokens 1604fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * array. 1605fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1606fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1607fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, 1608fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken **Tokens, unsigned *NumTokens); 1609896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1610fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1611fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Annotate the given set of tokens by providing cursors for each token 1612fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * that can be mapped to a specific entity within the abstract syntax tree. 1613fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 16140045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * This token-annotation routine is equivalent to invoking 16150045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() for the source locations of each of the 16160045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * tokens. The cursors provided are filtered, so that only those 16170045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * cursors that have a direct correspondence to the token are 16180045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * accepted. For example, given a function call \c f(x), 16190045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * clang_getCursor() would provide the following cursors: 16200045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * 16210045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 16220045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 16230045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 16240045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * 16250045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * Only the first and last of these cursors will occur within the 16260045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * annotate, since the tokens "f" and "x' directly refer to a function 16270045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * and a variable, respectively, but the parentheses are just a small 16280045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * part of the full syntax of the function call expression, which is 16290045e9fe1f7dfc37f1ea7bdb9b70bcdb6700f0c0Douglas Gregor * not provided as an annotation. 1630fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1631fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param TU the translation unit that owns the given tokens. 1632fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1633fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Tokens the set of tokens to annotate. 1634fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1635fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param NumTokens the number of tokens in \p Tokens. 1636fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * 1637fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \param Cursors an array of \p NumTokens cursors, whose contents will be 1638fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * replaced with the cursors corresponding to each token. 1639fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1640fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas GregorCINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, 1641fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken *Tokens, unsigned NumTokens, 1642fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXCursor *Cursors); 1643896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1644fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1645fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * \brief Free the given set of tokens. 1646fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1647896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, 1648fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor CXToken *Tokens, unsigned NumTokens); 1649896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1650fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1651fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor * @} 1652fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor */ 1653896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 1654fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor/** 1655c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_DEBUG Debugging facilities 1656c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1657c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * These routines are used for testing and debugging, only, and should not 1658c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * be relied upon. 1659c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1660c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 1661c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 16621efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 16634ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */ 1664e68fff6fc083c6270d835216a3de0b82c6ef0310Ted KremenekCINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); 16651efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, 16661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar const char **startBuf, 16674ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff const char **endBuf, 16684ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *startLine, 16694ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *startColumn, 16704ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *endLine, 16714ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff unsigned *endColumn); 16720a812cf707da15dadd19fdeb0178b9707f4e01a6Douglas GregorCINDEX_LINKAGE void clang_enableStackTraces(void); 16730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 1674c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 1675c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 16761efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1677c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 1678c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * \defgroup CINDEX_CODE_COMPLET Code completion 1679c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1680c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * Code completion involves taking an (incomplete) source file, along with 1681c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * knowledge of where the user is actively editing that file, and suggesting 1682c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * syntactically- and semantically-valid constructs that the user might want to 1683c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * use at that particular point in the source code. These data structures and 1684c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * routines provide support for code completion. 1685c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * 1686c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @{ 1687c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 16881efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 1689c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 16900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result. 16910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 16920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion 16930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the 16940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected. 16950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which 16960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g., 16970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of 16980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace 16990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 17001efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * description of the different kinds of chunks. 17010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString; 17031efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 17040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 17050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion. 17060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct { 17080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 17091efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief The kind of entity that this completion refers to. 17100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17111efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * The cursor kind will be a macro, keyword, or a declaration (one of the 17120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * *Decl cursor kinds), describing the entity that the completion is 17130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * referring to. 17140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \todo In the future, we would like to provide a full cursor, to allow 17160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the client to extract additional information from declaration. 17170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor enum CXCursorKind CursorKind; 17191efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 17201efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar /** 17210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief The code-completion string that describes how to insert this 17220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion result into the editing buffer. 17230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionString CompletionString; 17250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult; 17260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor 17270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 17280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string. 17290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17301efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * Each "chunk" within a code-completion string (\c CXCompletionString) is 17311efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * either a piece of text with a specific "kind" that describes how that text 17320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string. 17330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind { 17350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 17360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A code-completion string that describes "optional" text that 17370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * could be a part of the template (but is not required). 17380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * The Optional chunk is the only kind of chunk that has a code-completion 17401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * string for its representation, which is accessible via 17410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c clang_getCompletionChunkCompletionString(). The code-completion string 17420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * describes an additional part of the template that is completely optional. 17430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * For example, optional chunks can be used to describe the placeholders for 17440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * arguments that match up with defaulted function parameters, e.g. given: 17450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \code 17470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * void f(int x, float y = 3.14, double z = 2.71828); 17480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \endcode 17490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * The code-completion string for this function would contain: 17510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a TypedText chunk for "f". 17520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a LeftParen chunk for "(". 17530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Placeholder chunk for "int x" 17540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - an Optional chunk containing the remaining defaulted arguments, e.g., 17550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Comma chunk for "," 175671570182471d502a97f7f175aa527152544c75f2Daniel Dunbar * - a Placeholder chunk for "float y" 17570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - an Optional chunk containing the last defaulted argument: 17580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Comma chunk for "," 17590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a Placeholder chunk for "double z" 17600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - a RightParen chunk for ")" 17610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 176271570182471d502a97f7f175aa527152544c75f2Daniel Dunbar * There are many ways to handle Optional chunks. Two simple approaches are: 17630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - Completely ignore optional chunks, in which case the template for the 17640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * function "f" would only include the first parameter ("int x"). 17650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * - Fully expand all optional chunks, in which case the template for the 17660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * function "f" would have all of the parameters. 17670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Optional, 17690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 17700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Text that a user would be expected to type to get this 17711efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * code-completion result. 17720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17731efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * There will be exactly one "typed text" chunk in a semantic string, which 17741efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * will typically provide the spelling of a keyword or the name of a 17750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * declaration that could be used at the current code point. Clients are 17760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * expected to filter the code-completion results based on the text in this 17770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * chunk. 17780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_TypedText, 17800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 17810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Text that should be inserted as part of a code-completion result. 17820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A "text" chunk represents text that is part of the template to be 17840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * inserted into user code should this particular code-completion result 17850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * be selected. 17860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Text, 17880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 17890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Placeholder text that should be replaced by the user. 17900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 17910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A "placeholder" chunk marks a place where the user should insert text 17920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * into the code-completion template. For example, placeholders might mark 17930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the function parameters for a function declaration, to indicate that the 17940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * user should provide arguments for each of those parameters. The actual 17950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * text in a placeholder is a suggestion for the text to display before 17960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the user replaces the placeholder with real code. 17970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 17980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Placeholder, 17990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Informative text that should be displayed but never inserted as 18010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * part of the template. 18021efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * 18030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * An "informative" chunk contains annotations that can be displayed to 18040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * help the user decide whether a particular code-completion result is the 18050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * right option, but which is not part of the actual template to be inserted 18060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * by code completion. 18070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_Informative, 18090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Text that describes the current parameter when code-completion is 18110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * referring to function call, message send, or template specialization. 18120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 18130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A "current parameter" chunk occurs when code-completion is providing 18140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * information about a parameter corresponding to the argument at the 18150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion point. For example, given a function 18160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 18170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \code 18180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * int add(int x, int y); 18190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \endcode 18200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 18210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * and the source code \c add(, where the code-completion point is after the 18220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "(", the code-completion string will contain a "current parameter" chunk 18230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for "int x", indicating that the current argument will initialize that 18240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * parameter. After typing further, to \c add(17, (where the code-completion 18251efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * point is after the ","), the code-completion string will contain a 18260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "current paremeter" chunk to "int y". 18270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_CurrentParameter, 18290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left parenthesis ('('), used to initiate a function call or 18310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * signal the beginning of a function parameter list. 18320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftParen, 18340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right parenthesis (')'), used to finish a function call or 18360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * signal the end of a function parameter list. 18370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightParen, 18390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left bracket ('['). 18410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftBracket, 18430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right bracket (']'). 18450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightBracket, 18470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left brace ('{'). 18490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftBrace, 18510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right brace ('}'). 18530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightBrace, 18550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A left angle bracket ('<'). 18570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_LeftAngle, 18590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A right angle bracket ('>'). 18610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 18620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor CXCompletionChunk_RightAngle, 18630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor /** 18640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A comma separator (','). 18650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 1866ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor CXCompletionChunk_Comma, 1867ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor /** 18681efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Text that specifies the result type of a given result. 1869ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor * 1870ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor * This special kind of informative chunk is not meant to be inserted into 18711efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * the text buffer. Rather, it is meant to illustrate the type that an 1872ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor * expression using the given completion string would have. 1873ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor */ 187401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_ResultType, 187501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 187601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * \brief A colon (':'). 187701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 187801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_Colon, 187901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 188001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * \brief A semicolon (';'). 188101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 188201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_SemiColon, 188301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 188401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * \brief An '=' sign. 188501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 188601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_Equal, 188701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 188801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * Horizontal space (' '). 188901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 189001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_HorizontalSpace, 189101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor /** 189201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * Vertical space ('\n'), after which it is generally a good idea to 189301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor * perform indentation. 189401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor */ 189501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor CXCompletionChunk_VerticalSpace 18960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor}; 18971efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 18980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 18990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string. 19000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query. 19020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string. 19040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number. 19060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 19071efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE enum CXCompletionChunkKind 19080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string, 19090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor unsigned chunk_number); 19101efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 19110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 19121efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the text associated with a particular chunk within a 19130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string. 19140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query. 19160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string. 19180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number. 19200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 19212ef6f8f5a35a60870594c5b04e0aa2bf22c6886fTed KremenekCINDEX_LINKAGE CXString 19220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string, 19230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor unsigned chunk_number); 19240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor 19250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 19261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \brief Retrieve the completion string associated with a particular chunk 19270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string. 19280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query. 19300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string. 19320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index 19340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion 19350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string. 19360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 19370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString 19380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string, 19390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor unsigned chunk_number); 19401efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 19410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 19420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string. 19430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 19440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned 19450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string); 19460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor 19470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/** 194812e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * \brief Determine the priority of this code completion. 194912e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * 195012e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * The priority of a code completion indicates how likely it is that this 195112e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * particular completion is the completion that the user will select. The 195212e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * priority is selected by various internal heuristics. 195312e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * 195412e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * \param completion_string The completion string to query. 195512e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * 195612e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * \returns The priority of this completion string. Smaller values indicate 195712e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor * higher-priority (more likely) completions. 195812e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor */ 195912e131385e892e3723483a1081a89bcad29c8a84Douglas GregorCINDEX_LINKAGE unsigned 196012e131385e892e3723483a1081a89bcad29c8a84Douglas Gregorclang_getCompletionPriority(CXCompletionString completion_string); 196112e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor 196212e131385e892e3723483a1081a89bcad29c8a84Douglas Gregor/** 1963ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion. 1964ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * 1965ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as 19661efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * produced by \c clang_codeComplete. Its contents must be freed by 1967ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults. 1968ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 1969ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct { 1970ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor /** 1971ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief The code-completion results. 1972ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 1973ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor CXCompletionResult *Results; 1974ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor 1975ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor /** 1976ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief The number of code-completion results stored in the 1977ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c Results array. 1978ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 1979ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned NumResults; 1980ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults; 1981ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor 1982ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/** 19830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file. 19840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and 19860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential 19870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model 19880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file, 19890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has 19900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed 19910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the 19921efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * current location in the C/Objective-C/C++ grammar and the state of 19930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are 1994ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure. 19950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 19960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the 19971efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * user types punctuation characters or whitespace, at which point the 19980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p 19990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then 20000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">", 20010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that 20020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the 20030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results 20040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for 20050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after 20060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 20070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only 20080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface 2009ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion 20100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must 20110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency. 20120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 20130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code 20140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion. 20150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 20168506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to 20178506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the 20188506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results 20198506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced. NOTE: One can also specify NULL for this argument if the 20208506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args. 20210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 20220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in 20230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args. 20240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 20250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang 20261efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * compiler to build the given source file. This should include all of the 20270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header 20281efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * includes, etc., but should not include any information specific to 20290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion. 20300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 2031735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p 2032735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files. 2033735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 2034735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk 2035735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of 2036c6f530defd937faa1c00998e60deea6368526961Ted Kremenek * those files. The contents and name of these files (as specified by 2037c6f530defd937faa1c00998e60deea6368526961Ted Kremenek * CXUnsavedFile) are copied when necessary, so the client only needs to 2038c6f530defd937faa1c00998e60deea6368526961Ted Kremenek * guarantee their validity until the call to this function returns. 2039735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * 20400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion 20410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the 20421efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * source filename. However, the completion filename may also be a file 20431efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * included by the source file, which is required when producing 20440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header. 20450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 20460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur. 20470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 20481efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar * \param complete_column the column at which code-completion should occur. 20490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that 20500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token. 20510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * 2052936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * \param diag_callback callback function that will receive any diagnostics 2053936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * emitted while processing this source file. If NULL, diagnostics will be 2054936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * suppressed. 2055936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * 2056936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * \param diag_client_data client data that will be passed to the diagnostic 2057936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * callback function. 2058936ea3b590117d2cd73b1b92621d06c4a7edbe60Douglas Gregor * 2059ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure 2060ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be 2061ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code 2062ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL. 2063ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */ 20641efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE 20651efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, 2066ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor const char *source_filename, 20671efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar int num_command_line_args, 2068ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor const char **command_line_args, 2069ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned num_unsaved_files, 2070ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor struct CXUnsavedFile *unsaved_files, 2071ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor const char *complete_filename, 2072ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor unsigned complete_line, 2073a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned complete_column); 20741efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 2075ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/** 2076ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results. 20770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */ 20781efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel DunbarCINDEX_LINKAGE 2079ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); 20801efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 208120d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor/** 2082a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Determine the number of diagnostics produced prior to the 2083a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * location where code completion was performed. 2084a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */ 2085896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE 2086a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorunsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); 2087a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 2088a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/** 2089a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \brief Retrieve a diagnostic associated with the given code completion. 2090a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * 2091a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Result the code completion results to query. 2092a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \param Index the zero-based diagnostic number to retrieve. 2093a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * 2094a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * \returns the requested diagnostic. This diagnostic must be freed 2095a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor * via a call to \c clang_disposeDiagnostic(). 2096a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */ 2097896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted KremenekCINDEX_LINKAGE 2098a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas GregorCXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, 2099a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned Index); 2100a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 2101a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/** 210220d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor * @} 210320d416c36b46dd19ee0b1ea2d0266ae43be86e51Douglas Gregor */ 21041efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 21051efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 210604bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/** 210704bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * \defgroup CINDEX_MISC Miscellaneous utility functions 210804bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * 210904bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @{ 211004bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */ 211123e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek 211223e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek/** 211323e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek * \brief Return a version string, suitable for showing to a user, but not 211423e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek * intended to be parsed (the format is not guaranteed to be stable). 211523e1ad09bb68f929212e0ff51206258d06e7f6cfTed Kremenek */ 2116a2a9d6e4e5b6001b86b7dfc5db1ea296ce29a3d3Ted KremenekCINDEX_LINKAGE CXString clang_getClangVersion(); 211704bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek 211804bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek/** 211916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * \brief Return a version string, suitable for showing to a user, but not 212016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * intended to be parsed (the format is not guaranteed to be stable). 212116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */ 2122896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 2123896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek 212416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek /** 2125896b70ffc348f6e2c680b5fb5841984d5785b7b5Ted Kremenek * \brief Visitor invoked for each file in a translation unit 212616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * (used with clang_getInclusions()). 212716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * 212816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * This visitor function will be invoked by clang_getInclusions() for each 212916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * file included (either at the top-level or by #include directives) within 213016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * a translation unit. The first argument is the file being included, and 213116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * the second and third arguments provide the inclusion stack. The 213216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * array is sorted in order of immediate inclusion. For example, 213316b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * the first element refers to the location that included 'included_file'. 213416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */ 213516b55a71695a33c094383295cc7b7a2080e098daTed Kremenektypedef void (*CXInclusionVisitor)(CXFile included_file, 213616b55a71695a33c094383295cc7b7a2080e098daTed Kremenek CXSourceLocation* inclusion_stack, 213716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek unsigned include_len, 213816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek CXClientData client_data); 213916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek 214016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek/** 214116b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * \brief Visit the set of preprocessor inclusions in a translation unit. 214216b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * The visitor function is called with the provided data for every included 214316b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * file. This does not include headers included by the PCH file (unless one 214416b55a71695a33c094383295cc7b7a2080e098daTed Kremenek * is inspecting the inclusions in the PCH file itself). 214516b55a71695a33c094383295cc7b7a2080e098daTed Kremenek */ 214616b55a71695a33c094383295cc7b7a2080e098daTed KremenekCINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, 214716b55a71695a33c094383295cc7b7a2080e098daTed Kremenek CXInclusionVisitor visitor, 214816b55a71695a33c094383295cc7b7a2080e098daTed Kremenek CXClientData client_data); 214916b55a71695a33c094383295cc7b7a2080e098daTed Kremenek 215016b55a71695a33c094383295cc7b7a2080e098daTed Kremenek/** 215104bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek * @} 215204bb716aea8fd2372ac10b0c640cabc5e5caa615Ted Kremenek */ 21531efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 2154c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor/** 2155c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor * @} 2156c42fefa51f7555bb3644a7cde2ca4bfd0d848d74Douglas Gregor */ 21571efcf3d137c11fb6b21c385911e0d2ca59ca94c3Daniel Dunbar 2158d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus 2159d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek} 2160d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif 2161d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif 2162d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek 2163