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 interface 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 module clang.c.Index; 17 18 import core.stdc.config; 19 import core.stdc.time; 20 21 public import clang.c.CXErrorCode; 22 public import clang.c.CXString; 23 24 extern (C): 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 enum CINDEX_VERSION_MAJOR = 0; 35 enum CINDEX_VERSION_MINOR = 45; 36 37 extern (D) auto CINDEX_VERSION_ENCODE(T0, T1)(auto ref T0 major, auto ref T1 minor) 38 { 39 return (major * 10000) + (minor * 1); 40 } 41 42 enum CINDEX_VERSION = CINDEX_VERSION_ENCODE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR); 43 44 extern (D) string CINDEX_VERSION_STRINGIZE_(T0, T1)(auto ref T0 major, auto ref T1 minor) 45 { 46 import std.conv : to; 47 48 return to!string(major) ~ "." ~ to!string(minor); 49 } 50 51 alias CINDEX_VERSION_STRINGIZE = CINDEX_VERSION_STRINGIZE_; 52 53 enum CINDEX_VERSION_STRING = CINDEX_VERSION_STRINGIZE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR); 54 55 /** \defgroup CINDEX libclang: C Interface to Clang 56 * 57 * The C Interface to Clang provides a relatively small API that exposes 58 * facilities for parsing source code into an abstract syntax tree (AST), 59 * loading already-parsed ASTs, traversing the AST, associating 60 * physical source locations with elements within the AST, and other 61 * facilities that support Clang-based development tools. 62 * 63 * This C interface to Clang will never provide all of the information 64 * representation stored in Clang's C++ AST, nor should it: the intent is to 65 * maintain an API that is relatively stable from one release to the next, 66 * providing only the basic functionality needed to support development tools. 67 * 68 * To avoid namespace pollution, data types are prefixed with "CX" and 69 * functions are prefixed with "clang_". 70 * 71 * @{ 72 */ 73 74 /** 75 * \brief An "index" that consists of a set of translation units that would 76 * typically be linked together into an executable or library. 77 */ 78 alias CXIndex = void*; 79 80 /** 81 * \brief An opaque type representing target information for a given translation 82 * unit. 83 */ 84 struct CXTargetInfoImpl; 85 alias CXTargetInfo = CXTargetInfoImpl*; 86 87 /** 88 * \brief A single translation unit, which resides in an index. 89 */ 90 struct CXTranslationUnitImpl; 91 alias CXTranslationUnit = CXTranslationUnitImpl*; 92 93 /** 94 * \brief Opaque pointer representing client data that will be passed through 95 * to various callbacks and visitors. 96 */ 97 alias CXClientData = void*; 98 99 /** 100 * \brief Provides the contents of a file that has not yet been saved to disk. 101 * 102 * Each CXUnsavedFile instance provides the name of a file on the 103 * system along with the current contents of that file that have not 104 * yet been saved to disk. 105 */ 106 struct CXUnsavedFile 107 { 108 /** 109 * \brief The file whose contents have not yet been saved. 110 * 111 * This file must already exist in the file system. 112 */ 113 const(char)* Filename; 114 115 /** 116 * \brief A buffer containing the unsaved contents of this file. 117 */ 118 const(char)* Contents; 119 120 /** 121 * \brief The length of the unsaved contents of this buffer. 122 */ 123 c_ulong Length; 124 } 125 126 /** 127 * \brief Describes the availability of a particular entity, which indicates 128 * whether the use of this entity will result in a warning or error due to 129 * it being deprecated or unavailable. 130 */ 131 enum CXAvailabilityKind 132 { 133 /** 134 * \brief The entity is available. 135 */ 136 available = 0, 137 /** 138 * \brief The entity is available, but has been deprecated (and its use is 139 * not recommended). 140 */ 141 deprecated_ = 1, 142 /** 143 * \brief The entity is not available; any use of it will be an error. 144 */ 145 notAvailable = 2, 146 /** 147 * \brief The entity is available, but not accessible; any use of it will be 148 * an error. 149 */ 150 notAccessible = 3 151 } 152 153 /** 154 * \brief Describes a version number of the form major.minor.subminor. 155 */ 156 struct CXVersion 157 { 158 /** 159 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative 160 * value indicates that there is no version number at all. 161 */ 162 int Major; 163 /** 164 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value 165 * will be negative if no minor version number was provided, e.g., for 166 * version '10'. 167 */ 168 int Minor; 169 /** 170 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value 171 * will be negative if no minor or subminor version number was provided, 172 * e.g., in version '10' or '10.7'. 173 */ 174 int Subminor; 175 } 176 177 /** 178 * \brief Describes the exception specification of a cursor. 179 * 180 * A negative value indicates that the cursor is not a function declaration. 181 */ 182 enum CXCursor_ExceptionSpecificationKind 183 { 184 /** 185 * \brief The cursor has no exception specification. 186 */ 187 none = 0, 188 189 /** 190 * \brief The cursor has exception specification throw() 191 */ 192 dynamicNone = 1, 193 194 /** 195 * \brief The cursor has exception specification throw(T1, T2) 196 */ 197 dynamic = 2, 198 199 /** 200 * \brief The cursor has exception specification throw(...). 201 */ 202 msAny = 3, 203 204 /** 205 * \brief The cursor has exception specification basic noexcept. 206 */ 207 basicNoexcept = 4, 208 209 /** 210 * \brief The cursor has exception specification computed noexcept. 211 */ 212 computedNoexcept = 5, 213 214 /** 215 * \brief The exception specification has not yet been evaluated. 216 */ 217 unevaluated = 6, 218 219 /** 220 * \brief The exception specification has not yet been instantiated. 221 */ 222 uninstantiated = 7, 223 224 /** 225 * \brief The exception specification has not been parsed yet. 226 */ 227 unparsed = 8 228 } 229 230 /** 231 * \brief Provides a shared context for creating translation units. 232 * 233 * It provides two options: 234 * 235 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 236 * declarations (when loading any new translation units). A "local" declaration 237 * is one that belongs in the translation unit itself and not in a precompiled 238 * header that was used by the translation unit. If zero, all declarations 239 * will be enumerated. 240 * 241 * Here is an example: 242 * 243 * \code 244 * // excludeDeclsFromPCH = 1, displayDiagnostics=1 245 * Idx = clang_createIndex(1, 1); 246 * 247 * // IndexTest.pch was produced with the following command: 248 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 249 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 250 * 251 * // This will load all the symbols from 'IndexTest.pch' 252 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 253 * TranslationUnitVisitor, 0); 254 * clang_disposeTranslationUnit(TU); 255 * 256 * // This will load all the symbols from 'IndexTest.c', excluding symbols 257 * // from 'IndexTest.pch'. 258 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 259 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 260 * 0, 0); 261 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 262 * TranslationUnitVisitor, 0); 263 * clang_disposeTranslationUnit(TU); 264 * \endcode 265 * 266 * This process of creating the 'pch', loading it separately, and using it (via 267 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 268 * (which gives the indexer the same performance benefit as the compiler). 269 */ 270 CXIndex clang_createIndex( 271 int excludeDeclarationsFromPCH, 272 int displayDiagnostics); 273 274 /** 275 * \brief Destroy the given index. 276 * 277 * The index must not be destroyed until all of the translation units created 278 * within that index have been destroyed. 279 */ 280 void clang_disposeIndex(CXIndex index); 281 282 enum CXGlobalOptFlags 283 { 284 /** 285 * \brief Used to indicate that no special CXIndex options are needed. 286 */ 287 none = 0x0, 288 289 /** 290 * \brief Used to indicate that threads that libclang creates for indexing 291 * purposes should use background priority. 292 * 293 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit, 294 * #clang_parseTranslationUnit, #clang_saveTranslationUnit. 295 */ 296 threadBackgroundPriorityForIndexing = 0x1, 297 298 /** 299 * \brief Used to indicate that threads that libclang creates for editing 300 * purposes should use background priority. 301 * 302 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt, 303 * #clang_annotateTokens 304 */ 305 threadBackgroundPriorityForEditing = 0x2, 306 307 /** 308 * \brief Used to indicate that all threads that libclang creates should use 309 * background priority. 310 */ 311 threadBackgroundPriorityForAll = threadBackgroundPriorityForIndexing | threadBackgroundPriorityForEditing 312 } 313 314 /** 315 * \brief Sets general options associated with a CXIndex. 316 * 317 * For example: 318 * \code 319 * CXIndex idx = ...; 320 * clang_CXIndex_setGlobalOptions(idx, 321 * clang_CXIndex_getGlobalOptions(idx) | 322 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing); 323 * \endcode 324 * 325 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags. 326 */ 327 void clang_CXIndex_setGlobalOptions(CXIndex, uint options); 328 329 /** 330 * \brief Gets the general options associated with a CXIndex. 331 * 332 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that 333 * are associated with the given CXIndex object. 334 */ 335 uint clang_CXIndex_getGlobalOptions(CXIndex); 336 337 /** 338 * \brief Sets the invocation emission path option in a CXIndex. 339 * 340 * The invocation emission path specifies a path which will contain log 341 * files for certain libclang invocations. A null value (default) implies that 342 * libclang invocations are not logged.. 343 */ 344 void clang_CXIndex_setInvocationEmissionPathOption(CXIndex, const(char)* Path); 345 346 /** 347 * \defgroup CINDEX_FILES File manipulation routines 348 * 349 * @{ 350 */ 351 352 /** 353 * \brief A particular source file that is part of a translation unit. 354 */ 355 alias CXFile = void*; 356 357 /** 358 * \brief Retrieve the complete file and path name of the given file. 359 */ 360 CXString clang_getFileName(CXFile SFile); 361 362 /** 363 * \brief Retrieve the last modification time of the given file. 364 */ 365 time_t clang_getFileTime(CXFile SFile); 366 367 /** 368 * \brief Uniquely identifies a CXFile, that refers to the same underlying file, 369 * across an indexing session. 370 */ 371 struct CXFileUniqueID 372 { 373 ulong[3] data; 374 } 375 376 /** 377 * \brief Retrieve the unique ID for the given \c file. 378 * 379 * \param file the file to get the ID for. 380 * \param outID stores the returned CXFileUniqueID. 381 * \returns If there was a failure getting the unique ID, returns non-zero, 382 * otherwise returns 0. 383 */ 384 int clang_getFileUniqueID(CXFile file, CXFileUniqueID* outID); 385 386 /** 387 * \brief Determine whether the given header is guarded against 388 * multiple inclusions, either with the conventional 389 * \#ifndef/\#define/\#endif macro guards or with \#pragma once. 390 */ 391 uint clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file); 392 393 /** 394 * \brief Retrieve a file handle within the given translation unit. 395 * 396 * \param tu the translation unit 397 * 398 * \param file_name the name of the file. 399 * 400 * \returns the file handle for the named file in the translation unit \p tu, 401 * or a NULL file handle if the file was not a part of this translation unit. 402 */ 403 CXFile clang_getFile(CXTranslationUnit tu, const(char)* file_name); 404 405 /** 406 * \brief Retrieve the buffer associated with the given file. 407 * 408 * \param tu the translation unit 409 * 410 * \param file the file for which to retrieve the buffer. 411 * 412 * \param size [out] if non-NULL, will be set to the size of the buffer. 413 * 414 * \returns a pointer to the buffer in memory that holds the contents of 415 * \p file, or a NULL pointer when the file is not loaded. 416 */ 417 const(char)* clang_getFileContents( 418 CXTranslationUnit tu, 419 CXFile file, 420 size_t* size); 421 422 /** 423 * \brief Returns non-zero if the \c file1 and \c file2 point to the same file, 424 * or they are both NULL. 425 */ 426 int clang_File_isEqual(CXFile file1, CXFile file2); 427 428 /** 429 * @} 430 */ 431 432 /** 433 * \defgroup CINDEX_LOCATIONS Physical source locations 434 * 435 * Clang represents physical source locations in its abstract syntax tree in 436 * great detail, with file, line, and column information for the majority of 437 * the tokens parsed in the source code. These data types and functions are 438 * used to represent source location information, either for a particular 439 * point in the program or for a range of points in the program, and extract 440 * specific location information from those data types. 441 * 442 * @{ 443 */ 444 445 /** 446 * \brief Identifies a specific source location within a translation 447 * unit. 448 * 449 * Use clang_getExpansionLocation() or clang_getSpellingLocation() 450 * to map a source location to a particular file, line, and column. 451 */ 452 struct CXSourceLocation 453 { 454 const(void)*[2] ptr_data; 455 uint int_data; 456 } 457 458 /** 459 * \brief Identifies a half-open character range in the source code. 460 * 461 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 462 * starting and end locations from a source range, respectively. 463 */ 464 struct CXSourceRange 465 { 466 const(void)*[2] ptr_data; 467 uint begin_int_data; 468 uint end_int_data; 469 } 470 471 /** 472 * \brief Retrieve a NULL (invalid) source location. 473 */ 474 CXSourceLocation clang_getNullLocation(); 475 476 /** 477 * \brief Determine whether two source locations, which must refer into 478 * the same translation unit, refer to exactly the same point in the source 479 * code. 480 * 481 * \returns non-zero if the source locations refer to the same location, zero 482 * if they refer to different locations. 483 */ 484 uint clang_equalLocations(CXSourceLocation loc1, CXSourceLocation loc2); 485 486 /** 487 * \brief Retrieves the source location associated with a given file/line/column 488 * in a particular translation unit. 489 */ 490 CXSourceLocation clang_getLocation( 491 CXTranslationUnit tu, 492 CXFile file, 493 uint line, 494 uint column); 495 /** 496 * \brief Retrieves the source location associated with a given character offset 497 * in a particular translation unit. 498 */ 499 CXSourceLocation clang_getLocationForOffset( 500 CXTranslationUnit tu, 501 CXFile file, 502 uint offset); 503 504 /** 505 * \brief Returns non-zero if the given source location is in a system header. 506 */ 507 int clang_Location_isInSystemHeader(CXSourceLocation location); 508 509 /** 510 * \brief Returns non-zero if the given source location is in the main file of 511 * the corresponding translation unit. 512 */ 513 int clang_Location_isFromMainFile(CXSourceLocation location); 514 515 /** 516 * \brief Retrieve a NULL (invalid) source range. 517 */ 518 CXSourceRange clang_getNullRange(); 519 520 /** 521 * \brief Retrieve a source range given the beginning and ending source 522 * locations. 523 */ 524 CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end); 525 526 /** 527 * \brief Determine whether two ranges are equivalent. 528 * 529 * \returns non-zero if the ranges are the same, zero if they differ. 530 */ 531 uint clang_equalRanges(CXSourceRange range1, CXSourceRange range2); 532 533 /** 534 * \brief Returns non-zero if \p range is null. 535 */ 536 int clang_Range_isNull(CXSourceRange range); 537 538 /** 539 * \brief Retrieve the file, line, column, and offset represented by 540 * the given source location. 541 * 542 * If the location refers into a macro expansion, retrieves the 543 * location of the macro expansion. 544 * 545 * \param location the location within a source file that will be decomposed 546 * into its parts. 547 * 548 * \param file [out] if non-NULL, will be set to the file to which the given 549 * source location points. 550 * 551 * \param line [out] if non-NULL, will be set to the line to which the given 552 * source location points. 553 * 554 * \param column [out] if non-NULL, will be set to the column to which the given 555 * source location points. 556 * 557 * \param offset [out] if non-NULL, will be set to the offset into the 558 * buffer to which the given source location points. 559 */ 560 void clang_getExpansionLocation( 561 CXSourceLocation location, 562 CXFile* file, 563 uint* line, 564 uint* column, 565 uint* offset); 566 567 /** 568 * \brief Retrieve the file, line and column represented by the given source 569 * location, as specified in a # line directive. 570 * 571 * Example: given the following source code in a file somefile.c 572 * 573 * \code 574 * #123 "dummy.c" 1 575 * 576 * static int func(void) 577 * { 578 * return 0; 579 * } 580 * \endcode 581 * 582 * the location information returned by this function would be 583 * 584 * File: dummy.c Line: 124 Column: 12 585 * 586 * whereas clang_getExpansionLocation would have returned 587 * 588 * File: somefile.c Line: 3 Column: 12 589 * 590 * \param location the location within a source file that will be decomposed 591 * into its parts. 592 * 593 * \param filename [out] if non-NULL, will be set to the filename of the 594 * source location. Note that filenames returned will be for "virtual" files, 595 * which don't necessarily exist on the machine running clang - e.g. when 596 * parsing preprocessed output obtained from a different environment. If 597 * a non-NULL value is passed in, remember to dispose of the returned value 598 * using \c clang_disposeString() once you've finished with it. For an invalid 599 * source location, an empty string is returned. 600 * 601 * \param line [out] if non-NULL, will be set to the line number of the 602 * source location. For an invalid source location, zero is returned. 603 * 604 * \param column [out] if non-NULL, will be set to the column number of the 605 * source location. For an invalid source location, zero is returned. 606 */ 607 void clang_getPresumedLocation( 608 CXSourceLocation location, 609 CXString* filename, 610 uint* line, 611 uint* column); 612 613 /** 614 * \brief Legacy API to retrieve the file, line, column, and offset represented 615 * by the given source location. 616 * 617 * This interface has been replaced by the newer interface 618 * #clang_getExpansionLocation(). See that interface's documentation for 619 * details. 620 */ 621 void clang_getInstantiationLocation( 622 CXSourceLocation location, 623 CXFile* file, 624 uint* line, 625 uint* column, 626 uint* offset); 627 628 /** 629 * \brief Retrieve the file, line, column, and offset represented by 630 * the given source location. 631 * 632 * If the location refers into a macro instantiation, return where the 633 * location was originally spelled in the source file. 634 * 635 * \param location the location within a source file that will be decomposed 636 * into its parts. 637 * 638 * \param file [out] if non-NULL, will be set to the file to which the given 639 * source location points. 640 * 641 * \param line [out] if non-NULL, will be set to the line to which the given 642 * source location points. 643 * 644 * \param column [out] if non-NULL, will be set to the column to which the given 645 * source location points. 646 * 647 * \param offset [out] if non-NULL, will be set to the offset into the 648 * buffer to which the given source location points. 649 */ 650 void clang_getSpellingLocation( 651 CXSourceLocation location, 652 CXFile* file, 653 uint* line, 654 uint* column, 655 uint* offset); 656 657 /** 658 * \brief Retrieve the file, line, column, and offset represented by 659 * the given source location. 660 * 661 * If the location refers into a macro expansion, return where the macro was 662 * expanded or where the macro argument was written, if the location points at 663 * a macro argument. 664 * 665 * \param location the location within a source file that will be decomposed 666 * into its parts. 667 * 668 * \param file [out] if non-NULL, will be set to the file to which the given 669 * source location points. 670 * 671 * \param line [out] if non-NULL, will be set to the line to which the given 672 * source location points. 673 * 674 * \param column [out] if non-NULL, will be set to the column to which the given 675 * source location points. 676 * 677 * \param offset [out] if non-NULL, will be set to the offset into the 678 * buffer to which the given source location points. 679 */ 680 void clang_getFileLocation( 681 CXSourceLocation location, 682 CXFile* file, 683 uint* line, 684 uint* column, 685 uint* offset); 686 687 /** 688 * \brief Retrieve a source location representing the first character within a 689 * source range. 690 */ 691 CXSourceLocation clang_getRangeStart(CXSourceRange range); 692 693 /** 694 * \brief Retrieve a source location representing the last character within a 695 * source range. 696 */ 697 CXSourceLocation clang_getRangeEnd(CXSourceRange range); 698 699 /** 700 * \brief Identifies an array of ranges. 701 */ 702 struct CXSourceRangeList 703 { 704 /** \brief The number of ranges in the \c ranges array. */ 705 uint count; 706 /** 707 * \brief An array of \c CXSourceRanges. 708 */ 709 CXSourceRange* ranges; 710 } 711 712 /** 713 * \brief Retrieve all ranges that were skipped by the preprocessor. 714 * 715 * The preprocessor will skip lines when they are surrounded by an 716 * if/ifdef/ifndef directive whose condition does not evaluate to true. 717 */ 718 CXSourceRangeList* clang_getSkippedRanges(CXTranslationUnit tu, CXFile file); 719 720 /** 721 * \brief Retrieve all ranges from all files that were skipped by the 722 * preprocessor. 723 * 724 * The preprocessor will skip lines when they are surrounded by an 725 * if/ifdef/ifndef directive whose condition does not evaluate to true. 726 */ 727 CXSourceRangeList* clang_getAllSkippedRanges(CXTranslationUnit tu); 728 729 /** 730 * \brief Destroy the given \c CXSourceRangeList. 731 */ 732 void clang_disposeSourceRangeList(CXSourceRangeList* ranges); 733 734 /** 735 * @} 736 */ 737 738 /** 739 * \defgroup CINDEX_DIAG Diagnostic reporting 740 * 741 * @{ 742 */ 743 744 /** 745 * \brief Describes the severity of a particular diagnostic. 746 */ 747 enum CXDiagnosticSeverity 748 { 749 /** 750 * \brief A diagnostic that has been suppressed, e.g., by a command-line 751 * option. 752 */ 753 ignored = 0, 754 755 /** 756 * \brief This diagnostic is a note that should be attached to the 757 * previous (non-note) diagnostic. 758 */ 759 note = 1, 760 761 /** 762 * \brief This diagnostic indicates suspicious code that may not be 763 * wrong. 764 */ 765 warning = 2, 766 767 /** 768 * \brief This diagnostic indicates that the code is ill-formed. 769 */ 770 error = 3, 771 772 /** 773 * \brief This diagnostic indicates that the code is ill-formed such 774 * that future parser recovery is unlikely to produce useful 775 * results. 776 */ 777 fatal = 4 778 } 779 780 /** 781 * \brief A single diagnostic, containing the diagnostic's severity, 782 * location, text, source ranges, and fix-it hints. 783 */ 784 alias CXDiagnostic = void*; 785 786 /** 787 * \brief A group of CXDiagnostics. 788 */ 789 alias CXDiagnosticSet = void*; 790 791 /** 792 * \brief Determine the number of diagnostics in a CXDiagnosticSet. 793 */ 794 uint clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags); 795 796 /** 797 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet. 798 * 799 * \param Diags the CXDiagnosticSet to query. 800 * \param Index the zero-based diagnostic number to retrieve. 801 * 802 * \returns the requested diagnostic. This diagnostic must be freed 803 * via a call to \c clang_disposeDiagnostic(). 804 */ 805 CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, uint Index); 806 807 /** 808 * \brief Describes the kind of error that occurred (if any) in a call to 809 * \c clang_loadDiagnostics. 810 */ 811 enum CXLoadDiag_Error 812 { 813 /** 814 * \brief Indicates that no error occurred. 815 */ 816 none = 0, 817 818 /** 819 * \brief Indicates that an unknown error occurred while attempting to 820 * deserialize diagnostics. 821 */ 822 unknown = 1, 823 824 /** 825 * \brief Indicates that the file containing the serialized diagnostics 826 * could not be opened. 827 */ 828 cannotLoad = 2, 829 830 /** 831 * \brief Indicates that the serialized diagnostics file is invalid or 832 * corrupt. 833 */ 834 invalidFile = 3 835 } 836 837 /** 838 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode 839 * file. 840 * 841 * \param file The name of the file to deserialize. 842 * \param error A pointer to a enum value recording if there was a problem 843 * deserializing the diagnostics. 844 * \param errorString A pointer to a CXString for recording the error string 845 * if the file was not successfully loaded. 846 * 847 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These 848 * diagnostics should be released using clang_disposeDiagnosticSet(). 849 */ 850 CXDiagnosticSet clang_loadDiagnostics( 851 const(char)* file, 852 CXLoadDiag_Error* error, 853 CXString* errorString); 854 855 /** 856 * \brief Release a CXDiagnosticSet and all of its contained diagnostics. 857 */ 858 void clang_disposeDiagnosticSet(CXDiagnosticSet Diags); 859 860 /** 861 * \brief Retrieve the child diagnostics of a CXDiagnostic. 862 * 863 * This CXDiagnosticSet does not need to be released by 864 * clang_disposeDiagnosticSet. 865 */ 866 CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D); 867 868 /** 869 * \brief Determine the number of diagnostics produced for the given 870 * translation unit. 871 */ 872 uint clang_getNumDiagnostics(CXTranslationUnit Unit); 873 874 /** 875 * \brief Retrieve a diagnostic associated with the given translation unit. 876 * 877 * \param Unit the translation unit to query. 878 * \param Index the zero-based diagnostic number to retrieve. 879 * 880 * \returns the requested diagnostic. This diagnostic must be freed 881 * via a call to \c clang_disposeDiagnostic(). 882 */ 883 CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, uint Index); 884 885 /** 886 * \brief Retrieve the complete set of diagnostics associated with a 887 * translation unit. 888 * 889 * \param Unit the translation unit to query. 890 */ 891 CXDiagnosticSet clang_getDiagnosticSetFromTU(CXTranslationUnit Unit); 892 893 /** 894 * \brief Destroy a diagnostic. 895 */ 896 void clang_disposeDiagnostic(CXDiagnostic Diagnostic); 897 898 /** 899 * \brief Options to control the display of diagnostics. 900 * 901 * The values in this enum are meant to be combined to customize the 902 * behavior of \c clang_formatDiagnostic(). 903 */ 904 enum CXDiagnosticDisplayOptions 905 { 906 /** 907 * \brief Display the source-location information where the 908 * diagnostic was located. 909 * 910 * When set, diagnostics will be prefixed by the file, line, and 911 * (optionally) column to which the diagnostic refers. For example, 912 * 913 * \code 914 * test.c:28: warning: extra tokens at end of #endif directive 915 * \endcode 916 * 917 * This option corresponds to the clang flag \c -fshow-source-location. 918 */ 919 displaySourceLocation = 0x01, 920 921 /** 922 * \brief If displaying the source-location information of the 923 * diagnostic, also include the column number. 924 * 925 * This option corresponds to the clang flag \c -fshow-column. 926 */ 927 displayColumn = 0x02, 928 929 /** 930 * \brief If displaying the source-location information of the 931 * diagnostic, also include information about source ranges in a 932 * machine-parsable format. 933 * 934 * This option corresponds to the clang flag 935 * \c -fdiagnostics-print-source-range-info. 936 */ 937 displaySourceRanges = 0x04, 938 939 /** 940 * \brief Display the option name associated with this diagnostic, if any. 941 * 942 * The option name displayed (e.g., -Wconversion) will be placed in brackets 943 * after the diagnostic text. This option corresponds to the clang flag 944 * \c -fdiagnostics-show-option. 945 */ 946 displayOption = 0x08, 947 948 /** 949 * \brief Display the category number associated with this diagnostic, if any. 950 * 951 * The category number is displayed within brackets after the diagnostic text. 952 * This option corresponds to the clang flag 953 * \c -fdiagnostics-show-category=id. 954 */ 955 displayCategoryId = 0x10, 956 957 /** 958 * \brief Display the category name associated with this diagnostic, if any. 959 * 960 * The category name is displayed within brackets after the diagnostic text. 961 * This option corresponds to the clang flag 962 * \c -fdiagnostics-show-category=name. 963 */ 964 displayCategoryName = 0x20 965 } 966 967 /** 968 * \brief Format the given diagnostic in a manner that is suitable for display. 969 * 970 * This routine will format the given diagnostic to a string, rendering 971 * the diagnostic according to the various options given. The 972 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of 973 * options that most closely mimics the behavior of the clang compiler. 974 * 975 * \param Diagnostic The diagnostic to print. 976 * 977 * \param Options A set of options that control the diagnostic display, 978 * created by combining \c CXDiagnosticDisplayOptions values. 979 * 980 * \returns A new string containing for formatted diagnostic. 981 */ 982 CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, uint Options); 983 984 /** 985 * \brief Retrieve the set of display options most similar to the 986 * default behavior of the clang compiler. 987 * 988 * \returns A set of display options suitable for use with \c 989 * clang_formatDiagnostic(). 990 */ 991 uint clang_defaultDiagnosticDisplayOptions(); 992 993 /** 994 * \brief Determine the severity of the given diagnostic. 995 */ 996 CXDiagnosticSeverity clang_getDiagnosticSeverity(CXDiagnostic); 997 998 /** 999 * \brief Retrieve the source location of the given diagnostic. 1000 * 1001 * This location is where Clang would print the caret ('^') when 1002 * displaying the diagnostic on the command line. 1003 */ 1004 CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); 1005 1006 /** 1007 * \brief Retrieve the text of the given diagnostic. 1008 */ 1009 CXString clang_getDiagnosticSpelling(CXDiagnostic); 1010 1011 /** 1012 * \brief Retrieve the name of the command-line option that enabled this 1013 * diagnostic. 1014 * 1015 * \param Diag The diagnostic to be queried. 1016 * 1017 * \param Disable If non-NULL, will be set to the option that disables this 1018 * diagnostic (if any). 1019 * 1020 * \returns A string that contains the command-line option used to enable this 1021 * warning, such as "-Wconversion" or "-pedantic". 1022 */ 1023 CXString clang_getDiagnosticOption(CXDiagnostic Diag, CXString* Disable); 1024 1025 /** 1026 * \brief Retrieve the category number for this diagnostic. 1027 * 1028 * Diagnostics can be categorized into groups along with other, related 1029 * diagnostics (e.g., diagnostics under the same warning flag). This routine 1030 * retrieves the category number for the given diagnostic. 1031 * 1032 * \returns The number of the category that contains this diagnostic, or zero 1033 * if this diagnostic is uncategorized. 1034 */ 1035 uint clang_getDiagnosticCategory(CXDiagnostic); 1036 1037 /** 1038 * \brief Retrieve the name of a particular diagnostic category. This 1039 * is now deprecated. Use clang_getDiagnosticCategoryText() 1040 * instead. 1041 * 1042 * \param Category A diagnostic category number, as returned by 1043 * \c clang_getDiagnosticCategory(). 1044 * 1045 * \returns The name of the given diagnostic category. 1046 */ 1047 CXString clang_getDiagnosticCategoryName(uint Category); 1048 1049 /** 1050 * \brief Retrieve the diagnostic category text for a given diagnostic. 1051 * 1052 * \returns The text of the given diagnostic category. 1053 */ 1054 CXString clang_getDiagnosticCategoryText(CXDiagnostic); 1055 1056 /** 1057 * \brief Determine the number of source ranges associated with the given 1058 * diagnostic. 1059 */ 1060 uint clang_getDiagnosticNumRanges(CXDiagnostic); 1061 1062 /** 1063 * \brief Retrieve a source range associated with the diagnostic. 1064 * 1065 * A diagnostic's source ranges highlight important elements in the source 1066 * code. On the command line, Clang displays source ranges by 1067 * underlining them with '~' characters. 1068 * 1069 * \param Diagnostic the diagnostic whose range is being extracted. 1070 * 1071 * \param Range the zero-based index specifying which range to 1072 * 1073 * \returns the requested source range. 1074 */ 1075 CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, uint Range); 1076 1077 /** 1078 * \brief Determine the number of fix-it hints associated with the 1079 * given diagnostic. 1080 */ 1081 uint clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); 1082 1083 /** 1084 * \brief Retrieve the replacement information for a given fix-it. 1085 * 1086 * Fix-its are described in terms of a source range whose contents 1087 * should be replaced by a string. This approach generalizes over 1088 * three kinds of operations: removal of source code (the range covers 1089 * the code to be removed and the replacement string is empty), 1090 * replacement of source code (the range covers the code to be 1091 * replaced and the replacement string provides the new code), and 1092 * insertion (both the start and end of the range point at the 1093 * insertion location, and the replacement string provides the text to 1094 * insert). 1095 * 1096 * \param Diagnostic The diagnostic whose fix-its are being queried. 1097 * 1098 * \param FixIt The zero-based index of the fix-it. 1099 * 1100 * \param ReplacementRange The source range whose contents will be 1101 * replaced with the returned replacement string. Note that source 1102 * ranges are half-open ranges [a, b), so the source code should be 1103 * replaced from a and up to (but not including) b. 1104 * 1105 * \returns A string containing text that should be replace the source 1106 * code indicated by the \c ReplacementRange. 1107 */ 1108 CXString clang_getDiagnosticFixIt( 1109 CXDiagnostic Diagnostic, 1110 uint FixIt, 1111 CXSourceRange* ReplacementRange); 1112 1113 /** 1114 * @} 1115 */ 1116 1117 /** 1118 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation 1119 * 1120 * The routines in this group provide the ability to create and destroy 1121 * translation units from files, either by parsing the contents of the files or 1122 * by reading in a serialized representation of a translation unit. 1123 * 1124 * @{ 1125 */ 1126 1127 /** 1128 * \brief Get the original translation unit source file name. 1129 */ 1130 CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 1131 1132 /** 1133 * \brief Return the CXTranslationUnit for a given source file and the provided 1134 * command line arguments one would pass to the compiler. 1135 * 1136 * Note: The 'source_filename' argument is optional. If the caller provides a 1137 * NULL pointer, the name of the source file is expected to reside in the 1138 * specified command line arguments. 1139 * 1140 * Note: When encountered in 'clang_command_line_args', the following options 1141 * are ignored: 1142 * 1143 * '-c' 1144 * '-emit-ast' 1145 * '-fsyntax-only' 1146 * '-o \<output file>' (both '-o' and '\<output file>' are ignored) 1147 * 1148 * \param CIdx The index object with which the translation unit will be 1149 * associated. 1150 * 1151 * \param source_filename The name of the source file to load, or NULL if the 1152 * source file is included in \p clang_command_line_args. 1153 * 1154 * \param num_clang_command_line_args The number of command-line arguments in 1155 * \p clang_command_line_args. 1156 * 1157 * \param clang_command_line_args The command-line arguments that would be 1158 * passed to the \c clang executable if it were being invoked out-of-process. 1159 * These command-line options will be parsed and will affect how the translation 1160 * unit is parsed. Note that the following options are ignored: '-c', 1161 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'. 1162 * 1163 * \param num_unsaved_files the number of unsaved file entries in \p 1164 * unsaved_files. 1165 * 1166 * \param unsaved_files the files that have not yet been saved to disk 1167 * but may be required for code completion, including the contents of 1168 * those files. The contents and name of these files (as specified by 1169 * CXUnsavedFile) are copied when necessary, so the client only needs to 1170 * guarantee their validity until the call to this function returns. 1171 */ 1172 CXTranslationUnit clang_createTranslationUnitFromSourceFile( 1173 CXIndex CIdx, 1174 const(char)* source_filename, 1175 int num_clang_command_line_args, 1176 const(char*)* clang_command_line_args, 1177 uint num_unsaved_files, 1178 CXUnsavedFile* unsaved_files); 1179 1180 /** 1181 * \brief Same as \c clang_createTranslationUnit2, but returns 1182 * the \c CXTranslationUnit instead of an error code. In case of an error this 1183 * routine returns a \c NULL \c CXTranslationUnit, without further detailed 1184 * error codes. 1185 */ 1186 CXTranslationUnit clang_createTranslationUnit( 1187 CXIndex CIdx, 1188 const(char)* ast_filename); 1189 1190 /** 1191 * \brief Create a translation unit from an AST file (\c -emit-ast). 1192 * 1193 * \param[out] out_TU A non-NULL pointer to store the created 1194 * \c CXTranslationUnit. 1195 * 1196 * \returns Zero on success, otherwise returns an error code. 1197 */ 1198 CXErrorCode clang_createTranslationUnit2( 1199 CXIndex CIdx, 1200 const(char)* ast_filename, 1201 CXTranslationUnit* out_TU); 1202 1203 /** 1204 * \brief Flags that control the creation of translation units. 1205 * 1206 * The enumerators in this enumeration type are meant to be bitwise 1207 * ORed together to specify which options should be used when 1208 * constructing the translation unit. 1209 */ 1210 enum CXTranslationUnit_Flags 1211 { 1212 /** 1213 * \brief Used to indicate that no special translation-unit options are 1214 * needed. 1215 */ 1216 none = 0x0, 1217 1218 /** 1219 * \brief Used to indicate that the parser should construct a "detailed" 1220 * preprocessing record, including all macro definitions and instantiations. 1221 * 1222 * Constructing a detailed preprocessing record requires more memory 1223 * and time to parse, since the information contained in the record 1224 * is usually not retained. However, it can be useful for 1225 * applications that require more detailed information about the 1226 * behavior of the preprocessor. 1227 */ 1228 detailedPreprocessingRecord = 0x01, 1229 1230 /** 1231 * \brief Used to indicate that the translation unit is incomplete. 1232 * 1233 * When a translation unit is considered "incomplete", semantic 1234 * analysis that is typically performed at the end of the 1235 * translation unit will be suppressed. For example, this suppresses 1236 * the completion of tentative declarations in C and of 1237 * instantiation of implicitly-instantiation function templates in 1238 * C++. This option is typically used when parsing a header with the 1239 * intent of producing a precompiled header. 1240 */ 1241 incomplete = 0x02, 1242 1243 /** 1244 * \brief Used to indicate that the translation unit should be built with an 1245 * implicit precompiled header for the preamble. 1246 * 1247 * An implicit precompiled header is used as an optimization when a 1248 * particular translation unit is likely to be reparsed many times 1249 * when the sources aren't changing that often. In this case, an 1250 * implicit precompiled header will be built containing all of the 1251 * initial includes at the top of the main file (what we refer to as 1252 * the "preamble" of the file). In subsequent parses, if the 1253 * preamble or the files in it have not changed, \c 1254 * clang_reparseTranslationUnit() will re-use the implicit 1255 * precompiled header to improve parsing performance. 1256 */ 1257 precompiledPreamble = 0x04, 1258 1259 /** 1260 * \brief Used to indicate that the translation unit should cache some 1261 * code-completion results with each reparse of the source file. 1262 * 1263 * Caching of code-completion results is a performance optimization that 1264 * introduces some overhead to reparsing but improves the performance of 1265 * code-completion operations. 1266 */ 1267 cacheCompletionResults = 0x08, 1268 1269 /** 1270 * \brief Used to indicate that the translation unit will be serialized with 1271 * \c clang_saveTranslationUnit. 1272 * 1273 * This option is typically used when parsing a header with the intent of 1274 * producing a precompiled header. 1275 */ 1276 forSerialization = 0x10, 1277 1278 /** 1279 * \brief DEPRECATED: Enabled chained precompiled preambles in C++. 1280 * 1281 * Note: this is a *temporary* option that is available only while 1282 * we are testing C++ precompiled preamble support. It is deprecated. 1283 */ 1284 cxxChainedPCH = 0x20, 1285 1286 /** 1287 * \brief Used to indicate that function/method bodies should be skipped while 1288 * parsing. 1289 * 1290 * This option can be used to search for declarations/definitions while 1291 * ignoring the usages. 1292 */ 1293 skipFunctionBodies = 0x40, 1294 1295 /** 1296 * \brief Used to indicate that brief documentation comments should be 1297 * included into the set of code completions returned from this translation 1298 * unit. 1299 */ 1300 includeBriefCommentsInCodeCompletion = 0x80, 1301 1302 /** 1303 * \brief Used to indicate that the precompiled preamble should be created on 1304 * the first parse. Otherwise it will be created on the first reparse. This 1305 * trades runtime on the first parse (serializing the preamble takes time) for 1306 * reduced runtime on the second parse (can now reuse the preamble). 1307 */ 1308 createPreambleOnFirstParse = 0x100, 1309 1310 /** 1311 * \brief Do not stop processing when fatal errors are encountered. 1312 * 1313 * When fatal errors are encountered while parsing a translation unit, 1314 * semantic analysis is typically stopped early when compiling code. A common 1315 * source for fatal errors are unresolvable include files. For the 1316 * purposes of an IDE, this is undesirable behavior and as much information 1317 * as possible should be reported. Use this flag to enable this behavior. 1318 */ 1319 keepGoing = 0x200, 1320 1321 /** 1322 * \brief Sets the preprocessor in a mode for parsing a single file only. 1323 */ 1324 singleFileParse = 0x400 1325 } 1326 1327 /** 1328 * \brief Returns the set of flags that is suitable for parsing a translation 1329 * unit that is being edited. 1330 * 1331 * The set of flags returned provide options for \c clang_parseTranslationUnit() 1332 * to indicate that the translation unit is likely to be reparsed many times, 1333 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly 1334 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag 1335 * set contains an unspecified set of optimizations (e.g., the precompiled 1336 * preamble) geared toward improving the performance of these routines. The 1337 * set of optimizations enabled may change from one version to the next. 1338 */ 1339 uint clang_defaultEditingTranslationUnitOptions(); 1340 1341 /** 1342 * \brief Same as \c clang_parseTranslationUnit2, but returns 1343 * the \c CXTranslationUnit instead of an error code. In case of an error this 1344 * routine returns a \c NULL \c CXTranslationUnit, without further detailed 1345 * error codes. 1346 */ 1347 CXTranslationUnit clang_parseTranslationUnit( 1348 CXIndex CIdx, 1349 const(char)* source_filename, 1350 const(char*)* command_line_args, 1351 int num_command_line_args, 1352 CXUnsavedFile* unsaved_files, 1353 uint num_unsaved_files, 1354 uint options); 1355 1356 /** 1357 * \brief Parse the given source file and the translation unit corresponding 1358 * to that file. 1359 * 1360 * This routine is the main entry point for the Clang C API, providing the 1361 * ability to parse a source file into a translation unit that can then be 1362 * queried by other functions in the API. This routine accepts a set of 1363 * command-line arguments so that the compilation can be configured in the same 1364 * way that the compiler is configured on the command line. 1365 * 1366 * \param CIdx The index object with which the translation unit will be 1367 * associated. 1368 * 1369 * \param source_filename The name of the source file to load, or NULL if the 1370 * source file is included in \c command_line_args. 1371 * 1372 * \param command_line_args The command-line arguments that would be 1373 * passed to the \c clang executable if it were being invoked out-of-process. 1374 * These command-line options will be parsed and will affect how the translation 1375 * unit is parsed. Note that the following options are ignored: '-c', 1376 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'. 1377 * 1378 * \param num_command_line_args The number of command-line arguments in 1379 * \c command_line_args. 1380 * 1381 * \param unsaved_files the files that have not yet been saved to disk 1382 * but may be required for parsing, including the contents of 1383 * those files. The contents and name of these files (as specified by 1384 * CXUnsavedFile) are copied when necessary, so the client only needs to 1385 * guarantee their validity until the call to this function returns. 1386 * 1387 * \param num_unsaved_files the number of unsaved file entries in \p 1388 * unsaved_files. 1389 * 1390 * \param options A bitmask of options that affects how the translation unit 1391 * is managed but not its compilation. This should be a bitwise OR of the 1392 * CXTranslationUnit_XXX flags. 1393 * 1394 * \param[out] out_TU A non-NULL pointer to store the created 1395 * \c CXTranslationUnit, describing the parsed code and containing any 1396 * diagnostics produced by the compiler. 1397 * 1398 * \returns Zero on success, otherwise returns an error code. 1399 */ 1400 CXErrorCode clang_parseTranslationUnit2( 1401 CXIndex CIdx, 1402 const(char)* source_filename, 1403 const(char*)* command_line_args, 1404 int num_command_line_args, 1405 CXUnsavedFile* unsaved_files, 1406 uint num_unsaved_files, 1407 uint options, 1408 CXTranslationUnit* out_TU); 1409 1410 /** 1411 * \brief Same as clang_parseTranslationUnit2 but requires a full command line 1412 * for \c command_line_args including argv[0]. This is useful if the standard 1413 * library paths are relative to the binary. 1414 */ 1415 CXErrorCode clang_parseTranslationUnit2FullArgv( 1416 CXIndex CIdx, 1417 const(char)* source_filename, 1418 const(char*)* command_line_args, 1419 int num_command_line_args, 1420 CXUnsavedFile* unsaved_files, 1421 uint num_unsaved_files, 1422 uint options, 1423 CXTranslationUnit* out_TU); 1424 1425 /** 1426 * \brief Flags that control how translation units are saved. 1427 * 1428 * The enumerators in this enumeration type are meant to be bitwise 1429 * ORed together to specify which options should be used when 1430 * saving the translation unit. 1431 */ 1432 enum CXSaveTranslationUnit_Flags 1433 { 1434 /** 1435 * \brief Used to indicate that no special saving options are needed. 1436 */ 1437 none = 0x0 1438 } 1439 1440 /** 1441 * \brief Returns the set of flags that is suitable for saving a translation 1442 * unit. 1443 * 1444 * The set of flags returned provide options for 1445 * \c clang_saveTranslationUnit() by default. The returned flag 1446 * set contains an unspecified set of options that save translation units with 1447 * the most commonly-requested data. 1448 */ 1449 uint clang_defaultSaveOptions(CXTranslationUnit TU); 1450 1451 /** 1452 * \brief Describes the kind of error that occurred (if any) in a call to 1453 * \c clang_saveTranslationUnit(). 1454 */ 1455 enum CXSaveError 1456 { 1457 /** 1458 * \brief Indicates that no error occurred while saving a translation unit. 1459 */ 1460 none = 0, 1461 1462 /** 1463 * \brief Indicates that an unknown error occurred while attempting to save 1464 * the file. 1465 * 1466 * This error typically indicates that file I/O failed when attempting to 1467 * write the file. 1468 */ 1469 unknown = 1, 1470 1471 /** 1472 * \brief Indicates that errors during translation prevented this attempt 1473 * to save the translation unit. 1474 * 1475 * Errors that prevent the translation unit from being saved can be 1476 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic(). 1477 */ 1478 translationErrors = 2, 1479 1480 /** 1481 * \brief Indicates that the translation unit to be saved was somehow 1482 * invalid (e.g., NULL). 1483 */ 1484 invalidTU = 3 1485 } 1486 1487 /** 1488 * \brief Saves a translation unit into a serialized representation of 1489 * that translation unit on disk. 1490 * 1491 * Any translation unit that was parsed without error can be saved 1492 * into a file. The translation unit can then be deserialized into a 1493 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or, 1494 * if it is an incomplete translation unit that corresponds to a 1495 * header, used as a precompiled header when parsing other translation 1496 * units. 1497 * 1498 * \param TU The translation unit to save. 1499 * 1500 * \param FileName The file to which the translation unit will be saved. 1501 * 1502 * \param options A bitmask of options that affects how the translation unit 1503 * is saved. This should be a bitwise OR of the 1504 * CXSaveTranslationUnit_XXX flags. 1505 * 1506 * \returns A value that will match one of the enumerators of the CXSaveError 1507 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was 1508 * saved successfully, while a non-zero value indicates that a problem occurred. 1509 */ 1510 int clang_saveTranslationUnit( 1511 CXTranslationUnit TU, 1512 const(char)* FileName, 1513 uint options); 1514 1515 /** 1516 * \brief Suspend a translation unit in order to free memory associated with it. 1517 * 1518 * A suspended translation unit uses significantly less memory but on the other 1519 * side does not support any other calls than \c clang_reparseTranslationUnit 1520 * to resume it or \c clang_disposeTranslationUnit to dispose it completely. 1521 */ 1522 uint clang_suspendTranslationUnit(CXTranslationUnit); 1523 1524 /** 1525 * \brief Destroy the specified CXTranslationUnit object. 1526 */ 1527 void clang_disposeTranslationUnit(CXTranslationUnit); 1528 1529 /** 1530 * \brief Flags that control the reparsing of translation units. 1531 * 1532 * The enumerators in this enumeration type are meant to be bitwise 1533 * ORed together to specify which options should be used when 1534 * reparsing the translation unit. 1535 */ 1536 enum CXReparse_Flags 1537 { 1538 /** 1539 * \brief Used to indicate that no special reparsing options are needed. 1540 */ 1541 none = 0x0 1542 } 1543 1544 /** 1545 * \brief Returns the set of flags that is suitable for reparsing a translation 1546 * unit. 1547 * 1548 * The set of flags returned provide options for 1549 * \c clang_reparseTranslationUnit() by default. The returned flag 1550 * set contains an unspecified set of optimizations geared toward common uses 1551 * of reparsing. The set of optimizations enabled may change from one version 1552 * to the next. 1553 */ 1554 uint clang_defaultReparseOptions(CXTranslationUnit TU); 1555 1556 /** 1557 * \brief Reparse the source files that produced this translation unit. 1558 * 1559 * This routine can be used to re-parse the source files that originally 1560 * created the given translation unit, for example because those source files 1561 * have changed (either on disk or as passed via \p unsaved_files). The 1562 * source code will be reparsed with the same command-line options as it 1563 * was originally parsed. 1564 * 1565 * Reparsing a translation unit invalidates all cursors and source locations 1566 * that refer into that translation unit. This makes reparsing a translation 1567 * unit semantically equivalent to destroying the translation unit and then 1568 * creating a new translation unit with the same command-line arguments. 1569 * However, it may be more efficient to reparse a translation 1570 * unit using this routine. 1571 * 1572 * \param TU The translation unit whose contents will be re-parsed. The 1573 * translation unit must originally have been built with 1574 * \c clang_createTranslationUnitFromSourceFile(). 1575 * 1576 * \param num_unsaved_files The number of unsaved file entries in \p 1577 * unsaved_files. 1578 * 1579 * \param unsaved_files The files that have not yet been saved to disk 1580 * but may be required for parsing, including the contents of 1581 * those files. The contents and name of these files (as specified by 1582 * CXUnsavedFile) are copied when necessary, so the client only needs to 1583 * guarantee their validity until the call to this function returns. 1584 * 1585 * \param options A bitset of options composed of the flags in CXReparse_Flags. 1586 * The function \c clang_defaultReparseOptions() produces a default set of 1587 * options recommended for most uses, based on the translation unit. 1588 * 1589 * \returns 0 if the sources could be reparsed. A non-zero error code will be 1590 * returned if reparsing was impossible, such that the translation unit is 1591 * invalid. In such cases, the only valid call for \c TU is 1592 * \c clang_disposeTranslationUnit(TU). The error codes returned by this 1593 * routine are described by the \c CXErrorCode enum. 1594 */ 1595 int clang_reparseTranslationUnit( 1596 CXTranslationUnit TU, 1597 uint num_unsaved_files, 1598 CXUnsavedFile* unsaved_files, 1599 uint options); 1600 1601 /** 1602 * \brief Categorizes how memory is being used by a translation unit. 1603 */ 1604 enum CXTUResourceUsageKind 1605 { 1606 ast = 1, 1607 identifiers = 2, 1608 selectors = 3, 1609 globalCompletionResults = 4, 1610 sourceManagerContentCache = 5, 1611 astSideTables = 6, 1612 sourceManagerMembufferMalloc = 7, 1613 sourceManagerMembufferMMap = 8, 1614 externalASTSourceMembufferMalloc = 9, 1615 externalASTSourceMembufferMMap = 10, 1616 preprocessor = 11, 1617 preprocessingRecord = 12, 1618 sourceManagerDataStructures = 13, 1619 preprocessorHeaderSearch = 14, 1620 memoryInBytesBegin = ast, 1621 memoryInBytesEnd = preprocessorHeaderSearch, 1622 1623 first = ast, 1624 last = preprocessorHeaderSearch 1625 } 1626 1627 /** 1628 * \brief Returns the human-readable null-terminated C string that represents 1629 * the name of the memory category. This string should never be freed. 1630 */ 1631 const(char)* clang_getTUResourceUsageName(CXTUResourceUsageKind kind); 1632 1633 struct CXTUResourceUsageEntry 1634 { 1635 /* \brief The memory usage category. */ 1636 CXTUResourceUsageKind kind; 1637 /* \brief Amount of resources used. 1638 The units will depend on the resource kind. */ 1639 c_ulong amount; 1640 } 1641 1642 /** 1643 * \brief The memory usage of a CXTranslationUnit, broken into categories. 1644 */ 1645 struct CXTUResourceUsage 1646 { 1647 /* \brief Private data member, used for queries. */ 1648 void* data; 1649 1650 /* \brief The number of entries in the 'entries' array. */ 1651 uint numEntries; 1652 1653 /* \brief An array of key-value pairs, representing the breakdown of memory 1654 usage. */ 1655 CXTUResourceUsageEntry* entries; 1656 } 1657 1658 /** 1659 * \brief Return the memory usage of a translation unit. This object 1660 * should be released with clang_disposeCXTUResourceUsage(). 1661 */ 1662 CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU); 1663 1664 void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage); 1665 1666 /** 1667 * \brief Get target information for this translation unit. 1668 * 1669 * The CXTargetInfo object cannot outlive the CXTranslationUnit object. 1670 */ 1671 CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit); 1672 1673 /** 1674 * \brief Destroy the CXTargetInfo object. 1675 */ 1676 void clang_TargetInfo_dispose(CXTargetInfo Info); 1677 1678 /** 1679 * \brief Get the normalized target triple as a string. 1680 * 1681 * Returns the empty string in case of any error. 1682 */ 1683 CXString clang_TargetInfo_getTriple(CXTargetInfo Info); 1684 1685 /** 1686 * \brief Get the pointer width of the target in bits. 1687 * 1688 * Returns -1 in case of error. 1689 */ 1690 int clang_TargetInfo_getPointerWidth(CXTargetInfo Info); 1691 1692 /** 1693 * @} 1694 */ 1695 1696 /** 1697 * \brief Describes the kind of entity that a cursor refers to. 1698 */ 1699 enum CXCursorKind 1700 { 1701 /* Declarations */ 1702 /** 1703 * \brief A declaration whose specific kind is not exposed via this 1704 * interface. 1705 * 1706 * Unexposed declarations have the same operations as any other kind 1707 * of declaration; one can extract their location information, 1708 * spelling, find their definitions, etc. However, the specific kind 1709 * of the declaration is not reported. 1710 */ 1711 unexposedDecl = 1, 1712 /** \brief A C or C++ struct. */ 1713 structDecl = 2, 1714 /** \brief A C or C++ union. */ 1715 unionDecl = 3, 1716 /** \brief A C++ class. */ 1717 classDecl = 4, 1718 /** \brief An enumeration. */ 1719 enumDecl = 5, 1720 /** 1721 * \brief A field (in C) or non-static data member (in C++) in a 1722 * struct, union, or C++ class. 1723 */ 1724 fieldDecl = 6, 1725 /** \brief An enumerator constant. */ 1726 enumConstantDecl = 7, 1727 /** \brief A function. */ 1728 functionDecl = 8, 1729 /** \brief A variable. */ 1730 varDecl = 9, 1731 /** \brief A function or method parameter. */ 1732 parmDecl = 10, 1733 /** \brief An Objective-C \@interface. */ 1734 objCInterfaceDecl = 11, 1735 /** \brief An Objective-C \@interface for a category. */ 1736 objCCategoryDecl = 12, 1737 /** \brief An Objective-C \@protocol declaration. */ 1738 objCProtocolDecl = 13, 1739 /** \brief An Objective-C \@property declaration. */ 1740 objCPropertyDecl = 14, 1741 /** \brief An Objective-C instance variable. */ 1742 objCIvarDecl = 15, 1743 /** \brief An Objective-C instance method. */ 1744 objCInstanceMethodDecl = 16, 1745 /** \brief An Objective-C class method. */ 1746 objCClassMethodDecl = 17, 1747 /** \brief An Objective-C \@implementation. */ 1748 objCImplementationDecl = 18, 1749 /** \brief An Objective-C \@implementation for a category. */ 1750 objCCategoryImplDecl = 19, 1751 /** \brief A typedef. */ 1752 typedefDecl = 20, 1753 /** \brief A C++ class method. */ 1754 cxxMethod = 21, 1755 /** \brief A C++ namespace. */ 1756 namespace = 22, 1757 /** \brief A linkage specification, e.g. 'extern "C"'. */ 1758 linkageSpec = 23, 1759 /** \brief A C++ constructor. */ 1760 constructor = 24, 1761 /** \brief A C++ destructor. */ 1762 destructor = 25, 1763 /** \brief A C++ conversion function. */ 1764 conversionFunction = 26, 1765 /** \brief A C++ template type parameter. */ 1766 templateTypeParameter = 27, 1767 /** \brief A C++ non-type template parameter. */ 1768 nonTypeTemplateParameter = 28, 1769 /** \brief A C++ template template parameter. */ 1770 templateTemplateParameter = 29, 1771 /** \brief A C++ function template. */ 1772 functionTemplate = 30, 1773 /** \brief A C++ class template. */ 1774 classTemplate = 31, 1775 /** \brief A C++ class template partial specialization. */ 1776 classTemplatePartialSpecialization = 32, 1777 /** \brief A C++ namespace alias declaration. */ 1778 namespaceAlias = 33, 1779 /** \brief A C++ using directive. */ 1780 usingDirective = 34, 1781 /** \brief A C++ using declaration. */ 1782 usingDeclaration = 35, 1783 /** \brief A C++ alias declaration */ 1784 typeAliasDecl = 36, 1785 /** \brief An Objective-C \@synthesize definition. */ 1786 objCSynthesizeDecl = 37, 1787 /** \brief An Objective-C \@dynamic definition. */ 1788 objCDynamicDecl = 38, 1789 /** \brief An access specifier. */ 1790 cxxAccessSpecifier = 39, 1791 1792 firstDecl = unexposedDecl, 1793 lastDecl = cxxAccessSpecifier, 1794 1795 /* References */ 1796 firstRef = 40, /* Decl references */ 1797 objCSuperClassRef = 40, 1798 objCProtocolRef = 41, 1799 objCClassRef = 42, 1800 /** 1801 * \brief A reference to a type declaration. 1802 * 1803 * A type reference occurs anywhere where a type is named but not 1804 * declared. For example, given: 1805 * 1806 * \code 1807 * typedef unsigned size_type; 1808 * size_type size; 1809 * \endcode 1810 * 1811 * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 1812 * while the type of the variable "size" is referenced. The cursor 1813 * referenced by the type of size is the typedef for size_type. 1814 */ 1815 typeRef = 43, 1816 cxxBaseSpecifier = 44, 1817 /** 1818 * \brief A reference to a class template, function template, template 1819 * template parameter, or class template partial specialization. 1820 */ 1821 templateRef = 45, 1822 /** 1823 * \brief A reference to a namespace or namespace alias. 1824 */ 1825 namespaceRef = 46, 1826 /** 1827 * \brief A reference to a member of a struct, union, or class that occurs in 1828 * some non-expression context, e.g., a designated initializer. 1829 */ 1830 memberRef = 47, 1831 /** 1832 * \brief A reference to a labeled statement. 1833 * 1834 * This cursor kind is used to describe the jump to "start_over" in the 1835 * goto statement in the following example: 1836 * 1837 * \code 1838 * start_over: 1839 * ++counter; 1840 * 1841 * goto start_over; 1842 * \endcode 1843 * 1844 * A label reference cursor refers to a label statement. 1845 */ 1846 labelRef = 48, 1847 1848 /** 1849 * \brief A reference to a set of overloaded functions or function templates 1850 * that has not yet been resolved to a specific function or function template. 1851 * 1852 * An overloaded declaration reference cursor occurs in C++ templates where 1853 * a dependent name refers to a function. For example: 1854 * 1855 * \code 1856 * template<typename T> void swap(T&, T&); 1857 * 1858 * struct X { ... }; 1859 * void swap(X&, X&); 1860 * 1861 * template<typename T> 1862 * void reverse(T* first, T* last) { 1863 * while (first < last - 1) { 1864 * swap(*first, *--last); 1865 * ++first; 1866 * } 1867 * } 1868 * 1869 * struct Y { }; 1870 * void swap(Y&, Y&); 1871 * \endcode 1872 * 1873 * Here, the identifier "swap" is associated with an overloaded declaration 1874 * reference. In the template definition, "swap" refers to either of the two 1875 * "swap" functions declared above, so both results will be available. At 1876 * instantiation time, "swap" may also refer to other functions found via 1877 * argument-dependent lookup (e.g., the "swap" function at the end of the 1878 * example). 1879 * 1880 * The functions \c clang_getNumOverloadedDecls() and 1881 * \c clang_getOverloadedDecl() can be used to retrieve the definitions 1882 * referenced by this cursor. 1883 */ 1884 overloadedDeclRef = 49, 1885 1886 /** 1887 * \brief A reference to a variable that occurs in some non-expression 1888 * context, e.g., a C++ lambda capture list. 1889 */ 1890 variableRef = 50, 1891 1892 lastRef = variableRef, 1893 1894 /* Error conditions */ 1895 firstInvalid = 70, 1896 invalidFile = 70, 1897 noDeclFound = 71, 1898 notImplemented = 72, 1899 invalidCode = 73, 1900 lastInvalid = invalidCode, 1901 1902 /* Expressions */ 1903 firstExpr = 100, 1904 1905 /** 1906 * \brief An expression whose specific kind is not exposed via this 1907 * interface. 1908 * 1909 * Unexposed expressions have the same operations as any other kind 1910 * of expression; one can extract their location information, 1911 * spelling, children, etc. However, the specific kind of the 1912 * expression is not reported. 1913 */ 1914 unexposedExpr = 100, 1915 1916 /** 1917 * \brief An expression that refers to some value declaration, such 1918 * as a function, variable, or enumerator. 1919 */ 1920 declRefExpr = 101, 1921 1922 /** 1923 * \brief An expression that refers to a member of a struct, union, 1924 * class, Objective-C class, etc. 1925 */ 1926 memberRefExpr = 102, 1927 1928 /** \brief An expression that calls a function. */ 1929 callExpr = 103, 1930 1931 /** \brief An expression that sends a message to an Objective-C 1932 object or class. */ 1933 objCMessageExpr = 104, 1934 1935 /** \brief An expression that represents a block literal. */ 1936 blockExpr = 105, 1937 1938 /** \brief An integer literal. 1939 */ 1940 integerLiteral = 106, 1941 1942 /** \brief A floating point number literal. 1943 */ 1944 floatingLiteral = 107, 1945 1946 /** \brief An imaginary number literal. 1947 */ 1948 imaginaryLiteral = 108, 1949 1950 /** \brief A string literal. 1951 */ 1952 stringLiteral = 109, 1953 1954 /** \brief A character literal. 1955 */ 1956 characterLiteral = 110, 1957 1958 /** \brief A parenthesized expression, e.g. "(1)". 1959 * 1960 * This AST node is only formed if full location information is requested. 1961 */ 1962 parenExpr = 111, 1963 1964 /** \brief This represents the unary-expression's (except sizeof and 1965 * alignof). 1966 */ 1967 unaryOperator = 112, 1968 1969 /** \brief [C99 6.5.2.1] Array Subscripting. 1970 */ 1971 arraySubscriptExpr = 113, 1972 1973 /** \brief A builtin binary operation expression such as "x + y" or 1974 * "x <= y". 1975 */ 1976 binaryOperator = 114, 1977 1978 /** \brief Compound assignment such as "+=". 1979 */ 1980 compoundAssignOperator = 115, 1981 1982 /** \brief The ?: ternary operator. 1983 */ 1984 conditionalOperator = 116, 1985 1986 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++ 1987 * (C++ [expr.cast]), which uses the syntax (Type)expr. 1988 * 1989 * For example: (int)f. 1990 */ 1991 cStyleCastExpr = 117, 1992 1993 /** \brief [C99 6.5.2.5] 1994 */ 1995 compoundLiteralExpr = 118, 1996 1997 /** \brief Describes an C or C++ initializer list. 1998 */ 1999 initListExpr = 119, 2000 2001 /** \brief The GNU address of label extension, representing &&label. 2002 */ 2003 addrLabelExpr = 120, 2004 2005 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;}) 2006 */ 2007 stmtExpr = 121, 2008 2009 /** \brief Represents a C11 generic selection. 2010 */ 2011 genericSelectionExpr = 122, 2012 2013 /** \brief Implements the GNU __null extension, which is a name for a null 2014 * pointer constant that has integral type (e.g., int or long) and is the same 2015 * size and alignment as a pointer. 2016 * 2017 * The __null extension is typically only used by system headers, which define 2018 * NULL as __null in C++ rather than using 0 (which is an integer that may not 2019 * match the size of a pointer). 2020 */ 2021 gnuNullExpr = 123, 2022 2023 /** \brief C++'s static_cast<> expression. 2024 */ 2025 cxxStaticCastExpr = 124, 2026 2027 /** \brief C++'s dynamic_cast<> expression. 2028 */ 2029 cxxDynamicCastExpr = 125, 2030 2031 /** \brief C++'s reinterpret_cast<> expression. 2032 */ 2033 cxxReinterpretCastExpr = 126, 2034 2035 /** \brief C++'s const_cast<> expression. 2036 */ 2037 cxxConstCastExpr = 127, 2038 2039 /** \brief Represents an explicit C++ type conversion that uses "functional" 2040 * notion (C++ [expr.type.conv]). 2041 * 2042 * Example: 2043 * \code 2044 * x = int(0.5); 2045 * \endcode 2046 */ 2047 cxxFunctionalCastExpr = 128, 2048 2049 /** \brief A C++ typeid expression (C++ [expr.typeid]). 2050 */ 2051 cxxTypeidExpr = 129, 2052 2053 /** \brief [C++ 2.13.5] C++ Boolean Literal. 2054 */ 2055 cxxBoolLiteralExpr = 130, 2056 2057 /** \brief [C++0x 2.14.7] C++ Pointer Literal. 2058 */ 2059 cxxNullPtrLiteralExpr = 131, 2060 2061 /** \brief Represents the "this" expression in C++ 2062 */ 2063 cxxThisExpr = 132, 2064 2065 /** \brief [C++ 15] C++ Throw Expression. 2066 * 2067 * This handles 'throw' and 'throw' assignment-expression. When 2068 * assignment-expression isn't present, Op will be null. 2069 */ 2070 cxxThrowExpr = 133, 2071 2072 /** \brief A new expression for memory allocation and constructor calls, e.g: 2073 * "new CXXNewExpr(foo)". 2074 */ 2075 cxxNewExpr = 134, 2076 2077 /** \brief A delete expression for memory deallocation and destructor calls, 2078 * e.g. "delete[] pArray". 2079 */ 2080 cxxDeleteExpr = 135, 2081 2082 /** \brief A unary expression. (noexcept, sizeof, or other traits) 2083 */ 2084 unaryExpr = 136, 2085 2086 /** \brief An Objective-C string literal i.e. @"foo". 2087 */ 2088 objCStringLiteral = 137, 2089 2090 /** \brief An Objective-C \@encode expression. 2091 */ 2092 objCEncodeExpr = 138, 2093 2094 /** \brief An Objective-C \@selector expression. 2095 */ 2096 objCSelectorExpr = 139, 2097 2098 /** \brief An Objective-C \@protocol expression. 2099 */ 2100 objCProtocolExpr = 140, 2101 2102 /** \brief An Objective-C "bridged" cast expression, which casts between 2103 * Objective-C pointers and C pointers, transferring ownership in the process. 2104 * 2105 * \code 2106 * NSString *str = (__bridge_transfer NSString *)CFCreateString(); 2107 * \endcode 2108 */ 2109 objCBridgedCastExpr = 141, 2110 2111 /** \brief Represents a C++0x pack expansion that produces a sequence of 2112 * expressions. 2113 * 2114 * A pack expansion expression contains a pattern (which itself is an 2115 * expression) followed by an ellipsis. For example: 2116 * 2117 * \code 2118 * template<typename F, typename ...Types> 2119 * void forward(F f, Types &&...args) { 2120 * f(static_cast<Types&&>(args)...); 2121 * } 2122 * \endcode 2123 */ 2124 packExpansionExpr = 142, 2125 2126 /** \brief Represents an expression that computes the length of a parameter 2127 * pack. 2128 * 2129 * \code 2130 * template<typename ...Types> 2131 * struct count { 2132 * static const unsigned value = sizeof...(Types); 2133 * }; 2134 * \endcode 2135 */ 2136 sizeOfPackExpr = 143, 2137 2138 /* \brief Represents a C++ lambda expression that produces a local function 2139 * object. 2140 * 2141 * \code 2142 * void abssort(float *x, unsigned N) { 2143 * std::sort(x, x + N, 2144 * [](float a, float b) { 2145 * return std::abs(a) < std::abs(b); 2146 * }); 2147 * } 2148 * \endcode 2149 */ 2150 lambdaExpr = 144, 2151 2152 /** \brief Objective-c Boolean Literal. 2153 */ 2154 objCBoolLiteralExpr = 145, 2155 2156 /** \brief Represents the "self" expression in an Objective-C method. 2157 */ 2158 objCSelfExpr = 146, 2159 2160 /** \brief OpenMP 4.0 [2.4, Array Section]. 2161 */ 2162 ompArraySectionExpr = 147, 2163 2164 /** \brief Represents an @available(...) check. 2165 */ 2166 objCAvailabilityCheckExpr = 148, 2167 2168 lastExpr = objCAvailabilityCheckExpr, 2169 2170 /* Statements */ 2171 firstStmt = 200, 2172 /** 2173 * \brief A statement whose specific kind is not exposed via this 2174 * interface. 2175 * 2176 * Unexposed statements have the same operations as any other kind of 2177 * statement; one can extract their location information, spelling, 2178 * children, etc. However, the specific kind of the statement is not 2179 * reported. 2180 */ 2181 unexposedStmt = 200, 2182 2183 /** \brief A labelled statement in a function. 2184 * 2185 * This cursor kind is used to describe the "start_over:" label statement in 2186 * the following example: 2187 * 2188 * \code 2189 * start_over: 2190 * ++counter; 2191 * \endcode 2192 * 2193 */ 2194 labelStmt = 201, 2195 2196 /** \brief A group of statements like { stmt stmt }. 2197 * 2198 * This cursor kind is used to describe compound statements, e.g. function 2199 * bodies. 2200 */ 2201 compoundStmt = 202, 2202 2203 /** \brief A case statement. 2204 */ 2205 caseStmt = 203, 2206 2207 /** \brief A default statement. 2208 */ 2209 defaultStmt = 204, 2210 2211 /** \brief An if statement 2212 */ 2213 ifStmt = 205, 2214 2215 /** \brief A switch statement. 2216 */ 2217 switchStmt = 206, 2218 2219 /** \brief A while statement. 2220 */ 2221 whileStmt = 207, 2222 2223 /** \brief A do statement. 2224 */ 2225 doStmt = 208, 2226 2227 /** \brief A for statement. 2228 */ 2229 forStmt = 209, 2230 2231 /** \brief A goto statement. 2232 */ 2233 gotoStmt = 210, 2234 2235 /** \brief An indirect goto statement. 2236 */ 2237 indirectGotoStmt = 211, 2238 2239 /** \brief A continue statement. 2240 */ 2241 continueStmt = 212, 2242 2243 /** \brief A break statement. 2244 */ 2245 breakStmt = 213, 2246 2247 /** \brief A return statement. 2248 */ 2249 returnStmt = 214, 2250 2251 /** \brief A GCC inline assembly statement extension. 2252 */ 2253 gccAsmStmt = 215, 2254 asmStmt = gccAsmStmt, 2255 2256 /** \brief Objective-C's overall \@try-\@catch-\@finally statement. 2257 */ 2258 objCAtTryStmt = 216, 2259 2260 /** \brief Objective-C's \@catch statement. 2261 */ 2262 objCAtCatchStmt = 217, 2263 2264 /** \brief Objective-C's \@finally statement. 2265 */ 2266 objCAtFinallyStmt = 218, 2267 2268 /** \brief Objective-C's \@throw statement. 2269 */ 2270 objCAtThrowStmt = 219, 2271 2272 /** \brief Objective-C's \@synchronized statement. 2273 */ 2274 objCAtSynchronizedStmt = 220, 2275 2276 /** \brief Objective-C's autorelease pool statement. 2277 */ 2278 objCAutoreleasePoolStmt = 221, 2279 2280 /** \brief Objective-C's collection statement. 2281 */ 2282 objCForCollectionStmt = 222, 2283 2284 /** \brief C++'s catch statement. 2285 */ 2286 cxxCatchStmt = 223, 2287 2288 /** \brief C++'s try statement. 2289 */ 2290 cxxTryStmt = 224, 2291 2292 /** \brief C++'s for (* : *) statement. 2293 */ 2294 cxxForRangeStmt = 225, 2295 2296 /** \brief Windows Structured Exception Handling's try statement. 2297 */ 2298 sehTryStmt = 226, 2299 2300 /** \brief Windows Structured Exception Handling's except statement. 2301 */ 2302 sehExceptStmt = 227, 2303 2304 /** \brief Windows Structured Exception Handling's finally statement. 2305 */ 2306 sehFinallyStmt = 228, 2307 2308 /** \brief A MS inline assembly statement extension. 2309 */ 2310 msAsmStmt = 229, 2311 2312 /** \brief The null statement ";": C99 6.8.3p3. 2313 * 2314 * This cursor kind is used to describe the null statement. 2315 */ 2316 nullStmt = 230, 2317 2318 /** \brief Adaptor class for mixing declarations with statements and 2319 * expressions. 2320 */ 2321 declStmt = 231, 2322 2323 /** \brief OpenMP parallel directive. 2324 */ 2325 ompParallelDirective = 232, 2326 2327 /** \brief OpenMP SIMD directive. 2328 */ 2329 ompSimdDirective = 233, 2330 2331 /** \brief OpenMP for directive. 2332 */ 2333 ompForDirective = 234, 2334 2335 /** \brief OpenMP sections directive. 2336 */ 2337 ompSectionsDirective = 235, 2338 2339 /** \brief OpenMP section directive. 2340 */ 2341 ompSectionDirective = 236, 2342 2343 /** \brief OpenMP single directive. 2344 */ 2345 ompSingleDirective = 237, 2346 2347 /** \brief OpenMP parallel for directive. 2348 */ 2349 ompParallelForDirective = 238, 2350 2351 /** \brief OpenMP parallel sections directive. 2352 */ 2353 ompParallelSectionsDirective = 239, 2354 2355 /** \brief OpenMP task directive. 2356 */ 2357 ompTaskDirective = 240, 2358 2359 /** \brief OpenMP master directive. 2360 */ 2361 ompMasterDirective = 241, 2362 2363 /** \brief OpenMP critical directive. 2364 */ 2365 ompCriticalDirective = 242, 2366 2367 /** \brief OpenMP taskyield directive. 2368 */ 2369 ompTaskyieldDirective = 243, 2370 2371 /** \brief OpenMP barrier directive. 2372 */ 2373 ompBarrierDirective = 244, 2374 2375 /** \brief OpenMP taskwait directive. 2376 */ 2377 ompTaskwaitDirective = 245, 2378 2379 /** \brief OpenMP flush directive. 2380 */ 2381 ompFlushDirective = 246, 2382 2383 /** \brief Windows Structured Exception Handling's leave statement. 2384 */ 2385 sehLeaveStmt = 247, 2386 2387 /** \brief OpenMP ordered directive. 2388 */ 2389 ompOrderedDirective = 248, 2390 2391 /** \brief OpenMP atomic directive. 2392 */ 2393 ompAtomicDirective = 249, 2394 2395 /** \brief OpenMP for SIMD directive. 2396 */ 2397 ompForSimdDirective = 250, 2398 2399 /** \brief OpenMP parallel for SIMD directive. 2400 */ 2401 ompParallelForSimdDirective = 251, 2402 2403 /** \brief OpenMP target directive. 2404 */ 2405 ompTargetDirective = 252, 2406 2407 /** \brief OpenMP teams directive. 2408 */ 2409 ompTeamsDirective = 253, 2410 2411 /** \brief OpenMP taskgroup directive. 2412 */ 2413 ompTaskgroupDirective = 254, 2414 2415 /** \brief OpenMP cancellation point directive. 2416 */ 2417 ompCancellationPointDirective = 255, 2418 2419 /** \brief OpenMP cancel directive. 2420 */ 2421 ompCancelDirective = 256, 2422 2423 /** \brief OpenMP target data directive. 2424 */ 2425 ompTargetDataDirective = 257, 2426 2427 /** \brief OpenMP taskloop directive. 2428 */ 2429 ompTaskLoopDirective = 258, 2430 2431 /** \brief OpenMP taskloop simd directive. 2432 */ 2433 ompTaskLoopSimdDirective = 259, 2434 2435 /** \brief OpenMP distribute directive. 2436 */ 2437 ompDistributeDirective = 260, 2438 2439 /** \brief OpenMP target enter data directive. 2440 */ 2441 ompTargetEnterDataDirective = 261, 2442 2443 /** \brief OpenMP target exit data directive. 2444 */ 2445 ompTargetExitDataDirective = 262, 2446 2447 /** \brief OpenMP target parallel directive. 2448 */ 2449 ompTargetParallelDirective = 263, 2450 2451 /** \brief OpenMP target parallel for directive. 2452 */ 2453 ompTargetParallelForDirective = 264, 2454 2455 /** \brief OpenMP target update directive. 2456 */ 2457 ompTargetUpdateDirective = 265, 2458 2459 /** \brief OpenMP distribute parallel for directive. 2460 */ 2461 ompDistributeParallelForDirective = 266, 2462 2463 /** \brief OpenMP distribute parallel for simd directive. 2464 */ 2465 ompDistributeParallelForSimdDirective = 267, 2466 2467 /** \brief OpenMP distribute simd directive. 2468 */ 2469 ompDistributeSimdDirective = 268, 2470 2471 /** \brief OpenMP target parallel for simd directive. 2472 */ 2473 ompTargetParallelForSimdDirective = 269, 2474 2475 /** \brief OpenMP target simd directive. 2476 */ 2477 ompTargetSimdDirective = 270, 2478 2479 /** \brief OpenMP teams distribute directive. 2480 */ 2481 ompTeamsDistributeDirective = 271, 2482 2483 /** \brief OpenMP teams distribute simd directive. 2484 */ 2485 ompTeamsDistributeSimdDirective = 272, 2486 2487 /** \brief OpenMP teams distribute parallel for simd directive. 2488 */ 2489 ompTeamsDistributeParallelForSimdDirective = 273, 2490 2491 /** \brief OpenMP teams distribute parallel for directive. 2492 */ 2493 ompTeamsDistributeParallelForDirective = 274, 2494 2495 /** \brief OpenMP target teams directive. 2496 */ 2497 ompTargetTeamsDirective = 275, 2498 2499 /** \brief OpenMP target teams distribute directive. 2500 */ 2501 ompTargetTeamsDistributeDirective = 276, 2502 2503 /** \brief OpenMP target teams distribute parallel for directive. 2504 */ 2505 ompTargetTeamsDistributeParallelForDirective = 277, 2506 2507 /** \brief OpenMP target teams distribute parallel for simd directive. 2508 */ 2509 ompTargetTeamsDistributeParallelForSimdDirective = 278, 2510 2511 /** \brief OpenMP target teams distribute simd directive. 2512 */ 2513 ompTargetTeamsDistributeSimdDirective = 279, 2514 2515 lastStmt = ompTargetTeamsDistributeSimdDirective, 2516 2517 /** 2518 * \brief Cursor that represents the translation unit itself. 2519 * 2520 * The translation unit cursor exists primarily to act as the root 2521 * cursor for traversing the contents of a translation unit. 2522 */ 2523 translationUnit = 300, 2524 2525 /* Attributes */ 2526 firstAttr = 400, 2527 /** 2528 * \brief An attribute whose specific kind is not exposed via this 2529 * interface. 2530 */ 2531 unexposedAttr = 400, 2532 2533 ibActionAttr = 401, 2534 ibOutletAttr = 402, 2535 ibOutletCollectionAttr = 403, 2536 cxxFinalAttr = 404, 2537 cxxOverrideAttr = 405, 2538 annotateAttr = 406, 2539 asmLabelAttr = 407, 2540 packedAttr = 408, 2541 pureAttr = 409, 2542 constAttr = 410, 2543 noDuplicateAttr = 411, 2544 cudaConstantAttr = 412, 2545 cudaDeviceAttr = 413, 2546 cudaGlobalAttr = 414, 2547 cudaHostAttr = 415, 2548 cudaSharedAttr = 416, 2549 visibilityAttr = 417, 2550 dllExport = 418, 2551 dllImport = 419, 2552 lastAttr = dllImport, 2553 2554 /* Preprocessing */ 2555 preprocessingDirective = 500, 2556 macroDefinition = 501, 2557 macroExpansion = 502, 2558 macroInstantiation = macroExpansion, 2559 inclusionDirective = 503, 2560 firstPreprocessing = preprocessingDirective, 2561 lastPreprocessing = inclusionDirective, 2562 2563 /* Extra Declarations */ 2564 /** 2565 * \brief A module import declaration. 2566 */ 2567 moduleImportDecl = 600, 2568 typeAliasTemplateDecl = 601, 2569 /** 2570 * \brief A static_assert or _Static_assert node 2571 */ 2572 staticAssert = 602, 2573 /** 2574 * \brief a friend declaration. 2575 */ 2576 friendDecl = 603, 2577 firstExtraDecl = moduleImportDecl, 2578 lastExtraDecl = friendDecl, 2579 2580 /** 2581 * \brief A code completion overload candidate. 2582 */ 2583 overloadCandidate = 700 2584 } 2585 2586 /** 2587 * \brief A cursor representing some element in the abstract syntax tree for 2588 * a translation unit. 2589 * 2590 * The cursor abstraction unifies the different kinds of entities in a 2591 * program--declaration, statements, expressions, references to declarations, 2592 * etc.--under a single "cursor" abstraction with a common set of operations. 2593 * Common operation for a cursor include: getting the physical location in 2594 * a source file where the cursor points, getting the name associated with a 2595 * cursor, and retrieving cursors for any child nodes of a particular cursor. 2596 * 2597 * Cursors can be produced in two specific ways. 2598 * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 2599 * from which one can use clang_visitChildren() to explore the rest of the 2600 * translation unit. clang_getCursor() maps from a physical source location 2601 * to the entity that resides at that location, allowing one to map from the 2602 * source code into the AST. 2603 */ 2604 struct CXCursor 2605 { 2606 CXCursorKind kind; 2607 int xdata; 2608 const(void)*[3] data; 2609 } 2610 2611 /** 2612 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 2613 * 2614 * @{ 2615 */ 2616 2617 /** 2618 * \brief Retrieve the NULL cursor, which represents no entity. 2619 */ 2620 CXCursor clang_getNullCursor(); 2621 2622 /** 2623 * \brief Retrieve the cursor that represents the given translation unit. 2624 * 2625 * The translation unit cursor can be used to start traversing the 2626 * various declarations within the given translation unit. 2627 */ 2628 CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 2629 2630 /** 2631 * \brief Determine whether two cursors are equivalent. 2632 */ 2633 uint clang_equalCursors(CXCursor, CXCursor); 2634 2635 /** 2636 * \brief Returns non-zero if \p cursor is null. 2637 */ 2638 int clang_Cursor_isNull(CXCursor cursor); 2639 2640 /** 2641 * \brief Compute a hash value for the given cursor. 2642 */ 2643 uint clang_hashCursor(CXCursor); 2644 2645 /** 2646 * \brief Retrieve the kind of the given cursor. 2647 */ 2648 CXCursorKind clang_getCursorKind(CXCursor); 2649 2650 /** 2651 * \brief Determine whether the given cursor kind represents a declaration. 2652 */ 2653 uint clang_isDeclaration(CXCursorKind); 2654 2655 /** 2656 * \brief Determine whether the given cursor kind represents a simple 2657 * reference. 2658 * 2659 * Note that other kinds of cursors (such as expressions) can also refer to 2660 * other cursors. Use clang_getCursorReferenced() to determine whether a 2661 * particular cursor refers to another entity. 2662 */ 2663 uint clang_isReference(CXCursorKind); 2664 2665 /** 2666 * \brief Determine whether the given cursor kind represents an expression. 2667 */ 2668 uint clang_isExpression(CXCursorKind); 2669 2670 /** 2671 * \brief Determine whether the given cursor kind represents a statement. 2672 */ 2673 uint clang_isStatement(CXCursorKind); 2674 2675 /** 2676 * \brief Determine whether the given cursor kind represents an attribute. 2677 */ 2678 uint clang_isAttribute(CXCursorKind); 2679 2680 /** 2681 * \brief Determine whether the given cursor has any attributes. 2682 */ 2683 uint clang_Cursor_hasAttrs(CXCursor C); 2684 2685 /** 2686 * \brief Determine whether the given cursor kind represents an invalid 2687 * cursor. 2688 */ 2689 uint clang_isInvalid(CXCursorKind); 2690 2691 /** 2692 * \brief Determine whether the given cursor kind represents a translation 2693 * unit. 2694 */ 2695 uint clang_isTranslationUnit(CXCursorKind); 2696 2697 /*** 2698 * \brief Determine whether the given cursor represents a preprocessing 2699 * element, such as a preprocessor directive or macro instantiation. 2700 */ 2701 uint clang_isPreprocessing(CXCursorKind); 2702 2703 /*** 2704 * \brief Determine whether the given cursor represents a currently 2705 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). 2706 */ 2707 uint clang_isUnexposed(CXCursorKind); 2708 2709 /** 2710 * \brief Describe the linkage of the entity referred to by a cursor. 2711 */ 2712 enum CXLinkageKind 2713 { 2714 /** \brief This value indicates that no linkage information is available 2715 * for a provided CXCursor. */ 2716 invalid = 0, 2717 /** 2718 * \brief This is the linkage for variables, parameters, and so on that 2719 * have automatic storage. This covers normal (non-extern) local variables. 2720 */ 2721 noLinkage = 1, 2722 /** \brief This is the linkage for static variables and static functions. */ 2723 internal = 2, 2724 /** \brief This is the linkage for entities with external linkage that live 2725 * in C++ anonymous namespaces.*/ 2726 uniqueExternal = 3, 2727 /** \brief This is the linkage for entities with true, external linkage. */ 2728 external = 4 2729 } 2730 2731 /** 2732 * \brief Determine the linkage of the entity referred to by a given cursor. 2733 */ 2734 CXLinkageKind clang_getCursorLinkage(CXCursor cursor); 2735 2736 enum CXVisibilityKind 2737 { 2738 /** \brief This value indicates that no visibility information is available 2739 * for a provided CXCursor. */ 2740 invalid = 0, 2741 2742 /** \brief Symbol not seen by the linker. */ 2743 hidden = 1, 2744 /** \brief Symbol seen by the linker but resolves to a symbol inside this object. */ 2745 protected_ = 2, 2746 /** \brief Symbol seen by the linker and acts like a normal symbol. */ 2747 default_ = 3 2748 } 2749 2750 /** 2751 * \brief Describe the visibility of the entity referred to by a cursor. 2752 * 2753 * This returns the default visibility if not explicitly specified by 2754 * a visibility attribute. The default visibility may be changed by 2755 * commandline arguments. 2756 * 2757 * \param cursor The cursor to query. 2758 * 2759 * \returns The visibility of the cursor. 2760 */ 2761 CXVisibilityKind clang_getCursorVisibility(CXCursor cursor); 2762 2763 /** 2764 * \brief Determine the availability of the entity that this cursor refers to, 2765 * taking the current target platform into account. 2766 * 2767 * \param cursor The cursor to query. 2768 * 2769 * \returns The availability of the cursor. 2770 */ 2771 CXAvailabilityKind clang_getCursorAvailability(CXCursor cursor); 2772 2773 /** 2774 * Describes the availability of a given entity on a particular platform, e.g., 2775 * a particular class might only be available on Mac OS 10.7 or newer. 2776 */ 2777 struct CXPlatformAvailability 2778 { 2779 /** 2780 * \brief A string that describes the platform for which this structure 2781 * provides availability information. 2782 * 2783 * Possible values are "ios" or "macos". 2784 */ 2785 CXString Platform; 2786 /** 2787 * \brief The version number in which this entity was introduced. 2788 */ 2789 CXVersion Introduced; 2790 /** 2791 * \brief The version number in which this entity was deprecated (but is 2792 * still available). 2793 */ 2794 CXVersion Deprecated; 2795 /** 2796 * \brief The version number in which this entity was obsoleted, and therefore 2797 * is no longer available. 2798 */ 2799 CXVersion Obsoleted; 2800 /** 2801 * \brief Whether the entity is unconditionally unavailable on this platform. 2802 */ 2803 int Unavailable; 2804 /** 2805 * \brief An optional message to provide to a user of this API, e.g., to 2806 * suggest replacement APIs. 2807 */ 2808 CXString Message; 2809 } 2810 2811 /** 2812 * \brief Determine the availability of the entity that this cursor refers to 2813 * on any platforms for which availability information is known. 2814 * 2815 * \param cursor The cursor to query. 2816 * 2817 * \param always_deprecated If non-NULL, will be set to indicate whether the 2818 * entity is deprecated on all platforms. 2819 * 2820 * \param deprecated_message If non-NULL, will be set to the message text 2821 * provided along with the unconditional deprecation of this entity. The client 2822 * is responsible for deallocating this string. 2823 * 2824 * \param always_unavailable If non-NULL, will be set to indicate whether the 2825 * entity is unavailable on all platforms. 2826 * 2827 * \param unavailable_message If non-NULL, will be set to the message text 2828 * provided along with the unconditional unavailability of this entity. The 2829 * client is responsible for deallocating this string. 2830 * 2831 * \param availability If non-NULL, an array of CXPlatformAvailability instances 2832 * that will be populated with platform availability information, up to either 2833 * the number of platforms for which availability information is available (as 2834 * returned by this function) or \c availability_size, whichever is smaller. 2835 * 2836 * \param availability_size The number of elements available in the 2837 * \c availability array. 2838 * 2839 * \returns The number of platforms (N) for which availability information is 2840 * available (which is unrelated to \c availability_size). 2841 * 2842 * Note that the client is responsible for calling 2843 * \c clang_disposeCXPlatformAvailability to free each of the 2844 * platform-availability structures returned. There are 2845 * \c min(N, availability_size) such structures. 2846 */ 2847 int clang_getCursorPlatformAvailability( 2848 CXCursor cursor, 2849 int* always_deprecated, 2850 CXString* deprecated_message, 2851 int* always_unavailable, 2852 CXString* unavailable_message, 2853 CXPlatformAvailability* availability, 2854 int availability_size); 2855 2856 /** 2857 * \brief Free the memory associated with a \c CXPlatformAvailability structure. 2858 */ 2859 void clang_disposeCXPlatformAvailability(CXPlatformAvailability* availability); 2860 2861 /** 2862 * \brief Describe the "language" of the entity referred to by a cursor. 2863 */ 2864 enum CXLanguageKind 2865 { 2866 invalid = 0, 2867 c = 1, 2868 objC = 2, 2869 cPlusPlus = 3 2870 } 2871 2872 /** 2873 * \brief Determine the "language" of the entity referred to by a given cursor. 2874 */ 2875 CXLanguageKind clang_getCursorLanguage(CXCursor cursor); 2876 2877 /** 2878 * \brief Describe the "thread-local storage (TLS) kind" of the declaration 2879 * referred to by a cursor. 2880 */ 2881 enum CXTLSKind 2882 { 2883 none = 0, 2884 dynamic = 1, 2885 static_ = 2 2886 } 2887 2888 /** 2889 * \brief Determine the "thread-local storage (TLS) kind" of the declaration 2890 * referred to by a cursor. 2891 */ 2892 CXTLSKind clang_getCursorTLSKind(CXCursor cursor); 2893 2894 /** 2895 * \brief Returns the translation unit that a cursor originated from. 2896 */ 2897 CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor); 2898 2899 /** 2900 * \brief A fast container representing a set of CXCursors. 2901 */ 2902 struct CXCursorSetImpl; 2903 alias CXCursorSet = CXCursorSetImpl*; 2904 2905 /** 2906 * \brief Creates an empty CXCursorSet. 2907 */ 2908 CXCursorSet clang_createCXCursorSet(); 2909 2910 /** 2911 * \brief Disposes a CXCursorSet and releases its associated memory. 2912 */ 2913 void clang_disposeCXCursorSet(CXCursorSet cset); 2914 2915 /** 2916 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor. 2917 * 2918 * \returns non-zero if the set contains the specified cursor. 2919 */ 2920 uint clang_CXCursorSet_contains(CXCursorSet cset, CXCursor cursor); 2921 2922 /** 2923 * \brief Inserts a CXCursor into a CXCursorSet. 2924 * 2925 * \returns zero if the CXCursor was already in the set, and non-zero otherwise. 2926 */ 2927 uint clang_CXCursorSet_insert(CXCursorSet cset, CXCursor cursor); 2928 2929 /** 2930 * \brief Determine the semantic parent of the given cursor. 2931 * 2932 * The semantic parent of a cursor is the cursor that semantically contains 2933 * the given \p cursor. For many declarations, the lexical and semantic parents 2934 * are equivalent (the lexical parent is returned by 2935 * \c clang_getCursorLexicalParent()). They diverge when declarations or 2936 * definitions are provided out-of-line. For example: 2937 * 2938 * \code 2939 * class C { 2940 * void f(); 2941 * }; 2942 * 2943 * void C::f() { } 2944 * \endcode 2945 * 2946 * In the out-of-line definition of \c C::f, the semantic parent is 2947 * the class \c C, of which this function is a member. The lexical parent is 2948 * the place where the declaration actually occurs in the source code; in this 2949 * case, the definition occurs in the translation unit. In general, the 2950 * lexical parent for a given entity can change without affecting the semantics 2951 * of the program, and the lexical parent of different declarations of the 2952 * same entity may be different. Changing the semantic parent of a declaration, 2953 * on the other hand, can have a major impact on semantics, and redeclarations 2954 * of a particular entity should all have the same semantic context. 2955 * 2956 * In the example above, both declarations of \c C::f have \c C as their 2957 * semantic context, while the lexical context of the first \c C::f is \c C 2958 * and the lexical context of the second \c C::f is the translation unit. 2959 * 2960 * For global declarations, the semantic parent is the translation unit. 2961 */ 2962 CXCursor clang_getCursorSemanticParent(CXCursor cursor); 2963 2964 /** 2965 * \brief Determine the lexical parent of the given cursor. 2966 * 2967 * The lexical parent of a cursor is the cursor in which the given \p cursor 2968 * was actually written. For many declarations, the lexical and semantic parents 2969 * are equivalent (the semantic parent is returned by 2970 * \c clang_getCursorSemanticParent()). They diverge when declarations or 2971 * definitions are provided out-of-line. For example: 2972 * 2973 * \code 2974 * class C { 2975 * void f(); 2976 * }; 2977 * 2978 * void C::f() { } 2979 * \endcode 2980 * 2981 * In the out-of-line definition of \c C::f, the semantic parent is 2982 * the class \c C, of which this function is a member. The lexical parent is 2983 * the place where the declaration actually occurs in the source code; in this 2984 * case, the definition occurs in the translation unit. In general, the 2985 * lexical parent for a given entity can change without affecting the semantics 2986 * of the program, and the lexical parent of different declarations of the 2987 * same entity may be different. Changing the semantic parent of a declaration, 2988 * on the other hand, can have a major impact on semantics, and redeclarations 2989 * of a particular entity should all have the same semantic context. 2990 * 2991 * In the example above, both declarations of \c C::f have \c C as their 2992 * semantic context, while the lexical context of the first \c C::f is \c C 2993 * and the lexical context of the second \c C::f is the translation unit. 2994 * 2995 * For declarations written in the global scope, the lexical parent is 2996 * the translation unit. 2997 */ 2998 CXCursor clang_getCursorLexicalParent(CXCursor cursor); 2999 3000 /** 3001 * \brief Determine the set of methods that are overridden by the given 3002 * method. 3003 * 3004 * In both Objective-C and C++, a method (aka virtual member function, 3005 * in C++) can override a virtual method in a base class. For 3006 * Objective-C, a method is said to override any method in the class's 3007 * base class, its protocols, or its categories' protocols, that has the same 3008 * selector and is of the same kind (class or instance). 3009 * If no such method exists, the search continues to the class's superclass, 3010 * its protocols, and its categories, and so on. A method from an Objective-C 3011 * implementation is considered to override the same methods as its 3012 * corresponding method in the interface. 3013 * 3014 * For C++, a virtual member function overrides any virtual member 3015 * function with the same signature that occurs in its base 3016 * classes. With multiple inheritance, a virtual member function can 3017 * override several virtual member functions coming from different 3018 * base classes. 3019 * 3020 * In all cases, this function determines the immediate overridden 3021 * method, rather than all of the overridden methods. For example, if 3022 * a method is originally declared in a class A, then overridden in B 3023 * (which in inherits from A) and also in C (which inherited from B), 3024 * then the only overridden method returned from this function when 3025 * invoked on C's method will be B's method. The client may then 3026 * invoke this function again, given the previously-found overridden 3027 * methods, to map out the complete method-override set. 3028 * 3029 * \param cursor A cursor representing an Objective-C or C++ 3030 * method. This routine will compute the set of methods that this 3031 * method overrides. 3032 * 3033 * \param overridden A pointer whose pointee will be replaced with a 3034 * pointer to an array of cursors, representing the set of overridden 3035 * methods. If there are no overridden methods, the pointee will be 3036 * set to NULL. The pointee must be freed via a call to 3037 * \c clang_disposeOverriddenCursors(). 3038 * 3039 * \param num_overridden A pointer to the number of overridden 3040 * functions, will be set to the number of overridden functions in the 3041 * array pointed to by \p overridden. 3042 */ 3043 void clang_getOverriddenCursors( 3044 CXCursor cursor, 3045 CXCursor** overridden, 3046 uint* num_overridden); 3047 3048 /** 3049 * \brief Free the set of overridden cursors returned by \c 3050 * clang_getOverriddenCursors(). 3051 */ 3052 void clang_disposeOverriddenCursors(CXCursor* overridden); 3053 3054 /** 3055 * \brief Retrieve the file that is included by the given inclusion directive 3056 * cursor. 3057 */ 3058 CXFile clang_getIncludedFile(CXCursor cursor); 3059 3060 /** 3061 * @} 3062 */ 3063 3064 /** 3065 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 3066 * 3067 * Cursors represent a location within the Abstract Syntax Tree (AST). These 3068 * routines help map between cursors and the physical locations where the 3069 * described entities occur in the source code. The mapping is provided in 3070 * both directions, so one can map from source code to the AST and back. 3071 * 3072 * @{ 3073 */ 3074 3075 /** 3076 * \brief Map a source location to the cursor that describes the entity at that 3077 * location in the source code. 3078 * 3079 * clang_getCursor() maps an arbitrary source location within a translation 3080 * unit down to the most specific cursor that describes the entity at that 3081 * location. For example, given an expression \c x + y, invoking 3082 * clang_getCursor() with a source location pointing to "x" will return the 3083 * cursor for "x"; similarly for "y". If the cursor points anywhere between 3084 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 3085 * will return a cursor referring to the "+" expression. 3086 * 3087 * \returns a cursor representing the entity at the given source location, or 3088 * a NULL cursor if no such entity can be found. 3089 */ 3090 CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 3091 3092 /** 3093 * \brief Retrieve the physical location of the source constructor referenced 3094 * by the given cursor. 3095 * 3096 * The location of a declaration is typically the location of the name of that 3097 * declaration, where the name of that declaration would occur if it is 3098 * unnamed, or some keyword that introduces that particular declaration. 3099 * The location of a reference is where that reference occurs within the 3100 * source code. 3101 */ 3102 CXSourceLocation clang_getCursorLocation(CXCursor); 3103 3104 /** 3105 * \brief Retrieve the physical extent of the source construct referenced by 3106 * the given cursor. 3107 * 3108 * The extent of a cursor starts with the file/line/column pointing at the 3109 * first character within the source construct that the cursor refers to and 3110 * ends with the last character within that source construct. For a 3111 * declaration, the extent covers the declaration itself. For a reference, 3112 * the extent covers the location of the reference (e.g., where the referenced 3113 * entity was actually used). 3114 */ 3115 CXSourceRange clang_getCursorExtent(CXCursor); 3116 3117 /** 3118 * @} 3119 */ 3120 3121 /** 3122 * \defgroup CINDEX_TYPES Type information for CXCursors 3123 * 3124 * @{ 3125 */ 3126 3127 /** 3128 * \brief Describes the kind of type 3129 */ 3130 enum CXTypeKind 3131 { 3132 /** 3133 * \brief Represents an invalid type (e.g., where no type is available). 3134 */ 3135 invalid = 0, 3136 3137 /** 3138 * \brief A type whose specific kind is not exposed via this 3139 * interface. 3140 */ 3141 unexposed = 1, 3142 3143 /* Builtin types */ 3144 void_ = 2, 3145 bool_ = 3, 3146 charU = 4, 3147 uChar = 5, 3148 char16 = 6, 3149 char32 = 7, 3150 uShort = 8, 3151 uInt = 9, 3152 uLong = 10, 3153 uLongLong = 11, 3154 uInt128 = 12, 3155 charS = 13, 3156 sChar = 14, 3157 wChar = 15, 3158 short_ = 16, 3159 int_ = 17, 3160 long_ = 18, 3161 longLong = 19, 3162 int128 = 20, 3163 float_ = 21, 3164 double_ = 22, 3165 longDouble = 23, 3166 nullPtr = 24, 3167 overload = 25, 3168 dependent = 26, 3169 objCId = 27, 3170 objCClass = 28, 3171 objCSel = 29, 3172 float128 = 30, 3173 half = 31, 3174 float16 = 32, 3175 firstBuiltin = void_, 3176 lastBuiltin = float16, 3177 3178 complex = 100, 3179 pointer = 101, 3180 blockPointer = 102, 3181 lValueReference = 103, 3182 rValueReference = 104, 3183 record = 105, 3184 enum_ = 106, 3185 typedef_ = 107, 3186 objCInterface = 108, 3187 objCObjectPointer = 109, 3188 functionNoProto = 110, 3189 functionProto = 111, 3190 constantArray = 112, 3191 vector = 113, 3192 incompleteArray = 114, 3193 variableArray = 115, 3194 dependentSizedArray = 116, 3195 memberPointer = 117, 3196 auto_ = 118, 3197 3198 /** 3199 * \brief Represents a type that was referred to using an elaborated type keyword. 3200 * 3201 * E.g., struct S, or via a qualified name, e.g., N::M::type, or both. 3202 */ 3203 elaborated = 119, 3204 3205 /* OpenCL PipeType. */ 3206 pipe = 120, 3207 3208 /* OpenCL builtin types. */ 3209 oclImage1dRO = 121, 3210 oclImage1dArrayRO = 122, 3211 oclImage1dBufferRO = 123, 3212 oclImage2dRO = 124, 3213 oclImage2dArrayRO = 125, 3214 oclImage2dDepthRO = 126, 3215 oclImage2dArrayDepthRO = 127, 3216 oclImage2dMSAARO = 128, 3217 oclImage2dArrayMSAARO = 129, 3218 oclImage2dMSAADepthRO = 130, 3219 oclImage2dArrayMSAADepthRO = 131, 3220 oclImage3dRO = 132, 3221 oclImage1dWO = 133, 3222 oclImage1dArrayWO = 134, 3223 oclImage1dBufferWO = 135, 3224 oclImage2dWO = 136, 3225 oclImage2dArrayWO = 137, 3226 oclImage2dDepthWO = 138, 3227 oclImage2dArrayDepthWO = 139, 3228 oclImage2dMSAAWO = 140, 3229 oclImage2dArrayMSAAWO = 141, 3230 oclImage2dMSAADepthWO = 142, 3231 oclImage2dArrayMSAADepthWO = 143, 3232 oclImage3dWO = 144, 3233 oclImage1dRW = 145, 3234 oclImage1dArrayRW = 146, 3235 oclImage1dBufferRW = 147, 3236 oclImage2dRW = 148, 3237 oclImage2dArrayRW = 149, 3238 oclImage2dDepthRW = 150, 3239 oclImage2dArrayDepthRW = 151, 3240 oclImage2dMSAARW = 152, 3241 oclImage2dArrayMSAARW = 153, 3242 oclImage2dMSAADepthRW = 154, 3243 oclImage2dArrayMSAADepthRW = 155, 3244 oclImage3dRW = 156, 3245 oclSampler = 157, 3246 oclEvent = 158, 3247 oclQueue = 159, 3248 oclReserveID = 160 3249 } 3250 3251 /** 3252 * \brief Describes the calling convention of a function type 3253 */ 3254 enum CXCallingConv 3255 { 3256 default_ = 0, 3257 c = 1, 3258 x86StdCall = 2, 3259 x86FastCall = 3, 3260 x86ThisCall = 4, 3261 x86Pascal = 5, 3262 aapcs = 6, 3263 aapcsVfp = 7, 3264 x86RegCall = 8, 3265 intelOclBicc = 9, 3266 win64 = 10, 3267 /* Alias for compatibility with older versions of API. */ 3268 x8664Win64 = win64, 3269 x8664SysV = 11, 3270 x86VectorCall = 12, 3271 swift = 13, 3272 preserveMost = 14, 3273 preserveAll = 15, 3274 3275 invalid = 100, 3276 unexposed = 200 3277 } 3278 3279 /** 3280 * \brief The type of an element in the abstract syntax tree. 3281 * 3282 */ 3283 struct CXType 3284 { 3285 CXTypeKind kind; 3286 void*[2] data; 3287 } 3288 3289 /** 3290 * \brief Retrieve the type of a CXCursor (if any). 3291 */ 3292 CXType clang_getCursorType(CXCursor C); 3293 3294 /** 3295 * \brief Pretty-print the underlying type using the rules of the 3296 * language of the translation unit from which it came. 3297 * 3298 * If the type is invalid, an empty string is returned. 3299 */ 3300 CXString clang_getTypeSpelling(CXType CT); 3301 3302 /** 3303 * \brief Retrieve the underlying type of a typedef declaration. 3304 * 3305 * If the cursor does not reference a typedef declaration, an invalid type is 3306 * returned. 3307 */ 3308 CXType clang_getTypedefDeclUnderlyingType(CXCursor C); 3309 3310 /** 3311 * \brief Retrieve the integer type of an enum declaration. 3312 * 3313 * If the cursor does not reference an enum declaration, an invalid type is 3314 * returned. 3315 */ 3316 CXType clang_getEnumDeclIntegerType(CXCursor C); 3317 3318 /** 3319 * \brief Retrieve the integer value of an enum constant declaration as a signed 3320 * long long. 3321 * 3322 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned. 3323 * Since this is also potentially a valid constant value, the kind of the cursor 3324 * must be verified before calling this function. 3325 */ 3326 long clang_getEnumConstantDeclValue(CXCursor C); 3327 3328 /** 3329 * \brief Retrieve the integer value of an enum constant declaration as an unsigned 3330 * long long. 3331 * 3332 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned. 3333 * Since this is also potentially a valid constant value, the kind of the cursor 3334 * must be verified before calling this function. 3335 */ 3336 ulong clang_getEnumConstantDeclUnsignedValue(CXCursor C); 3337 3338 /** 3339 * \brief Retrieve the bit width of a bit field declaration as an integer. 3340 * 3341 * If a cursor that is not a bit field declaration is passed in, -1 is returned. 3342 */ 3343 int clang_getFieldDeclBitWidth(CXCursor C); 3344 3345 /** 3346 * \brief Retrieve the number of non-variadic arguments associated with a given 3347 * cursor. 3348 * 3349 * The number of arguments can be determined for calls as well as for 3350 * declarations of functions or methods. For other cursors -1 is returned. 3351 */ 3352 int clang_Cursor_getNumArguments(CXCursor C); 3353 3354 /** 3355 * \brief Retrieve the argument cursor of a function or method. 3356 * 3357 * The argument cursor can be determined for calls as well as for declarations 3358 * of functions or methods. For other cursors and for invalid indices, an 3359 * invalid cursor is returned. 3360 */ 3361 CXCursor clang_Cursor_getArgument(CXCursor C, uint i); 3362 3363 /** 3364 * \brief Describes the kind of a template argument. 3365 * 3366 * See the definition of llvm::clang::TemplateArgument::ArgKind for full 3367 * element descriptions. 3368 */ 3369 enum CXTemplateArgumentKind 3370 { 3371 null_ = 0, 3372 type = 1, 3373 declaration = 2, 3374 nullPtr = 3, 3375 integral = 4, 3376 template_ = 5, 3377 templateExpansion = 6, 3378 expression = 7, 3379 pack = 8, 3380 /* Indicates an error case, preventing the kind from being deduced. */ 3381 invalid = 9 3382 } 3383 3384 /** 3385 *\brief Returns the number of template args of a function decl representing a 3386 * template specialization. 3387 * 3388 * If the argument cursor cannot be converted into a template function 3389 * declaration, -1 is returned. 3390 * 3391 * For example, for the following declaration and specialization: 3392 * template <typename T, int kInt, bool kBool> 3393 * void foo() { ... } 3394 * 3395 * template <> 3396 * void foo<float, -7, true>(); 3397 * 3398 * The value 3 would be returned from this call. 3399 */ 3400 int clang_Cursor_getNumTemplateArguments(CXCursor C); 3401 3402 /** 3403 * \brief Retrieve the kind of the I'th template argument of the CXCursor C. 3404 * 3405 * If the argument CXCursor does not represent a FunctionDecl, an invalid 3406 * template argument kind is returned. 3407 * 3408 * For example, for the following declaration and specialization: 3409 * template <typename T, int kInt, bool kBool> 3410 * void foo() { ... } 3411 * 3412 * template <> 3413 * void foo<float, -7, true>(); 3414 * 3415 * For I = 0, 1, and 2, Type, Integral, and Integral will be returned, 3416 * respectively. 3417 */ 3418 CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(CXCursor C, uint I); 3419 3420 /** 3421 * \brief Retrieve a CXType representing the type of a TemplateArgument of a 3422 * function decl representing a template specialization. 3423 * 3424 * If the argument CXCursor does not represent a FunctionDecl whose I'th 3425 * template argument has a kind of CXTemplateArgKind_Integral, an invalid type 3426 * is returned. 3427 * 3428 * For example, for the following declaration and specialization: 3429 * template <typename T, int kInt, bool kBool> 3430 * void foo() { ... } 3431 * 3432 * template <> 3433 * void foo<float, -7, true>(); 3434 * 3435 * If called with I = 0, "float", will be returned. 3436 * Invalid types will be returned for I == 1 or 2. 3437 */ 3438 CXType clang_Cursor_getTemplateArgumentType(CXCursor C, uint I); 3439 3440 /** 3441 * \brief Retrieve the value of an Integral TemplateArgument (of a function 3442 * decl representing a template specialization) as a signed long long. 3443 * 3444 * It is undefined to call this function on a CXCursor that does not represent a 3445 * FunctionDecl or whose I'th template argument is not an integral value. 3446 * 3447 * For example, for the following declaration and specialization: 3448 * template <typename T, int kInt, bool kBool> 3449 * void foo() { ... } 3450 * 3451 * template <> 3452 * void foo<float, -7, true>(); 3453 * 3454 * If called with I = 1 or 2, -7 or true will be returned, respectively. 3455 * For I == 0, this function's behavior is undefined. 3456 */ 3457 long clang_Cursor_getTemplateArgumentValue(CXCursor C, uint I); 3458 3459 /** 3460 * \brief Retrieve the value of an Integral TemplateArgument (of a function 3461 * decl representing a template specialization) as an unsigned long long. 3462 * 3463 * It is undefined to call this function on a CXCursor that does not represent a 3464 * FunctionDecl or whose I'th template argument is not an integral value. 3465 * 3466 * For example, for the following declaration and specialization: 3467 * template <typename T, int kInt, bool kBool> 3468 * void foo() { ... } 3469 * 3470 * template <> 3471 * void foo<float, 2147483649, true>(); 3472 * 3473 * If called with I = 1 or 2, 2147483649 or true will be returned, respectively. 3474 * For I == 0, this function's behavior is undefined. 3475 */ 3476 ulong clang_Cursor_getTemplateArgumentUnsignedValue(CXCursor C, uint I); 3477 3478 /** 3479 * \brief Determine whether two CXTypes represent the same type. 3480 * 3481 * \returns non-zero if the CXTypes represent the same type and 3482 * zero otherwise. 3483 */ 3484 uint clang_equalTypes(CXType A, CXType B); 3485 3486 /** 3487 * \brief Return the canonical type for a CXType. 3488 * 3489 * Clang's type system explicitly models typedefs and all the ways 3490 * a specific type can be represented. The canonical type is the underlying 3491 * type with all the "sugar" removed. For example, if 'T' is a typedef 3492 * for 'int', the canonical type for 'T' would be 'int'. 3493 */ 3494 CXType clang_getCanonicalType(CXType T); 3495 3496 /** 3497 * \brief Determine whether a CXType has the "const" qualifier set, 3498 * without looking through typedefs that may have added "const" at a 3499 * different level. 3500 */ 3501 uint clang_isConstQualifiedType(CXType T); 3502 3503 /** 3504 * \brief Determine whether a CXCursor that is a macro, is 3505 * function like. 3506 */ 3507 uint clang_Cursor_isMacroFunctionLike(CXCursor C); 3508 3509 /** 3510 * \brief Determine whether a CXCursor that is a macro, is a 3511 * builtin one. 3512 */ 3513 uint clang_Cursor_isMacroBuiltin(CXCursor C); 3514 3515 /** 3516 * \brief Determine whether a CXCursor that is a function declaration, is an 3517 * inline declaration. 3518 */ 3519 uint clang_Cursor_isFunctionInlined(CXCursor C); 3520 3521 /** 3522 * \brief Determine whether a CXType has the "volatile" qualifier set, 3523 * without looking through typedefs that may have added "volatile" at 3524 * a different level. 3525 */ 3526 uint clang_isVolatileQualifiedType(CXType T); 3527 3528 /** 3529 * \brief Determine whether a CXType has the "restrict" qualifier set, 3530 * without looking through typedefs that may have added "restrict" at a 3531 * different level. 3532 */ 3533 uint clang_isRestrictQualifiedType(CXType T); 3534 3535 /** 3536 * \brief Returns the address space of the given type. 3537 */ 3538 uint clang_getAddressSpace(CXType T); 3539 3540 /** 3541 * \brief Returns the typedef name of the given type. 3542 */ 3543 CXString clang_getTypedefName(CXType CT); 3544 3545 /** 3546 * \brief For pointer types, returns the type of the pointee. 3547 */ 3548 CXType clang_getPointeeType(CXType T); 3549 3550 /** 3551 * \brief Return the cursor for the declaration of the given type. 3552 */ 3553 CXCursor clang_getTypeDeclaration(CXType T); 3554 3555 /** 3556 * Returns the Objective-C type encoding for the specified declaration. 3557 */ 3558 CXString clang_getDeclObjCTypeEncoding(CXCursor C); 3559 3560 /** 3561 * Returns the Objective-C type encoding for the specified CXType. 3562 */ 3563 CXString clang_Type_getObjCEncoding(CXType type); 3564 3565 /** 3566 * \brief Retrieve the spelling of a given CXTypeKind. 3567 */ 3568 CXString clang_getTypeKindSpelling(CXTypeKind K); 3569 3570 /** 3571 * \brief Retrieve the calling convention associated with a function type. 3572 * 3573 * If a non-function type is passed in, CXCallingConv_Invalid is returned. 3574 */ 3575 CXCallingConv clang_getFunctionTypeCallingConv(CXType T); 3576 3577 /** 3578 * \brief Retrieve the return type associated with a function type. 3579 * 3580 * If a non-function type is passed in, an invalid type is returned. 3581 */ 3582 CXType clang_getResultType(CXType T); 3583 3584 /** 3585 * \brief Retrieve the exception specification type associated with a function type. 3586 * 3587 * If a non-function type is passed in, an error code of -1 is returned. 3588 */ 3589 int clang_getExceptionSpecificationType(CXType T); 3590 3591 /** 3592 * \brief Retrieve the number of non-variadic parameters associated with a 3593 * function type. 3594 * 3595 * If a non-function type is passed in, -1 is returned. 3596 */ 3597 int clang_getNumArgTypes(CXType T); 3598 3599 /** 3600 * \brief Retrieve the type of a parameter of a function type. 3601 * 3602 * If a non-function type is passed in or the function does not have enough 3603 * parameters, an invalid type is returned. 3604 */ 3605 CXType clang_getArgType(CXType T, uint i); 3606 3607 /** 3608 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise. 3609 */ 3610 uint clang_isFunctionTypeVariadic(CXType T); 3611 3612 /** 3613 * \brief Retrieve the return type associated with a given cursor. 3614 * 3615 * This only returns a valid type if the cursor refers to a function or method. 3616 */ 3617 CXType clang_getCursorResultType(CXCursor C); 3618 3619 /** 3620 * \brief Retrieve the exception specification type associated with a given cursor. 3621 * 3622 * This only returns a valid result if the cursor refers to a function or method. 3623 */ 3624 int clang_getCursorExceptionSpecificationType(CXCursor C); 3625 3626 /** 3627 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 3628 * otherwise. 3629 */ 3630 uint clang_isPODType(CXType T); 3631 3632 /** 3633 * \brief Return the element type of an array, complex, or vector type. 3634 * 3635 * If a type is passed in that is not an array, complex, or vector type, 3636 * an invalid type is returned. 3637 */ 3638 CXType clang_getElementType(CXType T); 3639 3640 /** 3641 * \brief Return the number of elements of an array or vector type. 3642 * 3643 * If a type is passed in that is not an array or vector type, 3644 * -1 is returned. 3645 */ 3646 long clang_getNumElements(CXType T); 3647 3648 /** 3649 * \brief Return the element type of an array type. 3650 * 3651 * If a non-array type is passed in, an invalid type is returned. 3652 */ 3653 CXType clang_getArrayElementType(CXType T); 3654 3655 /** 3656 * \brief Return the array size of a constant array. 3657 * 3658 * If a non-array type is passed in, -1 is returned. 3659 */ 3660 long clang_getArraySize(CXType T); 3661 3662 /** 3663 * \brief Retrieve the type named by the qualified-id. 3664 * 3665 * If a non-elaborated type is passed in, an invalid type is returned. 3666 */ 3667 CXType clang_Type_getNamedType(CXType T); 3668 3669 /** 3670 * \brief Determine if a typedef is 'transparent' tag. 3671 * 3672 * A typedef is considered 'transparent' if it shares a name and spelling 3673 * location with its underlying tag type, as is the case with the NS_ENUM macro. 3674 * 3675 * \returns non-zero if transparent and zero otherwise. 3676 */ 3677 uint clang_Type_isTransparentTagTypedef(CXType T); 3678 3679 /** 3680 * \brief List the possible error codes for \c clang_Type_getSizeOf, 3681 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and 3682 * \c clang_Cursor_getOffsetOf. 3683 * 3684 * A value of this enumeration type can be returned if the target type is not 3685 * a valid argument to sizeof, alignof or offsetof. 3686 */ 3687 enum CXTypeLayoutError 3688 { 3689 /** 3690 * \brief Type is of kind CXType_Invalid. 3691 */ 3692 invalid = -1, 3693 /** 3694 * \brief The type is an incomplete Type. 3695 */ 3696 incomplete = -2, 3697 /** 3698 * \brief The type is a dependent Type. 3699 */ 3700 dependent = -3, 3701 /** 3702 * \brief The type is not a constant size type. 3703 */ 3704 notConstantSize = -4, 3705 /** 3706 * \brief The Field name is not valid for this record. 3707 */ 3708 invalidFieldName = -5 3709 } 3710 3711 /** 3712 * \brief Return the alignment of a type in bytes as per C++[expr.alignof] 3713 * standard. 3714 * 3715 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. 3716 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete 3717 * is returned. 3718 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is 3719 * returned. 3720 * If the type declaration is not a constant size type, 3721 * CXTypeLayoutError_NotConstantSize is returned. 3722 */ 3723 long clang_Type_getAlignOf(CXType T); 3724 3725 /** 3726 * \brief Return the class type of an member pointer type. 3727 * 3728 * If a non-member-pointer type is passed in, an invalid type is returned. 3729 */ 3730 CXType clang_Type_getClassType(CXType T); 3731 3732 /** 3733 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard. 3734 * 3735 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. 3736 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete 3737 * is returned. 3738 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is 3739 * returned. 3740 */ 3741 long clang_Type_getSizeOf(CXType T); 3742 3743 /** 3744 * \brief Return the offset of a field named S in a record of type T in bits 3745 * as it would be returned by __offsetof__ as per C++11[18.2p4] 3746 * 3747 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid 3748 * is returned. 3749 * If the field's type declaration is an incomplete type, 3750 * CXTypeLayoutError_Incomplete is returned. 3751 * If the field's type declaration is a dependent type, 3752 * CXTypeLayoutError_Dependent is returned. 3753 * If the field's name S is not found, 3754 * CXTypeLayoutError_InvalidFieldName is returned. 3755 */ 3756 long clang_Type_getOffsetOf(CXType T, const(char)* S); 3757 3758 /** 3759 * \brief Return the offset of the field represented by the Cursor. 3760 * 3761 * If the cursor is not a field declaration, -1 is returned. 3762 * If the cursor semantic parent is not a record field declaration, 3763 * CXTypeLayoutError_Invalid is returned. 3764 * If the field's type declaration is an incomplete type, 3765 * CXTypeLayoutError_Incomplete is returned. 3766 * If the field's type declaration is a dependent type, 3767 * CXTypeLayoutError_Dependent is returned. 3768 * If the field's name S is not found, 3769 * CXTypeLayoutError_InvalidFieldName is returned. 3770 */ 3771 long clang_Cursor_getOffsetOfField(CXCursor C); 3772 3773 /** 3774 * \brief Determine whether the given cursor represents an anonymous record 3775 * declaration. 3776 */ 3777 uint clang_Cursor_isAnonymous(CXCursor C); 3778 3779 enum CXRefQualifierKind 3780 { 3781 /** \brief No ref-qualifier was provided. */ 3782 none = 0, 3783 /** \brief An lvalue ref-qualifier was provided (\c &). */ 3784 lValue = 1, 3785 /** \brief An rvalue ref-qualifier was provided (\c &&). */ 3786 rValue = 2 3787 } 3788 3789 /** 3790 * \brief Returns the number of template arguments for given template 3791 * specialization, or -1 if type \c T is not a template specialization. 3792 */ 3793 int clang_Type_getNumTemplateArguments(CXType T); 3794 3795 /** 3796 * \brief Returns the type template argument of a template class specialization 3797 * at given index. 3798 * 3799 * This function only returns template type arguments and does not handle 3800 * template template arguments or variadic packs. 3801 */ 3802 CXType clang_Type_getTemplateArgumentAsType(CXType T, uint i); 3803 3804 /** 3805 * \brief Retrieve the ref-qualifier kind of a function or method. 3806 * 3807 * The ref-qualifier is returned for C++ functions or methods. For other types 3808 * or non-C++ declarations, CXRefQualifier_None is returned. 3809 */ 3810 CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T); 3811 3812 /** 3813 * \brief Returns non-zero if the cursor specifies a Record member that is a 3814 * bitfield. 3815 */ 3816 uint clang_Cursor_isBitField(CXCursor C); 3817 3818 /** 3819 * \brief Returns 1 if the base class specified by the cursor with kind 3820 * CX_CXXBaseSpecifier is virtual. 3821 */ 3822 uint clang_isVirtualBase(CXCursor); 3823 3824 /** 3825 * \brief Represents the C++ access control level to a base class for a 3826 * cursor with kind CX_CXXBaseSpecifier. 3827 */ 3828 enum CX_CXXAccessSpecifier 3829 { 3830 cxxInvalidAccessSpecifier = 0, 3831 cxxPublic = 1, 3832 cxxProtected = 2, 3833 cxxPrivate = 3 3834 } 3835 3836 /** 3837 * \brief Returns the access control level for the referenced object. 3838 * 3839 * If the cursor refers to a C++ declaration, its access control level within its 3840 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or 3841 * access specifier, the specifier itself is returned. 3842 */ 3843 CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor); 3844 3845 /** 3846 * \brief Represents the storage classes as declared in the source. CX_SC_Invalid 3847 * was added for the case that the passed cursor in not a declaration. 3848 */ 3849 enum CX_StorageClass 3850 { 3851 invalid = 0, 3852 none = 1, 3853 extern_ = 2, 3854 static_ = 3, 3855 privateExtern = 4, 3856 openCLWorkGroupLocal = 5, 3857 auto_ = 6, 3858 register = 7 3859 } 3860 3861 /** 3862 * \brief Returns the storage class for a function or variable declaration. 3863 * 3864 * If the passed in Cursor is not a function or variable declaration, 3865 * CX_SC_Invalid is returned else the storage class. 3866 */ 3867 CX_StorageClass clang_Cursor_getStorageClass(CXCursor); 3868 3869 /** 3870 * \brief Determine the number of overloaded declarations referenced by a 3871 * \c CXCursor_OverloadedDeclRef cursor. 3872 * 3873 * \param cursor The cursor whose overloaded declarations are being queried. 3874 * 3875 * \returns The number of overloaded declarations referenced by \c cursor. If it 3876 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0. 3877 */ 3878 uint clang_getNumOverloadedDecls(CXCursor cursor); 3879 3880 /** 3881 * \brief Retrieve a cursor for one of the overloaded declarations referenced 3882 * by a \c CXCursor_OverloadedDeclRef cursor. 3883 * 3884 * \param cursor The cursor whose overloaded declarations are being queried. 3885 * 3886 * \param index The zero-based index into the set of overloaded declarations in 3887 * the cursor. 3888 * 3889 * \returns A cursor representing the declaration referenced by the given 3890 * \c cursor at the specified \c index. If the cursor does not have an 3891 * associated set of overloaded declarations, or if the index is out of bounds, 3892 * returns \c clang_getNullCursor(); 3893 */ 3894 CXCursor clang_getOverloadedDecl(CXCursor cursor, uint index); 3895 3896 /** 3897 * @} 3898 */ 3899 3900 /** 3901 * \defgroup CINDEX_ATTRIBUTES Information for attributes 3902 * 3903 * @{ 3904 */ 3905 3906 /** 3907 * \brief For cursors representing an iboutletcollection attribute, 3908 * this function returns the collection element type. 3909 * 3910 */ 3911 CXType clang_getIBOutletCollectionType(CXCursor); 3912 3913 /** 3914 * @} 3915 */ 3916 3917 /** 3918 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 3919 * 3920 * These routines provide the ability to traverse the abstract syntax tree 3921 * using cursors. 3922 * 3923 * @{ 3924 */ 3925 3926 /** 3927 * \brief Describes how the traversal of the children of a particular 3928 * cursor should proceed after visiting a particular child cursor. 3929 * 3930 * A value of this enumeration type should be returned by each 3931 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 3932 */ 3933 enum CXChildVisitResult 3934 { 3935 /** 3936 * \brief Terminates the cursor traversal. 3937 */ 3938 break_ = 0, 3939 /** 3940 * \brief Continues the cursor traversal with the next sibling of 3941 * the cursor just visited, without visiting its children. 3942 */ 3943 continue_ = 1, 3944 /** 3945 * \brief Recursively traverse the children of this cursor, using 3946 * the same visitor and client data. 3947 */ 3948 recurse = 2 3949 } 3950 3951 /** 3952 * \brief Visitor invoked for each cursor found by a traversal. 3953 * 3954 * This visitor function will be invoked for each cursor found by 3955 * clang_visitCursorChildren(). Its first argument is the cursor being 3956 * visited, its second argument is the parent visitor for that cursor, 3957 * and its third argument is the client data provided to 3958 * clang_visitCursorChildren(). 3959 * 3960 * The visitor should return one of the \c CXChildVisitResult values 3961 * to direct clang_visitCursorChildren(). 3962 */ 3963 alias CXCursorVisitor = CXChildVisitResult function( 3964 CXCursor cursor, 3965 CXCursor parent, 3966 CXClientData client_data); 3967 3968 /** 3969 * \brief Visit the children of a particular cursor. 3970 * 3971 * This function visits all the direct children of the given cursor, 3972 * invoking the given \p visitor function with the cursors of each 3973 * visited child. The traversal may be recursive, if the visitor returns 3974 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 3975 * the visitor returns \c CXChildVisit_Break. 3976 * 3977 * \param parent the cursor whose child may be visited. All kinds of 3978 * cursors can be visited, including invalid cursors (which, by 3979 * definition, have no children). 3980 * 3981 * \param visitor the visitor function that will be invoked for each 3982 * child of \p parent. 3983 * 3984 * \param client_data pointer data supplied by the client, which will 3985 * be passed to the visitor each time it is invoked. 3986 * 3987 * \returns a non-zero value if the traversal was terminated 3988 * prematurely by the visitor returning \c CXChildVisit_Break. 3989 */ 3990 uint clang_visitChildren( 3991 CXCursor parent, 3992 CXCursorVisitor visitor, 3993 CXClientData client_data); 3994 /** 3995 * \brief Visitor invoked for each cursor found by a traversal. 3996 * 3997 * This visitor block will be invoked for each cursor found by 3998 * clang_visitChildrenWithBlock(). Its first argument is the cursor being 3999 * visited, its second argument is the parent visitor for that cursor. 4000 * 4001 * The visitor should return one of the \c CXChildVisitResult values 4002 * to direct clang_visitChildrenWithBlock(). 4003 */ 4004 4005 /** 4006 * Visits the children of a cursor using the specified block. Behaves 4007 * identically to clang_visitChildren() in all other respects. 4008 */ 4009 4010 /** 4011 * @} 4012 */ 4013 4014 /** 4015 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 4016 * 4017 * These routines provide the ability to determine references within and 4018 * across translation units, by providing the names of the entities referenced 4019 * by cursors, follow reference cursors to the declarations they reference, 4020 * and associate declarations with their definitions. 4021 * 4022 * @{ 4023 */ 4024 4025 /** 4026 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 4027 * by the given cursor. 4028 * 4029 * A Unified Symbol Resolution (USR) is a string that identifies a particular 4030 * entity (function, class, variable, etc.) within a program. USRs can be 4031 * compared across translation units to determine, e.g., when references in 4032 * one translation refer to an entity defined in another translation unit. 4033 */ 4034 CXString clang_getCursorUSR(CXCursor); 4035 4036 /** 4037 * \brief Construct a USR for a specified Objective-C class. 4038 */ 4039 CXString clang_constructUSR_ObjCClass(const(char)* class_name); 4040 4041 /** 4042 * \brief Construct a USR for a specified Objective-C category. 4043 */ 4044 CXString clang_constructUSR_ObjCCategory( 4045 const(char)* class_name, 4046 const(char)* category_name); 4047 4048 /** 4049 * \brief Construct a USR for a specified Objective-C protocol. 4050 */ 4051 CXString clang_constructUSR_ObjCProtocol(const(char)* protocol_name); 4052 4053 /** 4054 * \brief Construct a USR for a specified Objective-C instance variable and 4055 * the USR for its containing class. 4056 */ 4057 CXString clang_constructUSR_ObjCIvar(const(char)* name, CXString classUSR); 4058 4059 /** 4060 * \brief Construct a USR for a specified Objective-C method and 4061 * the USR for its containing class. 4062 */ 4063 CXString clang_constructUSR_ObjCMethod( 4064 const(char)* name, 4065 uint isInstanceMethod, 4066 CXString classUSR); 4067 4068 /** 4069 * \brief Construct a USR for a specified Objective-C property and the USR 4070 * for its containing class. 4071 */ 4072 CXString clang_constructUSR_ObjCProperty( 4073 const(char)* property, 4074 CXString classUSR); 4075 4076 /** 4077 * \brief Retrieve a name for the entity referenced by this cursor. 4078 */ 4079 CXString clang_getCursorSpelling(CXCursor); 4080 4081 /** 4082 * \brief Retrieve a range for a piece that forms the cursors spelling name. 4083 * Most of the times there is only one range for the complete spelling but for 4084 * Objective-C methods and Objective-C message expressions, there are multiple 4085 * pieces for each selector identifier. 4086 * 4087 * \param pieceIndex the index of the spelling name piece. If this is greater 4088 * than the actual number of pieces, it will return a NULL (invalid) range. 4089 * 4090 * \param options Reserved. 4091 */ 4092 CXSourceRange clang_Cursor_getSpellingNameRange( 4093 CXCursor, 4094 uint pieceIndex, 4095 uint options); 4096 4097 /** 4098 * \brief Retrieve the display name for the entity referenced by this cursor. 4099 * 4100 * The display name contains extra information that helps identify the cursor, 4101 * such as the parameters of a function or template or the arguments of a 4102 * class template specialization. 4103 */ 4104 CXString clang_getCursorDisplayName(CXCursor); 4105 4106 /** \brief For a cursor that is a reference, retrieve a cursor representing the 4107 * entity that it references. 4108 * 4109 * Reference cursors refer to other entities in the AST. For example, an 4110 * Objective-C superclass reference cursor refers to an Objective-C class. 4111 * This function produces the cursor for the Objective-C class from the 4112 * cursor for the superclass reference. If the input cursor is a declaration or 4113 * definition, it returns that declaration or definition unchanged. 4114 * Otherwise, returns the NULL cursor. 4115 */ 4116 CXCursor clang_getCursorReferenced(CXCursor); 4117 4118 /** 4119 * \brief For a cursor that is either a reference to or a declaration 4120 * of some entity, retrieve a cursor that describes the definition of 4121 * that entity. 4122 * 4123 * Some entities can be declared multiple times within a translation 4124 * unit, but only one of those declarations can also be a 4125 * definition. For example, given: 4126 * 4127 * \code 4128 * int f(int, int); 4129 * int g(int x, int y) { return f(x, y); } 4130 * int f(int a, int b) { return a + b; } 4131 * int f(int, int); 4132 * \endcode 4133 * 4134 * there are three declarations of the function "f", but only the 4135 * second one is a definition. The clang_getCursorDefinition() 4136 * function will take any cursor pointing to a declaration of "f" 4137 * (the first or fourth lines of the example) or a cursor referenced 4138 * that uses "f" (the call to "f' inside "g") and will return a 4139 * declaration cursor pointing to the definition (the second "f" 4140 * declaration). 4141 * 4142 * If given a cursor for which there is no corresponding definition, 4143 * e.g., because there is no definition of that entity within this 4144 * translation unit, returns a NULL cursor. 4145 */ 4146 CXCursor clang_getCursorDefinition(CXCursor); 4147 4148 /** 4149 * \brief Determine whether the declaration pointed to by this cursor 4150 * is also a definition of that entity. 4151 */ 4152 uint clang_isCursorDefinition(CXCursor); 4153 4154 /** 4155 * \brief Retrieve the canonical cursor corresponding to the given cursor. 4156 * 4157 * In the C family of languages, many kinds of entities can be declared several 4158 * times within a single translation unit. For example, a structure type can 4159 * be forward-declared (possibly multiple times) and later defined: 4160 * 4161 * \code 4162 * struct X; 4163 * struct X; 4164 * struct X { 4165 * int member; 4166 * }; 4167 * \endcode 4168 * 4169 * The declarations and the definition of \c X are represented by three 4170 * different cursors, all of which are declarations of the same underlying 4171 * entity. One of these cursor is considered the "canonical" cursor, which 4172 * is effectively the representative for the underlying entity. One can 4173 * determine if two cursors are declarations of the same underlying entity by 4174 * comparing their canonical cursors. 4175 * 4176 * \returns The canonical cursor for the entity referred to by the given cursor. 4177 */ 4178 CXCursor clang_getCanonicalCursor(CXCursor); 4179 4180 /** 4181 * \brief If the cursor points to a selector identifier in an Objective-C 4182 * method or message expression, this returns the selector index. 4183 * 4184 * After getting a cursor with #clang_getCursor, this can be called to 4185 * determine if the location points to a selector identifier. 4186 * 4187 * \returns The selector index if the cursor is an Objective-C method or message 4188 * expression and the cursor is pointing to a selector identifier, or -1 4189 * otherwise. 4190 */ 4191 int clang_Cursor_getObjCSelectorIndex(CXCursor); 4192 4193 /** 4194 * \brief Given a cursor pointing to a C++ method call or an Objective-C 4195 * message, returns non-zero if the method/message is "dynamic", meaning: 4196 * 4197 * For a C++ method: the call is virtual. 4198 * For an Objective-C message: the receiver is an object instance, not 'super' 4199 * or a specific class. 4200 * 4201 * If the method/message is "static" or the cursor does not point to a 4202 * method/message, it will return zero. 4203 */ 4204 int clang_Cursor_isDynamicCall(CXCursor C); 4205 4206 /** 4207 * \brief Given a cursor pointing to an Objective-C message or property 4208 * reference, or C++ method call, returns the CXType of the receiver. 4209 */ 4210 CXType clang_Cursor_getReceiverType(CXCursor C); 4211 4212 /** 4213 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl. 4214 */ 4215 enum CXObjCPropertyAttrKind 4216 { 4217 noattr = 0x00, 4218 readonly = 0x01, 4219 getter = 0x02, 4220 assign = 0x04, 4221 readwrite = 0x08, 4222 retain = 0x10, 4223 copy = 0x20, 4224 nonatomic = 0x40, 4225 setter = 0x80, 4226 atomic = 0x100, 4227 weak = 0x200, 4228 strong = 0x400, 4229 unsafeUnretained = 0x800, 4230 class_ = 0x1000 4231 } 4232 4233 /** 4234 * \brief Given a cursor that represents a property declaration, return the 4235 * associated property attributes. The bits are formed from 4236 * \c CXObjCPropertyAttrKind. 4237 * 4238 * \param reserved Reserved for future use, pass 0. 4239 */ 4240 uint clang_Cursor_getObjCPropertyAttributes(CXCursor C, uint reserved); 4241 4242 /** 4243 * \brief 'Qualifiers' written next to the return and parameter types in 4244 * Objective-C method declarations. 4245 */ 4246 enum CXObjCDeclQualifierKind 4247 { 4248 none = 0x0, 4249 in_ = 0x1, 4250 inout_ = 0x2, 4251 out_ = 0x4, 4252 bycopy = 0x8, 4253 byref = 0x10, 4254 oneway = 0x20 4255 } 4256 4257 /** 4258 * \brief Given a cursor that represents an Objective-C method or parameter 4259 * declaration, return the associated Objective-C qualifiers for the return 4260 * type or the parameter respectively. The bits are formed from 4261 * CXObjCDeclQualifierKind. 4262 */ 4263 uint clang_Cursor_getObjCDeclQualifiers(CXCursor C); 4264 4265 /** 4266 * \brief Given a cursor that represents an Objective-C method or property 4267 * declaration, return non-zero if the declaration was affected by "\@optional". 4268 * Returns zero if the cursor is not such a declaration or it is "\@required". 4269 */ 4270 uint clang_Cursor_isObjCOptional(CXCursor C); 4271 4272 /** 4273 * \brief Returns non-zero if the given cursor is a variadic function or method. 4274 */ 4275 uint clang_Cursor_isVariadic(CXCursor C); 4276 4277 /** 4278 * \brief Returns non-zero if the given cursor points to a symbol marked with 4279 * external_source_symbol attribute. 4280 * 4281 * \param language If non-NULL, and the attribute is present, will be set to 4282 * the 'language' string from the attribute. 4283 * 4284 * \param definedIn If non-NULL, and the attribute is present, will be set to 4285 * the 'definedIn' string from the attribute. 4286 * 4287 * \param isGenerated If non-NULL, and the attribute is present, will be set to 4288 * non-zero if the 'generated_declaration' is set in the attribute. 4289 */ 4290 uint clang_Cursor_isExternalSymbol( 4291 CXCursor C, 4292 CXString* language, 4293 CXString* definedIn, 4294 uint* isGenerated); 4295 4296 /** 4297 * \brief Given a cursor that represents a declaration, return the associated 4298 * comment's source range. The range may include multiple consecutive comments 4299 * with whitespace in between. 4300 */ 4301 CXSourceRange clang_Cursor_getCommentRange(CXCursor C); 4302 4303 /** 4304 * \brief Given a cursor that represents a declaration, return the associated 4305 * comment text, including comment markers. 4306 */ 4307 CXString clang_Cursor_getRawCommentText(CXCursor C); 4308 4309 /** 4310 * \brief Given a cursor that represents a documentable entity (e.g., 4311 * declaration), return the associated \\brief paragraph; otherwise return the 4312 * first paragraph. 4313 */ 4314 CXString clang_Cursor_getBriefCommentText(CXCursor C); 4315 4316 /** 4317 * @} 4318 */ 4319 4320 /** \defgroup CINDEX_MANGLE Name Mangling API Functions 4321 * 4322 * @{ 4323 */ 4324 4325 /** 4326 * \brief Retrieve the CXString representing the mangled name of the cursor. 4327 */ 4328 CXString clang_Cursor_getMangling(CXCursor); 4329 4330 /** 4331 * \brief Retrieve the CXStrings representing the mangled symbols of the C++ 4332 * constructor or destructor at the cursor. 4333 */ 4334 CXStringSet* clang_Cursor_getCXXManglings(CXCursor); 4335 4336 /** 4337 * \brief Retrieve the CXStrings representing the mangled symbols of the ObjC 4338 * class interface or implementation at the cursor. 4339 */ 4340 CXStringSet* clang_Cursor_getObjCManglings(CXCursor); 4341 4342 /** 4343 * @} 4344 */ 4345 4346 /** 4347 * \defgroup CINDEX_MODULE Module introspection 4348 * 4349 * The functions in this group provide access to information about modules. 4350 * 4351 * @{ 4352 */ 4353 4354 alias CXModule = void*; 4355 4356 /** 4357 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module. 4358 */ 4359 CXModule clang_Cursor_getModule(CXCursor C); 4360 4361 /** 4362 * \brief Given a CXFile header file, return the module that contains it, if one 4363 * exists. 4364 */ 4365 CXModule clang_getModuleForFile(CXTranslationUnit, CXFile); 4366 4367 /** 4368 * \param Module a module object. 4369 * 4370 * \returns the module file where the provided module object came from. 4371 */ 4372 CXFile clang_Module_getASTFile(CXModule Module); 4373 4374 /** 4375 * \param Module a module object. 4376 * 4377 * \returns the parent of a sub-module or NULL if the given module is top-level, 4378 * e.g. for 'std.vector' it will return the 'std' module. 4379 */ 4380 CXModule clang_Module_getParent(CXModule Module); 4381 4382 /** 4383 * \param Module a module object. 4384 * 4385 * \returns the name of the module, e.g. for the 'std.vector' sub-module it 4386 * will return "vector". 4387 */ 4388 CXString clang_Module_getName(CXModule Module); 4389 4390 /** 4391 * \param Module a module object. 4392 * 4393 * \returns the full name of the module, e.g. "std.vector". 4394 */ 4395 CXString clang_Module_getFullName(CXModule Module); 4396 4397 /** 4398 * \param Module a module object. 4399 * 4400 * \returns non-zero if the module is a system one. 4401 */ 4402 int clang_Module_isSystem(CXModule Module); 4403 4404 /** 4405 * \param Module a module object. 4406 * 4407 * \returns the number of top level headers associated with this module. 4408 */ 4409 uint clang_Module_getNumTopLevelHeaders(CXTranslationUnit, CXModule Module); 4410 4411 /** 4412 * \param Module a module object. 4413 * 4414 * \param Index top level header index (zero-based). 4415 * 4416 * \returns the specified top level header associated with the module. 4417 */ 4418 CXFile clang_Module_getTopLevelHeader( 4419 CXTranslationUnit, 4420 CXModule Module, 4421 uint Index); 4422 4423 /** 4424 * @} 4425 */ 4426 4427 /** 4428 * \defgroup CINDEX_CPP C++ AST introspection 4429 * 4430 * The routines in this group provide access information in the ASTs specific 4431 * to C++ language features. 4432 * 4433 * @{ 4434 */ 4435 4436 /** 4437 * \brief Determine if a C++ constructor is a converting constructor. 4438 */ 4439 uint clang_CXXConstructor_isConvertingConstructor(CXCursor C); 4440 4441 /** 4442 * \brief Determine if a C++ constructor is a copy constructor. 4443 */ 4444 uint clang_CXXConstructor_isCopyConstructor(CXCursor C); 4445 4446 /** 4447 * \brief Determine if a C++ constructor is the default constructor. 4448 */ 4449 uint clang_CXXConstructor_isDefaultConstructor(CXCursor C); 4450 4451 /** 4452 * \brief Determine if a C++ constructor is a move constructor. 4453 */ 4454 uint clang_CXXConstructor_isMoveConstructor(CXCursor C); 4455 4456 /** 4457 * \brief Determine if a C++ field is declared 'mutable'. 4458 */ 4459 uint clang_CXXField_isMutable(CXCursor C); 4460 4461 /** 4462 * \brief Determine if a C++ method is declared '= default'. 4463 */ 4464 uint clang_CXXMethod_isDefaulted(CXCursor C); 4465 4466 /** 4467 * \brief Determine if a C++ member function or member function template is 4468 * pure virtual. 4469 */ 4470 uint clang_CXXMethod_isPureVirtual(CXCursor C); 4471 4472 /** 4473 * \brief Determine if a C++ member function or member function template is 4474 * declared 'static'. 4475 */ 4476 uint clang_CXXMethod_isStatic(CXCursor C); 4477 4478 /** 4479 * \brief Determine if a C++ member function or member function template is 4480 * explicitly declared 'virtual' or if it overrides a virtual method from 4481 * one of the base classes. 4482 */ 4483 uint clang_CXXMethod_isVirtual(CXCursor C); 4484 4485 /** 4486 * \brief Determine if a C++ record is abstract, i.e. whether a class or struct 4487 * has a pure virtual member function. 4488 */ 4489 uint clang_CXXRecord_isAbstract(CXCursor C); 4490 4491 /** 4492 * \brief Determine if an enum declaration refers to a scoped enum. 4493 */ 4494 uint clang_EnumDecl_isScoped(CXCursor C); 4495 4496 /** 4497 * \brief Determine if a C++ member function or member function template is 4498 * declared 'const'. 4499 */ 4500 uint clang_CXXMethod_isConst(CXCursor C); 4501 4502 /** 4503 * \brief Given a cursor that represents a template, determine 4504 * the cursor kind of the specializations would be generated by instantiating 4505 * the template. 4506 * 4507 * This routine can be used to determine what flavor of function template, 4508 * class template, or class template partial specialization is stored in the 4509 * cursor. For example, it can describe whether a class template cursor is 4510 * declared with "struct", "class" or "union". 4511 * 4512 * \param C The cursor to query. This cursor should represent a template 4513 * declaration. 4514 * 4515 * \returns The cursor kind of the specializations that would be generated 4516 * by instantiating the template \p C. If \p C is not a template, returns 4517 * \c CXCursor_NoDeclFound. 4518 */ 4519 CXCursorKind clang_getTemplateCursorKind(CXCursor C); 4520 4521 /** 4522 * \brief Given a cursor that may represent a specialization or instantiation 4523 * of a template, retrieve the cursor that represents the template that it 4524 * specializes or from which it was instantiated. 4525 * 4526 * This routine determines the template involved both for explicit 4527 * specializations of templates and for implicit instantiations of the template, 4528 * both of which are referred to as "specializations". For a class template 4529 * specialization (e.g., \c std::vector<bool>), this routine will return 4530 * either the primary template (\c std::vector) or, if the specialization was 4531 * instantiated from a class template partial specialization, the class template 4532 * partial specialization. For a class template partial specialization and a 4533 * function template specialization (including instantiations), this 4534 * this routine will return the specialized template. 4535 * 4536 * For members of a class template (e.g., member functions, member classes, or 4537 * static data members), returns the specialized or instantiated member. 4538 * Although not strictly "templates" in the C++ language, members of class 4539 * templates have the same notions of specializations and instantiations that 4540 * templates do, so this routine treats them similarly. 4541 * 4542 * \param C A cursor that may be a specialization of a template or a member 4543 * of a template. 4544 * 4545 * \returns If the given cursor is a specialization or instantiation of a 4546 * template or a member thereof, the template or member that it specializes or 4547 * from which it was instantiated. Otherwise, returns a NULL cursor. 4548 */ 4549 CXCursor clang_getSpecializedCursorTemplate(CXCursor C); 4550 4551 /** 4552 * \brief Given a cursor that references something else, return the source range 4553 * covering that reference. 4554 * 4555 * \param C A cursor pointing to a member reference, a declaration reference, or 4556 * an operator call. 4557 * \param NameFlags A bitset with three independent flags: 4558 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and 4559 * CXNameRange_WantSinglePiece. 4560 * \param PieceIndex For contiguous names or when passing the flag 4561 * CXNameRange_WantSinglePiece, only one piece with index 0 is 4562 * available. When the CXNameRange_WantSinglePiece flag is not passed for a 4563 * non-contiguous names, this index can be used to retrieve the individual 4564 * pieces of the name. See also CXNameRange_WantSinglePiece. 4565 * 4566 * \returns The piece of the name pointed to by the given cursor. If there is no 4567 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned. 4568 */ 4569 CXSourceRange clang_getCursorReferenceNameRange( 4570 CXCursor C, 4571 uint NameFlags, 4572 uint PieceIndex); 4573 4574 enum CXNameRefFlags 4575 { 4576 /** 4577 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the 4578 * range. 4579 */ 4580 wantQualifier = 0x1, 4581 4582 /** 4583 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>, 4584 * in the range. 4585 */ 4586 wantTemplateArgs = 0x2, 4587 4588 /** 4589 * \brief If the name is non-contiguous, return the full spanning range. 4590 * 4591 * Non-contiguous names occur in Objective-C when a selector with two or more 4592 * parameters is used, or in C++ when using an operator: 4593 * \code 4594 * [object doSomething:here withValue:there]; // Objective-C 4595 * return some_vector[1]; // C++ 4596 * \endcode 4597 */ 4598 wantSinglePiece = 0x4 4599 } 4600 4601 /** 4602 * @} 4603 */ 4604 4605 /** 4606 * \defgroup CINDEX_LEX Token extraction and manipulation 4607 * 4608 * The routines in this group provide access to the tokens within a 4609 * translation unit, along with a semantic mapping of those tokens to 4610 * their corresponding cursors. 4611 * 4612 * @{ 4613 */ 4614 4615 /** 4616 * \brief Describes a kind of token. 4617 */ 4618 enum CXTokenKind 4619 { 4620 /** 4621 * \brief A token that contains some kind of punctuation. 4622 */ 4623 punctuation = 0, 4624 4625 /** 4626 * \brief A language keyword. 4627 */ 4628 keyword = 1, 4629 4630 /** 4631 * \brief An identifier (that is not a keyword). 4632 */ 4633 identifier = 2, 4634 4635 /** 4636 * \brief A numeric, string, or character literal. 4637 */ 4638 literal = 3, 4639 4640 /** 4641 * \brief A comment. 4642 */ 4643 comment = 4 4644 } 4645 4646 /** 4647 * \brief Describes a single preprocessing token. 4648 */ 4649 struct CXToken 4650 { 4651 uint[4] int_data; 4652 void* ptr_data; 4653 } 4654 4655 /** 4656 * \brief Determine the kind of the given token. 4657 */ 4658 CXTokenKind clang_getTokenKind(CXToken); 4659 4660 /** 4661 * \brief Determine the spelling of the given token. 4662 * 4663 * The spelling of a token is the textual representation of that token, e.g., 4664 * the text of an identifier or keyword. 4665 */ 4666 CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 4667 4668 /** 4669 * \brief Retrieve the source location of the given token. 4670 */ 4671 CXSourceLocation clang_getTokenLocation(CXTranslationUnit, CXToken); 4672 4673 /** 4674 * \brief Retrieve a source range that covers the given token. 4675 */ 4676 CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 4677 4678 /** 4679 * \brief Tokenize the source code described by the given range into raw 4680 * lexical tokens. 4681 * 4682 * \param TU the translation unit whose text is being tokenized. 4683 * 4684 * \param Range the source range in which text should be tokenized. All of the 4685 * tokens produced by tokenization will fall within this source range, 4686 * 4687 * \param Tokens this pointer will be set to point to the array of tokens 4688 * that occur within the given source range. The returned pointer must be 4689 * freed with clang_disposeTokens() before the translation unit is destroyed. 4690 * 4691 * \param NumTokens will be set to the number of tokens in the \c *Tokens 4692 * array. 4693 * 4694 */ 4695 void clang_tokenize( 4696 CXTranslationUnit TU, 4697 CXSourceRange Range, 4698 CXToken** Tokens, 4699 uint* NumTokens); 4700 4701 /** 4702 * \brief Annotate the given set of tokens by providing cursors for each token 4703 * that can be mapped to a specific entity within the abstract syntax tree. 4704 * 4705 * This token-annotation routine is equivalent to invoking 4706 * clang_getCursor() for the source locations of each of the 4707 * tokens. The cursors provided are filtered, so that only those 4708 * cursors that have a direct correspondence to the token are 4709 * accepted. For example, given a function call \c f(x), 4710 * clang_getCursor() would provide the following cursors: 4711 * 4712 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 4713 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 4714 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 4715 * 4716 * Only the first and last of these cursors will occur within the 4717 * annotate, since the tokens "f" and "x' directly refer to a function 4718 * and a variable, respectively, but the parentheses are just a small 4719 * part of the full syntax of the function call expression, which is 4720 * not provided as an annotation. 4721 * 4722 * \param TU the translation unit that owns the given tokens. 4723 * 4724 * \param Tokens the set of tokens to annotate. 4725 * 4726 * \param NumTokens the number of tokens in \p Tokens. 4727 * 4728 * \param Cursors an array of \p NumTokens cursors, whose contents will be 4729 * replaced with the cursors corresponding to each token. 4730 */ 4731 void clang_annotateTokens( 4732 CXTranslationUnit TU, 4733 CXToken* Tokens, 4734 uint NumTokens, 4735 CXCursor* Cursors); 4736 4737 /** 4738 * \brief Free the given set of tokens. 4739 */ 4740 void clang_disposeTokens(CXTranslationUnit TU, CXToken* Tokens, uint NumTokens); 4741 4742 /** 4743 * @} 4744 */ 4745 4746 /** 4747 * \defgroup CINDEX_DEBUG Debugging facilities 4748 * 4749 * These routines are used for testing and debugging, only, and should not 4750 * be relied upon. 4751 * 4752 * @{ 4753 */ 4754 4755 /* for debug/testing */ 4756 CXString clang_getCursorKindSpelling(CXCursorKind Kind); 4757 void clang_getDefinitionSpellingAndExtent( 4758 CXCursor, 4759 const(char*)* startBuf, 4760 const(char*)* endBuf, 4761 uint* startLine, 4762 uint* startColumn, 4763 uint* endLine, 4764 uint* endColumn); 4765 void clang_enableStackTraces(); 4766 void clang_executeOnThread( 4767 void function(void*) fn, 4768 void* user_data, 4769 uint stack_size); 4770 4771 /** 4772 * @} 4773 */ 4774 4775 /** 4776 * \defgroup CINDEX_CODE_COMPLET Code completion 4777 * 4778 * Code completion involves taking an (incomplete) source file, along with 4779 * knowledge of where the user is actively editing that file, and suggesting 4780 * syntactically- and semantically-valid constructs that the user might want to 4781 * use at that particular point in the source code. These data structures and 4782 * routines provide support for code completion. 4783 * 4784 * @{ 4785 */ 4786 4787 /** 4788 * \brief A semantic string that describes a code-completion result. 4789 * 4790 * A semantic string that describes the formatting of a code-completion 4791 * result as a single "template" of text that should be inserted into the 4792 * source buffer when a particular code-completion result is selected. 4793 * Each semantic string is made up of some number of "chunks", each of which 4794 * contains some text along with a description of what that text means, e.g., 4795 * the name of the entity being referenced, whether the text chunk is part of 4796 * the template, or whether it is a "placeholder" that the user should replace 4797 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 4798 * description of the different kinds of chunks. 4799 */ 4800 alias CXCompletionString = void*; 4801 4802 /** 4803 * \brief A single result of code completion. 4804 */ 4805 struct CXCompletionResult 4806 { 4807 /** 4808 * \brief The kind of entity that this completion refers to. 4809 * 4810 * The cursor kind will be a macro, keyword, or a declaration (one of the 4811 * *Decl cursor kinds), describing the entity that the completion is 4812 * referring to. 4813 * 4814 * \todo In the future, we would like to provide a full cursor, to allow 4815 * the client to extract additional information from declaration. 4816 */ 4817 CXCursorKind CursorKind; 4818 4819 /** 4820 * \brief The code-completion string that describes how to insert this 4821 * code-completion result into the editing buffer. 4822 */ 4823 CXCompletionString CompletionString; 4824 } 4825 4826 /** 4827 * \brief Describes a single piece of text within a code-completion string. 4828 * 4829 * Each "chunk" within a code-completion string (\c CXCompletionString) is 4830 * either a piece of text with a specific "kind" that describes how that text 4831 * should be interpreted by the client or is another completion string. 4832 */ 4833 enum CXCompletionChunkKind 4834 { 4835 /** 4836 * \brief A code-completion string that describes "optional" text that 4837 * could be a part of the template (but is not required). 4838 * 4839 * The Optional chunk is the only kind of chunk that has a code-completion 4840 * string for its representation, which is accessible via 4841 * \c clang_getCompletionChunkCompletionString(). The code-completion string 4842 * describes an additional part of the template that is completely optional. 4843 * For example, optional chunks can be used to describe the placeholders for 4844 * arguments that match up with defaulted function parameters, e.g. given: 4845 * 4846 * \code 4847 * void f(int x, float y = 3.14, double z = 2.71828); 4848 * \endcode 4849 * 4850 * The code-completion string for this function would contain: 4851 * - a TypedText chunk for "f". 4852 * - a LeftParen chunk for "(". 4853 * - a Placeholder chunk for "int x" 4854 * - an Optional chunk containing the remaining defaulted arguments, e.g., 4855 * - a Comma chunk for "," 4856 * - a Placeholder chunk for "float y" 4857 * - an Optional chunk containing the last defaulted argument: 4858 * - a Comma chunk for "," 4859 * - a Placeholder chunk for "double z" 4860 * - a RightParen chunk for ")" 4861 * 4862 * There are many ways to handle Optional chunks. Two simple approaches are: 4863 * - Completely ignore optional chunks, in which case the template for the 4864 * function "f" would only include the first parameter ("int x"). 4865 * - Fully expand all optional chunks, in which case the template for the 4866 * function "f" would have all of the parameters. 4867 */ 4868 optional = 0, 4869 /** 4870 * \brief Text that a user would be expected to type to get this 4871 * code-completion result. 4872 * 4873 * There will be exactly one "typed text" chunk in a semantic string, which 4874 * will typically provide the spelling of a keyword or the name of a 4875 * declaration that could be used at the current code point. Clients are 4876 * expected to filter the code-completion results based on the text in this 4877 * chunk. 4878 */ 4879 typedText = 1, 4880 /** 4881 * \brief Text that should be inserted as part of a code-completion result. 4882 * 4883 * A "text" chunk represents text that is part of the template to be 4884 * inserted into user code should this particular code-completion result 4885 * be selected. 4886 */ 4887 text = 2, 4888 /** 4889 * \brief Placeholder text that should be replaced by the user. 4890 * 4891 * A "placeholder" chunk marks a place where the user should insert text 4892 * into the code-completion template. For example, placeholders might mark 4893 * the function parameters for a function declaration, to indicate that the 4894 * user should provide arguments for each of those parameters. The actual 4895 * text in a placeholder is a suggestion for the text to display before 4896 * the user replaces the placeholder with real code. 4897 */ 4898 placeholder = 3, 4899 /** 4900 * \brief Informative text that should be displayed but never inserted as 4901 * part of the template. 4902 * 4903 * An "informative" chunk contains annotations that can be displayed to 4904 * help the user decide whether a particular code-completion result is the 4905 * right option, but which is not part of the actual template to be inserted 4906 * by code completion. 4907 */ 4908 informative = 4, 4909 /** 4910 * \brief Text that describes the current parameter when code-completion is 4911 * referring to function call, message send, or template specialization. 4912 * 4913 * A "current parameter" chunk occurs when code-completion is providing 4914 * information about a parameter corresponding to the argument at the 4915 * code-completion point. For example, given a function 4916 * 4917 * \code 4918 * int add(int x, int y); 4919 * \endcode 4920 * 4921 * and the source code \c add(, where the code-completion point is after the 4922 * "(", the code-completion string will contain a "current parameter" chunk 4923 * for "int x", indicating that the current argument will initialize that 4924 * parameter. After typing further, to \c add(17, (where the code-completion 4925 * point is after the ","), the code-completion string will contain a 4926 * "current paremeter" chunk to "int y". 4927 */ 4928 currentParameter = 5, 4929 /** 4930 * \brief A left parenthesis ('('), used to initiate a function call or 4931 * signal the beginning of a function parameter list. 4932 */ 4933 leftParen = 6, 4934 /** 4935 * \brief A right parenthesis (')'), used to finish a function call or 4936 * signal the end of a function parameter list. 4937 */ 4938 rightParen = 7, 4939 /** 4940 * \brief A left bracket ('['). 4941 */ 4942 leftBracket = 8, 4943 /** 4944 * \brief A right bracket (']'). 4945 */ 4946 rightBracket = 9, 4947 /** 4948 * \brief A left brace ('{'). 4949 */ 4950 leftBrace = 10, 4951 /** 4952 * \brief A right brace ('}'). 4953 */ 4954 rightBrace = 11, 4955 /** 4956 * \brief A left angle bracket ('<'). 4957 */ 4958 leftAngle = 12, 4959 /** 4960 * \brief A right angle bracket ('>'). 4961 */ 4962 rightAngle = 13, 4963 /** 4964 * \brief A comma separator (','). 4965 */ 4966 comma = 14, 4967 /** 4968 * \brief Text that specifies the result type of a given result. 4969 * 4970 * This special kind of informative chunk is not meant to be inserted into 4971 * the text buffer. Rather, it is meant to illustrate the type that an 4972 * expression using the given completion string would have. 4973 */ 4974 resultType = 15, 4975 /** 4976 * \brief A colon (':'). 4977 */ 4978 colon = 16, 4979 /** 4980 * \brief A semicolon (';'). 4981 */ 4982 semiColon = 17, 4983 /** 4984 * \brief An '=' sign. 4985 */ 4986 equal = 18, 4987 /** 4988 * Horizontal space (' '). 4989 */ 4990 horizontalSpace = 19, 4991 /** 4992 * Vertical space ('\\n'), after which it is generally a good idea to 4993 * perform indentation. 4994 */ 4995 verticalSpace = 20 4996 } 4997 4998 /** 4999 * \brief Determine the kind of a particular chunk within a completion string. 5000 * 5001 * \param completion_string the completion string to query. 5002 * 5003 * \param chunk_number the 0-based index of the chunk in the completion string. 5004 * 5005 * \returns the kind of the chunk at the index \c chunk_number. 5006 */ 5007 CXCompletionChunkKind clang_getCompletionChunkKind( 5008 CXCompletionString completion_string, 5009 uint chunk_number); 5010 5011 /** 5012 * \brief Retrieve the text associated with a particular chunk within a 5013 * completion string. 5014 * 5015 * \param completion_string the completion string to query. 5016 * 5017 * \param chunk_number the 0-based index of the chunk in the completion string. 5018 * 5019 * \returns the text associated with the chunk at index \c chunk_number. 5020 */ 5021 CXString clang_getCompletionChunkText( 5022 CXCompletionString completion_string, 5023 uint chunk_number); 5024 5025 /** 5026 * \brief Retrieve the completion string associated with a particular chunk 5027 * within a completion string. 5028 * 5029 * \param completion_string the completion string to query. 5030 * 5031 * \param chunk_number the 0-based index of the chunk in the completion string. 5032 * 5033 * \returns the completion string associated with the chunk at index 5034 * \c chunk_number. 5035 */ 5036 CXCompletionString clang_getCompletionChunkCompletionString( 5037 CXCompletionString completion_string, 5038 uint chunk_number); 5039 5040 /** 5041 * \brief Retrieve the number of chunks in the given code-completion string. 5042 */ 5043 uint clang_getNumCompletionChunks(CXCompletionString completion_string); 5044 5045 /** 5046 * \brief Determine the priority of this code completion. 5047 * 5048 * The priority of a code completion indicates how likely it is that this 5049 * particular completion is the completion that the user will select. The 5050 * priority is selected by various internal heuristics. 5051 * 5052 * \param completion_string The completion string to query. 5053 * 5054 * \returns The priority of this completion string. Smaller values indicate 5055 * higher-priority (more likely) completions. 5056 */ 5057 uint clang_getCompletionPriority(CXCompletionString completion_string); 5058 5059 /** 5060 * \brief Determine the availability of the entity that this code-completion 5061 * string refers to. 5062 * 5063 * \param completion_string The completion string to query. 5064 * 5065 * \returns The availability of the completion string. 5066 */ 5067 CXAvailabilityKind clang_getCompletionAvailability( 5068 CXCompletionString completion_string); 5069 5070 /** 5071 * \brief Retrieve the number of annotations associated with the given 5072 * completion string. 5073 * 5074 * \param completion_string the completion string to query. 5075 * 5076 * \returns the number of annotations associated with the given completion 5077 * string. 5078 */ 5079 uint clang_getCompletionNumAnnotations(CXCompletionString completion_string); 5080 5081 /** 5082 * \brief Retrieve the annotation associated with the given completion string. 5083 * 5084 * \param completion_string the completion string to query. 5085 * 5086 * \param annotation_number the 0-based index of the annotation of the 5087 * completion string. 5088 * 5089 * \returns annotation string associated with the completion at index 5090 * \c annotation_number, or a NULL string if that annotation is not available. 5091 */ 5092 CXString clang_getCompletionAnnotation( 5093 CXCompletionString completion_string, 5094 uint annotation_number); 5095 5096 /** 5097 * \brief Retrieve the parent context of the given completion string. 5098 * 5099 * The parent context of a completion string is the semantic parent of 5100 * the declaration (if any) that the code completion represents. For example, 5101 * a code completion for an Objective-C method would have the method's class 5102 * or protocol as its context. 5103 * 5104 * \param completion_string The code completion string whose parent is 5105 * being queried. 5106 * 5107 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL. 5108 * 5109 * \returns The name of the completion parent, e.g., "NSObject" if 5110 * the completion string represents a method in the NSObject class. 5111 */ 5112 CXString clang_getCompletionParent( 5113 CXCompletionString completion_string, 5114 CXCursorKind* kind); 5115 5116 /** 5117 * \brief Retrieve the brief documentation comment attached to the declaration 5118 * that corresponds to the given completion string. 5119 */ 5120 CXString clang_getCompletionBriefComment(CXCompletionString completion_string); 5121 5122 /** 5123 * \brief Retrieve a completion string for an arbitrary declaration or macro 5124 * definition cursor. 5125 * 5126 * \param cursor The cursor to query. 5127 * 5128 * \returns A non-context-sensitive completion string for declaration and macro 5129 * definition cursors, or NULL for other kinds of cursors. 5130 */ 5131 CXCompletionString clang_getCursorCompletionString(CXCursor cursor); 5132 5133 /** 5134 * \brief Contains the results of code-completion. 5135 * 5136 * This data structure contains the results of code completion, as 5137 * produced by \c clang_codeCompleteAt(). Its contents must be freed by 5138 * \c clang_disposeCodeCompleteResults. 5139 */ 5140 struct CXCodeCompleteResults 5141 { 5142 /** 5143 * \brief The code-completion results. 5144 */ 5145 CXCompletionResult* Results; 5146 5147 /** 5148 * \brief The number of code-completion results stored in the 5149 * \c Results array. 5150 */ 5151 uint NumResults; 5152 } 5153 5154 /** 5155 * \brief Flags that can be passed to \c clang_codeCompleteAt() to 5156 * modify its behavior. 5157 * 5158 * The enumerators in this enumeration can be bitwise-OR'd together to 5159 * provide multiple options to \c clang_codeCompleteAt(). 5160 */ 5161 enum CXCodeComplete_Flags 5162 { 5163 /** 5164 * \brief Whether to include macros within the set of code 5165 * completions returned. 5166 */ 5167 includeMacros = 0x01, 5168 5169 /** 5170 * \brief Whether to include code patterns for language constructs 5171 * within the set of code completions, e.g., for loops. 5172 */ 5173 includeCodePatterns = 0x02, 5174 5175 /** 5176 * \brief Whether to include brief documentation within the set of code 5177 * completions returned. 5178 */ 5179 includeBriefComments = 0x04 5180 } 5181 5182 /** 5183 * \brief Bits that represent the context under which completion is occurring. 5184 * 5185 * The enumerators in this enumeration may be bitwise-OR'd together if multiple 5186 * contexts are occurring simultaneously. 5187 */ 5188 enum CXCompletionContext 5189 { 5190 /** 5191 * \brief The context for completions is unexposed, as only Clang results 5192 * should be included. (This is equivalent to having no context bits set.) 5193 */ 5194 unexposed = 0, 5195 5196 /** 5197 * \brief Completions for any possible type should be included in the results. 5198 */ 5199 anyType = 1 << 0, 5200 5201 /** 5202 * \brief Completions for any possible value (variables, function calls, etc.) 5203 * should be included in the results. 5204 */ 5205 anyValue = 1 << 1, 5206 /** 5207 * \brief Completions for values that resolve to an Objective-C object should 5208 * be included in the results. 5209 */ 5210 objCObjectValue = 1 << 2, 5211 /** 5212 * \brief Completions for values that resolve to an Objective-C selector 5213 * should be included in the results. 5214 */ 5215 objCSelectorValue = 1 << 3, 5216 /** 5217 * \brief Completions for values that resolve to a C++ class type should be 5218 * included in the results. 5219 */ 5220 cxxClassTypeValue = 1 << 4, 5221 5222 /** 5223 * \brief Completions for fields of the member being accessed using the dot 5224 * operator should be included in the results. 5225 */ 5226 dotMemberAccess = 1 << 5, 5227 /** 5228 * \brief Completions for fields of the member being accessed using the arrow 5229 * operator should be included in the results. 5230 */ 5231 arrowMemberAccess = 1 << 6, 5232 /** 5233 * \brief Completions for properties of the Objective-C object being accessed 5234 * using the dot operator should be included in the results. 5235 */ 5236 objCPropertyAccess = 1 << 7, 5237 5238 /** 5239 * \brief Completions for enum tags should be included in the results. 5240 */ 5241 enumTag = 1 << 8, 5242 /** 5243 * \brief Completions for union tags should be included in the results. 5244 */ 5245 unionTag = 1 << 9, 5246 /** 5247 * \brief Completions for struct tags should be included in the results. 5248 */ 5249 structTag = 1 << 10, 5250 5251 /** 5252 * \brief Completions for C++ class names should be included in the results. 5253 */ 5254 classTag = 1 << 11, 5255 /** 5256 * \brief Completions for C++ namespaces and namespace aliases should be 5257 * included in the results. 5258 */ 5259 namespace = 1 << 12, 5260 /** 5261 * \brief Completions for C++ nested name specifiers should be included in 5262 * the results. 5263 */ 5264 nestedNameSpecifier = 1 << 13, 5265 5266 /** 5267 * \brief Completions for Objective-C interfaces (classes) should be included 5268 * in the results. 5269 */ 5270 objCInterface = 1 << 14, 5271 /** 5272 * \brief Completions for Objective-C protocols should be included in 5273 * the results. 5274 */ 5275 objCProtocol = 1 << 15, 5276 /** 5277 * \brief Completions for Objective-C categories should be included in 5278 * the results. 5279 */ 5280 objCCategory = 1 << 16, 5281 /** 5282 * \brief Completions for Objective-C instance messages should be included 5283 * in the results. 5284 */ 5285 objCInstanceMessage = 1 << 17, 5286 /** 5287 * \brief Completions for Objective-C class messages should be included in 5288 * the results. 5289 */ 5290 objCClassMessage = 1 << 18, 5291 /** 5292 * \brief Completions for Objective-C selector names should be included in 5293 * the results. 5294 */ 5295 objCSelectorName = 1 << 19, 5296 5297 /** 5298 * \brief Completions for preprocessor macro names should be included in 5299 * the results. 5300 */ 5301 macroName = 1 << 20, 5302 5303 /** 5304 * \brief Natural language completions should be included in the results. 5305 */ 5306 naturalLanguage = 1 << 21, 5307 5308 /** 5309 * \brief The current context is unknown, so set all contexts. 5310 */ 5311 unknown = (1 << 22) - 1 5312 } 5313 5314 /** 5315 * \brief Returns a default set of code-completion options that can be 5316 * passed to\c clang_codeCompleteAt(). 5317 */ 5318 uint clang_defaultCodeCompleteOptions(); 5319 5320 /** 5321 * \brief Perform code completion at a given location in a translation unit. 5322 * 5323 * This function performs code completion at a particular file, line, and 5324 * column within source code, providing results that suggest potential 5325 * code snippets based on the context of the completion. The basic model 5326 * for code completion is that Clang will parse a complete source file, 5327 * performing syntax checking up to the location where code-completion has 5328 * been requested. At that point, a special code-completion token is passed 5329 * to the parser, which recognizes this token and determines, based on the 5330 * current location in the C/Objective-C/C++ grammar and the state of 5331 * semantic analysis, what completions to provide. These completions are 5332 * returned via a new \c CXCodeCompleteResults structure. 5333 * 5334 * Code completion itself is meant to be triggered by the client when the 5335 * user types punctuation characters or whitespace, at which point the 5336 * code-completion location will coincide with the cursor. For example, if \c p 5337 * is a pointer, code-completion might be triggered after the "-" and then 5338 * after the ">" in \c p->. When the code-completion location is afer the ">", 5339 * the completion results will provide, e.g., the members of the struct that 5340 * "p" points to. The client is responsible for placing the cursor at the 5341 * beginning of the token currently being typed, then filtering the results 5342 * based on the contents of the token. For example, when code-completing for 5343 * the expression \c p->get, the client should provide the location just after 5344 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 5345 * client can filter the results based on the current token text ("get"), only 5346 * showing those results that start with "get". The intent of this interface 5347 * is to separate the relatively high-latency acquisition of code-completion 5348 * results from the filtering of results on a per-character basis, which must 5349 * have a lower latency. 5350 * 5351 * \param TU The translation unit in which code-completion should 5352 * occur. The source files for this translation unit need not be 5353 * completely up-to-date (and the contents of those source files may 5354 * be overridden via \p unsaved_files). Cursors referring into the 5355 * translation unit may be invalidated by this invocation. 5356 * 5357 * \param complete_filename The name of the source file where code 5358 * completion should be performed. This filename may be any file 5359 * included in the translation unit. 5360 * 5361 * \param complete_line The line at which code-completion should occur. 5362 * 5363 * \param complete_column The column at which code-completion should occur. 5364 * Note that the column should point just after the syntactic construct that 5365 * initiated code completion, and not in the middle of a lexical token. 5366 * 5367 * \param unsaved_files the Files that have not yet been saved to disk 5368 * but may be required for parsing or code completion, including the 5369 * contents of those files. The contents and name of these files (as 5370 * specified by CXUnsavedFile) are copied when necessary, so the 5371 * client only needs to guarantee their validity until the call to 5372 * this function returns. 5373 * 5374 * \param num_unsaved_files The number of unsaved file entries in \p 5375 * unsaved_files. 5376 * 5377 * \param options Extra options that control the behavior of code 5378 * completion, expressed as a bitwise OR of the enumerators of the 5379 * CXCodeComplete_Flags enumeration. The 5380 * \c clang_defaultCodeCompleteOptions() function returns a default set 5381 * of code-completion options. 5382 * 5383 * \returns If successful, a new \c CXCodeCompleteResults structure 5384 * containing code-completion results, which should eventually be 5385 * freed with \c clang_disposeCodeCompleteResults(). If code 5386 * completion fails, returns NULL. 5387 */ 5388 CXCodeCompleteResults* clang_codeCompleteAt( 5389 CXTranslationUnit TU, 5390 const(char)* complete_filename, 5391 uint complete_line, 5392 uint complete_column, 5393 CXUnsavedFile* unsaved_files, 5394 uint num_unsaved_files, 5395 uint options); 5396 5397 /** 5398 * \brief Sort the code-completion results in case-insensitive alphabetical 5399 * order. 5400 * 5401 * \param Results The set of results to sort. 5402 * \param NumResults The number of results in \p Results. 5403 */ 5404 void clang_sortCodeCompletionResults( 5405 CXCompletionResult* Results, 5406 uint NumResults); 5407 5408 /** 5409 * \brief Free the given set of code-completion results. 5410 */ 5411 void clang_disposeCodeCompleteResults(CXCodeCompleteResults* Results); 5412 5413 /** 5414 * \brief Determine the number of diagnostics produced prior to the 5415 * location where code completion was performed. 5416 */ 5417 uint clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults* Results); 5418 5419 /** 5420 * \brief Retrieve a diagnostic associated with the given code completion. 5421 * 5422 * \param Results the code completion results to query. 5423 * \param Index the zero-based diagnostic number to retrieve. 5424 * 5425 * \returns the requested diagnostic. This diagnostic must be freed 5426 * via a call to \c clang_disposeDiagnostic(). 5427 */ 5428 CXDiagnostic clang_codeCompleteGetDiagnostic( 5429 CXCodeCompleteResults* Results, 5430 uint Index); 5431 5432 /** 5433 * \brief Determines what completions are appropriate for the context 5434 * the given code completion. 5435 * 5436 * \param Results the code completion results to query 5437 * 5438 * \returns the kinds of completions that are appropriate for use 5439 * along with the given code completion results. 5440 */ 5441 ulong clang_codeCompleteGetContexts(CXCodeCompleteResults* Results); 5442 5443 /** 5444 * \brief Returns the cursor kind for the container for the current code 5445 * completion context. The container is only guaranteed to be set for 5446 * contexts where a container exists (i.e. member accesses or Objective-C 5447 * message sends); if there is not a container, this function will return 5448 * CXCursor_InvalidCode. 5449 * 5450 * \param Results the code completion results to query 5451 * 5452 * \param IsIncomplete on return, this value will be false if Clang has complete 5453 * information about the container. If Clang does not have complete 5454 * information, this value will be true. 5455 * 5456 * \returns the container kind, or CXCursor_InvalidCode if there is not a 5457 * container 5458 */ 5459 CXCursorKind clang_codeCompleteGetContainerKind( 5460 CXCodeCompleteResults* Results, 5461 uint* IsIncomplete); 5462 5463 /** 5464 * \brief Returns the USR for the container for the current code completion 5465 * context. If there is not a container for the current context, this 5466 * function will return the empty string. 5467 * 5468 * \param Results the code completion results to query 5469 * 5470 * \returns the USR for the container 5471 */ 5472 CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults* Results); 5473 5474 /** 5475 * \brief Returns the currently-entered selector for an Objective-C message 5476 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a 5477 * non-empty string for CXCompletionContext_ObjCInstanceMessage and 5478 * CXCompletionContext_ObjCClassMessage. 5479 * 5480 * \param Results the code completion results to query 5481 * 5482 * \returns the selector (or partial selector) that has been entered thus far 5483 * for an Objective-C message send. 5484 */ 5485 CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults* Results); 5486 5487 /** 5488 * @} 5489 */ 5490 5491 /** 5492 * \defgroup CINDEX_MISC Miscellaneous utility functions 5493 * 5494 * @{ 5495 */ 5496 5497 /** 5498 * \brief Return a version string, suitable for showing to a user, but not 5499 * intended to be parsed (the format is not guaranteed to be stable). 5500 */ 5501 CXString clang_getClangVersion(); 5502 5503 /** 5504 * \brief Enable/disable crash recovery. 5505 * 5506 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero 5507 * value enables crash recovery, while 0 disables it. 5508 */ 5509 void clang_toggleCrashRecovery(uint isEnabled); 5510 5511 /** 5512 * \brief Visitor invoked for each file in a translation unit 5513 * (used with clang_getInclusions()). 5514 * 5515 * This visitor function will be invoked by clang_getInclusions() for each 5516 * file included (either at the top-level or by \#include directives) within 5517 * a translation unit. The first argument is the file being included, and 5518 * the second and third arguments provide the inclusion stack. The 5519 * array is sorted in order of immediate inclusion. For example, 5520 * the first element refers to the location that included 'included_file'. 5521 */ 5522 alias CXInclusionVisitor = void function( 5523 CXFile included_file, 5524 CXSourceLocation* inclusion_stack, 5525 uint include_len, 5526 CXClientData client_data); 5527 5528 /** 5529 * \brief Visit the set of preprocessor inclusions in a translation unit. 5530 * The visitor function is called with the provided data for every included 5531 * file. This does not include headers included by the PCH file (unless one 5532 * is inspecting the inclusions in the PCH file itself). 5533 */ 5534 void clang_getInclusions( 5535 CXTranslationUnit tu, 5536 CXInclusionVisitor visitor, 5537 CXClientData client_data); 5538 5539 enum CXEvalResultKind 5540 { 5541 int_ = 1, 5542 float_ = 2, 5543 objCStrLiteral = 3, 5544 strLiteral = 4, 5545 cfStr = 5, 5546 other = 6, 5547 5548 unExposed = 0 5549 } 5550 5551 /** 5552 * \brief Evaluation result of a cursor 5553 */ 5554 alias CXEvalResult = void*; 5555 5556 /** 5557 * \brief If cursor is a statement declaration tries to evaluate the 5558 * statement and if its variable, tries to evaluate its initializer, 5559 * into its corresponding type. 5560 */ 5561 CXEvalResult clang_Cursor_Evaluate(CXCursor C); 5562 5563 /** 5564 * \brief Returns the kind of the evaluated result. 5565 */ 5566 CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E); 5567 5568 /** 5569 * \brief Returns the evaluation result as integer if the 5570 * kind is Int. 5571 */ 5572 int clang_EvalResult_getAsInt(CXEvalResult E); 5573 5574 /** 5575 * \brief Returns the evaluation result as a long long integer if the 5576 * kind is Int. This prevents overflows that may happen if the result is 5577 * returned with clang_EvalResult_getAsInt. 5578 */ 5579 long clang_EvalResult_getAsLongLong(CXEvalResult E); 5580 5581 /** 5582 * \brief Returns a non-zero value if the kind is Int and the evaluation 5583 * result resulted in an unsigned integer. 5584 */ 5585 uint clang_EvalResult_isUnsignedInt(CXEvalResult E); 5586 5587 /** 5588 * \brief Returns the evaluation result as an unsigned integer if 5589 * the kind is Int and clang_EvalResult_isUnsignedInt is non-zero. 5590 */ 5591 ulong clang_EvalResult_getAsUnsigned(CXEvalResult E); 5592 5593 /** 5594 * \brief Returns the evaluation result as double if the 5595 * kind is double. 5596 */ 5597 double clang_EvalResult_getAsDouble(CXEvalResult E); 5598 5599 /** 5600 * \brief Returns the evaluation result as a constant string if the 5601 * kind is other than Int or float. User must not free this pointer, 5602 * instead call clang_EvalResult_dispose on the CXEvalResult returned 5603 * by clang_Cursor_Evaluate. 5604 */ 5605 const(char)* clang_EvalResult_getAsStr(CXEvalResult E); 5606 5607 /** 5608 * \brief Disposes the created Eval memory. 5609 */ 5610 void clang_EvalResult_dispose(CXEvalResult E); 5611 /** 5612 * @} 5613 */ 5614 5615 /** \defgroup CINDEX_REMAPPING Remapping functions 5616 * 5617 * @{ 5618 */ 5619 5620 /** 5621 * \brief A remapping of original source files and their translated files. 5622 */ 5623 alias CXRemapping = void*; 5624 5625 /** 5626 * \brief Retrieve a remapping. 5627 * 5628 * \param path the path that contains metadata about remappings. 5629 * 5630 * \returns the requested remapping. This remapping must be freed 5631 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. 5632 */ 5633 CXRemapping clang_getRemappings(const(char)* path); 5634 5635 /** 5636 * \brief Retrieve a remapping. 5637 * 5638 * \param filePaths pointer to an array of file paths containing remapping info. 5639 * 5640 * \param numFiles number of file paths. 5641 * 5642 * \returns the requested remapping. This remapping must be freed 5643 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. 5644 */ 5645 CXRemapping clang_getRemappingsFromFileList( 5646 const(char*)* filePaths, 5647 uint numFiles); 5648 5649 /** 5650 * \brief Determine the number of remappings. 5651 */ 5652 uint clang_remap_getNumFiles(CXRemapping); 5653 5654 /** 5655 * \brief Get the original and the associated filename from the remapping. 5656 * 5657 * \param original If non-NULL, will be set to the original filename. 5658 * 5659 * \param transformed If non-NULL, will be set to the filename that the original 5660 * is associated with. 5661 */ 5662 void clang_remap_getFilenames( 5663 CXRemapping, 5664 uint index, 5665 CXString* original, 5666 CXString* transformed); 5667 5668 /** 5669 * \brief Dispose the remapping. 5670 */ 5671 void clang_remap_dispose(CXRemapping); 5672 5673 /** 5674 * @} 5675 */ 5676 5677 /** \defgroup CINDEX_HIGH Higher level API functions 5678 * 5679 * @{ 5680 */ 5681 5682 enum CXVisitorResult 5683 { 5684 break_ = 0, 5685 continue_ = 1 5686 } 5687 5688 struct CXCursorAndRangeVisitor 5689 { 5690 void* context; 5691 CXVisitorResult function(void* context, CXCursor, CXSourceRange) visit; 5692 } 5693 5694 enum CXResult 5695 { 5696 /** 5697 * \brief Function returned successfully. 5698 */ 5699 success = 0, 5700 /** 5701 * \brief One of the parameters was invalid for the function. 5702 */ 5703 invalid = 1, 5704 /** 5705 * \brief The function was terminated by a callback (e.g. it returned 5706 * CXVisit_Break) 5707 */ 5708 visitBreak = 2 5709 } 5710 5711 /** 5712 * \brief Find references of a declaration in a specific file. 5713 * 5714 * \param cursor pointing to a declaration or a reference of one. 5715 * 5716 * \param file to search for references. 5717 * 5718 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for 5719 * each reference found. 5720 * The CXSourceRange will point inside the file; if the reference is inside 5721 * a macro (and not a macro argument) the CXSourceRange will be invalid. 5722 * 5723 * \returns one of the CXResult enumerators. 5724 */ 5725 CXResult clang_findReferencesInFile( 5726 CXCursor cursor, 5727 CXFile file, 5728 CXCursorAndRangeVisitor visitor); 5729 5730 /** 5731 * \brief Find #import/#include directives in a specific file. 5732 * 5733 * \param TU translation unit containing the file to query. 5734 * 5735 * \param file to search for #import/#include directives. 5736 * 5737 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for 5738 * each directive found. 5739 * 5740 * \returns one of the CXResult enumerators. 5741 */ 5742 CXResult clang_findIncludesInFile( 5743 CXTranslationUnit TU, 5744 CXFile file, 5745 CXCursorAndRangeVisitor visitor); 5746 5747 /** 5748 * \brief The client's data object that is associated with a CXFile. 5749 */ 5750 alias CXIdxClientFile = void*; 5751 5752 /** 5753 * \brief The client's data object that is associated with a semantic entity. 5754 */ 5755 alias CXIdxClientEntity = void*; 5756 5757 /** 5758 * \brief The client's data object that is associated with a semantic container 5759 * of entities. 5760 */ 5761 alias CXIdxClientContainer = void*; 5762 5763 /** 5764 * \brief The client's data object that is associated with an AST file (PCH 5765 * or module). 5766 */ 5767 alias CXIdxClientASTFile = void*; 5768 5769 /** 5770 * \brief Source location passed to index callbacks. 5771 */ 5772 struct CXIdxLoc 5773 { 5774 void*[2] ptr_data; 5775 uint int_data; 5776 } 5777 5778 /** 5779 * \brief Data for ppIncludedFile callback. 5780 */ 5781 struct CXIdxIncludedFileInfo 5782 { 5783 /** 5784 * \brief Location of '#' in the \#include/\#import directive. 5785 */ 5786 CXIdxLoc hashLoc; 5787 /** 5788 * \brief Filename as written in the \#include/\#import directive. 5789 */ 5790 const(char)* filename; 5791 /** 5792 * \brief The actual file that the \#include/\#import directive resolved to. 5793 */ 5794 CXFile file; 5795 int isImport; 5796 int isAngled; 5797 /** 5798 * \brief Non-zero if the directive was automatically turned into a module 5799 * import. 5800 */ 5801 int isModuleImport; 5802 } 5803 5804 /** 5805 * \brief Data for IndexerCallbacks#importedASTFile. 5806 */ 5807 struct CXIdxImportedASTFileInfo 5808 { 5809 /** 5810 * \brief Top level AST file containing the imported PCH, module or submodule. 5811 */ 5812 CXFile file; 5813 /** 5814 * \brief The imported module or NULL if the AST file is a PCH. 5815 */ 5816 CXModule module_; 5817 /** 5818 * \brief Location where the file is imported. Applicable only for modules. 5819 */ 5820 CXIdxLoc loc; 5821 /** 5822 * \brief Non-zero if an inclusion directive was automatically turned into 5823 * a module import. Applicable only for modules. 5824 */ 5825 int isImplicit; 5826 } 5827 5828 enum CXIdxEntityKind 5829 { 5830 unexposed = 0, 5831 typedef_ = 1, 5832 function_ = 2, 5833 variable = 3, 5834 field = 4, 5835 enumConstant = 5, 5836 5837 objCClass = 6, 5838 objCProtocol = 7, 5839 objCCategory = 8, 5840 5841 objCInstanceMethod = 9, 5842 objCClassMethod = 10, 5843 objCProperty = 11, 5844 objCIvar = 12, 5845 5846 enum_ = 13, 5847 struct_ = 14, 5848 union_ = 15, 5849 5850 cxxClass = 16, 5851 cxxNamespace = 17, 5852 cxxNamespaceAlias = 18, 5853 cxxStaticVariable = 19, 5854 cxxStaticMethod = 20, 5855 cxxInstanceMethod = 21, 5856 cxxConstructor = 22, 5857 cxxDestructor = 23, 5858 cxxConversionFunction = 24, 5859 cxxTypeAlias = 25, 5860 cxxInterface = 26 5861 } 5862 5863 enum CXIdxEntityLanguage 5864 { 5865 none = 0, 5866 c = 1, 5867 objC = 2, 5868 cxx = 3, 5869 swift = 4 5870 } 5871 5872 /** 5873 * \brief Extra C++ template information for an entity. This can apply to: 5874 * CXIdxEntity_Function 5875 * CXIdxEntity_CXXClass 5876 * CXIdxEntity_CXXStaticMethod 5877 * CXIdxEntity_CXXInstanceMethod 5878 * CXIdxEntity_CXXConstructor 5879 * CXIdxEntity_CXXConversionFunction 5880 * CXIdxEntity_CXXTypeAlias 5881 */ 5882 enum CXIdxEntityCXXTemplateKind 5883 { 5884 nonTemplate = 0, 5885 template_ = 1, 5886 templatePartialSpecialization = 2, 5887 templateSpecialization = 3 5888 } 5889 5890 enum CXIdxAttrKind 5891 { 5892 unexposed = 0, 5893 ibAction = 1, 5894 ibOutlet = 2, 5895 ibOutletCollection = 3 5896 } 5897 5898 struct CXIdxAttrInfo 5899 { 5900 CXIdxAttrKind kind; 5901 CXCursor cursor; 5902 CXIdxLoc loc; 5903 } 5904 5905 struct CXIdxEntityInfo 5906 { 5907 CXIdxEntityKind kind; 5908 CXIdxEntityCXXTemplateKind templateKind; 5909 CXIdxEntityLanguage lang; 5910 const(char)* name; 5911 const(char)* USR; 5912 CXCursor cursor; 5913 const(CXIdxAttrInfo*)* attributes; 5914 uint numAttributes; 5915 } 5916 5917 struct CXIdxContainerInfo 5918 { 5919 CXCursor cursor; 5920 } 5921 5922 struct CXIdxIBOutletCollectionAttrInfo 5923 { 5924 const(CXIdxAttrInfo)* attrInfo; 5925 const(CXIdxEntityInfo)* objcClass; 5926 CXCursor classCursor; 5927 CXIdxLoc classLoc; 5928 } 5929 5930 enum CXIdxDeclInfoFlags 5931 { 5932 skipped = 0x1 5933 } 5934 5935 struct CXIdxDeclInfo 5936 { 5937 const(CXIdxEntityInfo)* entityInfo; 5938 CXCursor cursor; 5939 CXIdxLoc loc; 5940 const(CXIdxContainerInfo)* semanticContainer; 5941 /** 5942 * \brief Generally same as #semanticContainer but can be different in 5943 * cases like out-of-line C++ member functions. 5944 */ 5945 const(CXIdxContainerInfo)* lexicalContainer; 5946 int isRedeclaration; 5947 int isDefinition; 5948 int isContainer; 5949 const(CXIdxContainerInfo)* declAsContainer; 5950 /** 5951 * \brief Whether the declaration exists in code or was created implicitly 5952 * by the compiler, e.g. implicit Objective-C methods for properties. 5953 */ 5954 int isImplicit; 5955 const(CXIdxAttrInfo*)* attributes; 5956 uint numAttributes; 5957 5958 uint flags; 5959 } 5960 5961 enum CXIdxObjCContainerKind 5962 { 5963 forwardRef = 0, 5964 interface_ = 1, 5965 implementation = 2 5966 } 5967 5968 struct CXIdxObjCContainerDeclInfo 5969 { 5970 const(CXIdxDeclInfo)* declInfo; 5971 CXIdxObjCContainerKind kind; 5972 } 5973 5974 struct CXIdxBaseClassInfo 5975 { 5976 const(CXIdxEntityInfo)* base; 5977 CXCursor cursor; 5978 CXIdxLoc loc; 5979 } 5980 5981 struct CXIdxObjCProtocolRefInfo 5982 { 5983 const(CXIdxEntityInfo)* protocol; 5984 CXCursor cursor; 5985 CXIdxLoc loc; 5986 } 5987 5988 struct CXIdxObjCProtocolRefListInfo 5989 { 5990 const(CXIdxObjCProtocolRefInfo*)* protocols; 5991 uint numProtocols; 5992 } 5993 5994 struct CXIdxObjCInterfaceDeclInfo 5995 { 5996 const(CXIdxObjCContainerDeclInfo)* containerInfo; 5997 const(CXIdxBaseClassInfo)* superInfo; 5998 const(CXIdxObjCProtocolRefListInfo)* protocols; 5999 } 6000 6001 struct CXIdxObjCCategoryDeclInfo 6002 { 6003 const(CXIdxObjCContainerDeclInfo)* containerInfo; 6004 const(CXIdxEntityInfo)* objcClass; 6005 CXCursor classCursor; 6006 CXIdxLoc classLoc; 6007 const(CXIdxObjCProtocolRefListInfo)* protocols; 6008 } 6009 6010 struct CXIdxObjCPropertyDeclInfo 6011 { 6012 const(CXIdxDeclInfo)* declInfo; 6013 const(CXIdxEntityInfo)* getter; 6014 const(CXIdxEntityInfo)* setter; 6015 } 6016 6017 struct CXIdxCXXClassDeclInfo 6018 { 6019 const(CXIdxDeclInfo)* declInfo; 6020 const(CXIdxBaseClassInfo*)* bases; 6021 uint numBases; 6022 } 6023 6024 /** 6025 * \brief Data for IndexerCallbacks#indexEntityReference. 6026 */ 6027 enum CXIdxEntityRefKind 6028 { 6029 /** 6030 * \brief The entity is referenced directly in user's code. 6031 */ 6032 direct = 1, 6033 /** 6034 * \brief An implicit reference, e.g. a reference of an Objective-C method 6035 * via the dot syntax. 6036 */ 6037 implicit = 2 6038 } 6039 6040 /** 6041 * \brief Data for IndexerCallbacks#indexEntityReference. 6042 */ 6043 struct CXIdxEntityRefInfo 6044 { 6045 CXIdxEntityRefKind kind; 6046 /** 6047 * \brief Reference cursor. 6048 */ 6049 CXCursor cursor; 6050 CXIdxLoc loc; 6051 /** 6052 * \brief The entity that gets referenced. 6053 */ 6054 const(CXIdxEntityInfo)* referencedEntity; 6055 /** 6056 * \brief Immediate "parent" of the reference. For example: 6057 * 6058 * \code 6059 * Foo *var; 6060 * \endcode 6061 * 6062 * The parent of reference of type 'Foo' is the variable 'var'. 6063 * For references inside statement bodies of functions/methods, 6064 * the parentEntity will be the function/method. 6065 */ 6066 const(CXIdxEntityInfo)* parentEntity; 6067 /** 6068 * \brief Lexical container context of the reference. 6069 */ 6070 const(CXIdxContainerInfo)* container; 6071 } 6072 6073 /** 6074 * \brief A group of callbacks used by #clang_indexSourceFile and 6075 * #clang_indexTranslationUnit. 6076 */ 6077 struct IndexerCallbacks 6078 { 6079 /** 6080 * \brief Called periodically to check whether indexing should be aborted. 6081 * Should return 0 to continue, and non-zero to abort. 6082 */ 6083 int function(CXClientData client_data, void* reserved) abortQuery; 6084 6085 /** 6086 * \brief Called at the end of indexing; passes the complete diagnostic set. 6087 */ 6088 void function( 6089 CXClientData client_data, 6090 CXDiagnosticSet, 6091 void* reserved) diagnostic; 6092 6093 CXIdxClientFile function( 6094 CXClientData client_data, 6095 CXFile mainFile, 6096 void* reserved) enteredMainFile; 6097 6098 /** 6099 * \brief Called when a file gets \#included/\#imported. 6100 */ 6101 CXIdxClientFile function( 6102 CXClientData client_data, 6103 const(CXIdxIncludedFileInfo)*) ppIncludedFile; 6104 6105 /** 6106 * \brief Called when a AST file (PCH or module) gets imported. 6107 * 6108 * AST files will not get indexed (there will not be callbacks to index all 6109 * the entities in an AST file). The recommended action is that, if the AST 6110 * file is not already indexed, to initiate a new indexing job specific to 6111 * the AST file. 6112 */ 6113 CXIdxClientASTFile function( 6114 CXClientData client_data, 6115 const(CXIdxImportedASTFileInfo)*) importedASTFile; 6116 6117 /** 6118 * \brief Called at the beginning of indexing a translation unit. 6119 */ 6120 CXIdxClientContainer function( 6121 CXClientData client_data, 6122 void* reserved) startedTranslationUnit; 6123 6124 void function( 6125 CXClientData client_data, 6126 const(CXIdxDeclInfo)*) indexDeclaration; 6127 6128 /** 6129 * \brief Called to index a reference of an entity. 6130 */ 6131 void function( 6132 CXClientData client_data, 6133 const(CXIdxEntityRefInfo)*) indexEntityReference; 6134 } 6135 6136 int clang_index_isEntityObjCContainerKind(CXIdxEntityKind); 6137 const(CXIdxObjCContainerDeclInfo)* clang_index_getObjCContainerDeclInfo( 6138 const(CXIdxDeclInfo)*); 6139 6140 const(CXIdxObjCInterfaceDeclInfo)* clang_index_getObjCInterfaceDeclInfo( 6141 const(CXIdxDeclInfo)*); 6142 6143 const(CXIdxObjCCategoryDeclInfo)* clang_index_getObjCCategoryDeclInfo( 6144 const(CXIdxDeclInfo)*); 6145 6146 const(CXIdxObjCProtocolRefListInfo)* clang_index_getObjCProtocolRefListInfo( 6147 const(CXIdxDeclInfo)*); 6148 6149 const(CXIdxObjCPropertyDeclInfo)* clang_index_getObjCPropertyDeclInfo( 6150 const(CXIdxDeclInfo)*); 6151 6152 const(CXIdxIBOutletCollectionAttrInfo)* clang_index_getIBOutletCollectionAttrInfo( 6153 const(CXIdxAttrInfo)*); 6154 6155 const(CXIdxCXXClassDeclInfo)* clang_index_getCXXClassDeclInfo( 6156 const(CXIdxDeclInfo)*); 6157 6158 /** 6159 * \brief For retrieving a custom CXIdxClientContainer attached to a 6160 * container. 6161 */ 6162 CXIdxClientContainer clang_index_getClientContainer(const(CXIdxContainerInfo)*); 6163 6164 /** 6165 * \brief For setting a custom CXIdxClientContainer attached to a 6166 * container. 6167 */ 6168 void clang_index_setClientContainer( 6169 const(CXIdxContainerInfo)*, 6170 CXIdxClientContainer); 6171 6172 /** 6173 * \brief For retrieving a custom CXIdxClientEntity attached to an entity. 6174 */ 6175 CXIdxClientEntity clang_index_getClientEntity(const(CXIdxEntityInfo)*); 6176 6177 /** 6178 * \brief For setting a custom CXIdxClientEntity attached to an entity. 6179 */ 6180 void clang_index_setClientEntity(const(CXIdxEntityInfo)*, CXIdxClientEntity); 6181 6182 /** 6183 * \brief An indexing action/session, to be applied to one or multiple 6184 * translation units. 6185 */ 6186 alias CXIndexAction = void*; 6187 6188 /** 6189 * \brief An indexing action/session, to be applied to one or multiple 6190 * translation units. 6191 * 6192 * \param CIdx The index object with which the index action will be associated. 6193 */ 6194 CXIndexAction clang_IndexAction_create(CXIndex CIdx); 6195 6196 /** 6197 * \brief Destroy the given index action. 6198 * 6199 * The index action must not be destroyed until all of the translation units 6200 * created within that index action have been destroyed. 6201 */ 6202 void clang_IndexAction_dispose(CXIndexAction); 6203 6204 enum CXIndexOptFlags 6205 { 6206 /** 6207 * \brief Used to indicate that no special indexing options are needed. 6208 */ 6209 none = 0x0, 6210 6211 /** 6212 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should 6213 * be invoked for only one reference of an entity per source file that does 6214 * not also include a declaration/definition of the entity. 6215 */ 6216 suppressRedundantRefs = 0x1, 6217 6218 /** 6219 * \brief Function-local symbols should be indexed. If this is not set 6220 * function-local symbols will be ignored. 6221 */ 6222 indexFunctionLocalSymbols = 0x2, 6223 6224 /** 6225 * \brief Implicit function/class template instantiations should be indexed. 6226 * If this is not set, implicit instantiations will be ignored. 6227 */ 6228 indexImplicitTemplateInstantiations = 0x4, 6229 6230 /** 6231 * \brief Suppress all compiler warnings when parsing for indexing. 6232 */ 6233 suppressWarnings = 0x8, 6234 6235 /** 6236 * \brief Skip a function/method body that was already parsed during an 6237 * indexing session associated with a \c CXIndexAction object. 6238 * Bodies in system headers are always skipped. 6239 */ 6240 skipParsedBodiesInSession = 0x10 6241 } 6242 6243 /** 6244 * \brief Index the given source file and the translation unit corresponding 6245 * to that file via callbacks implemented through #IndexerCallbacks. 6246 * 6247 * \param client_data pointer data supplied by the client, which will 6248 * be passed to the invoked callbacks. 6249 * 6250 * \param index_callbacks Pointer to indexing callbacks that the client 6251 * implements. 6252 * 6253 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets 6254 * passed in index_callbacks. 6255 * 6256 * \param index_options A bitmask of options that affects how indexing is 6257 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags. 6258 * 6259 * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be 6260 * reused after indexing is finished. Set to \c NULL if you do not require it. 6261 * 6262 * \returns 0 on success or if there were errors from which the compiler could 6263 * recover. If there is a failure from which there is no recovery, returns 6264 * a non-zero \c CXErrorCode. 6265 * 6266 * The rest of the parameters are the same as #clang_parseTranslationUnit. 6267 */ 6268 int clang_indexSourceFile( 6269 CXIndexAction, 6270 CXClientData client_data, 6271 IndexerCallbacks* index_callbacks, 6272 uint index_callbacks_size, 6273 uint index_options, 6274 const(char)* source_filename, 6275 const(char*)* command_line_args, 6276 int num_command_line_args, 6277 CXUnsavedFile* unsaved_files, 6278 uint num_unsaved_files, 6279 CXTranslationUnit* out_TU, 6280 uint TU_options); 6281 6282 /** 6283 * \brief Same as clang_indexSourceFile but requires a full command line 6284 * for \c command_line_args including argv[0]. This is useful if the standard 6285 * library paths are relative to the binary. 6286 */ 6287 int clang_indexSourceFileFullArgv( 6288 CXIndexAction, 6289 CXClientData client_data, 6290 IndexerCallbacks* index_callbacks, 6291 uint index_callbacks_size, 6292 uint index_options, 6293 const(char)* source_filename, 6294 const(char*)* command_line_args, 6295 int num_command_line_args, 6296 CXUnsavedFile* unsaved_files, 6297 uint num_unsaved_files, 6298 CXTranslationUnit* out_TU, 6299 uint TU_options); 6300 6301 /** 6302 * \brief Index the given translation unit via callbacks implemented through 6303 * #IndexerCallbacks. 6304 * 6305 * The order of callback invocations is not guaranteed to be the same as 6306 * when indexing a source file. The high level order will be: 6307 * 6308 * -Preprocessor callbacks invocations 6309 * -Declaration/reference callbacks invocations 6310 * -Diagnostic callback invocations 6311 * 6312 * The parameters are the same as #clang_indexSourceFile. 6313 * 6314 * \returns If there is a failure from which there is no recovery, returns 6315 * non-zero, otherwise returns 0. 6316 */ 6317 int clang_indexTranslationUnit( 6318 CXIndexAction, 6319 CXClientData client_data, 6320 IndexerCallbacks* index_callbacks, 6321 uint index_callbacks_size, 6322 uint index_options, 6323 CXTranslationUnit); 6324 6325 /** 6326 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by 6327 * the given CXIdxLoc. 6328 * 6329 * If the location refers into a macro expansion, retrieves the 6330 * location of the macro expansion and if it refers into a macro argument 6331 * retrieves the location of the argument. 6332 */ 6333 void clang_indexLoc_getFileLocation( 6334 CXIdxLoc loc, 6335 CXIdxClientFile* indexFile, 6336 CXFile* file, 6337 uint* line, 6338 uint* column, 6339 uint* offset); 6340 6341 /** 6342 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc. 6343 */ 6344 CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc); 6345 6346 /** 6347 * \brief Visitor invoked for each field found by a traversal. 6348 * 6349 * This visitor function will be invoked for each field found by 6350 * \c clang_Type_visitFields. Its first argument is the cursor being 6351 * visited, its second argument is the client data provided to 6352 * \c clang_Type_visitFields. 6353 * 6354 * The visitor should return one of the \c CXVisitorResult values 6355 * to direct \c clang_Type_visitFields. 6356 */ 6357 alias CXFieldVisitor = CXVisitorResult function( 6358 CXCursor C, 6359 CXClientData client_data); 6360 6361 /** 6362 * \brief Visit the fields of a particular type. 6363 * 6364 * This function visits all the direct fields of the given cursor, 6365 * invoking the given \p visitor function with the cursors of each 6366 * visited field. The traversal may be ended prematurely, if 6367 * the visitor returns \c CXFieldVisit_Break. 6368 * 6369 * \param T the record type whose field may be visited. 6370 * 6371 * \param visitor the visitor function that will be invoked for each 6372 * field of \p T. 6373 * 6374 * \param client_data pointer data supplied by the client, which will 6375 * be passed to the visitor each time it is invoked. 6376 * 6377 * \returns a non-zero value if the traversal was terminated 6378 * prematurely by the visitor returning \c CXFieldVisit_Break. 6379 */ 6380 uint clang_Type_visitFields( 6381 CXType T, 6382 CXFieldVisitor visitor, 6383 CXClientData client_data); 6384 6385 /** 6386 * @} 6387 */ 6388 6389 /** 6390 * @} 6391 */ 6392