Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 1 | /*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\ |
| 2 | |* *| |
| 3 | |* The LLVM Compiler Infrastructure *| |
| 4 | |* *| |
| 5 | |* This file is distributed under the University of Illinois Open Source *| |
| 6 | |* License. See LICENSE.TXT for details. *| |
| 7 | |* *| |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* *| |
| 10 | |* This header provides a public inferface to a Clang library for extracting *| |
| 11 | |* high-level symbol information from source files without exposing the full *| |
| 12 | |* Clang C++ API. *| |
| 13 | |* *| |
| 14 | \*===----------------------------------------------------------------------===*/ |
| 15 | |
| 16 | #ifndef CLANG_C_INDEX_H |
| 17 | #define CLANG_C_INDEX_H |
| 18 | |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 19 | #include <sys/stat.h> |
Chandler Carruth | 3d31560 | 2009-12-17 09:27:29 +0000 | [diff] [blame] | 20 | #include <time.h> |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 21 | #include <stdio.h> |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 22 | |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 27 | /* MSVC DLL import/export. */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 28 | #ifdef _MSC_VER |
| 29 | #ifdef _CINDEX_LIB_ |
| 30 | #define CINDEX_LINKAGE __declspec(dllexport) |
| 31 | #else |
| 32 | #define CINDEX_LINKAGE __declspec(dllimport) |
| 33 | #endif |
| 34 | #else |
| 35 | #define CINDEX_LINKAGE |
| 36 | #endif |
| 37 | |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 38 | /** \defgroup CINDEX C Interface to Clang |
| 39 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 40 | * The C Interface to Clang provides a relatively small API that exposes |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 41 | * facilities for parsing source code into an abstract syntax tree (AST), |
| 42 | * loading already-parsed ASTs, traversing the AST, associating |
| 43 | * physical source locations with elements within the AST, and other |
| 44 | * facilities that support Clang-based development tools. |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 45 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 46 | * This C interface to Clang will never provide all of the information |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 47 | * representation stored in Clang's C++ AST, nor should it: the intent is to |
| 48 | * maintain an API that is relatively stable from one release to the next, |
| 49 | * providing only the basic functionality needed to support development tools. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 50 | * |
| 51 | * To avoid namespace pollution, data types are prefixed with "CX" and |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 52 | * functions are prefixed with "clang_". |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 53 | * |
| 54 | * @{ |
| 55 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 56 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 57 | /** |
| 58 | * \brief An "index" that consists of a set of translation units that would |
| 59 | * typically be linked together into an executable or library. |
| 60 | */ |
| 61 | typedef void *CXIndex; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 62 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 63 | /** |
| 64 | * \brief A single translation unit, which resides in an index. |
| 65 | */ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 66 | typedef void *CXTranslationUnit; /* A translation unit instance. */ |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 67 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 68 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 69 | * \brief Opaque pointer representing client data that will be passed through |
| 70 | * to various callbacks and visitors. |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 71 | */ |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 72 | typedef void *CXClientData; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 73 | |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 74 | /** |
| 75 | * \brief Provides the contents of a file that has not yet been saved to disk. |
| 76 | * |
| 77 | * Each CXUnsavedFile instance provides the name of a file on the |
| 78 | * system along with the current contents of that file that have not |
| 79 | * yet been saved to disk. |
| 80 | */ |
| 81 | struct CXUnsavedFile { |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 82 | /** |
| 83 | * \brief The file whose contents have not yet been saved. |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 84 | * |
| 85 | * This file must already exist in the file system. |
| 86 | */ |
| 87 | const char *Filename; |
| 88 | |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 89 | /** |
Douglas Gregor | c8dfe5e | 2010-02-27 01:32:48 +0000 | [diff] [blame] | 90 | * \brief A buffer containing the unsaved contents of this file. |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 91 | */ |
| 92 | const char *Contents; |
| 93 | |
| 94 | /** |
Douglas Gregor | c8dfe5e | 2010-02-27 01:32:48 +0000 | [diff] [blame] | 95 | * \brief The length of the unsaved contents of this buffer. |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 96 | */ |
| 97 | unsigned long Length; |
| 98 | }; |
| 99 | |
Peter Collingbourne | 076c22a | 2010-08-24 00:31:37 +0000 | [diff] [blame] | 100 | /** |
| 101 | * \brief Describes the availability of a particular entity, which indicates |
| 102 | * whether the use of this entity will result in a warning or error due to |
| 103 | * it being deprecated or unavailable. |
| 104 | */ |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 105 | enum CXAvailabilityKind { |
Peter Collingbourne | 076c22a | 2010-08-24 00:31:37 +0000 | [diff] [blame] | 106 | /** |
| 107 | * \brief The entity is available. |
| 108 | */ |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 109 | CXAvailability_Available, |
Peter Collingbourne | 076c22a | 2010-08-24 00:31:37 +0000 | [diff] [blame] | 110 | /** |
| 111 | * \brief The entity is available, but has been deprecated (and its use is |
| 112 | * not recommended). |
| 113 | */ |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 114 | CXAvailability_Deprecated, |
Peter Collingbourne | 076c22a | 2010-08-24 00:31:37 +0000 | [diff] [blame] | 115 | /** |
| 116 | * \brief The entity is not available; any use of it will be an error. |
| 117 | */ |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 118 | CXAvailability_NotAvailable |
| 119 | }; |
| 120 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 121 | /** |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 122 | * \defgroup CINDEX_STRING String manipulation routines |
| 123 | * |
| 124 | * @{ |
| 125 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 126 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 127 | /** |
| 128 | * \brief A character string. |
| 129 | * |
| 130 | * The \c CXString type is used to return strings from the interface when |
| 131 | * the ownership of that string might different from one call to the next. |
| 132 | * Use \c clang_getCString() to retrieve the string data and, once finished |
| 133 | * with the string data, call \c clang_disposeString() to free the string. |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 134 | */ |
| 135 | typedef struct { |
| 136 | const char *Spelling; |
| 137 | /* A 1 value indicates the clang_ indexing API needed to allocate the string |
| 138 | (and it must be freed by clang_disposeString()). */ |
| 139 | int MustFreeString; |
| 140 | } CXString; |
| 141 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 142 | /** |
| 143 | * \brief Retrieve the character data associated with the given string. |
| 144 | */ |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 145 | CINDEX_LINKAGE const char *clang_getCString(CXString string); |
| 146 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 147 | /** |
| 148 | * \brief Free the given string, |
| 149 | */ |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 150 | CINDEX_LINKAGE void clang_disposeString(CXString string); |
| 151 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 152 | /** |
| 153 | * @} |
| 154 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 155 | |
| 156 | /** |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 157 | * \brief clang_createIndex() provides a shared context for creating |
| 158 | * translation units. It provides two options: |
| 159 | * |
| 160 | * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" |
| 161 | * declarations (when loading any new translation units). A "local" declaration |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 162 | * is one that belongs in the translation unit itself and not in a precompiled |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 163 | * header that was used by the translation unit. If zero, all declarations |
| 164 | * will be enumerated. |
| 165 | * |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 166 | * Here is an example: |
| 167 | * |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 168 | * // excludeDeclsFromPCH = 1, displayDiagnostics=1 |
| 169 | * Idx = clang_createIndex(1, 1); |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 170 | * |
| 171 | * // IndexTest.pch was produced with the following command: |
| 172 | * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" |
| 173 | * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); |
| 174 | * |
| 175 | * // This will load all the symbols from 'IndexTest.pch' |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 176 | * clang_visitChildren(clang_getTranslationUnitCursor(TU), |
Douglas Gregor | 002a528 | 2010-01-20 21:37:00 +0000 | [diff] [blame] | 177 | * TranslationUnitVisitor, 0); |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 178 | * clang_disposeTranslationUnit(TU); |
| 179 | * |
| 180 | * // This will load all the symbols from 'IndexTest.c', excluding symbols |
| 181 | * // from 'IndexTest.pch'. |
Daniel Dunbar | fd9f234 | 2010-01-25 00:43:14 +0000 | [diff] [blame] | 182 | * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; |
| 183 | * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, |
| 184 | * 0, 0); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 185 | * clang_visitChildren(clang_getTranslationUnitCursor(TU), |
| 186 | * TranslationUnitVisitor, 0); |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 187 | * clang_disposeTranslationUnit(TU); |
| 188 | * |
| 189 | * This process of creating the 'pch', loading it separately, and using it (via |
| 190 | * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks |
| 191 | * (which gives the indexer the same performance benefit as the compiler). |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 192 | */ |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 193 | CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, |
| 194 | int displayDiagnostics); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 195 | |
Douglas Gregor | 0087e1a | 2010-02-08 23:03:06 +0000 | [diff] [blame] | 196 | /** |
| 197 | * \brief Destroy the given index. |
| 198 | * |
| 199 | * The index must not be destroyed until all of the translation units created |
| 200 | * within that index have been destroyed. |
| 201 | */ |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 202 | CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 203 | |
| 204 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 205 | * \defgroup CINDEX_FILES File manipulation routines |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 206 | * |
| 207 | * @{ |
| 208 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 209 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 210 | /** |
| 211 | * \brief A particular source file that is part of a translation unit. |
| 212 | */ |
| 213 | typedef void *CXFile; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 214 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * \brief Retrieve the complete file and path name of the given file. |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 218 | */ |
Ted Kremenek | 7484407 | 2010-02-17 00:41:20 +0000 | [diff] [blame] | 219 | CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 220 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 221 | /** |
| 222 | * \brief Retrieve the last modification time of the given file. |
| 223 | */ |
Douglas Gregor | 08b0e8d | 2009-10-31 15:48:08 +0000 | [diff] [blame] | 224 | CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 225 | |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 226 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 227 | * \brief Retrieve a file handle within the given translation unit. |
| 228 | * |
| 229 | * \param tu the translation unit |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 230 | * |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 231 | * \param file_name the name of the file. |
| 232 | * |
| 233 | * \returns the file handle for the named file in the translation unit \p tu, |
| 234 | * or a NULL file handle if the file was not a part of this translation unit. |
| 235 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 236 | CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 237 | const char *file_name); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 238 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 239 | /** |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 240 | * @} |
| 241 | */ |
| 242 | |
| 243 | /** |
| 244 | * \defgroup CINDEX_LOCATIONS Physical source locations |
| 245 | * |
| 246 | * Clang represents physical source locations in its abstract syntax tree in |
| 247 | * great detail, with file, line, and column information for the majority of |
| 248 | * the tokens parsed in the source code. These data types and functions are |
| 249 | * used to represent source location information, either for a particular |
| 250 | * point in the program or for a range of points in the program, and extract |
| 251 | * specific location information from those data types. |
| 252 | * |
| 253 | * @{ |
| 254 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 255 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 256 | /** |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 257 | * \brief Identifies a specific source location within a translation |
| 258 | * unit. |
| 259 | * |
| 260 | * Use clang_getInstantiationLocation() to map a source location to a |
| 261 | * particular file, line, and column. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 262 | */ |
| 263 | typedef struct { |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 264 | void *ptr_data[2]; |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 265 | unsigned int_data; |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 266 | } CXSourceLocation; |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 267 | |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 268 | /** |
Daniel Dunbar | d52864b | 2010-02-14 10:02:57 +0000 | [diff] [blame] | 269 | * \brief Identifies a half-open character range in the source code. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 270 | * |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 271 | * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the |
| 272 | * starting and end locations from a source range, respectively. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 273 | */ |
| 274 | typedef struct { |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 275 | void *ptr_data[2]; |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 276 | unsigned begin_int_data; |
| 277 | unsigned end_int_data; |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 278 | } CXSourceRange; |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 279 | |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 280 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 281 | * \brief Retrieve a NULL (invalid) source location. |
| 282 | */ |
| 283 | CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 284 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 285 | /** |
| 286 | * \determine Determine whether two source locations, which must refer into |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 287 | * the same translation unit, refer to exactly the same point in the source |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 288 | * code. |
| 289 | * |
| 290 | * \returns non-zero if the source locations refer to the same location, zero |
| 291 | * if they refer to different locations. |
| 292 | */ |
| 293 | CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, |
| 294 | CXSourceLocation loc2); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 295 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 296 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 297 | * \brief Retrieves the source location associated with a given file/line/column |
| 298 | * in a particular translation unit. |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 299 | */ |
| 300 | CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, |
| 301 | CXFile file, |
| 302 | unsigned line, |
| 303 | unsigned column); |
David Chisnall | 83889a7 | 2010-10-15 17:07:39 +0000 | [diff] [blame] | 304 | /** |
| 305 | * \brief Retrieves the source location associated with a given character offset |
| 306 | * in a particular translation unit. |
| 307 | */ |
| 308 | CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, |
| 309 | CXFile file, |
| 310 | unsigned offset); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 311 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 312 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 313 | * \brief Retrieve a NULL (invalid) source range. |
| 314 | */ |
| 315 | CINDEX_LINKAGE CXSourceRange clang_getNullRange(); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 316 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 317 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 318 | * \brief Retrieve a source range given the beginning and ending source |
| 319 | * locations. |
| 320 | */ |
| 321 | CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, |
| 322 | CXSourceLocation end); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 324 | /** |
Douglas Gregor | 46766dc | 2010-01-26 19:19:08 +0000 | [diff] [blame] | 325 | * \brief Retrieve the file, line, column, and offset represented by |
| 326 | * the given source location. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 327 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 328 | * \param location the location within a source file that will be decomposed |
| 329 | * into its parts. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 330 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 331 | * \param file [out] if non-NULL, will be set to the file to which the given |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 332 | * source location points. |
| 333 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 334 | * \param line [out] if non-NULL, will be set to the line to which the given |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 335 | * source location points. |
| 336 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 337 | * \param column [out] if non-NULL, will be set to the column to which the given |
| 338 | * source location points. |
Douglas Gregor | 46766dc | 2010-01-26 19:19:08 +0000 | [diff] [blame] | 339 | * |
| 340 | * \param offset [out] if non-NULL, will be set to the offset into the |
| 341 | * buffer to which the given source location points. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 342 | */ |
| 343 | CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, |
| 344 | CXFile *file, |
| 345 | unsigned *line, |
Douglas Gregor | 46766dc | 2010-01-26 19:19:08 +0000 | [diff] [blame] | 346 | unsigned *column, |
| 347 | unsigned *offset); |
Douglas Gregor | e69517c | 2010-01-26 03:07:15 +0000 | [diff] [blame] | 348 | |
| 349 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 350 | * \brief Retrieve a source location representing the first character within a |
| 351 | * source range. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 352 | */ |
| 353 | CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); |
| 354 | |
| 355 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 356 | * \brief Retrieve a source location representing the last character within a |
| 357 | * source range. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 358 | */ |
| 359 | CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); |
| 360 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 361 | /** |
| 362 | * @} |
| 363 | */ |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 364 | |
| 365 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 366 | * \defgroup CINDEX_DIAG Diagnostic reporting |
| 367 | * |
| 368 | * @{ |
| 369 | */ |
| 370 | |
| 371 | /** |
| 372 | * \brief Describes the severity of a particular diagnostic. |
| 373 | */ |
| 374 | enum CXDiagnosticSeverity { |
| 375 | /** |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 376 | * \brief A diagnostic that has been suppressed, e.g., by a command-line |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 377 | * option. |
| 378 | */ |
| 379 | CXDiagnostic_Ignored = 0, |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 380 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 381 | /** |
| 382 | * \brief This diagnostic is a note that should be attached to the |
| 383 | * previous (non-note) diagnostic. |
| 384 | */ |
| 385 | CXDiagnostic_Note = 1, |
| 386 | |
| 387 | /** |
| 388 | * \brief This diagnostic indicates suspicious code that may not be |
| 389 | * wrong. |
| 390 | */ |
| 391 | CXDiagnostic_Warning = 2, |
| 392 | |
| 393 | /** |
| 394 | * \brief This diagnostic indicates that the code is ill-formed. |
| 395 | */ |
| 396 | CXDiagnostic_Error = 3, |
| 397 | |
| 398 | /** |
| 399 | * \brief This diagnostic indicates that the code is ill-formed such |
| 400 | * that future parser recovery is unlikely to produce useful |
| 401 | * results. |
| 402 | */ |
| 403 | CXDiagnostic_Fatal = 4 |
| 404 | }; |
| 405 | |
| 406 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 407 | * \brief A single diagnostic, containing the diagnostic's severity, |
| 408 | * location, text, source ranges, and fix-it hints. |
| 409 | */ |
| 410 | typedef void *CXDiagnostic; |
| 411 | |
| 412 | /** |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 413 | * \brief Determine the number of diagnostics produced for the given |
| 414 | * translation unit. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 415 | */ |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 416 | CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); |
| 417 | |
| 418 | /** |
| 419 | * \brief Retrieve a diagnostic associated with the given translation unit. |
| 420 | * |
| 421 | * \param Unit the translation unit to query. |
| 422 | * \param Index the zero-based diagnostic number to retrieve. |
| 423 | * |
| 424 | * \returns the requested diagnostic. This diagnostic must be freed |
| 425 | * via a call to \c clang_disposeDiagnostic(). |
| 426 | */ |
| 427 | CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, |
| 428 | unsigned Index); |
| 429 | |
| 430 | /** |
| 431 | * \brief Destroy a diagnostic. |
| 432 | */ |
| 433 | CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 434 | |
| 435 | /** |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 436 | * \brief Options to control the display of diagnostics. |
| 437 | * |
| 438 | * The values in this enum are meant to be combined to customize the |
| 439 | * behavior of \c clang_displayDiagnostic(). |
| 440 | */ |
| 441 | enum CXDiagnosticDisplayOptions { |
| 442 | /** |
| 443 | * \brief Display the source-location information where the |
| 444 | * diagnostic was located. |
| 445 | * |
| 446 | * When set, diagnostics will be prefixed by the file, line, and |
| 447 | * (optionally) column to which the diagnostic refers. For example, |
| 448 | * |
| 449 | * \code |
| 450 | * test.c:28: warning: extra tokens at end of #endif directive |
| 451 | * \endcode |
| 452 | * |
| 453 | * This option corresponds to the clang flag \c -fshow-source-location. |
| 454 | */ |
| 455 | CXDiagnostic_DisplaySourceLocation = 0x01, |
| 456 | |
| 457 | /** |
| 458 | * \brief If displaying the source-location information of the |
| 459 | * diagnostic, also include the column number. |
| 460 | * |
| 461 | * This option corresponds to the clang flag \c -fshow-column. |
| 462 | */ |
| 463 | CXDiagnostic_DisplayColumn = 0x02, |
| 464 | |
| 465 | /** |
| 466 | * \brief If displaying the source-location information of the |
| 467 | * diagnostic, also include information about source ranges in a |
| 468 | * machine-parsable format. |
| 469 | * |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 470 | * This option corresponds to the clang flag |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 471 | * \c -fdiagnostics-print-source-range-info. |
| 472 | */ |
| 473 | CXDiagnostic_DisplaySourceRanges = 0x04 |
| 474 | }; |
| 475 | |
| 476 | /** |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 477 | * \brief Format the given diagnostic in a manner that is suitable for display. |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 478 | * |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 479 | * This routine will format the given diagnostic to a string, rendering |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 480 | * the diagnostic according to the various options given. The |
| 481 | * \c clang_defaultDiagnosticDisplayOptions() function returns the set of |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 482 | * options that most closely mimics the behavior of the clang compiler. |
| 483 | * |
| 484 | * \param Diagnostic The diagnostic to print. |
| 485 | * |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 486 | * \param Options A set of options that control the diagnostic display, |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 487 | * created by combining \c CXDiagnosticDisplayOptions values. |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 488 | * |
| 489 | * \returns A new string containing for formatted diagnostic. |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 490 | */ |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 491 | CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, |
| 492 | unsigned Options); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 493 | |
| 494 | /** |
| 495 | * \brief Retrieve the set of display options most similar to the |
| 496 | * default behavior of the clang compiler. |
| 497 | * |
| 498 | * \returns A set of display options suitable for use with \c |
| 499 | * clang_displayDiagnostic(). |
| 500 | */ |
| 501 | CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); |
| 502 | |
| 503 | /** |
| 504 | * \brief Print a diagnostic to the given file. |
| 505 | */ |
| 506 | |
| 507 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 508 | * \brief Determine the severity of the given diagnostic. |
| 509 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 510 | CINDEX_LINKAGE enum CXDiagnosticSeverity |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 511 | clang_getDiagnosticSeverity(CXDiagnostic); |
| 512 | |
| 513 | /** |
| 514 | * \brief Retrieve the source location of the given diagnostic. |
| 515 | * |
| 516 | * This location is where Clang would print the caret ('^') when |
| 517 | * displaying the diagnostic on the command line. |
| 518 | */ |
| 519 | CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); |
| 520 | |
| 521 | /** |
| 522 | * \brief Retrieve the text of the given diagnostic. |
| 523 | */ |
| 524 | CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 525 | |
| 526 | /** |
| 527 | * \brief Determine the number of source ranges associated with the given |
| 528 | * diagnostic. |
| 529 | */ |
| 530 | CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 531 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 532 | /** |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 533 | * \brief Retrieve a source range associated with the diagnostic. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 534 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 535 | * A diagnostic's source ranges highlight important elements in the source |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 536 | * code. On the command line, Clang displays source ranges by |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 537 | * underlining them with '~' characters. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 538 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 539 | * \param Diagnostic the diagnostic whose range is being extracted. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 540 | * |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 541 | * \param Range the zero-based index specifying which range to |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 542 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 543 | * \returns the requested source range. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 544 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 545 | CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 546 | unsigned Range); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 547 | |
| 548 | /** |
| 549 | * \brief Determine the number of fix-it hints associated with the |
| 550 | * given diagnostic. |
| 551 | */ |
| 552 | CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); |
| 553 | |
| 554 | /** |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 555 | * \brief Retrieve the replacement information for a given fix-it. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 556 | * |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 557 | * Fix-its are described in terms of a source range whose contents |
| 558 | * should be replaced by a string. This approach generalizes over |
| 559 | * three kinds of operations: removal of source code (the range covers |
| 560 | * the code to be removed and the replacement string is empty), |
| 561 | * replacement of source code (the range covers the code to be |
| 562 | * replaced and the replacement string provides the new code), and |
| 563 | * insertion (both the start and end of the range point at the |
| 564 | * insertion location, and the replacement string provides the text to |
| 565 | * insert). |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 566 | * |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 567 | * \param Diagnostic The diagnostic whose fix-its are being queried. |
| 568 | * |
| 569 | * \param FixIt The zero-based index of the fix-it. |
| 570 | * |
| 571 | * \param ReplacementRange The source range whose contents will be |
| 572 | * replaced with the returned replacement string. Note that source |
| 573 | * ranges are half-open ranges [a, b), so the source code should be |
| 574 | * replaced from a and up to (but not including) b. |
| 575 | * |
| 576 | * \returns A string containing text that should be replace the source |
| 577 | * code indicated by the \c ReplacementRange. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 578 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 579 | CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 580 | unsigned FixIt, |
| 581 | CXSourceRange *ReplacementRange); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 582 | |
| 583 | /** |
| 584 | * @} |
| 585 | */ |
| 586 | |
| 587 | /** |
| 588 | * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation |
| 589 | * |
| 590 | * The routines in this group provide the ability to create and destroy |
| 591 | * translation units from files, either by parsing the contents of the files or |
| 592 | * by reading in a serialized representation of a translation unit. |
| 593 | * |
| 594 | * @{ |
| 595 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 596 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 597 | /** |
| 598 | * \brief Get the original translation unit source file name. |
| 599 | */ |
| 600 | CINDEX_LINKAGE CXString |
| 601 | clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); |
| 602 | |
| 603 | /** |
| 604 | * \brief Return the CXTranslationUnit for a given source file and the provided |
| 605 | * command line arguments one would pass to the compiler. |
| 606 | * |
| 607 | * Note: The 'source_filename' argument is optional. If the caller provides a |
| 608 | * NULL pointer, the name of the source file is expected to reside in the |
| 609 | * specified command line arguments. |
| 610 | * |
| 611 | * Note: When encountered in 'clang_command_line_args', the following options |
| 612 | * are ignored: |
| 613 | * |
| 614 | * '-c' |
| 615 | * '-emit-ast' |
| 616 | * '-fsyntax-only' |
| 617 | * '-o <output file>' (both '-o' and '<output file>' are ignored) |
| 618 | * |
| 619 | * |
| 620 | * \param source_filename - The name of the source file to load, or NULL if the |
| 621 | * source file is included in clang_command_line_args. |
| 622 | * |
| 623 | * \param num_unsaved_files the number of unsaved file entries in \p |
| 624 | * unsaved_files. |
| 625 | * |
| 626 | * \param unsaved_files the files that have not yet been saved to disk |
| 627 | * but may be required for code completion, including the contents of |
Ted Kremenek | c6f530d | 2010-04-12 18:47:26 +0000 | [diff] [blame] | 628 | * those files. The contents and name of these files (as specified by |
| 629 | * CXUnsavedFile) are copied when necessary, so the client only needs to |
| 630 | * guarantee their validity until the call to this function returns. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 631 | * |
| 632 | * \param diag_callback callback function that will receive any diagnostics |
| 633 | * emitted while processing this source file. If NULL, diagnostics will be |
| 634 | * suppressed. |
| 635 | * |
| 636 | * \param diag_client_data client data that will be passed to the diagnostic |
| 637 | * callback function. |
| 638 | */ |
| 639 | CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( |
| 640 | CXIndex CIdx, |
| 641 | const char *source_filename, |
| 642 | int num_clang_command_line_args, |
Douglas Gregor | 2ef6944 | 2010-09-01 16:43:19 +0000 | [diff] [blame] | 643 | const char * const *clang_command_line_args, |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 644 | unsigned num_unsaved_files, |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 645 | struct CXUnsavedFile *unsaved_files); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 646 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 647 | /** |
| 648 | * \brief Create a translation unit from an AST file (-emit-ast). |
| 649 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 650 | CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 651 | const char *ast_filename); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 652 | |
Douglas Gregor | 44c181a | 2010-07-23 00:33:23 +0000 | [diff] [blame] | 653 | /** |
| 654 | * \brief Flags that control the creation of translation units. |
| 655 | * |
| 656 | * The enumerators in this enumeration type are meant to be bitwise |
| 657 | * ORed together to specify which options should be used when |
| 658 | * constructing the translation unit. |
| 659 | */ |
Douglas Gregor | 5a43021 | 2010-07-21 18:52:53 +0000 | [diff] [blame] | 660 | enum CXTranslationUnit_Flags { |
| 661 | /** |
| 662 | * \brief Used to indicate that no special translation-unit options are |
| 663 | * needed. |
| 664 | */ |
| 665 | CXTranslationUnit_None = 0x0, |
| 666 | |
| 667 | /** |
| 668 | * \brief Used to indicate that the parser should construct a "detailed" |
| 669 | * preprocessing record, including all macro definitions and instantiations. |
| 670 | * |
| 671 | * Constructing a detailed preprocessing record requires more memory |
| 672 | * and time to parse, since the information contained in the record |
| 673 | * is usually not retained. However, it can be useful for |
| 674 | * applications that require more detailed information about the |
| 675 | * behavior of the preprocessor. |
| 676 | */ |
Douglas Gregor | 44c181a | 2010-07-23 00:33:23 +0000 | [diff] [blame] | 677 | CXTranslationUnit_DetailedPreprocessingRecord = 0x01, |
| 678 | |
| 679 | /** |
Douglas Gregor | b1c031b | 2010-08-09 22:28:58 +0000 | [diff] [blame] | 680 | * \brief Used to indicate that the translation unit is incomplete. |
Douglas Gregor | 44c181a | 2010-07-23 00:33:23 +0000 | [diff] [blame] | 681 | * |
Douglas Gregor | b1c031b | 2010-08-09 22:28:58 +0000 | [diff] [blame] | 682 | * When a translation unit is considered "incomplete", semantic |
| 683 | * analysis that is typically performed at the end of the |
| 684 | * translation unit will be suppressed. For example, this suppresses |
| 685 | * the completion of tentative declarations in C and of |
| 686 | * instantiation of implicitly-instantiation function templates in |
| 687 | * C++. This option is typically used when parsing a header with the |
| 688 | * intent of producing a precompiled header. |
Douglas Gregor | 44c181a | 2010-07-23 00:33:23 +0000 | [diff] [blame] | 689 | */ |
Douglas Gregor | b1c031b | 2010-08-09 22:28:58 +0000 | [diff] [blame] | 690 | CXTranslationUnit_Incomplete = 0x02, |
Douglas Gregor | 44c181a | 2010-07-23 00:33:23 +0000 | [diff] [blame] | 691 | |
| 692 | /** |
| 693 | * \brief Used to indicate that the translation unit should be built with an |
| 694 | * implicit precompiled header for the preamble. |
| 695 | * |
| 696 | * An implicit precompiled header is used as an optimization when a |
| 697 | * particular translation unit is likely to be reparsed many times |
| 698 | * when the sources aren't changing that often. In this case, an |
| 699 | * implicit precompiled header will be built containing all of the |
| 700 | * initial includes at the top of the main file (what we refer to as |
| 701 | * the "preamble" of the file). In subsequent parses, if the |
| 702 | * preamble or the files in it have not changed, \c |
| 703 | * clang_reparseTranslationUnit() will re-use the implicit |
| 704 | * precompiled header to improve parsing performance. |
| 705 | */ |
Douglas Gregor | e1e13bf | 2010-08-11 15:58:42 +0000 | [diff] [blame] | 706 | CXTranslationUnit_PrecompiledPreamble = 0x04, |
| 707 | |
| 708 | /** |
| 709 | * \brief Used to indicate that the translation unit should cache some |
| 710 | * code-completion results with each reparse of the source file. |
| 711 | * |
| 712 | * Caching of code-completion results is a performance optimization that |
| 713 | * introduces some overhead to reparsing but improves the performance of |
| 714 | * code-completion operations. |
| 715 | */ |
Douglas Gregor | 99ba202 | 2010-10-27 17:24:53 +0000 | [diff] [blame] | 716 | CXTranslationUnit_CacheCompletionResults = 0x08, |
| 717 | /** |
| 718 | * \brief Enable precompiled preambles in C++. |
| 719 | * |
| 720 | * Note: this is a *temporary* option that is available only while |
| 721 | * we are testing C++ precompiled preamble support. |
| 722 | */ |
| 723 | CXTranslationUnit_CXXPrecompiledPreamble = 0x10, |
| 724 | |
| 725 | /** |
| 726 | * \brief Enabled chained precompiled preambles in C++. |
| 727 | * |
| 728 | * Note: this is a *temporary* option that is available only while |
| 729 | * we are testing C++ precompiled preamble support. |
| 730 | */ |
| 731 | CXTranslationUnit_CXXChainedPCH = 0x20 |
Douglas Gregor | 5a43021 | 2010-07-21 18:52:53 +0000 | [diff] [blame] | 732 | }; |
| 733 | |
| 734 | /** |
Douglas Gregor | b1c031b | 2010-08-09 22:28:58 +0000 | [diff] [blame] | 735 | * \brief Returns the set of flags that is suitable for parsing a translation |
| 736 | * unit that is being edited. |
| 737 | * |
| 738 | * The set of flags returned provide options for \c clang_parseTranslationUnit() |
| 739 | * to indicate that the translation unit is likely to be reparsed many times, |
| 740 | * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly |
| 741 | * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag |
| 742 | * set contains an unspecified set of optimizations (e.g., the precompiled |
| 743 | * preamble) geared toward improving the performance of these routines. The |
| 744 | * set of optimizations enabled may change from one version to the next. |
| 745 | */ |
Douglas Gregor | e1e13bf | 2010-08-11 15:58:42 +0000 | [diff] [blame] | 746 | CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void); |
Douglas Gregor | b1c031b | 2010-08-09 22:28:58 +0000 | [diff] [blame] | 747 | |
| 748 | /** |
Douglas Gregor | 5a43021 | 2010-07-21 18:52:53 +0000 | [diff] [blame] | 749 | * \brief Parse the given source file and the translation unit corresponding |
| 750 | * to that file. |
| 751 | * |
| 752 | * This routine is the main entry point for the Clang C API, providing the |
| 753 | * ability to parse a source file into a translation unit that can then be |
| 754 | * queried by other functions in the API. This routine accepts a set of |
| 755 | * command-line arguments so that the compilation can be configured in the same |
| 756 | * way that the compiler is configured on the command line. |
| 757 | * |
| 758 | * \param CIdx The index object with which the translation unit will be |
| 759 | * associated. |
| 760 | * |
| 761 | * \param source_filename The name of the source file to load, or NULL if the |
| 762 | * source file is included in \p clang_command_line_args. |
| 763 | * |
| 764 | * \param command_line_args The command-line arguments that would be |
| 765 | * passed to the \c clang executable if it were being invoked out-of-process. |
| 766 | * These command-line options will be parsed and will affect how the translation |
| 767 | * unit is parsed. Note that the following options are ignored: '-c', |
| 768 | * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. |
| 769 | * |
| 770 | * \param num_command_line_args The number of command-line arguments in |
| 771 | * \p command_line_args. |
| 772 | * |
| 773 | * \param unsaved_files the files that have not yet been saved to disk |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 774 | * but may be required for parsing, including the contents of |
Douglas Gregor | 5a43021 | 2010-07-21 18:52:53 +0000 | [diff] [blame] | 775 | * those files. The contents and name of these files (as specified by |
| 776 | * CXUnsavedFile) are copied when necessary, so the client only needs to |
| 777 | * guarantee their validity until the call to this function returns. |
| 778 | * |
| 779 | * \param num_unsaved_files the number of unsaved file entries in \p |
| 780 | * unsaved_files. |
| 781 | * |
| 782 | * \param options A bitmask of options that affects how the translation unit |
| 783 | * is managed but not its compilation. This should be a bitwise OR of the |
| 784 | * CXTranslationUnit_XXX flags. |
| 785 | * |
| 786 | * \returns A new translation unit describing the parsed code and containing |
| 787 | * any diagnostics produced by the compiler. If there is a failure from which |
| 788 | * the compiler cannot recover, returns NULL. |
| 789 | */ |
| 790 | CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx, |
| 791 | const char *source_filename, |
Douglas Gregor | 2ef6944 | 2010-09-01 16:43:19 +0000 | [diff] [blame] | 792 | const char * const *command_line_args, |
Douglas Gregor | 5a43021 | 2010-07-21 18:52:53 +0000 | [diff] [blame] | 793 | int num_command_line_args, |
| 794 | struct CXUnsavedFile *unsaved_files, |
| 795 | unsigned num_unsaved_files, |
| 796 | unsigned options); |
| 797 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 798 | /** |
Douglas Gregor | 1999844 | 2010-08-13 15:35:05 +0000 | [diff] [blame] | 799 | * \brief Flags that control how translation units are saved. |
| 800 | * |
| 801 | * The enumerators in this enumeration type are meant to be bitwise |
| 802 | * ORed together to specify which options should be used when |
| 803 | * saving the translation unit. |
| 804 | */ |
| 805 | enum CXSaveTranslationUnit_Flags { |
| 806 | /** |
| 807 | * \brief Used to indicate that no special saving options are needed. |
| 808 | */ |
| 809 | CXSaveTranslationUnit_None = 0x0 |
| 810 | }; |
| 811 | |
| 812 | /** |
| 813 | * \brief Returns the set of flags that is suitable for saving a translation |
| 814 | * unit. |
| 815 | * |
| 816 | * The set of flags returned provide options for |
| 817 | * \c clang_saveTranslationUnit() by default. The returned flag |
| 818 | * set contains an unspecified set of options that save translation units with |
| 819 | * the most commonly-requested data. |
| 820 | */ |
| 821 | CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU); |
| 822 | |
| 823 | /** |
Douglas Gregor | 7ae2faa | 2010-08-13 05:36:37 +0000 | [diff] [blame] | 824 | * \brief Saves a translation unit into a serialized representation of |
| 825 | * that translation unit on disk. |
| 826 | * |
| 827 | * Any translation unit that was parsed without error can be saved |
| 828 | * into a file. The translation unit can then be deserialized into a |
| 829 | * new \c CXTranslationUnit with \c clang_createTranslationUnit() or, |
| 830 | * if it is an incomplete translation unit that corresponds to a |
| 831 | * header, used as a precompiled header when parsing other translation |
| 832 | * units. |
| 833 | * |
| 834 | * \param TU The translation unit to save. |
Douglas Gregor | 1999844 | 2010-08-13 15:35:05 +0000 | [diff] [blame] | 835 | * |
Douglas Gregor | 7ae2faa | 2010-08-13 05:36:37 +0000 | [diff] [blame] | 836 | * \param FileName The file to which the translation unit will be saved. |
| 837 | * |
Douglas Gregor | 1999844 | 2010-08-13 15:35:05 +0000 | [diff] [blame] | 838 | * \param options A bitmask of options that affects how the translation unit |
| 839 | * is saved. This should be a bitwise OR of the |
| 840 | * CXSaveTranslationUnit_XXX flags. |
| 841 | * |
Douglas Gregor | 7ae2faa | 2010-08-13 05:36:37 +0000 | [diff] [blame] | 842 | * \returns Zero if the translation unit was saved successfully, a |
| 843 | * non-zero value otherwise. |
| 844 | */ |
| 845 | CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU, |
Douglas Gregor | 1999844 | 2010-08-13 15:35:05 +0000 | [diff] [blame] | 846 | const char *FileName, |
| 847 | unsigned options); |
Douglas Gregor | 7ae2faa | 2010-08-13 05:36:37 +0000 | [diff] [blame] | 848 | |
| 849 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 850 | * \brief Destroy the specified CXTranslationUnit object. |
| 851 | */ |
| 852 | CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 854 | /** |
Douglas Gregor | e1e13bf | 2010-08-11 15:58:42 +0000 | [diff] [blame] | 855 | * \brief Flags that control the reparsing of translation units. |
| 856 | * |
| 857 | * The enumerators in this enumeration type are meant to be bitwise |
| 858 | * ORed together to specify which options should be used when |
| 859 | * reparsing the translation unit. |
| 860 | */ |
| 861 | enum CXReparse_Flags { |
| 862 | /** |
| 863 | * \brief Used to indicate that no special reparsing options are needed. |
| 864 | */ |
| 865 | CXReparse_None = 0x0 |
| 866 | }; |
| 867 | |
| 868 | /** |
| 869 | * \brief Returns the set of flags that is suitable for reparsing a translation |
| 870 | * unit. |
| 871 | * |
| 872 | * The set of flags returned provide options for |
| 873 | * \c clang_reparseTranslationUnit() by default. The returned flag |
| 874 | * set contains an unspecified set of optimizations geared toward common uses |
| 875 | * of reparsing. The set of optimizations enabled may change from one version |
| 876 | * to the next. |
| 877 | */ |
| 878 | CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU); |
| 879 | |
| 880 | /** |
Douglas Gregor | abc563f | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 881 | * \brief Reparse the source files that produced this translation unit. |
| 882 | * |
| 883 | * This routine can be used to re-parse the source files that originally |
| 884 | * created the given translation unit, for example because those source files |
| 885 | * have changed (either on disk or as passed via \p unsaved_files). The |
| 886 | * source code will be reparsed with the same command-line options as it |
| 887 | * was originally parsed. |
| 888 | * |
| 889 | * Reparsing a translation unit invalidates all cursors and source locations |
| 890 | * that refer into that translation unit. This makes reparsing a translation |
| 891 | * unit semantically equivalent to destroying the translation unit and then |
| 892 | * creating a new translation unit with the same command-line arguments. |
| 893 | * However, it may be more efficient to reparse a translation |
| 894 | * unit using this routine. |
| 895 | * |
| 896 | * \param TU The translation unit whose contents will be re-parsed. The |
| 897 | * translation unit must originally have been built with |
| 898 | * \c clang_createTranslationUnitFromSourceFile(). |
| 899 | * |
| 900 | * \param num_unsaved_files The number of unsaved file entries in \p |
| 901 | * unsaved_files. |
| 902 | * |
| 903 | * \param unsaved_files The files that have not yet been saved to disk |
| 904 | * but may be required for parsing, including the contents of |
| 905 | * those files. The contents and name of these files (as specified by |
| 906 | * CXUnsavedFile) are copied when necessary, so the client only needs to |
| 907 | * guarantee their validity until the call to this function returns. |
| 908 | * |
Douglas Gregor | e1e13bf | 2010-08-11 15:58:42 +0000 | [diff] [blame] | 909 | * \param options A bitset of options composed of the flags in CXReparse_Flags. |
| 910 | * The function \c clang_defaultReparseOptions() produces a default set of |
| 911 | * options recommended for most uses, based on the translation unit. |
| 912 | * |
Douglas Gregor | abc563f | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 913 | * \returns 0 if the sources could be reparsed. A non-zero value will be |
| 914 | * returned if reparsing was impossible, such that the translation unit is |
| 915 | * invalid. In such cases, the only valid call for \p TU is |
| 916 | * \c clang_disposeTranslationUnit(TU). |
| 917 | */ |
| 918 | CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, |
| 919 | unsigned num_unsaved_files, |
Douglas Gregor | e1e13bf | 2010-08-11 15:58:42 +0000 | [diff] [blame] | 920 | struct CXUnsavedFile *unsaved_files, |
| 921 | unsigned options); |
Douglas Gregor | abc563f | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 922 | |
| 923 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 924 | * @} |
| 925 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 926 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 927 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 928 | * \brief Describes the kind of entity that a cursor refers to. |
| 929 | */ |
| 930 | enum CXCursorKind { |
| 931 | /* Declarations */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 932 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 933 | * \brief A declaration whose specific kind is not exposed via this |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 934 | * interface. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 935 | * |
| 936 | * Unexposed declarations have the same operations as any other kind |
| 937 | * of declaration; one can extract their location information, |
| 938 | * spelling, find their definitions, etc. However, the specific kind |
| 939 | * of the declaration is not reported. |
| 940 | */ |
| 941 | CXCursor_UnexposedDecl = 1, |
| 942 | /** \brief A C or C++ struct. */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 943 | CXCursor_StructDecl = 2, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 944 | /** \brief A C or C++ union. */ |
| 945 | CXCursor_UnionDecl = 3, |
| 946 | /** \brief A C++ class. */ |
| 947 | CXCursor_ClassDecl = 4, |
| 948 | /** \brief An enumeration. */ |
| 949 | CXCursor_EnumDecl = 5, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 950 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 951 | * \brief A field (in C) or non-static data member (in C++) in a |
| 952 | * struct, union, or C++ class. |
| 953 | */ |
| 954 | CXCursor_FieldDecl = 6, |
| 955 | /** \brief An enumerator constant. */ |
| 956 | CXCursor_EnumConstantDecl = 7, |
| 957 | /** \brief A function. */ |
| 958 | CXCursor_FunctionDecl = 8, |
| 959 | /** \brief A variable. */ |
| 960 | CXCursor_VarDecl = 9, |
| 961 | /** \brief A function or method parameter. */ |
| 962 | CXCursor_ParmDecl = 10, |
| 963 | /** \brief An Objective-C @interface. */ |
| 964 | CXCursor_ObjCInterfaceDecl = 11, |
| 965 | /** \brief An Objective-C @interface for a category. */ |
| 966 | CXCursor_ObjCCategoryDecl = 12, |
| 967 | /** \brief An Objective-C @protocol declaration. */ |
| 968 | CXCursor_ObjCProtocolDecl = 13, |
| 969 | /** \brief An Objective-C @property declaration. */ |
| 970 | CXCursor_ObjCPropertyDecl = 14, |
| 971 | /** \brief An Objective-C instance variable. */ |
| 972 | CXCursor_ObjCIvarDecl = 15, |
| 973 | /** \brief An Objective-C instance method. */ |
| 974 | CXCursor_ObjCInstanceMethodDecl = 16, |
| 975 | /** \brief An Objective-C class method. */ |
| 976 | CXCursor_ObjCClassMethodDecl = 17, |
| 977 | /** \brief An Objective-C @implementation. */ |
| 978 | CXCursor_ObjCImplementationDecl = 18, |
| 979 | /** \brief An Objective-C @implementation for a category. */ |
| 980 | CXCursor_ObjCCategoryImplDecl = 19, |
| 981 | /** \brief A typedef */ |
| 982 | CXCursor_TypedefDecl = 20, |
Ted Kremenek | 8bd5a69 | 2010-04-13 23:39:06 +0000 | [diff] [blame] | 983 | /** \brief A C++ class method. */ |
| 984 | CXCursor_CXXMethod = 21, |
Ted Kremenek | 8f06e0e | 2010-05-06 23:38:21 +0000 | [diff] [blame] | 985 | /** \brief A C++ namespace. */ |
| 986 | CXCursor_Namespace = 22, |
Ted Kremenek | a0536d8 | 2010-05-07 01:04:29 +0000 | [diff] [blame] | 987 | /** \brief A linkage specification, e.g. 'extern "C"'. */ |
| 988 | CXCursor_LinkageSpec = 23, |
Douglas Gregor | 01829d3 | 2010-08-31 14:41:23 +0000 | [diff] [blame] | 989 | /** \brief A C++ constructor. */ |
| 990 | CXCursor_Constructor = 24, |
| 991 | /** \brief A C++ destructor. */ |
| 992 | CXCursor_Destructor = 25, |
| 993 | /** \brief A C++ conversion function. */ |
| 994 | CXCursor_ConversionFunction = 26, |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 995 | /** \brief A C++ template type parameter. */ |
| 996 | CXCursor_TemplateTypeParameter = 27, |
| 997 | /** \brief A C++ non-type template parameter. */ |
| 998 | CXCursor_NonTypeTemplateParameter = 28, |
| 999 | /** \brief A C++ template template parameter. */ |
| 1000 | CXCursor_TemplateTemplateParameter = 29, |
| 1001 | /** \brief A C++ function template. */ |
| 1002 | CXCursor_FunctionTemplate = 30, |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 1003 | /** \brief A C++ class template. */ |
| 1004 | CXCursor_ClassTemplate = 31, |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 1005 | /** \brief A C++ class template partial specialization. */ |
| 1006 | CXCursor_ClassTemplatePartialSpecialization = 32, |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 1007 | /** \brief A C++ namespace alias declaration. */ |
| 1008 | CXCursor_NamespaceAlias = 33, |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 1009 | /** \brief A C++ using directive. */ |
| 1010 | CXCursor_UsingDirective = 34, |
Douglas Gregor | 7e24256 | 2010-09-01 19:52:22 +0000 | [diff] [blame] | 1011 | /** \brief A using declaration. */ |
| 1012 | CXCursor_UsingDeclaration = 35, |
Ted Kremenek | 50aa6ac | 2010-05-19 21:51:10 +0000 | [diff] [blame] | 1013 | CXCursor_FirstDecl = CXCursor_UnexposedDecl, |
Douglas Gregor | 7e24256 | 2010-09-01 19:52:22 +0000 | [diff] [blame] | 1014 | CXCursor_LastDecl = CXCursor_UsingDeclaration, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1016 | /* References */ |
| 1017 | CXCursor_FirstRef = 40, /* Decl references */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1018 | CXCursor_ObjCSuperClassRef = 40, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1019 | CXCursor_ObjCProtocolRef = 41, |
| 1020 | CXCursor_ObjCClassRef = 42, |
| 1021 | /** |
| 1022 | * \brief A reference to a type declaration. |
| 1023 | * |
| 1024 | * A type reference occurs anywhere where a type is named but not |
| 1025 | * declared. For example, given: |
| 1026 | * |
| 1027 | * \code |
| 1028 | * typedef unsigned size_type; |
| 1029 | * size_type size; |
| 1030 | * \endcode |
| 1031 | * |
| 1032 | * The typedef is a declaration of size_type (CXCursor_TypedefDecl), |
| 1033 | * while the type of the variable "size" is referenced. The cursor |
| 1034 | * referenced by the type of size is the typedef for size_type. |
| 1035 | */ |
| 1036 | CXCursor_TypeRef = 43, |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 1037 | CXCursor_CXXBaseSpecifier = 44, |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 1038 | /** |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 1039 | * \brief A reference to a class template, function template, template |
| 1040 | * template parameter, or class template partial specialization. |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 1041 | */ |
| 1042 | CXCursor_TemplateRef = 45, |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 1043 | /** |
| 1044 | * \brief A reference to a namespace or namespace alias. |
| 1045 | */ |
| 1046 | CXCursor_NamespaceRef = 46, |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 1047 | /** |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 1048 | * \brief A reference to a member of a struct, union, or class that occurs in |
| 1049 | * some non-expression context, e.g., a designated initializer. |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 1050 | */ |
| 1051 | CXCursor_MemberRef = 47, |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 1052 | /** |
| 1053 | * \brief A reference to a labeled statement. |
| 1054 | * |
| 1055 | * This cursor kind is used to describe the jump to "start_over" in the |
| 1056 | * goto statement in the following example: |
| 1057 | * |
| 1058 | * \code |
| 1059 | * start_over: |
| 1060 | * ++counter; |
| 1061 | * |
| 1062 | * goto start_over; |
| 1063 | * \endcode |
| 1064 | * |
| 1065 | * A label reference cursor refers to a label statement. |
| 1066 | */ |
| 1067 | CXCursor_LabelRef = 48, |
| 1068 | |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 1069 | /** |
| 1070 | * \brief A reference to a set of overloaded functions or function templates |
| 1071 | * that has not yet been resolved to a specific function or function template. |
| 1072 | * |
| 1073 | * An overloaded declaration reference cursor occurs in C++ templates where |
| 1074 | * a dependent name refers to a function. For example: |
| 1075 | * |
| 1076 | * \code |
| 1077 | * template<typename T> void swap(T&, T&); |
| 1078 | * |
| 1079 | * struct X { ... }; |
| 1080 | * void swap(X&, X&); |
| 1081 | * |
| 1082 | * template<typename T> |
| 1083 | * void reverse(T* first, T* last) { |
| 1084 | * while (first < last - 1) { |
| 1085 | * swap(*first, *--last); |
| 1086 | * ++first; |
| 1087 | * } |
| 1088 | * } |
| 1089 | * |
| 1090 | * struct Y { }; |
| 1091 | * void swap(Y&, Y&); |
| 1092 | * \endcode |
| 1093 | * |
| 1094 | * Here, the identifier "swap" is associated with an overloaded declaration |
| 1095 | * reference. In the template definition, "swap" refers to either of the two |
| 1096 | * "swap" functions declared above, so both results will be available. At |
| 1097 | * instantiation time, "swap" may also refer to other functions found via |
| 1098 | * argument-dependent lookup (e.g., the "swap" function at the end of the |
| 1099 | * example). |
| 1100 | * |
| 1101 | * The functions \c clang_getNumOverloadedDecls() and |
| 1102 | * \c clang_getOverloadedDecl() can be used to retrieve the definitions |
| 1103 | * referenced by this cursor. |
| 1104 | */ |
| 1105 | CXCursor_OverloadedDeclRef = 49, |
| 1106 | |
| 1107 | CXCursor_LastRef = CXCursor_OverloadedDeclRef, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1109 | /* Error conditions */ |
| 1110 | CXCursor_FirstInvalid = 70, |
| 1111 | CXCursor_InvalidFile = 70, |
| 1112 | CXCursor_NoDeclFound = 71, |
| 1113 | CXCursor_NotImplemented = 72, |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 1114 | CXCursor_InvalidCode = 73, |
| 1115 | CXCursor_LastInvalid = CXCursor_InvalidCode, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1116 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1117 | /* Expressions */ |
| 1118 | CXCursor_FirstExpr = 100, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1119 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1120 | /** |
| 1121 | * \brief An expression whose specific kind is not exposed via this |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1122 | * interface. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1123 | * |
| 1124 | * Unexposed expressions have the same operations as any other kind |
| 1125 | * of expression; one can extract their location information, |
| 1126 | * spelling, children, etc. However, the specific kind of the |
| 1127 | * expression is not reported. |
| 1128 | */ |
| 1129 | CXCursor_UnexposedExpr = 100, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1130 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1131 | /** |
| 1132 | * \brief An expression that refers to some value declaration, such |
| 1133 | * as a function, varible, or enumerator. |
| 1134 | */ |
| 1135 | CXCursor_DeclRefExpr = 101, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1136 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1137 | /** |
| 1138 | * \brief An expression that refers to a member of a struct, union, |
| 1139 | * class, Objective-C class, etc. |
| 1140 | */ |
| 1141 | CXCursor_MemberRefExpr = 102, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1143 | /** \brief An expression that calls a function. */ |
| 1144 | CXCursor_CallExpr = 103, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1145 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1146 | /** \brief An expression that sends a message to an Objective-C |
| 1147 | object or class. */ |
| 1148 | CXCursor_ObjCMessageExpr = 104, |
Ted Kremenek | 1ee6cad | 2010-04-11 21:47:37 +0000 | [diff] [blame] | 1149 | |
| 1150 | /** \brief An expression that represents a block literal. */ |
| 1151 | CXCursor_BlockExpr = 105, |
| 1152 | |
| 1153 | CXCursor_LastExpr = 105, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1154 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1155 | /* Statements */ |
| 1156 | CXCursor_FirstStmt = 200, |
| 1157 | /** |
| 1158 | * \brief A statement whose specific kind is not exposed via this |
| 1159 | * interface. |
| 1160 | * |
| 1161 | * Unexposed statements have the same operations as any other kind of |
| 1162 | * statement; one can extract their location information, spelling, |
| 1163 | * children, etc. However, the specific kind of the statement is not |
| 1164 | * reported. |
| 1165 | */ |
| 1166 | CXCursor_UnexposedStmt = 200, |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 1167 | |
| 1168 | /** \brief A labelled statement in a function. |
| 1169 | * |
| 1170 | * This cursor kind is used to describe the "start_over:" label statement in |
| 1171 | * the following example: |
| 1172 | * |
| 1173 | * \code |
| 1174 | * start_over: |
| 1175 | * ++counter; |
| 1176 | * \endcode |
| 1177 | * |
| 1178 | */ |
| 1179 | CXCursor_LabelStmt = 201, |
| 1180 | |
| 1181 | CXCursor_LastStmt = CXCursor_LabelStmt, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1182 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1183 | /** |
| 1184 | * \brief Cursor that represents the translation unit itself. |
| 1185 | * |
| 1186 | * The translation unit cursor exists primarily to act as the root |
| 1187 | * cursor for traversing the contents of a translation unit. |
| 1188 | */ |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 1189 | CXCursor_TranslationUnit = 300, |
| 1190 | |
| 1191 | /* Attributes */ |
| 1192 | CXCursor_FirstAttr = 400, |
| 1193 | /** |
| 1194 | * \brief An attribute whose specific kind is not exposed via this |
| 1195 | * interface. |
| 1196 | */ |
| 1197 | CXCursor_UnexposedAttr = 400, |
| 1198 | |
| 1199 | CXCursor_IBActionAttr = 401, |
| 1200 | CXCursor_IBOutletAttr = 402, |
Ted Kremenek | 857e918 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 1201 | CXCursor_IBOutletCollectionAttr = 403, |
| 1202 | CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr, |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 1203 | |
| 1204 | /* Preprocessing */ |
| 1205 | CXCursor_PreprocessingDirective = 500, |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 1206 | CXCursor_MacroDefinition = 501, |
| 1207 | CXCursor_MacroInstantiation = 502, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1208 | CXCursor_InclusionDirective = 503, |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 1209 | CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1210 | CXCursor_LastPreprocessing = CXCursor_InclusionDirective |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1211 | }; |
| 1212 | |
| 1213 | /** |
| 1214 | * \brief A cursor representing some element in the abstract syntax tree for |
| 1215 | * a translation unit. |
| 1216 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1217 | * The cursor abstraction unifies the different kinds of entities in a |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1218 | * program--declaration, statements, expressions, references to declarations, |
| 1219 | * etc.--under a single "cursor" abstraction with a common set of operations. |
| 1220 | * Common operation for a cursor include: getting the physical location in |
| 1221 | * a source file where the cursor points, getting the name associated with a |
| 1222 | * cursor, and retrieving cursors for any child nodes of a particular cursor. |
| 1223 | * |
| 1224 | * Cursors can be produced in two specific ways. |
| 1225 | * clang_getTranslationUnitCursor() produces a cursor for a translation unit, |
| 1226 | * from which one can use clang_visitChildren() to explore the rest of the |
| 1227 | * translation unit. clang_getCursor() maps from a physical source location |
| 1228 | * to the entity that resides at that location, allowing one to map from the |
| 1229 | * source code into the AST. |
| 1230 | */ |
| 1231 | typedef struct { |
| 1232 | enum CXCursorKind kind; |
| 1233 | void *data[3]; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1234 | } CXCursor; |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1235 | |
| 1236 | /** |
| 1237 | * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations |
| 1238 | * |
| 1239 | * @{ |
| 1240 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1241 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1242 | /** |
| 1243 | * \brief Retrieve the NULL cursor, which represents no entity. |
| 1244 | */ |
| 1245 | CINDEX_LINKAGE CXCursor clang_getNullCursor(void); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1246 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1247 | /** |
| 1248 | * \brief Retrieve the cursor that represents the given translation unit. |
| 1249 | * |
| 1250 | * The translation unit cursor can be used to start traversing the |
| 1251 | * various declarations within the given translation unit. |
| 1252 | */ |
| 1253 | CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); |
| 1254 | |
| 1255 | /** |
| 1256 | * \brief Determine whether two cursors are equivalent. |
| 1257 | */ |
| 1258 | CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1259 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1260 | /** |
| 1261 | * \brief Retrieve the kind of the given cursor. |
| 1262 | */ |
| 1263 | CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); |
| 1264 | |
| 1265 | /** |
| 1266 | * \brief Determine whether the given cursor kind represents a declaration. |
| 1267 | */ |
| 1268 | CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); |
| 1269 | |
| 1270 | /** |
| 1271 | * \brief Determine whether the given cursor kind represents a simple |
| 1272 | * reference. |
| 1273 | * |
| 1274 | * Note that other kinds of cursors (such as expressions) can also refer to |
| 1275 | * other cursors. Use clang_getCursorReferenced() to determine whether a |
| 1276 | * particular cursor refers to another entity. |
| 1277 | */ |
| 1278 | CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); |
| 1279 | |
| 1280 | /** |
| 1281 | * \brief Determine whether the given cursor kind represents an expression. |
| 1282 | */ |
| 1283 | CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); |
| 1284 | |
| 1285 | /** |
| 1286 | * \brief Determine whether the given cursor kind represents a statement. |
| 1287 | */ |
| 1288 | CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); |
| 1289 | |
| 1290 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1291 | * \brief Determine whether the given cursor kind represents an invalid |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1292 | * cursor. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1293 | */ |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1294 | CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); |
| 1295 | |
| 1296 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1297 | * \brief Determine whether the given cursor kind represents a translation |
| 1298 | * unit. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1299 | */ |
| 1300 | CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1301 | |
Ted Kremenek | ad6eff6 | 2010-03-08 21:17:29 +0000 | [diff] [blame] | 1302 | /*** |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 1303 | * \brief Determine whether the given cursor represents a preprocessing |
| 1304 | * element, such as a preprocessor directive or macro instantiation. |
| 1305 | */ |
| 1306 | CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); |
| 1307 | |
| 1308 | /*** |
Ted Kremenek | ad6eff6 | 2010-03-08 21:17:29 +0000 | [diff] [blame] | 1309 | * \brief Determine whether the given cursor represents a currently |
| 1310 | * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). |
| 1311 | */ |
| 1312 | CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); |
| 1313 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1314 | /** |
Ted Kremenek | 16b4259 | 2010-03-03 06:36:57 +0000 | [diff] [blame] | 1315 | * \brief Describe the linkage of the entity referred to by a cursor. |
| 1316 | */ |
| 1317 | enum CXLinkageKind { |
| 1318 | /** \brief This value indicates that no linkage information is available |
| 1319 | * for a provided CXCursor. */ |
| 1320 | CXLinkage_Invalid, |
| 1321 | /** |
| 1322 | * \brief This is the linkage for variables, parameters, and so on that |
| 1323 | * have automatic storage. This covers normal (non-extern) local variables. |
| 1324 | */ |
| 1325 | CXLinkage_NoLinkage, |
| 1326 | /** \brief This is the linkage for static variables and static functions. */ |
| 1327 | CXLinkage_Internal, |
| 1328 | /** \brief This is the linkage for entities with external linkage that live |
| 1329 | * in C++ anonymous namespaces.*/ |
| 1330 | CXLinkage_UniqueExternal, |
| 1331 | /** \brief This is the linkage for entities with true, external linkage. */ |
| 1332 | CXLinkage_External |
| 1333 | }; |
| 1334 | |
| 1335 | /** |
Ted Kremenek | 45e1dae | 2010-04-12 21:22:16 +0000 | [diff] [blame] | 1336 | * \brief Determine the linkage of the entity referred to by a given cursor. |
Ted Kremenek | 16b4259 | 2010-03-03 06:36:57 +0000 | [diff] [blame] | 1337 | */ |
| 1338 | CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); |
| 1339 | |
| 1340 | /** |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 1341 | * \brief Determine the availability of the entity that this cursor refers to. |
| 1342 | * |
| 1343 | * \param cursor The cursor to query. |
| 1344 | * |
| 1345 | * \returns The availability of the cursor. |
| 1346 | */ |
| 1347 | CINDEX_LINKAGE enum CXAvailabilityKind |
| 1348 | clang_getCursorAvailability(CXCursor cursor); |
| 1349 | |
| 1350 | /** |
Ted Kremenek | 45e1dae | 2010-04-12 21:22:16 +0000 | [diff] [blame] | 1351 | * \brief Describe the "language" of the entity referred to by a cursor. |
| 1352 | */ |
| 1353 | CINDEX_LINKAGE enum CXLanguageKind { |
Ted Kremenek | 6cd1e7c | 2010-04-14 20:58:32 +0000 | [diff] [blame] | 1354 | CXLanguage_Invalid = 0, |
Ted Kremenek | 45e1dae | 2010-04-12 21:22:16 +0000 | [diff] [blame] | 1355 | CXLanguage_C, |
| 1356 | CXLanguage_ObjC, |
Ted Kremenek | 6cd1e7c | 2010-04-14 20:58:32 +0000 | [diff] [blame] | 1357 | CXLanguage_CPlusPlus |
Ted Kremenek | 45e1dae | 2010-04-12 21:22:16 +0000 | [diff] [blame] | 1358 | }; |
| 1359 | |
| 1360 | /** |
| 1361 | * \brief Determine the "language" of the entity referred to by a given cursor. |
| 1362 | */ |
| 1363 | CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); |
| 1364 | |
Douglas Gregor | 2be5bc9 | 2010-09-22 21:22:29 +0000 | [diff] [blame] | 1365 | |
| 1366 | /** |
| 1367 | * \brief Determine the semantic parent of the given cursor. |
| 1368 | * |
| 1369 | * The semantic parent of a cursor is the cursor that semantically contains |
| 1370 | * the given \p cursor. For many declarations, the lexical and semantic parents |
| 1371 | * are equivalent (the lexical parent is returned by |
| 1372 | * \c clang_getCursorLexicalParent()). They diverge when declarations or |
| 1373 | * definitions are provided out-of-line. For example: |
| 1374 | * |
| 1375 | * \code |
| 1376 | * class C { |
| 1377 | * void f(); |
| 1378 | * }; |
| 1379 | * |
| 1380 | * void C::f() { } |
| 1381 | * \endcode |
| 1382 | * |
| 1383 | * In the out-of-line definition of \c C::f, the semantic parent is the |
| 1384 | * the class \c C, of which this function is a member. The lexical parent is |
| 1385 | * the place where the declaration actually occurs in the source code; in this |
| 1386 | * case, the definition occurs in the translation unit. In general, the |
| 1387 | * lexical parent for a given entity can change without affecting the semantics |
| 1388 | * of the program, and the lexical parent of different declarations of the |
| 1389 | * same entity may be different. Changing the semantic parent of a declaration, |
| 1390 | * on the other hand, can have a major impact on semantics, and redeclarations |
| 1391 | * of a particular entity should all have the same semantic context. |
| 1392 | * |
| 1393 | * In the example above, both declarations of \c C::f have \c C as their |
| 1394 | * semantic context, while the lexical context of the first \c C::f is \c C |
| 1395 | * and the lexical context of the second \c C::f is the translation unit. |
| 1396 | */ |
| 1397 | CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor); |
| 1398 | |
| 1399 | /** |
| 1400 | * \brief Determine the lexical parent of the given cursor. |
| 1401 | * |
| 1402 | * The lexical parent of a cursor is the cursor in which the given \p cursor |
| 1403 | * was actually written. For many declarations, the lexical and semantic parents |
| 1404 | * are equivalent (the semantic parent is returned by |
| 1405 | * \c clang_getCursorSemanticParent()). They diverge when declarations or |
| 1406 | * definitions are provided out-of-line. For example: |
| 1407 | * |
| 1408 | * \code |
| 1409 | * class C { |
| 1410 | * void f(); |
| 1411 | * }; |
| 1412 | * |
| 1413 | * void C::f() { } |
| 1414 | * \endcode |
| 1415 | * |
| 1416 | * In the out-of-line definition of \c C::f, the semantic parent is the |
| 1417 | * the class \c C, of which this function is a member. The lexical parent is |
| 1418 | * the place where the declaration actually occurs in the source code; in this |
| 1419 | * case, the definition occurs in the translation unit. In general, the |
| 1420 | * lexical parent for a given entity can change without affecting the semantics |
| 1421 | * of the program, and the lexical parent of different declarations of the |
| 1422 | * same entity may be different. Changing the semantic parent of a declaration, |
| 1423 | * on the other hand, can have a major impact on semantics, and redeclarations |
| 1424 | * of a particular entity should all have the same semantic context. |
| 1425 | * |
| 1426 | * In the example above, both declarations of \c C::f have \c C as their |
| 1427 | * semantic context, while the lexical context of the first \c C::f is \c C |
| 1428 | * and the lexical context of the second \c C::f is the translation unit. |
| 1429 | */ |
| 1430 | CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor); |
Douglas Gregor | 9f59234 | 2010-10-01 20:25:15 +0000 | [diff] [blame] | 1431 | |
| 1432 | /** |
| 1433 | * \brief Determine the set of methods that are overridden by the given |
| 1434 | * method. |
| 1435 | * |
| 1436 | * In both Objective-C and C++, a method (aka virtual member function, |
| 1437 | * in C++) can override a virtual method in a base class. For |
| 1438 | * Objective-C, a method is said to override any method in the class's |
| 1439 | * interface (if we're coming from an implementation), its protocols, |
| 1440 | * or its categories, that has the same selector and is of the same |
| 1441 | * kind (class or instance). If no such method exists, the search |
| 1442 | * continues to the class's superclass, its protocols, and its |
| 1443 | * categories, and so on. |
| 1444 | * |
| 1445 | * For C++, a virtual member function overrides any virtual member |
| 1446 | * function with the same signature that occurs in its base |
| 1447 | * classes. With multiple inheritance, a virtual member function can |
| 1448 | * override several virtual member functions coming from different |
| 1449 | * base classes. |
| 1450 | * |
| 1451 | * In all cases, this function determines the immediate overridden |
| 1452 | * method, rather than all of the overridden methods. For example, if |
| 1453 | * a method is originally declared in a class A, then overridden in B |
| 1454 | * (which in inherits from A) and also in C (which inherited from B), |
| 1455 | * then the only overridden method returned from this function when |
| 1456 | * invoked on C's method will be B's method. The client may then |
| 1457 | * invoke this function again, given the previously-found overridden |
| 1458 | * methods, to map out the complete method-override set. |
| 1459 | * |
| 1460 | * \param cursor A cursor representing an Objective-C or C++ |
| 1461 | * method. This routine will compute the set of methods that this |
| 1462 | * method overrides. |
| 1463 | * |
| 1464 | * \param overridden A pointer whose pointee will be replaced with a |
| 1465 | * pointer to an array of cursors, representing the set of overridden |
| 1466 | * methods. If there are no overridden methods, the pointee will be |
| 1467 | * set to NULL. The pointee must be freed via a call to |
| 1468 | * \c clang_disposeOverriddenCursors(). |
| 1469 | * |
| 1470 | * \param num_overridden A pointer to the number of overridden |
| 1471 | * functions, will be set to the number of overridden functions in the |
| 1472 | * array pointed to by \p overridden. |
| 1473 | */ |
| 1474 | CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor, |
| 1475 | CXCursor **overridden, |
| 1476 | unsigned *num_overridden); |
| 1477 | |
| 1478 | /** |
| 1479 | * \brief Free the set of overridden cursors returned by \c |
| 1480 | * clang_getOverriddenCursors(). |
| 1481 | */ |
| 1482 | CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden); |
| 1483 | |
Ted Kremenek | 45e1dae | 2010-04-12 21:22:16 +0000 | [diff] [blame] | 1484 | /** |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1485 | * \brief Retrieve the file that is included by the given inclusion directive |
| 1486 | * cursor. |
| 1487 | */ |
| 1488 | CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor); |
| 1489 | |
| 1490 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1491 | * @} |
| 1492 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1493 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1494 | /** |
| 1495 | * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code |
| 1496 | * |
| 1497 | * Cursors represent a location within the Abstract Syntax Tree (AST). These |
| 1498 | * routines help map between cursors and the physical locations where the |
| 1499 | * described entities occur in the source code. The mapping is provided in |
| 1500 | * both directions, so one can map from source code to the AST and back. |
| 1501 | * |
| 1502 | * @{ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 1503 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1504 | |
Steve Naroff | 6a6de8b | 2009-10-21 13:56:23 +0000 | [diff] [blame] | 1505 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 1506 | * \brief Map a source location to the cursor that describes the entity at that |
| 1507 | * location in the source code. |
| 1508 | * |
| 1509 | * clang_getCursor() maps an arbitrary source location within a translation |
| 1510 | * unit down to the most specific cursor that describes the entity at that |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1511 | * location. For example, given an expression \c x + y, invoking |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 1512 | * clang_getCursor() with a source location pointing to "x" will return the |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1513 | * cursor for "x"; similarly for "y". If the cursor points anywhere between |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 1514 | * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() |
| 1515 | * will return a cursor referring to the "+" expression. |
| 1516 | * |
| 1517 | * \returns a cursor representing the entity at the given source location, or |
| 1518 | * a NULL cursor if no such entity can be found. |
Steve Naroff | 6a6de8b | 2009-10-21 13:56:23 +0000 | [diff] [blame] | 1519 | */ |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 1520 | CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | 98258af | 2010-01-18 22:46:11 +0000 | [diff] [blame] | 1522 | /** |
| 1523 | * \brief Retrieve the physical location of the source constructor referenced |
| 1524 | * by the given cursor. |
| 1525 | * |
| 1526 | * The location of a declaration is typically the location of the name of that |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1527 | * declaration, where the name of that declaration would occur if it is |
| 1528 | * unnamed, or some keyword that introduces that particular declaration. |
| 1529 | * The location of a reference is where that reference occurs within the |
Douglas Gregor | 98258af | 2010-01-18 22:46:11 +0000 | [diff] [blame] | 1530 | * source code. |
| 1531 | */ |
| 1532 | CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1533 | |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1534 | /** |
| 1535 | * \brief Retrieve the physical extent of the source construct referenced by |
Douglas Gregor | a7bde20 | 2010-01-19 00:34:46 +0000 | [diff] [blame] | 1536 | * the given cursor. |
| 1537 | * |
| 1538 | * The extent of a cursor starts with the file/line/column pointing at the |
| 1539 | * first character within the source construct that the cursor refers to and |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1540 | * ends with the last character withinin that source construct. For a |
Douglas Gregor | a7bde20 | 2010-01-19 00:34:46 +0000 | [diff] [blame] | 1541 | * declaration, the extent covers the declaration itself. For a reference, |
| 1542 | * the extent covers the location of the reference (e.g., where the referenced |
| 1543 | * entity was actually used). |
| 1544 | */ |
| 1545 | CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1546 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1547 | /** |
| 1548 | * @} |
| 1549 | */ |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 1550 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1551 | /** |
Ted Kremenek | 8e0ac17 | 2010-05-14 21:29:26 +0000 | [diff] [blame] | 1552 | * \defgroup CINDEX_TYPES Type information for CXCursors |
| 1553 | * |
| 1554 | * @{ |
| 1555 | */ |
| 1556 | |
| 1557 | /** |
| 1558 | * \brief Describes the kind of type |
| 1559 | */ |
| 1560 | enum CXTypeKind { |
| 1561 | /** |
| 1562 | * \brief Reprents an invalid type (e.g., where no type is available). |
| 1563 | */ |
| 1564 | CXType_Invalid = 0, |
| 1565 | |
| 1566 | /** |
| 1567 | * \brief A type whose specific kind is not exposed via this |
| 1568 | * interface. |
| 1569 | */ |
| 1570 | CXType_Unexposed = 1, |
| 1571 | |
| 1572 | /* Builtin types */ |
| 1573 | CXType_Void = 2, |
| 1574 | CXType_Bool = 3, |
| 1575 | CXType_Char_U = 4, |
| 1576 | CXType_UChar = 5, |
| 1577 | CXType_Char16 = 6, |
| 1578 | CXType_Char32 = 7, |
| 1579 | CXType_UShort = 8, |
| 1580 | CXType_UInt = 9, |
| 1581 | CXType_ULong = 10, |
| 1582 | CXType_ULongLong = 11, |
| 1583 | CXType_UInt128 = 12, |
| 1584 | CXType_Char_S = 13, |
| 1585 | CXType_SChar = 14, |
| 1586 | CXType_WChar = 15, |
| 1587 | CXType_Short = 16, |
| 1588 | CXType_Int = 17, |
| 1589 | CXType_Long = 18, |
| 1590 | CXType_LongLong = 19, |
| 1591 | CXType_Int128 = 20, |
| 1592 | CXType_Float = 21, |
| 1593 | CXType_Double = 22, |
| 1594 | CXType_LongDouble = 23, |
| 1595 | CXType_NullPtr = 24, |
| 1596 | CXType_Overload = 25, |
| 1597 | CXType_Dependent = 26, |
| 1598 | CXType_ObjCId = 27, |
| 1599 | CXType_ObjCClass = 28, |
| 1600 | CXType_ObjCSel = 29, |
| 1601 | CXType_FirstBuiltin = CXType_Void, |
| 1602 | CXType_LastBuiltin = CXType_ObjCSel, |
| 1603 | |
| 1604 | CXType_Complex = 100, |
| 1605 | CXType_Pointer = 101, |
| 1606 | CXType_BlockPointer = 102, |
| 1607 | CXType_LValueReference = 103, |
| 1608 | CXType_RValueReference = 104, |
| 1609 | CXType_Record = 105, |
| 1610 | CXType_Enum = 106, |
| 1611 | CXType_Typedef = 107, |
| 1612 | CXType_ObjCInterface = 108, |
Ted Kremenek | 04c3cf3 | 2010-06-21 20:15:39 +0000 | [diff] [blame] | 1613 | CXType_ObjCObjectPointer = 109, |
| 1614 | CXType_FunctionNoProto = 110, |
| 1615 | CXType_FunctionProto = 111 |
Ted Kremenek | 8e0ac17 | 2010-05-14 21:29:26 +0000 | [diff] [blame] | 1616 | }; |
| 1617 | |
| 1618 | /** |
| 1619 | * \brief The type of an element in the abstract syntax tree. |
| 1620 | * |
| 1621 | */ |
| 1622 | typedef struct { |
| 1623 | enum CXTypeKind kind; |
| 1624 | void *data[2]; |
| 1625 | } CXType; |
| 1626 | |
| 1627 | /** |
| 1628 | * \brief Retrieve the type of a CXCursor (if any). |
| 1629 | */ |
| 1630 | CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); |
| 1631 | |
| 1632 | /** |
| 1633 | * \determine Determine whether two CXTypes represent the same type. |
| 1634 | * |
| 1635 | * \returns non-zero if the CXTypes represent the same type and |
| 1636 | zero otherwise. |
| 1637 | */ |
| 1638 | CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); |
| 1639 | |
| 1640 | /** |
| 1641 | * \brief Return the canonical type for a CXType. |
| 1642 | * |
| 1643 | * Clang's type system explicitly models typedefs and all the ways |
| 1644 | * a specific type can be represented. The canonical type is the underlying |
| 1645 | * type with all the "sugar" removed. For example, if 'T' is a typedef |
| 1646 | * for 'int', the canonical type for 'T' would be 'int'. |
| 1647 | */ |
| 1648 | CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); |
| 1649 | |
| 1650 | /** |
| 1651 | * \brief For pointer types, returns the type of the pointee. |
| 1652 | * |
| 1653 | */ |
| 1654 | CINDEX_LINKAGE CXType clang_getPointeeType(CXType T); |
| 1655 | |
| 1656 | /** |
| 1657 | * \brief Return the cursor for the declaration of the given type. |
| 1658 | */ |
| 1659 | CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); |
| 1660 | |
| 1661 | |
| 1662 | /** |
| 1663 | * \brief Retrieve the spelling of a given CXTypeKind. |
| 1664 | */ |
| 1665 | CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); |
| 1666 | |
| 1667 | /** |
Ted Kremenek | 9a14084 | 2010-06-21 20:48:56 +0000 | [diff] [blame] | 1668 | * \brief Retrieve the result type associated with a function type. |
Ted Kremenek | 04c3cf3 | 2010-06-21 20:15:39 +0000 | [diff] [blame] | 1669 | */ |
| 1670 | CINDEX_LINKAGE CXType clang_getResultType(CXType T); |
| 1671 | |
| 1672 | /** |
Ted Kremenek | 9a14084 | 2010-06-21 20:48:56 +0000 | [diff] [blame] | 1673 | * \brief Retrieve the result type associated with a given cursor. This only |
| 1674 | * returns a valid type of the cursor refers to a function or method. |
| 1675 | */ |
| 1676 | CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); |
| 1677 | |
| 1678 | /** |
Ted Kremenek | 3ce9e7d | 2010-07-30 00:14:11 +0000 | [diff] [blame] | 1679 | * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 |
| 1680 | * otherwise. |
| 1681 | */ |
| 1682 | CINDEX_LINKAGE unsigned clang_isPODType(CXType T); |
| 1683 | |
| 1684 | /** |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 1685 | * \brief Returns 1 if the base class specified by the cursor with kind |
| 1686 | * CX_CXXBaseSpecifier is virtual. |
| 1687 | */ |
| 1688 | CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor); |
| 1689 | |
| 1690 | /** |
| 1691 | * \brief Represents the C++ access control level to a base class for a |
| 1692 | * cursor with kind CX_CXXBaseSpecifier. |
| 1693 | */ |
| 1694 | enum CX_CXXAccessSpecifier { |
| 1695 | CX_CXXInvalidAccessSpecifier, |
| 1696 | CX_CXXPublic, |
| 1697 | CX_CXXProtected, |
| 1698 | CX_CXXPrivate |
| 1699 | }; |
| 1700 | |
| 1701 | /** |
| 1702 | * \brief Returns the access control level for the C++ base specifier |
| 1703 | * represented by a cursor with kind CX_CXXBaseSpecifier. |
| 1704 | */ |
| 1705 | CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor); |
| 1706 | |
| 1707 | /** |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 1708 | * \brief Determine the number of overloaded declarations referenced by a |
| 1709 | * \c CXCursor_OverloadedDeclRef cursor. |
| 1710 | * |
| 1711 | * \param cursor The cursor whose overloaded declarations are being queried. |
| 1712 | * |
| 1713 | * \returns The number of overloaded declarations referenced by \c cursor. If it |
| 1714 | * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0. |
| 1715 | */ |
| 1716 | CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor); |
| 1717 | |
| 1718 | /** |
| 1719 | * \brief Retrieve a cursor for one of the overloaded declarations referenced |
| 1720 | * by a \c CXCursor_OverloadedDeclRef cursor. |
| 1721 | * |
| 1722 | * \param cursor The cursor whose overloaded declarations are being queried. |
| 1723 | * |
| 1724 | * \param index The zero-based index into the set of overloaded declarations in |
| 1725 | * the cursor. |
| 1726 | * |
| 1727 | * \returns A cursor representing the declaration referenced by the given |
| 1728 | * \c cursor at the specified \c index. If the cursor does not have an |
| 1729 | * associated set of overloaded declarations, or if the index is out of bounds, |
| 1730 | * returns \c clang_getNullCursor(); |
| 1731 | */ |
| 1732 | CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor, |
| 1733 | unsigned index); |
| 1734 | |
| 1735 | /** |
Ted Kremenek | 8e0ac17 | 2010-05-14 21:29:26 +0000 | [diff] [blame] | 1736 | * @} |
| 1737 | */ |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 1738 | |
| 1739 | /** |
Ted Kremenek | ad72f4d | 2010-08-27 21:34:51 +0000 | [diff] [blame] | 1740 | * \defgroup CINDEX_ATTRIBUTES Information for attributes |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 1741 | * |
| 1742 | * @{ |
| 1743 | */ |
| 1744 | |
| 1745 | |
| 1746 | /** |
| 1747 | * \brief For cursors representing an iboutletcollection attribute, |
| 1748 | * this function returns the collection element type. |
| 1749 | * |
| 1750 | */ |
| 1751 | CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor); |
| 1752 | |
| 1753 | /** |
| 1754 | * @} |
| 1755 | */ |
Ted Kremenek | 8e0ac17 | 2010-05-14 21:29:26 +0000 | [diff] [blame] | 1756 | |
| 1757 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1758 | * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors |
| 1759 | * |
| 1760 | * These routines provide the ability to traverse the abstract syntax tree |
| 1761 | * using cursors. |
| 1762 | * |
| 1763 | * @{ |
| 1764 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1765 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1766 | /** |
| 1767 | * \brief Describes how the traversal of the children of a particular |
| 1768 | * cursor should proceed after visiting a particular child cursor. |
| 1769 | * |
| 1770 | * A value of this enumeration type should be returned by each |
| 1771 | * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. |
| 1772 | */ |
| 1773 | enum CXChildVisitResult { |
| 1774 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1775 | * \brief Terminates the cursor traversal. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1776 | */ |
| 1777 | CXChildVisit_Break, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1778 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1779 | * \brief Continues the cursor traversal with the next sibling of |
| 1780 | * the cursor just visited, without visiting its children. |
| 1781 | */ |
| 1782 | CXChildVisit_Continue, |
| 1783 | /** |
| 1784 | * \brief Recursively traverse the children of this cursor, using |
| 1785 | * the same visitor and client data. |
| 1786 | */ |
| 1787 | CXChildVisit_Recurse |
| 1788 | }; |
| 1789 | |
| 1790 | /** |
| 1791 | * \brief Visitor invoked for each cursor found by a traversal. |
| 1792 | * |
| 1793 | * This visitor function will be invoked for each cursor found by |
| 1794 | * clang_visitCursorChildren(). Its first argument is the cursor being |
| 1795 | * visited, its second argument is the parent visitor for that cursor, |
| 1796 | * and its third argument is the client data provided to |
| 1797 | * clang_visitCursorChildren(). |
| 1798 | * |
| 1799 | * The visitor should return one of the \c CXChildVisitResult values |
| 1800 | * to direct clang_visitCursorChildren(). |
| 1801 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1802 | typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, |
| 1803 | CXCursor parent, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1804 | CXClientData client_data); |
| 1805 | |
| 1806 | /** |
| 1807 | * \brief Visit the children of a particular cursor. |
| 1808 | * |
| 1809 | * This function visits all the direct children of the given cursor, |
| 1810 | * invoking the given \p visitor function with the cursors of each |
| 1811 | * visited child. The traversal may be recursive, if the visitor returns |
| 1812 | * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if |
| 1813 | * the visitor returns \c CXChildVisit_Break. |
| 1814 | * |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1815 | * \param parent the cursor whose child may be visited. All kinds of |
Daniel Dunbar | a57259e | 2010-01-24 04:10:31 +0000 | [diff] [blame] | 1816 | * cursors can be visited, including invalid cursors (which, by |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1817 | * definition, have no children). |
| 1818 | * |
| 1819 | * \param visitor the visitor function that will be invoked for each |
| 1820 | * child of \p parent. |
| 1821 | * |
| 1822 | * \param client_data pointer data supplied by the client, which will |
| 1823 | * be passed to the visitor each time it is invoked. |
| 1824 | * |
| 1825 | * \returns a non-zero value if the traversal was terminated |
| 1826 | * prematurely by the visitor returning \c CXChildVisit_Break. |
| 1827 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1828 | CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1829 | CXCursorVisitor visitor, |
| 1830 | CXClientData client_data); |
David Chisnall | 3387c65 | 2010-11-03 14:12:26 +0000 | [diff] [blame^] | 1831 | #ifdef __has_feature |
| 1832 | # if __has_feature(blocks) |
| 1833 | /** |
| 1834 | * \brief Visitor invoked for each cursor found by a traversal. |
| 1835 | * |
| 1836 | * This visitor block will be invoked for each cursor found by |
| 1837 | * clang_visitChildrenWithBlock(). Its first argument is the cursor being |
| 1838 | * visited, its second argument is the parent visitor for that cursor. |
| 1839 | * |
| 1840 | * The visitor should return one of the \c CXChildVisitResult values |
| 1841 | * to direct clang_visitChildrenWithBlock(). |
| 1842 | */ |
| 1843 | typedef enum CXChildVisitResult |
| 1844 | (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent); |
| 1845 | |
| 1846 | /** |
| 1847 | * Visits the children of a cursor using the specified block. Behaves |
| 1848 | * identically to clang_visitChildren() in all other respects. |
| 1849 | */ |
| 1850 | unsigned clang_visitChildrenWithBlock(CXCursor parent, |
| 1851 | CXCursorVisitorBlock block); |
| 1852 | # endif |
| 1853 | #endif |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1855 | /** |
| 1856 | * @} |
| 1857 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1858 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1859 | /** |
| 1860 | * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST |
| 1861 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1862 | * These routines provide the ability to determine references within and |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1863 | * across translation units, by providing the names of the entities referenced |
| 1864 | * by cursors, follow reference cursors to the declarations they reference, |
| 1865 | * and associate declarations with their definitions. |
| 1866 | * |
| 1867 | * @{ |
| 1868 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1869 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1870 | /** |
| 1871 | * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced |
| 1872 | * by the given cursor. |
| 1873 | * |
| 1874 | * A Unified Symbol Resolution (USR) is a string that identifies a particular |
| 1875 | * entity (function, class, variable, etc.) within a program. USRs can be |
| 1876 | * compared across translation units to determine, e.g., when references in |
| 1877 | * one translation refer to an entity defined in another translation unit. |
| 1878 | */ |
| 1879 | CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); |
| 1880 | |
| 1881 | /** |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 1882 | * \brief Construct a USR for a specified Objective-C class. |
| 1883 | */ |
| 1884 | CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); |
| 1885 | |
| 1886 | /** |
| 1887 | * \brief Construct a USR for a specified Objective-C category. |
| 1888 | */ |
| 1889 | CINDEX_LINKAGE CXString |
Ted Kremenek | 66ccaec | 2010-03-15 17:38:58 +0000 | [diff] [blame] | 1890 | clang_constructUSR_ObjCCategory(const char *class_name, |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 1891 | const char *category_name); |
| 1892 | |
| 1893 | /** |
| 1894 | * \brief Construct a USR for a specified Objective-C protocol. |
| 1895 | */ |
| 1896 | CINDEX_LINKAGE CXString |
| 1897 | clang_constructUSR_ObjCProtocol(const char *protocol_name); |
| 1898 | |
| 1899 | |
| 1900 | /** |
| 1901 | * \brief Construct a USR for a specified Objective-C instance variable and |
| 1902 | * the USR for its containing class. |
| 1903 | */ |
| 1904 | CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, |
| 1905 | CXString classUSR); |
| 1906 | |
| 1907 | /** |
| 1908 | * \brief Construct a USR for a specified Objective-C method and |
| 1909 | * the USR for its containing class. |
| 1910 | */ |
| 1911 | CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, |
| 1912 | unsigned isInstanceMethod, |
| 1913 | CXString classUSR); |
| 1914 | |
| 1915 | /** |
| 1916 | * \brief Construct a USR for a specified Objective-C property and the USR |
| 1917 | * for its containing class. |
| 1918 | */ |
| 1919 | CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, |
| 1920 | CXString classUSR); |
| 1921 | |
| 1922 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1923 | * \brief Retrieve a name for the entity referenced by this cursor. |
| 1924 | */ |
| 1925 | CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); |
| 1926 | |
Douglas Gregor | 358559d | 2010-10-02 22:49:11 +0000 | [diff] [blame] | 1927 | /** |
| 1928 | * \brief Retrieve the display name for the entity referenced by this cursor. |
| 1929 | * |
| 1930 | * The display name contains extra information that helps identify the cursor, |
| 1931 | * such as the parameters of a function or template or the arguments of a |
| 1932 | * class template specialization. |
| 1933 | */ |
| 1934 | CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor); |
| 1935 | |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1936 | /** \brief For a cursor that is a reference, retrieve a cursor representing the |
| 1937 | * entity that it references. |
| 1938 | * |
| 1939 | * Reference cursors refer to other entities in the AST. For example, an |
| 1940 | * Objective-C superclass reference cursor refers to an Objective-C class. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1941 | * This function produces the cursor for the Objective-C class from the |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1942 | * cursor for the superclass reference. If the input cursor is a declaration or |
| 1943 | * definition, it returns that declaration or definition unchanged. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1944 | * Otherwise, returns the NULL cursor. |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1945 | */ |
| 1946 | CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1947 | |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1948 | /** |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1949 | * \brief For a cursor that is either a reference to or a declaration |
| 1950 | * of some entity, retrieve a cursor that describes the definition of |
| 1951 | * that entity. |
| 1952 | * |
| 1953 | * Some entities can be declared multiple times within a translation |
| 1954 | * unit, but only one of those declarations can also be a |
| 1955 | * definition. For example, given: |
| 1956 | * |
| 1957 | * \code |
| 1958 | * int f(int, int); |
| 1959 | * int g(int x, int y) { return f(x, y); } |
| 1960 | * int f(int a, int b) { return a + b; } |
| 1961 | * int f(int, int); |
| 1962 | * \endcode |
| 1963 | * |
| 1964 | * there are three declarations of the function "f", but only the |
| 1965 | * second one is a definition. The clang_getCursorDefinition() |
| 1966 | * function will take any cursor pointing to a declaration of "f" |
| 1967 | * (the first or fourth lines of the example) or a cursor referenced |
| 1968 | * that uses "f" (the call to "f' inside "g") and will return a |
| 1969 | * declaration cursor pointing to the definition (the second "f" |
| 1970 | * declaration). |
| 1971 | * |
| 1972 | * If given a cursor for which there is no corresponding definition, |
| 1973 | * e.g., because there is no definition of that entity within this |
| 1974 | * translation unit, returns a NULL cursor. |
| 1975 | */ |
| 1976 | CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); |
| 1977 | |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1978 | /** |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1979 | * \brief Determine whether the declaration pointed to by this cursor |
| 1980 | * is also a definition of that entity. |
| 1981 | */ |
| 1982 | CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); |
| 1983 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1984 | /** |
| 1985 | * @} |
| 1986 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1987 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1988 | /** |
Ted Kremenek | 9ada39a | 2010-05-17 20:06:56 +0000 | [diff] [blame] | 1989 | * \defgroup CINDEX_CPP C++ AST introspection |
| 1990 | * |
| 1991 | * The routines in this group provide access information in the ASTs specific |
| 1992 | * to C++ language features. |
| 1993 | * |
| 1994 | * @{ |
| 1995 | */ |
| 1996 | |
| 1997 | /** |
Douglas Gregor | 49f6f54 | 2010-08-31 22:12:17 +0000 | [diff] [blame] | 1998 | * \brief Determine if a C++ member function or member function template is |
| 1999 | * declared 'static'. |
Ted Kremenek | 9ada39a | 2010-05-17 20:06:56 +0000 | [diff] [blame] | 2000 | */ |
| 2001 | CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); |
| 2002 | |
| 2003 | /** |
Douglas Gregor | 49f6f54 | 2010-08-31 22:12:17 +0000 | [diff] [blame] | 2004 | * \brief Given a cursor that represents a template, determine |
| 2005 | * the cursor kind of the specializations would be generated by instantiating |
| 2006 | * the template. |
| 2007 | * |
| 2008 | * This routine can be used to determine what flavor of function template, |
| 2009 | * class template, or class template partial specialization is stored in the |
| 2010 | * cursor. For example, it can describe whether a class template cursor is |
| 2011 | * declared with "struct", "class" or "union". |
| 2012 | * |
| 2013 | * \param C The cursor to query. This cursor should represent a template |
| 2014 | * declaration. |
| 2015 | * |
| 2016 | * \returns The cursor kind of the specializations that would be generated |
| 2017 | * by instantiating the template \p C. If \p C is not a template, returns |
| 2018 | * \c CXCursor_NoDeclFound. |
| 2019 | */ |
| 2020 | CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C); |
| 2021 | |
| 2022 | /** |
Douglas Gregor | e0329ac | 2010-09-02 00:07:54 +0000 | [diff] [blame] | 2023 | * \brief Given a cursor that may represent a specialization or instantiation |
| 2024 | * of a template, retrieve the cursor that represents the template that it |
| 2025 | * specializes or from which it was instantiated. |
| 2026 | * |
| 2027 | * This routine determines the template involved both for explicit |
| 2028 | * specializations of templates and for implicit instantiations of the template, |
| 2029 | * both of which are referred to as "specializations". For a class template |
| 2030 | * specialization (e.g., \c std::vector<bool>), this routine will return |
| 2031 | * either the primary template (\c std::vector) or, if the specialization was |
| 2032 | * instantiated from a class template partial specialization, the class template |
| 2033 | * partial specialization. For a class template partial specialization and a |
| 2034 | * function template specialization (including instantiations), this |
| 2035 | * this routine will return the specialized template. |
| 2036 | * |
| 2037 | * For members of a class template (e.g., member functions, member classes, or |
| 2038 | * static data members), returns the specialized or instantiated member. |
| 2039 | * Although not strictly "templates" in the C++ language, members of class |
| 2040 | * templates have the same notions of specializations and instantiations that |
| 2041 | * templates do, so this routine treats them similarly. |
| 2042 | * |
| 2043 | * \param C A cursor that may be a specialization of a template or a member |
| 2044 | * of a template. |
| 2045 | * |
| 2046 | * \returns If the given cursor is a specialization or instantiation of a |
| 2047 | * template or a member thereof, the template or member that it specializes or |
| 2048 | * from which it was instantiated. Otherwise, returns a NULL cursor. |
| 2049 | */ |
| 2050 | CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C); |
| 2051 | |
| 2052 | /** |
Ted Kremenek | 9ada39a | 2010-05-17 20:06:56 +0000 | [diff] [blame] | 2053 | * @} |
| 2054 | */ |
| 2055 | |
| 2056 | /** |
Douglas Gregor | 0045e9f | 2010-01-26 18:31:56 +0000 | [diff] [blame] | 2057 | * \defgroup CINDEX_LEX Token extraction and manipulation |
| 2058 | * |
| 2059 | * The routines in this group provide access to the tokens within a |
| 2060 | * translation unit, along with a semantic mapping of those tokens to |
| 2061 | * their corresponding cursors. |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2062 | * |
| 2063 | * @{ |
| 2064 | */ |
| 2065 | |
| 2066 | /** |
| 2067 | * \brief Describes a kind of token. |
| 2068 | */ |
| 2069 | typedef enum CXTokenKind { |
| 2070 | /** |
| 2071 | * \brief A token that contains some kind of punctuation. |
| 2072 | */ |
| 2073 | CXToken_Punctuation, |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2074 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2075 | /** |
Douglas Gregor | 0045e9f | 2010-01-26 18:31:56 +0000 | [diff] [blame] | 2076 | * \brief A language keyword. |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2077 | */ |
| 2078 | CXToken_Keyword, |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2079 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2080 | /** |
| 2081 | * \brief An identifier (that is not a keyword). |
| 2082 | */ |
| 2083 | CXToken_Identifier, |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2084 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2085 | /** |
| 2086 | * \brief A numeric, string, or character literal. |
| 2087 | */ |
| 2088 | CXToken_Literal, |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2090 | /** |
| 2091 | * \brief A comment. |
| 2092 | */ |
| 2093 | CXToken_Comment |
| 2094 | } CXTokenKind; |
| 2095 | |
| 2096 | /** |
| 2097 | * \brief Describes a single preprocessing token. |
| 2098 | */ |
| 2099 | typedef struct { |
| 2100 | unsigned int_data[4]; |
| 2101 | void *ptr_data; |
| 2102 | } CXToken; |
| 2103 | |
| 2104 | /** |
| 2105 | * \brief Determine the kind of the given token. |
| 2106 | */ |
| 2107 | CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2108 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2109 | /** |
| 2110 | * \brief Determine the spelling of the given token. |
| 2111 | * |
| 2112 | * The spelling of a token is the textual representation of that token, e.g., |
| 2113 | * the text of an identifier or keyword. |
| 2114 | */ |
| 2115 | CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2116 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2117 | /** |
| 2118 | * \brief Retrieve the source location of the given token. |
| 2119 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2120 | CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2121 | CXToken); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2122 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2123 | /** |
| 2124 | * \brief Retrieve a source range that covers the given token. |
| 2125 | */ |
| 2126 | CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); |
| 2127 | |
| 2128 | /** |
| 2129 | * \brief Tokenize the source code described by the given range into raw |
| 2130 | * lexical tokens. |
| 2131 | * |
| 2132 | * \param TU the translation unit whose text is being tokenized. |
| 2133 | * |
| 2134 | * \param Range the source range in which text should be tokenized. All of the |
| 2135 | * tokens produced by tokenization will fall within this source range, |
| 2136 | * |
| 2137 | * \param Tokens this pointer will be set to point to the array of tokens |
| 2138 | * that occur within the given source range. The returned pointer must be |
| 2139 | * freed with clang_disposeTokens() before the translation unit is destroyed. |
| 2140 | * |
| 2141 | * \param NumTokens will be set to the number of tokens in the \c *Tokens |
| 2142 | * array. |
| 2143 | * |
| 2144 | */ |
| 2145 | CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, |
| 2146 | CXToken **Tokens, unsigned *NumTokens); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2147 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2148 | /** |
| 2149 | * \brief Annotate the given set of tokens by providing cursors for each token |
| 2150 | * that can be mapped to a specific entity within the abstract syntax tree. |
| 2151 | * |
Douglas Gregor | 0045e9f | 2010-01-26 18:31:56 +0000 | [diff] [blame] | 2152 | * This token-annotation routine is equivalent to invoking |
| 2153 | * clang_getCursor() for the source locations of each of the |
| 2154 | * tokens. The cursors provided are filtered, so that only those |
| 2155 | * cursors that have a direct correspondence to the token are |
| 2156 | * accepted. For example, given a function call \c f(x), |
| 2157 | * clang_getCursor() would provide the following cursors: |
| 2158 | * |
| 2159 | * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. |
| 2160 | * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. |
| 2161 | * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. |
| 2162 | * |
| 2163 | * Only the first and last of these cursors will occur within the |
| 2164 | * annotate, since the tokens "f" and "x' directly refer to a function |
| 2165 | * and a variable, respectively, but the parentheses are just a small |
| 2166 | * part of the full syntax of the function call expression, which is |
| 2167 | * not provided as an annotation. |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2168 | * |
| 2169 | * \param TU the translation unit that owns the given tokens. |
| 2170 | * |
| 2171 | * \param Tokens the set of tokens to annotate. |
| 2172 | * |
| 2173 | * \param NumTokens the number of tokens in \p Tokens. |
| 2174 | * |
| 2175 | * \param Cursors an array of \p NumTokens cursors, whose contents will be |
| 2176 | * replaced with the cursors corresponding to each token. |
| 2177 | */ |
| 2178 | CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, |
| 2179 | CXToken *Tokens, unsigned NumTokens, |
| 2180 | CXCursor *Cursors); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2181 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2182 | /** |
| 2183 | * \brief Free the given set of tokens. |
| 2184 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2185 | CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2186 | CXToken *Tokens, unsigned NumTokens); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2187 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2188 | /** |
| 2189 | * @} |
| 2190 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 2192 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 2193 | * \defgroup CINDEX_DEBUG Debugging facilities |
| 2194 | * |
| 2195 | * These routines are used for testing and debugging, only, and should not |
| 2196 | * be relied upon. |
| 2197 | * |
| 2198 | * @{ |
| 2199 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2200 | |
Steve Naroff | 4ade6d6 | 2009-09-23 17:52:52 +0000 | [diff] [blame] | 2201 | /* for debug/testing */ |
Ted Kremenek | e68fff6 | 2010-02-17 00:41:32 +0000 | [diff] [blame] | 2202 | CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2203 | CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, |
| 2204 | const char **startBuf, |
Steve Naroff | 4ade6d6 | 2009-09-23 17:52:52 +0000 | [diff] [blame] | 2205 | const char **endBuf, |
| 2206 | unsigned *startLine, |
| 2207 | unsigned *startColumn, |
| 2208 | unsigned *endLine, |
| 2209 | unsigned *endColumn); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 2210 | CINDEX_LINKAGE void clang_enableStackTraces(void); |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2211 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 2212 | * @} |
| 2213 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2214 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 2215 | /** |
| 2216 | * \defgroup CINDEX_CODE_COMPLET Code completion |
| 2217 | * |
| 2218 | * Code completion involves taking an (incomplete) source file, along with |
| 2219 | * knowledge of where the user is actively editing that file, and suggesting |
| 2220 | * syntactically- and semantically-valid constructs that the user might want to |
| 2221 | * use at that particular point in the source code. These data structures and |
| 2222 | * routines provide support for code completion. |
| 2223 | * |
| 2224 | * @{ |
| 2225 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2226 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 2227 | /** |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2228 | * \brief A semantic string that describes a code-completion result. |
| 2229 | * |
| 2230 | * A semantic string that describes the formatting of a code-completion |
| 2231 | * result as a single "template" of text that should be inserted into the |
| 2232 | * source buffer when a particular code-completion result is selected. |
| 2233 | * Each semantic string is made up of some number of "chunks", each of which |
| 2234 | * contains some text along with a description of what that text means, e.g., |
| 2235 | * the name of the entity being referenced, whether the text chunk is part of |
| 2236 | * the template, or whether it is a "placeholder" that the user should replace |
| 2237 | * with actual code,of a specific kind. See \c CXCompletionChunkKind for a |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2238 | * description of the different kinds of chunks. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2239 | */ |
| 2240 | typedef void *CXCompletionString; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2241 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2242 | /** |
| 2243 | * \brief A single result of code completion. |
| 2244 | */ |
| 2245 | typedef struct { |
| 2246 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2247 | * \brief The kind of entity that this completion refers to. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2248 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2249 | * The cursor kind will be a macro, keyword, or a declaration (one of the |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2250 | * *Decl cursor kinds), describing the entity that the completion is |
| 2251 | * referring to. |
| 2252 | * |
| 2253 | * \todo In the future, we would like to provide a full cursor, to allow |
| 2254 | * the client to extract additional information from declaration. |
| 2255 | */ |
| 2256 | enum CXCursorKind CursorKind; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2257 | |
| 2258 | /** |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2259 | * \brief The code-completion string that describes how to insert this |
| 2260 | * code-completion result into the editing buffer. |
| 2261 | */ |
| 2262 | CXCompletionString CompletionString; |
| 2263 | } CXCompletionResult; |
| 2264 | |
| 2265 | /** |
| 2266 | * \brief Describes a single piece of text within a code-completion string. |
| 2267 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2268 | * Each "chunk" within a code-completion string (\c CXCompletionString) is |
| 2269 | * either a piece of text with a specific "kind" that describes how that text |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2270 | * should be interpreted by the client or is another completion string. |
| 2271 | */ |
| 2272 | enum CXCompletionChunkKind { |
| 2273 | /** |
| 2274 | * \brief A code-completion string that describes "optional" text that |
| 2275 | * could be a part of the template (but is not required). |
| 2276 | * |
| 2277 | * The Optional chunk is the only kind of chunk that has a code-completion |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2278 | * string for its representation, which is accessible via |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2279 | * \c clang_getCompletionChunkCompletionString(). The code-completion string |
| 2280 | * describes an additional part of the template that is completely optional. |
| 2281 | * For example, optional chunks can be used to describe the placeholders for |
| 2282 | * arguments that match up with defaulted function parameters, e.g. given: |
| 2283 | * |
| 2284 | * \code |
| 2285 | * void f(int x, float y = 3.14, double z = 2.71828); |
| 2286 | * \endcode |
| 2287 | * |
| 2288 | * The code-completion string for this function would contain: |
| 2289 | * - a TypedText chunk for "f". |
| 2290 | * - a LeftParen chunk for "(". |
| 2291 | * - a Placeholder chunk for "int x" |
| 2292 | * - an Optional chunk containing the remaining defaulted arguments, e.g., |
| 2293 | * - a Comma chunk for "," |
Daniel Dunbar | 7157018 | 2010-02-17 08:07:44 +0000 | [diff] [blame] | 2294 | * - a Placeholder chunk for "float y" |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2295 | * - an Optional chunk containing the last defaulted argument: |
| 2296 | * - a Comma chunk for "," |
| 2297 | * - a Placeholder chunk for "double z" |
| 2298 | * - a RightParen chunk for ")" |
| 2299 | * |
Daniel Dunbar | 7157018 | 2010-02-17 08:07:44 +0000 | [diff] [blame] | 2300 | * There are many ways to handle Optional chunks. Two simple approaches are: |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2301 | * - Completely ignore optional chunks, in which case the template for the |
| 2302 | * function "f" would only include the first parameter ("int x"). |
| 2303 | * - Fully expand all optional chunks, in which case the template for the |
| 2304 | * function "f" would have all of the parameters. |
| 2305 | */ |
| 2306 | CXCompletionChunk_Optional, |
| 2307 | /** |
| 2308 | * \brief Text that a user would be expected to type to get this |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2309 | * code-completion result. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2310 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2311 | * There will be exactly one "typed text" chunk in a semantic string, which |
| 2312 | * will typically provide the spelling of a keyword or the name of a |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2313 | * declaration that could be used at the current code point. Clients are |
| 2314 | * expected to filter the code-completion results based on the text in this |
| 2315 | * chunk. |
| 2316 | */ |
| 2317 | CXCompletionChunk_TypedText, |
| 2318 | /** |
| 2319 | * \brief Text that should be inserted as part of a code-completion result. |
| 2320 | * |
| 2321 | * A "text" chunk represents text that is part of the template to be |
| 2322 | * inserted into user code should this particular code-completion result |
| 2323 | * be selected. |
| 2324 | */ |
| 2325 | CXCompletionChunk_Text, |
| 2326 | /** |
| 2327 | * \brief Placeholder text that should be replaced by the user. |
| 2328 | * |
| 2329 | * A "placeholder" chunk marks a place where the user should insert text |
| 2330 | * into the code-completion template. For example, placeholders might mark |
| 2331 | * the function parameters for a function declaration, to indicate that the |
| 2332 | * user should provide arguments for each of those parameters. The actual |
| 2333 | * text in a placeholder is a suggestion for the text to display before |
| 2334 | * the user replaces the placeholder with real code. |
| 2335 | */ |
| 2336 | CXCompletionChunk_Placeholder, |
| 2337 | /** |
| 2338 | * \brief Informative text that should be displayed but never inserted as |
| 2339 | * part of the template. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2340 | * |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2341 | * An "informative" chunk contains annotations that can be displayed to |
| 2342 | * help the user decide whether a particular code-completion result is the |
| 2343 | * right option, but which is not part of the actual template to be inserted |
| 2344 | * by code completion. |
| 2345 | */ |
| 2346 | CXCompletionChunk_Informative, |
| 2347 | /** |
| 2348 | * \brief Text that describes the current parameter when code-completion is |
| 2349 | * referring to function call, message send, or template specialization. |
| 2350 | * |
| 2351 | * A "current parameter" chunk occurs when code-completion is providing |
| 2352 | * information about a parameter corresponding to the argument at the |
| 2353 | * code-completion point. For example, given a function |
| 2354 | * |
| 2355 | * \code |
| 2356 | * int add(int x, int y); |
| 2357 | * \endcode |
| 2358 | * |
| 2359 | * and the source code \c add(, where the code-completion point is after the |
| 2360 | * "(", the code-completion string will contain a "current parameter" chunk |
| 2361 | * for "int x", indicating that the current argument will initialize that |
| 2362 | * parameter. After typing further, to \c add(17, (where the code-completion |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2363 | * point is after the ","), the code-completion string will contain a |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2364 | * "current paremeter" chunk to "int y". |
| 2365 | */ |
| 2366 | CXCompletionChunk_CurrentParameter, |
| 2367 | /** |
| 2368 | * \brief A left parenthesis ('('), used to initiate a function call or |
| 2369 | * signal the beginning of a function parameter list. |
| 2370 | */ |
| 2371 | CXCompletionChunk_LeftParen, |
| 2372 | /** |
| 2373 | * \brief A right parenthesis (')'), used to finish a function call or |
| 2374 | * signal the end of a function parameter list. |
| 2375 | */ |
| 2376 | CXCompletionChunk_RightParen, |
| 2377 | /** |
| 2378 | * \brief A left bracket ('['). |
| 2379 | */ |
| 2380 | CXCompletionChunk_LeftBracket, |
| 2381 | /** |
| 2382 | * \brief A right bracket (']'). |
| 2383 | */ |
| 2384 | CXCompletionChunk_RightBracket, |
| 2385 | /** |
| 2386 | * \brief A left brace ('{'). |
| 2387 | */ |
| 2388 | CXCompletionChunk_LeftBrace, |
| 2389 | /** |
| 2390 | * \brief A right brace ('}'). |
| 2391 | */ |
| 2392 | CXCompletionChunk_RightBrace, |
| 2393 | /** |
| 2394 | * \brief A left angle bracket ('<'). |
| 2395 | */ |
| 2396 | CXCompletionChunk_LeftAngle, |
| 2397 | /** |
| 2398 | * \brief A right angle bracket ('>'). |
| 2399 | */ |
| 2400 | CXCompletionChunk_RightAngle, |
| 2401 | /** |
| 2402 | * \brief A comma separator (','). |
| 2403 | */ |
Douglas Gregor | ff5ce6e | 2009-12-18 18:53:37 +0000 | [diff] [blame] | 2404 | CXCompletionChunk_Comma, |
| 2405 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2406 | * \brief Text that specifies the result type of a given result. |
Douglas Gregor | ff5ce6e | 2009-12-18 18:53:37 +0000 | [diff] [blame] | 2407 | * |
| 2408 | * This special kind of informative chunk is not meant to be inserted into |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2409 | * the text buffer. Rather, it is meant to illustrate the type that an |
Douglas Gregor | ff5ce6e | 2009-12-18 18:53:37 +0000 | [diff] [blame] | 2410 | * expression using the given completion string would have. |
| 2411 | */ |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 2412 | CXCompletionChunk_ResultType, |
| 2413 | /** |
| 2414 | * \brief A colon (':'). |
| 2415 | */ |
| 2416 | CXCompletionChunk_Colon, |
| 2417 | /** |
| 2418 | * \brief A semicolon (';'). |
| 2419 | */ |
| 2420 | CXCompletionChunk_SemiColon, |
| 2421 | /** |
| 2422 | * \brief An '=' sign. |
| 2423 | */ |
| 2424 | CXCompletionChunk_Equal, |
| 2425 | /** |
| 2426 | * Horizontal space (' '). |
| 2427 | */ |
| 2428 | CXCompletionChunk_HorizontalSpace, |
| 2429 | /** |
| 2430 | * Vertical space ('\n'), after which it is generally a good idea to |
| 2431 | * perform indentation. |
| 2432 | */ |
| 2433 | CXCompletionChunk_VerticalSpace |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2434 | }; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2435 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2436 | /** |
| 2437 | * \brief Determine the kind of a particular chunk within a completion string. |
| 2438 | * |
| 2439 | * \param completion_string the completion string to query. |
| 2440 | * |
| 2441 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 2442 | * |
| 2443 | * \returns the kind of the chunk at the index \c chunk_number. |
| 2444 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2445 | CINDEX_LINKAGE enum CXCompletionChunkKind |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2446 | clang_getCompletionChunkKind(CXCompletionString completion_string, |
| 2447 | unsigned chunk_number); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2448 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2449 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2450 | * \brief Retrieve the text associated with a particular chunk within a |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2451 | * completion string. |
| 2452 | * |
| 2453 | * \param completion_string the completion string to query. |
| 2454 | * |
| 2455 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 2456 | * |
| 2457 | * \returns the text associated with the chunk at index \c chunk_number. |
| 2458 | */ |
Ted Kremenek | 2ef6f8f | 2010-02-17 01:42:24 +0000 | [diff] [blame] | 2459 | CINDEX_LINKAGE CXString |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2460 | clang_getCompletionChunkText(CXCompletionString completion_string, |
| 2461 | unsigned chunk_number); |
| 2462 | |
| 2463 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2464 | * \brief Retrieve the completion string associated with a particular chunk |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2465 | * within a completion string. |
| 2466 | * |
| 2467 | * \param completion_string the completion string to query. |
| 2468 | * |
| 2469 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 2470 | * |
| 2471 | * \returns the completion string associated with the chunk at index |
| 2472 | * \c chunk_number, or NULL if that chunk is not represented by a completion |
| 2473 | * string. |
| 2474 | */ |
| 2475 | CINDEX_LINKAGE CXCompletionString |
| 2476 | clang_getCompletionChunkCompletionString(CXCompletionString completion_string, |
| 2477 | unsigned chunk_number); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2478 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 2479 | /** |
| 2480 | * \brief Retrieve the number of chunks in the given code-completion string. |
| 2481 | */ |
| 2482 | CINDEX_LINKAGE unsigned |
| 2483 | clang_getNumCompletionChunks(CXCompletionString completion_string); |
| 2484 | |
| 2485 | /** |
Douglas Gregor | 12e1313 | 2010-05-26 22:00:08 +0000 | [diff] [blame] | 2486 | * \brief Determine the priority of this code completion. |
| 2487 | * |
| 2488 | * The priority of a code completion indicates how likely it is that this |
| 2489 | * particular completion is the completion that the user will select. The |
| 2490 | * priority is selected by various internal heuristics. |
| 2491 | * |
| 2492 | * \param completion_string The completion string to query. |
| 2493 | * |
| 2494 | * \returns The priority of this completion string. Smaller values indicate |
| 2495 | * higher-priority (more likely) completions. |
| 2496 | */ |
| 2497 | CINDEX_LINKAGE unsigned |
| 2498 | clang_getCompletionPriority(CXCompletionString completion_string); |
| 2499 | |
| 2500 | /** |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 2501 | * \brief Determine the availability of the entity that this code-completion |
| 2502 | * string refers to. |
| 2503 | * |
| 2504 | * \param completion_string The completion string to query. |
| 2505 | * |
| 2506 | * \returns The availability of the completion string. |
| 2507 | */ |
| 2508 | CINDEX_LINKAGE enum CXAvailabilityKind |
| 2509 | clang_getCompletionAvailability(CXCompletionString completion_string); |
| 2510 | |
| 2511 | /** |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 2512 | * \brief Contains the results of code-completion. |
| 2513 | * |
| 2514 | * This data structure contains the results of code completion, as |
Douglas Gregor | e0cc52e | 2010-10-11 21:51:20 +0000 | [diff] [blame] | 2515 | * produced by \c clang_codeCompleteAt(). Its contents must be freed by |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 2516 | * \c clang_disposeCodeCompleteResults. |
| 2517 | */ |
| 2518 | typedef struct { |
| 2519 | /** |
| 2520 | * \brief The code-completion results. |
| 2521 | */ |
| 2522 | CXCompletionResult *Results; |
| 2523 | |
| 2524 | /** |
| 2525 | * \brief The number of code-completion results stored in the |
| 2526 | * \c Results array. |
| 2527 | */ |
| 2528 | unsigned NumResults; |
| 2529 | } CXCodeCompleteResults; |
| 2530 | |
| 2531 | /** |
Douglas Gregor | cee235c | 2010-08-05 09:09:23 +0000 | [diff] [blame] | 2532 | * \brief Flags that can be passed to \c clang_codeCompleteAt() to |
| 2533 | * modify its behavior. |
| 2534 | * |
| 2535 | * The enumerators in this enumeration can be bitwise-OR'd together to |
| 2536 | * provide multiple options to \c clang_codeCompleteAt(). |
| 2537 | */ |
| 2538 | enum CXCodeComplete_Flags { |
| 2539 | /** |
| 2540 | * \brief Whether to include macros within the set of code |
| 2541 | * completions returned. |
| 2542 | */ |
| 2543 | CXCodeComplete_IncludeMacros = 0x01, |
| 2544 | |
| 2545 | /** |
| 2546 | * \brief Whether to include code patterns for language constructs |
| 2547 | * within the set of code completions, e.g., for loops. |
| 2548 | */ |
| 2549 | CXCodeComplete_IncludeCodePatterns = 0x02 |
| 2550 | }; |
| 2551 | |
| 2552 | /** |
| 2553 | * \brief Returns a default set of code-completion options that can be |
| 2554 | * passed to\c clang_codeCompleteAt(). |
| 2555 | */ |
| 2556 | CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void); |
| 2557 | |
| 2558 | /** |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 2559 | * \brief Perform code completion at a given location in a translation unit. |
| 2560 | * |
| 2561 | * This function performs code completion at a particular file, line, and |
| 2562 | * column within source code, providing results that suggest potential |
| 2563 | * code snippets based on the context of the completion. The basic model |
| 2564 | * for code completion is that Clang will parse a complete source file, |
| 2565 | * performing syntax checking up to the location where code-completion has |
| 2566 | * been requested. At that point, a special code-completion token is passed |
| 2567 | * to the parser, which recognizes this token and determines, based on the |
| 2568 | * current location in the C/Objective-C/C++ grammar and the state of |
| 2569 | * semantic analysis, what completions to provide. These completions are |
| 2570 | * returned via a new \c CXCodeCompleteResults structure. |
| 2571 | * |
| 2572 | * Code completion itself is meant to be triggered by the client when the |
| 2573 | * user types punctuation characters or whitespace, at which point the |
| 2574 | * code-completion location will coincide with the cursor. For example, if \c p |
| 2575 | * is a pointer, code-completion might be triggered after the "-" and then |
| 2576 | * after the ">" in \c p->. When the code-completion location is afer the ">", |
| 2577 | * the completion results will provide, e.g., the members of the struct that |
| 2578 | * "p" points to. The client is responsible for placing the cursor at the |
| 2579 | * beginning of the token currently being typed, then filtering the results |
| 2580 | * based on the contents of the token. For example, when code-completing for |
| 2581 | * the expression \c p->get, the client should provide the location just after |
| 2582 | * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the |
| 2583 | * client can filter the results based on the current token text ("get"), only |
| 2584 | * showing those results that start with "get". The intent of this interface |
| 2585 | * is to separate the relatively high-latency acquisition of code-completion |
| 2586 | * results from the filtering of results on a per-character basis, which must |
| 2587 | * have a lower latency. |
| 2588 | * |
| 2589 | * \param TU The translation unit in which code-completion should |
| 2590 | * occur. The source files for this translation unit need not be |
| 2591 | * completely up-to-date (and the contents of those source files may |
| 2592 | * be overridden via \p unsaved_files). Cursors referring into the |
| 2593 | * translation unit may be invalidated by this invocation. |
| 2594 | * |
| 2595 | * \param complete_filename The name of the source file where code |
| 2596 | * completion should be performed. This filename may be any file |
| 2597 | * included in the translation unit. |
| 2598 | * |
| 2599 | * \param complete_line The line at which code-completion should occur. |
| 2600 | * |
| 2601 | * \param complete_column The column at which code-completion should occur. |
| 2602 | * Note that the column should point just after the syntactic construct that |
| 2603 | * initiated code completion, and not in the middle of a lexical token. |
| 2604 | * |
| 2605 | * \param unsaved_files the Tiles that have not yet been saved to disk |
| 2606 | * but may be required for parsing or code completion, including the |
| 2607 | * contents of those files. The contents and name of these files (as |
| 2608 | * specified by CXUnsavedFile) are copied when necessary, so the |
| 2609 | * client only needs to guarantee their validity until the call to |
| 2610 | * this function returns. |
| 2611 | * |
| 2612 | * \param num_unsaved_files The number of unsaved file entries in \p |
| 2613 | * unsaved_files. |
| 2614 | * |
Douglas Gregor | cee235c | 2010-08-05 09:09:23 +0000 | [diff] [blame] | 2615 | * \param options Extra options that control the behavior of code |
| 2616 | * completion, expressed as a bitwise OR of the enumerators of the |
| 2617 | * CXCodeComplete_Flags enumeration. The |
| 2618 | * \c clang_defaultCodeCompleteOptions() function returns a default set |
| 2619 | * of code-completion options. |
| 2620 | * |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 2621 | * \returns If successful, a new \c CXCodeCompleteResults structure |
| 2622 | * containing code-completion results, which should eventually be |
| 2623 | * freed with \c clang_disposeCodeCompleteResults(). If code |
| 2624 | * completion fails, returns NULL. |
| 2625 | */ |
| 2626 | CINDEX_LINKAGE |
| 2627 | CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, |
| 2628 | const char *complete_filename, |
| 2629 | unsigned complete_line, |
| 2630 | unsigned complete_column, |
| 2631 | struct CXUnsavedFile *unsaved_files, |
Douglas Gregor | cee235c | 2010-08-05 09:09:23 +0000 | [diff] [blame] | 2632 | unsigned num_unsaved_files, |
| 2633 | unsigned options); |
Douglas Gregor | 1abc6bc | 2010-08-04 16:47:14 +0000 | [diff] [blame] | 2634 | |
| 2635 | /** |
Douglas Gregor | 1e5e668 | 2010-08-26 13:48:20 +0000 | [diff] [blame] | 2636 | * \brief Sort the code-completion results in case-insensitive alphabetical |
| 2637 | * order. |
| 2638 | * |
| 2639 | * \param Results The set of results to sort. |
| 2640 | * \param NumResults The number of results in \p Results. |
| 2641 | */ |
| 2642 | CINDEX_LINKAGE |
| 2643 | void clang_sortCodeCompletionResults(CXCompletionResult *Results, |
| 2644 | unsigned NumResults); |
| 2645 | |
| 2646 | /** |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 2647 | * \brief Free the given set of code-completion results. |
| 2648 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2649 | CINDEX_LINKAGE |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 2650 | void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); |
Douglas Gregor | 58ddb60 | 2010-08-23 23:00:57 +0000 | [diff] [blame] | 2651 | |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 2652 | /** |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 2653 | * \brief Determine the number of diagnostics produced prior to the |
| 2654 | * location where code completion was performed. |
| 2655 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2656 | CINDEX_LINKAGE |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 2657 | unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); |
| 2658 | |
| 2659 | /** |
| 2660 | * \brief Retrieve a diagnostic associated with the given code completion. |
| 2661 | * |
| 2662 | * \param Result the code completion results to query. |
| 2663 | * \param Index the zero-based diagnostic number to retrieve. |
| 2664 | * |
| 2665 | * \returns the requested diagnostic. This diagnostic must be freed |
| 2666 | * via a call to \c clang_disposeDiagnostic(). |
| 2667 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2668 | CINDEX_LINKAGE |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 2669 | CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, |
| 2670 | unsigned Index); |
| 2671 | |
| 2672 | /** |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 2673 | * @} |
| 2674 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2675 | |
| 2676 | |
Ted Kremenek | 04bb716 | 2010-01-22 22:44:15 +0000 | [diff] [blame] | 2677 | /** |
| 2678 | * \defgroup CINDEX_MISC Miscellaneous utility functions |
| 2679 | * |
| 2680 | * @{ |
| 2681 | */ |
Ted Kremenek | 23e1ad0 | 2010-01-23 17:51:23 +0000 | [diff] [blame] | 2682 | |
| 2683 | /** |
| 2684 | * \brief Return a version string, suitable for showing to a user, but not |
| 2685 | * intended to be parsed (the format is not guaranteed to be stable). |
| 2686 | */ |
Ted Kremenek | a2a9d6e | 2010-02-12 22:54:40 +0000 | [diff] [blame] | 2687 | CINDEX_LINKAGE CXString clang_getClangVersion(); |
Ted Kremenek | 04bb716 | 2010-01-22 22:44:15 +0000 | [diff] [blame] | 2688 | |
| 2689 | /** |
Ted Kremenek | 16b55a7 | 2010-01-26 19:31:51 +0000 | [diff] [blame] | 2690 | * \brief Return a version string, suitable for showing to a user, but not |
| 2691 | * intended to be parsed (the format is not guaranteed to be stable). |
| 2692 | */ |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2693 | |
| 2694 | |
Ted Kremenek | 16b55a7 | 2010-01-26 19:31:51 +0000 | [diff] [blame] | 2695 | /** |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 2696 | * \brief Visitor invoked for each file in a translation unit |
Ted Kremenek | 16b55a7 | 2010-01-26 19:31:51 +0000 | [diff] [blame] | 2697 | * (used with clang_getInclusions()). |
| 2698 | * |
| 2699 | * This visitor function will be invoked by clang_getInclusions() for each |
| 2700 | * file included (either at the top-level or by #include directives) within |
| 2701 | * a translation unit. The first argument is the file being included, and |
| 2702 | * the second and third arguments provide the inclusion stack. The |
| 2703 | * array is sorted in order of immediate inclusion. For example, |
| 2704 | * the first element refers to the location that included 'included_file'. |
| 2705 | */ |
| 2706 | typedef void (*CXInclusionVisitor)(CXFile included_file, |
| 2707 | CXSourceLocation* inclusion_stack, |
| 2708 | unsigned include_len, |
| 2709 | CXClientData client_data); |
| 2710 | |
| 2711 | /** |
| 2712 | * \brief Visit the set of preprocessor inclusions in a translation unit. |
| 2713 | * The visitor function is called with the provided data for every included |
| 2714 | * file. This does not include headers included by the PCH file (unless one |
| 2715 | * is inspecting the inclusions in the PCH file itself). |
| 2716 | */ |
| 2717 | CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, |
| 2718 | CXInclusionVisitor visitor, |
| 2719 | CXClientData client_data); |
| 2720 | |
| 2721 | /** |
Ted Kremenek | 04bb716 | 2010-01-22 22:44:15 +0000 | [diff] [blame] | 2722 | * @} |
| 2723 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2724 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 2725 | /** |
| 2726 | * @} |
| 2727 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 2728 | |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 2729 | #ifdef __cplusplus |
| 2730 | } |
| 2731 | #endif |
| 2732 | #endif |
| 2733 | |