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> |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 21 | |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 26 | /* MSVC DLL import/export. */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 27 | #ifdef _MSC_VER |
| 28 | #ifdef _CINDEX_LIB_ |
| 29 | #define CINDEX_LINKAGE __declspec(dllexport) |
| 30 | #else |
| 31 | #define CINDEX_LINKAGE __declspec(dllimport) |
| 32 | #endif |
| 33 | #else |
| 34 | #define CINDEX_LINKAGE |
| 35 | #endif |
| 36 | |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 37 | /** \defgroup CINDEX C Interface to Clang |
| 38 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 39 | * The C Interface to Clang provides a relatively small API that exposes |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 40 | * facilities for parsing source code into an abstract syntax tree (AST), |
| 41 | * loading already-parsed ASTs, traversing the AST, associating |
| 42 | * physical source locations with elements within the AST, and other |
| 43 | * facilities that support Clang-based development tools. |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 44 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 45 | * This C interface to Clang will never provide all of the information |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 46 | * representation stored in Clang's C++ AST, nor should it: the intent is to |
| 47 | * maintain an API that is relatively stable from one release to the next, |
| 48 | * providing only the basic functionality needed to support development tools. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 49 | * |
| 50 | * To avoid namespace pollution, data types are prefixed with "CX" and |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 51 | * functions are prefixed with "clang_". |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 52 | * |
| 53 | * @{ |
| 54 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 55 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 56 | /** |
| 57 | * \brief An "index" that consists of a set of translation units that would |
| 58 | * typically be linked together into an executable or library. |
| 59 | */ |
| 60 | typedef void *CXIndex; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 61 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 62 | /** |
| 63 | * \brief A single translation unit, which resides in an index. |
| 64 | */ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 65 | typedef void *CXTranslationUnit; /* A translation unit instance. */ |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 66 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 67 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 68 | * \brief Opaque pointer representing client data that will be passed through |
| 69 | * to various callbacks and visitors. |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 70 | */ |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 71 | typedef void *CXClientData; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 72 | |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 73 | /** |
| 74 | * \brief Provides the contents of a file that has not yet been saved to disk. |
| 75 | * |
| 76 | * Each CXUnsavedFile instance provides the name of a file on the |
| 77 | * system along with the current contents of that file that have not |
| 78 | * yet been saved to disk. |
| 79 | */ |
| 80 | struct CXUnsavedFile { |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 81 | /** |
| 82 | * \brief The file whose contents have not yet been saved. |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 83 | * |
| 84 | * This file must already exist in the file system. |
| 85 | */ |
| 86 | const char *Filename; |
| 87 | |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 88 | /** |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 89 | * \brief A null-terminated buffer containing the unsaved contents |
| 90 | * of this file. |
| 91 | */ |
| 92 | const char *Contents; |
| 93 | |
| 94 | /** |
| 95 | * \brief The length of the unsaved contents of this buffer, not |
| 96 | * counting the NULL at the end of the buffer. |
| 97 | */ |
| 98 | unsigned long Length; |
| 99 | }; |
| 100 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 101 | /** |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 102 | * \defgroup CINDEX_STRING String manipulation routines |
| 103 | * |
| 104 | * @{ |
| 105 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 107 | /** |
| 108 | * \brief A character string. |
| 109 | * |
| 110 | * The \c CXString type is used to return strings from the interface when |
| 111 | * the ownership of that string might different from one call to the next. |
| 112 | * Use \c clang_getCString() to retrieve the string data and, once finished |
| 113 | * with the string data, call \c clang_disposeString() to free the string. |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 114 | */ |
| 115 | typedef struct { |
| 116 | const char *Spelling; |
| 117 | /* A 1 value indicates the clang_ indexing API needed to allocate the string |
| 118 | (and it must be freed by clang_disposeString()). */ |
| 119 | int MustFreeString; |
| 120 | } CXString; |
| 121 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 122 | /** |
| 123 | * \brief Retrieve the character data associated with the given string. |
| 124 | */ |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 125 | CINDEX_LINKAGE const char *clang_getCString(CXString string); |
| 126 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 127 | /** |
| 128 | * \brief Free the given string, |
| 129 | */ |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 130 | CINDEX_LINKAGE void clang_disposeString(CXString string); |
| 131 | |
Douglas Gregor | 7f17376 | 2010-01-20 22:28:27 +0000 | [diff] [blame] | 132 | /** |
| 133 | * @} |
| 134 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 135 | |
| 136 | /** |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 137 | * \brief clang_createIndex() provides a shared context for creating |
| 138 | * translation units. It provides two options: |
| 139 | * |
| 140 | * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" |
| 141 | * declarations (when loading any new translation units). A "local" declaration |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 142 | * 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] | 143 | * header that was used by the translation unit. If zero, all declarations |
| 144 | * will be enumerated. |
| 145 | * |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 146 | * Here is an example: |
| 147 | * |
Douglas Gregor | 436f3f0 | 2010-02-18 22:27:07 +0000 | [diff] [blame] | 148 | * // excludeDeclsFromPCH = 1 |
| 149 | * Idx = clang_createIndex(1); |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 150 | * |
| 151 | * // IndexTest.pch was produced with the following command: |
| 152 | * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" |
| 153 | * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); |
| 154 | * |
| 155 | * // This will load all the symbols from 'IndexTest.pch' |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 156 | * clang_visitChildren(clang_getTranslationUnitCursor(TU), |
Douglas Gregor | 002a528 | 2010-01-20 21:37:00 +0000 | [diff] [blame] | 157 | * TranslationUnitVisitor, 0); |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 158 | * clang_disposeTranslationUnit(TU); |
| 159 | * |
| 160 | * // This will load all the symbols from 'IndexTest.c', excluding symbols |
| 161 | * // from 'IndexTest.pch'. |
Daniel Dunbar | fd9f234 | 2010-01-25 00:43:14 +0000 | [diff] [blame] | 162 | * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; |
| 163 | * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, |
| 164 | * 0, 0); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 165 | * clang_visitChildren(clang_getTranslationUnitCursor(TU), |
| 166 | * TranslationUnitVisitor, 0); |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 167 | * clang_disposeTranslationUnit(TU); |
| 168 | * |
| 169 | * This process of creating the 'pch', loading it separately, and using it (via |
| 170 | * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks |
| 171 | * (which gives the indexer the same performance benefit as the compiler). |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 172 | */ |
Douglas Gregor | 436f3f0 | 2010-02-18 22:27:07 +0000 | [diff] [blame] | 173 | CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH); |
Douglas Gregor | 0087e1a | 2010-02-08 23:03:06 +0000 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * \brief Destroy the given index. |
| 177 | * |
| 178 | * The index must not be destroyed until all of the translation units created |
| 179 | * within that index have been destroyed. |
| 180 | */ |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 181 | CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 182 | |
| 183 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 184 | * \brief Request that AST's be generated externally for API calls which parse |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 185 | * source code on the fly, e.g. \see createTranslationUnitFromSourceFile. |
| 186 | * |
| 187 | * Note: This is for debugging purposes only, and may be removed at a later |
| 188 | * date. |
| 189 | * |
| 190 | * \param index - The index to update. |
| 191 | * \param value - The new flag value. |
| 192 | */ |
| 193 | CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index, |
| 194 | int value); |
Douglas Gregor | 7eaa8ae | 2010-01-20 00:23:15 +0000 | [diff] [blame] | 195 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 196 | * \defgroup CINDEX_FILES File manipulation routines |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 197 | * |
| 198 | * @{ |
| 199 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 200 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 201 | /** |
| 202 | * \brief A particular source file that is part of a translation unit. |
| 203 | */ |
| 204 | typedef void *CXFile; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 205 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * \brief Retrieve the complete file and path name of the given file. |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 209 | */ |
Ted Kremenek | 7484407 | 2010-02-17 00:41:20 +0000 | [diff] [blame] | 210 | CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 212 | /** |
| 213 | * \brief Retrieve the last modification time of the given file. |
| 214 | */ |
Douglas Gregor | 08b0e8d | 2009-10-31 15:48:08 +0000 | [diff] [blame] | 215 | CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 216 | |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 217 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 218 | * \brief Retrieve a file handle within the given translation unit. |
| 219 | * |
| 220 | * \param tu the translation unit |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 221 | * |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 222 | * \param file_name the name of the file. |
| 223 | * |
| 224 | * \returns the file handle for the named file in the translation unit \p tu, |
| 225 | * or a NULL file handle if the file was not a part of this translation unit. |
| 226 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 227 | CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 228 | const char *file_name); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 229 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 230 | /** |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 231 | * @} |
| 232 | */ |
| 233 | |
| 234 | /** |
| 235 | * \defgroup CINDEX_LOCATIONS Physical source locations |
| 236 | * |
| 237 | * Clang represents physical source locations in its abstract syntax tree in |
| 238 | * great detail, with file, line, and column information for the majority of |
| 239 | * the tokens parsed in the source code. These data types and functions are |
| 240 | * used to represent source location information, either for a particular |
| 241 | * point in the program or for a range of points in the program, and extract |
| 242 | * specific location information from those data types. |
| 243 | * |
| 244 | * @{ |
| 245 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 246 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 247 | /** |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 248 | * \brief Identifies a specific source location within a translation |
| 249 | * unit. |
| 250 | * |
| 251 | * Use clang_getInstantiationLocation() to map a source location to a |
| 252 | * particular file, line, and column. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 253 | */ |
| 254 | typedef struct { |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 255 | void *ptr_data[2]; |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 256 | unsigned int_data; |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 257 | } CXSourceLocation; |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 258 | |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 259 | /** |
Daniel Dunbar | d52864b | 2010-02-14 10:02:57 +0000 | [diff] [blame] | 260 | * \brief Identifies a half-open character range in the source code. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 261 | * |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 262 | * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the |
| 263 | * starting and end locations from a source range, respectively. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 264 | */ |
| 265 | typedef struct { |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 266 | void *ptr_data[2]; |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 267 | unsigned begin_int_data; |
| 268 | unsigned end_int_data; |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 269 | } CXSourceRange; |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 270 | |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 271 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 272 | * \brief Retrieve a NULL (invalid) source location. |
| 273 | */ |
| 274 | CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 275 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 276 | /** |
| 277 | * \determine Determine whether two source locations, which must refer into |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 278 | * 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] | 279 | * code. |
| 280 | * |
| 281 | * \returns non-zero if the source locations refer to the same location, zero |
| 282 | * if they refer to different locations. |
| 283 | */ |
| 284 | CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, |
| 285 | CXSourceLocation loc2); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 287 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 288 | * \brief Retrieves the source location associated with a given file/line/column |
| 289 | * in a particular translation unit. |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 290 | */ |
| 291 | CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, |
| 292 | CXFile file, |
| 293 | unsigned line, |
| 294 | unsigned column); |
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 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 297 | * \brief Retrieve a NULL (invalid) source range. |
| 298 | */ |
| 299 | CINDEX_LINKAGE CXSourceRange clang_getNullRange(); |
| 300 | |
| 301 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 302 | * \brief Retrieve a source range given the beginning and ending source |
| 303 | * locations. |
| 304 | */ |
| 305 | CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, |
| 306 | CXSourceLocation end); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 307 | |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 308 | /** |
Douglas Gregor | 46766dc | 2010-01-26 19:19:08 +0000 | [diff] [blame] | 309 | * \brief Retrieve the file, line, column, and offset represented by |
| 310 | * the given source location. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 311 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 312 | * \param location the location within a source file that will be decomposed |
| 313 | * into its parts. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 314 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 315 | * \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] | 316 | * source location points. |
| 317 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 318 | * \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] | 319 | * source location points. |
| 320 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 321 | * \param column [out] if non-NULL, will be set to the column to which the given |
| 322 | * source location points. |
Douglas Gregor | 46766dc | 2010-01-26 19:19:08 +0000 | [diff] [blame] | 323 | * |
| 324 | * \param offset [out] if non-NULL, will be set to the offset into the |
| 325 | * buffer to which the given source location points. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 326 | */ |
| 327 | CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, |
| 328 | CXFile *file, |
| 329 | unsigned *line, |
Douglas Gregor | 46766dc | 2010-01-26 19:19:08 +0000 | [diff] [blame] | 330 | unsigned *column, |
| 331 | unsigned *offset); |
Douglas Gregor | e69517c | 2010-01-26 03:07:15 +0000 | [diff] [blame] | 332 | |
| 333 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 334 | * \brief Retrieve a source location representing the first character within a |
| 335 | * source range. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 336 | */ |
| 337 | CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); |
| 338 | |
| 339 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 340 | * \brief Retrieve a source location representing the last character within a |
| 341 | * source range. |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 342 | */ |
| 343 | CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); |
| 344 | |
Douglas Gregor | f552544 | 2010-01-20 22:45:41 +0000 | [diff] [blame] | 345 | /** |
| 346 | * @} |
| 347 | */ |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 348 | |
| 349 | /** |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 350 | * \defgroup CINDEX_DIAG Diagnostic reporting |
| 351 | * |
| 352 | * @{ |
| 353 | */ |
| 354 | |
| 355 | /** |
| 356 | * \brief Describes the severity of a particular diagnostic. |
| 357 | */ |
| 358 | enum CXDiagnosticSeverity { |
| 359 | /** |
| 360 | * \brief A diagnostic that has been suppressed, e.g., by a command-line |
| 361 | * option. |
| 362 | */ |
| 363 | CXDiagnostic_Ignored = 0, |
| 364 | |
| 365 | /** |
| 366 | * \brief This diagnostic is a note that should be attached to the |
| 367 | * previous (non-note) diagnostic. |
| 368 | */ |
| 369 | CXDiagnostic_Note = 1, |
| 370 | |
| 371 | /** |
| 372 | * \brief This diagnostic indicates suspicious code that may not be |
| 373 | * wrong. |
| 374 | */ |
| 375 | CXDiagnostic_Warning = 2, |
| 376 | |
| 377 | /** |
| 378 | * \brief This diagnostic indicates that the code is ill-formed. |
| 379 | */ |
| 380 | CXDiagnostic_Error = 3, |
| 381 | |
| 382 | /** |
| 383 | * \brief This diagnostic indicates that the code is ill-formed such |
| 384 | * that future parser recovery is unlikely to produce useful |
| 385 | * results. |
| 386 | */ |
| 387 | CXDiagnostic_Fatal = 4 |
| 388 | }; |
| 389 | |
| 390 | /** |
| 391 | * \brief Describes the kind of fix-it hint expressed within a |
| 392 | * diagnostic. |
| 393 | */ |
| 394 | enum CXFixItKind { |
| 395 | /** |
| 396 | * \brief A fix-it hint that inserts code at a particular position. |
| 397 | */ |
| 398 | CXFixIt_Insertion = 0, |
| 399 | |
| 400 | /** |
| 401 | * \brief A fix-it hint that removes code within a range. |
| 402 | */ |
| 403 | CXFixIt_Removal = 1, |
| 404 | |
| 405 | /** |
| 406 | * \brief A fix-it hint that replaces the code within a range with another |
| 407 | * string. |
| 408 | */ |
| 409 | CXFixIt_Replacement = 2 |
| 410 | }; |
| 411 | |
| 412 | /** |
| 413 | * \brief A single diagnostic, containing the diagnostic's severity, |
| 414 | * location, text, source ranges, and fix-it hints. |
| 415 | */ |
| 416 | typedef void *CXDiagnostic; |
| 417 | |
| 418 | /** |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 419 | * \brief Determine the number of diagnostics produced for the given |
| 420 | * translation unit. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 421 | */ |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 422 | CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); |
| 423 | |
| 424 | /** |
| 425 | * \brief Retrieve a diagnostic associated with the given translation unit. |
| 426 | * |
| 427 | * \param Unit the translation unit to query. |
| 428 | * \param Index the zero-based diagnostic number to retrieve. |
| 429 | * |
| 430 | * \returns the requested diagnostic. This diagnostic must be freed |
| 431 | * via a call to \c clang_disposeDiagnostic(). |
| 432 | */ |
| 433 | CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, |
| 434 | unsigned Index); |
| 435 | |
| 436 | /** |
| 437 | * \brief Destroy a diagnostic. |
| 438 | */ |
| 439 | CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 440 | |
| 441 | /** |
| 442 | * \brief Determine the severity of the given diagnostic. |
| 443 | */ |
| 444 | CINDEX_LINKAGE enum CXDiagnosticSeverity |
| 445 | clang_getDiagnosticSeverity(CXDiagnostic); |
| 446 | |
| 447 | /** |
| 448 | * \brief Retrieve the source location of the given diagnostic. |
| 449 | * |
| 450 | * This location is where Clang would print the caret ('^') when |
| 451 | * displaying the diagnostic on the command line. |
| 452 | */ |
| 453 | CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); |
| 454 | |
| 455 | /** |
| 456 | * \brief Retrieve the text of the given diagnostic. |
| 457 | */ |
| 458 | CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 459 | |
| 460 | /** |
| 461 | * \brief Determine the number of source ranges associated with the given |
| 462 | * diagnostic. |
| 463 | */ |
| 464 | CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 465 | |
| 466 | /** |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 467 | * \brief Retrieve a source range associated with the diagnostic. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 468 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 469 | * A diagnostic's source ranges highlight important elements in the source |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 470 | * code. On the command line, Clang displays source ranges by |
| 471 | * underlining them with '~' characters. |
| 472 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 473 | * \param Diagnostic the diagnostic whose range is being extracted. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 474 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 475 | * \param Range the zero-based index specifying which range to |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 476 | * |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 477 | * \returns the requested source range. |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 478 | */ |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 479 | CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, |
| 480 | unsigned Range); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 481 | |
| 482 | /** |
| 483 | * \brief Determine the number of fix-it hints associated with the |
| 484 | * given diagnostic. |
| 485 | */ |
| 486 | CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); |
| 487 | |
| 488 | /** |
| 489 | * \brief Retrieve the kind of the given fix-it. |
| 490 | * |
| 491 | * \param Diagnostic the diagnostic whose fix-its are being queried. |
| 492 | * |
| 493 | * \param FixIt the zero-based index of the fix-it to query. |
| 494 | */ |
| 495 | CINDEX_LINKAGE enum CXFixItKind |
| 496 | clang_getDiagnosticFixItKind(CXDiagnostic Diagnostic, unsigned FixIt); |
| 497 | |
| 498 | /** |
| 499 | * \brief Retrieve the insertion information for an insertion fix-it. |
| 500 | * |
| 501 | * For a fix-it that describes an insertion into a text buffer, |
| 502 | * retrieve the source location where the text should be inserted and |
| 503 | * the text to be inserted. |
| 504 | * |
| 505 | * \param Diagnostic the diagnostic whose fix-its are being queried. |
| 506 | * |
| 507 | * \param FixIt the zero-based index of the insertion fix-it. |
| 508 | * |
| 509 | * \param Location will be set to the location where text should be |
| 510 | * inserted. |
| 511 | * |
| 512 | * \returns the text string to insert at the given location. |
| 513 | */ |
| 514 | CINDEX_LINKAGE CXString |
| 515 | clang_getDiagnosticFixItInsertion(CXDiagnostic Diagnostic, unsigned FixIt, |
| 516 | CXSourceLocation *Location); |
| 517 | |
| 518 | /** |
| 519 | * \brief Retrieve the removal information for a removal fix-it. |
| 520 | * |
| 521 | * For a fix-it that describes a removal from a text buffer, retrieve |
| 522 | * the source range that should be removed. |
| 523 | * |
| 524 | * \param Diagnostic the diagnostic whose fix-its are being queried. |
| 525 | * |
| 526 | * \param FixIt the zero-based index of the removal fix-it. |
| 527 | * |
| 528 | * \returns a source range describing the text that should be removed |
| 529 | * from the buffer. |
| 530 | */ |
| 531 | CINDEX_LINKAGE CXSourceRange |
| 532 | clang_getDiagnosticFixItRemoval(CXDiagnostic Diagnostic, unsigned FixIt); |
| 533 | |
| 534 | /** |
| 535 | * \brief Retrieve the replacement information for an replacement fix-it. |
| 536 | * |
| 537 | * For a fix-it that describes replacement of text in the text buffer |
| 538 | * with alternative text. |
| 539 | * |
| 540 | * \param Diagnostic the diagnostic whose fix-its are being queried. |
| 541 | * |
| 542 | * \param FixIt the zero-based index of the replacement fix-it. |
| 543 | * |
| 544 | * \param Range will be set to the source range whose text should be |
| 545 | * replaced with the returned text. |
| 546 | * |
| 547 | * \returns the text string to use as replacement text. |
| 548 | */ |
| 549 | CINDEX_LINKAGE CXString |
| 550 | clang_getDiagnosticFixItReplacement(CXDiagnostic Diagnostic, unsigned FixIt, |
| 551 | CXSourceRange *Range); |
| 552 | |
| 553 | /** |
| 554 | * @} |
| 555 | */ |
| 556 | |
| 557 | /** |
| 558 | * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation |
| 559 | * |
| 560 | * The routines in this group provide the ability to create and destroy |
| 561 | * translation units from files, either by parsing the contents of the files or |
| 562 | * by reading in a serialized representation of a translation unit. |
| 563 | * |
| 564 | * @{ |
| 565 | */ |
| 566 | |
| 567 | /** |
| 568 | * \brief Get the original translation unit source file name. |
| 569 | */ |
| 570 | CINDEX_LINKAGE CXString |
| 571 | clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); |
| 572 | |
| 573 | /** |
| 574 | * \brief Return the CXTranslationUnit for a given source file and the provided |
| 575 | * command line arguments one would pass to the compiler. |
| 576 | * |
| 577 | * Note: The 'source_filename' argument is optional. If the caller provides a |
| 578 | * NULL pointer, the name of the source file is expected to reside in the |
| 579 | * specified command line arguments. |
| 580 | * |
| 581 | * Note: When encountered in 'clang_command_line_args', the following options |
| 582 | * are ignored: |
| 583 | * |
| 584 | * '-c' |
| 585 | * '-emit-ast' |
| 586 | * '-fsyntax-only' |
| 587 | * '-o <output file>' (both '-o' and '<output file>' are ignored) |
| 588 | * |
| 589 | * |
| 590 | * \param source_filename - The name of the source file to load, or NULL if the |
| 591 | * source file is included in clang_command_line_args. |
| 592 | * |
| 593 | * \param num_unsaved_files the number of unsaved file entries in \p |
| 594 | * unsaved_files. |
| 595 | * |
| 596 | * \param unsaved_files the files that have not yet been saved to disk |
| 597 | * but may be required for code completion, including the contents of |
| 598 | * those files. |
| 599 | * |
| 600 | * \param diag_callback callback function that will receive any diagnostics |
| 601 | * emitted while processing this source file. If NULL, diagnostics will be |
| 602 | * suppressed. |
| 603 | * |
| 604 | * \param diag_client_data client data that will be passed to the diagnostic |
| 605 | * callback function. |
| 606 | */ |
| 607 | CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( |
| 608 | CXIndex CIdx, |
| 609 | const char *source_filename, |
| 610 | int num_clang_command_line_args, |
| 611 | const char **clang_command_line_args, |
| 612 | unsigned num_unsaved_files, |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 613 | struct CXUnsavedFile *unsaved_files); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * \brief Create a translation unit from an AST file (-emit-ast). |
| 617 | */ |
| 618 | CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 619 | const char *ast_filename); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 620 | |
| 621 | /** |
| 622 | * \brief Destroy the specified CXTranslationUnit object. |
| 623 | */ |
| 624 | CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); |
| 625 | |
| 626 | /** |
| 627 | * @} |
| 628 | */ |
| 629 | |
| 630 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 631 | * \brief Describes the kind of entity that a cursor refers to. |
| 632 | */ |
| 633 | enum CXCursorKind { |
| 634 | /* Declarations */ |
| 635 | CXCursor_FirstDecl = 1, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 636 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 637 | * \brief A declaration whose specific kind is not exposed via this |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 638 | * interface. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 639 | * |
| 640 | * Unexposed declarations have the same operations as any other kind |
| 641 | * of declaration; one can extract their location information, |
| 642 | * spelling, find their definitions, etc. However, the specific kind |
| 643 | * of the declaration is not reported. |
| 644 | */ |
| 645 | CXCursor_UnexposedDecl = 1, |
| 646 | /** \brief A C or C++ struct. */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 647 | CXCursor_StructDecl = 2, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 648 | /** \brief A C or C++ union. */ |
| 649 | CXCursor_UnionDecl = 3, |
| 650 | /** \brief A C++ class. */ |
| 651 | CXCursor_ClassDecl = 4, |
| 652 | /** \brief An enumeration. */ |
| 653 | CXCursor_EnumDecl = 5, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 654 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 655 | * \brief A field (in C) or non-static data member (in C++) in a |
| 656 | * struct, union, or C++ class. |
| 657 | */ |
| 658 | CXCursor_FieldDecl = 6, |
| 659 | /** \brief An enumerator constant. */ |
| 660 | CXCursor_EnumConstantDecl = 7, |
| 661 | /** \brief A function. */ |
| 662 | CXCursor_FunctionDecl = 8, |
| 663 | /** \brief A variable. */ |
| 664 | CXCursor_VarDecl = 9, |
| 665 | /** \brief A function or method parameter. */ |
| 666 | CXCursor_ParmDecl = 10, |
| 667 | /** \brief An Objective-C @interface. */ |
| 668 | CXCursor_ObjCInterfaceDecl = 11, |
| 669 | /** \brief An Objective-C @interface for a category. */ |
| 670 | CXCursor_ObjCCategoryDecl = 12, |
| 671 | /** \brief An Objective-C @protocol declaration. */ |
| 672 | CXCursor_ObjCProtocolDecl = 13, |
| 673 | /** \brief An Objective-C @property declaration. */ |
| 674 | CXCursor_ObjCPropertyDecl = 14, |
| 675 | /** \brief An Objective-C instance variable. */ |
| 676 | CXCursor_ObjCIvarDecl = 15, |
| 677 | /** \brief An Objective-C instance method. */ |
| 678 | CXCursor_ObjCInstanceMethodDecl = 16, |
| 679 | /** \brief An Objective-C class method. */ |
| 680 | CXCursor_ObjCClassMethodDecl = 17, |
| 681 | /** \brief An Objective-C @implementation. */ |
| 682 | CXCursor_ObjCImplementationDecl = 18, |
| 683 | /** \brief An Objective-C @implementation for a category. */ |
| 684 | CXCursor_ObjCCategoryImplDecl = 19, |
| 685 | /** \brief A typedef */ |
| 686 | CXCursor_TypedefDecl = 20, |
| 687 | CXCursor_LastDecl = 20, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 688 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 689 | /* References */ |
| 690 | CXCursor_FirstRef = 40, /* Decl references */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 691 | CXCursor_ObjCSuperClassRef = 40, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 692 | CXCursor_ObjCProtocolRef = 41, |
| 693 | CXCursor_ObjCClassRef = 42, |
| 694 | /** |
| 695 | * \brief A reference to a type declaration. |
| 696 | * |
| 697 | * A type reference occurs anywhere where a type is named but not |
| 698 | * declared. For example, given: |
| 699 | * |
| 700 | * \code |
| 701 | * typedef unsigned size_type; |
| 702 | * size_type size; |
| 703 | * \endcode |
| 704 | * |
| 705 | * The typedef is a declaration of size_type (CXCursor_TypedefDecl), |
| 706 | * while the type of the variable "size" is referenced. The cursor |
| 707 | * referenced by the type of size is the typedef for size_type. |
| 708 | */ |
| 709 | CXCursor_TypeRef = 43, |
| 710 | CXCursor_LastRef = 43, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 711 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 712 | /* Error conditions */ |
| 713 | CXCursor_FirstInvalid = 70, |
| 714 | CXCursor_InvalidFile = 70, |
| 715 | CXCursor_NoDeclFound = 71, |
| 716 | CXCursor_NotImplemented = 72, |
| 717 | CXCursor_LastInvalid = 72, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 718 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 719 | /* Expressions */ |
| 720 | CXCursor_FirstExpr = 100, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 722 | /** |
| 723 | * \brief An expression whose specific kind is not exposed via this |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 724 | * interface. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 725 | * |
| 726 | * Unexposed expressions have the same operations as any other kind |
| 727 | * of expression; one can extract their location information, |
| 728 | * spelling, children, etc. However, the specific kind of the |
| 729 | * expression is not reported. |
| 730 | */ |
| 731 | CXCursor_UnexposedExpr = 100, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 732 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 733 | /** |
| 734 | * \brief An expression that refers to some value declaration, such |
| 735 | * as a function, varible, or enumerator. |
| 736 | */ |
| 737 | CXCursor_DeclRefExpr = 101, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 738 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 739 | /** |
| 740 | * \brief An expression that refers to a member of a struct, union, |
| 741 | * class, Objective-C class, etc. |
| 742 | */ |
| 743 | CXCursor_MemberRefExpr = 102, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 744 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 745 | /** \brief An expression that calls a function. */ |
| 746 | CXCursor_CallExpr = 103, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 748 | /** \brief An expression that sends a message to an Objective-C |
| 749 | object or class. */ |
| 750 | CXCursor_ObjCMessageExpr = 104, |
| 751 | CXCursor_LastExpr = 104, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 753 | /* Statements */ |
| 754 | CXCursor_FirstStmt = 200, |
| 755 | /** |
| 756 | * \brief A statement whose specific kind is not exposed via this |
| 757 | * interface. |
| 758 | * |
| 759 | * Unexposed statements have the same operations as any other kind of |
| 760 | * statement; one can extract their location information, spelling, |
| 761 | * children, etc. However, the specific kind of the statement is not |
| 762 | * reported. |
| 763 | */ |
| 764 | CXCursor_UnexposedStmt = 200, |
| 765 | CXCursor_LastStmt = 200, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 766 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 767 | /** |
| 768 | * \brief Cursor that represents the translation unit itself. |
| 769 | * |
| 770 | * The translation unit cursor exists primarily to act as the root |
| 771 | * cursor for traversing the contents of a translation unit. |
| 772 | */ |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 773 | CXCursor_TranslationUnit = 300, |
| 774 | |
| 775 | /* Attributes */ |
| 776 | CXCursor_FirstAttr = 400, |
| 777 | /** |
| 778 | * \brief An attribute whose specific kind is not exposed via this |
| 779 | * interface. |
| 780 | */ |
| 781 | CXCursor_UnexposedAttr = 400, |
| 782 | |
| 783 | CXCursor_IBActionAttr = 401, |
| 784 | CXCursor_IBOutletAttr = 402, |
| 785 | CXCursor_LastAttr = CXCursor_IBOutletAttr |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 786 | }; |
| 787 | |
| 788 | /** |
| 789 | * \brief A cursor representing some element in the abstract syntax tree for |
| 790 | * a translation unit. |
| 791 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 792 | * The cursor abstraction unifies the different kinds of entities in a |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 793 | * program--declaration, statements, expressions, references to declarations, |
| 794 | * etc.--under a single "cursor" abstraction with a common set of operations. |
| 795 | * Common operation for a cursor include: getting the physical location in |
| 796 | * a source file where the cursor points, getting the name associated with a |
| 797 | * cursor, and retrieving cursors for any child nodes of a particular cursor. |
| 798 | * |
| 799 | * Cursors can be produced in two specific ways. |
| 800 | * clang_getTranslationUnitCursor() produces a cursor for a translation unit, |
| 801 | * from which one can use clang_visitChildren() to explore the rest of the |
| 802 | * translation unit. clang_getCursor() maps from a physical source location |
| 803 | * to the entity that resides at that location, allowing one to map from the |
| 804 | * source code into the AST. |
| 805 | */ |
| 806 | typedef struct { |
| 807 | enum CXCursorKind kind; |
| 808 | void *data[3]; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 809 | } CXCursor; |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 810 | |
| 811 | /** |
| 812 | * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations |
| 813 | * |
| 814 | * @{ |
| 815 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 817 | /** |
| 818 | * \brief Retrieve the NULL cursor, which represents no entity. |
| 819 | */ |
| 820 | CINDEX_LINKAGE CXCursor clang_getNullCursor(void); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 821 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 822 | /** |
| 823 | * \brief Retrieve the cursor that represents the given translation unit. |
| 824 | * |
| 825 | * The translation unit cursor can be used to start traversing the |
| 826 | * various declarations within the given translation unit. |
| 827 | */ |
| 828 | CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); |
| 829 | |
| 830 | /** |
| 831 | * \brief Determine whether two cursors are equivalent. |
| 832 | */ |
| 833 | CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 834 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 835 | /** |
| 836 | * \brief Retrieve the kind of the given cursor. |
| 837 | */ |
| 838 | CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); |
| 839 | |
| 840 | /** |
| 841 | * \brief Determine whether the given cursor kind represents a declaration. |
| 842 | */ |
| 843 | CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); |
| 844 | |
| 845 | /** |
| 846 | * \brief Determine whether the given cursor kind represents a simple |
| 847 | * reference. |
| 848 | * |
| 849 | * Note that other kinds of cursors (such as expressions) can also refer to |
| 850 | * other cursors. Use clang_getCursorReferenced() to determine whether a |
| 851 | * particular cursor refers to another entity. |
| 852 | */ |
| 853 | CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); |
| 854 | |
| 855 | /** |
| 856 | * \brief Determine whether the given cursor kind represents an expression. |
| 857 | */ |
| 858 | CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); |
| 859 | |
| 860 | /** |
| 861 | * \brief Determine whether the given cursor kind represents a statement. |
| 862 | */ |
| 863 | CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); |
| 864 | |
| 865 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 866 | * \brief Determine whether the given cursor kind represents an invalid |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 867 | * cursor. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 868 | */ |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 869 | CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); |
| 870 | |
| 871 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 872 | * \brief Determine whether the given cursor kind represents a translation |
| 873 | * unit. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 874 | */ |
| 875 | CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 876 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 877 | /** |
| 878 | * @} |
| 879 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 880 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 881 | /** |
| 882 | * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code |
| 883 | * |
| 884 | * Cursors represent a location within the Abstract Syntax Tree (AST). These |
| 885 | * routines help map between cursors and the physical locations where the |
| 886 | * described entities occur in the source code. The mapping is provided in |
| 887 | * both directions, so one can map from source code to the AST and back. |
| 888 | * |
| 889 | * @{ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 890 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 891 | |
Steve Naroff | 6a6de8b | 2009-10-21 13:56:23 +0000 | [diff] [blame] | 892 | /** |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 893 | * \brief Map a source location to the cursor that describes the entity at that |
| 894 | * location in the source code. |
| 895 | * |
| 896 | * clang_getCursor() maps an arbitrary source location within a translation |
| 897 | * 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] | 898 | * location. For example, given an expression \c x + y, invoking |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 899 | * clang_getCursor() with a source location pointing to "x" will return the |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 900 | * cursor for "x"; similarly for "y". If the cursor points anywhere between |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 901 | * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() |
| 902 | * will return a cursor referring to the "+" expression. |
| 903 | * |
| 904 | * \returns a cursor representing the entity at the given source location, or |
| 905 | * a NULL cursor if no such entity can be found. |
Steve Naroff | 6a6de8b | 2009-10-21 13:56:23 +0000 | [diff] [blame] | 906 | */ |
Douglas Gregor | b979034 | 2010-01-22 21:44:22 +0000 | [diff] [blame] | 907 | CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 908 | |
Douglas Gregor | 98258af | 2010-01-18 22:46:11 +0000 | [diff] [blame] | 909 | /** |
| 910 | * \brief Retrieve the physical location of the source constructor referenced |
| 911 | * by the given cursor. |
| 912 | * |
| 913 | * 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] | 914 | * declaration, where the name of that declaration would occur if it is |
| 915 | * unnamed, or some keyword that introduces that particular declaration. |
| 916 | * The location of a reference is where that reference occurs within the |
Douglas Gregor | 98258af | 2010-01-18 22:46:11 +0000 | [diff] [blame] | 917 | * source code. |
| 918 | */ |
| 919 | CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 920 | |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 921 | /** |
| 922 | * \brief Retrieve the physical extent of the source construct referenced by |
Douglas Gregor | a7bde20 | 2010-01-19 00:34:46 +0000 | [diff] [blame] | 923 | * the given cursor. |
| 924 | * |
| 925 | * The extent of a cursor starts with the file/line/column pointing at the |
| 926 | * first character within the source construct that the cursor refers to and |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 927 | * ends with the last character withinin that source construct. For a |
Douglas Gregor | a7bde20 | 2010-01-19 00:34:46 +0000 | [diff] [blame] | 928 | * declaration, the extent covers the declaration itself. For a reference, |
| 929 | * the extent covers the location of the reference (e.g., where the referenced |
| 930 | * entity was actually used). |
| 931 | */ |
| 932 | CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 933 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 934 | /** |
| 935 | * @} |
| 936 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 937 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 938 | /** |
| 939 | * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors |
| 940 | * |
| 941 | * These routines provide the ability to traverse the abstract syntax tree |
| 942 | * using cursors. |
| 943 | * |
| 944 | * @{ |
| 945 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 946 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 947 | /** |
| 948 | * \brief Describes how the traversal of the children of a particular |
| 949 | * cursor should proceed after visiting a particular child cursor. |
| 950 | * |
| 951 | * A value of this enumeration type should be returned by each |
| 952 | * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. |
| 953 | */ |
| 954 | enum CXChildVisitResult { |
| 955 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 956 | * \brief Terminates the cursor traversal. |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 957 | */ |
| 958 | CXChildVisit_Break, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 959 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 960 | * \brief Continues the cursor traversal with the next sibling of |
| 961 | * the cursor just visited, without visiting its children. |
| 962 | */ |
| 963 | CXChildVisit_Continue, |
| 964 | /** |
| 965 | * \brief Recursively traverse the children of this cursor, using |
| 966 | * the same visitor and client data. |
| 967 | */ |
| 968 | CXChildVisit_Recurse |
| 969 | }; |
| 970 | |
| 971 | /** |
| 972 | * \brief Visitor invoked for each cursor found by a traversal. |
| 973 | * |
| 974 | * This visitor function will be invoked for each cursor found by |
| 975 | * clang_visitCursorChildren(). Its first argument is the cursor being |
| 976 | * visited, its second argument is the parent visitor for that cursor, |
| 977 | * and its third argument is the client data provided to |
| 978 | * clang_visitCursorChildren(). |
| 979 | * |
| 980 | * The visitor should return one of the \c CXChildVisitResult values |
| 981 | * to direct clang_visitCursorChildren(). |
| 982 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 983 | typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, |
| 984 | CXCursor parent, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 985 | CXClientData client_data); |
| 986 | |
| 987 | /** |
| 988 | * \brief Visit the children of a particular cursor. |
| 989 | * |
| 990 | * This function visits all the direct children of the given cursor, |
| 991 | * invoking the given \p visitor function with the cursors of each |
| 992 | * visited child. The traversal may be recursive, if the visitor returns |
| 993 | * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if |
| 994 | * the visitor returns \c CXChildVisit_Break. |
| 995 | * |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 996 | * \param parent the cursor whose child may be visited. All kinds of |
Daniel Dunbar | a57259e | 2010-01-24 04:10:31 +0000 | [diff] [blame] | 997 | * cursors can be visited, including invalid cursors (which, by |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 998 | * definition, have no children). |
| 999 | * |
| 1000 | * \param visitor the visitor function that will be invoked for each |
| 1001 | * child of \p parent. |
| 1002 | * |
| 1003 | * \param client_data pointer data supplied by the client, which will |
| 1004 | * be passed to the visitor each time it is invoked. |
| 1005 | * |
| 1006 | * \returns a non-zero value if the traversal was terminated |
| 1007 | * prematurely by the visitor returning \c CXChildVisit_Break. |
| 1008 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1009 | CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1010 | CXCursorVisitor visitor, |
| 1011 | CXClientData client_data); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1012 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1013 | /** |
| 1014 | * @} |
| 1015 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1016 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1017 | /** |
| 1018 | * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST |
| 1019 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1020 | * These routines provide the ability to determine references within and |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1021 | * across translation units, by providing the names of the entities referenced |
| 1022 | * by cursors, follow reference cursors to the declarations they reference, |
| 1023 | * and associate declarations with their definitions. |
| 1024 | * |
| 1025 | * @{ |
| 1026 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1027 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1028 | /** |
| 1029 | * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced |
| 1030 | * by the given cursor. |
| 1031 | * |
| 1032 | * A Unified Symbol Resolution (USR) is a string that identifies a particular |
| 1033 | * entity (function, class, variable, etc.) within a program. USRs can be |
| 1034 | * compared across translation units to determine, e.g., when references in |
| 1035 | * one translation refer to an entity defined in another translation unit. |
| 1036 | */ |
| 1037 | CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); |
| 1038 | |
| 1039 | /** |
| 1040 | * \brief Retrieve a name for the entity referenced by this cursor. |
| 1041 | */ |
| 1042 | CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); |
| 1043 | |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1044 | /** \brief For a cursor that is a reference, retrieve a cursor representing the |
| 1045 | * entity that it references. |
| 1046 | * |
| 1047 | * Reference cursors refer to other entities in the AST. For example, an |
| 1048 | * Objective-C superclass reference cursor refers to an Objective-C class. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1049 | * This function produces the cursor for the Objective-C class from the |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1050 | * cursor for the superclass reference. If the input cursor is a declaration or |
| 1051 | * definition, it returns that declaration or definition unchanged. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1052 | * Otherwise, returns the NULL cursor. |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 1053 | */ |
| 1054 | CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1055 | |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1056 | /** |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1057 | * \brief For a cursor that is either a reference to or a declaration |
| 1058 | * of some entity, retrieve a cursor that describes the definition of |
| 1059 | * that entity. |
| 1060 | * |
| 1061 | * Some entities can be declared multiple times within a translation |
| 1062 | * unit, but only one of those declarations can also be a |
| 1063 | * definition. For example, given: |
| 1064 | * |
| 1065 | * \code |
| 1066 | * int f(int, int); |
| 1067 | * int g(int x, int y) { return f(x, y); } |
| 1068 | * int f(int a, int b) { return a + b; } |
| 1069 | * int f(int, int); |
| 1070 | * \endcode |
| 1071 | * |
| 1072 | * there are three declarations of the function "f", but only the |
| 1073 | * second one is a definition. The clang_getCursorDefinition() |
| 1074 | * function will take any cursor pointing to a declaration of "f" |
| 1075 | * (the first or fourth lines of the example) or a cursor referenced |
| 1076 | * that uses "f" (the call to "f' inside "g") and will return a |
| 1077 | * declaration cursor pointing to the definition (the second "f" |
| 1078 | * declaration). |
| 1079 | * |
| 1080 | * If given a cursor for which there is no corresponding definition, |
| 1081 | * e.g., because there is no definition of that entity within this |
| 1082 | * translation unit, returns a NULL cursor. |
| 1083 | */ |
| 1084 | CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); |
| 1085 | |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1086 | /** |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 1087 | * \brief Determine whether the declaration pointed to by this cursor |
| 1088 | * is also a definition of that entity. |
| 1089 | */ |
| 1090 | CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); |
| 1091 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1092 | /** |
| 1093 | * @} |
| 1094 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1095 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1096 | /** |
Douglas Gregor | 0045e9f | 2010-01-26 18:31:56 +0000 | [diff] [blame] | 1097 | * \defgroup CINDEX_LEX Token extraction and manipulation |
| 1098 | * |
| 1099 | * The routines in this group provide access to the tokens within a |
| 1100 | * translation unit, along with a semantic mapping of those tokens to |
| 1101 | * their corresponding cursors. |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 1102 | * |
| 1103 | * @{ |
| 1104 | */ |
| 1105 | |
| 1106 | /** |
| 1107 | * \brief Describes a kind of token. |
| 1108 | */ |
| 1109 | typedef enum CXTokenKind { |
| 1110 | /** |
| 1111 | * \brief A token that contains some kind of punctuation. |
| 1112 | */ |
| 1113 | CXToken_Punctuation, |
| 1114 | |
| 1115 | /** |
Douglas Gregor | 0045e9f | 2010-01-26 18:31:56 +0000 | [diff] [blame] | 1116 | * \brief A language keyword. |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 1117 | */ |
| 1118 | CXToken_Keyword, |
| 1119 | |
| 1120 | /** |
| 1121 | * \brief An identifier (that is not a keyword). |
| 1122 | */ |
| 1123 | CXToken_Identifier, |
| 1124 | |
| 1125 | /** |
| 1126 | * \brief A numeric, string, or character literal. |
| 1127 | */ |
| 1128 | CXToken_Literal, |
| 1129 | |
| 1130 | /** |
| 1131 | * \brief A comment. |
| 1132 | */ |
| 1133 | CXToken_Comment |
| 1134 | } CXTokenKind; |
| 1135 | |
| 1136 | /** |
| 1137 | * \brief Describes a single preprocessing token. |
| 1138 | */ |
| 1139 | typedef struct { |
| 1140 | unsigned int_data[4]; |
| 1141 | void *ptr_data; |
| 1142 | } CXToken; |
| 1143 | |
| 1144 | /** |
| 1145 | * \brief Determine the kind of the given token. |
| 1146 | */ |
| 1147 | CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); |
| 1148 | |
| 1149 | /** |
| 1150 | * \brief Determine the spelling of the given token. |
| 1151 | * |
| 1152 | * The spelling of a token is the textual representation of that token, e.g., |
| 1153 | * the text of an identifier or keyword. |
| 1154 | */ |
| 1155 | CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); |
| 1156 | |
| 1157 | /** |
| 1158 | * \brief Retrieve the source location of the given token. |
| 1159 | */ |
| 1160 | CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, |
| 1161 | CXToken); |
| 1162 | |
| 1163 | /** |
| 1164 | * \brief Retrieve a source range that covers the given token. |
| 1165 | */ |
| 1166 | CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); |
| 1167 | |
| 1168 | /** |
| 1169 | * \brief Tokenize the source code described by the given range into raw |
| 1170 | * lexical tokens. |
| 1171 | * |
| 1172 | * \param TU the translation unit whose text is being tokenized. |
| 1173 | * |
| 1174 | * \param Range the source range in which text should be tokenized. All of the |
| 1175 | * tokens produced by tokenization will fall within this source range, |
| 1176 | * |
| 1177 | * \param Tokens this pointer will be set to point to the array of tokens |
| 1178 | * that occur within the given source range. The returned pointer must be |
| 1179 | * freed with clang_disposeTokens() before the translation unit is destroyed. |
| 1180 | * |
| 1181 | * \param NumTokens will be set to the number of tokens in the \c *Tokens |
| 1182 | * array. |
| 1183 | * |
| 1184 | */ |
| 1185 | CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, |
| 1186 | CXToken **Tokens, unsigned *NumTokens); |
| 1187 | |
| 1188 | /** |
| 1189 | * \brief Annotate the given set of tokens by providing cursors for each token |
| 1190 | * that can be mapped to a specific entity within the abstract syntax tree. |
| 1191 | * |
Douglas Gregor | 0045e9f | 2010-01-26 18:31:56 +0000 | [diff] [blame] | 1192 | * This token-annotation routine is equivalent to invoking |
| 1193 | * clang_getCursor() for the source locations of each of the |
| 1194 | * tokens. The cursors provided are filtered, so that only those |
| 1195 | * cursors that have a direct correspondence to the token are |
| 1196 | * accepted. For example, given a function call \c f(x), |
| 1197 | * clang_getCursor() would provide the following cursors: |
| 1198 | * |
| 1199 | * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. |
| 1200 | * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. |
| 1201 | * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. |
| 1202 | * |
| 1203 | * Only the first and last of these cursors will occur within the |
| 1204 | * annotate, since the tokens "f" and "x' directly refer to a function |
| 1205 | * and a variable, respectively, but the parentheses are just a small |
| 1206 | * part of the full syntax of the function call expression, which is |
| 1207 | * not provided as an annotation. |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 1208 | * |
| 1209 | * \param TU the translation unit that owns the given tokens. |
| 1210 | * |
| 1211 | * \param Tokens the set of tokens to annotate. |
| 1212 | * |
| 1213 | * \param NumTokens the number of tokens in \p Tokens. |
| 1214 | * |
| 1215 | * \param Cursors an array of \p NumTokens cursors, whose contents will be |
| 1216 | * replaced with the cursors corresponding to each token. |
| 1217 | */ |
| 1218 | CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, |
| 1219 | CXToken *Tokens, unsigned NumTokens, |
| 1220 | CXCursor *Cursors); |
| 1221 | |
| 1222 | /** |
| 1223 | * \brief Free the given set of tokens. |
| 1224 | */ |
| 1225 | CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, |
| 1226 | CXToken *Tokens, unsigned NumTokens); |
| 1227 | |
| 1228 | /** |
| 1229 | * @} |
| 1230 | */ |
| 1231 | |
| 1232 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1233 | * \defgroup CINDEX_DEBUG Debugging facilities |
| 1234 | * |
| 1235 | * These routines are used for testing and debugging, only, and should not |
| 1236 | * be relied upon. |
| 1237 | * |
| 1238 | * @{ |
| 1239 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1240 | |
Steve Naroff | 4ade6d6 | 2009-09-23 17:52:52 +0000 | [diff] [blame] | 1241 | /* for debug/testing */ |
Ted Kremenek | e68fff6 | 2010-02-17 00:41:32 +0000 | [diff] [blame] | 1242 | CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1243 | CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, |
| 1244 | const char **startBuf, |
Steve Naroff | 4ade6d6 | 2009-09-23 17:52:52 +0000 | [diff] [blame] | 1245 | const char **endBuf, |
| 1246 | unsigned *startLine, |
| 1247 | unsigned *startColumn, |
| 1248 | unsigned *endLine, |
| 1249 | unsigned *endColumn); |
Douglas Gregor | 436f3f0 | 2010-02-18 22:27:07 +0000 | [diff] [blame] | 1250 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1251 | /** |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1252 | * @} |
| 1253 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1255 | /** |
| 1256 | * \defgroup CINDEX_CODE_COMPLET Code completion |
| 1257 | * |
| 1258 | * Code completion involves taking an (incomplete) source file, along with |
| 1259 | * knowledge of where the user is actively editing that file, and suggesting |
| 1260 | * syntactically- and semantically-valid constructs that the user might want to |
| 1261 | * use at that particular point in the source code. These data structures and |
| 1262 | * routines provide support for code completion. |
| 1263 | * |
| 1264 | * @{ |
| 1265 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1266 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1267 | /** |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1268 | * \brief A semantic string that describes a code-completion result. |
| 1269 | * |
| 1270 | * A semantic string that describes the formatting of a code-completion |
| 1271 | * result as a single "template" of text that should be inserted into the |
| 1272 | * source buffer when a particular code-completion result is selected. |
| 1273 | * Each semantic string is made up of some number of "chunks", each of which |
| 1274 | * contains some text along with a description of what that text means, e.g., |
| 1275 | * the name of the entity being referenced, whether the text chunk is part of |
| 1276 | * the template, or whether it is a "placeholder" that the user should replace |
| 1277 | * with actual code,of a specific kind. See \c CXCompletionChunkKind for a |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1278 | * description of the different kinds of chunks. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1279 | */ |
| 1280 | typedef void *CXCompletionString; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1281 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1282 | /** |
| 1283 | * \brief A single result of code completion. |
| 1284 | */ |
| 1285 | typedef struct { |
| 1286 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1287 | * \brief The kind of entity that this completion refers to. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1288 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1289 | * 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] | 1290 | * *Decl cursor kinds), describing the entity that the completion is |
| 1291 | * referring to. |
| 1292 | * |
| 1293 | * \todo In the future, we would like to provide a full cursor, to allow |
| 1294 | * the client to extract additional information from declaration. |
| 1295 | */ |
| 1296 | enum CXCursorKind CursorKind; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1297 | |
| 1298 | /** |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1299 | * \brief The code-completion string that describes how to insert this |
| 1300 | * code-completion result into the editing buffer. |
| 1301 | */ |
| 1302 | CXCompletionString CompletionString; |
| 1303 | } CXCompletionResult; |
| 1304 | |
| 1305 | /** |
| 1306 | * \brief Describes a single piece of text within a code-completion string. |
| 1307 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1308 | * Each "chunk" within a code-completion string (\c CXCompletionString) is |
| 1309 | * 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] | 1310 | * should be interpreted by the client or is another completion string. |
| 1311 | */ |
| 1312 | enum CXCompletionChunkKind { |
| 1313 | /** |
| 1314 | * \brief A code-completion string that describes "optional" text that |
| 1315 | * could be a part of the template (but is not required). |
| 1316 | * |
| 1317 | * 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] | 1318 | * string for its representation, which is accessible via |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1319 | * \c clang_getCompletionChunkCompletionString(). The code-completion string |
| 1320 | * describes an additional part of the template that is completely optional. |
| 1321 | * For example, optional chunks can be used to describe the placeholders for |
| 1322 | * arguments that match up with defaulted function parameters, e.g. given: |
| 1323 | * |
| 1324 | * \code |
| 1325 | * void f(int x, float y = 3.14, double z = 2.71828); |
| 1326 | * \endcode |
| 1327 | * |
| 1328 | * The code-completion string for this function would contain: |
| 1329 | * - a TypedText chunk for "f". |
| 1330 | * - a LeftParen chunk for "(". |
| 1331 | * - a Placeholder chunk for "int x" |
| 1332 | * - an Optional chunk containing the remaining defaulted arguments, e.g., |
| 1333 | * - a Comma chunk for "," |
Daniel Dunbar | 7157018 | 2010-02-17 08:07:44 +0000 | [diff] [blame] | 1334 | * - a Placeholder chunk for "float y" |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1335 | * - an Optional chunk containing the last defaulted argument: |
| 1336 | * - a Comma chunk for "," |
| 1337 | * - a Placeholder chunk for "double z" |
| 1338 | * - a RightParen chunk for ")" |
| 1339 | * |
Daniel Dunbar | 7157018 | 2010-02-17 08:07:44 +0000 | [diff] [blame] | 1340 | * There are many ways to handle Optional chunks. Two simple approaches are: |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1341 | * - Completely ignore optional chunks, in which case the template for the |
| 1342 | * function "f" would only include the first parameter ("int x"). |
| 1343 | * - Fully expand all optional chunks, in which case the template for the |
| 1344 | * function "f" would have all of the parameters. |
| 1345 | */ |
| 1346 | CXCompletionChunk_Optional, |
| 1347 | /** |
| 1348 | * \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] | 1349 | * code-completion result. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1350 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1351 | * There will be exactly one "typed text" chunk in a semantic string, which |
| 1352 | * 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] | 1353 | * declaration that could be used at the current code point. Clients are |
| 1354 | * expected to filter the code-completion results based on the text in this |
| 1355 | * chunk. |
| 1356 | */ |
| 1357 | CXCompletionChunk_TypedText, |
| 1358 | /** |
| 1359 | * \brief Text that should be inserted as part of a code-completion result. |
| 1360 | * |
| 1361 | * A "text" chunk represents text that is part of the template to be |
| 1362 | * inserted into user code should this particular code-completion result |
| 1363 | * be selected. |
| 1364 | */ |
| 1365 | CXCompletionChunk_Text, |
| 1366 | /** |
| 1367 | * \brief Placeholder text that should be replaced by the user. |
| 1368 | * |
| 1369 | * A "placeholder" chunk marks a place where the user should insert text |
| 1370 | * into the code-completion template. For example, placeholders might mark |
| 1371 | * the function parameters for a function declaration, to indicate that the |
| 1372 | * user should provide arguments for each of those parameters. The actual |
| 1373 | * text in a placeholder is a suggestion for the text to display before |
| 1374 | * the user replaces the placeholder with real code. |
| 1375 | */ |
| 1376 | CXCompletionChunk_Placeholder, |
| 1377 | /** |
| 1378 | * \brief Informative text that should be displayed but never inserted as |
| 1379 | * part of the template. |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1380 | * |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1381 | * An "informative" chunk contains annotations that can be displayed to |
| 1382 | * help the user decide whether a particular code-completion result is the |
| 1383 | * right option, but which is not part of the actual template to be inserted |
| 1384 | * by code completion. |
| 1385 | */ |
| 1386 | CXCompletionChunk_Informative, |
| 1387 | /** |
| 1388 | * \brief Text that describes the current parameter when code-completion is |
| 1389 | * referring to function call, message send, or template specialization. |
| 1390 | * |
| 1391 | * A "current parameter" chunk occurs when code-completion is providing |
| 1392 | * information about a parameter corresponding to the argument at the |
| 1393 | * code-completion point. For example, given a function |
| 1394 | * |
| 1395 | * \code |
| 1396 | * int add(int x, int y); |
| 1397 | * \endcode |
| 1398 | * |
| 1399 | * and the source code \c add(, where the code-completion point is after the |
| 1400 | * "(", the code-completion string will contain a "current parameter" chunk |
| 1401 | * for "int x", indicating that the current argument will initialize that |
| 1402 | * parameter. After typing further, to \c add(17, (where the code-completion |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1403 | * point is after the ","), the code-completion string will contain a |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1404 | * "current paremeter" chunk to "int y". |
| 1405 | */ |
| 1406 | CXCompletionChunk_CurrentParameter, |
| 1407 | /** |
| 1408 | * \brief A left parenthesis ('('), used to initiate a function call or |
| 1409 | * signal the beginning of a function parameter list. |
| 1410 | */ |
| 1411 | CXCompletionChunk_LeftParen, |
| 1412 | /** |
| 1413 | * \brief A right parenthesis (')'), used to finish a function call or |
| 1414 | * signal the end of a function parameter list. |
| 1415 | */ |
| 1416 | CXCompletionChunk_RightParen, |
| 1417 | /** |
| 1418 | * \brief A left bracket ('['). |
| 1419 | */ |
| 1420 | CXCompletionChunk_LeftBracket, |
| 1421 | /** |
| 1422 | * \brief A right bracket (']'). |
| 1423 | */ |
| 1424 | CXCompletionChunk_RightBracket, |
| 1425 | /** |
| 1426 | * \brief A left brace ('{'). |
| 1427 | */ |
| 1428 | CXCompletionChunk_LeftBrace, |
| 1429 | /** |
| 1430 | * \brief A right brace ('}'). |
| 1431 | */ |
| 1432 | CXCompletionChunk_RightBrace, |
| 1433 | /** |
| 1434 | * \brief A left angle bracket ('<'). |
| 1435 | */ |
| 1436 | CXCompletionChunk_LeftAngle, |
| 1437 | /** |
| 1438 | * \brief A right angle bracket ('>'). |
| 1439 | */ |
| 1440 | CXCompletionChunk_RightAngle, |
| 1441 | /** |
| 1442 | * \brief A comma separator (','). |
| 1443 | */ |
Douglas Gregor | ff5ce6e | 2009-12-18 18:53:37 +0000 | [diff] [blame] | 1444 | CXCompletionChunk_Comma, |
| 1445 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1446 | * \brief Text that specifies the result type of a given result. |
Douglas Gregor | ff5ce6e | 2009-12-18 18:53:37 +0000 | [diff] [blame] | 1447 | * |
| 1448 | * 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] | 1449 | * 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] | 1450 | * expression using the given completion string would have. |
| 1451 | */ |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 1452 | CXCompletionChunk_ResultType, |
| 1453 | /** |
| 1454 | * \brief A colon (':'). |
| 1455 | */ |
| 1456 | CXCompletionChunk_Colon, |
| 1457 | /** |
| 1458 | * \brief A semicolon (';'). |
| 1459 | */ |
| 1460 | CXCompletionChunk_SemiColon, |
| 1461 | /** |
| 1462 | * \brief An '=' sign. |
| 1463 | */ |
| 1464 | CXCompletionChunk_Equal, |
| 1465 | /** |
| 1466 | * Horizontal space (' '). |
| 1467 | */ |
| 1468 | CXCompletionChunk_HorizontalSpace, |
| 1469 | /** |
| 1470 | * Vertical space ('\n'), after which it is generally a good idea to |
| 1471 | * perform indentation. |
| 1472 | */ |
| 1473 | CXCompletionChunk_VerticalSpace |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1474 | }; |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1475 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1476 | /** |
| 1477 | * \brief Determine the kind of a particular chunk within a completion string. |
| 1478 | * |
| 1479 | * \param completion_string the completion string to query. |
| 1480 | * |
| 1481 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 1482 | * |
| 1483 | * \returns the kind of the chunk at the index \c chunk_number. |
| 1484 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1485 | CINDEX_LINKAGE enum CXCompletionChunkKind |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1486 | clang_getCompletionChunkKind(CXCompletionString completion_string, |
| 1487 | unsigned chunk_number); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1488 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1489 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1490 | * \brief Retrieve the text associated with a particular chunk within a |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1491 | * completion string. |
| 1492 | * |
| 1493 | * \param completion_string the completion string to query. |
| 1494 | * |
| 1495 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 1496 | * |
| 1497 | * \returns the text associated with the chunk at index \c chunk_number. |
| 1498 | */ |
Ted Kremenek | 2ef6f8f | 2010-02-17 01:42:24 +0000 | [diff] [blame] | 1499 | CINDEX_LINKAGE CXString |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1500 | clang_getCompletionChunkText(CXCompletionString completion_string, |
| 1501 | unsigned chunk_number); |
| 1502 | |
| 1503 | /** |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1504 | * \brief Retrieve the completion string associated with a particular chunk |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1505 | * within a completion string. |
| 1506 | * |
| 1507 | * \param completion_string the completion string to query. |
| 1508 | * |
| 1509 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 1510 | * |
| 1511 | * \returns the completion string associated with the chunk at index |
| 1512 | * \c chunk_number, or NULL if that chunk is not represented by a completion |
| 1513 | * string. |
| 1514 | */ |
| 1515 | CINDEX_LINKAGE CXCompletionString |
| 1516 | clang_getCompletionChunkCompletionString(CXCompletionString completion_string, |
| 1517 | unsigned chunk_number); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1518 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1519 | /** |
| 1520 | * \brief Retrieve the number of chunks in the given code-completion string. |
| 1521 | */ |
| 1522 | CINDEX_LINKAGE unsigned |
| 1523 | clang_getNumCompletionChunks(CXCompletionString completion_string); |
| 1524 | |
| 1525 | /** |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1526 | * \brief Contains the results of code-completion. |
| 1527 | * |
| 1528 | * This data structure contains the results of code completion, as |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1529 | * produced by \c clang_codeComplete. Its contents must be freed by |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1530 | * \c clang_disposeCodeCompleteResults. |
| 1531 | */ |
| 1532 | typedef struct { |
| 1533 | /** |
| 1534 | * \brief The code-completion results. |
| 1535 | */ |
| 1536 | CXCompletionResult *Results; |
| 1537 | |
| 1538 | /** |
| 1539 | * \brief The number of code-completion results stored in the |
| 1540 | * \c Results array. |
| 1541 | */ |
| 1542 | unsigned NumResults; |
| 1543 | } CXCodeCompleteResults; |
| 1544 | |
| 1545 | /** |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1546 | * \brief Perform code completion at a given location in a source file. |
| 1547 | * |
| 1548 | * This function performs code completion at a particular file, line, and |
| 1549 | * column within source code, providing results that suggest potential |
| 1550 | * code snippets based on the context of the completion. The basic model |
| 1551 | * for code completion is that Clang will parse a complete source file, |
| 1552 | * performing syntax checking up to the location where code-completion has |
| 1553 | * been requested. At that point, a special code-completion token is passed |
| 1554 | * to the parser, which recognizes this token and determines, based on the |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1555 | * current location in the C/Objective-C/C++ grammar and the state of |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1556 | * semantic analysis, what completions to provide. These completions are |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1557 | * returned via a new \c CXCodeCompleteResults structure. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1558 | * |
| 1559 | * Code completion itself is meant to be triggered by the client when the |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1560 | * user types punctuation characters or whitespace, at which point the |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1561 | * code-completion location will coincide with the cursor. For example, if \c p |
| 1562 | * is a pointer, code-completion might be triggered after the "-" and then |
| 1563 | * after the ">" in \c p->. When the code-completion location is afer the ">", |
| 1564 | * the completion results will provide, e.g., the members of the struct that |
| 1565 | * "p" points to. The client is responsible for placing the cursor at the |
| 1566 | * beginning of the token currently being typed, then filtering the results |
| 1567 | * based on the contents of the token. For example, when code-completing for |
| 1568 | * the expression \c p->get, the client should provide the location just after |
| 1569 | * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the |
| 1570 | * client can filter the results based on the current token text ("get"), only |
| 1571 | * showing those results that start with "get". The intent of this interface |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1572 | * is to separate the relatively high-latency acquisition of code-completion |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1573 | * results from the filtering of results on a per-character basis, which must |
| 1574 | * have a lower latency. |
| 1575 | * |
| 1576 | * \param CIdx the \c CXIndex instance that will be used to perform code |
| 1577 | * completion. |
| 1578 | * |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 1579 | * \param source_filename the name of the source file that should be parsed to |
| 1580 | * perform code-completion. This source file must be the same as or include the |
| 1581 | * filename described by \p complete_filename, or no code-completion results |
| 1582 | * will be produced. NOTE: One can also specify NULL for this argument if the |
| 1583 | * source file is included in command_line_args. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1584 | * |
| 1585 | * \param num_command_line_args the number of command-line arguments stored in |
| 1586 | * \p command_line_args. |
| 1587 | * |
| 1588 | * \param command_line_args the command-line arguments to pass to the Clang |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1589 | * compiler to build the given source file. This should include all of the |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1590 | * necessary include paths, language-dialect switches, precompiled header |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1591 | * includes, etc., but should not include any information specific to |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1592 | * code completion. |
| 1593 | * |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 1594 | * \param num_unsaved_files the number of unsaved file entries in \p |
| 1595 | * unsaved_files. |
| 1596 | * |
| 1597 | * \param unsaved_files the files that have not yet been saved to disk |
| 1598 | * but may be required for code completion, including the contents of |
| 1599 | * those files. |
| 1600 | * |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1601 | * \param complete_filename the name of the source file where code completion |
| 1602 | * should be performed. In many cases, this name will be the same as the |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1603 | * source filename. However, the completion filename may also be a file |
| 1604 | * included by the source file, which is required when producing |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1605 | * code-completion results for a header. |
| 1606 | * |
| 1607 | * \param complete_line the line at which code-completion should occur. |
| 1608 | * |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1609 | * \param complete_column the column at which code-completion should occur. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1610 | * Note that the column should point just after the syntactic construct that |
| 1611 | * initiated code completion, and not in the middle of a lexical token. |
| 1612 | * |
Douglas Gregor | 936ea3b | 2010-01-28 00:56:43 +0000 | [diff] [blame] | 1613 | * \param diag_callback callback function that will receive any diagnostics |
| 1614 | * emitted while processing this source file. If NULL, diagnostics will be |
| 1615 | * suppressed. |
| 1616 | * |
| 1617 | * \param diag_client_data client data that will be passed to the diagnostic |
| 1618 | * callback function. |
| 1619 | * |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1620 | * \returns if successful, a new CXCodeCompleteResults structure |
| 1621 | * containing code-completion results, which should eventually be |
| 1622 | * freed with \c clang_disposeCodeCompleteResults(). If code |
| 1623 | * completion fails, returns NULL. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 1624 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1625 | CINDEX_LINKAGE |
| 1626 | CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1627 | const char *source_filename, |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1628 | int num_command_line_args, |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1629 | const char **command_line_args, |
| 1630 | unsigned num_unsaved_files, |
| 1631 | struct CXUnsavedFile *unsaved_files, |
| 1632 | const char *complete_filename, |
| 1633 | unsigned complete_line, |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 1634 | unsigned complete_column); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1636 | /** |
| 1637 | * \brief Free the given set of code-completion results. |
| 1638 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1639 | CINDEX_LINKAGE |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 1640 | void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1641 | |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 1642 | /** |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 1643 | * \brief Determine the number of diagnostics produced prior to the |
| 1644 | * location where code completion was performed. |
| 1645 | */ |
| 1646 | CINDEX_LINKAGE |
| 1647 | unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); |
| 1648 | |
| 1649 | /** |
| 1650 | * \brief Retrieve a diagnostic associated with the given code completion. |
| 1651 | * |
| 1652 | * \param Result the code completion results to query. |
| 1653 | * \param Index the zero-based diagnostic number to retrieve. |
| 1654 | * |
| 1655 | * \returns the requested diagnostic. This diagnostic must be freed |
| 1656 | * via a call to \c clang_disposeDiagnostic(). |
| 1657 | */ |
| 1658 | CINDEX_LINKAGE |
| 1659 | CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, |
| 1660 | unsigned Index); |
| 1661 | |
| 1662 | /** |
Douglas Gregor | 20d416c | 2010-01-20 01:10:47 +0000 | [diff] [blame] | 1663 | * @} |
| 1664 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1665 | |
| 1666 | |
Ted Kremenek | 04bb716 | 2010-01-22 22:44:15 +0000 | [diff] [blame] | 1667 | /** |
| 1668 | * \defgroup CINDEX_MISC Miscellaneous utility functions |
| 1669 | * |
| 1670 | * @{ |
| 1671 | */ |
Ted Kremenek | 23e1ad0 | 2010-01-23 17:51:23 +0000 | [diff] [blame] | 1672 | |
| 1673 | /** |
| 1674 | * \brief Return a version string, suitable for showing to a user, but not |
| 1675 | * intended to be parsed (the format is not guaranteed to be stable). |
| 1676 | */ |
Ted Kremenek | a2a9d6e | 2010-02-12 22:54:40 +0000 | [diff] [blame] | 1677 | CINDEX_LINKAGE CXString clang_getClangVersion(); |
Ted Kremenek | 04bb716 | 2010-01-22 22:44:15 +0000 | [diff] [blame] | 1678 | |
| 1679 | /** |
Ted Kremenek | 16b55a7 | 2010-01-26 19:31:51 +0000 | [diff] [blame] | 1680 | * \brief Return a version string, suitable for showing to a user, but not |
| 1681 | * intended to be parsed (the format is not guaranteed to be stable). |
| 1682 | */ |
| 1683 | |
| 1684 | |
| 1685 | /** |
| 1686 | * \brief Visitor invoked for each file in a translation unit |
| 1687 | * (used with clang_getInclusions()). |
| 1688 | * |
| 1689 | * This visitor function will be invoked by clang_getInclusions() for each |
| 1690 | * file included (either at the top-level or by #include directives) within |
| 1691 | * a translation unit. The first argument is the file being included, and |
| 1692 | * the second and third arguments provide the inclusion stack. The |
| 1693 | * array is sorted in order of immediate inclusion. For example, |
| 1694 | * the first element refers to the location that included 'included_file'. |
| 1695 | */ |
| 1696 | typedef void (*CXInclusionVisitor)(CXFile included_file, |
| 1697 | CXSourceLocation* inclusion_stack, |
| 1698 | unsigned include_len, |
| 1699 | CXClientData client_data); |
| 1700 | |
| 1701 | /** |
| 1702 | * \brief Visit the set of preprocessor inclusions in a translation unit. |
| 1703 | * The visitor function is called with the provided data for every included |
| 1704 | * file. This does not include headers included by the PCH file (unless one |
| 1705 | * is inspecting the inclusions in the PCH file itself). |
| 1706 | */ |
| 1707 | CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, |
| 1708 | CXInclusionVisitor visitor, |
| 1709 | CXClientData client_data); |
| 1710 | |
| 1711 | /** |
Ted Kremenek | 04bb716 | 2010-01-22 22:44:15 +0000 | [diff] [blame] | 1712 | * @} |
| 1713 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1714 | |
Douglas Gregor | c42fefa | 2010-01-22 22:29:16 +0000 | [diff] [blame] | 1715 | /** |
| 1716 | * @} |
| 1717 | */ |
Daniel Dunbar | 1efcf3d | 2010-01-24 02:54:26 +0000 | [diff] [blame] | 1718 | |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 1719 | #ifdef __cplusplus |
| 1720 | } |
| 1721 | #endif |
| 1722 | #endif |
| 1723 | |