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