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 19 #include <time.h> 20 21 #include "clang-c/Platform.h" 22 #include "clang-c/CXErrorCode.h" 23 #include "clang-c/CXString.h" 24 #include "clang-c/BuildSystem.h" 25 26 /** 27 * \brief The version constants for the libclang API. 28 * CINDEX_VERSION_MINOR should increase when there are API additions. 29 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes. 30 * 31 * The policy about the libclang API was always to keep it source and ABI 32 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. 33 */ 34 #define CINDEX_VERSION_MAJOR 0 35 #define CINDEX_VERSION_MINOR 27 36 37 #define CINDEX_VERSION_ENCODE(major, minor) ( \ 38 ((major) * 10000) \ 39 + ((minor) * 1)) 40 41 #define CINDEX_VERSION CINDEX_VERSION_ENCODE( \ 42 CINDEX_VERSION_MAJOR, \ 43 CINDEX_VERSION_MINOR ) 44 45 #define CINDEX_VERSION_STRINGIZE_(major, minor) \ 46 #major"."#minor 47 #define CINDEX_VERSION_STRINGIZE(major, minor) \ 48 CINDEX_VERSION_STRINGIZE_(major, minor) 49 50 #define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \ 51 CINDEX_VERSION_MAJOR, \ 52 CINDEX_VERSION_MINOR) 53 54 #ifdef __cplusplus 55 extern "C" { 56 #endif 57 58 /** \defgroup CINDEX libclang: C Interface to Clang 59 * 60 * The C Interface to Clang provides a relatively small API that exposes 61 * facilities for parsing source code into an abstract syntax tree (AST), 62 * loading already-parsed ASTs, traversing the AST, associating 63 * physical source locations with elements within the AST, and other 64 * facilities that support Clang-based development tools. 65 * 66 * This C interface to Clang will never provide all of the information 67 * representation stored in Clang's C++ AST, nor should it: the intent is to 68 * maintain an API that is relatively stable from one release to the next, 69 * providing only the basic functionality needed to support development tools. 70 * 71 * To avoid namespace pollution, data types are prefixed with "CX" and 72 * functions are prefixed with "clang_". 73 * 74 * @{ 75 */ 76 77 /** 78 * \brief An "index" that consists of a set of translation units that would 79 * typically be linked together into an executable or library. 80 */ 81 typedef void *CXIndex; 82 83 /** 84 * \brief A single translation unit, which resides in an index. 85 */ 86 typedef struct CXTranslationUnitImpl *CXTranslationUnit; 87 88 /** 89 * \brief Opaque pointer representing client data that will be passed through 90 * to various callbacks and visitors. 91 */ 92 typedef void *CXClientData; 93 94 /** 95 * \brief Provides the contents of a file that has not yet been saved to disk. 96 * 97 * Each CXUnsavedFile instance provides the name of a file on the 98 * system along with the current contents of that file that have not 99 * yet been saved to disk. 100 */ 101 struct CXUnsavedFile { 102 /** 103 * \brief The file whose contents have not yet been saved. 104 * 105 * This file must already exist in the file system. 106 */ 107 const char *Filename; 108 109 /** 110 * \brief A buffer containing the unsaved contents of this file. 111 */ 112 const char *Contents; 113 114 /** 115 * \brief The length of the unsaved contents of this buffer. 116 */ 117 unsigned long Length; 118 }; 119 120 /** 121 * \brief Describes the availability of a particular entity, which indicates 122 * whether the use of this entity will result in a warning or error due to 123 * it being deprecated or unavailable. 124 */ 125 enum CXAvailabilityKind { 126 /** 127 * \brief The entity is available. 128 */ 129 CXAvailability_Available, 130 /** 131 * \brief The entity is available, but has been deprecated (and its use is 132 * not recommended). 133 */ 134 CXAvailability_Deprecated, 135 /** 136 * \brief The entity is not available; any use of it will be an error. 137 */ 138 CXAvailability_NotAvailable, 139 /** 140 * \brief The entity is available, but not accessible; any use of it will be 141 * an error. 142 */ 143 CXAvailability_NotAccessible 144 }; 145 146 /** 147 * \brief Describes a version number of the form major.minor.subminor. 148 */ 149 typedef struct CXVersion { 150 /** 151 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative 152 * value indicates that there is no version number at all. 153 */ 154 int Major; 155 /** 156 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value 157 * will be negative if no minor version number was provided, e.g., for 158 * version '10'. 159 */ 160 int Minor; 161 /** 162 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value 163 * will be negative if no minor or subminor version number was provided, 164 * e.g., in version '10' or '10.7'. 165 */ 166 int Subminor; 167 } CXVersion; 168 169 /** 170 * \brief Provides a shared context for creating translation units. 171 * 172 * It provides two options: 173 * 174 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 175 * declarations (when loading any new translation units). A "local" declaration 176 * is one that belongs in the translation unit itself and not in a precompiled 177 * header that was used by the translation unit. If zero, all declarations 178 * will be enumerated. 179 * 180 * Here is an example: 181 * 182 * \code 183 * // excludeDeclsFromPCH = 1, displayDiagnostics=1 184 * Idx = clang_createIndex(1, 1); 185 * 186 * // IndexTest.pch was produced with the following command: 187 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 188 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 189 * 190 * // This will load all the symbols from 'IndexTest.pch' 191 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 192 * TranslationUnitVisitor, 0); 193 * clang_disposeTranslationUnit(TU); 194 * 195 * // This will load all the symbols from 'IndexTest.c', excluding symbols 196 * // from 'IndexTest.pch'. 197 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 198 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 199 * 0, 0); 200 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 201 * TranslationUnitVisitor, 0); 202 * clang_disposeTranslationUnit(TU); 203 * \endcode 204 * 205 * This process of creating the 'pch', loading it separately, and using it (via 206 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 207 * (which gives the indexer the same performance benefit as the compiler). 208 */ 209 CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, 210 int displayDiagnostics); 211 212 /** 213 * \brief Destroy the given index. 214 * 215 * The index must not be destroyed until all of the translation units created 216 * within that index have been destroyed. 217 */ 218 CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); 219 220 typedef enum { 221 /** 222 * \brief Used to indicate that no special CXIndex options are needed. 223 */ 224 CXGlobalOpt_None = 0x0, 225 226 /** 227 * \brief Used to indicate that threads that libclang creates for indexing 228 * purposes should use background priority. 229 * 230 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit, 231 * #clang_parseTranslationUnit, #clang_saveTranslationUnit. 232 */ 233 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1, 234 235 /** 236 * \brief Used to indicate that threads that libclang creates for editing 237 * purposes should use background priority. 238 * 239 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt, 240 * #clang_annotateTokens 241 */ 242 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2, 243 244 /** 245 * \brief Used to indicate that all threads that libclang creates should use 246 * background priority. 247 */ 248 CXGlobalOpt_ThreadBackgroundPriorityForAll = 249 CXGlobalOpt_ThreadBackgroundPriorityForIndexing | 250 CXGlobalOpt_ThreadBackgroundPriorityForEditing 251 252 } CXGlobalOptFlags; 253 254 /** 255 * \brief Sets general options associated with a CXIndex. 256 * 257 * For example: 258 * \code 259 * CXIndex idx = ...; 260 * clang_CXIndex_setGlobalOptions(idx, 261 * clang_CXIndex_getGlobalOptions(idx) | 262 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing); 263 * \endcode 264 * 265 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags. 266 */ 267 CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options); 268 269 /** 270 * \brief Gets the general options associated with a CXIndex. 271 * 272 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that 273 * are associated with the given CXIndex object. 274 */ 275 CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex); 276 277 /** 278 * \defgroup CINDEX_FILES File manipulation routines 279 * 280 * @{ 281 */ 282 283 /** 284 * \brief A particular source file that is part of a translation unit. 285 */ 286 typedef void *CXFile; 287 288 289 /** 290 * \brief Retrieve the complete file and path name of the given file. 291 */ 292 CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); 293 294 /** 295 * \brief Retrieve the last modification time of the given file. 296 */ 297 CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); 298 299 /** 300 * \brief Uniquely identifies a CXFile, that refers to the same underlying file, 301 * across an indexing session. 302 */ 303 typedef struct { 304 unsigned long long data[3]; 305 } CXFileUniqueID; 306 307 /** 308 * \brief Retrieve the unique ID for the given \c file. 309 * 310 * \param file the file to get the ID for. 311 * \param outID stores the returned CXFileUniqueID. 312 * \returns If there was a failure getting the unique ID, returns non-zero, 313 * otherwise returns 0. 314 */ 315 CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID); 316 317 /** 318 * \brief Determine whether the given header is guarded against 319 * multiple inclusions, either with the conventional 320 * \#ifndef/\#define/\#endif macro guards or with \#pragma once. 321 */ 322 CINDEX_LINKAGE unsigned 323 clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file); 324 325 /** 326 * \brief Retrieve a file handle within the given translation unit. 327 * 328 * \param tu the translation unit 329 * 330 * \param file_name the name of the file. 331 * 332 * \returns the file handle for the named file in the translation unit \p tu, 333 * or a NULL file handle if the file was not a part of this translation unit. 334 */ 335 CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, 336 const char *file_name); 337 338 /** 339 * @} 340 */ 341 342 /** 343 * \defgroup CINDEX_LOCATIONS Physical source locations 344 * 345 * Clang represents physical source locations in its abstract syntax tree in 346 * great detail, with file, line, and column information for the majority of 347 * the tokens parsed in the source code. These data types and functions are 348 * used to represent source location information, either for a particular 349 * point in the program or for a range of points in the program, and extract 350 * specific location information from those data types. 351 * 352 * @{ 353 */ 354 355 /** 356 * \brief Identifies a specific source location within a translation 357 * unit. 358 * 359 * Use clang_getExpansionLocation() or clang_getSpellingLocation() 360 * to map a source location to a particular file, line, and column. 361 */ 362 typedef struct { 363 const void *ptr_data[2]; 364 unsigned int_data; 365 } CXSourceLocation; 366 367 /** 368 * \brief Identifies a half-open character range in the source code. 369 * 370 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 371 * starting and end locations from a source range, respectively. 372 */ 373 typedef struct { 374 const void *ptr_data[2]; 375 unsigned begin_int_data; 376 unsigned end_int_data; 377 } CXSourceRange; 378 379 /** 380 * \brief Retrieve a NULL (invalid) source location. 381 */ 382 CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void); 383 384 /** 385 * \brief Determine whether two source locations, which must refer into 386 * the same translation unit, refer to exactly the same point in the source 387 * code. 388 * 389 * \returns non-zero if the source locations refer to the same location, zero 390 * if they refer to different locations. 391 */ 392 CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, 393 CXSourceLocation loc2); 394 395 /** 396 * \brief Retrieves the source location associated with a given file/line/column 397 * in a particular translation unit. 398 */ 399 CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, 400 CXFile file, 401 unsigned line, 402 unsigned column); 403 /** 404 * \brief Retrieves the source location associated with a given character offset 405 * in a particular translation unit. 406 */ 407 CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, 408 CXFile file, 409 unsigned offset); 410 411 /** 412 * \brief Returns non-zero if the given source location is in a system header. 413 */ 414 CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location); 415 416 /** 417 * \brief Returns non-zero if the given source location is in the main file of 418 * the corresponding translation unit. 419 */ 420 CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location); 421 422 /** 423 * \brief Retrieve a NULL (invalid) source range. 424 */ 425 CINDEX_LINKAGE CXSourceRange clang_getNullRange(void); 426 427 /** 428 * \brief Retrieve a source range given the beginning and ending source 429 * locations. 430 */ 431 CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, 432 CXSourceLocation end); 433 434 /** 435 * \brief Determine whether two ranges are equivalent. 436 * 437 * \returns non-zero if the ranges are the same, zero if they differ. 438 */ 439 CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1, 440 CXSourceRange range2); 441 442 /** 443 * \brief Returns non-zero if \p range is null. 444 */ 445 CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range); 446 447 /** 448 * \brief Retrieve the file, line, column, and offset represented by 449 * the given source location. 450 * 451 * If the location refers into a macro expansion, retrieves the 452 * location of the macro expansion. 453 * 454 * \param location the location within a source file that will be decomposed 455 * into its parts. 456 * 457 * \param file [out] if non-NULL, will be set to the file to which the given 458 * source location points. 459 * 460 * \param line [out] if non-NULL, will be set to the line to which the given 461 * source location points. 462 * 463 * \param column [out] if non-NULL, will be set to the column to which the given 464 * source location points. 465 * 466 * \param offset [out] if non-NULL, will be set to the offset into the 467 * buffer to which the given source location points. 468 */ 469 CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location, 470 CXFile *file, 471 unsigned *line, 472 unsigned *column, 473 unsigned *offset); 474 475 /** 476 * \brief Retrieve the file, line, column, and offset represented by 477 * the given source location, as specified in a # line directive. 478 * 479 * Example: given the following source code in a file somefile.c 480 * 481 * \code 482 * #123 "dummy.c" 1 483 * 484 * static int func(void) 485 * { 486 * return 0; 487 * } 488 * \endcode 489 * 490 * the location information returned by this function would be 491 * 492 * File: dummy.c Line: 124 Column: 12 493 * 494 * whereas clang_getExpansionLocation would have returned 495 * 496 * File: somefile.c Line: 3 Column: 12 497 * 498 * \param location the location within a source file that will be decomposed 499 * into its parts. 500 * 501 * \param filename [out] if non-NULL, will be set to the filename of the 502 * source location. Note that filenames returned will be for "virtual" files, 503 * which don't necessarily exist on the machine running clang - e.g. when 504 * parsing preprocessed output obtained from a different environment. If 505 * a non-NULL value is passed in, remember to dispose of the returned value 506 * using \c clang_disposeString() once you've finished with it. For an invalid 507 * source location, an empty string is returned. 508 * 509 * \param line [out] if non-NULL, will be set to the line number of the 510 * source location. For an invalid source location, zero is returned. 511 * 512 * \param column [out] if non-NULL, will be set to the column number of the 513 * source location. For an invalid source location, zero is returned. 514 */ 515 CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location, 516 CXString *filename, 517 unsigned *line, 518 unsigned *column); 519 520 /** 521 * \brief Legacy API to retrieve the file, line, column, and offset represented 522 * by the given source location. 523 * 524 * This interface has been replaced by the newer interface 525 * #clang_getExpansionLocation(). See that interface's documentation for 526 * details. 527 */ 528 CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, 529 CXFile *file, 530 unsigned *line, 531 unsigned *column, 532 unsigned *offset); 533 534 /** 535 * \brief Retrieve the file, line, column, and offset represented by 536 * the given source location. 537 * 538 * If the location refers into a macro instantiation, return where the 539 * location was originally spelled in the source file. 540 * 541 * \param location the location within a source file that will be decomposed 542 * into its parts. 543 * 544 * \param file [out] if non-NULL, will be set to the file to which the given 545 * source location points. 546 * 547 * \param line [out] if non-NULL, will be set to the line to which the given 548 * source location points. 549 * 550 * \param column [out] if non-NULL, will be set to the column to which the given 551 * source location points. 552 * 553 * \param offset [out] if non-NULL, will be set to the offset into the 554 * buffer to which the given source location points. 555 */ 556 CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location, 557 CXFile *file, 558 unsigned *line, 559 unsigned *column, 560 unsigned *offset); 561 562 /** 563 * \brief Retrieve the file, line, column, and offset represented by 564 * the given source location. 565 * 566 * If the location refers into a macro expansion, return where the macro was 567 * expanded or where the macro argument was written, if the location points at 568 * a macro argument. 569 * 570 * \param location the location within a source file that will be decomposed 571 * into its parts. 572 * 573 * \param file [out] if non-NULL, will be set to the file to which the given 574 * source location points. 575 * 576 * \param line [out] if non-NULL, will be set to the line to which the given 577 * source location points. 578 * 579 * \param column [out] if non-NULL, will be set to the column to which the given 580 * source location points. 581 * 582 * \param offset [out] if non-NULL, will be set to the offset into the 583 * buffer to which the given source location points. 584 */ 585 CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location, 586 CXFile *file, 587 unsigned *line, 588 unsigned *column, 589 unsigned *offset); 590 591 /** 592 * \brief Retrieve a source location representing the first character within a 593 * source range. 594 */ 595 CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); 596 597 /** 598 * \brief Retrieve a source location representing the last character within a 599 * source range. 600 */ 601 CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); 602 603 /** 604 * \brief Identifies an array of ranges. 605 */ 606 typedef struct { 607 /** \brief The number of ranges in the \c ranges array. */ 608 unsigned count; 609 /** 610 * \brief An array of \c CXSourceRanges. 611 */ 612 CXSourceRange *ranges; 613 } CXSourceRangeList; 614 615 /** 616 * \brief Retrieve all ranges that were skipped by the preprocessor. 617 * 618 * The preprocessor will skip lines when they are surrounded by an 619 * if/ifdef/ifndef directive whose condition does not evaluate to true. 620 */ 621 CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu, 622 CXFile file); 623 624 /** 625 * \brief Destroy the given \c CXSourceRangeList. 626 */ 627 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges); 628 629 /** 630 * @} 631 */ 632 633 /** 634 * \defgroup CINDEX_DIAG Diagnostic reporting 635 * 636 * @{ 637 */ 638 639 /** 640 * \brief Describes the severity of a particular diagnostic. 641 */ 642 enum CXDiagnosticSeverity { 643 /** 644 * \brief A diagnostic that has been suppressed, e.g., by a command-line 645 * option. 646 */ 647 CXDiagnostic_Ignored = 0, 648 649 /** 650 * \brief This diagnostic is a note that should be attached to the 651 * previous (non-note) diagnostic. 652 */ 653 CXDiagnostic_Note = 1, 654 655 /** 656 * \brief This diagnostic indicates suspicious code that may not be 657 * wrong. 658 */ 659 CXDiagnostic_Warning = 2, 660 661 /** 662 * \brief This diagnostic indicates that the code is ill-formed. 663 */ 664 CXDiagnostic_Error = 3, 665 666 /** 667 * \brief This diagnostic indicates that the code is ill-formed such 668 * that future parser recovery is unlikely to produce useful 669 * results. 670 */ 671 CXDiagnostic_Fatal = 4 672 }; 673 674 /** 675 * \brief A single diagnostic, containing the diagnostic's severity, 676 * location, text, source ranges, and fix-it hints. 677 */ 678 typedef void *CXDiagnostic; 679 680 /** 681 * \brief A group of CXDiagnostics. 682 */ 683 typedef void *CXDiagnosticSet; 684 685 /** 686 * \brief Determine the number of diagnostics in a CXDiagnosticSet. 687 */ 688 CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags); 689 690 /** 691 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet. 692 * 693 * \param Diags the CXDiagnosticSet to query. 694 * \param Index the zero-based diagnostic number to retrieve. 695 * 696 * \returns the requested diagnostic. This diagnostic must be freed 697 * via a call to \c clang_disposeDiagnostic(). 698 */ 699 CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, 700 unsigned Index); 701 702 703 /** 704 * \brief Describes the kind of error that occurred (if any) in a call to 705 * \c clang_loadDiagnostics. 706 */ 707 enum CXLoadDiag_Error { 708 /** 709 * \brief Indicates that no error occurred. 710 */ 711 CXLoadDiag_None = 0, 712 713 /** 714 * \brief Indicates that an unknown error occurred while attempting to 715 * deserialize diagnostics. 716 */ 717 CXLoadDiag_Unknown = 1, 718 719 /** 720 * \brief Indicates that the file containing the serialized diagnostics 721 * could not be opened. 722 */ 723 CXLoadDiag_CannotLoad = 2, 724 725 /** 726 * \brief Indicates that the serialized diagnostics file is invalid or 727 * corrupt. 728 */ 729 CXLoadDiag_InvalidFile = 3 730 }; 731 732 /** 733 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode 734 * file. 735 * 736 * \param file The name of the file to deserialize. 737 * \param error A pointer to a enum value recording if there was a problem 738 * deserializing the diagnostics. 739 * \param errorString A pointer to a CXString for recording the error string 740 * if the file was not successfully loaded. 741 * 742 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These 743 * diagnostics should be released using clang_disposeDiagnosticSet(). 744 */ 745 CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file, 746 enum CXLoadDiag_Error *error, 747 CXString *errorString); 748 749 /** 750 * \brief Release a CXDiagnosticSet and all of its contained diagnostics. 751 */ 752 CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags); 753 754 /** 755 * \brief Retrieve the child diagnostics of a CXDiagnostic. 756 * 757 * This CXDiagnosticSet does not need to be released by 758 * clang_disposeDiagnosticSet. 759 */ 760 CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D); 761 762 /** 763 * \brief Determine the number of diagnostics produced for the given 764 * translation unit. 765 */ 766 CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); 767 768 /** 769 * \brief Retrieve a diagnostic associated with the given translation unit. 770 * 771 * \param Unit the translation unit to query. 772 * \param Index the zero-based diagnostic number to retrieve. 773 * 774 * \returns the requested diagnostic. This diagnostic must be freed 775 * via a call to \c clang_disposeDiagnostic(). 776 */ 777 CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, 778 unsigned Index); 779 780 /** 781 * \brief Retrieve the complete set of diagnostics associated with a 782 * translation unit. 783 * 784 * \param Unit the translation unit to query. 785 */ 786 CINDEX_LINKAGE CXDiagnosticSet 787 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit); 788 789 /** 790 * \brief Destroy a diagnostic. 791 */ 792 CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); 793 794 /** 795 * \brief Options to control the display of diagnostics. 796 * 797 * The values in this enum are meant to be combined to customize the 798 * behavior of \c clang_formatDiagnostic(). 799 */ 800 enum CXDiagnosticDisplayOptions { 801 /** 802 * \brief Display the source-location information where the 803 * diagnostic was located. 804 * 805 * When set, diagnostics will be prefixed by the file, line, and 806 * (optionally) column to which the diagnostic refers. For example, 807 * 808 * \code 809 * test.c:28: warning: extra tokens at end of #endif directive 810 * \endcode 811 * 812 * This option corresponds to the clang flag \c -fshow-source-location. 813 */ 814 CXDiagnostic_DisplaySourceLocation = 0x01, 815 816 /** 817 * \brief If displaying the source-location information of the 818 * diagnostic, also include the column number. 819 * 820 * This option corresponds to the clang flag \c -fshow-column. 821 */ 822 CXDiagnostic_DisplayColumn = 0x02, 823 824 /** 825 * \brief If displaying the source-location information of the 826 * diagnostic, also include information about source ranges in a 827 * machine-parsable format. 828 * 829 * This option corresponds to the clang flag 830 * \c -fdiagnostics-print-source-range-info. 831 */ 832 CXDiagnostic_DisplaySourceRanges = 0x04, 833 834 /** 835 * \brief Display the option name associated with this diagnostic, if any. 836 * 837 * The option name displayed (e.g., -Wconversion) will be placed in brackets 838 * after the diagnostic text. This option corresponds to the clang flag 839 * \c -fdiagnostics-show-option. 840 */ 841 CXDiagnostic_DisplayOption = 0x08, 842 843 /** 844 * \brief Display the category number associated with this diagnostic, if any. 845 * 846 * The category number is displayed within brackets after the diagnostic text. 847 * This option corresponds to the clang flag 848 * \c -fdiagnostics-show-category=id. 849 */ 850 CXDiagnostic_DisplayCategoryId = 0x10, 851 852 /** 853 * \brief Display the category name associated with this diagnostic, if any. 854 * 855 * The category name is displayed within brackets after the diagnostic text. 856 * This option corresponds to the clang flag 857 * \c -fdiagnostics-show-category=name. 858 */ 859 CXDiagnostic_DisplayCategoryName = 0x20 860 }; 861 862 /** 863 * \brief Format the given diagnostic in a manner that is suitable for display. 864 * 865 * This routine will format the given diagnostic to a string, rendering 866 * the diagnostic according to the various options given. The 867 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of 868 * options that most closely mimics the behavior of the clang compiler. 869 * 870 * \param Diagnostic The diagnostic to print. 871 * 872 * \param Options A set of options that control the diagnostic display, 873 * created by combining \c CXDiagnosticDisplayOptions values. 874 * 875 * \returns A new string containing for formatted diagnostic. 876 */ 877 CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, 878 unsigned Options); 879 880 /** 881 * \brief Retrieve the set of display options most similar to the 882 * default behavior of the clang compiler. 883 * 884 * \returns A set of display options suitable for use with \c 885 * clang_formatDiagnostic(). 886 */ 887 CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); 888 889 /** 890 * \brief Determine the severity of the given diagnostic. 891 */ 892 CINDEX_LINKAGE enum CXDiagnosticSeverity 893 clang_getDiagnosticSeverity(CXDiagnostic); 894 895 /** 896 * \brief Retrieve the source location of the given diagnostic. 897 * 898 * This location is where Clang would print the caret ('^') when 899 * displaying the diagnostic on the command line. 900 */ 901 CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); 902 903 /** 904 * \brief Retrieve the text of the given diagnostic. 905 */ 906 CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); 907 908 /** 909 * \brief Retrieve the name of the command-line option that enabled this 910 * diagnostic. 911 * 912 * \param Diag The diagnostic to be queried. 913 * 914 * \param Disable If non-NULL, will be set to the option that disables this 915 * diagnostic (if any). 916 * 917 * \returns A string that contains the command-line option used to enable this 918 * warning, such as "-Wconversion" or "-pedantic". 919 */ 920 CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag, 921 CXString *Disable); 922 923 /** 924 * \brief Retrieve the category number for this diagnostic. 925 * 926 * Diagnostics can be categorized into groups along with other, related 927 * diagnostics (e.g., diagnostics under the same warning flag). This routine 928 * retrieves the category number for the given diagnostic. 929 * 930 * \returns The number of the category that contains this diagnostic, or zero 931 * if this diagnostic is uncategorized. 932 */ 933 CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic); 934 935 /** 936 * \brief Retrieve the name of a particular diagnostic category. This 937 * is now deprecated. Use clang_getDiagnosticCategoryText() 938 * instead. 939 * 940 * \param Category A diagnostic category number, as returned by 941 * \c clang_getDiagnosticCategory(). 942 * 943 * \returns The name of the given diagnostic category. 944 */ 945 CINDEX_DEPRECATED CINDEX_LINKAGE 946 CXString clang_getDiagnosticCategoryName(unsigned Category); 947 948 /** 949 * \brief Retrieve the diagnostic category text for a given diagnostic. 950 * 951 * \returns The text of the given diagnostic category. 952 */ 953 CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic); 954 955 /** 956 * \brief Determine the number of source ranges associated with the given 957 * diagnostic. 958 */ 959 CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); 960 961 /** 962 * \brief Retrieve a source range associated with the diagnostic. 963 * 964 * A diagnostic's source ranges highlight important elements in the source 965 * code. On the command line, Clang displays source ranges by 966 * underlining them with '~' characters. 967 * 968 * \param Diagnostic the diagnostic whose range is being extracted. 969 * 970 * \param Range the zero-based index specifying which range to 971 * 972 * \returns the requested source range. 973 */ 974 CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, 975 unsigned Range); 976 977 /** 978 * \brief Determine the number of fix-it hints associated with the 979 * given diagnostic. 980 */ 981 CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); 982 983 /** 984 * \brief Retrieve the replacement information for a given fix-it. 985 * 986 * Fix-its are described in terms of a source range whose contents 987 * should be replaced by a string. This approach generalizes over 988 * three kinds of operations: removal of source code (the range covers 989 * the code to be removed and the replacement string is empty), 990 * replacement of source code (the range covers the code to be 991 * replaced and the replacement string provides the new code), and 992 * insertion (both the start and end of the range point at the 993 * insertion location, and the replacement string provides the text to 994 * insert). 995 * 996 * \param Diagnostic The diagnostic whose fix-its are being queried. 997 * 998 * \param FixIt The zero-based index of the fix-it. 999 * 1000 * \param ReplacementRange The source range whose contents will be 1001 * replaced with the returned replacement string. Note that source 1002 * ranges are half-open ranges [a, b), so the source code should be 1003 * replaced from a and up to (but not including) b. 1004 * 1005 * \returns A string containing text that should be replace the source 1006 * code indicated by the \c ReplacementRange. 1007 */ 1008 CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, 1009 unsigned FixIt, 1010 CXSourceRange *ReplacementRange); 1011 1012 /** 1013 * @} 1014 */ 1015 1016 /** 1017 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation 1018 * 1019 * The routines in this group provide the ability to create and destroy 1020 * translation units from files, either by parsing the contents of the files or 1021 * by reading in a serialized representation of a translation unit. 1022 * 1023 * @{ 1024 */ 1025 1026 /** 1027 * \brief Get the original translation unit source file name. 1028 */ 1029 CINDEX_LINKAGE CXString 1030 clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 1031 1032 /** 1033 * \brief Return the CXTranslationUnit for a given source file and the provided 1034 * command line arguments one would pass to the compiler. 1035 * 1036 * Note: The 'source_filename' argument is optional. If the caller provides a 1037 * NULL pointer, the name of the source file is expected to reside in the 1038 * specified command line arguments. 1039 * 1040 * Note: When encountered in 'clang_command_line_args', the following options 1041 * are ignored: 1042 * 1043 * '-c' 1044 * '-emit-ast' 1045 * '-fsyntax-only' 1046 * '-o \<output file>' (both '-o' and '\<output file>' are ignored) 1047 * 1048 * \param CIdx The index object with which the translation unit will be 1049 * associated. 1050 * 1051 * \param source_filename The name of the source file to load, or NULL if the 1052 * source file is included in \p clang_command_line_args. 1053 * 1054 * \param num_clang_command_line_args The number of command-line arguments in 1055 * \p clang_command_line_args. 1056 * 1057 * \param clang_command_line_args The command-line arguments that would be 1058 * passed to the \c clang executable if it were being invoked out-of-process. 1059 * These command-line options will be parsed and will affect how the translation 1060 * unit is parsed. Note that the following options are ignored: '-c', 1061 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'. 1062 * 1063 * \param num_unsaved_files the number of unsaved file entries in \p 1064 * unsaved_files. 1065 * 1066 * \param unsaved_files the files that have not yet been saved to disk 1067 * but may be required for code completion, including the contents of 1068 * those files. The contents and name of these files (as specified by 1069 * CXUnsavedFile) are copied when necessary, so the client only needs to 1070 * guarantee their validity until the call to this function returns. 1071 */ 1072 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( 1073 CXIndex CIdx, 1074 const char *source_filename, 1075 int num_clang_command_line_args, 1076 const char * const *clang_command_line_args, 1077 unsigned num_unsaved_files, 1078 struct CXUnsavedFile *unsaved_files); 1079 1080 /** 1081 * \brief Same as \c clang_createTranslationUnit2, but returns 1082 * the \c CXTranslationUnit instead of an error code. In case of an error this 1083 * routine returns a \c NULL \c CXTranslationUnit, without further detailed 1084 * error codes. 1085 */ 1086 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit( 1087 CXIndex CIdx, 1088 const char *ast_filename); 1089 1090 /** 1091 * \brief Create a translation unit from an AST file (\c -emit-ast). 1092 * 1093 * \param[out] out_TU A non-NULL pointer to store the created 1094 * \c CXTranslationUnit. 1095 * 1096 * \returns Zero on success, otherwise returns an error code. 1097 */ 1098 CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2( 1099 CXIndex CIdx, 1100 const char *ast_filename, 1101 CXTranslationUnit *out_TU); 1102 1103 /** 1104 * \brief Flags that control the creation of translation units. 1105 * 1106 * The enumerators in this enumeration type are meant to be bitwise 1107 * ORed together to specify which options should be used when 1108 * constructing the translation unit. 1109 */ 1110 enum CXTranslationUnit_Flags { 1111 /** 1112 * \brief Used to indicate that no special translation-unit options are 1113 * needed. 1114 */ 1115 CXTranslationUnit_None = 0x0, 1116 1117 /** 1118 * \brief Used to indicate that the parser should construct a "detailed" 1119 * preprocessing record, including all macro definitions and instantiations. 1120 * 1121 * Constructing a detailed preprocessing record requires more memory 1122 * and time to parse, since the information contained in the record 1123 * is usually not retained. However, it can be useful for 1124 * applications that require more detailed information about the 1125 * behavior of the preprocessor. 1126 */ 1127 CXTranslationUnit_DetailedPreprocessingRecord = 0x01, 1128 1129 /** 1130 * \brief Used to indicate that the translation unit is incomplete. 1131 * 1132 * When a translation unit is considered "incomplete", semantic 1133 * analysis that is typically performed at the end of the 1134 * translation unit will be suppressed. For example, this suppresses 1135 * the completion of tentative declarations in C and of 1136 * instantiation of implicitly-instantiation function templates in 1137 * C++. This option is typically used when parsing a header with the 1138 * intent of producing a precompiled header. 1139 */ 1140 CXTranslationUnit_Incomplete = 0x02, 1141 1142 /** 1143 * \brief Used to indicate that the translation unit should be built with an 1144 * implicit precompiled header for the preamble. 1145 * 1146 * An implicit precompiled header is used as an optimization when a 1147 * particular translation unit is likely to be reparsed many times 1148 * when the sources aren't changing that often. In this case, an 1149 * implicit precompiled header will be built containing all of the 1150 * initial includes at the top of the main file (what we refer to as 1151 * the "preamble" of the file). In subsequent parses, if the 1152 * preamble or the files in it have not changed, \c 1153 * clang_reparseTranslationUnit() will re-use the implicit 1154 * precompiled header to improve parsing performance. 1155 */ 1156 CXTranslationUnit_PrecompiledPreamble = 0x04, 1157 1158 /** 1159 * \brief Used to indicate that the translation unit should cache some 1160 * code-completion results with each reparse of the source file. 1161 * 1162 * Caching of code-completion results is a performance optimization that 1163 * introduces some overhead to reparsing but improves the performance of 1164 * code-completion operations. 1165 */ 1166 CXTranslationUnit_CacheCompletionResults = 0x08, 1167 1168 /** 1169 * \brief Used to indicate that the translation unit will be serialized with 1170 * \c clang_saveTranslationUnit. 1171 * 1172 * This option is typically used when parsing a header with the intent of 1173 * producing a precompiled header. 1174 */ 1175 CXTranslationUnit_ForSerialization = 0x10, 1176 1177 /** 1178 * \brief DEPRECATED: Enabled chained precompiled preambles in C++. 1179 * 1180 * Note: this is a *temporary* option that is available only while 1181 * we are testing C++ precompiled preamble support. It is deprecated. 1182 */ 1183 CXTranslationUnit_CXXChainedPCH = 0x20, 1184 1185 /** 1186 * \brief Used to indicate that function/method bodies should be skipped while 1187 * parsing. 1188 * 1189 * This option can be used to search for declarations/definitions while 1190 * ignoring the usages. 1191 */ 1192 CXTranslationUnit_SkipFunctionBodies = 0x40, 1193 1194 /** 1195 * \brief Used to indicate that brief documentation comments should be 1196 * included into the set of code completions returned from this translation 1197 * unit. 1198 */ 1199 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80 1200 }; 1201 1202 /** 1203 * \brief Returns the set of flags that is suitable for parsing a translation 1204 * unit that is being edited. 1205 * 1206 * The set of flags returned provide options for \c clang_parseTranslationUnit() 1207 * to indicate that the translation unit is likely to be reparsed many times, 1208 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly 1209 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag 1210 * set contains an unspecified set of optimizations (e.g., the precompiled 1211 * preamble) geared toward improving the performance of these routines. The 1212 * set of optimizations enabled may change from one version to the next. 1213 */ 1214 CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void); 1215 1216 /** 1217 * \brief Same as \c clang_parseTranslationUnit2, but returns 1218 * the \c CXTranslationUnit instead of an error code. In case of an error this 1219 * routine returns a \c NULL \c CXTranslationUnit, without further detailed 1220 * error codes. 1221 */ 1222 CINDEX_LINKAGE CXTranslationUnit 1223 clang_parseTranslationUnit(CXIndex CIdx, 1224 const char *source_filename, 1225 const char *const *command_line_args, 1226 int num_command_line_args, 1227 struct CXUnsavedFile *unsaved_files, 1228 unsigned num_unsaved_files, 1229 unsigned options); 1230 1231 /** 1232 * \brief Parse the given source file and the translation unit corresponding 1233 * to that file. 1234 * 1235 * This routine is the main entry point for the Clang C API, providing the 1236 * ability to parse a source file into a translation unit that can then be 1237 * queried by other functions in the API. This routine accepts a set of 1238 * command-line arguments so that the compilation can be configured in the same 1239 * way that the compiler is configured on the command line. 1240 * 1241 * \param CIdx The index object with which the translation unit will be 1242 * associated. 1243 * 1244 * \param source_filename The name of the source file to load, or NULL if the 1245 * source file is included in \c command_line_args. 1246 * 1247 * \param command_line_args The command-line arguments that would be 1248 * passed to the \c clang executable if it were being invoked out-of-process. 1249 * These command-line options will be parsed and will affect how the translation 1250 * unit is parsed. Note that the following options are ignored: '-c', 1251 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'. 1252 * 1253 * \param num_command_line_args The number of command-line arguments in 1254 * \c command_line_args. 1255 * 1256 * \param unsaved_files the files that have not yet been saved to disk 1257 * but may be required for parsing, including the contents of 1258 * those files. The contents and name of these files (as specified by 1259 * CXUnsavedFile) are copied when necessary, so the client only needs to 1260 * guarantee their validity until the call to this function returns. 1261 * 1262 * \param num_unsaved_files the number of unsaved file entries in \p 1263 * unsaved_files. 1264 * 1265 * \param options A bitmask of options that affects how the translation unit 1266 * is managed but not its compilation. This should be a bitwise OR of the 1267 * CXTranslationUnit_XXX flags. 1268 * 1269 * \param[out] out_TU A non-NULL pointer to store the created 1270 * \c CXTranslationUnit, describing the parsed code and containing any 1271 * diagnostics produced by the compiler. 1272 * 1273 * \returns Zero on success, otherwise returns an error code. 1274 */ 1275 CINDEX_LINKAGE enum CXErrorCode 1276 clang_parseTranslationUnit2(CXIndex CIdx, 1277 const char *source_filename, 1278 const char *const *command_line_args, 1279 int num_command_line_args, 1280 struct CXUnsavedFile *unsaved_files, 1281 unsigned num_unsaved_files, 1282 unsigned options, 1283 CXTranslationUnit *out_TU); 1284 1285 /** 1286 * \brief Flags that control how translation units are saved. 1287 * 1288 * The enumerators in this enumeration type are meant to be bitwise 1289 * ORed together to specify which options should be used when 1290 * saving the translation unit. 1291 */ 1292 enum CXSaveTranslationUnit_Flags { 1293 /** 1294 * \brief Used to indicate that no special saving options are needed. 1295 */ 1296 CXSaveTranslationUnit_None = 0x0 1297 }; 1298 1299 /** 1300 * \brief Returns the set of flags that is suitable for saving a translation 1301 * unit. 1302 * 1303 * The set of flags returned provide options for 1304 * \c clang_saveTranslationUnit() by default. The returned flag 1305 * set contains an unspecified set of options that save translation units with 1306 * the most commonly-requested data. 1307 */ 1308 CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU); 1309 1310 /** 1311 * \brief Describes the kind of error that occurred (if any) in a call to 1312 * \c clang_saveTranslationUnit(). 1313 */ 1314 enum CXSaveError { 1315 /** 1316 * \brief Indicates that no error occurred while saving a translation unit. 1317 */ 1318 CXSaveError_None = 0, 1319 1320 /** 1321 * \brief Indicates that an unknown error occurred while attempting to save 1322 * the file. 1323 * 1324 * This error typically indicates that file I/O failed when attempting to 1325 * write the file. 1326 */ 1327 CXSaveError_Unknown = 1, 1328 1329 /** 1330 * \brief Indicates that errors during translation prevented this attempt 1331 * to save the translation unit. 1332 * 1333 * Errors that prevent the translation unit from being saved can be 1334 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic(). 1335 */ 1336 CXSaveError_TranslationErrors = 2, 1337 1338 /** 1339 * \brief Indicates that the translation unit to be saved was somehow 1340 * invalid (e.g., NULL). 1341 */ 1342 CXSaveError_InvalidTU = 3 1343 }; 1344 1345 /** 1346 * \brief Saves a translation unit into a serialized representation of 1347 * that translation unit on disk. 1348 * 1349 * Any translation unit that was parsed without error can be saved 1350 * into a file. The translation unit can then be deserialized into a 1351 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or, 1352 * if it is an incomplete translation unit that corresponds to a 1353 * header, used as a precompiled header when parsing other translation 1354 * units. 1355 * 1356 * \param TU The translation unit to save. 1357 * 1358 * \param FileName The file to which the translation unit will be saved. 1359 * 1360 * \param options A bitmask of options that affects how the translation unit 1361 * is saved. This should be a bitwise OR of the 1362 * CXSaveTranslationUnit_XXX flags. 1363 * 1364 * \returns A value that will match one of the enumerators of the CXSaveError 1365 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was 1366 * saved successfully, while a non-zero value indicates that a problem occurred. 1367 */ 1368 CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU, 1369 const char *FileName, 1370 unsigned options); 1371 1372 /** 1373 * \brief Destroy the specified CXTranslationUnit object. 1374 */ 1375 CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); 1376 1377 /** 1378 * \brief Flags that control the reparsing of translation units. 1379 * 1380 * The enumerators in this enumeration type are meant to be bitwise 1381 * ORed together to specify which options should be used when 1382 * reparsing the translation unit. 1383 */ 1384 enum CXReparse_Flags { 1385 /** 1386 * \brief Used to indicate that no special reparsing options are needed. 1387 */ 1388 CXReparse_None = 0x0 1389 }; 1390 1391 /** 1392 * \brief Returns the set of flags that is suitable for reparsing a translation 1393 * unit. 1394 * 1395 * The set of flags returned provide options for 1396 * \c clang_reparseTranslationUnit() by default. The returned flag 1397 * set contains an unspecified set of optimizations geared toward common uses 1398 * of reparsing. The set of optimizations enabled may change from one version 1399 * to the next. 1400 */ 1401 CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU); 1402 1403 /** 1404 * \brief Reparse the source files that produced this translation unit. 1405 * 1406 * This routine can be used to re-parse the source files that originally 1407 * created the given translation unit, for example because those source files 1408 * have changed (either on disk or as passed via \p unsaved_files). The 1409 * source code will be reparsed with the same command-line options as it 1410 * was originally parsed. 1411 * 1412 * Reparsing a translation unit invalidates all cursors and source locations 1413 * that refer into that translation unit. This makes reparsing a translation 1414 * unit semantically equivalent to destroying the translation unit and then 1415 * creating a new translation unit with the same command-line arguments. 1416 * However, it may be more efficient to reparse a translation 1417 * unit using this routine. 1418 * 1419 * \param TU The translation unit whose contents will be re-parsed. The 1420 * translation unit must originally have been built with 1421 * \c clang_createTranslationUnitFromSourceFile(). 1422 * 1423 * \param num_unsaved_files The number of unsaved file entries in \p 1424 * unsaved_files. 1425 * 1426 * \param unsaved_files The files that have not yet been saved to disk 1427 * but may be required for parsing, including the contents of 1428 * those files. The contents and name of these files (as specified by 1429 * CXUnsavedFile) are copied when necessary, so the client only needs to 1430 * guarantee their validity until the call to this function returns. 1431 * 1432 * \param options A bitset of options composed of the flags in CXReparse_Flags. 1433 * The function \c clang_defaultReparseOptions() produces a default set of 1434 * options recommended for most uses, based on the translation unit. 1435 * 1436 * \returns 0 if the sources could be reparsed. A non-zero error code will be 1437 * returned if reparsing was impossible, such that the translation unit is 1438 * invalid. In such cases, the only valid call for \c TU is 1439 * \c clang_disposeTranslationUnit(TU). The error codes returned by this 1440 * routine are described by the \c CXErrorCode enum. 1441 */ 1442 CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, 1443 unsigned num_unsaved_files, 1444 struct CXUnsavedFile *unsaved_files, 1445 unsigned options); 1446 1447 /** 1448 * \brief Categorizes how memory is being used by a translation unit. 1449 */ 1450 enum CXTUResourceUsageKind { 1451 CXTUResourceUsage_AST = 1, 1452 CXTUResourceUsage_Identifiers = 2, 1453 CXTUResourceUsage_Selectors = 3, 1454 CXTUResourceUsage_GlobalCompletionResults = 4, 1455 CXTUResourceUsage_SourceManagerContentCache = 5, 1456 CXTUResourceUsage_AST_SideTables = 6, 1457 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7, 1458 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8, 1459 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9, 1460 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10, 1461 CXTUResourceUsage_Preprocessor = 11, 1462 CXTUResourceUsage_PreprocessingRecord = 12, 1463 CXTUResourceUsage_SourceManager_DataStructures = 13, 1464 CXTUResourceUsage_Preprocessor_HeaderSearch = 14, 1465 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST, 1466 CXTUResourceUsage_MEMORY_IN_BYTES_END = 1467 CXTUResourceUsage_Preprocessor_HeaderSearch, 1468 1469 CXTUResourceUsage_First = CXTUResourceUsage_AST, 1470 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch 1471 }; 1472 1473 /** 1474 * \brief Returns the human-readable null-terminated C string that represents 1475 * the name of the memory category. This string should never be freed. 1476 */ 1477 CINDEX_LINKAGE 1478 const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind); 1479 1480 typedef struct CXTUResourceUsageEntry { 1481 /* \brief The memory usage category. */ 1482 enum CXTUResourceUsageKind kind; 1483 /* \brief Amount of resources used. 1484 The units will depend on the resource kind. */ 1485 unsigned long amount; 1486 } CXTUResourceUsageEntry; 1487 1488 /** 1489 * \brief The memory usage of a CXTranslationUnit, broken into categories. 1490 */ 1491 typedef struct CXTUResourceUsage { 1492 /* \brief Private data member, used for queries. */ 1493 void *data; 1494 1495 /* \brief The number of entries in the 'entries' array. */ 1496 unsigned numEntries; 1497 1498 /* \brief An array of key-value pairs, representing the breakdown of memory 1499 usage. */ 1500 CXTUResourceUsageEntry *entries; 1501 1502 } CXTUResourceUsage; 1503 1504 /** 1505 * \brief Return the memory usage of a translation unit. This object 1506 * should be released with clang_disposeCXTUResourceUsage(). 1507 */ 1508 CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU); 1509 1510 CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage); 1511 1512 /** 1513 * @} 1514 */ 1515 1516 /** 1517 * \brief Describes the kind of entity that a cursor refers to. 1518 */ 1519 enum CXCursorKind { 1520 /* Declarations */ 1521 /** 1522 * \brief A declaration whose specific kind is not exposed via this 1523 * interface. 1524 * 1525 * Unexposed declarations have the same operations as any other kind 1526 * of declaration; one can extract their location information, 1527 * spelling, find their definitions, etc. However, the specific kind 1528 * of the declaration is not reported. 1529 */ 1530 CXCursor_UnexposedDecl = 1, 1531 /** \brief A C or C++ struct. */ 1532 CXCursor_StructDecl = 2, 1533 /** \brief A C or C++ union. */ 1534 CXCursor_UnionDecl = 3, 1535 /** \brief A C++ class. */ 1536 CXCursor_ClassDecl = 4, 1537 /** \brief An enumeration. */ 1538 CXCursor_EnumDecl = 5, 1539 /** 1540 * \brief A field (in C) or non-static data member (in C++) in a 1541 * struct, union, or C++ class. 1542 */ 1543 CXCursor_FieldDecl = 6, 1544 /** \brief An enumerator constant. */ 1545 CXCursor_EnumConstantDecl = 7, 1546 /** \brief A function. */ 1547 CXCursor_FunctionDecl = 8, 1548 /** \brief A variable. */ 1549 CXCursor_VarDecl = 9, 1550 /** \brief A function or method parameter. */ 1551 CXCursor_ParmDecl = 10, 1552 /** \brief An Objective-C \@interface. */ 1553 CXCursor_ObjCInterfaceDecl = 11, 1554 /** \brief An Objective-C \@interface for a category. */ 1555 CXCursor_ObjCCategoryDecl = 12, 1556 /** \brief An Objective-C \@protocol declaration. */ 1557 CXCursor_ObjCProtocolDecl = 13, 1558 /** \brief An Objective-C \@property declaration. */ 1559 CXCursor_ObjCPropertyDecl = 14, 1560 /** \brief An Objective-C instance variable. */ 1561 CXCursor_ObjCIvarDecl = 15, 1562 /** \brief An Objective-C instance method. */ 1563 CXCursor_ObjCInstanceMethodDecl = 16, 1564 /** \brief An Objective-C class method. */ 1565 CXCursor_ObjCClassMethodDecl = 17, 1566 /** \brief An Objective-C \@implementation. */ 1567 CXCursor_ObjCImplementationDecl = 18, 1568 /** \brief An Objective-C \@implementation for a category. */ 1569 CXCursor_ObjCCategoryImplDecl = 19, 1570 /** \brief A typedef */ 1571 CXCursor_TypedefDecl = 20, 1572 /** \brief A C++ class method. */ 1573 CXCursor_CXXMethod = 21, 1574 /** \brief A C++ namespace. */ 1575 CXCursor_Namespace = 22, 1576 /** \brief A linkage specification, e.g. 'extern "C"'. */ 1577 CXCursor_LinkageSpec = 23, 1578 /** \brief A C++ constructor. */ 1579 CXCursor_Constructor = 24, 1580 /** \brief A C++ destructor. */ 1581 CXCursor_Destructor = 25, 1582 /** \brief A C++ conversion function. */ 1583 CXCursor_ConversionFunction = 26, 1584 /** \brief A C++ template type parameter. */ 1585 CXCursor_TemplateTypeParameter = 27, 1586 /** \brief A C++ non-type template parameter. */ 1587 CXCursor_NonTypeTemplateParameter = 28, 1588 /** \brief A C++ template template parameter. */ 1589 CXCursor_TemplateTemplateParameter = 29, 1590 /** \brief A C++ function template. */ 1591 CXCursor_FunctionTemplate = 30, 1592 /** \brief A C++ class template. */ 1593 CXCursor_ClassTemplate = 31, 1594 /** \brief A C++ class template partial specialization. */ 1595 CXCursor_ClassTemplatePartialSpecialization = 32, 1596 /** \brief A C++ namespace alias declaration. */ 1597 CXCursor_NamespaceAlias = 33, 1598 /** \brief A C++ using directive. */ 1599 CXCursor_UsingDirective = 34, 1600 /** \brief A C++ using declaration. */ 1601 CXCursor_UsingDeclaration = 35, 1602 /** \brief A C++ alias declaration */ 1603 CXCursor_TypeAliasDecl = 36, 1604 /** \brief An Objective-C \@synthesize definition. */ 1605 CXCursor_ObjCSynthesizeDecl = 37, 1606 /** \brief An Objective-C \@dynamic definition. */ 1607 CXCursor_ObjCDynamicDecl = 38, 1608 /** \brief An access specifier. */ 1609 CXCursor_CXXAccessSpecifier = 39, 1610 1611 CXCursor_FirstDecl = CXCursor_UnexposedDecl, 1612 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier, 1613 1614 /* References */ 1615 CXCursor_FirstRef = 40, /* Decl references */ 1616 CXCursor_ObjCSuperClassRef = 40, 1617 CXCursor_ObjCProtocolRef = 41, 1618 CXCursor_ObjCClassRef = 42, 1619 /** 1620 * \brief A reference to a type declaration. 1621 * 1622 * A type reference occurs anywhere where a type is named but not 1623 * declared. For example, given: 1624 * 1625 * \code 1626 * typedef unsigned size_type; 1627 * size_type size; 1628 * \endcode 1629 * 1630 * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 1631 * while the type of the variable "size" is referenced. The cursor 1632 * referenced by the type of size is the typedef for size_type. 1633 */ 1634 CXCursor_TypeRef = 43, 1635 CXCursor_CXXBaseSpecifier = 44, 1636 /** 1637 * \brief A reference to a class template, function template, template 1638 * template parameter, or class template partial specialization. 1639 */ 1640 CXCursor_TemplateRef = 45, 1641 /** 1642 * \brief A reference to a namespace or namespace alias. 1643 */ 1644 CXCursor_NamespaceRef = 46, 1645 /** 1646 * \brief A reference to a member of a struct, union, or class that occurs in 1647 * some non-expression context, e.g., a designated initializer. 1648 */ 1649 CXCursor_MemberRef = 47, 1650 /** 1651 * \brief A reference to a labeled statement. 1652 * 1653 * This cursor kind is used to describe the jump to "start_over" in the 1654 * goto statement in the following example: 1655 * 1656 * \code 1657 * start_over: 1658 * ++counter; 1659 * 1660 * goto start_over; 1661 * \endcode 1662 * 1663 * A label reference cursor refers to a label statement. 1664 */ 1665 CXCursor_LabelRef = 48, 1666 1667 /** 1668 * \brief A reference to a set of overloaded functions or function templates 1669 * that has not yet been resolved to a specific function or function template. 1670 * 1671 * An overloaded declaration reference cursor occurs in C++ templates where 1672 * a dependent name refers to a function. For example: 1673 * 1674 * \code 1675 * template<typename T> void swap(T&, T&); 1676 * 1677 * struct X { ... }; 1678 * void swap(X&, X&); 1679 * 1680 * template<typename T> 1681 * void reverse(T* first, T* last) { 1682 * while (first < last - 1) { 1683 * swap(*first, *--last); 1684 * ++first; 1685 * } 1686 * } 1687 * 1688 * struct Y { }; 1689 * void swap(Y&, Y&); 1690 * \endcode 1691 * 1692 * Here, the identifier "swap" is associated with an overloaded declaration 1693 * reference. In the template definition, "swap" refers to either of the two 1694 * "swap" functions declared above, so both results will be available. At 1695 * instantiation time, "swap" may also refer to other functions found via 1696 * argument-dependent lookup (e.g., the "swap" function at the end of the 1697 * example). 1698 * 1699 * The functions \c clang_getNumOverloadedDecls() and 1700 * \c clang_getOverloadedDecl() can be used to retrieve the definitions 1701 * referenced by this cursor. 1702 */ 1703 CXCursor_OverloadedDeclRef = 49, 1704 1705 /** 1706 * \brief A reference to a variable that occurs in some non-expression 1707 * context, e.g., a C++ lambda capture list. 1708 */ 1709 CXCursor_VariableRef = 50, 1710 1711 CXCursor_LastRef = CXCursor_VariableRef, 1712 1713 /* Error conditions */ 1714 CXCursor_FirstInvalid = 70, 1715 CXCursor_InvalidFile = 70, 1716 CXCursor_NoDeclFound = 71, 1717 CXCursor_NotImplemented = 72, 1718 CXCursor_InvalidCode = 73, 1719 CXCursor_LastInvalid = CXCursor_InvalidCode, 1720 1721 /* Expressions */ 1722 CXCursor_FirstExpr = 100, 1723 1724 /** 1725 * \brief An expression whose specific kind is not exposed via this 1726 * interface. 1727 * 1728 * Unexposed expressions have the same operations as any other kind 1729 * of expression; one can extract their location information, 1730 * spelling, children, etc. However, the specific kind of the 1731 * expression is not reported. 1732 */ 1733 CXCursor_UnexposedExpr = 100, 1734 1735 /** 1736 * \brief An expression that refers to some value declaration, such 1737 * as a function, variable, or enumerator. 1738 */ 1739 CXCursor_DeclRefExpr = 101, 1740 1741 /** 1742 * \brief An expression that refers to a member of a struct, union, 1743 * class, Objective-C class, etc. 1744 */ 1745 CXCursor_MemberRefExpr = 102, 1746 1747 /** \brief An expression that calls a function. */ 1748 CXCursor_CallExpr = 103, 1749 1750 /** \brief An expression that sends a message to an Objective-C 1751 object or class. */ 1752 CXCursor_ObjCMessageExpr = 104, 1753 1754 /** \brief An expression that represents a block literal. */ 1755 CXCursor_BlockExpr = 105, 1756 1757 /** \brief An integer literal. 1758 */ 1759 CXCursor_IntegerLiteral = 106, 1760 1761 /** \brief A floating point number literal. 1762 */ 1763 CXCursor_FloatingLiteral = 107, 1764 1765 /** \brief An imaginary number literal. 1766 */ 1767 CXCursor_ImaginaryLiteral = 108, 1768 1769 /** \brief A string literal. 1770 */ 1771 CXCursor_StringLiteral = 109, 1772 1773 /** \brief A character literal. 1774 */ 1775 CXCursor_CharacterLiteral = 110, 1776 1777 /** \brief A parenthesized expression, e.g. "(1)". 1778 * 1779 * This AST node is only formed if full location information is requested. 1780 */ 1781 CXCursor_ParenExpr = 111, 1782 1783 /** \brief This represents the unary-expression's (except sizeof and 1784 * alignof). 1785 */ 1786 CXCursor_UnaryOperator = 112, 1787 1788 /** \brief [C99 6.5.2.1] Array Subscripting. 1789 */ 1790 CXCursor_ArraySubscriptExpr = 113, 1791 1792 /** \brief A builtin binary operation expression such as "x + y" or 1793 * "x <= y". 1794 */ 1795 CXCursor_BinaryOperator = 114, 1796 1797 /** \brief Compound assignment such as "+=". 1798 */ 1799 CXCursor_CompoundAssignOperator = 115, 1800 1801 /** \brief The ?: ternary operator. 1802 */ 1803 CXCursor_ConditionalOperator = 116, 1804 1805 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++ 1806 * (C++ [expr.cast]), which uses the syntax (Type)expr. 1807 * 1808 * For example: (int)f. 1809 */ 1810 CXCursor_CStyleCastExpr = 117, 1811 1812 /** \brief [C99 6.5.2.5] 1813 */ 1814 CXCursor_CompoundLiteralExpr = 118, 1815 1816 /** \brief Describes an C or C++ initializer list. 1817 */ 1818 CXCursor_InitListExpr = 119, 1819 1820 /** \brief The GNU address of label extension, representing &&label. 1821 */ 1822 CXCursor_AddrLabelExpr = 120, 1823 1824 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;}) 1825 */ 1826 CXCursor_StmtExpr = 121, 1827 1828 /** \brief Represents a C11 generic selection. 1829 */ 1830 CXCursor_GenericSelectionExpr = 122, 1831 1832 /** \brief Implements the GNU __null extension, which is a name for a null 1833 * pointer constant that has integral type (e.g., int or long) and is the same 1834 * size and alignment as a pointer. 1835 * 1836 * The __null extension is typically only used by system headers, which define 1837 * NULL as __null in C++ rather than using 0 (which is an integer that may not 1838 * match the size of a pointer). 1839 */ 1840 CXCursor_GNUNullExpr = 123, 1841 1842 /** \brief C++'s static_cast<> expression. 1843 */ 1844 CXCursor_CXXStaticCastExpr = 124, 1845 1846 /** \brief C++'s dynamic_cast<> expression. 1847 */ 1848 CXCursor_CXXDynamicCastExpr = 125, 1849 1850 /** \brief C++'s reinterpret_cast<> expression. 1851 */ 1852 CXCursor_CXXReinterpretCastExpr = 126, 1853 1854 /** \brief C++'s const_cast<> expression. 1855 */ 1856 CXCursor_CXXConstCastExpr = 127, 1857 1858 /** \brief Represents an explicit C++ type conversion that uses "functional" 1859 * notion (C++ [expr.type.conv]). 1860 * 1861 * Example: 1862 * \code 1863 * x = int(0.5); 1864 * \endcode 1865 */ 1866 CXCursor_CXXFunctionalCastExpr = 128, 1867 1868 /** \brief A C++ typeid expression (C++ [expr.typeid]). 1869 */ 1870 CXCursor_CXXTypeidExpr = 129, 1871 1872 /** \brief [C++ 2.13.5] C++ Boolean Literal. 1873 */ 1874 CXCursor_CXXBoolLiteralExpr = 130, 1875 1876 /** \brief [C++0x 2.14.7] C++ Pointer Literal. 1877 */ 1878 CXCursor_CXXNullPtrLiteralExpr = 131, 1879 1880 /** \brief Represents the "this" expression in C++ 1881 */ 1882 CXCursor_CXXThisExpr = 132, 1883 1884 /** \brief [C++ 15] C++ Throw Expression. 1885 * 1886 * This handles 'throw' and 'throw' assignment-expression. When 1887 * assignment-expression isn't present, Op will be null. 1888 */ 1889 CXCursor_CXXThrowExpr = 133, 1890 1891 /** \brief A new expression for memory allocation and constructor calls, e.g: 1892 * "new CXXNewExpr(foo)". 1893 */ 1894 CXCursor_CXXNewExpr = 134, 1895 1896 /** \brief A delete expression for memory deallocation and destructor calls, 1897 * e.g. "delete[] pArray". 1898 */ 1899 CXCursor_CXXDeleteExpr = 135, 1900 1901 /** \brief A unary expression. 1902 */ 1903 CXCursor_UnaryExpr = 136, 1904 1905 /** \brief An Objective-C string literal i.e. @"foo". 1906 */ 1907 CXCursor_ObjCStringLiteral = 137, 1908 1909 /** \brief An Objective-C \@encode expression. 1910 */ 1911 CXCursor_ObjCEncodeExpr = 138, 1912 1913 /** \brief An Objective-C \@selector expression. 1914 */ 1915 CXCursor_ObjCSelectorExpr = 139, 1916 1917 /** \brief An Objective-C \@protocol expression. 1918 */ 1919 CXCursor_ObjCProtocolExpr = 140, 1920 1921 /** \brief An Objective-C "bridged" cast expression, which casts between 1922 * Objective-C pointers and C pointers, transferring ownership in the process. 1923 * 1924 * \code 1925 * NSString *str = (__bridge_transfer NSString *)CFCreateString(); 1926 * \endcode 1927 */ 1928 CXCursor_ObjCBridgedCastExpr = 141, 1929 1930 /** \brief Represents a C++0x pack expansion that produces a sequence of 1931 * expressions. 1932 * 1933 * A pack expansion expression contains a pattern (which itself is an 1934 * expression) followed by an ellipsis. For example: 1935 * 1936 * \code 1937 * template<typename F, typename ...Types> 1938 * void forward(F f, Types &&...args) { 1939 * f(static_cast<Types&&>(args)...); 1940 * } 1941 * \endcode 1942 */ 1943 CXCursor_PackExpansionExpr = 142, 1944 1945 /** \brief Represents an expression that computes the length of a parameter 1946 * pack. 1947 * 1948 * \code 1949 * template<typename ...Types> 1950 * struct count { 1951 * static const unsigned value = sizeof...(Types); 1952 * }; 1953 * \endcode 1954 */ 1955 CXCursor_SizeOfPackExpr = 143, 1956 1957 /* \brief Represents a C++ lambda expression that produces a local function 1958 * object. 1959 * 1960 * \code 1961 * void abssort(float *x, unsigned N) { 1962 * std::sort(x, x + N, 1963 * [](float a, float b) { 1964 * return std::abs(a) < std::abs(b); 1965 * }); 1966 * } 1967 * \endcode 1968 */ 1969 CXCursor_LambdaExpr = 144, 1970 1971 /** \brief Objective-c Boolean Literal. 1972 */ 1973 CXCursor_ObjCBoolLiteralExpr = 145, 1974 1975 /** \brief Represents the "self" expression in an Objective-C method. 1976 */ 1977 CXCursor_ObjCSelfExpr = 146, 1978 1979 CXCursor_LastExpr = CXCursor_ObjCSelfExpr, 1980 1981 /* Statements */ 1982 CXCursor_FirstStmt = 200, 1983 /** 1984 * \brief A statement whose specific kind is not exposed via this 1985 * interface. 1986 * 1987 * Unexposed statements have the same operations as any other kind of 1988 * statement; one can extract their location information, spelling, 1989 * children, etc. However, the specific kind of the statement is not 1990 * reported. 1991 */ 1992 CXCursor_UnexposedStmt = 200, 1993 1994 /** \brief A labelled statement in a function. 1995 * 1996 * This cursor kind is used to describe the "start_over:" label statement in 1997 * the following example: 1998 * 1999 * \code 2000 * start_over: 2001 * ++counter; 2002 * \endcode 2003 * 2004 */ 2005 CXCursor_LabelStmt = 201, 2006 2007 /** \brief A group of statements like { stmt stmt }. 2008 * 2009 * This cursor kind is used to describe compound statements, e.g. function 2010 * bodies. 2011 */ 2012 CXCursor_CompoundStmt = 202, 2013 2014 /** \brief A case statement. 2015 */ 2016 CXCursor_CaseStmt = 203, 2017 2018 /** \brief A default statement. 2019 */ 2020 CXCursor_DefaultStmt = 204, 2021 2022 /** \brief An if statement 2023 */ 2024 CXCursor_IfStmt = 205, 2025 2026 /** \brief A switch statement. 2027 */ 2028 CXCursor_SwitchStmt = 206, 2029 2030 /** \brief A while statement. 2031 */ 2032 CXCursor_WhileStmt = 207, 2033 2034 /** \brief A do statement. 2035 */ 2036 CXCursor_DoStmt = 208, 2037 2038 /** \brief A for statement. 2039 */ 2040 CXCursor_ForStmt = 209, 2041 2042 /** \brief A goto statement. 2043 */ 2044 CXCursor_GotoStmt = 210, 2045 2046 /** \brief An indirect goto statement. 2047 */ 2048 CXCursor_IndirectGotoStmt = 211, 2049 2050 /** \brief A continue statement. 2051 */ 2052 CXCursor_ContinueStmt = 212, 2053 2054 /** \brief A break statement. 2055 */ 2056 CXCursor_BreakStmt = 213, 2057 2058 /** \brief A return statement. 2059 */ 2060 CXCursor_ReturnStmt = 214, 2061 2062 /** \brief A GCC inline assembly statement extension. 2063 */ 2064 CXCursor_GCCAsmStmt = 215, 2065 CXCursor_AsmStmt = CXCursor_GCCAsmStmt, 2066 2067 /** \brief Objective-C's overall \@try-\@catch-\@finally statement. 2068 */ 2069 CXCursor_ObjCAtTryStmt = 216, 2070 2071 /** \brief Objective-C's \@catch statement. 2072 */ 2073 CXCursor_ObjCAtCatchStmt = 217, 2074 2075 /** \brief Objective-C's \@finally statement. 2076 */ 2077 CXCursor_ObjCAtFinallyStmt = 218, 2078 2079 /** \brief Objective-C's \@throw statement. 2080 */ 2081 CXCursor_ObjCAtThrowStmt = 219, 2082 2083 /** \brief Objective-C's \@synchronized statement. 2084 */ 2085 CXCursor_ObjCAtSynchronizedStmt = 220, 2086 2087 /** \brief Objective-C's autorelease pool statement. 2088 */ 2089 CXCursor_ObjCAutoreleasePoolStmt = 221, 2090 2091 /** \brief Objective-C's collection statement. 2092 */ 2093 CXCursor_ObjCForCollectionStmt = 222, 2094 2095 /** \brief C++'s catch statement. 2096 */ 2097 CXCursor_CXXCatchStmt = 223, 2098 2099 /** \brief C++'s try statement. 2100 */ 2101 CXCursor_CXXTryStmt = 224, 2102 2103 /** \brief C++'s for (* : *) statement. 2104 */ 2105 CXCursor_CXXForRangeStmt = 225, 2106 2107 /** \brief Windows Structured Exception Handling's try statement. 2108 */ 2109 CXCursor_SEHTryStmt = 226, 2110 2111 /** \brief Windows Structured Exception Handling's except statement. 2112 */ 2113 CXCursor_SEHExceptStmt = 227, 2114 2115 /** \brief Windows Structured Exception Handling's finally statement. 2116 */ 2117 CXCursor_SEHFinallyStmt = 228, 2118 2119 /** \brief A MS inline assembly statement extension. 2120 */ 2121 CXCursor_MSAsmStmt = 229, 2122 2123 /** \brief The null satement ";": C99 6.8.3p3. 2124 * 2125 * This cursor kind is used to describe the null statement. 2126 */ 2127 CXCursor_NullStmt = 230, 2128 2129 /** \brief Adaptor class for mixing declarations with statements and 2130 * expressions. 2131 */ 2132 CXCursor_DeclStmt = 231, 2133 2134 /** \brief OpenMP parallel directive. 2135 */ 2136 CXCursor_OMPParallelDirective = 232, 2137 2138 /** \brief OpenMP simd directive. 2139 */ 2140 CXCursor_OMPSimdDirective = 233, 2141 2142 /** \brief OpenMP for directive. 2143 */ 2144 CXCursor_OMPForDirective = 234, 2145 2146 /** \brief OpenMP sections directive. 2147 */ 2148 CXCursor_OMPSectionsDirective = 235, 2149 2150 /** \brief OpenMP section directive. 2151 */ 2152 CXCursor_OMPSectionDirective = 236, 2153 2154 /** \brief OpenMP single directive. 2155 */ 2156 CXCursor_OMPSingleDirective = 237, 2157 2158 /** \brief OpenMP parallel for directive. 2159 */ 2160 CXCursor_OMPParallelForDirective = 238, 2161 2162 /** \brief OpenMP parallel sections directive. 2163 */ 2164 CXCursor_OMPParallelSectionsDirective = 239, 2165 2166 /** \brief Windows Structured Exception Handling's leave statement. 2167 */ 2168 CXCursor_SEHLeaveStmt = 240, 2169 2170 CXCursor_LastStmt = CXCursor_SEHLeaveStmt, 2171 2172 /** 2173 * \brief Cursor that represents the translation unit itself. 2174 * 2175 * The translation unit cursor exists primarily to act as the root 2176 * cursor for traversing the contents of a translation unit. 2177 */ 2178 CXCursor_TranslationUnit = 300, 2179 2180 /* Attributes */ 2181 CXCursor_FirstAttr = 400, 2182 /** 2183 * \brief An attribute whose specific kind is not exposed via this 2184 * interface. 2185 */ 2186 CXCursor_UnexposedAttr = 400, 2187 2188 CXCursor_IBActionAttr = 401, 2189 CXCursor_IBOutletAttr = 402, 2190 CXCursor_IBOutletCollectionAttr = 403, 2191 CXCursor_CXXFinalAttr = 404, 2192 CXCursor_CXXOverrideAttr = 405, 2193 CXCursor_AnnotateAttr = 406, 2194 CXCursor_AsmLabelAttr = 407, 2195 CXCursor_PackedAttr = 408, 2196 CXCursor_PureAttr = 409, 2197 CXCursor_ConstAttr = 410, 2198 CXCursor_NoDuplicateAttr = 411, 2199 CXCursor_CUDAConstantAttr = 412, 2200 CXCursor_CUDADeviceAttr = 413, 2201 CXCursor_CUDAGlobalAttr = 414, 2202 CXCursor_CUDAHostAttr = 415, 2203 CXCursor_LastAttr = CXCursor_CUDAHostAttr, 2204 2205 /* Preprocessing */ 2206 CXCursor_PreprocessingDirective = 500, 2207 CXCursor_MacroDefinition = 501, 2208 CXCursor_MacroExpansion = 502, 2209 CXCursor_MacroInstantiation = CXCursor_MacroExpansion, 2210 CXCursor_InclusionDirective = 503, 2211 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, 2212 CXCursor_LastPreprocessing = CXCursor_InclusionDirective, 2213 2214 /* Extra Declarations */ 2215 /** 2216 * \brief A module import declaration. 2217 */ 2218 CXCursor_ModuleImportDecl = 600, 2219 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl, 2220 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl 2221 }; 2222 2223 /** 2224 * \brief A cursor representing some element in the abstract syntax tree for 2225 * a translation unit. 2226 * 2227 * The cursor abstraction unifies the different kinds of entities in a 2228 * program--declaration, statements, expressions, references to declarations, 2229 * etc.--under a single "cursor" abstraction with a common set of operations. 2230 * Common operation for a cursor include: getting the physical location in 2231 * a source file where the cursor points, getting the name associated with a 2232 * cursor, and retrieving cursors for any child nodes of a particular cursor. 2233 * 2234 * Cursors can be produced in two specific ways. 2235 * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 2236 * from which one can use clang_visitChildren() to explore the rest of the 2237 * translation unit. clang_getCursor() maps from a physical source location 2238 * to the entity that resides at that location, allowing one to map from the 2239 * source code into the AST. 2240 */ 2241 typedef struct { 2242 enum CXCursorKind kind; 2243 int xdata; 2244 const void *data[3]; 2245 } CXCursor; 2246 2247 /** 2248 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 2249 * 2250 * @{ 2251 */ 2252 2253 /** 2254 * \brief Retrieve the NULL cursor, which represents no entity. 2255 */ 2256 CINDEX_LINKAGE CXCursor clang_getNullCursor(void); 2257 2258 /** 2259 * \brief Retrieve the cursor that represents the given translation unit. 2260 * 2261 * The translation unit cursor can be used to start traversing the 2262 * various declarations within the given translation unit. 2263 */ 2264 CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 2265 2266 /** 2267 * \brief Determine whether two cursors are equivalent. 2268 */ 2269 CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); 2270 2271 /** 2272 * \brief Returns non-zero if \p cursor is null. 2273 */ 2274 CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor); 2275 2276 /** 2277 * \brief Compute a hash value for the given cursor. 2278 */ 2279 CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor); 2280 2281 /** 2282 * \brief Retrieve the kind of the given cursor. 2283 */ 2284 CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); 2285 2286 /** 2287 * \brief Determine whether the given cursor kind represents a declaration. 2288 */ 2289 CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); 2290 2291 /** 2292 * \brief Determine whether the given cursor kind represents a simple 2293 * reference. 2294 * 2295 * Note that other kinds of cursors (such as expressions) can also refer to 2296 * other cursors. Use clang_getCursorReferenced() to determine whether a 2297 * particular cursor refers to another entity. 2298 */ 2299 CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); 2300 2301 /** 2302 * \brief Determine whether the given cursor kind represents an expression. 2303 */ 2304 CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); 2305 2306 /** 2307 * \brief Determine whether the given cursor kind represents a statement. 2308 */ 2309 CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); 2310 2311 /** 2312 * \brief Determine whether the given cursor kind represents an attribute. 2313 */ 2314 CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind); 2315 2316 /** 2317 * \brief Determine whether the given cursor kind represents an invalid 2318 * cursor. 2319 */ 2320 CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); 2321 2322 /** 2323 * \brief Determine whether the given cursor kind represents a translation 2324 * unit. 2325 */ 2326 CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); 2327 2328 /*** 2329 * \brief Determine whether the given cursor represents a preprocessing 2330 * element, such as a preprocessor directive or macro instantiation. 2331 */ 2332 CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); 2333 2334 /*** 2335 * \brief Determine whether the given cursor represents a currently 2336 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). 2337 */ 2338 CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); 2339 2340 /** 2341 * \brief Describe the linkage of the entity referred to by a cursor. 2342 */ 2343 enum CXLinkageKind { 2344 /** \brief This value indicates that no linkage information is available 2345 * for a provided CXCursor. */ 2346 CXLinkage_Invalid, 2347 /** 2348 * \brief This is the linkage for variables, parameters, and so on that 2349 * have automatic storage. This covers normal (non-extern) local variables. 2350 */ 2351 CXLinkage_NoLinkage, 2352 /** \brief This is the linkage for static variables and static functions. */ 2353 CXLinkage_Internal, 2354 /** \brief This is the linkage for entities with external linkage that live 2355 * in C++ anonymous namespaces.*/ 2356 CXLinkage_UniqueExternal, 2357 /** \brief This is the linkage for entities with true, external linkage. */ 2358 CXLinkage_External 2359 }; 2360 2361 /** 2362 * \brief Determine the linkage of the entity referred to by a given cursor. 2363 */ 2364 CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); 2365 2366 /** 2367 * \brief Determine the availability of the entity that this cursor refers to, 2368 * taking the current target platform into account. 2369 * 2370 * \param cursor The cursor to query. 2371 * 2372 * \returns The availability of the cursor. 2373 */ 2374 CINDEX_LINKAGE enum CXAvailabilityKind 2375 clang_getCursorAvailability(CXCursor cursor); 2376 2377 /** 2378 * Describes the availability of a given entity on a particular platform, e.g., 2379 * a particular class might only be available on Mac OS 10.7 or newer. 2380 */ 2381 typedef struct CXPlatformAvailability { 2382 /** 2383 * \brief A string that describes the platform for which this structure 2384 * provides availability information. 2385 * 2386 * Possible values are "ios" or "macosx". 2387 */ 2388 CXString Platform; 2389 /** 2390 * \brief The version number in which this entity was introduced. 2391 */ 2392 CXVersion Introduced; 2393 /** 2394 * \brief The version number in which this entity was deprecated (but is 2395 * still available). 2396 */ 2397 CXVersion Deprecated; 2398 /** 2399 * \brief The version number in which this entity was obsoleted, and therefore 2400 * is no longer available. 2401 */ 2402 CXVersion Obsoleted; 2403 /** 2404 * \brief Whether the entity is unconditionally unavailable on this platform. 2405 */ 2406 int Unavailable; 2407 /** 2408 * \brief An optional message to provide to a user of this API, e.g., to 2409 * suggest replacement APIs. 2410 */ 2411 CXString Message; 2412 } CXPlatformAvailability; 2413 2414 /** 2415 * \brief Determine the availability of the entity that this cursor refers to 2416 * on any platforms for which availability information is known. 2417 * 2418 * \param cursor The cursor to query. 2419 * 2420 * \param always_deprecated If non-NULL, will be set to indicate whether the 2421 * entity is deprecated on all platforms. 2422 * 2423 * \param deprecated_message If non-NULL, will be set to the message text 2424 * provided along with the unconditional deprecation of this entity. The client 2425 * is responsible for deallocating this string. 2426 * 2427 * \param always_unavailable If non-NULL, will be set to indicate whether the 2428 * entity is unavailable on all platforms. 2429 * 2430 * \param unavailable_message If non-NULL, will be set to the message text 2431 * provided along with the unconditional unavailability of this entity. The 2432 * client is responsible for deallocating this string. 2433 * 2434 * \param availability If non-NULL, an array of CXPlatformAvailability instances 2435 * that will be populated with platform availability information, up to either 2436 * the number of platforms for which availability information is available (as 2437 * returned by this function) or \c availability_size, whichever is smaller. 2438 * 2439 * \param availability_size The number of elements available in the 2440 * \c availability array. 2441 * 2442 * \returns The number of platforms (N) for which availability information is 2443 * available (which is unrelated to \c availability_size). 2444 * 2445 * Note that the client is responsible for calling 2446 * \c clang_disposeCXPlatformAvailability to free each of the 2447 * platform-availability structures returned. There are 2448 * \c min(N, availability_size) such structures. 2449 */ 2450 CINDEX_LINKAGE int 2451 clang_getCursorPlatformAvailability(CXCursor cursor, 2452 int *always_deprecated, 2453 CXString *deprecated_message, 2454 int *always_unavailable, 2455 CXString *unavailable_message, 2456 CXPlatformAvailability *availability, 2457 int availability_size); 2458 2459 /** 2460 * \brief Free the memory associated with a \c CXPlatformAvailability structure. 2461 */ 2462 CINDEX_LINKAGE void 2463 clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability); 2464 2465 /** 2466 * \brief Describe the "language" of the entity referred to by a cursor. 2467 */ 2468 enum CXLanguageKind { 2469 CXLanguage_Invalid = 0, 2470 CXLanguage_C, 2471 CXLanguage_ObjC, 2472 CXLanguage_CPlusPlus 2473 }; 2474 2475 /** 2476 * \brief Determine the "language" of the entity referred to by a given cursor. 2477 */ 2478 CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); 2479 2480 /** 2481 * \brief Returns the translation unit that a cursor originated from. 2482 */ 2483 CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor); 2484 2485 2486 /** 2487 * \brief A fast container representing a set of CXCursors. 2488 */ 2489 typedef struct CXCursorSetImpl *CXCursorSet; 2490 2491 /** 2492 * \brief Creates an empty CXCursorSet. 2493 */ 2494 CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void); 2495 2496 /** 2497 * \brief Disposes a CXCursorSet and releases its associated memory. 2498 */ 2499 CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset); 2500 2501 /** 2502 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor. 2503 * 2504 * \returns non-zero if the set contains the specified cursor. 2505 */ 2506 CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset, 2507 CXCursor cursor); 2508 2509 /** 2510 * \brief Inserts a CXCursor into a CXCursorSet. 2511 * 2512 * \returns zero if the CXCursor was already in the set, and non-zero otherwise. 2513 */ 2514 CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset, 2515 CXCursor cursor); 2516 2517 /** 2518 * \brief Determine the semantic parent of the given cursor. 2519 * 2520 * The semantic parent of a cursor is the cursor that semantically contains 2521 * the given \p cursor. For many declarations, the lexical and semantic parents 2522 * are equivalent (the lexical parent is returned by 2523 * \c clang_getCursorLexicalParent()). They diverge when declarations or 2524 * definitions are provided out-of-line. For example: 2525 * 2526 * \code 2527 * class C { 2528 * void f(); 2529 * }; 2530 * 2531 * void C::f() { } 2532 * \endcode 2533 * 2534 * In the out-of-line definition of \c C::f, the semantic parent is 2535 * the class \c C, of which this function is a member. The lexical parent is 2536 * the place where the declaration actually occurs in the source code; in this 2537 * case, the definition occurs in the translation unit. In general, the 2538 * lexical parent for a given entity can change without affecting the semantics 2539 * of the program, and the lexical parent of different declarations of the 2540 * same entity may be different. Changing the semantic parent of a declaration, 2541 * on the other hand, can have a major impact on semantics, and redeclarations 2542 * of a particular entity should all have the same semantic context. 2543 * 2544 * In the example above, both declarations of \c C::f have \c C as their 2545 * semantic context, while the lexical context of the first \c C::f is \c C 2546 * and the lexical context of the second \c C::f is the translation unit. 2547 * 2548 * For global declarations, the semantic parent is the translation unit. 2549 */ 2550 CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor); 2551 2552 /** 2553 * \brief Determine the lexical parent of the given cursor. 2554 * 2555 * The lexical parent of a cursor is the cursor in which the given \p cursor 2556 * was actually written. For many declarations, the lexical and semantic parents 2557 * are equivalent (the semantic parent is returned by 2558 * \c clang_getCursorSemanticParent()). They diverge when declarations or 2559 * definitions are provided out-of-line. For example: 2560 * 2561 * \code 2562 * class C { 2563 * void f(); 2564 * }; 2565 * 2566 * void C::f() { } 2567 * \endcode 2568 * 2569 * In the out-of-line definition of \c C::f, the semantic parent is 2570 * the class \c C, of which this function is a member. The lexical parent is 2571 * the place where the declaration actually occurs in the source code; in this 2572 * case, the definition occurs in the translation unit. In general, the 2573 * lexical parent for a given entity can change without affecting the semantics 2574 * of the program, and the lexical parent of different declarations of the 2575 * same entity may be different. Changing the semantic parent of a declaration, 2576 * on the other hand, can have a major impact on semantics, and redeclarations 2577 * of a particular entity should all have the same semantic context. 2578 * 2579 * In the example above, both declarations of \c C::f have \c C as their 2580 * semantic context, while the lexical context of the first \c C::f is \c C 2581 * and the lexical context of the second \c C::f is the translation unit. 2582 * 2583 * For declarations written in the global scope, the lexical parent is 2584 * the translation unit. 2585 */ 2586 CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor); 2587 2588 /** 2589 * \brief Determine the set of methods that are overridden by the given 2590 * method. 2591 * 2592 * In both Objective-C and C++, a method (aka virtual member function, 2593 * in C++) can override a virtual method in a base class. For 2594 * Objective-C, a method is said to override any method in the class's 2595 * base class, its protocols, or its categories' protocols, that has the same 2596 * selector and is of the same kind (class or instance). 2597 * If no such method exists, the search continues to the class's superclass, 2598 * its protocols, and its categories, and so on. A method from an Objective-C 2599 * implementation is considered to override the same methods as its 2600 * corresponding method in the interface. 2601 * 2602 * For C++, a virtual member function overrides any virtual member 2603 * function with the same signature that occurs in its base 2604 * classes. With multiple inheritance, a virtual member function can 2605 * override several virtual member functions coming from different 2606 * base classes. 2607 * 2608 * In all cases, this function determines the immediate overridden 2609 * method, rather than all of the overridden methods. For example, if 2610 * a method is originally declared in a class A, then overridden in B 2611 * (which in inherits from A) and also in C (which inherited from B), 2612 * then the only overridden method returned from this function when 2613 * invoked on C's method will be B's method. The client may then 2614 * invoke this function again, given the previously-found overridden 2615 * methods, to map out the complete method-override set. 2616 * 2617 * \param cursor A cursor representing an Objective-C or C++ 2618 * method. This routine will compute the set of methods that this 2619 * method overrides. 2620 * 2621 * \param overridden A pointer whose pointee will be replaced with a 2622 * pointer to an array of cursors, representing the set of overridden 2623 * methods. If there are no overridden methods, the pointee will be 2624 * set to NULL. The pointee must be freed via a call to 2625 * \c clang_disposeOverriddenCursors(). 2626 * 2627 * \param num_overridden A pointer to the number of overridden 2628 * functions, will be set to the number of overridden functions in the 2629 * array pointed to by \p overridden. 2630 */ 2631 CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor, 2632 CXCursor **overridden, 2633 unsigned *num_overridden); 2634 2635 /** 2636 * \brief Free the set of overridden cursors returned by \c 2637 * clang_getOverriddenCursors(). 2638 */ 2639 CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden); 2640 2641 /** 2642 * \brief Retrieve the file that is included by the given inclusion directive 2643 * cursor. 2644 */ 2645 CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor); 2646 2647 /** 2648 * @} 2649 */ 2650 2651 /** 2652 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 2653 * 2654 * Cursors represent a location within the Abstract Syntax Tree (AST). These 2655 * routines help map between cursors and the physical locations where the 2656 * described entities occur in the source code. The mapping is provided in 2657 * both directions, so one can map from source code to the AST and back. 2658 * 2659 * @{ 2660 */ 2661 2662 /** 2663 * \brief Map a source location to the cursor that describes the entity at that 2664 * location in the source code. 2665 * 2666 * clang_getCursor() maps an arbitrary source location within a translation 2667 * unit down to the most specific cursor that describes the entity at that 2668 * location. For example, given an expression \c x + y, invoking 2669 * clang_getCursor() with a source location pointing to "x" will return the 2670 * cursor for "x"; similarly for "y". If the cursor points anywhere between 2671 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 2672 * will return a cursor referring to the "+" expression. 2673 * 2674 * \returns a cursor representing the entity at the given source location, or 2675 * a NULL cursor if no such entity can be found. 2676 */ 2677 CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 2678 2679 /** 2680 * \brief Retrieve the physical location of the source constructor referenced 2681 * by the given cursor. 2682 * 2683 * The location of a declaration is typically the location of the name of that 2684 * declaration, where the name of that declaration would occur if it is 2685 * unnamed, or some keyword that introduces that particular declaration. 2686 * The location of a reference is where that reference occurs within the 2687 * source code. 2688 */ 2689 CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); 2690 2691 /** 2692 * \brief Retrieve the physical extent of the source construct referenced by 2693 * the given cursor. 2694 * 2695 * The extent of a cursor starts with the file/line/column pointing at the 2696 * first character within the source construct that the cursor refers to and 2697 * ends with the last character within that source construct. For a 2698 * declaration, the extent covers the declaration itself. For a reference, 2699 * the extent covers the location of the reference (e.g., where the referenced 2700 * entity was actually used). 2701 */ 2702 CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); 2703 2704 /** 2705 * @} 2706 */ 2707 2708 /** 2709 * \defgroup CINDEX_TYPES Type information for CXCursors 2710 * 2711 * @{ 2712 */ 2713 2714 /** 2715 * \brief Describes the kind of type 2716 */ 2717 enum CXTypeKind { 2718 /** 2719 * \brief Represents an invalid type (e.g., where no type is available). 2720 */ 2721 CXType_Invalid = 0, 2722 2723 /** 2724 * \brief A type whose specific kind is not exposed via this 2725 * interface. 2726 */ 2727 CXType_Unexposed = 1, 2728 2729 /* Builtin types */ 2730 CXType_Void = 2, 2731 CXType_Bool = 3, 2732 CXType_Char_U = 4, 2733 CXType_UChar = 5, 2734 CXType_Char16 = 6, 2735 CXType_Char32 = 7, 2736 CXType_UShort = 8, 2737 CXType_UInt = 9, 2738 CXType_ULong = 10, 2739 CXType_ULongLong = 11, 2740 CXType_UInt128 = 12, 2741 CXType_Char_S = 13, 2742 CXType_SChar = 14, 2743 CXType_WChar = 15, 2744 CXType_Short = 16, 2745 CXType_Int = 17, 2746 CXType_Long = 18, 2747 CXType_LongLong = 19, 2748 CXType_Int128 = 20, 2749 CXType_Float = 21, 2750 CXType_Double = 22, 2751 CXType_LongDouble = 23, 2752 CXType_NullPtr = 24, 2753 CXType_Overload = 25, 2754 CXType_Dependent = 26, 2755 CXType_ObjCId = 27, 2756 CXType_ObjCClass = 28, 2757 CXType_ObjCSel = 29, 2758 CXType_FirstBuiltin = CXType_Void, 2759 CXType_LastBuiltin = CXType_ObjCSel, 2760 2761 CXType_Complex = 100, 2762 CXType_Pointer = 101, 2763 CXType_BlockPointer = 102, 2764 CXType_LValueReference = 103, 2765 CXType_RValueReference = 104, 2766 CXType_Record = 105, 2767 CXType_Enum = 106, 2768 CXType_Typedef = 107, 2769 CXType_ObjCInterface = 108, 2770 CXType_ObjCObjectPointer = 109, 2771 CXType_FunctionNoProto = 110, 2772 CXType_FunctionProto = 111, 2773 CXType_ConstantArray = 112, 2774 CXType_Vector = 113, 2775 CXType_IncompleteArray = 114, 2776 CXType_VariableArray = 115, 2777 CXType_DependentSizedArray = 116, 2778 CXType_MemberPointer = 117 2779 }; 2780 2781 /** 2782 * \brief Describes the calling convention of a function type 2783 */ 2784 enum CXCallingConv { 2785 CXCallingConv_Default = 0, 2786 CXCallingConv_C = 1, 2787 CXCallingConv_X86StdCall = 2, 2788 CXCallingConv_X86FastCall = 3, 2789 CXCallingConv_X86ThisCall = 4, 2790 CXCallingConv_X86Pascal = 5, 2791 CXCallingConv_AAPCS = 6, 2792 CXCallingConv_AAPCS_VFP = 7, 2793 CXCallingConv_PnaclCall = 8, 2794 CXCallingConv_IntelOclBicc = 9, 2795 CXCallingConv_X86_64Win64 = 10, 2796 CXCallingConv_X86_64SysV = 11, 2797 2798 CXCallingConv_Invalid = 100, 2799 CXCallingConv_Unexposed = 200 2800 }; 2801 2802 2803 /** 2804 * \brief The type of an element in the abstract syntax tree. 2805 * 2806 */ 2807 typedef struct { 2808 enum CXTypeKind kind; 2809 void *data[2]; 2810 } CXType; 2811 2812 /** 2813 * \brief Retrieve the type of a CXCursor (if any). 2814 */ 2815 CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); 2816 2817 /** 2818 * \brief Pretty-print the underlying type using the rules of the 2819 * language of the translation unit from which it came. 2820 * 2821 * If the type is invalid, an empty string is returned. 2822 */ 2823 CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT); 2824 2825 /** 2826 * \brief Retrieve the underlying type of a typedef declaration. 2827 * 2828 * If the cursor does not reference a typedef declaration, an invalid type is 2829 * returned. 2830 */ 2831 CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C); 2832 2833 /** 2834 * \brief Retrieve the integer type of an enum declaration. 2835 * 2836 * If the cursor does not reference an enum declaration, an invalid type is 2837 * returned. 2838 */ 2839 CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C); 2840 2841 /** 2842 * \brief Retrieve the integer value of an enum constant declaration as a signed 2843 * long long. 2844 * 2845 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned. 2846 * Since this is also potentially a valid constant value, the kind of the cursor 2847 * must be verified before calling this function. 2848 */ 2849 CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C); 2850 2851 /** 2852 * \brief Retrieve the integer value of an enum constant declaration as an unsigned 2853 * long long. 2854 * 2855 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned. 2856 * Since this is also potentially a valid constant value, the kind of the cursor 2857 * must be verified before calling this function. 2858 */ 2859 CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C); 2860 2861 /** 2862 * \brief Retrieve the bit width of a bit field declaration as an integer. 2863 * 2864 * If a cursor that is not a bit field declaration is passed in, -1 is returned. 2865 */ 2866 CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C); 2867 2868 /** 2869 * \brief Retrieve the number of non-variadic arguments associated with a given 2870 * cursor. 2871 * 2872 * The number of arguments can be determined for calls as well as for 2873 * declarations of functions or methods. For other cursors -1 is returned. 2874 */ 2875 CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C); 2876 2877 /** 2878 * \brief Retrieve the argument cursor of a function or method. 2879 * 2880 * The argument cursor can be determined for calls as well as for declarations 2881 * of functions or methods. For other cursors and for invalid indices, an 2882 * invalid cursor is returned. 2883 */ 2884 CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i); 2885 2886 /** 2887 * \brief Determine whether two CXTypes represent the same type. 2888 * 2889 * \returns non-zero if the CXTypes represent the same type and 2890 * zero otherwise. 2891 */ 2892 CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); 2893 2894 /** 2895 * \brief Return the canonical type for a CXType. 2896 * 2897 * Clang's type system explicitly models typedefs and all the ways 2898 * a specific type can be represented. The canonical type is the underlying 2899 * type with all the "sugar" removed. For example, if 'T' is a typedef 2900 * for 'int', the canonical type for 'T' would be 'int'. 2901 */ 2902 CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); 2903 2904 /** 2905 * \brief Determine whether a CXType has the "const" qualifier set, 2906 * without looking through typedefs that may have added "const" at a 2907 * different level. 2908 */ 2909 CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T); 2910 2911 /** 2912 * \brief Determine whether a CXType has the "volatile" qualifier set, 2913 * without looking through typedefs that may have added "volatile" at 2914 * a different level. 2915 */ 2916 CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T); 2917 2918 /** 2919 * \brief Determine whether a CXType has the "restrict" qualifier set, 2920 * without looking through typedefs that may have added "restrict" at a 2921 * different level. 2922 */ 2923 CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T); 2924 2925 /** 2926 * \brief For pointer types, returns the type of the pointee. 2927 */ 2928 CINDEX_LINKAGE CXType clang_getPointeeType(CXType T); 2929 2930 /** 2931 * \brief Return the cursor for the declaration of the given type. 2932 */ 2933 CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); 2934 2935 /** 2936 * Returns the Objective-C type encoding for the specified declaration. 2937 */ 2938 CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C); 2939 2940 /** 2941 * \brief Retrieve the spelling of a given CXTypeKind. 2942 */ 2943 CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); 2944 2945 /** 2946 * \brief Retrieve the calling convention associated with a function type. 2947 * 2948 * If a non-function type is passed in, CXCallingConv_Invalid is returned. 2949 */ 2950 CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T); 2951 2952 /** 2953 * \brief Retrieve the return type associated with a function type. 2954 * 2955 * If a non-function type is passed in, an invalid type is returned. 2956 */ 2957 CINDEX_LINKAGE CXType clang_getResultType(CXType T); 2958 2959 /** 2960 * \brief Retrieve the number of non-variadic parameters associated with a 2961 * function type. 2962 * 2963 * If a non-function type is passed in, -1 is returned. 2964 */ 2965 CINDEX_LINKAGE int clang_getNumArgTypes(CXType T); 2966 2967 /** 2968 * \brief Retrieve the type of a parameter of a function type. 2969 * 2970 * If a non-function type is passed in or the function does not have enough 2971 * parameters, an invalid type is returned. 2972 */ 2973 CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i); 2974 2975 /** 2976 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise. 2977 */ 2978 CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T); 2979 2980 /** 2981 * \brief Retrieve the return type associated with a given cursor. 2982 * 2983 * This only returns a valid type if the cursor refers to a function or method. 2984 */ 2985 CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); 2986 2987 /** 2988 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 2989 * otherwise. 2990 */ 2991 CINDEX_LINKAGE unsigned clang_isPODType(CXType T); 2992 2993 /** 2994 * \brief Return the element type of an array, complex, or vector type. 2995 * 2996 * If a type is passed in that is not an array, complex, or vector type, 2997 * an invalid type is returned. 2998 */ 2999 CINDEX_LINKAGE CXType clang_getElementType(CXType T); 3000 3001 /** 3002 * \brief Return the number of elements of an array or vector type. 3003 * 3004 * If a type is passed in that is not an array or vector type, 3005 * -1 is returned. 3006 */ 3007 CINDEX_LINKAGE long long clang_getNumElements(CXType T); 3008 3009 /** 3010 * \brief Return the element type of an array type. 3011 * 3012 * If a non-array type is passed in, an invalid type is returned. 3013 */ 3014 CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T); 3015 3016 /** 3017 * \brief Return the array size of a constant array. 3018 * 3019 * If a non-array type is passed in, -1 is returned. 3020 */ 3021 CINDEX_LINKAGE long long clang_getArraySize(CXType T); 3022 3023 /** 3024 * \brief List the possible error codes for \c clang_Type_getSizeOf, 3025 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and 3026 * \c clang_Cursor_getOffsetOf. 3027 * 3028 * A value of this enumeration type can be returned if the target type is not 3029 * a valid argument to sizeof, alignof or offsetof. 3030 */ 3031 enum CXTypeLayoutError { 3032 /** 3033 * \brief Type is of kind CXType_Invalid. 3034 */ 3035 CXTypeLayoutError_Invalid = -1, 3036 /** 3037 * \brief The type is an incomplete Type. 3038 */ 3039 CXTypeLayoutError_Incomplete = -2, 3040 /** 3041 * \brief The type is a dependent Type. 3042 */ 3043 CXTypeLayoutError_Dependent = -3, 3044 /** 3045 * \brief The type is not a constant size type. 3046 */ 3047 CXTypeLayoutError_NotConstantSize = -4, 3048 /** 3049 * \brief The Field name is not valid for this record. 3050 */ 3051 CXTypeLayoutError_InvalidFieldName = -5 3052 }; 3053 3054 /** 3055 * \brief Return the alignment of a type in bytes as per C++[expr.alignof] 3056 * standard. 3057 * 3058 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. 3059 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete 3060 * is returned. 3061 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is 3062 * returned. 3063 * If the type declaration is not a constant size type, 3064 * CXTypeLayoutError_NotConstantSize is returned. 3065 */ 3066 CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T); 3067 3068 /** 3069 * \brief Return the class type of an member pointer type. 3070 * 3071 * If a non-member-pointer type is passed in, an invalid type is returned. 3072 */ 3073 CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T); 3074 3075 /** 3076 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard. 3077 * 3078 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. 3079 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete 3080 * is returned. 3081 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is 3082 * returned. 3083 */ 3084 CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T); 3085 3086 /** 3087 * \brief Return the offset of a field named S in a record of type T in bits 3088 * as it would be returned by __offsetof__ as per C++11[18.2p4] 3089 * 3090 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid 3091 * is returned. 3092 * If the field's type declaration is an incomplete type, 3093 * CXTypeLayoutError_Incomplete is returned. 3094 * If the field's type declaration is a dependent type, 3095 * CXTypeLayoutError_Dependent is returned. 3096 * If the field's name S is not found, 3097 * CXTypeLayoutError_InvalidFieldName is returned. 3098 */ 3099 CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S); 3100 3101 enum CXRefQualifierKind { 3102 /** \brief No ref-qualifier was provided. */ 3103 CXRefQualifier_None = 0, 3104 /** \brief An lvalue ref-qualifier was provided (\c &). */ 3105 CXRefQualifier_LValue, 3106 /** \brief An rvalue ref-qualifier was provided (\c &&). */ 3107 CXRefQualifier_RValue 3108 }; 3109 3110 /** 3111 * \brief Returns the number of template arguments for given class template 3112 * specialization, or -1 if type \c T is not a class template specialization. 3113 * 3114 * Variadic argument packs count as only one argument, and can not be inspected 3115 * further. 3116 */ 3117 CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T); 3118 3119 /** 3120 * \brief Returns the type template argument of a template class specialization 3121 * at given index. 3122 * 3123 * This function only returns template type arguments and does not handle 3124 * template template arguments or variadic packs. 3125 */ 3126 CINDEX_LINKAGE CXType clang_Type_getTemplateArgumentAsType(CXType T, unsigned i); 3127 3128 /** 3129 * \brief Retrieve the ref-qualifier kind of a function or method. 3130 * 3131 * The ref-qualifier is returned for C++ functions or methods. For other types 3132 * or non-C++ declarations, CXRefQualifier_None is returned. 3133 */ 3134 CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T); 3135 3136 /** 3137 * \brief Returns non-zero if the cursor specifies a Record member that is a 3138 * bitfield. 3139 */ 3140 CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C); 3141 3142 /** 3143 * \brief Returns 1 if the base class specified by the cursor with kind 3144 * CX_CXXBaseSpecifier is virtual. 3145 */ 3146 CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor); 3147 3148 /** 3149 * \brief Represents the C++ access control level to a base class for a 3150 * cursor with kind CX_CXXBaseSpecifier. 3151 */ 3152 enum CX_CXXAccessSpecifier { 3153 CX_CXXInvalidAccessSpecifier, 3154 CX_CXXPublic, 3155 CX_CXXProtected, 3156 CX_CXXPrivate 3157 }; 3158 3159 /** 3160 * \brief Returns the access control level for the referenced object. 3161 * 3162 * If the cursor refers to a C++ declaration, its access control level within its 3163 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or 3164 * access specifier, the specifier itself is returned. 3165 */ 3166 CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor); 3167 3168 /** 3169 * \brief Determine the number of overloaded declarations referenced by a 3170 * \c CXCursor_OverloadedDeclRef cursor. 3171 * 3172 * \param cursor The cursor whose overloaded declarations are being queried. 3173 * 3174 * \returns The number of overloaded declarations referenced by \c cursor. If it 3175 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0. 3176 */ 3177 CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor); 3178 3179 /** 3180 * \brief Retrieve a cursor for one of the overloaded declarations referenced 3181 * by a \c CXCursor_OverloadedDeclRef cursor. 3182 * 3183 * \param cursor The cursor whose overloaded declarations are being queried. 3184 * 3185 * \param index The zero-based index into the set of overloaded declarations in 3186 * the cursor. 3187 * 3188 * \returns A cursor representing the declaration referenced by the given 3189 * \c cursor at the specified \c index. If the cursor does not have an 3190 * associated set of overloaded declarations, or if the index is out of bounds, 3191 * returns \c clang_getNullCursor(); 3192 */ 3193 CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor, 3194 unsigned index); 3195 3196 /** 3197 * @} 3198 */ 3199 3200 /** 3201 * \defgroup CINDEX_ATTRIBUTES Information for attributes 3202 * 3203 * @{ 3204 */ 3205 3206 3207 /** 3208 * \brief For cursors representing an iboutletcollection attribute, 3209 * this function returns the collection element type. 3210 * 3211 */ 3212 CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor); 3213 3214 /** 3215 * @} 3216 */ 3217 3218 /** 3219 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 3220 * 3221 * These routines provide the ability to traverse the abstract syntax tree 3222 * using cursors. 3223 * 3224 * @{ 3225 */ 3226 3227 /** 3228 * \brief Describes how the traversal of the children of a particular 3229 * cursor should proceed after visiting a particular child cursor. 3230 * 3231 * A value of this enumeration type should be returned by each 3232 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 3233 */ 3234 enum CXChildVisitResult { 3235 /** 3236 * \brief Terminates the cursor traversal. 3237 */ 3238 CXChildVisit_Break, 3239 /** 3240 * \brief Continues the cursor traversal with the next sibling of 3241 * the cursor just visited, without visiting its children. 3242 */ 3243 CXChildVisit_Continue, 3244 /** 3245 * \brief Recursively traverse the children of this cursor, using 3246 * the same visitor and client data. 3247 */ 3248 CXChildVisit_Recurse 3249 }; 3250 3251 /** 3252 * \brief Visitor invoked for each cursor found by a traversal. 3253 * 3254 * This visitor function will be invoked for each cursor found by 3255 * clang_visitCursorChildren(). Its first argument is the cursor being 3256 * visited, its second argument is the parent visitor for that cursor, 3257 * and its third argument is the client data provided to 3258 * clang_visitCursorChildren(). 3259 * 3260 * The visitor should return one of the \c CXChildVisitResult values 3261 * to direct clang_visitCursorChildren(). 3262 */ 3263 typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, 3264 CXCursor parent, 3265 CXClientData client_data); 3266 3267 /** 3268 * \brief Visit the children of a particular cursor. 3269 * 3270 * This function visits all the direct children of the given cursor, 3271 * invoking the given \p visitor function with the cursors of each 3272 * visited child. The traversal may be recursive, if the visitor returns 3273 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 3274 * the visitor returns \c CXChildVisit_Break. 3275 * 3276 * \param parent the cursor whose child may be visited. All kinds of 3277 * cursors can be visited, including invalid cursors (which, by 3278 * definition, have no children). 3279 * 3280 * \param visitor the visitor function that will be invoked for each 3281 * child of \p parent. 3282 * 3283 * \param client_data pointer data supplied by the client, which will 3284 * be passed to the visitor each time it is invoked. 3285 * 3286 * \returns a non-zero value if the traversal was terminated 3287 * prematurely by the visitor returning \c CXChildVisit_Break. 3288 */ 3289 CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, 3290 CXCursorVisitor visitor, 3291 CXClientData client_data); 3292 #ifdef __has_feature 3293 # if __has_feature(blocks) 3294 /** 3295 * \brief Visitor invoked for each cursor found by a traversal. 3296 * 3297 * This visitor block will be invoked for each cursor found by 3298 * clang_visitChildrenWithBlock(). Its first argument is the cursor being 3299 * visited, its second argument is the parent visitor for that cursor. 3300 * 3301 * The visitor should return one of the \c CXChildVisitResult values 3302 * to direct clang_visitChildrenWithBlock(). 3303 */ 3304 typedef enum CXChildVisitResult 3305 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent); 3306 3307 /** 3308 * Visits the children of a cursor using the specified block. Behaves 3309 * identically to clang_visitChildren() in all other respects. 3310 */ 3311 unsigned clang_visitChildrenWithBlock(CXCursor parent, 3312 CXCursorVisitorBlock block); 3313 # endif 3314 #endif 3315 3316 /** 3317 * @} 3318 */ 3319 3320 /** 3321 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 3322 * 3323 * These routines provide the ability to determine references within and 3324 * across translation units, by providing the names of the entities referenced 3325 * by cursors, follow reference cursors to the declarations they reference, 3326 * and associate declarations with their definitions. 3327 * 3328 * @{ 3329 */ 3330 3331 /** 3332 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 3333 * by the given cursor. 3334 * 3335 * A Unified Symbol Resolution (USR) is a string that identifies a particular 3336 * entity (function, class, variable, etc.) within a program. USRs can be 3337 * compared across translation units to determine, e.g., when references in 3338 * one translation refer to an entity defined in another translation unit. 3339 */ 3340 CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); 3341 3342 /** 3343 * \brief Construct a USR for a specified Objective-C class. 3344 */ 3345 CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); 3346 3347 /** 3348 * \brief Construct a USR for a specified Objective-C category. 3349 */ 3350 CINDEX_LINKAGE CXString 3351 clang_constructUSR_ObjCCategory(const char *class_name, 3352 const char *category_name); 3353 3354 /** 3355 * \brief Construct a USR for a specified Objective-C protocol. 3356 */ 3357 CINDEX_LINKAGE CXString 3358 clang_constructUSR_ObjCProtocol(const char *protocol_name); 3359 3360 3361 /** 3362 * \brief Construct a USR for a specified Objective-C instance variable and 3363 * the USR for its containing class. 3364 */ 3365 CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, 3366 CXString classUSR); 3367 3368 /** 3369 * \brief Construct a USR for a specified Objective-C method and 3370 * the USR for its containing class. 3371 */ 3372 CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, 3373 unsigned isInstanceMethod, 3374 CXString classUSR); 3375 3376 /** 3377 * \brief Construct a USR for a specified Objective-C property and the USR 3378 * for its containing class. 3379 */ 3380 CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, 3381 CXString classUSR); 3382 3383 /** 3384 * \brief Retrieve a name for the entity referenced by this cursor. 3385 */ 3386 CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); 3387 3388 /** 3389 * \brief Retrieve a range for a piece that forms the cursors spelling name. 3390 * Most of the times there is only one range for the complete spelling but for 3391 * Objective-C methods and Objective-C message expressions, there are multiple 3392 * pieces for each selector identifier. 3393 * 3394 * \param pieceIndex the index of the spelling name piece. If this is greater 3395 * than the actual number of pieces, it will return a NULL (invalid) range. 3396 * 3397 * \param options Reserved. 3398 */ 3399 CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor, 3400 unsigned pieceIndex, 3401 unsigned options); 3402 3403 /** 3404 * \brief Retrieve the display name for the entity referenced by this cursor. 3405 * 3406 * The display name contains extra information that helps identify the cursor, 3407 * such as the parameters of a function or template or the arguments of a 3408 * class template specialization. 3409 */ 3410 CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor); 3411 3412 /** \brief For a cursor that is a reference, retrieve a cursor representing the 3413 * entity that it references. 3414 * 3415 * Reference cursors refer to other entities in the AST. For example, an 3416 * Objective-C superclass reference cursor refers to an Objective-C class. 3417 * This function produces the cursor for the Objective-C class from the 3418 * cursor for the superclass reference. If the input cursor is a declaration or 3419 * definition, it returns that declaration or definition unchanged. 3420 * Otherwise, returns the NULL cursor. 3421 */ 3422 CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); 3423 3424 /** 3425 * \brief For a cursor that is either a reference to or a declaration 3426 * of some entity, retrieve a cursor that describes the definition of 3427 * that entity. 3428 * 3429 * Some entities can be declared multiple times within a translation 3430 * unit, but only one of those declarations can also be a 3431 * definition. For example, given: 3432 * 3433 * \code 3434 * int f(int, int); 3435 * int g(int x, int y) { return f(x, y); } 3436 * int f(int a, int b) { return a + b; } 3437 * int f(int, int); 3438 * \endcode 3439 * 3440 * there are three declarations of the function "f", but only the 3441 * second one is a definition. The clang_getCursorDefinition() 3442 * function will take any cursor pointing to a declaration of "f" 3443 * (the first or fourth lines of the example) or a cursor referenced 3444 * that uses "f" (the call to "f' inside "g") and will return a 3445 * declaration cursor pointing to the definition (the second "f" 3446 * declaration). 3447 * 3448 * If given a cursor for which there is no corresponding definition, 3449 * e.g., because there is no definition of that entity within this 3450 * translation unit, returns a NULL cursor. 3451 */ 3452 CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); 3453 3454 /** 3455 * \brief Determine whether the declaration pointed to by this cursor 3456 * is also a definition of that entity. 3457 */ 3458 CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); 3459 3460 /** 3461 * \brief Retrieve the canonical cursor corresponding to the given cursor. 3462 * 3463 * In the C family of languages, many kinds of entities can be declared several 3464 * times within a single translation unit. For example, a structure type can 3465 * be forward-declared (possibly multiple times) and later defined: 3466 * 3467 * \code 3468 * struct X; 3469 * struct X; 3470 * struct X { 3471 * int member; 3472 * }; 3473 * \endcode 3474 * 3475 * The declarations and the definition of \c X are represented by three 3476 * different cursors, all of which are declarations of the same underlying 3477 * entity. One of these cursor is considered the "canonical" cursor, which 3478 * is effectively the representative for the underlying entity. One can 3479 * determine if two cursors are declarations of the same underlying entity by 3480 * comparing their canonical cursors. 3481 * 3482 * \returns The canonical cursor for the entity referred to by the given cursor. 3483 */ 3484 CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor); 3485 3486 3487 /** 3488 * \brief If the cursor points to a selector identifier in an Objective-C 3489 * method or message expression, this returns the selector index. 3490 * 3491 * After getting a cursor with #clang_getCursor, this can be called to 3492 * determine if the location points to a selector identifier. 3493 * 3494 * \returns The selector index if the cursor is an Objective-C method or message 3495 * expression and the cursor is pointing to a selector identifier, or -1 3496 * otherwise. 3497 */ 3498 CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor); 3499 3500 /** 3501 * \brief Given a cursor pointing to a C++ method call or an Objective-C 3502 * message, returns non-zero if the method/message is "dynamic", meaning: 3503 * 3504 * For a C++ method: the call is virtual. 3505 * For an Objective-C message: the receiver is an object instance, not 'super' 3506 * or a specific class. 3507 * 3508 * If the method/message is "static" or the cursor does not point to a 3509 * method/message, it will return zero. 3510 */ 3511 CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C); 3512 3513 /** 3514 * \brief Given a cursor pointing to an Objective-C message, returns the CXType 3515 * of the receiver. 3516 */ 3517 CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C); 3518 3519 /** 3520 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl. 3521 */ 3522 typedef enum { 3523 CXObjCPropertyAttr_noattr = 0x00, 3524 CXObjCPropertyAttr_readonly = 0x01, 3525 CXObjCPropertyAttr_getter = 0x02, 3526 CXObjCPropertyAttr_assign = 0x04, 3527 CXObjCPropertyAttr_readwrite = 0x08, 3528 CXObjCPropertyAttr_retain = 0x10, 3529 CXObjCPropertyAttr_copy = 0x20, 3530 CXObjCPropertyAttr_nonatomic = 0x40, 3531 CXObjCPropertyAttr_setter = 0x80, 3532 CXObjCPropertyAttr_atomic = 0x100, 3533 CXObjCPropertyAttr_weak = 0x200, 3534 CXObjCPropertyAttr_strong = 0x400, 3535 CXObjCPropertyAttr_unsafe_unretained = 0x800 3536 } CXObjCPropertyAttrKind; 3537 3538 /** 3539 * \brief Given a cursor that represents a property declaration, return the 3540 * associated property attributes. The bits are formed from 3541 * \c CXObjCPropertyAttrKind. 3542 * 3543 * \param reserved Reserved for future use, pass 0. 3544 */ 3545 CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, 3546 unsigned reserved); 3547 3548 /** 3549 * \brief 'Qualifiers' written next to the return and parameter types in 3550 * Objective-C method declarations. 3551 */ 3552 typedef enum { 3553 CXObjCDeclQualifier_None = 0x0, 3554 CXObjCDeclQualifier_In = 0x1, 3555 CXObjCDeclQualifier_Inout = 0x2, 3556 CXObjCDeclQualifier_Out = 0x4, 3557 CXObjCDeclQualifier_Bycopy = 0x8, 3558 CXObjCDeclQualifier_Byref = 0x10, 3559 CXObjCDeclQualifier_Oneway = 0x20 3560 } CXObjCDeclQualifierKind; 3561 3562 /** 3563 * \brief Given a cursor that represents an Objective-C method or parameter 3564 * declaration, return the associated Objective-C qualifiers for the return 3565 * type or the parameter respectively. The bits are formed from 3566 * CXObjCDeclQualifierKind. 3567 */ 3568 CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C); 3569 3570 /** 3571 * \brief Given a cursor that represents an Objective-C method or property 3572 * declaration, return non-zero if the declaration was affected by "@optional". 3573 * Returns zero if the cursor is not such a declaration or it is "@required". 3574 */ 3575 CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C); 3576 3577 /** 3578 * \brief Returns non-zero if the given cursor is a variadic function or method. 3579 */ 3580 CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C); 3581 3582 /** 3583 * \brief Given a cursor that represents a declaration, return the associated 3584 * comment's source range. The range may include multiple consecutive comments 3585 * with whitespace in between. 3586 */ 3587 CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C); 3588 3589 /** 3590 * \brief Given a cursor that represents a declaration, return the associated 3591 * comment text, including comment markers. 3592 */ 3593 CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C); 3594 3595 /** 3596 * \brief Given a cursor that represents a documentable entity (e.g., 3597 * declaration), return the associated \\brief paragraph; otherwise return the 3598 * first paragraph. 3599 */ 3600 CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C); 3601 3602 /** 3603 * @} 3604 */ 3605 3606 /** 3607 * \defgroup CINDEX_MODULE Module introspection 3608 * 3609 * The functions in this group provide access to information about modules. 3610 * 3611 * @{ 3612 */ 3613 3614 typedef void *CXModule; 3615 3616 /** 3617 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module. 3618 */ 3619 CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C); 3620 3621 /** 3622 * \brief Given a CXFile header file, return the module that contains it, if one 3623 * exists. 3624 */ 3625 CINDEX_LINKAGE CXModule clang_getModuleForFile(CXTranslationUnit, CXFile); 3626 3627 /** 3628 * \param Module a module object. 3629 * 3630 * \returns the module file where the provided module object came from. 3631 */ 3632 CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module); 3633 3634 /** 3635 * \param Module a module object. 3636 * 3637 * \returns the parent of a sub-module or NULL if the given module is top-level, 3638 * e.g. for 'std.vector' it will return the 'std' module. 3639 */ 3640 CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module); 3641 3642 /** 3643 * \param Module a module object. 3644 * 3645 * \returns the name of the module, e.g. for the 'std.vector' sub-module it 3646 * will return "vector". 3647 */ 3648 CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module); 3649 3650 /** 3651 * \param Module a module object. 3652 * 3653 * \returns the full name of the module, e.g. "std.vector". 3654 */ 3655 CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module); 3656 3657 /** 3658 * \param Module a module object. 3659 * 3660 * \returns non-zero if the module is a system one. 3661 */ 3662 CINDEX_LINKAGE int clang_Module_isSystem(CXModule Module); 3663 3664 /** 3665 * \param Module a module object. 3666 * 3667 * \returns the number of top level headers associated with this module. 3668 */ 3669 CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit, 3670 CXModule Module); 3671 3672 /** 3673 * \param Module a module object. 3674 * 3675 * \param Index top level header index (zero-based). 3676 * 3677 * \returns the specified top level header associated with the module. 3678 */ 3679 CINDEX_LINKAGE 3680 CXFile clang_Module_getTopLevelHeader(CXTranslationUnit, 3681 CXModule Module, unsigned Index); 3682 3683 /** 3684 * @} 3685 */ 3686 3687 /** 3688 * \defgroup CINDEX_CPP C++ AST introspection 3689 * 3690 * The routines in this group provide access information in the ASTs specific 3691 * to C++ language features. 3692 * 3693 * @{ 3694 */ 3695 3696 /** 3697 * \brief Determine if a C++ member function or member function template is 3698 * pure virtual. 3699 */ 3700 CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C); 3701 3702 /** 3703 * \brief Determine if a C++ member function or member function template is 3704 * declared 'static'. 3705 */ 3706 CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); 3707 3708 /** 3709 * \brief Determine if a C++ member function or member function template is 3710 * explicitly declared 'virtual' or if it overrides a virtual method from 3711 * one of the base classes. 3712 */ 3713 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C); 3714 3715 /** 3716 * \brief Determine if a C++ member function or member function template is 3717 * declared 'const'. 3718 */ 3719 CINDEX_LINKAGE unsigned clang_CXXMethod_isConst(CXCursor C); 3720 3721 /** 3722 * \brief Given a cursor that represents a template, determine 3723 * the cursor kind of the specializations would be generated by instantiating 3724 * the template. 3725 * 3726 * This routine can be used to determine what flavor of function template, 3727 * class template, or class template partial specialization is stored in the 3728 * cursor. For example, it can describe whether a class template cursor is 3729 * declared with "struct", "class" or "union". 3730 * 3731 * \param C The cursor to query. This cursor should represent a template 3732 * declaration. 3733 * 3734 * \returns The cursor kind of the specializations that would be generated 3735 * by instantiating the template \p C. If \p C is not a template, returns 3736 * \c CXCursor_NoDeclFound. 3737 */ 3738 CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C); 3739 3740 /** 3741 * \brief Given a cursor that may represent a specialization or instantiation 3742 * of a template, retrieve the cursor that represents the template that it 3743 * specializes or from which it was instantiated. 3744 * 3745 * This routine determines the template involved both for explicit 3746 * specializations of templates and for implicit instantiations of the template, 3747 * both of which are referred to as "specializations". For a class template 3748 * specialization (e.g., \c std::vector<bool>), this routine will return 3749 * either the primary template (\c std::vector) or, if the specialization was 3750 * instantiated from a class template partial specialization, the class template 3751 * partial specialization. For a class template partial specialization and a 3752 * function template specialization (including instantiations), this 3753 * this routine will return the specialized template. 3754 * 3755 * For members of a class template (e.g., member functions, member classes, or 3756 * static data members), returns the specialized or instantiated member. 3757 * Although not strictly "templates" in the C++ language, members of class 3758 * templates have the same notions of specializations and instantiations that 3759 * templates do, so this routine treats them similarly. 3760 * 3761 * \param C A cursor that may be a specialization of a template or a member 3762 * of a template. 3763 * 3764 * \returns If the given cursor is a specialization or instantiation of a 3765 * template or a member thereof, the template or member that it specializes or 3766 * from which it was instantiated. Otherwise, returns a NULL cursor. 3767 */ 3768 CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C); 3769 3770 /** 3771 * \brief Given a cursor that references something else, return the source range 3772 * covering that reference. 3773 * 3774 * \param C A cursor pointing to a member reference, a declaration reference, or 3775 * an operator call. 3776 * \param NameFlags A bitset with three independent flags: 3777 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and 3778 * CXNameRange_WantSinglePiece. 3779 * \param PieceIndex For contiguous names or when passing the flag 3780 * CXNameRange_WantSinglePiece, only one piece with index 0 is 3781 * available. When the CXNameRange_WantSinglePiece flag is not passed for a 3782 * non-contiguous names, this index can be used to retrieve the individual 3783 * pieces of the name. See also CXNameRange_WantSinglePiece. 3784 * 3785 * \returns The piece of the name pointed to by the given cursor. If there is no 3786 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned. 3787 */ 3788 CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, 3789 unsigned NameFlags, 3790 unsigned PieceIndex); 3791 3792 enum CXNameRefFlags { 3793 /** 3794 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the 3795 * range. 3796 */ 3797 CXNameRange_WantQualifier = 0x1, 3798 3799 /** 3800 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>, 3801 * in the range. 3802 */ 3803 CXNameRange_WantTemplateArgs = 0x2, 3804 3805 /** 3806 * \brief If the name is non-contiguous, return the full spanning range. 3807 * 3808 * Non-contiguous names occur in Objective-C when a selector with two or more 3809 * parameters is used, or in C++ when using an operator: 3810 * \code 3811 * [object doSomething:here withValue:there]; // Objective-C 3812 * return some_vector[1]; // C++ 3813 * \endcode 3814 */ 3815 CXNameRange_WantSinglePiece = 0x4 3816 }; 3817 3818 /** 3819 * @} 3820 */ 3821 3822 /** 3823 * \defgroup CINDEX_LEX Token extraction and manipulation 3824 * 3825 * The routines in this group provide access to the tokens within a 3826 * translation unit, along with a semantic mapping of those tokens to 3827 * their corresponding cursors. 3828 * 3829 * @{ 3830 */ 3831 3832 /** 3833 * \brief Describes a kind of token. 3834 */ 3835 typedef enum CXTokenKind { 3836 /** 3837 * \brief A token that contains some kind of punctuation. 3838 */ 3839 CXToken_Punctuation, 3840 3841 /** 3842 * \brief A language keyword. 3843 */ 3844 CXToken_Keyword, 3845 3846 /** 3847 * \brief An identifier (that is not a keyword). 3848 */ 3849 CXToken_Identifier, 3850 3851 /** 3852 * \brief A numeric, string, or character literal. 3853 */ 3854 CXToken_Literal, 3855 3856 /** 3857 * \brief A comment. 3858 */ 3859 CXToken_Comment 3860 } CXTokenKind; 3861 3862 /** 3863 * \brief Describes a single preprocessing token. 3864 */ 3865 typedef struct { 3866 unsigned int_data[4]; 3867 void *ptr_data; 3868 } CXToken; 3869 3870 /** 3871 * \brief Determine the kind of the given token. 3872 */ 3873 CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); 3874 3875 /** 3876 * \brief Determine the spelling of the given token. 3877 * 3878 * The spelling of a token is the textual representation of that token, e.g., 3879 * the text of an identifier or keyword. 3880 */ 3881 CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 3882 3883 /** 3884 * \brief Retrieve the source location of the given token. 3885 */ 3886 CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, 3887 CXToken); 3888 3889 /** 3890 * \brief Retrieve a source range that covers the given token. 3891 */ 3892 CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 3893 3894 /** 3895 * \brief Tokenize the source code described by the given range into raw 3896 * lexical tokens. 3897 * 3898 * \param TU the translation unit whose text is being tokenized. 3899 * 3900 * \param Range the source range in which text should be tokenized. All of the 3901 * tokens produced by tokenization will fall within this source range, 3902 * 3903 * \param Tokens this pointer will be set to point to the array of tokens 3904 * that occur within the given source range. The returned pointer must be 3905 * freed with clang_disposeTokens() before the translation unit is destroyed. 3906 * 3907 * \param NumTokens will be set to the number of tokens in the \c *Tokens 3908 * array. 3909 * 3910 */ 3911 CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, 3912 CXToken **Tokens, unsigned *NumTokens); 3913 3914 /** 3915 * \brief Annotate the given set of tokens by providing cursors for each token 3916 * that can be mapped to a specific entity within the abstract syntax tree. 3917 * 3918 * This token-annotation routine is equivalent to invoking 3919 * clang_getCursor() for the source locations of each of the 3920 * tokens. The cursors provided are filtered, so that only those 3921 * cursors that have a direct correspondence to the token are 3922 * accepted. For example, given a function call \c f(x), 3923 * clang_getCursor() would provide the following cursors: 3924 * 3925 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 3926 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 3927 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 3928 * 3929 * Only the first and last of these cursors will occur within the 3930 * annotate, since the tokens "f" and "x' directly refer to a function 3931 * and a variable, respectively, but the parentheses are just a small 3932 * part of the full syntax of the function call expression, which is 3933 * not provided as an annotation. 3934 * 3935 * \param TU the translation unit that owns the given tokens. 3936 * 3937 * \param Tokens the set of tokens to annotate. 3938 * 3939 * \param NumTokens the number of tokens in \p Tokens. 3940 * 3941 * \param Cursors an array of \p NumTokens cursors, whose contents will be 3942 * replaced with the cursors corresponding to each token. 3943 */ 3944 CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, 3945 CXToken *Tokens, unsigned NumTokens, 3946 CXCursor *Cursors); 3947 3948 /** 3949 * \brief Free the given set of tokens. 3950 */ 3951 CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, 3952 CXToken *Tokens, unsigned NumTokens); 3953 3954 /** 3955 * @} 3956 */ 3957 3958 /** 3959 * \defgroup CINDEX_DEBUG Debugging facilities 3960 * 3961 * These routines are used for testing and debugging, only, and should not 3962 * be relied upon. 3963 * 3964 * @{ 3965 */ 3966 3967 /* for debug/testing */ 3968 CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); 3969 CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, 3970 const char **startBuf, 3971 const char **endBuf, 3972 unsigned *startLine, 3973 unsigned *startColumn, 3974 unsigned *endLine, 3975 unsigned *endColumn); 3976 CINDEX_LINKAGE void clang_enableStackTraces(void); 3977 CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data, 3978 unsigned stack_size); 3979 3980 /** 3981 * @} 3982 */ 3983 3984 /** 3985 * \defgroup CINDEX_CODE_COMPLET Code completion 3986 * 3987 * Code completion involves taking an (incomplete) source file, along with 3988 * knowledge of where the user is actively editing that file, and suggesting 3989 * syntactically- and semantically-valid constructs that the user might want to 3990 * use at that particular point in the source code. These data structures and 3991 * routines provide support for code completion. 3992 * 3993 * @{ 3994 */ 3995 3996 /** 3997 * \brief A semantic string that describes a code-completion result. 3998 * 3999 * A semantic string that describes the formatting of a code-completion 4000 * result as a single "template" of text that should be inserted into the 4001 * source buffer when a particular code-completion result is selected. 4002 * Each semantic string is made up of some number of "chunks", each of which 4003 * contains some text along with a description of what that text means, e.g., 4004 * the name of the entity being referenced, whether the text chunk is part of 4005 * the template, or whether it is a "placeholder" that the user should replace 4006 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 4007 * description of the different kinds of chunks. 4008 */ 4009 typedef void *CXCompletionString; 4010 4011 /** 4012 * \brief A single result of code completion. 4013 */ 4014 typedef struct { 4015 /** 4016 * \brief The kind of entity that this completion refers to. 4017 * 4018 * The cursor kind will be a macro, keyword, or a declaration (one of the 4019 * *Decl cursor kinds), describing the entity that the completion is 4020 * referring to. 4021 * 4022 * \todo In the future, we would like to provide a full cursor, to allow 4023 * the client to extract additional information from declaration. 4024 */ 4025 enum CXCursorKind CursorKind; 4026 4027 /** 4028 * \brief The code-completion string that describes how to insert this 4029 * code-completion result into the editing buffer. 4030 */ 4031 CXCompletionString CompletionString; 4032 } CXCompletionResult; 4033 4034 /** 4035 * \brief Describes a single piece of text within a code-completion string. 4036 * 4037 * Each "chunk" within a code-completion string (\c CXCompletionString) is 4038 * either a piece of text with a specific "kind" that describes how that text 4039 * should be interpreted by the client or is another completion string. 4040 */ 4041 enum CXCompletionChunkKind { 4042 /** 4043 * \brief A code-completion string that describes "optional" text that 4044 * could be a part of the template (but is not required). 4045 * 4046 * The Optional chunk is the only kind of chunk that has a code-completion 4047 * string for its representation, which is accessible via 4048 * \c clang_getCompletionChunkCompletionString(). The code-completion string 4049 * describes an additional part of the template that is completely optional. 4050 * For example, optional chunks can be used to describe the placeholders for 4051 * arguments that match up with defaulted function parameters, e.g. given: 4052 * 4053 * \code 4054 * void f(int x, float y = 3.14, double z = 2.71828); 4055 * \endcode 4056 * 4057 * The code-completion string for this function would contain: 4058 * - a TypedText chunk for "f". 4059 * - a LeftParen chunk for "(". 4060 * - a Placeholder chunk for "int x" 4061 * - an Optional chunk containing the remaining defaulted arguments, e.g., 4062 * - a Comma chunk for "," 4063 * - a Placeholder chunk for "float y" 4064 * - an Optional chunk containing the last defaulted argument: 4065 * - a Comma chunk for "," 4066 * - a Placeholder chunk for "double z" 4067 * - a RightParen chunk for ")" 4068 * 4069 * There are many ways to handle Optional chunks. Two simple approaches are: 4070 * - Completely ignore optional chunks, in which case the template for the 4071 * function "f" would only include the first parameter ("int x"). 4072 * - Fully expand all optional chunks, in which case the template for the 4073 * function "f" would have all of the parameters. 4074 */ 4075 CXCompletionChunk_Optional, 4076 /** 4077 * \brief Text that a user would be expected to type to get this 4078 * code-completion result. 4079 * 4080 * There will be exactly one "typed text" chunk in a semantic string, which 4081 * will typically provide the spelling of a keyword or the name of a 4082 * declaration that could be used at the current code point. Clients are 4083 * expected to filter the code-completion results based on the text in this 4084 * chunk. 4085 */ 4086 CXCompletionChunk_TypedText, 4087 /** 4088 * \brief Text that should be inserted as part of a code-completion result. 4089 * 4090 * A "text" chunk represents text that is part of the template to be 4091 * inserted into user code should this particular code-completion result 4092 * be selected. 4093 */ 4094 CXCompletionChunk_Text, 4095 /** 4096 * \brief Placeholder text that should be replaced by the user. 4097 * 4098 * A "placeholder" chunk marks a place where the user should insert text 4099 * into the code-completion template. For example, placeholders might mark 4100 * the function parameters for a function declaration, to indicate that the 4101 * user should provide arguments for each of those parameters. The actual 4102 * text in a placeholder is a suggestion for the text to display before 4103 * the user replaces the placeholder with real code. 4104 */ 4105 CXCompletionChunk_Placeholder, 4106 /** 4107 * \brief Informative text that should be displayed but never inserted as 4108 * part of the template. 4109 * 4110 * An "informative" chunk contains annotations that can be displayed to 4111 * help the user decide whether a particular code-completion result is the 4112 * right option, but which is not part of the actual template to be inserted 4113 * by code completion. 4114 */ 4115 CXCompletionChunk_Informative, 4116 /** 4117 * \brief Text that describes the current parameter when code-completion is 4118 * referring to function call, message send, or template specialization. 4119 * 4120 * A "current parameter" chunk occurs when code-completion is providing 4121 * information about a parameter corresponding to the argument at the 4122 * code-completion point. For example, given a function 4123 * 4124 * \code 4125 * int add(int x, int y); 4126 * \endcode 4127 * 4128 * and the source code \c add(, where the code-completion point is after the 4129 * "(", the code-completion string will contain a "current parameter" chunk 4130 * for "int x", indicating that the current argument will initialize that 4131 * parameter. After typing further, to \c add(17, (where the code-completion 4132 * point is after the ","), the code-completion string will contain a 4133 * "current paremeter" chunk to "int y". 4134 */ 4135 CXCompletionChunk_CurrentParameter, 4136 /** 4137 * \brief A left parenthesis ('('), used to initiate a function call or 4138 * signal the beginning of a function parameter list. 4139 */ 4140 CXCompletionChunk_LeftParen, 4141 /** 4142 * \brief A right parenthesis (')'), used to finish a function call or 4143 * signal the end of a function parameter list. 4144 */ 4145 CXCompletionChunk_RightParen, 4146 /** 4147 * \brief A left bracket ('['). 4148 */ 4149 CXCompletionChunk_LeftBracket, 4150 /** 4151 * \brief A right bracket (']'). 4152 */ 4153 CXCompletionChunk_RightBracket, 4154 /** 4155 * \brief A left brace ('{'). 4156 */ 4157 CXCompletionChunk_LeftBrace, 4158 /** 4159 * \brief A right brace ('}'). 4160 */ 4161 CXCompletionChunk_RightBrace, 4162 /** 4163 * \brief A left angle bracket ('<'). 4164 */ 4165 CXCompletionChunk_LeftAngle, 4166 /** 4167 * \brief A right angle bracket ('>'). 4168 */ 4169 CXCompletionChunk_RightAngle, 4170 /** 4171 * \brief A comma separator (','). 4172 */ 4173 CXCompletionChunk_Comma, 4174 /** 4175 * \brief Text that specifies the result type of a given result. 4176 * 4177 * This special kind of informative chunk is not meant to be inserted into 4178 * the text buffer. Rather, it is meant to illustrate the type that an 4179 * expression using the given completion string would have. 4180 */ 4181 CXCompletionChunk_ResultType, 4182 /** 4183 * \brief A colon (':'). 4184 */ 4185 CXCompletionChunk_Colon, 4186 /** 4187 * \brief A semicolon (';'). 4188 */ 4189 CXCompletionChunk_SemiColon, 4190 /** 4191 * \brief An '=' sign. 4192 */ 4193 CXCompletionChunk_Equal, 4194 /** 4195 * Horizontal space (' '). 4196 */ 4197 CXCompletionChunk_HorizontalSpace, 4198 /** 4199 * Vertical space ('\n'), after which it is generally a good idea to 4200 * perform indentation. 4201 */ 4202 CXCompletionChunk_VerticalSpace 4203 }; 4204 4205 /** 4206 * \brief Determine the kind of a particular chunk within a completion string. 4207 * 4208 * \param completion_string the completion string to query. 4209 * 4210 * \param chunk_number the 0-based index of the chunk in the completion string. 4211 * 4212 * \returns the kind of the chunk at the index \c chunk_number. 4213 */ 4214 CINDEX_LINKAGE enum CXCompletionChunkKind 4215 clang_getCompletionChunkKind(CXCompletionString completion_string, 4216 unsigned chunk_number); 4217 4218 /** 4219 * \brief Retrieve the text associated with a particular chunk within a 4220 * completion string. 4221 * 4222 * \param completion_string the completion string to query. 4223 * 4224 * \param chunk_number the 0-based index of the chunk in the completion string. 4225 * 4226 * \returns the text associated with the chunk at index \c chunk_number. 4227 */ 4228 CINDEX_LINKAGE CXString 4229 clang_getCompletionChunkText(CXCompletionString completion_string, 4230 unsigned chunk_number); 4231 4232 /** 4233 * \brief Retrieve the completion string associated with a particular chunk 4234 * within a completion string. 4235 * 4236 * \param completion_string the completion string to query. 4237 * 4238 * \param chunk_number the 0-based index of the chunk in the completion string. 4239 * 4240 * \returns the completion string associated with the chunk at index 4241 * \c chunk_number. 4242 */ 4243 CINDEX_LINKAGE CXCompletionString 4244 clang_getCompletionChunkCompletionString(CXCompletionString completion_string, 4245 unsigned chunk_number); 4246 4247 /** 4248 * \brief Retrieve the number of chunks in the given code-completion string. 4249 */ 4250 CINDEX_LINKAGE unsigned 4251 clang_getNumCompletionChunks(CXCompletionString completion_string); 4252 4253 /** 4254 * \brief Determine the priority of this code completion. 4255 * 4256 * The priority of a code completion indicates how likely it is that this 4257 * particular completion is the completion that the user will select. The 4258 * priority is selected by various internal heuristics. 4259 * 4260 * \param completion_string The completion string to query. 4261 * 4262 * \returns The priority of this completion string. Smaller values indicate 4263 * higher-priority (more likely) completions. 4264 */ 4265 CINDEX_LINKAGE unsigned 4266 clang_getCompletionPriority(CXCompletionString completion_string); 4267 4268 /** 4269 * \brief Determine the availability of the entity that this code-completion 4270 * string refers to. 4271 * 4272 * \param completion_string The completion string to query. 4273 * 4274 * \returns The availability of the completion string. 4275 */ 4276 CINDEX_LINKAGE enum CXAvailabilityKind 4277 clang_getCompletionAvailability(CXCompletionString completion_string); 4278 4279 /** 4280 * \brief Retrieve the number of annotations associated with the given 4281 * completion string. 4282 * 4283 * \param completion_string the completion string to query. 4284 * 4285 * \returns the number of annotations associated with the given completion 4286 * string. 4287 */ 4288 CINDEX_LINKAGE unsigned 4289 clang_getCompletionNumAnnotations(CXCompletionString completion_string); 4290 4291 /** 4292 * \brief Retrieve the annotation associated with the given completion string. 4293 * 4294 * \param completion_string the completion string to query. 4295 * 4296 * \param annotation_number the 0-based index of the annotation of the 4297 * completion string. 4298 * 4299 * \returns annotation string associated with the completion at index 4300 * \c annotation_number, or a NULL string if that annotation is not available. 4301 */ 4302 CINDEX_LINKAGE CXString 4303 clang_getCompletionAnnotation(CXCompletionString completion_string, 4304 unsigned annotation_number); 4305 4306 /** 4307 * \brief Retrieve the parent context of the given completion string. 4308 * 4309 * The parent context of a completion string is the semantic parent of 4310 * the declaration (if any) that the code completion represents. For example, 4311 * a code completion for an Objective-C method would have the method's class 4312 * or protocol as its context. 4313 * 4314 * \param completion_string The code completion string whose parent is 4315 * being queried. 4316 * 4317 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL. 4318 * 4319 * \returns The name of the completion parent, e.g., "NSObject" if 4320 * the completion string represents a method in the NSObject class. 4321 */ 4322 CINDEX_LINKAGE CXString 4323 clang_getCompletionParent(CXCompletionString completion_string, 4324 enum CXCursorKind *kind); 4325 4326 /** 4327 * \brief Retrieve the brief documentation comment attached to the declaration 4328 * that corresponds to the given completion string. 4329 */ 4330 CINDEX_LINKAGE CXString 4331 clang_getCompletionBriefComment(CXCompletionString completion_string); 4332 4333 /** 4334 * \brief Retrieve a completion string for an arbitrary declaration or macro 4335 * definition cursor. 4336 * 4337 * \param cursor The cursor to query. 4338 * 4339 * \returns A non-context-sensitive completion string for declaration and macro 4340 * definition cursors, or NULL for other kinds of cursors. 4341 */ 4342 CINDEX_LINKAGE CXCompletionString 4343 clang_getCursorCompletionString(CXCursor cursor); 4344 4345 /** 4346 * \brief Contains the results of code-completion. 4347 * 4348 * This data structure contains the results of code completion, as 4349 * produced by \c clang_codeCompleteAt(). Its contents must be freed by 4350 * \c clang_disposeCodeCompleteResults. 4351 */ 4352 typedef struct { 4353 /** 4354 * \brief The code-completion results. 4355 */ 4356 CXCompletionResult *Results; 4357 4358 /** 4359 * \brief The number of code-completion results stored in the 4360 * \c Results array. 4361 */ 4362 unsigned NumResults; 4363 } CXCodeCompleteResults; 4364 4365 /** 4366 * \brief Flags that can be passed to \c clang_codeCompleteAt() to 4367 * modify its behavior. 4368 * 4369 * The enumerators in this enumeration can be bitwise-OR'd together to 4370 * provide multiple options to \c clang_codeCompleteAt(). 4371 */ 4372 enum CXCodeComplete_Flags { 4373 /** 4374 * \brief Whether to include macros within the set of code 4375 * completions returned. 4376 */ 4377 CXCodeComplete_IncludeMacros = 0x01, 4378 4379 /** 4380 * \brief Whether to include code patterns for language constructs 4381 * within the set of code completions, e.g., for loops. 4382 */ 4383 CXCodeComplete_IncludeCodePatterns = 0x02, 4384 4385 /** 4386 * \brief Whether to include brief documentation within the set of code 4387 * completions returned. 4388 */ 4389 CXCodeComplete_IncludeBriefComments = 0x04 4390 }; 4391 4392 /** 4393 * \brief Bits that represent the context under which completion is occurring. 4394 * 4395 * The enumerators in this enumeration may be bitwise-OR'd together if multiple 4396 * contexts are occurring simultaneously. 4397 */ 4398 enum CXCompletionContext { 4399 /** 4400 * \brief The context for completions is unexposed, as only Clang results 4401 * should be included. (This is equivalent to having no context bits set.) 4402 */ 4403 CXCompletionContext_Unexposed = 0, 4404 4405 /** 4406 * \brief Completions for any possible type should be included in the results. 4407 */ 4408 CXCompletionContext_AnyType = 1 << 0, 4409 4410 /** 4411 * \brief Completions for any possible value (variables, function calls, etc.) 4412 * should be included in the results. 4413 */ 4414 CXCompletionContext_AnyValue = 1 << 1, 4415 /** 4416 * \brief Completions for values that resolve to an Objective-C object should 4417 * be included in the results. 4418 */ 4419 CXCompletionContext_ObjCObjectValue = 1 << 2, 4420 /** 4421 * \brief Completions for values that resolve to an Objective-C selector 4422 * should be included in the results. 4423 */ 4424 CXCompletionContext_ObjCSelectorValue = 1 << 3, 4425 /** 4426 * \brief Completions for values that resolve to a C++ class type should be 4427 * included in the results. 4428 */ 4429 CXCompletionContext_CXXClassTypeValue = 1 << 4, 4430 4431 /** 4432 * \brief Completions for fields of the member being accessed using the dot 4433 * operator should be included in the results. 4434 */ 4435 CXCompletionContext_DotMemberAccess = 1 << 5, 4436 /** 4437 * \brief Completions for fields of the member being accessed using the arrow 4438 * operator should be included in the results. 4439 */ 4440 CXCompletionContext_ArrowMemberAccess = 1 << 6, 4441 /** 4442 * \brief Completions for properties of the Objective-C object being accessed 4443 * using the dot operator should be included in the results. 4444 */ 4445 CXCompletionContext_ObjCPropertyAccess = 1 << 7, 4446 4447 /** 4448 * \brief Completions for enum tags should be included in the results. 4449 */ 4450 CXCompletionContext_EnumTag = 1 << 8, 4451 /** 4452 * \brief Completions for union tags should be included in the results. 4453 */ 4454 CXCompletionContext_UnionTag = 1 << 9, 4455 /** 4456 * \brief Completions for struct tags should be included in the results. 4457 */ 4458 CXCompletionContext_StructTag = 1 << 10, 4459 4460 /** 4461 * \brief Completions for C++ class names should be included in the results. 4462 */ 4463 CXCompletionContext_ClassTag = 1 << 11, 4464 /** 4465 * \brief Completions for C++ namespaces and namespace aliases should be 4466 * included in the results. 4467 */ 4468 CXCompletionContext_Namespace = 1 << 12, 4469 /** 4470 * \brief Completions for C++ nested name specifiers should be included in 4471 * the results. 4472 */ 4473 CXCompletionContext_NestedNameSpecifier = 1 << 13, 4474 4475 /** 4476 * \brief Completions for Objective-C interfaces (classes) should be included 4477 * in the results. 4478 */ 4479 CXCompletionContext_ObjCInterface = 1 << 14, 4480 /** 4481 * \brief Completions for Objective-C protocols should be included in 4482 * the results. 4483 */ 4484 CXCompletionContext_ObjCProtocol = 1 << 15, 4485 /** 4486 * \brief Completions for Objective-C categories should be included in 4487 * the results. 4488 */ 4489 CXCompletionContext_ObjCCategory = 1 << 16, 4490 /** 4491 * \brief Completions for Objective-C instance messages should be included 4492 * in the results. 4493 */ 4494 CXCompletionContext_ObjCInstanceMessage = 1 << 17, 4495 /** 4496 * \brief Completions for Objective-C class messages should be included in 4497 * the results. 4498 */ 4499 CXCompletionContext_ObjCClassMessage = 1 << 18, 4500 /** 4501 * \brief Completions for Objective-C selector names should be included in 4502 * the results. 4503 */ 4504 CXCompletionContext_ObjCSelectorName = 1 << 19, 4505 4506 /** 4507 * \brief Completions for preprocessor macro names should be included in 4508 * the results. 4509 */ 4510 CXCompletionContext_MacroName = 1 << 20, 4511 4512 /** 4513 * \brief Natural language completions should be included in the results. 4514 */ 4515 CXCompletionContext_NaturalLanguage = 1 << 21, 4516 4517 /** 4518 * \brief The current context is unknown, so set all contexts. 4519 */ 4520 CXCompletionContext_Unknown = ((1 << 22) - 1) 4521 }; 4522 4523 /** 4524 * \brief Returns a default set of code-completion options that can be 4525 * passed to\c clang_codeCompleteAt(). 4526 */ 4527 CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void); 4528 4529 /** 4530 * \brief Perform code completion at a given location in a translation unit. 4531 * 4532 * This function performs code completion at a particular file, line, and 4533 * column within source code, providing results that suggest potential 4534 * code snippets based on the context of the completion. The basic model 4535 * for code completion is that Clang will parse a complete source file, 4536 * performing syntax checking up to the location where code-completion has 4537 * been requested. At that point, a special code-completion token is passed 4538 * to the parser, which recognizes this token and determines, based on the 4539 * current location in the C/Objective-C/C++ grammar and the state of 4540 * semantic analysis, what completions to provide. These completions are 4541 * returned via a new \c CXCodeCompleteResults structure. 4542 * 4543 * Code completion itself is meant to be triggered by the client when the 4544 * user types punctuation characters or whitespace, at which point the 4545 * code-completion location will coincide with the cursor. For example, if \c p 4546 * is a pointer, code-completion might be triggered after the "-" and then 4547 * after the ">" in \c p->. When the code-completion location is afer the ">", 4548 * the completion results will provide, e.g., the members of the struct that 4549 * "p" points to. The client is responsible for placing the cursor at the 4550 * beginning of the token currently being typed, then filtering the results 4551 * based on the contents of the token. For example, when code-completing for 4552 * the expression \c p->get, the client should provide the location just after 4553 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 4554 * client can filter the results based on the current token text ("get"), only 4555 * showing those results that start with "get". The intent of this interface 4556 * is to separate the relatively high-latency acquisition of code-completion 4557 * results from the filtering of results on a per-character basis, which must 4558 * have a lower latency. 4559 * 4560 * \param TU The translation unit in which code-completion should 4561 * occur. The source files for this translation unit need not be 4562 * completely up-to-date (and the contents of those source files may 4563 * be overridden via \p unsaved_files). Cursors referring into the 4564 * translation unit may be invalidated by this invocation. 4565 * 4566 * \param complete_filename The name of the source file where code 4567 * completion should be performed. This filename may be any file 4568 * included in the translation unit. 4569 * 4570 * \param complete_line The line at which code-completion should occur. 4571 * 4572 * \param complete_column The column at which code-completion should occur. 4573 * Note that the column should point just after the syntactic construct that 4574 * initiated code completion, and not in the middle of a lexical token. 4575 * 4576 * \param unsaved_files the Tiles that have not yet been saved to disk 4577 * but may be required for parsing or code completion, including the 4578 * contents of those files. The contents and name of these files (as 4579 * specified by CXUnsavedFile) are copied when necessary, so the 4580 * client only needs to guarantee their validity until the call to 4581 * this function returns. 4582 * 4583 * \param num_unsaved_files The number of unsaved file entries in \p 4584 * unsaved_files. 4585 * 4586 * \param options Extra options that control the behavior of code 4587 * completion, expressed as a bitwise OR of the enumerators of the 4588 * CXCodeComplete_Flags enumeration. The 4589 * \c clang_defaultCodeCompleteOptions() function returns a default set 4590 * of code-completion options. 4591 * 4592 * \returns If successful, a new \c CXCodeCompleteResults structure 4593 * containing code-completion results, which should eventually be 4594 * freed with \c clang_disposeCodeCompleteResults(). If code 4595 * completion fails, returns NULL. 4596 */ 4597 CINDEX_LINKAGE 4598 CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, 4599 const char *complete_filename, 4600 unsigned complete_line, 4601 unsigned complete_column, 4602 struct CXUnsavedFile *unsaved_files, 4603 unsigned num_unsaved_files, 4604 unsigned options); 4605 4606 /** 4607 * \brief Sort the code-completion results in case-insensitive alphabetical 4608 * order. 4609 * 4610 * \param Results The set of results to sort. 4611 * \param NumResults The number of results in \p Results. 4612 */ 4613 CINDEX_LINKAGE 4614 void clang_sortCodeCompletionResults(CXCompletionResult *Results, 4615 unsigned NumResults); 4616 4617 /** 4618 * \brief Free the given set of code-completion results. 4619 */ 4620 CINDEX_LINKAGE 4621 void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); 4622 4623 /** 4624 * \brief Determine the number of diagnostics produced prior to the 4625 * location where code completion was performed. 4626 */ 4627 CINDEX_LINKAGE 4628 unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); 4629 4630 /** 4631 * \brief Retrieve a diagnostic associated with the given code completion. 4632 * 4633 * \param Results the code completion results to query. 4634 * \param Index the zero-based diagnostic number to retrieve. 4635 * 4636 * \returns the requested diagnostic. This diagnostic must be freed 4637 * via a call to \c clang_disposeDiagnostic(). 4638 */ 4639 CINDEX_LINKAGE 4640 CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, 4641 unsigned Index); 4642 4643 /** 4644 * \brief Determines what completions are appropriate for the context 4645 * the given code completion. 4646 * 4647 * \param Results the code completion results to query 4648 * 4649 * \returns the kinds of completions that are appropriate for use 4650 * along with the given code completion results. 4651 */ 4652 CINDEX_LINKAGE 4653 unsigned long long clang_codeCompleteGetContexts( 4654 CXCodeCompleteResults *Results); 4655 4656 /** 4657 * \brief Returns the cursor kind for the container for the current code 4658 * completion context. The container is only guaranteed to be set for 4659 * contexts where a container exists (i.e. member accesses or Objective-C 4660 * message sends); if there is not a container, this function will return 4661 * CXCursor_InvalidCode. 4662 * 4663 * \param Results the code completion results to query 4664 * 4665 * \param IsIncomplete on return, this value will be false if Clang has complete 4666 * information about the container. If Clang does not have complete 4667 * information, this value will be true. 4668 * 4669 * \returns the container kind, or CXCursor_InvalidCode if there is not a 4670 * container 4671 */ 4672 CINDEX_LINKAGE 4673 enum CXCursorKind clang_codeCompleteGetContainerKind( 4674 CXCodeCompleteResults *Results, 4675 unsigned *IsIncomplete); 4676 4677 /** 4678 * \brief Returns the USR for the container for the current code completion 4679 * context. If there is not a container for the current context, this 4680 * function will return the empty string. 4681 * 4682 * \param Results the code completion results to query 4683 * 4684 * \returns the USR for the container 4685 */ 4686 CINDEX_LINKAGE 4687 CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results); 4688 4689 4690 /** 4691 * \brief Returns the currently-entered selector for an Objective-C message 4692 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a 4693 * non-empty string for CXCompletionContext_ObjCInstanceMessage and 4694 * CXCompletionContext_ObjCClassMessage. 4695 * 4696 * \param Results the code completion results to query 4697 * 4698 * \returns the selector (or partial selector) that has been entered thus far 4699 * for an Objective-C message send. 4700 */ 4701 CINDEX_LINKAGE 4702 CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results); 4703 4704 /** 4705 * @} 4706 */ 4707 4708 4709 /** 4710 * \defgroup CINDEX_MISC Miscellaneous utility functions 4711 * 4712 * @{ 4713 */ 4714 4715 /** 4716 * \brief Return a version string, suitable for showing to a user, but not 4717 * intended to be parsed (the format is not guaranteed to be stable). 4718 */ 4719 CINDEX_LINKAGE CXString clang_getClangVersion(void); 4720 4721 4722 /** 4723 * \brief Enable/disable crash recovery. 4724 * 4725 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero 4726 * value enables crash recovery, while 0 disables it. 4727 */ 4728 CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled); 4729 4730 /** 4731 * \brief Visitor invoked for each file in a translation unit 4732 * (used with clang_getInclusions()). 4733 * 4734 * This visitor function will be invoked by clang_getInclusions() for each 4735 * file included (either at the top-level or by \#include directives) within 4736 * a translation unit. The first argument is the file being included, and 4737 * the second and third arguments provide the inclusion stack. The 4738 * array is sorted in order of immediate inclusion. For example, 4739 * the first element refers to the location that included 'included_file'. 4740 */ 4741 typedef void (*CXInclusionVisitor)(CXFile included_file, 4742 CXSourceLocation* inclusion_stack, 4743 unsigned include_len, 4744 CXClientData client_data); 4745 4746 /** 4747 * \brief Visit the set of preprocessor inclusions in a translation unit. 4748 * The visitor function is called with the provided data for every included 4749 * file. This does not include headers included by the PCH file (unless one 4750 * is inspecting the inclusions in the PCH file itself). 4751 */ 4752 CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, 4753 CXInclusionVisitor visitor, 4754 CXClientData client_data); 4755 4756 /** 4757 * @} 4758 */ 4759 4760 /** \defgroup CINDEX_REMAPPING Remapping functions 4761 * 4762 * @{ 4763 */ 4764 4765 /** 4766 * \brief A remapping of original source files and their translated files. 4767 */ 4768 typedef void *CXRemapping; 4769 4770 /** 4771 * \brief Retrieve a remapping. 4772 * 4773 * \param path the path that contains metadata about remappings. 4774 * 4775 * \returns the requested remapping. This remapping must be freed 4776 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. 4777 */ 4778 CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path); 4779 4780 /** 4781 * \brief Retrieve a remapping. 4782 * 4783 * \param filePaths pointer to an array of file paths containing remapping info. 4784 * 4785 * \param numFiles number of file paths. 4786 * 4787 * \returns the requested remapping. This remapping must be freed 4788 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. 4789 */ 4790 CINDEX_LINKAGE 4791 CXRemapping clang_getRemappingsFromFileList(const char **filePaths, 4792 unsigned numFiles); 4793 4794 /** 4795 * \brief Determine the number of remappings. 4796 */ 4797 CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping); 4798 4799 /** 4800 * \brief Get the original and the associated filename from the remapping. 4801 * 4802 * \param original If non-NULL, will be set to the original filename. 4803 * 4804 * \param transformed If non-NULL, will be set to the filename that the original 4805 * is associated with. 4806 */ 4807 CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index, 4808 CXString *original, CXString *transformed); 4809 4810 /** 4811 * \brief Dispose the remapping. 4812 */ 4813 CINDEX_LINKAGE void clang_remap_dispose(CXRemapping); 4814 4815 /** 4816 * @} 4817 */ 4818 4819 /** \defgroup CINDEX_HIGH Higher level API functions 4820 * 4821 * @{ 4822 */ 4823 4824 enum CXVisitorResult { 4825 CXVisit_Break, 4826 CXVisit_Continue 4827 }; 4828 4829 typedef struct { 4830 void *context; 4831 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange); 4832 } CXCursorAndRangeVisitor; 4833 4834 typedef enum { 4835 /** 4836 * \brief Function returned successfully. 4837 */ 4838 CXResult_Success = 0, 4839 /** 4840 * \brief One of the parameters was invalid for the function. 4841 */ 4842 CXResult_Invalid = 1, 4843 /** 4844 * \brief The function was terminated by a callback (e.g. it returned 4845 * CXVisit_Break) 4846 */ 4847 CXResult_VisitBreak = 2 4848 4849 } CXResult; 4850 4851 /** 4852 * \brief Find references of a declaration in a specific file. 4853 * 4854 * \param cursor pointing to a declaration or a reference of one. 4855 * 4856 * \param file to search for references. 4857 * 4858 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for 4859 * each reference found. 4860 * The CXSourceRange will point inside the file; if the reference is inside 4861 * a macro (and not a macro argument) the CXSourceRange will be invalid. 4862 * 4863 * \returns one of the CXResult enumerators. 4864 */ 4865 CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file, 4866 CXCursorAndRangeVisitor visitor); 4867 4868 /** 4869 * \brief Find #import/#include directives in a specific file. 4870 * 4871 * \param TU translation unit containing the file to query. 4872 * 4873 * \param file to search for #import/#include directives. 4874 * 4875 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for 4876 * each directive found. 4877 * 4878 * \returns one of the CXResult enumerators. 4879 */ 4880 CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU, 4881 CXFile file, 4882 CXCursorAndRangeVisitor visitor); 4883 4884 #ifdef __has_feature 4885 # if __has_feature(blocks) 4886 4887 typedef enum CXVisitorResult 4888 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange); 4889 4890 CINDEX_LINKAGE 4891 CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile, 4892 CXCursorAndRangeVisitorBlock); 4893 4894 CINDEX_LINKAGE 4895 CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile, 4896 CXCursorAndRangeVisitorBlock); 4897 4898 # endif 4899 #endif 4900 4901 /** 4902 * \brief The client's data object that is associated with a CXFile. 4903 */ 4904 typedef void *CXIdxClientFile; 4905 4906 /** 4907 * \brief The client's data object that is associated with a semantic entity. 4908 */ 4909 typedef void *CXIdxClientEntity; 4910 4911 /** 4912 * \brief The client's data object that is associated with a semantic container 4913 * of entities. 4914 */ 4915 typedef void *CXIdxClientContainer; 4916 4917 /** 4918 * \brief The client's data object that is associated with an AST file (PCH 4919 * or module). 4920 */ 4921 typedef void *CXIdxClientASTFile; 4922 4923 /** 4924 * \brief Source location passed to index callbacks. 4925 */ 4926 typedef struct { 4927 void *ptr_data[2]; 4928 unsigned int_data; 4929 } CXIdxLoc; 4930 4931 /** 4932 * \brief Data for ppIncludedFile callback. 4933 */ 4934 typedef struct { 4935 /** 4936 * \brief Location of '#' in the \#include/\#import directive. 4937 */ 4938 CXIdxLoc hashLoc; 4939 /** 4940 * \brief Filename as written in the \#include/\#import directive. 4941 */ 4942 const char *filename; 4943 /** 4944 * \brief The actual file that the \#include/\#import directive resolved to. 4945 */ 4946 CXFile file; 4947 int isImport; 4948 int isAngled; 4949 /** 4950 * \brief Non-zero if the directive was automatically turned into a module 4951 * import. 4952 */ 4953 int isModuleImport; 4954 } CXIdxIncludedFileInfo; 4955 4956 /** 4957 * \brief Data for IndexerCallbacks#importedASTFile. 4958 */ 4959 typedef struct { 4960 /** 4961 * \brief Top level AST file containing the imported PCH, module or submodule. 4962 */ 4963 CXFile file; 4964 /** 4965 * \brief The imported module or NULL if the AST file is a PCH. 4966 */ 4967 CXModule module; 4968 /** 4969 * \brief Location where the file is imported. Applicable only for modules. 4970 */ 4971 CXIdxLoc loc; 4972 /** 4973 * \brief Non-zero if an inclusion directive was automatically turned into 4974 * a module import. Applicable only for modules. 4975 */ 4976 int isImplicit; 4977 4978 } CXIdxImportedASTFileInfo; 4979 4980 typedef enum { 4981 CXIdxEntity_Unexposed = 0, 4982 CXIdxEntity_Typedef = 1, 4983 CXIdxEntity_Function = 2, 4984 CXIdxEntity_Variable = 3, 4985 CXIdxEntity_Field = 4, 4986 CXIdxEntity_EnumConstant = 5, 4987 4988 CXIdxEntity_ObjCClass = 6, 4989 CXIdxEntity_ObjCProtocol = 7, 4990 CXIdxEntity_ObjCCategory = 8, 4991 4992 CXIdxEntity_ObjCInstanceMethod = 9, 4993 CXIdxEntity_ObjCClassMethod = 10, 4994 CXIdxEntity_ObjCProperty = 11, 4995 CXIdxEntity_ObjCIvar = 12, 4996 4997 CXIdxEntity_Enum = 13, 4998 CXIdxEntity_Struct = 14, 4999 CXIdxEntity_Union = 15, 5000 5001 CXIdxEntity_CXXClass = 16, 5002 CXIdxEntity_CXXNamespace = 17, 5003 CXIdxEntity_CXXNamespaceAlias = 18, 5004 CXIdxEntity_CXXStaticVariable = 19, 5005 CXIdxEntity_CXXStaticMethod = 20, 5006 CXIdxEntity_CXXInstanceMethod = 21, 5007 CXIdxEntity_CXXConstructor = 22, 5008 CXIdxEntity_CXXDestructor = 23, 5009 CXIdxEntity_CXXConversionFunction = 24, 5010 CXIdxEntity_CXXTypeAlias = 25, 5011 CXIdxEntity_CXXInterface = 26 5012 5013 } CXIdxEntityKind; 5014 5015 typedef enum { 5016 CXIdxEntityLang_None = 0, 5017 CXIdxEntityLang_C = 1, 5018 CXIdxEntityLang_ObjC = 2, 5019 CXIdxEntityLang_CXX = 3 5020 } CXIdxEntityLanguage; 5021 5022 /** 5023 * \brief Extra C++ template information for an entity. This can apply to: 5024 * CXIdxEntity_Function 5025 * CXIdxEntity_CXXClass 5026 * CXIdxEntity_CXXStaticMethod 5027 * CXIdxEntity_CXXInstanceMethod 5028 * CXIdxEntity_CXXConstructor 5029 * CXIdxEntity_CXXConversionFunction 5030 * CXIdxEntity_CXXTypeAlias 5031 */ 5032 typedef enum { 5033 CXIdxEntity_NonTemplate = 0, 5034 CXIdxEntity_Template = 1, 5035 CXIdxEntity_TemplatePartialSpecialization = 2, 5036 CXIdxEntity_TemplateSpecialization = 3 5037 } CXIdxEntityCXXTemplateKind; 5038 5039 typedef enum { 5040 CXIdxAttr_Unexposed = 0, 5041 CXIdxAttr_IBAction = 1, 5042 CXIdxAttr_IBOutlet = 2, 5043 CXIdxAttr_IBOutletCollection = 3 5044 } CXIdxAttrKind; 5045 5046 typedef struct { 5047 CXIdxAttrKind kind; 5048 CXCursor cursor; 5049 CXIdxLoc loc; 5050 } CXIdxAttrInfo; 5051 5052 typedef struct { 5053 CXIdxEntityKind kind; 5054 CXIdxEntityCXXTemplateKind templateKind; 5055 CXIdxEntityLanguage lang; 5056 const char *name; 5057 const char *USR; 5058 CXCursor cursor; 5059 const CXIdxAttrInfo *const *attributes; 5060 unsigned numAttributes; 5061 } CXIdxEntityInfo; 5062 5063 typedef struct { 5064 CXCursor cursor; 5065 } CXIdxContainerInfo; 5066 5067 typedef struct { 5068 const CXIdxAttrInfo *attrInfo; 5069 const CXIdxEntityInfo *objcClass; 5070 CXCursor classCursor; 5071 CXIdxLoc classLoc; 5072 } CXIdxIBOutletCollectionAttrInfo; 5073 5074 typedef enum { 5075 CXIdxDeclFlag_Skipped = 0x1 5076 } CXIdxDeclInfoFlags; 5077 5078 typedef struct { 5079 const CXIdxEntityInfo *entityInfo; 5080 CXCursor cursor; 5081 CXIdxLoc loc; 5082 const CXIdxContainerInfo *semanticContainer; 5083 /** 5084 * \brief Generally same as #semanticContainer but can be different in 5085 * cases like out-of-line C++ member functions. 5086 */ 5087 const CXIdxContainerInfo *lexicalContainer; 5088 int isRedeclaration; 5089 int isDefinition; 5090 int isContainer; 5091 const CXIdxContainerInfo *declAsContainer; 5092 /** 5093 * \brief Whether the declaration exists in code or was created implicitly 5094 * by the compiler, e.g. implicit Objective-C methods for properties. 5095 */ 5096 int isImplicit; 5097 const CXIdxAttrInfo *const *attributes; 5098 unsigned numAttributes; 5099 5100 unsigned flags; 5101 5102 } CXIdxDeclInfo; 5103 5104 typedef enum { 5105 CXIdxObjCContainer_ForwardRef = 0, 5106 CXIdxObjCContainer_Interface = 1, 5107 CXIdxObjCContainer_Implementation = 2 5108 } CXIdxObjCContainerKind; 5109 5110 typedef struct { 5111 const CXIdxDeclInfo *declInfo; 5112 CXIdxObjCContainerKind kind; 5113 } CXIdxObjCContainerDeclInfo; 5114 5115 typedef struct { 5116 const CXIdxEntityInfo *base; 5117 CXCursor cursor; 5118 CXIdxLoc loc; 5119 } CXIdxBaseClassInfo; 5120 5121 typedef struct { 5122 const CXIdxEntityInfo *protocol; 5123 CXCursor cursor; 5124 CXIdxLoc loc; 5125 } CXIdxObjCProtocolRefInfo; 5126 5127 typedef struct { 5128 const CXIdxObjCProtocolRefInfo *const *protocols; 5129 unsigned numProtocols; 5130 } CXIdxObjCProtocolRefListInfo; 5131 5132 typedef struct { 5133 const CXIdxObjCContainerDeclInfo *containerInfo; 5134 const CXIdxBaseClassInfo *superInfo; 5135 const CXIdxObjCProtocolRefListInfo *protocols; 5136 } CXIdxObjCInterfaceDeclInfo; 5137 5138 typedef struct { 5139 const CXIdxObjCContainerDeclInfo *containerInfo; 5140 const CXIdxEntityInfo *objcClass; 5141 CXCursor classCursor; 5142 CXIdxLoc classLoc; 5143 const CXIdxObjCProtocolRefListInfo *protocols; 5144 } CXIdxObjCCategoryDeclInfo; 5145 5146 typedef struct { 5147 const CXIdxDeclInfo *declInfo; 5148 const CXIdxEntityInfo *getter; 5149 const CXIdxEntityInfo *setter; 5150 } CXIdxObjCPropertyDeclInfo; 5151 5152 typedef struct { 5153 const CXIdxDeclInfo *declInfo; 5154 const CXIdxBaseClassInfo *const *bases; 5155 unsigned numBases; 5156 } CXIdxCXXClassDeclInfo; 5157 5158 /** 5159 * \brief Data for IndexerCallbacks#indexEntityReference. 5160 */ 5161 typedef enum { 5162 /** 5163 * \brief The entity is referenced directly in user's code. 5164 */ 5165 CXIdxEntityRef_Direct = 1, 5166 /** 5167 * \brief An implicit reference, e.g. a reference of an Objective-C method 5168 * via the dot syntax. 5169 */ 5170 CXIdxEntityRef_Implicit = 2 5171 } CXIdxEntityRefKind; 5172 5173 /** 5174 * \brief Data for IndexerCallbacks#indexEntityReference. 5175 */ 5176 typedef struct { 5177 CXIdxEntityRefKind kind; 5178 /** 5179 * \brief Reference cursor. 5180 */ 5181 CXCursor cursor; 5182 CXIdxLoc loc; 5183 /** 5184 * \brief The entity that gets referenced. 5185 */ 5186 const CXIdxEntityInfo *referencedEntity; 5187 /** 5188 * \brief Immediate "parent" of the reference. For example: 5189 * 5190 * \code 5191 * Foo *var; 5192 * \endcode 5193 * 5194 * The parent of reference of type 'Foo' is the variable 'var'. 5195 * For references inside statement bodies of functions/methods, 5196 * the parentEntity will be the function/method. 5197 */ 5198 const CXIdxEntityInfo *parentEntity; 5199 /** 5200 * \brief Lexical container context of the reference. 5201 */ 5202 const CXIdxContainerInfo *container; 5203 } CXIdxEntityRefInfo; 5204 5205 /** 5206 * \brief A group of callbacks used by #clang_indexSourceFile and 5207 * #clang_indexTranslationUnit. 5208 */ 5209 typedef struct { 5210 /** 5211 * \brief Called periodically to check whether indexing should be aborted. 5212 * Should return 0 to continue, and non-zero to abort. 5213 */ 5214 int (*abortQuery)(CXClientData client_data, void *reserved); 5215 5216 /** 5217 * \brief Called at the end of indexing; passes the complete diagnostic set. 5218 */ 5219 void (*diagnostic)(CXClientData client_data, 5220 CXDiagnosticSet, void *reserved); 5221 5222 CXIdxClientFile (*enteredMainFile)(CXClientData client_data, 5223 CXFile mainFile, void *reserved); 5224 5225 /** 5226 * \brief Called when a file gets \#included/\#imported. 5227 */ 5228 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data, 5229 const CXIdxIncludedFileInfo *); 5230 5231 /** 5232 * \brief Called when a AST file (PCH or module) gets imported. 5233 * 5234 * AST files will not get indexed (there will not be callbacks to index all 5235 * the entities in an AST file). The recommended action is that, if the AST 5236 * file is not already indexed, to initiate a new indexing job specific to 5237 * the AST file. 5238 */ 5239 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data, 5240 const CXIdxImportedASTFileInfo *); 5241 5242 /** 5243 * \brief Called at the beginning of indexing a translation unit. 5244 */ 5245 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data, 5246 void *reserved); 5247 5248 void (*indexDeclaration)(CXClientData client_data, 5249 const CXIdxDeclInfo *); 5250 5251 /** 5252 * \brief Called to index a reference of an entity. 5253 */ 5254 void (*indexEntityReference)(CXClientData client_data, 5255 const CXIdxEntityRefInfo *); 5256 5257 } IndexerCallbacks; 5258 5259 CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind); 5260 CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo * 5261 clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *); 5262 5263 CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo * 5264 clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *); 5265 5266 CINDEX_LINKAGE 5267 const CXIdxObjCCategoryDeclInfo * 5268 clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *); 5269 5270 CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo * 5271 clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *); 5272 5273 CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo * 5274 clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *); 5275 5276 CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo * 5277 clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *); 5278 5279 CINDEX_LINKAGE const CXIdxCXXClassDeclInfo * 5280 clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *); 5281 5282 /** 5283 * \brief For retrieving a custom CXIdxClientContainer attached to a 5284 * container. 5285 */ 5286 CINDEX_LINKAGE CXIdxClientContainer 5287 clang_index_getClientContainer(const CXIdxContainerInfo *); 5288 5289 /** 5290 * \brief For setting a custom CXIdxClientContainer attached to a 5291 * container. 5292 */ 5293 CINDEX_LINKAGE void 5294 clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer); 5295 5296 /** 5297 * \brief For retrieving a custom CXIdxClientEntity attached to an entity. 5298 */ 5299 CINDEX_LINKAGE CXIdxClientEntity 5300 clang_index_getClientEntity(const CXIdxEntityInfo *); 5301 5302 /** 5303 * \brief For setting a custom CXIdxClientEntity attached to an entity. 5304 */ 5305 CINDEX_LINKAGE void 5306 clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity); 5307 5308 /** 5309 * \brief An indexing action/session, to be applied to one or multiple 5310 * translation units. 5311 */ 5312 typedef void *CXIndexAction; 5313 5314 /** 5315 * \brief An indexing action/session, to be applied to one or multiple 5316 * translation units. 5317 * 5318 * \param CIdx The index object with which the index action will be associated. 5319 */ 5320 CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx); 5321 5322 /** 5323 * \brief Destroy the given index action. 5324 * 5325 * The index action must not be destroyed until all of the translation units 5326 * created within that index action have been destroyed. 5327 */ 5328 CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction); 5329 5330 typedef enum { 5331 /** 5332 * \brief Used to indicate that no special indexing options are needed. 5333 */ 5334 CXIndexOpt_None = 0x0, 5335 5336 /** 5337 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should 5338 * be invoked for only one reference of an entity per source file that does 5339 * not also include a declaration/definition of the entity. 5340 */ 5341 CXIndexOpt_SuppressRedundantRefs = 0x1, 5342 5343 /** 5344 * \brief Function-local symbols should be indexed. If this is not set 5345 * function-local symbols will be ignored. 5346 */ 5347 CXIndexOpt_IndexFunctionLocalSymbols = 0x2, 5348 5349 /** 5350 * \brief Implicit function/class template instantiations should be indexed. 5351 * If this is not set, implicit instantiations will be ignored. 5352 */ 5353 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4, 5354 5355 /** 5356 * \brief Suppress all compiler warnings when parsing for indexing. 5357 */ 5358 CXIndexOpt_SuppressWarnings = 0x8, 5359 5360 /** 5361 * \brief Skip a function/method body that was already parsed during an 5362 * indexing session associated with a \c CXIndexAction object. 5363 * Bodies in system headers are always skipped. 5364 */ 5365 CXIndexOpt_SkipParsedBodiesInSession = 0x10 5366 5367 } CXIndexOptFlags; 5368 5369 /** 5370 * \brief Index the given source file and the translation unit corresponding 5371 * to that file via callbacks implemented through #IndexerCallbacks. 5372 * 5373 * \param client_data pointer data supplied by the client, which will 5374 * be passed to the invoked callbacks. 5375 * 5376 * \param index_callbacks Pointer to indexing callbacks that the client 5377 * implements. 5378 * 5379 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets 5380 * passed in index_callbacks. 5381 * 5382 * \param index_options A bitmask of options that affects how indexing is 5383 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags. 5384 * 5385 * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be 5386 * reused after indexing is finished. Set to \c NULL if you do not require it. 5387 * 5388 * \returns 0 on success or if there were errors from which the compiler could 5389 * recover. If there is a failure from which the there is no recovery, returns 5390 * a non-zero \c CXErrorCode. 5391 * 5392 * The rest of the parameters are the same as #clang_parseTranslationUnit. 5393 */ 5394 CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction, 5395 CXClientData client_data, 5396 IndexerCallbacks *index_callbacks, 5397 unsigned index_callbacks_size, 5398 unsigned index_options, 5399 const char *source_filename, 5400 const char * const *command_line_args, 5401 int num_command_line_args, 5402 struct CXUnsavedFile *unsaved_files, 5403 unsigned num_unsaved_files, 5404 CXTranslationUnit *out_TU, 5405 unsigned TU_options); 5406 5407 /** 5408 * \brief Index the given translation unit via callbacks implemented through 5409 * #IndexerCallbacks. 5410 * 5411 * The order of callback invocations is not guaranteed to be the same as 5412 * when indexing a source file. The high level order will be: 5413 * 5414 * -Preprocessor callbacks invocations 5415 * -Declaration/reference callbacks invocations 5416 * -Diagnostic callback invocations 5417 * 5418 * The parameters are the same as #clang_indexSourceFile. 5419 * 5420 * \returns If there is a failure from which the there is no recovery, returns 5421 * non-zero, otherwise returns 0. 5422 */ 5423 CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction, 5424 CXClientData client_data, 5425 IndexerCallbacks *index_callbacks, 5426 unsigned index_callbacks_size, 5427 unsigned index_options, 5428 CXTranslationUnit); 5429 5430 /** 5431 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by 5432 * the given CXIdxLoc. 5433 * 5434 * If the location refers into a macro expansion, retrieves the 5435 * location of the macro expansion and if it refers into a macro argument 5436 * retrieves the location of the argument. 5437 */ 5438 CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc, 5439 CXIdxClientFile *indexFile, 5440 CXFile *file, 5441 unsigned *line, 5442 unsigned *column, 5443 unsigned *offset); 5444 5445 /** 5446 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc. 5447 */ 5448 CINDEX_LINKAGE 5449 CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc); 5450 5451 /** 5452 * @} 5453 */ 5454 5455 /** 5456 * @} 5457 */ 5458 5459 /* Include the comment API for compatibility. This will eventually go away. */ 5460 #include "clang-c/Documentation.h" 5461 5462 #ifdef __cplusplus 5463 } 5464 #endif 5465 #endif 5466 5467