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