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 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 37 | /* |
| 38 | Clang indeX abstractions. The backing store for the following API's will be |
Steve Naroff | b7cd17c | 2009-09-01 17:13:31 +0000 | [diff] [blame] | 39 | clangs AST file (currently based on PCH). AST files are created as follows: |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 40 | |
Steve Naroff | b7cd17c | 2009-09-01 17:13:31 +0000 | [diff] [blame] | 41 | "clang -emit-ast <sourcefile.langsuffix> -o <sourcefile.ast>". |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 42 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 43 | Naming Conventions: To avoid namespace pollution, data types are prefixed |
| 44 | with "CX" and functions are prefixed with "clang_". |
| 45 | */ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 46 | typedef void *CXIndex; /* An indexing instance. */ |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 47 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 48 | typedef void *CXTranslationUnit; /* A translation unit instance. */ |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 49 | |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 50 | typedef void *CXFile; /* A source file */ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 51 | typedef void *CXDecl; /* A specific declaration within a translation unit. */ |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 52 | typedef void *CXStmt; /* A specific statement within a function/method */ |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 53 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 54 | /* Cursors represent declarations, definitions, and references. */ |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 55 | enum CXCursorKind { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 56 | /* Declarations */ |
| 57 | CXCursor_FirstDecl = 1, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 58 | /** \brief A typedef */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 59 | CXCursor_TypedefDecl = 1, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 60 | /** \brief A C or C++ struct. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 61 | CXCursor_StructDecl = 2, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 62 | /** \brief A C or C++ union. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 63 | CXCursor_UnionDecl = 3, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 64 | /** \brief A C++ class. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 65 | CXCursor_ClassDecl = 4, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 66 | /** \brief An enumeration. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 67 | CXCursor_EnumDecl = 5, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 68 | /** |
| 69 | * \brief A field (in C) or non-static data member (in C++) in a |
| 70 | * struct, union, or C++ class. |
| 71 | */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 72 | CXCursor_FieldDecl = 6, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 73 | /** \brief An enumerator constant. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 74 | CXCursor_EnumConstantDecl = 7, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 75 | /** \brief A function. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 76 | CXCursor_FunctionDecl = 8, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 77 | /** \brief A variable. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 78 | CXCursor_VarDecl = 9, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 79 | /** \brief A function or method parameter. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 80 | CXCursor_ParmDecl = 10, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 81 | /** \brief An Objective-C @interface. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 82 | CXCursor_ObjCInterfaceDecl = 11, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 83 | /** \brief An Objective-C @interface for a category. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 84 | CXCursor_ObjCCategoryDecl = 12, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 85 | /** \brief An Objective-C @protocol declaration. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 86 | CXCursor_ObjCProtocolDecl = 13, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 87 | /** \brief An Objective-C @property declaration. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 88 | CXCursor_ObjCPropertyDecl = 14, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 89 | /** \brief An Objective-C instance variable. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 90 | CXCursor_ObjCIvarDecl = 15, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 91 | /** \brief An Objective-C instance method. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 92 | CXCursor_ObjCInstanceMethodDecl = 16, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 93 | /** \brief An Objective-C class method. */ |
Ted Kremenek | deb06bd | 2010-01-16 02:02:09 +0000 | [diff] [blame] | 94 | CXCursor_ObjCClassMethodDecl = 17, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 95 | /** \brief An Objective-C @implementation. */ |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 96 | CXCursor_ObjCImplementationDecl = 18, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 97 | /** \brief An Objective-C @implementation for a category. */ |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 98 | CXCursor_ObjCCategoryImplDecl = 19, |
Douglas Gregor | 3012213 | 2010-01-19 22:07:56 +0000 | [diff] [blame] | 99 | /** |
| 100 | * \brief A declaration whose specific kind is not exposed via this |
| 101 | * interface. |
| 102 | * |
| 103 | * Unexposed declarations have the same operations as any other kind |
| 104 | * of declaration; one can extract their location information, |
| 105 | * spelling, find their definitions, etc. However, the specific kind |
| 106 | * of the declaration is not reported. |
| 107 | */ |
| 108 | CXCursor_UnexposedDecl = 20, |
| 109 | CXCursor_LastDecl = 20, |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 110 | |
| 111 | /* References */ |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 112 | CXCursor_FirstRef = 40, /* Decl references */ |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 113 | CXCursor_ObjCSuperClassRef = 40, |
| 114 | CXCursor_ObjCProtocolRef = 41, |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 115 | CXCursor_ObjCClassRef = 42, |
Douglas Gregor | e0ca4ba | 2010-01-19 23:25:01 +0000 | [diff] [blame^] | 116 | CXCursor_LastRef = 42, |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 117 | |
| 118 | /* Error conditions */ |
| 119 | CXCursor_FirstInvalid = 70, |
| 120 | CXCursor_InvalidFile = 70, |
| 121 | CXCursor_NoDeclFound = 71, |
| 122 | CXCursor_NotImplemented = 72, |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 123 | CXCursor_LastInvalid = 72, |
| 124 | |
| 125 | /* Expressions */ |
| 126 | CXCursor_FirstExpr = 100, |
| 127 | |
| 128 | /** |
| 129 | * \brief An expression whose specific kind is not exposed via this |
| 130 | * interface. |
| 131 | * |
| 132 | * Unexposed expressions have the same operations as any other kind |
| 133 | * of expression; one can extract their location information, |
| 134 | * spelling, children, etc. However, the specific kind of the |
| 135 | * expression is not reported. |
| 136 | */ |
| 137 | CXCursor_UnexposedExpr = 100, |
| 138 | |
| 139 | /** |
| 140 | * \brief An expression that refers to some value declaration, such |
| 141 | * as a function, varible, or enumerator. |
| 142 | */ |
| 143 | CXCursor_DeclRefExpr = 101, |
| 144 | |
| 145 | /** |
| 146 | * \brief An expression that refers to a member of a struct, union, |
| 147 | * class, Objective-C class, etc. |
| 148 | */ |
| 149 | CXCursor_MemberRefExpr = 102, |
| 150 | |
| 151 | /** \brief An expression that calls a function. */ |
| 152 | CXCursor_CallExpr = 103, |
| 153 | |
| 154 | /** \brief An expression that sends a message to an Objective-C |
| 155 | object or class. */ |
| 156 | CXCursor_ObjCMessageExpr = 104, |
| 157 | CXCursor_LastExpr = 104, |
| 158 | |
| 159 | /* Statements */ |
| 160 | CXCursor_FirstStmt = 200, |
| 161 | /** |
| 162 | * \brief A statement whose specific kind is not exposed via this |
| 163 | * interface. |
| 164 | * |
| 165 | * Unexposed statements have the same operations as any other kind of |
| 166 | * statement; one can extract their location information, spelling, |
| 167 | * children, etc. However, the specific kind of the statement is not |
| 168 | * reported. |
| 169 | */ |
| 170 | CXCursor_UnexposedStmt = 200, |
| 171 | CXCursor_LastStmt = 200 |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 174 | /** |
| 175 | * \brief Provides the contents of a file that has not yet been saved to disk. |
| 176 | * |
| 177 | * Each CXUnsavedFile instance provides the name of a file on the |
| 178 | * system along with the current contents of that file that have not |
| 179 | * yet been saved to disk. |
| 180 | */ |
| 181 | struct CXUnsavedFile { |
| 182 | /** |
| 183 | * \brief The file whose contents have not yet been saved. |
| 184 | * |
| 185 | * This file must already exist in the file system. |
| 186 | */ |
| 187 | const char *Filename; |
| 188 | |
| 189 | /** |
| 190 | * \brief A null-terminated buffer containing the unsaved contents |
| 191 | * of this file. |
| 192 | */ |
| 193 | const char *Contents; |
| 194 | |
| 195 | /** |
| 196 | * \brief The length of the unsaved contents of this buffer, not |
| 197 | * counting the NULL at the end of the buffer. |
| 198 | */ |
| 199 | unsigned long Length; |
| 200 | }; |
| 201 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 202 | /* A cursor into the CXTranslationUnit. */ |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 203 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 204 | typedef struct { |
| 205 | enum CXCursorKind kind; |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 206 | void *data[3]; |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 207 | } CXCursor; |
| 208 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 209 | /* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */ |
Ted Kremenek | 3172383 | 2010-01-11 23:56:39 +0000 | [diff] [blame] | 210 | typedef struct { |
| 211 | CXIndex index; |
| 212 | void *data; |
| 213 | } CXEntity; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 214 | |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 215 | /** |
| 216 | * For functions returning a string that might or might not need |
| 217 | * to be internally allocated and freed. |
| 218 | * Use clang_getCString to access the C string value. |
| 219 | * Use clang_disposeString to free the value. |
| 220 | * Treat it as an opaque type. |
| 221 | */ |
| 222 | typedef struct { |
| 223 | const char *Spelling; |
| 224 | /* A 1 value indicates the clang_ indexing API needed to allocate the string |
| 225 | (and it must be freed by clang_disposeString()). */ |
| 226 | int MustFreeString; |
| 227 | } CXString; |
| 228 | |
| 229 | /* Get C string pointer from a CXString. */ |
| 230 | CINDEX_LINKAGE const char *clang_getCString(CXString string); |
| 231 | |
| 232 | /* Free CXString. */ |
| 233 | CINDEX_LINKAGE void clang_disposeString(CXString string); |
| 234 | |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 235 | /** |
| 236 | * \brief clang_createIndex() provides a shared context for creating |
| 237 | * translation units. It provides two options: |
| 238 | * |
| 239 | * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" |
| 240 | * declarations (when loading any new translation units). A "local" declaration |
| 241 | * is one that belongs in the translation unit itself and not in a precompiled |
| 242 | * header that was used by the translation unit. If zero, all declarations |
| 243 | * will be enumerated. |
| 244 | * |
| 245 | * - displayDiagnostics: when non-zero, diagnostics will be output. If zero, |
| 246 | * diagnostics will be ignored. |
Steve Naroff | b4ece63 | 2009-10-20 16:36:34 +0000 | [diff] [blame] | 247 | * |
| 248 | * Here is an example: |
| 249 | * |
| 250 | * // excludeDeclsFromPCH = 1, displayDiagnostics = 1 |
| 251 | * Idx = clang_createIndex(1, 1); |
| 252 | * |
| 253 | * // IndexTest.pch was produced with the following command: |
| 254 | * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" |
| 255 | * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); |
| 256 | * |
| 257 | * // This will load all the symbols from 'IndexTest.pch' |
| 258 | * clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0); |
| 259 | * clang_disposeTranslationUnit(TU); |
| 260 | * |
| 261 | * // This will load all the symbols from 'IndexTest.c', excluding symbols |
| 262 | * // from 'IndexTest.pch'. |
| 263 | * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch", 0 }; |
| 264 | * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args); |
| 265 | * clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0); |
| 266 | * clang_disposeTranslationUnit(TU); |
| 267 | * |
| 268 | * This process of creating the 'pch', loading it separately, and using it (via |
| 269 | * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks |
| 270 | * (which gives the indexer the same performance benefit as the compiler). |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 271 | */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 272 | CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 273 | int displayDiagnostics); |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 274 | CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); |
| 275 | CINDEX_LINKAGE CXString |
| 276 | clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); |
| 277 | |
| 278 | /* |
| 279 | * \brief Request that AST's be generated external for API calls which parse |
| 280 | * source code on the fly, e.g. \see createTranslationUnitFromSourceFile. |
| 281 | * |
| 282 | * Note: This is for debugging purposes only, and may be removed at a later |
| 283 | * date. |
| 284 | * |
| 285 | * \param index - The index to update. |
| 286 | * \param value - The new flag value. |
| 287 | */ |
| 288 | CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index, |
| 289 | int value); |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 290 | |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 291 | /* |
| 292 | * \brief Create a translation unit from an AST file (-emit-ast). |
| 293 | */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 294 | CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit( |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 295 | CXIndex, const char *ast_filename |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 296 | ); |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 297 | |
Ted Kremenek | 1374598 | 2009-10-19 22:15:09 +0000 | [diff] [blame] | 298 | /** |
| 299 | * \brief Destroy the specified CXTranslationUnit object. |
| 300 | */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 301 | CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); |
Ted Kremenek | 1374598 | 2009-10-19 22:15:09 +0000 | [diff] [blame] | 302 | |
| 303 | /** |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 304 | * \brief Return the CXTranslationUnit for a given source file and the provided |
| 305 | * command line arguments one would pass to the compiler. |
| 306 | * |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 307 | * Note: The 'source_filename' argument is optional. If the caller provides a |
| 308 | * NULL pointer, the name of the source file is expected to reside in the |
| 309 | * specified command line arguments. |
Ted Kremenek | 139ba86 | 2009-10-22 00:03:57 +0000 | [diff] [blame] | 310 | * |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 311 | * Note: When encountered in 'clang_command_line_args', the following options |
| 312 | * are ignored: |
Ted Kremenek | 139ba86 | 2009-10-22 00:03:57 +0000 | [diff] [blame] | 313 | * |
| 314 | * '-c' |
| 315 | * '-emit-ast' |
| 316 | * '-fsyntax-only' |
| 317 | * '-o <output file>' (both '-o' and '<output file>' are ignored) |
| 318 | * |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 319 | * |
| 320 | * \param source_filename - The name of the source file to load, or NULL if the |
| 321 | * source file is included in clang_command_line_args. |
Ted Kremenek | 1374598 | 2009-10-19 22:15:09 +0000 | [diff] [blame] | 322 | */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 323 | CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 324 | CXIndex CIdx, |
| 325 | const char *source_filename, |
Steve Naroff | 5b7d8e2 | 2009-10-15 20:04:39 +0000 | [diff] [blame] | 326 | int num_clang_command_line_args, |
Steve Naroff | e56b4ba | 2009-10-20 14:46:24 +0000 | [diff] [blame] | 327 | const char **clang_command_line_args |
Steve Naroff | 5b7d8e2 | 2009-10-15 20:04:39 +0000 | [diff] [blame] | 328 | ); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | Usage: clang_loadTranslationUnit(). Will load the toplevel declarations |
| 332 | within a translation unit, issuing a 'callback' for each one. |
| 333 | |
| 334 | void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) { |
| 335 | if (clang_getCursorKind(C) == Cursor_Declaration) { |
| 336 | CXDecl D = clang_getCursorDecl(C); |
| 337 | if (clang_getDeclKind(D) == CXDecl_ObjC_interface) |
| 338 | printf("@interface %s in file %s on line %d column %d\n", |
| 339 | clang_getDeclSpelling(D), clang_getCursorSource(C), |
| 340 | clang_getCursorLine(C), clang_getCursorColumn(C)); |
| 341 | } |
| 342 | } |
| 343 | static void usage { |
| 344 | clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames); |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 345 | } |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 346 | */ |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 347 | typedef void *CXClientData; |
| 348 | typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor, |
| 349 | CXClientData); |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 350 | CINDEX_LINKAGE void clang_loadTranslationUnit(CXTranslationUnit, |
| 351 | CXTranslationUnitIterator, |
| 352 | CXClientData); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | Usage: clang_loadDeclaration(). Will load the declaration, issuing a |
| 356 | 'callback' for each declaration/reference within the respective declaration. |
| 357 | |
| 358 | For interface declarations, this will index the super class, protocols, |
| 359 | ivars, methods, etc. For structure declarations, this will index the fields. |
| 360 | For functions, this will index the parameters (and body, for function |
| 361 | definitions), local declarations/references. |
| 362 | |
| 363 | void getInterfaceDetails(CXDecl X, CXCursor C) { |
| 364 | switch (clang_getCursorKind(C)) { |
| 365 | case Cursor_ObjC_ClassRef: |
| 366 | CXDecl SuperClass = clang_getCursorDecl(C); |
| 367 | case Cursor_ObjC_ProtocolRef: |
| 368 | CXDecl AdoptsProtocol = clang_getCursorDecl(C); |
| 369 | case Cursor_Declaration: |
| 370 | CXDecl AnIvarOrMethod = clang_getCursorDecl(C); |
| 371 | } |
| 372 | } |
| 373 | static void usage() { |
| 374 | if (clang_getDeclKind(D) == CXDecl_ObjC_interface) { |
| 375 | clang_loadDeclaration(D, getInterfaceDetails); |
| 376 | } |
| 377 | } |
| 378 | */ |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 379 | typedef void (*CXDeclIterator)(CXDecl, CXCursor, CXClientData); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 380 | |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 381 | CINDEX_LINKAGE void clang_loadDeclaration(CXDecl, CXDeclIterator, CXClientData); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 382 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 383 | /* |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 384 | * CXFile Operations. |
| 385 | */ |
Douglas Gregor | 08b0e8d | 2009-10-31 15:48:08 +0000 | [diff] [blame] | 386 | CINDEX_LINKAGE const char *clang_getFileName(CXFile SFile); |
| 387 | CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); |
Steve Naroff | 8814503 | 2009-10-27 14:35:18 +0000 | [diff] [blame] | 388 | |
| 389 | /* |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 390 | * CXEntity Operations. |
| 391 | */ |
Ted Kremenek | 3172383 | 2010-01-11 23:56:39 +0000 | [diff] [blame] | 392 | |
| 393 | /* clang_getDeclaration() maps from a CXEntity to the matching CXDecl (if any) |
| 394 | * in a specified translation unit. */ |
| 395 | CINDEX_LINKAGE CXDecl clang_getDeclaration(CXEntity, CXTranslationUnit); |
| 396 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 397 | /* |
| 398 | * CXDecl Operations. |
| 399 | */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 400 | CINDEX_LINKAGE CXCursor clang_getCursorFromDecl(CXDecl); |
Ted Kremenek | 3172383 | 2010-01-11 23:56:39 +0000 | [diff] [blame] | 401 | CINDEX_LINKAGE CXEntity clang_getEntityFromDecl(CXIndex, CXDecl); |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 402 | CINDEX_LINKAGE CXString clang_getDeclSpelling(CXDecl); |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 403 | CINDEX_LINKAGE unsigned clang_getDeclLine(CXDecl); /* deprecate */ |
| 404 | CINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl); /* deprecate */ |
Ted Kremenek | 6ab9db1 | 2010-01-08 17:11:32 +0000 | [diff] [blame] | 405 | CINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */ |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 406 | CINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl); /* deprecate */ |
Steve Naroff | 699a07d | 2009-09-25 21:32:34 +0000 | [diff] [blame] | 407 | |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 408 | /** |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 409 | * \brief Identifies a specific source location within a translation |
| 410 | * unit. |
| 411 | * |
| 412 | * Use clang_getInstantiationLocation() to map a source location to a |
| 413 | * particular file, line, and column. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 414 | */ |
| 415 | typedef struct { |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 416 | void *ptr_data; |
| 417 | unsigned int_data; |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 418 | } CXSourceLocation; |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 419 | |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 420 | /** |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 421 | * \brief Identifies a range of source locations in the source code. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 422 | * |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 423 | * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the |
| 424 | * starting and end locations from a source range, respectively. |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 425 | */ |
| 426 | typedef struct { |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 427 | void *ptr_data; |
| 428 | unsigned begin_int_data; |
| 429 | unsigned end_int_data; |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 430 | } CXSourceRange; |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 431 | |
Douglas Gregor | 1db19de | 2010-01-19 21:36:55 +0000 | [diff] [blame] | 432 | /** |
| 433 | * \brief Retrieve the file, line, and column represented by the |
| 434 | * given source location. |
| 435 | * |
| 436 | * \param location the location within a source file that will be |
| 437 | * decomposed into its parts. |
| 438 | * |
| 439 | * \param file if non-NULL, will be set to the file to which the given |
| 440 | * source location points. |
| 441 | * |
| 442 | * \param line if non-NULL, will be set to the line to which the given |
| 443 | * source location points. |
| 444 | * |
| 445 | * \param column if non-NULL, will be set to the column to which the |
| 446 | * given source location points. |
| 447 | */ |
| 448 | CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, |
| 449 | CXFile *file, |
| 450 | unsigned *line, |
| 451 | unsigned *column); |
| 452 | |
| 453 | /** |
| 454 | * \brief Retrieve a source location representing the first |
| 455 | * character within a source range. |
| 456 | */ |
| 457 | CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); |
| 458 | |
| 459 | /** |
| 460 | * \brief Retrieve a source location representing the last |
| 461 | * character within a source range. |
| 462 | */ |
| 463 | CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); |
| 464 | |
Daniel Dunbar | 3aacd53 | 2010-01-06 06:51:48 +0000 | [diff] [blame] | 465 | /* clang_getDeclExtent() returns the physical extent of a declaration. The |
| 466 | * beginning line/column pair points to the start of the first token in the |
Ted Kremenek | d821065 | 2010-01-06 23:43:31 +0000 | [diff] [blame] | 467 | * declaration, and the ending line/column pair points to the last character in |
| 468 | * the last token of the declaration. |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 469 | */ |
Douglas Gregor | 3c7313d | 2010-01-18 22:13:09 +0000 | [diff] [blame] | 470 | CINDEX_LINKAGE CXSourceRange clang_getDeclExtent(CXDecl); |
Ted Kremenek | fe6fd3d | 2010-01-05 23:18:49 +0000 | [diff] [blame] | 471 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 472 | /* |
| 473 | * CXCursor Operations. |
| 474 | */ |
Steve Naroff | 6a6de8b | 2009-10-21 13:56:23 +0000 | [diff] [blame] | 475 | /** |
| 476 | Usage: clang_getCursor() will translate a source/line/column position |
| 477 | into an AST cursor (to derive semantic information from the source code). |
Steve Naroff | 6a6de8b | 2009-10-21 13:56:23 +0000 | [diff] [blame] | 478 | */ |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 479 | CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, |
| 480 | const char *source_name, |
| 481 | unsigned line, unsigned column); |
Ted Kremenek | 7388555 | 2009-11-17 19:28:59 +0000 | [diff] [blame] | 482 | |
| 483 | CINDEX_LINKAGE CXCursor clang_getNullCursor(void); |
Ted Kremenek | fbcb2b7 | 2009-10-22 17:22:53 +0000 | [diff] [blame] | 484 | |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 485 | /* clang_getCursorUSR() returns the USR (if any) associated with entity referred to by the |
| 486 | * provided CXCursor object. */ |
| 487 | CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); |
| 488 | |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 489 | CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); |
| 490 | CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); |
| 491 | CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 492 | CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); |
| 493 | CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 494 | CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 495 | |
Ted Kremenek | 7388555 | 2009-11-17 19:28:59 +0000 | [diff] [blame] | 496 | CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); |
| 497 | |
Steve Naroff | ef0cef6 | 2009-11-09 17:45:52 +0000 | [diff] [blame] | 498 | CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | 98258af | 2010-01-18 22:46:11 +0000 | [diff] [blame] | 500 | /** |
| 501 | * \brief Retrieve the physical location of the source constructor referenced |
| 502 | * by the given cursor. |
| 503 | * |
| 504 | * The location of a declaration is typically the location of the name of that |
| 505 | * declaration, where the name of that declaration would occur if it is |
| 506 | * unnamed, or some keyword that introduces that particular declaration. |
| 507 | * The location of a reference is where that reference occurs within the |
| 508 | * source code. |
| 509 | */ |
| 510 | CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); |
| 511 | |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 512 | /** |
| 513 | * \brief Retrieve the physical extent of the source construct referenced by |
Douglas Gregor | a7bde20 | 2010-01-19 00:34:46 +0000 | [diff] [blame] | 514 | * the given cursor. |
| 515 | * |
| 516 | * The extent of a cursor starts with the file/line/column pointing at the |
| 517 | * first character within the source construct that the cursor refers to and |
| 518 | * ends with the last character withinin that source construct. For a |
| 519 | * declaration, the extent covers the declaration itself. For a reference, |
| 520 | * the extent covers the location of the reference (e.g., where the referenced |
| 521 | * entity was actually used). |
| 522 | */ |
| 523 | CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); |
Douglas Gregor | c5d1e93 | 2010-01-19 01:20:04 +0000 | [diff] [blame] | 524 | |
| 525 | /** \brief For a cursor that is a reference, retrieve a cursor representing the |
| 526 | * entity that it references. |
| 527 | * |
| 528 | * Reference cursors refer to other entities in the AST. For example, an |
| 529 | * Objective-C superclass reference cursor refers to an Objective-C class. |
| 530 | * This function produces the cursor for the Objective-C class from the |
| 531 | * cursor for the superclass reference. If the input cursor is a declaration or |
| 532 | * definition, it returns that declaration or definition unchanged. |
| 533 | * Othewise, returns the NULL cursor. |
| 534 | */ |
| 535 | CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); |
Douglas Gregor | b699866 | 2010-01-19 19:34:47 +0000 | [diff] [blame] | 536 | |
| 537 | /** |
| 538 | * \brief For a cursor that is either a reference to or a declaration |
| 539 | * of some entity, retrieve a cursor that describes the definition of |
| 540 | * that entity. |
| 541 | * |
| 542 | * Some entities can be declared multiple times within a translation |
| 543 | * unit, but only one of those declarations can also be a |
| 544 | * definition. For example, given: |
| 545 | * |
| 546 | * \code |
| 547 | * int f(int, int); |
| 548 | * int g(int x, int y) { return f(x, y); } |
| 549 | * int f(int a, int b) { return a + b; } |
| 550 | * int f(int, int); |
| 551 | * \endcode |
| 552 | * |
| 553 | * there are three declarations of the function "f", but only the |
| 554 | * second one is a definition. The clang_getCursorDefinition() |
| 555 | * function will take any cursor pointing to a declaration of "f" |
| 556 | * (the first or fourth lines of the example) or a cursor referenced |
| 557 | * that uses "f" (the call to "f' inside "g") and will return a |
| 558 | * declaration cursor pointing to the definition (the second "f" |
| 559 | * declaration). |
| 560 | * |
| 561 | * If given a cursor for which there is no corresponding definition, |
| 562 | * e.g., because there is no definition of that entity within this |
| 563 | * translation unit, returns a NULL cursor. |
| 564 | */ |
| 565 | CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); |
| 566 | |
| 567 | /** |
| 568 | * \brief Determine whether the declaration pointed to by this cursor |
| 569 | * is also a definition of that entity. |
| 570 | */ |
| 571 | CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); |
| 572 | |
Steve Naroff | 4ade6d6 | 2009-09-23 17:52:52 +0000 | [diff] [blame] | 573 | /* for debug/testing */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 574 | CINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind); |
| 575 | CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, |
Steve Naroff | 4ade6d6 | 2009-09-23 17:52:52 +0000 | [diff] [blame] | 576 | const char **startBuf, |
| 577 | const char **endBuf, |
| 578 | unsigned *startLine, |
| 579 | unsigned *startColumn, |
| 580 | unsigned *endLine, |
| 581 | unsigned *endColumn); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 582 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 583 | /* |
Chris Lattner | 459789b | 2009-09-16 20:18:54 +0000 | [diff] [blame] | 584 | * If CXCursorKind == Cursor_Reference, then this will return the referenced |
| 585 | * declaration. |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 586 | * If CXCursorKind == Cursor_Declaration, then this will return the declaration. |
| 587 | */ |
John Thompson | 2e06fc8 | 2009-10-27 13:42:56 +0000 | [diff] [blame] | 588 | CINDEX_LINKAGE CXDecl clang_getCursorDecl(CXCursor); |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 589 | |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 590 | /** |
| 591 | * \brief A semantic string that describes a code-completion result. |
| 592 | * |
| 593 | * A semantic string that describes the formatting of a code-completion |
| 594 | * result as a single "template" of text that should be inserted into the |
| 595 | * source buffer when a particular code-completion result is selected. |
| 596 | * Each semantic string is made up of some number of "chunks", each of which |
| 597 | * contains some text along with a description of what that text means, e.g., |
| 598 | * the name of the entity being referenced, whether the text chunk is part of |
| 599 | * the template, or whether it is a "placeholder" that the user should replace |
| 600 | * with actual code,of a specific kind. See \c CXCompletionChunkKind for a |
| 601 | * description of the different kinds of chunks. |
| 602 | */ |
| 603 | typedef void *CXCompletionString; |
| 604 | |
| 605 | /** |
| 606 | * \brief A single result of code completion. |
| 607 | */ |
| 608 | typedef struct { |
| 609 | /** |
| 610 | * \brief The kind of entity that this completion refers to. |
| 611 | * |
| 612 | * The cursor kind will be a macro, keyword, or a declaration (one of the |
| 613 | * *Decl cursor kinds), describing the entity that the completion is |
| 614 | * referring to. |
| 615 | * |
| 616 | * \todo In the future, we would like to provide a full cursor, to allow |
| 617 | * the client to extract additional information from declaration. |
| 618 | */ |
| 619 | enum CXCursorKind CursorKind; |
| 620 | |
| 621 | /** |
| 622 | * \brief The code-completion string that describes how to insert this |
| 623 | * code-completion result into the editing buffer. |
| 624 | */ |
| 625 | CXCompletionString CompletionString; |
| 626 | } CXCompletionResult; |
| 627 | |
| 628 | /** |
| 629 | * \brief Describes a single piece of text within a code-completion string. |
| 630 | * |
| 631 | * Each "chunk" within a code-completion string (\c CXCompletionString) is |
| 632 | * either a piece of text with a specific "kind" that describes how that text |
| 633 | * should be interpreted by the client or is another completion string. |
| 634 | */ |
| 635 | enum CXCompletionChunkKind { |
| 636 | /** |
| 637 | * \brief A code-completion string that describes "optional" text that |
| 638 | * could be a part of the template (but is not required). |
| 639 | * |
| 640 | * The Optional chunk is the only kind of chunk that has a code-completion |
| 641 | * string for its representation, which is accessible via |
| 642 | * \c clang_getCompletionChunkCompletionString(). The code-completion string |
| 643 | * describes an additional part of the template that is completely optional. |
| 644 | * For example, optional chunks can be used to describe the placeholders for |
| 645 | * arguments that match up with defaulted function parameters, e.g. given: |
| 646 | * |
| 647 | * \code |
| 648 | * void f(int x, float y = 3.14, double z = 2.71828); |
| 649 | * \endcode |
| 650 | * |
| 651 | * The code-completion string for this function would contain: |
| 652 | * - a TypedText chunk for "f". |
| 653 | * - a LeftParen chunk for "(". |
| 654 | * - a Placeholder chunk for "int x" |
| 655 | * - an Optional chunk containing the remaining defaulted arguments, e.g., |
| 656 | * - a Comma chunk for "," |
| 657 | * - a Placeholder chunk for "float x" |
| 658 | * - an Optional chunk containing the last defaulted argument: |
| 659 | * - a Comma chunk for "," |
| 660 | * - a Placeholder chunk for "double z" |
| 661 | * - a RightParen chunk for ")" |
| 662 | * |
| 663 | * There are many ways two handle Optional chunks. Two simple approaches are: |
| 664 | * - Completely ignore optional chunks, in which case the template for the |
| 665 | * function "f" would only include the first parameter ("int x"). |
| 666 | * - Fully expand all optional chunks, in which case the template for the |
| 667 | * function "f" would have all of the parameters. |
| 668 | */ |
| 669 | CXCompletionChunk_Optional, |
| 670 | /** |
| 671 | * \brief Text that a user would be expected to type to get this |
| 672 | * code-completion result. |
| 673 | * |
| 674 | * There will be exactly one "typed text" chunk in a semantic string, which |
| 675 | * will typically provide the spelling of a keyword or the name of a |
| 676 | * declaration that could be used at the current code point. Clients are |
| 677 | * expected to filter the code-completion results based on the text in this |
| 678 | * chunk. |
| 679 | */ |
| 680 | CXCompletionChunk_TypedText, |
| 681 | /** |
| 682 | * \brief Text that should be inserted as part of a code-completion result. |
| 683 | * |
| 684 | * A "text" chunk represents text that is part of the template to be |
| 685 | * inserted into user code should this particular code-completion result |
| 686 | * be selected. |
| 687 | */ |
| 688 | CXCompletionChunk_Text, |
| 689 | /** |
| 690 | * \brief Placeholder text that should be replaced by the user. |
| 691 | * |
| 692 | * A "placeholder" chunk marks a place where the user should insert text |
| 693 | * into the code-completion template. For example, placeholders might mark |
| 694 | * the function parameters for a function declaration, to indicate that the |
| 695 | * user should provide arguments for each of those parameters. The actual |
| 696 | * text in a placeholder is a suggestion for the text to display before |
| 697 | * the user replaces the placeholder with real code. |
| 698 | */ |
| 699 | CXCompletionChunk_Placeholder, |
| 700 | /** |
| 701 | * \brief Informative text that should be displayed but never inserted as |
| 702 | * part of the template. |
| 703 | * |
| 704 | * An "informative" chunk contains annotations that can be displayed to |
| 705 | * help the user decide whether a particular code-completion result is the |
| 706 | * right option, but which is not part of the actual template to be inserted |
| 707 | * by code completion. |
| 708 | */ |
| 709 | CXCompletionChunk_Informative, |
| 710 | /** |
| 711 | * \brief Text that describes the current parameter when code-completion is |
| 712 | * referring to function call, message send, or template specialization. |
| 713 | * |
| 714 | * A "current parameter" chunk occurs when code-completion is providing |
| 715 | * information about a parameter corresponding to the argument at the |
| 716 | * code-completion point. For example, given a function |
| 717 | * |
| 718 | * \code |
| 719 | * int add(int x, int y); |
| 720 | * \endcode |
| 721 | * |
| 722 | * and the source code \c add(, where the code-completion point is after the |
| 723 | * "(", the code-completion string will contain a "current parameter" chunk |
| 724 | * for "int x", indicating that the current argument will initialize that |
| 725 | * parameter. After typing further, to \c add(17, (where the code-completion |
| 726 | * point is after the ","), the code-completion string will contain a |
| 727 | * "current paremeter" chunk to "int y". |
| 728 | */ |
| 729 | CXCompletionChunk_CurrentParameter, |
| 730 | /** |
| 731 | * \brief A left parenthesis ('('), used to initiate a function call or |
| 732 | * signal the beginning of a function parameter list. |
| 733 | */ |
| 734 | CXCompletionChunk_LeftParen, |
| 735 | /** |
| 736 | * \brief A right parenthesis (')'), used to finish a function call or |
| 737 | * signal the end of a function parameter list. |
| 738 | */ |
| 739 | CXCompletionChunk_RightParen, |
| 740 | /** |
| 741 | * \brief A left bracket ('['). |
| 742 | */ |
| 743 | CXCompletionChunk_LeftBracket, |
| 744 | /** |
| 745 | * \brief A right bracket (']'). |
| 746 | */ |
| 747 | CXCompletionChunk_RightBracket, |
| 748 | /** |
| 749 | * \brief A left brace ('{'). |
| 750 | */ |
| 751 | CXCompletionChunk_LeftBrace, |
| 752 | /** |
| 753 | * \brief A right brace ('}'). |
| 754 | */ |
| 755 | CXCompletionChunk_RightBrace, |
| 756 | /** |
| 757 | * \brief A left angle bracket ('<'). |
| 758 | */ |
| 759 | CXCompletionChunk_LeftAngle, |
| 760 | /** |
| 761 | * \brief A right angle bracket ('>'). |
| 762 | */ |
| 763 | CXCompletionChunk_RightAngle, |
| 764 | /** |
| 765 | * \brief A comma separator (','). |
| 766 | */ |
Douglas Gregor | ff5ce6e | 2009-12-18 18:53:37 +0000 | [diff] [blame] | 767 | CXCompletionChunk_Comma, |
| 768 | /** |
| 769 | * \brief Text that specifies the result type of a given result. |
| 770 | * |
| 771 | * This special kind of informative chunk is not meant to be inserted into |
| 772 | * the text buffer. Rather, it is meant to illustrate the type that an |
| 773 | * expression using the given completion string would have. |
| 774 | */ |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 775 | CXCompletionChunk_ResultType, |
| 776 | /** |
| 777 | * \brief A colon (':'). |
| 778 | */ |
| 779 | CXCompletionChunk_Colon, |
| 780 | /** |
| 781 | * \brief A semicolon (';'). |
| 782 | */ |
| 783 | CXCompletionChunk_SemiColon, |
| 784 | /** |
| 785 | * \brief An '=' sign. |
| 786 | */ |
| 787 | CXCompletionChunk_Equal, |
| 788 | /** |
| 789 | * Horizontal space (' '). |
| 790 | */ |
| 791 | CXCompletionChunk_HorizontalSpace, |
| 792 | /** |
| 793 | * Vertical space ('\n'), after which it is generally a good idea to |
| 794 | * perform indentation. |
| 795 | */ |
| 796 | CXCompletionChunk_VerticalSpace |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 797 | }; |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 798 | |
| 799 | /** |
| 800 | * \brief Determine the kind of a particular chunk within a completion string. |
| 801 | * |
| 802 | * \param completion_string the completion string to query. |
| 803 | * |
| 804 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 805 | * |
| 806 | * \returns the kind of the chunk at the index \c chunk_number. |
| 807 | */ |
| 808 | CINDEX_LINKAGE enum CXCompletionChunkKind |
| 809 | clang_getCompletionChunkKind(CXCompletionString completion_string, |
| 810 | unsigned chunk_number); |
| 811 | |
| 812 | /** |
| 813 | * \brief Retrieve the text associated with a particular chunk within a |
| 814 | * completion string. |
| 815 | * |
| 816 | * \param completion_string the completion string to query. |
| 817 | * |
| 818 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 819 | * |
| 820 | * \returns the text associated with the chunk at index \c chunk_number. |
| 821 | */ |
| 822 | CINDEX_LINKAGE const char * |
| 823 | clang_getCompletionChunkText(CXCompletionString completion_string, |
| 824 | unsigned chunk_number); |
| 825 | |
| 826 | /** |
| 827 | * \brief Retrieve the completion string associated with a particular chunk |
| 828 | * within a completion string. |
| 829 | * |
| 830 | * \param completion_string the completion string to query. |
| 831 | * |
| 832 | * \param chunk_number the 0-based index of the chunk in the completion string. |
| 833 | * |
| 834 | * \returns the completion string associated with the chunk at index |
| 835 | * \c chunk_number, or NULL if that chunk is not represented by a completion |
| 836 | * string. |
| 837 | */ |
| 838 | CINDEX_LINKAGE CXCompletionString |
| 839 | clang_getCompletionChunkCompletionString(CXCompletionString completion_string, |
| 840 | unsigned chunk_number); |
| 841 | |
| 842 | /** |
| 843 | * \brief Retrieve the number of chunks in the given code-completion string. |
| 844 | */ |
| 845 | CINDEX_LINKAGE unsigned |
| 846 | clang_getNumCompletionChunks(CXCompletionString completion_string); |
| 847 | |
| 848 | /** |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 849 | * \brief Contains the results of code-completion. |
| 850 | * |
| 851 | * This data structure contains the results of code completion, as |
| 852 | * produced by \c clang_codeComplete. Its contents must be freed by |
| 853 | * \c clang_disposeCodeCompleteResults. |
| 854 | */ |
| 855 | typedef struct { |
| 856 | /** |
| 857 | * \brief The code-completion results. |
| 858 | */ |
| 859 | CXCompletionResult *Results; |
| 860 | |
| 861 | /** |
| 862 | * \brief The number of code-completion results stored in the |
| 863 | * \c Results array. |
| 864 | */ |
| 865 | unsigned NumResults; |
| 866 | } CXCodeCompleteResults; |
| 867 | |
| 868 | /** |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 869 | * \brief Perform code completion at a given location in a source file. |
| 870 | * |
| 871 | * This function performs code completion at a particular file, line, and |
| 872 | * column within source code, providing results that suggest potential |
| 873 | * code snippets based on the context of the completion. The basic model |
| 874 | * for code completion is that Clang will parse a complete source file, |
| 875 | * performing syntax checking up to the location where code-completion has |
| 876 | * been requested. At that point, a special code-completion token is passed |
| 877 | * to the parser, which recognizes this token and determines, based on the |
| 878 | * current location in the C/Objective-C/C++ grammar and the state of |
| 879 | * semantic analysis, what completions to provide. These completions are |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 880 | * returned via a new \c CXCodeCompleteResults structure. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 881 | * |
| 882 | * Code completion itself is meant to be triggered by the client when the |
| 883 | * user types punctuation characters or whitespace, at which point the |
| 884 | * code-completion location will coincide with the cursor. For example, if \c p |
| 885 | * is a pointer, code-completion might be triggered after the "-" and then |
| 886 | * after the ">" in \c p->. When the code-completion location is afer the ">", |
| 887 | * the completion results will provide, e.g., the members of the struct that |
| 888 | * "p" points to. The client is responsible for placing the cursor at the |
| 889 | * beginning of the token currently being typed, then filtering the results |
| 890 | * based on the contents of the token. For example, when code-completing for |
| 891 | * the expression \c p->get, the client should provide the location just after |
| 892 | * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the |
| 893 | * client can filter the results based on the current token text ("get"), only |
| 894 | * showing those results that start with "get". The intent of this interface |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 895 | * is to separate the relatively high-latency acquisition of code-completion |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 896 | * results from the filtering of results on a per-character basis, which must |
| 897 | * have a lower latency. |
| 898 | * |
| 899 | * \param CIdx the \c CXIndex instance that will be used to perform code |
| 900 | * completion. |
| 901 | * |
Daniel Dunbar | 8506dde | 2009-12-03 01:54:28 +0000 | [diff] [blame] | 902 | * \param source_filename the name of the source file that should be parsed to |
| 903 | * perform code-completion. This source file must be the same as or include the |
| 904 | * filename described by \p complete_filename, or no code-completion results |
| 905 | * will be produced. NOTE: One can also specify NULL for this argument if the |
| 906 | * source file is included in command_line_args. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 907 | * |
| 908 | * \param num_command_line_args the number of command-line arguments stored in |
| 909 | * \p command_line_args. |
| 910 | * |
| 911 | * \param command_line_args the command-line arguments to pass to the Clang |
| 912 | * compiler to build the given source file. This should include all of the |
| 913 | * necessary include paths, language-dialect switches, precompiled header |
| 914 | * includes, etc., but should not include any information specific to |
| 915 | * code completion. |
| 916 | * |
Douglas Gregor | 735df88 | 2009-12-02 09:21:34 +0000 | [diff] [blame] | 917 | * \param num_unsaved_files the number of unsaved file entries in \p |
| 918 | * unsaved_files. |
| 919 | * |
| 920 | * \param unsaved_files the files that have not yet been saved to disk |
| 921 | * but may be required for code completion, including the contents of |
| 922 | * those files. |
| 923 | * |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 924 | * \param complete_filename the name of the source file where code completion |
| 925 | * should be performed. In many cases, this name will be the same as the |
| 926 | * source filename. However, the completion filename may also be a file |
| 927 | * included by the source file, which is required when producing |
| 928 | * code-completion results for a header. |
| 929 | * |
| 930 | * \param complete_line the line at which code-completion should occur. |
| 931 | * |
| 932 | * \param complete_column the column at which code-completion should occur. |
| 933 | * Note that the column should point just after the syntactic construct that |
| 934 | * initiated code completion, and not in the middle of a lexical token. |
| 935 | * |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 936 | * \returns if successful, a new CXCodeCompleteResults structure |
| 937 | * containing code-completion results, which should eventually be |
| 938 | * freed with \c clang_disposeCodeCompleteResults(). If code |
| 939 | * completion fails, returns NULL. |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 940 | */ |
Douglas Gregor | ec6762c | 2009-12-18 16:20:58 +0000 | [diff] [blame] | 941 | CINDEX_LINKAGE |
| 942 | CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, |
| 943 | const char *source_filename, |
| 944 | int num_command_line_args, |
| 945 | const char **command_line_args, |
| 946 | unsigned num_unsaved_files, |
| 947 | struct CXUnsavedFile *unsaved_files, |
| 948 | const char *complete_filename, |
| 949 | unsigned complete_line, |
| 950 | unsigned complete_column); |
| 951 | |
| 952 | /** |
| 953 | * \brief Free the given set of code-completion results. |
| 954 | */ |
| 955 | CINDEX_LINKAGE |
| 956 | void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); |
Douglas Gregor | 0c8296d | 2009-11-07 00:00:49 +0000 | [diff] [blame] | 957 | |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 958 | #ifdef __cplusplus |
| 959 | } |
| 960 | #endif |
| 961 | #endif |
| 962 | |