Index.h revision c71d55469e7d5f7b376a30620617a175a9442da9
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 <sys/stat.h> 20#include <time.h> 21#include <stdio.h> 22 23#ifdef __cplusplus 24extern "C" { 25#endif 26 27/* MSVC DLL import/export. */ 28#ifdef _MSC_VER 29 #ifdef _CINDEX_LIB_ 30 #define CINDEX_LINKAGE __declspec(dllexport) 31 #else 32 #define CINDEX_LINKAGE __declspec(dllimport) 33 #endif 34#else 35 #define CINDEX_LINKAGE 36#endif 37 38/** \defgroup CINDEX libclang: C Interface to Clang 39 * 40 * The C Interface to Clang provides a relatively small API that exposes 41 * facilities for parsing source code into an abstract syntax tree (AST), 42 * loading already-parsed ASTs, traversing the AST, associating 43 * physical source locations with elements within the AST, and other 44 * facilities that support Clang-based development tools. 45 * 46 * This C interface to Clang will never provide all of the information 47 * representation stored in Clang's C++ AST, nor should it: the intent is to 48 * maintain an API that is relatively stable from one release to the next, 49 * providing only the basic functionality needed to support development tools. 50 * 51 * To avoid namespace pollution, data types are prefixed with "CX" and 52 * functions are prefixed with "clang_". 53 * 54 * @{ 55 */ 56 57/** 58 * \brief An "index" that consists of a set of translation units that would 59 * typically be linked together into an executable or library. 60 */ 61typedef void *CXIndex; 62 63/** 64 * \brief A single translation unit, which resides in an index. 65 */ 66typedef struct CXTranslationUnitImpl *CXTranslationUnit; 67 68/** 69 * \brief Opaque pointer representing client data that will be passed through 70 * to various callbacks and visitors. 71 */ 72typedef void *CXClientData; 73 74/** 75 * \brief Provides the contents of a file that has not yet been saved to disk. 76 * 77 * Each CXUnsavedFile instance provides the name of a file on the 78 * system along with the current contents of that file that have not 79 * yet been saved to disk. 80 */ 81struct CXUnsavedFile { 82 /** 83 * \brief The file whose contents have not yet been saved. 84 * 85 * This file must already exist in the file system. 86 */ 87 const char *Filename; 88 89 /** 90 * \brief A buffer containing the unsaved contents of this file. 91 */ 92 const char *Contents; 93 94 /** 95 * \brief The length of the unsaved contents of this buffer. 96 */ 97 unsigned long Length; 98}; 99 100/** 101 * \brief Describes the availability of a particular entity, which indicates 102 * whether the use of this entity will result in a warning or error due to 103 * it being deprecated or unavailable. 104 */ 105enum CXAvailabilityKind { 106 /** 107 * \brief The entity is available. 108 */ 109 CXAvailability_Available, 110 /** 111 * \brief The entity is available, but has been deprecated (and its use is 112 * not recommended). 113 */ 114 CXAvailability_Deprecated, 115 /** 116 * \brief The entity is not available; any use of it will be an error. 117 */ 118 CXAvailability_NotAvailable, 119 /** 120 * \brief The entity is available, but not accessible; any use of it will be 121 * an error. 122 */ 123 CXAvailability_NotAccessible 124}; 125 126/** 127 * \defgroup CINDEX_STRING String manipulation routines 128 * 129 * @{ 130 */ 131 132/** 133 * \brief A character string. 134 * 135 * The \c CXString type is used to return strings from the interface when 136 * the ownership of that string might different from one call to the next. 137 * Use \c clang_getCString() to retrieve the string data and, once finished 138 * with the string data, call \c clang_disposeString() to free the string. 139 */ 140typedef struct { 141 void *data; 142 unsigned private_flags; 143} CXString; 144 145/** 146 * \brief Retrieve the character data associated with the given string. 147 */ 148CINDEX_LINKAGE const char *clang_getCString(CXString string); 149 150/** 151 * \brief Free the given string, 152 */ 153CINDEX_LINKAGE void clang_disposeString(CXString string); 154 155/** 156 * @} 157 */ 158 159/** 160 * \brief clang_createIndex() provides a shared context for creating 161 * translation units. It provides two options: 162 * 163 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 164 * declarations (when loading any new translation units). A "local" declaration 165 * is one that belongs in the translation unit itself and not in a precompiled 166 * header that was used by the translation unit. If zero, all declarations 167 * will be enumerated. 168 * 169 * Here is an example: 170 * 171 * // excludeDeclsFromPCH = 1, displayDiagnostics=1 172 * Idx = clang_createIndex(1, 1); 173 * 174 * // IndexTest.pch was produced with the following command: 175 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 176 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 177 * 178 * // This will load all the symbols from 'IndexTest.pch' 179 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 180 * TranslationUnitVisitor, 0); 181 * clang_disposeTranslationUnit(TU); 182 * 183 * // This will load all the symbols from 'IndexTest.c', excluding symbols 184 * // from 'IndexTest.pch'. 185 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 186 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 187 * 0, 0); 188 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 189 * TranslationUnitVisitor, 0); 190 * clang_disposeTranslationUnit(TU); 191 * 192 * This process of creating the 'pch', loading it separately, and using it (via 193 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 194 * (which gives the indexer the same performance benefit as the compiler). 195 */ 196CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, 197 int displayDiagnostics); 198 199/** 200 * \brief Destroy the given index. 201 * 202 * The index must not be destroyed until all of the translation units created 203 * within that index have been destroyed. 204 */ 205CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); 206 207/** 208 * \defgroup CINDEX_FILES File manipulation routines 209 * 210 * @{ 211 */ 212 213/** 214 * \brief A particular source file that is part of a translation unit. 215 */ 216typedef void *CXFile; 217 218 219/** 220 * \brief Retrieve the complete file and path name of the given file. 221 */ 222CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); 223 224/** 225 * \brief Retrieve the last modification time of the given file. 226 */ 227CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); 228 229/** 230 * \brief Determine whether the given header is guarded against 231 * multiple inclusions, either with the conventional 232 * #ifndef/#define/#endif macro guards or with #pragma once. 233 */ 234CINDEX_LINKAGE unsigned 235clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file); 236 237/** 238 * \brief Retrieve a file handle within the given translation unit. 239 * 240 * \param tu the translation unit 241 * 242 * \param file_name the name of the file. 243 * 244 * \returns the file handle for the named file in the translation unit \p tu, 245 * or a NULL file handle if the file was not a part of this translation unit. 246 */ 247CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, 248 const char *file_name); 249 250/** 251 * @} 252 */ 253 254/** 255 * \defgroup CINDEX_LOCATIONS Physical source locations 256 * 257 * Clang represents physical source locations in its abstract syntax tree in 258 * great detail, with file, line, and column information for the majority of 259 * the tokens parsed in the source code. These data types and functions are 260 * used to represent source location information, either for a particular 261 * point in the program or for a range of points in the program, and extract 262 * specific location information from those data types. 263 * 264 * @{ 265 */ 266 267/** 268 * \brief Identifies a specific source location within a translation 269 * unit. 270 * 271 * Use clang_getExpansionLocation() or clang_getSpellingLocation() 272 * to map a source location to a particular file, line, and column. 273 */ 274typedef struct { 275 void *ptr_data[2]; 276 unsigned int_data; 277} CXSourceLocation; 278 279/** 280 * \brief Identifies a half-open character range in the source code. 281 * 282 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 283 * starting and end locations from a source range, respectively. 284 */ 285typedef struct { 286 void *ptr_data[2]; 287 unsigned begin_int_data; 288 unsigned end_int_data; 289} CXSourceRange; 290 291/** 292 * \brief Retrieve a NULL (invalid) source location. 293 */ 294CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); 295 296/** 297 * \determine Determine whether two source locations, which must refer into 298 * the same translation unit, refer to exactly the same point in the source 299 * code. 300 * 301 * \returns non-zero if the source locations refer to the same location, zero 302 * if they refer to different locations. 303 */ 304CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, 305 CXSourceLocation loc2); 306 307/** 308 * \brief Retrieves the source location associated with a given file/line/column 309 * in a particular translation unit. 310 */ 311CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, 312 CXFile file, 313 unsigned line, 314 unsigned column); 315/** 316 * \brief Retrieves the source location associated with a given character offset 317 * in a particular translation unit. 318 */ 319CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, 320 CXFile file, 321 unsigned offset); 322 323/** 324 * \brief Retrieve a NULL (invalid) source range. 325 */ 326CINDEX_LINKAGE CXSourceRange clang_getNullRange(); 327 328/** 329 * \brief Retrieve a source range given the beginning and ending source 330 * locations. 331 */ 332CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, 333 CXSourceLocation end); 334 335/** 336 * \brief Determine whether two ranges are equivalent. 337 * 338 * \returns non-zero if the ranges are the same, zero if they differ. 339 */ 340CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1, 341 CXSourceRange range2); 342 343/** 344 * \brief Returns non-zero if \arg range is null. 345 */ 346CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range); 347 348/** 349 * \brief Retrieve the file, line, column, and offset represented by 350 * the given source location. 351 * 352 * If the location refers into a macro expansion, retrieves the 353 * location of the macro expansion. 354 * 355 * \param location the location within a source file that will be decomposed 356 * into its parts. 357 * 358 * \param file [out] if non-NULL, will be set to the file to which the given 359 * source location points. 360 * 361 * \param line [out] if non-NULL, will be set to the line to which the given 362 * source location points. 363 * 364 * \param column [out] if non-NULL, will be set to the column to which the given 365 * source location points. 366 * 367 * \param offset [out] if non-NULL, will be set to the offset into the 368 * buffer to which the given source location points. 369 */ 370CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location, 371 CXFile *file, 372 unsigned *line, 373 unsigned *column, 374 unsigned *offset); 375 376/** 377 * \brief Retrieve the file, line, column, and offset represented by 378 * the given source location, as specified in a # line directive. 379 * 380 * Example: given the following source code in a file somefile.c 381 * 382 * #123 "dummy.c" 1 383 * 384 * static int func(void) 385 * { 386 * return 0; 387 * } 388 * 389 * the location information returned by this function would be 390 * 391 * File: dummy.c Line: 124 Column: 12 392 * 393 * whereas clang_getExpansionLocation would have returned 394 * 395 * File: somefile.c Line: 3 Column: 12 396 * 397 * \param location the location within a source file that will be decomposed 398 * into its parts. 399 * 400 * \param filename [out] if non-NULL, will be set to the filename of the 401 * source location. Note that filenames returned will be for "virtual" files, 402 * which don't necessarily exist on the machine running clang - e.g. when 403 * parsing preprocessed output obtained from a different environment. If 404 * a non-NULL value is passed in, remember to dispose of the returned value 405 * using \c clang_disposeString() once you've finished with it. For an invalid 406 * source location, an empty string is returned. 407 * 408 * \param line [out] if non-NULL, will be set to the line number of the 409 * source location. For an invalid source location, zero is returned. 410 * 411 * \param column [out] if non-NULL, will be set to the column number of the 412 * source location. For an invalid source location, zero is returned. 413 */ 414CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location, 415 CXString *filename, 416 unsigned *line, 417 unsigned *column); 418 419/** 420 * \brief Legacy API to retrieve the file, line, column, and offset represented 421 * by the given source location. 422 * 423 * This interface has been replaced by the newer interface 424 * \see clang_getExpansionLocation(). See that interface's documentation for 425 * details. 426 */ 427CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, 428 CXFile *file, 429 unsigned *line, 430 unsigned *column, 431 unsigned *offset); 432 433/** 434 * \brief Retrieve the file, line, column, and offset represented by 435 * the given source location. 436 * 437 * If the location refers into a macro instantiation, return where the 438 * location was originally spelled in the source file. 439 * 440 * \param location the location within a source file that will be decomposed 441 * into its parts. 442 * 443 * \param file [out] if non-NULL, will be set to the file to which the given 444 * source location points. 445 * 446 * \param line [out] if non-NULL, will be set to the line to which the given 447 * source location points. 448 * 449 * \param column [out] if non-NULL, will be set to the column to which the given 450 * source location points. 451 * 452 * \param offset [out] if non-NULL, will be set to the offset into the 453 * buffer to which the given source location points. 454 */ 455CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location, 456 CXFile *file, 457 unsigned *line, 458 unsigned *column, 459 unsigned *offset); 460 461/** 462 * \brief Retrieve a source location representing the first character within a 463 * source range. 464 */ 465CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); 466 467/** 468 * \brief Retrieve a source location representing the last character within a 469 * source range. 470 */ 471CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); 472 473/** 474 * @} 475 */ 476 477/** 478 * \defgroup CINDEX_DIAG Diagnostic reporting 479 * 480 * @{ 481 */ 482 483/** 484 * \brief Describes the severity of a particular diagnostic. 485 */ 486enum CXDiagnosticSeverity { 487 /** 488 * \brief A diagnostic that has been suppressed, e.g., by a command-line 489 * option. 490 */ 491 CXDiagnostic_Ignored = 0, 492 493 /** 494 * \brief This diagnostic is a note that should be attached to the 495 * previous (non-note) diagnostic. 496 */ 497 CXDiagnostic_Note = 1, 498 499 /** 500 * \brief This diagnostic indicates suspicious code that may not be 501 * wrong. 502 */ 503 CXDiagnostic_Warning = 2, 504 505 /** 506 * \brief This diagnostic indicates that the code is ill-formed. 507 */ 508 CXDiagnostic_Error = 3, 509 510 /** 511 * \brief This diagnostic indicates that the code is ill-formed such 512 * that future parser recovery is unlikely to produce useful 513 * results. 514 */ 515 CXDiagnostic_Fatal = 4 516}; 517 518/** 519 * \brief A single diagnostic, containing the diagnostic's severity, 520 * location, text, source ranges, and fix-it hints. 521 */ 522typedef void *CXDiagnostic; 523 524/** 525 * \brief A group of CXDiagnostics. 526 */ 527typedef void *CXDiagnosticSet; 528 529/** 530 * \brief Determine the number of diagnostics in a CXDiagnosticSet. 531 */ 532CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags); 533 534/** 535 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet. 536 * 537 * \param Unit the CXDiagnosticSet to query. 538 * \param Index the zero-based diagnostic number to retrieve. 539 * 540 * \returns the requested diagnostic. This diagnostic must be freed 541 * via a call to \c clang_disposeDiagnostic(). 542 */ 543CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, 544 unsigned Index); 545 546 547/** 548 * \brief Describes the kind of error that occurred (if any) in a call to 549 * \c clang_loadDiagnostics. 550 */ 551enum CXLoadDiag_Error { 552 /** 553 * \brief Indicates that no error occurred. 554 */ 555 CXLoadDiag_None = 0, 556 557 /** 558 * \brief Indicates that an unknown error occurred while attempting to 559 * deserialize diagnostics. 560 */ 561 CXLoadDiag_Unknown = 1, 562 563 /** 564 * \brief Indicates that the file containing the serialized diagnostics 565 * could not be opened. 566 */ 567 CXLoadDiag_CannotLoad = 2, 568 569 /** 570 * \brief Indicates that the serialized diagnostics file is invalid or 571 * corrupt. 572 */ 573 CXLoadDiag_InvalidFile = 3 574}; 575 576/** 577 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode 578 * file. 579 * 580 * \param The name of the file to deserialize. 581 * \param A pointer to a enum value recording if there was a problem 582 * deserializing the diagnostics. 583 * \param A pointer to a CXString for recording the error string 584 * if the file was not successfully loaded. 585 * 586 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These 587 * diagnostics should be released using clang_disposeDiagnosticSet(). 588 */ 589CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file, 590 enum CXLoadDiag_Error *error, 591 CXString *errorString); 592 593/** 594 * \brief Release a CXDiagnosticSet and all of its contained diagnostics. 595 */ 596CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags); 597 598/** 599 * \brief Retrieve the child diagnostics of a CXDiagnostic. This 600 * CXDiagnosticSet does not need to be released by clang_diposeDiagnosticSet. 601 */ 602CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D); 603 604/** 605 * \brief Determine the number of diagnostics produced for the given 606 * translation unit. 607 */ 608CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); 609 610/** 611 * \brief Retrieve a diagnostic associated with the given translation unit. 612 * 613 * \param Unit the translation unit to query. 614 * \param Index the zero-based diagnostic number to retrieve. 615 * 616 * \returns the requested diagnostic. This diagnostic must be freed 617 * via a call to \c clang_disposeDiagnostic(). 618 */ 619CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, 620 unsigned Index); 621 622/** 623 * \brief Destroy a diagnostic. 624 */ 625CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); 626 627/** 628 * \brief Options to control the display of diagnostics. 629 * 630 * The values in this enum are meant to be combined to customize the 631 * behavior of \c clang_displayDiagnostic(). 632 */ 633enum CXDiagnosticDisplayOptions { 634 /** 635 * \brief Display the source-location information where the 636 * diagnostic was located. 637 * 638 * When set, diagnostics will be prefixed by the file, line, and 639 * (optionally) column to which the diagnostic refers. For example, 640 * 641 * \code 642 * test.c:28: warning: extra tokens at end of #endif directive 643 * \endcode 644 * 645 * This option corresponds to the clang flag \c -fshow-source-location. 646 */ 647 CXDiagnostic_DisplaySourceLocation = 0x01, 648 649 /** 650 * \brief If displaying the source-location information of the 651 * diagnostic, also include the column number. 652 * 653 * This option corresponds to the clang flag \c -fshow-column. 654 */ 655 CXDiagnostic_DisplayColumn = 0x02, 656 657 /** 658 * \brief If displaying the source-location information of the 659 * diagnostic, also include information about source ranges in a 660 * machine-parsable format. 661 * 662 * This option corresponds to the clang flag 663 * \c -fdiagnostics-print-source-range-info. 664 */ 665 CXDiagnostic_DisplaySourceRanges = 0x04, 666 667 /** 668 * \brief Display the option name associated with this diagnostic, if any. 669 * 670 * The option name displayed (e.g., -Wconversion) will be placed in brackets 671 * after the diagnostic text. This option corresponds to the clang flag 672 * \c -fdiagnostics-show-option. 673 */ 674 CXDiagnostic_DisplayOption = 0x08, 675 676 /** 677 * \brief Display the category number associated with this diagnostic, if any. 678 * 679 * The category number is displayed within brackets after the diagnostic text. 680 * This option corresponds to the clang flag 681 * \c -fdiagnostics-show-category=id. 682 */ 683 CXDiagnostic_DisplayCategoryId = 0x10, 684 685 /** 686 * \brief Display the category name associated with this diagnostic, if any. 687 * 688 * The category name is displayed within brackets after the diagnostic text. 689 * This option corresponds to the clang flag 690 * \c -fdiagnostics-show-category=name. 691 */ 692 CXDiagnostic_DisplayCategoryName = 0x20 693}; 694 695/** 696 * \brief Format the given diagnostic in a manner that is suitable for display. 697 * 698 * This routine will format the given diagnostic to a string, rendering 699 * the diagnostic according to the various options given. The 700 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of 701 * options that most closely mimics the behavior of the clang compiler. 702 * 703 * \param Diagnostic The diagnostic to print. 704 * 705 * \param Options A set of options that control the diagnostic display, 706 * created by combining \c CXDiagnosticDisplayOptions values. 707 * 708 * \returns A new string containing for formatted diagnostic. 709 */ 710CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, 711 unsigned Options); 712 713/** 714 * \brief Retrieve the set of display options most similar to the 715 * default behavior of the clang compiler. 716 * 717 * \returns A set of display options suitable for use with \c 718 * clang_displayDiagnostic(). 719 */ 720CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); 721 722/** 723 * \brief Determine the severity of the given diagnostic. 724 */ 725CINDEX_LINKAGE enum CXDiagnosticSeverity 726clang_getDiagnosticSeverity(CXDiagnostic); 727 728/** 729 * \brief Retrieve the source location of the given diagnostic. 730 * 731 * This location is where Clang would print the caret ('^') when 732 * displaying the diagnostic on the command line. 733 */ 734CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); 735 736/** 737 * \brief Retrieve the text of the given diagnostic. 738 */ 739CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); 740 741/** 742 * \brief Retrieve the name of the command-line option that enabled this 743 * diagnostic. 744 * 745 * \param Diag The diagnostic to be queried. 746 * 747 * \param Disable If non-NULL, will be set to the option that disables this 748 * diagnostic (if any). 749 * 750 * \returns A string that contains the command-line option used to enable this 751 * warning, such as "-Wconversion" or "-pedantic". 752 */ 753CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag, 754 CXString *Disable); 755 756/** 757 * \brief Retrieve the category number for this diagnostic. 758 * 759 * Diagnostics can be categorized into groups along with other, related 760 * diagnostics (e.g., diagnostics under the same warning flag). This routine 761 * retrieves the category number for the given diagnostic. 762 * 763 * \returns The number of the category that contains this diagnostic, or zero 764 * if this diagnostic is uncategorized. 765 */ 766CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic); 767 768/** 769 * \brief Retrieve the name of a particular diagnostic category. 770 * 771 * \param Category A diagnostic category number, as returned by 772 * \c clang_getDiagnosticCategory(). 773 * 774 * \returns The name of the given diagnostic category. 775 */ 776CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category); 777 778/** 779 * \brief Determine the number of source ranges associated with the given 780 * diagnostic. 781 */ 782CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); 783 784/** 785 * \brief Retrieve a source range associated with the diagnostic. 786 * 787 * A diagnostic's source ranges highlight important elements in the source 788 * code. On the command line, Clang displays source ranges by 789 * underlining them with '~' characters. 790 * 791 * \param Diagnostic the diagnostic whose range is being extracted. 792 * 793 * \param Range the zero-based index specifying which range to 794 * 795 * \returns the requested source range. 796 */ 797CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, 798 unsigned Range); 799 800/** 801 * \brief Determine the number of fix-it hints associated with the 802 * given diagnostic. 803 */ 804CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); 805 806/** 807 * \brief Retrieve the replacement information for a given fix-it. 808 * 809 * Fix-its are described in terms of a source range whose contents 810 * should be replaced by a string. This approach generalizes over 811 * three kinds of operations: removal of source code (the range covers 812 * the code to be removed and the replacement string is empty), 813 * replacement of source code (the range covers the code to be 814 * replaced and the replacement string provides the new code), and 815 * insertion (both the start and end of the range point at the 816 * insertion location, and the replacement string provides the text to 817 * insert). 818 * 819 * \param Diagnostic The diagnostic whose fix-its are being queried. 820 * 821 * \param FixIt The zero-based index of the fix-it. 822 * 823 * \param ReplacementRange The source range whose contents will be 824 * replaced with the returned replacement string. Note that source 825 * ranges are half-open ranges [a, b), so the source code should be 826 * replaced from a and up to (but not including) b. 827 * 828 * \returns A string containing text that should be replace the source 829 * code indicated by the \c ReplacementRange. 830 */ 831CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, 832 unsigned FixIt, 833 CXSourceRange *ReplacementRange); 834 835/** 836 * @} 837 */ 838 839/** 840 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation 841 * 842 * The routines in this group provide the ability to create and destroy 843 * translation units from files, either by parsing the contents of the files or 844 * by reading in a serialized representation of a translation unit. 845 * 846 * @{ 847 */ 848 849/** 850 * \brief Get the original translation unit source file name. 851 */ 852CINDEX_LINKAGE CXString 853clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 854 855/** 856 * \brief Return the CXTranslationUnit for a given source file and the provided 857 * command line arguments one would pass to the compiler. 858 * 859 * Note: The 'source_filename' argument is optional. If the caller provides a 860 * NULL pointer, the name of the source file is expected to reside in the 861 * specified command line arguments. 862 * 863 * Note: When encountered in 'clang_command_line_args', the following options 864 * are ignored: 865 * 866 * '-c' 867 * '-emit-ast' 868 * '-fsyntax-only' 869 * '-o <output file>' (both '-o' and '<output file>' are ignored) 870 * 871 * \param CIdx The index object with which the translation unit will be 872 * associated. 873 * 874 * \param source_filename - The name of the source file to load, or NULL if the 875 * source file is included in \p clang_command_line_args. 876 * 877 * \param num_clang_command_line_args The number of command-line arguments in 878 * \p clang_command_line_args. 879 * 880 * \param clang_command_line_args The command-line arguments that would be 881 * passed to the \c clang executable if it were being invoked out-of-process. 882 * These command-line options will be parsed and will affect how the translation 883 * unit is parsed. Note that the following options are ignored: '-c', 884 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. 885 * 886 * \param num_unsaved_files the number of unsaved file entries in \p 887 * unsaved_files. 888 * 889 * \param unsaved_files the files that have not yet been saved to disk 890 * but may be required for code completion, including the contents of 891 * those files. The contents and name of these files (as specified by 892 * CXUnsavedFile) are copied when necessary, so the client only needs to 893 * guarantee their validity until the call to this function returns. 894 */ 895CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( 896 CXIndex CIdx, 897 const char *source_filename, 898 int num_clang_command_line_args, 899 const char * const *clang_command_line_args, 900 unsigned num_unsaved_files, 901 struct CXUnsavedFile *unsaved_files); 902 903/** 904 * \brief Create a translation unit from an AST file (-emit-ast). 905 */ 906CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, 907 const char *ast_filename); 908 909/** 910 * \brief Flags that control the creation of translation units. 911 * 912 * The enumerators in this enumeration type are meant to be bitwise 913 * ORed together to specify which options should be used when 914 * constructing the translation unit. 915 */ 916enum CXTranslationUnit_Flags { 917 /** 918 * \brief Used to indicate that no special translation-unit options are 919 * needed. 920 */ 921 CXTranslationUnit_None = 0x0, 922 923 /** 924 * \brief Used to indicate that the parser should construct a "detailed" 925 * preprocessing record, including all macro definitions and instantiations. 926 * 927 * Constructing a detailed preprocessing record requires more memory 928 * and time to parse, since the information contained in the record 929 * is usually not retained. However, it can be useful for 930 * applications that require more detailed information about the 931 * behavior of the preprocessor. 932 */ 933 CXTranslationUnit_DetailedPreprocessingRecord = 0x01, 934 935 /** 936 * \brief Used to indicate that the translation unit is incomplete. 937 * 938 * When a translation unit is considered "incomplete", semantic 939 * analysis that is typically performed at the end of the 940 * translation unit will be suppressed. For example, this suppresses 941 * the completion of tentative declarations in C and of 942 * instantiation of implicitly-instantiation function templates in 943 * C++. This option is typically used when parsing a header with the 944 * intent of producing a precompiled header. 945 */ 946 CXTranslationUnit_Incomplete = 0x02, 947 948 /** 949 * \brief Used to indicate that the translation unit should be built with an 950 * implicit precompiled header for the preamble. 951 * 952 * An implicit precompiled header is used as an optimization when a 953 * particular translation unit is likely to be reparsed many times 954 * when the sources aren't changing that often. In this case, an 955 * implicit precompiled header will be built containing all of the 956 * initial includes at the top of the main file (what we refer to as 957 * the "preamble" of the file). In subsequent parses, if the 958 * preamble or the files in it have not changed, \c 959 * clang_reparseTranslationUnit() will re-use the implicit 960 * precompiled header to improve parsing performance. 961 */ 962 CXTranslationUnit_PrecompiledPreamble = 0x04, 963 964 /** 965 * \brief Used to indicate that the translation unit should cache some 966 * code-completion results with each reparse of the source file. 967 * 968 * Caching of code-completion results is a performance optimization that 969 * introduces some overhead to reparsing but improves the performance of 970 * code-completion operations. 971 */ 972 CXTranslationUnit_CacheCompletionResults = 0x08, 973 /** 974 * \brief DEPRECATED: Enable precompiled preambles in C++. 975 * 976 * Note: this is a *temporary* option that is available only while 977 * we are testing C++ precompiled preamble support. It is deprecated. 978 */ 979 CXTranslationUnit_CXXPrecompiledPreamble = 0x10, 980 981 /** 982 * \brief DEPRECATED: Enabled chained precompiled preambles in C++. 983 * 984 * Note: this is a *temporary* option that is available only while 985 * we are testing C++ precompiled preamble support. It is deprecated. 986 */ 987 CXTranslationUnit_CXXChainedPCH = 0x20, 988 989 /** 990 * \brief Used to indicate that the "detailed" preprocessing record, 991 * if requested, should also contain nested macro expansions. 992 * 993 * Nested macro expansions (i.e., macro expansions that occur 994 * inside another macro expansion) can, in some code bases, require 995 * a large amount of storage to due preprocessor metaprogramming. Moreover, 996 * its fairly rare that this information is useful for libclang clients. 997 */ 998 CXTranslationUnit_NestedMacroExpansions = 0x40, 999 1000 /** 1001 * \brief Legacy name to indicate that the "detailed" preprocessing record, 1002 * if requested, should contain nested macro expansions. 1003 * 1004 * \see CXTranslationUnit_NestedMacroExpansions for the current name for this 1005 * value, and its semantics. This is just an alias. 1006 */ 1007 CXTranslationUnit_NestedMacroInstantiations = 1008 CXTranslationUnit_NestedMacroExpansions 1009}; 1010 1011/** 1012 * \brief Returns the set of flags that is suitable for parsing a translation 1013 * unit that is being edited. 1014 * 1015 * The set of flags returned provide options for \c clang_parseTranslationUnit() 1016 * to indicate that the translation unit is likely to be reparsed many times, 1017 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly 1018 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag 1019 * set contains an unspecified set of optimizations (e.g., the precompiled 1020 * preamble) geared toward improving the performance of these routines. The 1021 * set of optimizations enabled may change from one version to the next. 1022 */ 1023CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void); 1024 1025/** 1026 * \brief Parse the given source file and the translation unit corresponding 1027 * to that file. 1028 * 1029 * This routine is the main entry point for the Clang C API, providing the 1030 * ability to parse a source file into a translation unit that can then be 1031 * queried by other functions in the API. This routine accepts a set of 1032 * command-line arguments so that the compilation can be configured in the same 1033 * way that the compiler is configured on the command line. 1034 * 1035 * \param CIdx The index object with which the translation unit will be 1036 * associated. 1037 * 1038 * \param source_filename The name of the source file to load, or NULL if the 1039 * source file is included in \p command_line_args. 1040 * 1041 * \param command_line_args The command-line arguments that would be 1042 * passed to the \c clang executable if it were being invoked out-of-process. 1043 * These command-line options will be parsed and will affect how the translation 1044 * unit is parsed. Note that the following options are ignored: '-c', 1045 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. 1046 * 1047 * \param num_command_line_args The number of command-line arguments in 1048 * \p command_line_args. 1049 * 1050 * \param unsaved_files the files that have not yet been saved to disk 1051 * but may be required for parsing, including the contents of 1052 * those files. The contents and name of these files (as specified by 1053 * CXUnsavedFile) are copied when necessary, so the client only needs to 1054 * guarantee their validity until the call to this function returns. 1055 * 1056 * \param num_unsaved_files the number of unsaved file entries in \p 1057 * unsaved_files. 1058 * 1059 * \param options A bitmask of options that affects how the translation unit 1060 * is managed but not its compilation. This should be a bitwise OR of the 1061 * CXTranslationUnit_XXX flags. 1062 * 1063 * \returns A new translation unit describing the parsed code and containing 1064 * any diagnostics produced by the compiler. If there is a failure from which 1065 * the compiler cannot recover, returns NULL. 1066 */ 1067CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx, 1068 const char *source_filename, 1069 const char * const *command_line_args, 1070 int num_command_line_args, 1071 struct CXUnsavedFile *unsaved_files, 1072 unsigned num_unsaved_files, 1073 unsigned options); 1074 1075/** 1076 * \brief Flags that control how translation units are saved. 1077 * 1078 * The enumerators in this enumeration type are meant to be bitwise 1079 * ORed together to specify which options should be used when 1080 * saving the translation unit. 1081 */ 1082enum CXSaveTranslationUnit_Flags { 1083 /** 1084 * \brief Used to indicate that no special saving options are needed. 1085 */ 1086 CXSaveTranslationUnit_None = 0x0 1087}; 1088 1089/** 1090 * \brief Returns the set of flags that is suitable for saving a translation 1091 * unit. 1092 * 1093 * The set of flags returned provide options for 1094 * \c clang_saveTranslationUnit() by default. The returned flag 1095 * set contains an unspecified set of options that save translation units with 1096 * the most commonly-requested data. 1097 */ 1098CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU); 1099 1100/** 1101 * \brief Describes the kind of error that occurred (if any) in a call to 1102 * \c clang_saveTranslationUnit(). 1103 */ 1104enum CXSaveError { 1105 /** 1106 * \brief Indicates that no error occurred while saving a translation unit. 1107 */ 1108 CXSaveError_None = 0, 1109 1110 /** 1111 * \brief Indicates that an unknown error occurred while attempting to save 1112 * the file. 1113 * 1114 * This error typically indicates that file I/O failed when attempting to 1115 * write the file. 1116 */ 1117 CXSaveError_Unknown = 1, 1118 1119 /** 1120 * \brief Indicates that errors during translation prevented this attempt 1121 * to save the translation unit. 1122 * 1123 * Errors that prevent the translation unit from being saved can be 1124 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic(). 1125 */ 1126 CXSaveError_TranslationErrors = 2, 1127 1128 /** 1129 * \brief Indicates that the translation unit to be saved was somehow 1130 * invalid (e.g., NULL). 1131 */ 1132 CXSaveError_InvalidTU = 3 1133}; 1134 1135/** 1136 * \brief Saves a translation unit into a serialized representation of 1137 * that translation unit on disk. 1138 * 1139 * Any translation unit that was parsed without error can be saved 1140 * into a file. The translation unit can then be deserialized into a 1141 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or, 1142 * if it is an incomplete translation unit that corresponds to a 1143 * header, used as a precompiled header when parsing other translation 1144 * units. 1145 * 1146 * \param TU The translation unit to save. 1147 * 1148 * \param FileName The file to which the translation unit will be saved. 1149 * 1150 * \param options A bitmask of options that affects how the translation unit 1151 * is saved. This should be a bitwise OR of the 1152 * CXSaveTranslationUnit_XXX flags. 1153 * 1154 * \returns A value that will match one of the enumerators of the CXSaveError 1155 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was 1156 * saved successfully, while a non-zero value indicates that a problem occurred. 1157 */ 1158CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU, 1159 const char *FileName, 1160 unsigned options); 1161 1162/** 1163 * \brief Destroy the specified CXTranslationUnit object. 1164 */ 1165CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); 1166 1167/** 1168 * \brief Flags that control the reparsing of translation units. 1169 * 1170 * The enumerators in this enumeration type are meant to be bitwise 1171 * ORed together to specify which options should be used when 1172 * reparsing the translation unit. 1173 */ 1174enum CXReparse_Flags { 1175 /** 1176 * \brief Used to indicate that no special reparsing options are needed. 1177 */ 1178 CXReparse_None = 0x0 1179}; 1180 1181/** 1182 * \brief Returns the set of flags that is suitable for reparsing a translation 1183 * unit. 1184 * 1185 * The set of flags returned provide options for 1186 * \c clang_reparseTranslationUnit() by default. The returned flag 1187 * set contains an unspecified set of optimizations geared toward common uses 1188 * of reparsing. The set of optimizations enabled may change from one version 1189 * to the next. 1190 */ 1191CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU); 1192 1193/** 1194 * \brief Reparse the source files that produced this translation unit. 1195 * 1196 * This routine can be used to re-parse the source files that originally 1197 * created the given translation unit, for example because those source files 1198 * have changed (either on disk or as passed via \p unsaved_files). The 1199 * source code will be reparsed with the same command-line options as it 1200 * was originally parsed. 1201 * 1202 * Reparsing a translation unit invalidates all cursors and source locations 1203 * that refer into that translation unit. This makes reparsing a translation 1204 * unit semantically equivalent to destroying the translation unit and then 1205 * creating a new translation unit with the same command-line arguments. 1206 * However, it may be more efficient to reparse a translation 1207 * unit using this routine. 1208 * 1209 * \param TU The translation unit whose contents will be re-parsed. The 1210 * translation unit must originally have been built with 1211 * \c clang_createTranslationUnitFromSourceFile(). 1212 * 1213 * \param num_unsaved_files The number of unsaved file entries in \p 1214 * unsaved_files. 1215 * 1216 * \param unsaved_files The files that have not yet been saved to disk 1217 * but may be required for parsing, including the contents of 1218 * those files. The contents and name of these files (as specified by 1219 * CXUnsavedFile) are copied when necessary, so the client only needs to 1220 * guarantee their validity until the call to this function returns. 1221 * 1222 * \param options A bitset of options composed of the flags in CXReparse_Flags. 1223 * The function \c clang_defaultReparseOptions() produces a default set of 1224 * options recommended for most uses, based on the translation unit. 1225 * 1226 * \returns 0 if the sources could be reparsed. A non-zero value will be 1227 * returned if reparsing was impossible, such that the translation unit is 1228 * invalid. In such cases, the only valid call for \p TU is 1229 * \c clang_disposeTranslationUnit(TU). 1230 */ 1231CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, 1232 unsigned num_unsaved_files, 1233 struct CXUnsavedFile *unsaved_files, 1234 unsigned options); 1235 1236/** 1237 * \brief Categorizes how memory is being used by a translation unit. 1238 */ 1239enum CXTUResourceUsageKind { 1240 CXTUResourceUsage_AST = 1, 1241 CXTUResourceUsage_Identifiers = 2, 1242 CXTUResourceUsage_Selectors = 3, 1243 CXTUResourceUsage_GlobalCompletionResults = 4, 1244 CXTUResourceUsage_SourceManagerContentCache = 5, 1245 CXTUResourceUsage_AST_SideTables = 6, 1246 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7, 1247 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8, 1248 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9, 1249 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10, 1250 CXTUResourceUsage_Preprocessor = 11, 1251 CXTUResourceUsage_PreprocessingRecord = 12, 1252 CXTUResourceUsage_SourceManager_DataStructures = 13, 1253 CXTUResourceUsage_Preprocessor_HeaderSearch = 14, 1254 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST, 1255 CXTUResourceUsage_MEMORY_IN_BYTES_END = 1256 CXTUResourceUsage_Preprocessor_HeaderSearch, 1257 1258 CXTUResourceUsage_First = CXTUResourceUsage_AST, 1259 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch 1260}; 1261 1262/** 1263 * \brief Returns the human-readable null-terminated C string that represents 1264 * the name of the memory category. This string should never be freed. 1265 */ 1266CINDEX_LINKAGE 1267const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind); 1268 1269typedef struct CXTUResourceUsageEntry { 1270 /* \brief The memory usage category. */ 1271 enum CXTUResourceUsageKind kind; 1272 /* \brief Amount of resources used. 1273 The units will depend on the resource kind. */ 1274 unsigned long amount; 1275} CXTUResourceUsageEntry; 1276 1277/** 1278 * \brief The memory usage of a CXTranslationUnit, broken into categories. 1279 */ 1280typedef struct CXTUResourceUsage { 1281 /* \brief Private data member, used for queries. */ 1282 void *data; 1283 1284 /* \brief The number of entries in the 'entries' array. */ 1285 unsigned numEntries; 1286 1287 /* \brief An array of key-value pairs, representing the breakdown of memory 1288 usage. */ 1289 CXTUResourceUsageEntry *entries; 1290 1291} CXTUResourceUsage; 1292 1293/** 1294 * \brief Return the memory usage of a translation unit. This object 1295 * should be released with clang_disposeCXTUResourceUsage(). 1296 */ 1297CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU); 1298 1299CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage); 1300 1301/** 1302 * @} 1303 */ 1304 1305/** 1306 * \brief Describes the kind of entity that a cursor refers to. 1307 */ 1308enum CXCursorKind { 1309 /* Declarations */ 1310 /** 1311 * \brief A declaration whose specific kind is not exposed via this 1312 * interface. 1313 * 1314 * Unexposed declarations have the same operations as any other kind 1315 * of declaration; one can extract their location information, 1316 * spelling, find their definitions, etc. However, the specific kind 1317 * of the declaration is not reported. 1318 */ 1319 CXCursor_UnexposedDecl = 1, 1320 /** \brief A C or C++ struct. */ 1321 CXCursor_StructDecl = 2, 1322 /** \brief A C or C++ union. */ 1323 CXCursor_UnionDecl = 3, 1324 /** \brief A C++ class. */ 1325 CXCursor_ClassDecl = 4, 1326 /** \brief An enumeration. */ 1327 CXCursor_EnumDecl = 5, 1328 /** 1329 * \brief A field (in C) or non-static data member (in C++) in a 1330 * struct, union, or C++ class. 1331 */ 1332 CXCursor_FieldDecl = 6, 1333 /** \brief An enumerator constant. */ 1334 CXCursor_EnumConstantDecl = 7, 1335 /** \brief A function. */ 1336 CXCursor_FunctionDecl = 8, 1337 /** \brief A variable. */ 1338 CXCursor_VarDecl = 9, 1339 /** \brief A function or method parameter. */ 1340 CXCursor_ParmDecl = 10, 1341 /** \brief An Objective-C @interface. */ 1342 CXCursor_ObjCInterfaceDecl = 11, 1343 /** \brief An Objective-C @interface for a category. */ 1344 CXCursor_ObjCCategoryDecl = 12, 1345 /** \brief An Objective-C @protocol declaration. */ 1346 CXCursor_ObjCProtocolDecl = 13, 1347 /** \brief An Objective-C @property declaration. */ 1348 CXCursor_ObjCPropertyDecl = 14, 1349 /** \brief An Objective-C instance variable. */ 1350 CXCursor_ObjCIvarDecl = 15, 1351 /** \brief An Objective-C instance method. */ 1352 CXCursor_ObjCInstanceMethodDecl = 16, 1353 /** \brief An Objective-C class method. */ 1354 CXCursor_ObjCClassMethodDecl = 17, 1355 /** \brief An Objective-C @implementation. */ 1356 CXCursor_ObjCImplementationDecl = 18, 1357 /** \brief An Objective-C @implementation for a category. */ 1358 CXCursor_ObjCCategoryImplDecl = 19, 1359 /** \brief A typedef */ 1360 CXCursor_TypedefDecl = 20, 1361 /** \brief A C++ class method. */ 1362 CXCursor_CXXMethod = 21, 1363 /** \brief A C++ namespace. */ 1364 CXCursor_Namespace = 22, 1365 /** \brief A linkage specification, e.g. 'extern "C"'. */ 1366 CXCursor_LinkageSpec = 23, 1367 /** \brief A C++ constructor. */ 1368 CXCursor_Constructor = 24, 1369 /** \brief A C++ destructor. */ 1370 CXCursor_Destructor = 25, 1371 /** \brief A C++ conversion function. */ 1372 CXCursor_ConversionFunction = 26, 1373 /** \brief A C++ template type parameter. */ 1374 CXCursor_TemplateTypeParameter = 27, 1375 /** \brief A C++ non-type template parameter. */ 1376 CXCursor_NonTypeTemplateParameter = 28, 1377 /** \brief A C++ template template parameter. */ 1378 CXCursor_TemplateTemplateParameter = 29, 1379 /** \brief A C++ function template. */ 1380 CXCursor_FunctionTemplate = 30, 1381 /** \brief A C++ class template. */ 1382 CXCursor_ClassTemplate = 31, 1383 /** \brief A C++ class template partial specialization. */ 1384 CXCursor_ClassTemplatePartialSpecialization = 32, 1385 /** \brief A C++ namespace alias declaration. */ 1386 CXCursor_NamespaceAlias = 33, 1387 /** \brief A C++ using directive. */ 1388 CXCursor_UsingDirective = 34, 1389 /** \brief A C++ using declaration. */ 1390 CXCursor_UsingDeclaration = 35, 1391 /** \brief A C++ alias declaration */ 1392 CXCursor_TypeAliasDecl = 36, 1393 /** \brief An Objective-C @synthesize definition. */ 1394 CXCursor_ObjCSynthesizeDecl = 37, 1395 /** \brief An Objective-C @dynamic definition. */ 1396 CXCursor_ObjCDynamicDecl = 38, 1397 /** \brief An access specifier. */ 1398 CXCursor_CXXAccessSpecifier = 39, 1399 1400 CXCursor_FirstDecl = CXCursor_UnexposedDecl, 1401 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier, 1402 1403 /* References */ 1404 CXCursor_FirstRef = 40, /* Decl references */ 1405 CXCursor_ObjCSuperClassRef = 40, 1406 CXCursor_ObjCProtocolRef = 41, 1407 CXCursor_ObjCClassRef = 42, 1408 /** 1409 * \brief A reference to a type declaration. 1410 * 1411 * A type reference occurs anywhere where a type is named but not 1412 * declared. For example, given: 1413 * 1414 * \code 1415 * typedef unsigned size_type; 1416 * size_type size; 1417 * \endcode 1418 * 1419 * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 1420 * while the type of the variable "size" is referenced. The cursor 1421 * referenced by the type of size is the typedef for size_type. 1422 */ 1423 CXCursor_TypeRef = 43, 1424 CXCursor_CXXBaseSpecifier = 44, 1425 /** 1426 * \brief A reference to a class template, function template, template 1427 * template parameter, or class template partial specialization. 1428 */ 1429 CXCursor_TemplateRef = 45, 1430 /** 1431 * \brief A reference to a namespace or namespace alias. 1432 */ 1433 CXCursor_NamespaceRef = 46, 1434 /** 1435 * \brief A reference to a member of a struct, union, or class that occurs in 1436 * some non-expression context, e.g., a designated initializer. 1437 */ 1438 CXCursor_MemberRef = 47, 1439 /** 1440 * \brief A reference to a labeled statement. 1441 * 1442 * This cursor kind is used to describe the jump to "start_over" in the 1443 * goto statement in the following example: 1444 * 1445 * \code 1446 * start_over: 1447 * ++counter; 1448 * 1449 * goto start_over; 1450 * \endcode 1451 * 1452 * A label reference cursor refers to a label statement. 1453 */ 1454 CXCursor_LabelRef = 48, 1455 1456 /** 1457 * \brief A reference to a set of overloaded functions or function templates 1458 * that has not yet been resolved to a specific function or function template. 1459 * 1460 * An overloaded declaration reference cursor occurs in C++ templates where 1461 * a dependent name refers to a function. For example: 1462 * 1463 * \code 1464 * template<typename T> void swap(T&, T&); 1465 * 1466 * struct X { ... }; 1467 * void swap(X&, X&); 1468 * 1469 * template<typename T> 1470 * void reverse(T* first, T* last) { 1471 * while (first < last - 1) { 1472 * swap(*first, *--last); 1473 * ++first; 1474 * } 1475 * } 1476 * 1477 * struct Y { }; 1478 * void swap(Y&, Y&); 1479 * \endcode 1480 * 1481 * Here, the identifier "swap" is associated with an overloaded declaration 1482 * reference. In the template definition, "swap" refers to either of the two 1483 * "swap" functions declared above, so both results will be available. At 1484 * instantiation time, "swap" may also refer to other functions found via 1485 * argument-dependent lookup (e.g., the "swap" function at the end of the 1486 * example). 1487 * 1488 * The functions \c clang_getNumOverloadedDecls() and 1489 * \c clang_getOverloadedDecl() can be used to retrieve the definitions 1490 * referenced by this cursor. 1491 */ 1492 CXCursor_OverloadedDeclRef = 49, 1493 1494 CXCursor_LastRef = CXCursor_OverloadedDeclRef, 1495 1496 /* Error conditions */ 1497 CXCursor_FirstInvalid = 70, 1498 CXCursor_InvalidFile = 70, 1499 CXCursor_NoDeclFound = 71, 1500 CXCursor_NotImplemented = 72, 1501 CXCursor_InvalidCode = 73, 1502 CXCursor_LastInvalid = CXCursor_InvalidCode, 1503 1504 /* Expressions */ 1505 CXCursor_FirstExpr = 100, 1506 1507 /** 1508 * \brief An expression whose specific kind is not exposed via this 1509 * interface. 1510 * 1511 * Unexposed expressions have the same operations as any other kind 1512 * of expression; one can extract their location information, 1513 * spelling, children, etc. However, the specific kind of the 1514 * expression is not reported. 1515 */ 1516 CXCursor_UnexposedExpr = 100, 1517 1518 /** 1519 * \brief An expression that refers to some value declaration, such 1520 * as a function, varible, or enumerator. 1521 */ 1522 CXCursor_DeclRefExpr = 101, 1523 1524 /** 1525 * \brief An expression that refers to a member of a struct, union, 1526 * class, Objective-C class, etc. 1527 */ 1528 CXCursor_MemberRefExpr = 102, 1529 1530 /** \brief An expression that calls a function. */ 1531 CXCursor_CallExpr = 103, 1532 1533 /** \brief An expression that sends a message to an Objective-C 1534 object or class. */ 1535 CXCursor_ObjCMessageExpr = 104, 1536 1537 /** \brief An expression that represents a block literal. */ 1538 CXCursor_BlockExpr = 105, 1539 1540 /** \brief An integer literal. 1541 */ 1542 CXCursor_IntegerLiteral = 106, 1543 1544 /** \brief A floating point number literal. 1545 */ 1546 CXCursor_FloatingLiteral = 107, 1547 1548 /** \brief An imaginary number literal. 1549 */ 1550 CXCursor_ImaginaryLiteral = 108, 1551 1552 /** \brief A string literal. 1553 */ 1554 CXCursor_StringLiteral = 109, 1555 1556 /** \brief A character literal. 1557 */ 1558 CXCursor_CharacterLiteral = 110, 1559 1560 /** \brief A parenthesized expression, e.g. "(1)". 1561 * 1562 * This AST node is only formed if full location information is requested. 1563 */ 1564 CXCursor_ParenExpr = 111, 1565 1566 /** \brief This represents the unary-expression's (except sizeof and 1567 * alignof). 1568 */ 1569 CXCursor_UnaryOperator = 112, 1570 1571 /** \brief [C99 6.5.2.1] Array Subscripting. 1572 */ 1573 CXCursor_ArraySubscriptExpr = 113, 1574 1575 /** \brief A builtin binary operation expression such as "x + y" or 1576 * "x <= y". 1577 */ 1578 CXCursor_BinaryOperator = 114, 1579 1580 /** \brief Compound assignment such as "+=". 1581 */ 1582 CXCursor_CompoundAssignOperator = 115, 1583 1584 /** \brief The ?: ternary operator. 1585 */ 1586 CXCursor_ConditionalOperator = 116, 1587 1588 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++ 1589 * (C++ [expr.cast]), which uses the syntax (Type)expr. 1590 * 1591 * For example: (int)f. 1592 */ 1593 CXCursor_CStyleCastExpr = 117, 1594 1595 /** \brief [C99 6.5.2.5] 1596 */ 1597 CXCursor_CompoundLiteralExpr = 118, 1598 1599 /** \brief Describes an C or C++ initializer list. 1600 */ 1601 CXCursor_InitListExpr = 119, 1602 1603 /** \brief The GNU address of label extension, representing &&label. 1604 */ 1605 CXCursor_AddrLabelExpr = 120, 1606 1607 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;}) 1608 */ 1609 CXCursor_StmtExpr = 121, 1610 1611 /** \brief Represents a C1X generic selection. 1612 */ 1613 CXCursor_GenericSelectionExpr = 122, 1614 1615 /** \brief Implements the GNU __null extension, which is a name for a null 1616 * pointer constant that has integral type (e.g., int or long) and is the same 1617 * size and alignment as a pointer. 1618 * 1619 * The __null extension is typically only used by system headers, which define 1620 * NULL as __null in C++ rather than using 0 (which is an integer that may not 1621 * match the size of a pointer). 1622 */ 1623 CXCursor_GNUNullExpr = 123, 1624 1625 /** \brief C++'s static_cast<> expression. 1626 */ 1627 CXCursor_CXXStaticCastExpr = 124, 1628 1629 /** \brief C++'s dynamic_cast<> expression. 1630 */ 1631 CXCursor_CXXDynamicCastExpr = 125, 1632 1633 /** \brief C++'s reinterpret_cast<> expression. 1634 */ 1635 CXCursor_CXXReinterpretCastExpr = 126, 1636 1637 /** \brief C++'s const_cast<> expression. 1638 */ 1639 CXCursor_CXXConstCastExpr = 127, 1640 1641 /** \brief Represents an explicit C++ type conversion that uses "functional" 1642 * notion (C++ [expr.type.conv]). 1643 * 1644 * Example: 1645 * \code 1646 * x = int(0.5); 1647 * \endcode 1648 */ 1649 CXCursor_CXXFunctionalCastExpr = 128, 1650 1651 /** \brief A C++ typeid expression (C++ [expr.typeid]). 1652 */ 1653 CXCursor_CXXTypeidExpr = 129, 1654 1655 /** \brief [C++ 2.13.5] C++ Boolean Literal. 1656 */ 1657 CXCursor_CXXBoolLiteralExpr = 130, 1658 1659 /** \brief [C++0x 2.14.7] C++ Pointer Literal. 1660 */ 1661 CXCursor_CXXNullPtrLiteralExpr = 131, 1662 1663 /** \brief Represents the "this" expression in C++ 1664 */ 1665 CXCursor_CXXThisExpr = 132, 1666 1667 /** \brief [C++ 15] C++ Throw Expression. 1668 * 1669 * This handles 'throw' and 'throw' assignment-expression. When 1670 * assignment-expression isn't present, Op will be null. 1671 */ 1672 CXCursor_CXXThrowExpr = 133, 1673 1674 /** \brief A new expression for memory allocation and constructor calls, e.g: 1675 * "new CXXNewExpr(foo)". 1676 */ 1677 CXCursor_CXXNewExpr = 134, 1678 1679 /** \brief A delete expression for memory deallocation and destructor calls, 1680 * e.g. "delete[] pArray". 1681 */ 1682 CXCursor_CXXDeleteExpr = 135, 1683 1684 /** \brief A unary expression. 1685 */ 1686 CXCursor_UnaryExpr = 136, 1687 1688 /** \brief An Objective-C string literal i.e. @"foo". 1689 */ 1690 CXCursor_ObjCStringLiteral = 137, 1691 1692 /** \brief An Objective-C @encode expression. 1693 */ 1694 CXCursor_ObjCEncodeExpr = 138, 1695 1696 /** \brief An Objective-C @selector expression. 1697 */ 1698 CXCursor_ObjCSelectorExpr = 139, 1699 1700 /** \brief An Objective-C @protocol expression. 1701 */ 1702 CXCursor_ObjCProtocolExpr = 140, 1703 1704 /** \brief An Objective-C "bridged" cast expression, which casts between 1705 * Objective-C pointers and C pointers, transferring ownership in the process. 1706 * 1707 * \code 1708 * NSString *str = (__bridge_transfer NSString *)CFCreateString(); 1709 * \endcode 1710 */ 1711 CXCursor_ObjCBridgedCastExpr = 141, 1712 1713 /** \brief Represents a C++0x pack expansion that produces a sequence of 1714 * expressions. 1715 * 1716 * A pack expansion expression contains a pattern (which itself is an 1717 * expression) followed by an ellipsis. For example: 1718 * 1719 * \code 1720 * template<typename F, typename ...Types> 1721 * void forward(F f, Types &&...args) { 1722 * f(static_cast<Types&&>(args)...); 1723 * } 1724 * \endcode 1725 */ 1726 CXCursor_PackExpansionExpr = 142, 1727 1728 /** \brief Represents an expression that computes the length of a parameter 1729 * pack. 1730 * 1731 * \code 1732 * template<typename ...Types> 1733 * struct count { 1734 * static const unsigned value = sizeof...(Types); 1735 * }; 1736 * \endcode 1737 */ 1738 CXCursor_SizeOfPackExpr = 143, 1739 1740 CXCursor_LastExpr = CXCursor_SizeOfPackExpr, 1741 1742 /* Statements */ 1743 CXCursor_FirstStmt = 200, 1744 /** 1745 * \brief A statement whose specific kind is not exposed via this 1746 * interface. 1747 * 1748 * Unexposed statements have the same operations as any other kind of 1749 * statement; one can extract their location information, spelling, 1750 * children, etc. However, the specific kind of the statement is not 1751 * reported. 1752 */ 1753 CXCursor_UnexposedStmt = 200, 1754 1755 /** \brief A labelled statement in a function. 1756 * 1757 * This cursor kind is used to describe the "start_over:" label statement in 1758 * the following example: 1759 * 1760 * \code 1761 * start_over: 1762 * ++counter; 1763 * \endcode 1764 * 1765 */ 1766 CXCursor_LabelStmt = 201, 1767 1768 /** \brief A group of statements like { stmt stmt }. 1769 * 1770 * This cursor kind is used to describe compound statements, e.g. function 1771 * bodies. 1772 */ 1773 CXCursor_CompoundStmt = 202, 1774 1775 /** \brief A case statment. 1776 */ 1777 CXCursor_CaseStmt = 203, 1778 1779 /** \brief A default statement. 1780 */ 1781 CXCursor_DefaultStmt = 204, 1782 1783 /** \brief An if statement 1784 */ 1785 CXCursor_IfStmt = 205, 1786 1787 /** \brief A switch statement. 1788 */ 1789 CXCursor_SwitchStmt = 206, 1790 1791 /** \brief A while statement. 1792 */ 1793 CXCursor_WhileStmt = 207, 1794 1795 /** \brief A do statement. 1796 */ 1797 CXCursor_DoStmt = 208, 1798 1799 /** \brief A for statement. 1800 */ 1801 CXCursor_ForStmt = 209, 1802 1803 /** \brief A goto statement. 1804 */ 1805 CXCursor_GotoStmt = 210, 1806 1807 /** \brief An indirect goto statement. 1808 */ 1809 CXCursor_IndirectGotoStmt = 211, 1810 1811 /** \brief A continue statement. 1812 */ 1813 CXCursor_ContinueStmt = 212, 1814 1815 /** \brief A break statement. 1816 */ 1817 CXCursor_BreakStmt = 213, 1818 1819 /** \brief A return statement. 1820 */ 1821 CXCursor_ReturnStmt = 214, 1822 1823 /** \brief A GNU inline assembly statement extension. 1824 */ 1825 CXCursor_AsmStmt = 215, 1826 1827 /** \brief Objective-C's overall @try-@catch-@finally statement. 1828 */ 1829 CXCursor_ObjCAtTryStmt = 216, 1830 1831 /** \brief Objective-C's @catch statement. 1832 */ 1833 CXCursor_ObjCAtCatchStmt = 217, 1834 1835 /** \brief Objective-C's @finally statement. 1836 */ 1837 CXCursor_ObjCAtFinallyStmt = 218, 1838 1839 /** \brief Objective-C's @throw statement. 1840 */ 1841 CXCursor_ObjCAtThrowStmt = 219, 1842 1843 /** \brief Objective-C's @synchronized statement. 1844 */ 1845 CXCursor_ObjCAtSynchronizedStmt = 220, 1846 1847 /** \brief Objective-C's autorelease pool statement. 1848 */ 1849 CXCursor_ObjCAutoreleasePoolStmt = 221, 1850 1851 /** \brief Objective-C's collection statement. 1852 */ 1853 CXCursor_ObjCForCollectionStmt = 222, 1854 1855 /** \brief C++'s catch statement. 1856 */ 1857 CXCursor_CXXCatchStmt = 223, 1858 1859 /** \brief C++'s try statement. 1860 */ 1861 CXCursor_CXXTryStmt = 224, 1862 1863 /** \brief C++'s for (* : *) statement. 1864 */ 1865 CXCursor_CXXForRangeStmt = 225, 1866 1867 /** \brief Windows Structured Exception Handling's try statement. 1868 */ 1869 CXCursor_SEHTryStmt = 226, 1870 1871 /** \brief Windows Structured Exception Handling's except statement. 1872 */ 1873 CXCursor_SEHExceptStmt = 227, 1874 1875 /** \brief Windows Structured Exception Handling's finally statement. 1876 */ 1877 CXCursor_SEHFinallyStmt = 228, 1878 1879 /** \brief The null satement ";": C99 6.8.3p3. 1880 * 1881 * This cursor kind is used to describe the null statement. 1882 */ 1883 CXCursor_NullStmt = 230, 1884 1885 /** \brief Adaptor class for mixing declarations with statements and 1886 * expressions. 1887 */ 1888 CXCursor_DeclStmt = 231, 1889 1890 CXCursor_LastStmt = CXCursor_DeclStmt, 1891 1892 /** 1893 * \brief Cursor that represents the translation unit itself. 1894 * 1895 * The translation unit cursor exists primarily to act as the root 1896 * cursor for traversing the contents of a translation unit. 1897 */ 1898 CXCursor_TranslationUnit = 300, 1899 1900 /* Attributes */ 1901 CXCursor_FirstAttr = 400, 1902 /** 1903 * \brief An attribute whose specific kind is not exposed via this 1904 * interface. 1905 */ 1906 CXCursor_UnexposedAttr = 400, 1907 1908 CXCursor_IBActionAttr = 401, 1909 CXCursor_IBOutletAttr = 402, 1910 CXCursor_IBOutletCollectionAttr = 403, 1911 CXCursor_CXXFinalAttr = 404, 1912 CXCursor_CXXOverrideAttr = 405, 1913 CXCursor_AnnotateAttr = 406, 1914 CXCursor_LastAttr = CXCursor_AnnotateAttr, 1915 1916 /* Preprocessing */ 1917 CXCursor_PreprocessingDirective = 500, 1918 CXCursor_MacroDefinition = 501, 1919 CXCursor_MacroExpansion = 502, 1920 CXCursor_MacroInstantiation = CXCursor_MacroExpansion, 1921 CXCursor_InclusionDirective = 503, 1922 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, 1923 CXCursor_LastPreprocessing = CXCursor_InclusionDirective 1924}; 1925 1926/** 1927 * \brief A cursor representing some element in the abstract syntax tree for 1928 * a translation unit. 1929 * 1930 * The cursor abstraction unifies the different kinds of entities in a 1931 * program--declaration, statements, expressions, references to declarations, 1932 * etc.--under a single "cursor" abstraction with a common set of operations. 1933 * Common operation for a cursor include: getting the physical location in 1934 * a source file where the cursor points, getting the name associated with a 1935 * cursor, and retrieving cursors for any child nodes of a particular cursor. 1936 * 1937 * Cursors can be produced in two specific ways. 1938 * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 1939 * from which one can use clang_visitChildren() to explore the rest of the 1940 * translation unit. clang_getCursor() maps from a physical source location 1941 * to the entity that resides at that location, allowing one to map from the 1942 * source code into the AST. 1943 */ 1944typedef struct { 1945 enum CXCursorKind kind; 1946 int xdata; 1947 void *data[3]; 1948} CXCursor; 1949 1950/** 1951 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 1952 * 1953 * @{ 1954 */ 1955 1956/** 1957 * \brief Retrieve the NULL cursor, which represents no entity. 1958 */ 1959CINDEX_LINKAGE CXCursor clang_getNullCursor(void); 1960 1961/** 1962 * \brief Retrieve the cursor that represents the given translation unit. 1963 * 1964 * The translation unit cursor can be used to start traversing the 1965 * various declarations within the given translation unit. 1966 */ 1967CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 1968 1969/** 1970 * \brief Determine whether two cursors are equivalent. 1971 */ 1972CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); 1973 1974/** 1975 * \brief Returns non-zero if \arg cursor is null. 1976 */ 1977int clang_Cursor_isNull(CXCursor); 1978 1979/** 1980 * \brief Compute a hash value for the given cursor. 1981 */ 1982CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor); 1983 1984/** 1985 * \brief Retrieve the kind of the given cursor. 1986 */ 1987CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); 1988 1989/** 1990 * \brief Determine whether the given cursor kind represents a declaration. 1991 */ 1992CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); 1993 1994/** 1995 * \brief Determine whether the given cursor kind represents a simple 1996 * reference. 1997 * 1998 * Note that other kinds of cursors (such as expressions) can also refer to 1999 * other cursors. Use clang_getCursorReferenced() to determine whether a 2000 * particular cursor refers to another entity. 2001 */ 2002CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); 2003 2004/** 2005 * \brief Determine whether the given cursor kind represents an expression. 2006 */ 2007CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); 2008 2009/** 2010 * \brief Determine whether the given cursor kind represents a statement. 2011 */ 2012CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); 2013 2014/** 2015 * \brief Determine whether the given cursor kind represents an attribute. 2016 */ 2017CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind); 2018 2019/** 2020 * \brief Determine whether the given cursor kind represents an invalid 2021 * cursor. 2022 */ 2023CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); 2024 2025/** 2026 * \brief Determine whether the given cursor kind represents a translation 2027 * unit. 2028 */ 2029CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); 2030 2031/*** 2032 * \brief Determine whether the given cursor represents a preprocessing 2033 * element, such as a preprocessor directive or macro instantiation. 2034 */ 2035CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); 2036 2037/*** 2038 * \brief Determine whether the given cursor represents a currently 2039 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). 2040 */ 2041CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); 2042 2043/** 2044 * \brief Describe the linkage of the entity referred to by a cursor. 2045 */ 2046enum CXLinkageKind { 2047 /** \brief This value indicates that no linkage information is available 2048 * for a provided CXCursor. */ 2049 CXLinkage_Invalid, 2050 /** 2051 * \brief This is the linkage for variables, parameters, and so on that 2052 * have automatic storage. This covers normal (non-extern) local variables. 2053 */ 2054 CXLinkage_NoLinkage, 2055 /** \brief This is the linkage for static variables and static functions. */ 2056 CXLinkage_Internal, 2057 /** \brief This is the linkage for entities with external linkage that live 2058 * in C++ anonymous namespaces.*/ 2059 CXLinkage_UniqueExternal, 2060 /** \brief This is the linkage for entities with true, external linkage. */ 2061 CXLinkage_External 2062}; 2063 2064/** 2065 * \brief Determine the linkage of the entity referred to by a given cursor. 2066 */ 2067CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); 2068 2069/** 2070 * \brief Determine the availability of the entity that this cursor refers to. 2071 * 2072 * \param cursor The cursor to query. 2073 * 2074 * \returns The availability of the cursor. 2075 */ 2076CINDEX_LINKAGE enum CXAvailabilityKind 2077clang_getCursorAvailability(CXCursor cursor); 2078 2079/** 2080 * \brief Describe the "language" of the entity referred to by a cursor. 2081 */ 2082CINDEX_LINKAGE enum CXLanguageKind { 2083 CXLanguage_Invalid = 0, 2084 CXLanguage_C, 2085 CXLanguage_ObjC, 2086 CXLanguage_CPlusPlus 2087}; 2088 2089/** 2090 * \brief Determine the "language" of the entity referred to by a given cursor. 2091 */ 2092CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); 2093 2094/** 2095 * \brief Returns the translation unit that a cursor originated from. 2096 */ 2097CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor); 2098 2099 2100/** 2101 * \brief A fast container representing a set of CXCursors. 2102 */ 2103typedef struct CXCursorSetImpl *CXCursorSet; 2104 2105/** 2106 * \brief Creates an empty CXCursorSet. 2107 */ 2108CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(); 2109 2110/** 2111 * \brief Disposes a CXCursorSet and releases its associated memory. 2112 */ 2113CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset); 2114 2115/** 2116 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor. 2117 * 2118 * \returns non-zero if the set contains the specified cursor. 2119*/ 2120CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset, 2121 CXCursor cursor); 2122 2123/** 2124 * \brief Inserts a CXCursor into a CXCursorSet. 2125 * 2126 * \returns zero if the CXCursor was already in the set, and non-zero otherwise. 2127*/ 2128CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset, 2129 CXCursor cursor); 2130 2131/** 2132 * \brief Determine the semantic parent of the given cursor. 2133 * 2134 * The semantic parent of a cursor is the cursor that semantically contains 2135 * the given \p cursor. For many declarations, the lexical and semantic parents 2136 * are equivalent (the lexical parent is returned by 2137 * \c clang_getCursorLexicalParent()). They diverge when declarations or 2138 * definitions are provided out-of-line. For example: 2139 * 2140 * \code 2141 * class C { 2142 * void f(); 2143 * }; 2144 * 2145 * void C::f() { } 2146 * \endcode 2147 * 2148 * In the out-of-line definition of \c C::f, the semantic parent is the 2149 * the class \c C, of which this function is a member. The lexical parent is 2150 * the place where the declaration actually occurs in the source code; in this 2151 * case, the definition occurs in the translation unit. In general, the 2152 * lexical parent for a given entity can change without affecting the semantics 2153 * of the program, and the lexical parent of different declarations of the 2154 * same entity may be different. Changing the semantic parent of a declaration, 2155 * on the other hand, can have a major impact on semantics, and redeclarations 2156 * of a particular entity should all have the same semantic context. 2157 * 2158 * In the example above, both declarations of \c C::f have \c C as their 2159 * semantic context, while the lexical context of the first \c C::f is \c C 2160 * and the lexical context of the second \c C::f is the translation unit. 2161 * 2162 * For global declarations, the semantic parent is the translation unit. 2163 */ 2164CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor); 2165 2166/** 2167 * \brief Determine the lexical parent of the given cursor. 2168 * 2169 * The lexical parent of a cursor is the cursor in which the given \p cursor 2170 * was actually written. For many declarations, the lexical and semantic parents 2171 * are equivalent (the semantic parent is returned by 2172 * \c clang_getCursorSemanticParent()). They diverge when declarations or 2173 * definitions are provided out-of-line. For example: 2174 * 2175 * \code 2176 * class C { 2177 * void f(); 2178 * }; 2179 * 2180 * void C::f() { } 2181 * \endcode 2182 * 2183 * In the out-of-line definition of \c C::f, the semantic parent is the 2184 * the class \c C, of which this function is a member. The lexical parent is 2185 * the place where the declaration actually occurs in the source code; in this 2186 * case, the definition occurs in the translation unit. In general, the 2187 * lexical parent for a given entity can change without affecting the semantics 2188 * of the program, and the lexical parent of different declarations of the 2189 * same entity may be different. Changing the semantic parent of a declaration, 2190 * on the other hand, can have a major impact on semantics, and redeclarations 2191 * of a particular entity should all have the same semantic context. 2192 * 2193 * In the example above, both declarations of \c C::f have \c C as their 2194 * semantic context, while the lexical context of the first \c C::f is \c C 2195 * and the lexical context of the second \c C::f is the translation unit. 2196 * 2197 * For declarations written in the global scope, the lexical parent is 2198 * the translation unit. 2199 */ 2200CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor); 2201 2202/** 2203 * \brief Determine the set of methods that are overridden by the given 2204 * method. 2205 * 2206 * In both Objective-C and C++, a method (aka virtual member function, 2207 * in C++) can override a virtual method in a base class. For 2208 * Objective-C, a method is said to override any method in the class's 2209 * interface (if we're coming from an implementation), its protocols, 2210 * or its categories, that has the same selector and is of the same 2211 * kind (class or instance). If no such method exists, the search 2212 * continues to the class's superclass, its protocols, and its 2213 * categories, and so on. 2214 * 2215 * For C++, a virtual member function overrides any virtual member 2216 * function with the same signature that occurs in its base 2217 * classes. With multiple inheritance, a virtual member function can 2218 * override several virtual member functions coming from different 2219 * base classes. 2220 * 2221 * In all cases, this function determines the immediate overridden 2222 * method, rather than all of the overridden methods. For example, if 2223 * a method is originally declared in a class A, then overridden in B 2224 * (which in inherits from A) and also in C (which inherited from B), 2225 * then the only overridden method returned from this function when 2226 * invoked on C's method will be B's method. The client may then 2227 * invoke this function again, given the previously-found overridden 2228 * methods, to map out the complete method-override set. 2229 * 2230 * \param cursor A cursor representing an Objective-C or C++ 2231 * method. This routine will compute the set of methods that this 2232 * method overrides. 2233 * 2234 * \param overridden A pointer whose pointee will be replaced with a 2235 * pointer to an array of cursors, representing the set of overridden 2236 * methods. If there are no overridden methods, the pointee will be 2237 * set to NULL. The pointee must be freed via a call to 2238 * \c clang_disposeOverriddenCursors(). 2239 * 2240 * \param num_overridden A pointer to the number of overridden 2241 * functions, will be set to the number of overridden functions in the 2242 * array pointed to by \p overridden. 2243 */ 2244CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor, 2245 CXCursor **overridden, 2246 unsigned *num_overridden); 2247 2248/** 2249 * \brief Free the set of overridden cursors returned by \c 2250 * clang_getOverriddenCursors(). 2251 */ 2252CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden); 2253 2254/** 2255 * \brief Retrieve the file that is included by the given inclusion directive 2256 * cursor. 2257 */ 2258CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor); 2259 2260/** 2261 * @} 2262 */ 2263 2264/** 2265 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 2266 * 2267 * Cursors represent a location within the Abstract Syntax Tree (AST). These 2268 * routines help map between cursors and the physical locations where the 2269 * described entities occur in the source code. The mapping is provided in 2270 * both directions, so one can map from source code to the AST and back. 2271 * 2272 * @{ 2273 */ 2274 2275/** 2276 * \brief Map a source location to the cursor that describes the entity at that 2277 * location in the source code. 2278 * 2279 * clang_getCursor() maps an arbitrary source location within a translation 2280 * unit down to the most specific cursor that describes the entity at that 2281 * location. For example, given an expression \c x + y, invoking 2282 * clang_getCursor() with a source location pointing to "x" will return the 2283 * cursor for "x"; similarly for "y". If the cursor points anywhere between 2284 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 2285 * will return a cursor referring to the "+" expression. 2286 * 2287 * \returns a cursor representing the entity at the given source location, or 2288 * a NULL cursor if no such entity can be found. 2289 */ 2290CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 2291 2292/** 2293 * \brief Retrieve the physical location of the source constructor referenced 2294 * by the given cursor. 2295 * 2296 * The location of a declaration is typically the location of the name of that 2297 * declaration, where the name of that declaration would occur if it is 2298 * unnamed, or some keyword that introduces that particular declaration. 2299 * The location of a reference is where that reference occurs within the 2300 * source code. 2301 */ 2302CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); 2303 2304/** 2305 * \brief Retrieve the physical extent of the source construct referenced by 2306 * the given cursor. 2307 * 2308 * The extent of a cursor starts with the file/line/column pointing at the 2309 * first character within the source construct that the cursor refers to and 2310 * ends with the last character withinin that source construct. For a 2311 * declaration, the extent covers the declaration itself. For a reference, 2312 * the extent covers the location of the reference (e.g., where the referenced 2313 * entity was actually used). 2314 */ 2315CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); 2316 2317/** 2318 * @} 2319 */ 2320 2321/** 2322 * \defgroup CINDEX_TYPES Type information for CXCursors 2323 * 2324 * @{ 2325 */ 2326 2327/** 2328 * \brief Describes the kind of type 2329 */ 2330enum CXTypeKind { 2331 /** 2332 * \brief Reprents an invalid type (e.g., where no type is available). 2333 */ 2334 CXType_Invalid = 0, 2335 2336 /** 2337 * \brief A type whose specific kind is not exposed via this 2338 * interface. 2339 */ 2340 CXType_Unexposed = 1, 2341 2342 /* Builtin types */ 2343 CXType_Void = 2, 2344 CXType_Bool = 3, 2345 CXType_Char_U = 4, 2346 CXType_UChar = 5, 2347 CXType_Char16 = 6, 2348 CXType_Char32 = 7, 2349 CXType_UShort = 8, 2350 CXType_UInt = 9, 2351 CXType_ULong = 10, 2352 CXType_ULongLong = 11, 2353 CXType_UInt128 = 12, 2354 CXType_Char_S = 13, 2355 CXType_SChar = 14, 2356 CXType_WChar = 15, 2357 CXType_Short = 16, 2358 CXType_Int = 17, 2359 CXType_Long = 18, 2360 CXType_LongLong = 19, 2361 CXType_Int128 = 20, 2362 CXType_Float = 21, 2363 CXType_Double = 22, 2364 CXType_LongDouble = 23, 2365 CXType_NullPtr = 24, 2366 CXType_Overload = 25, 2367 CXType_Dependent = 26, 2368 CXType_ObjCId = 27, 2369 CXType_ObjCClass = 28, 2370 CXType_ObjCSel = 29, 2371 CXType_FirstBuiltin = CXType_Void, 2372 CXType_LastBuiltin = CXType_ObjCSel, 2373 2374 CXType_Complex = 100, 2375 CXType_Pointer = 101, 2376 CXType_BlockPointer = 102, 2377 CXType_LValueReference = 103, 2378 CXType_RValueReference = 104, 2379 CXType_Record = 105, 2380 CXType_Enum = 106, 2381 CXType_Typedef = 107, 2382 CXType_ObjCInterface = 108, 2383 CXType_ObjCObjectPointer = 109, 2384 CXType_FunctionNoProto = 110, 2385 CXType_FunctionProto = 111, 2386 CXType_ConstantArray = 112 2387}; 2388 2389/** 2390 * \brief The type of an element in the abstract syntax tree. 2391 * 2392 */ 2393typedef struct { 2394 enum CXTypeKind kind; 2395 void *data[2]; 2396} CXType; 2397 2398/** 2399 * \brief Retrieve the type of a CXCursor (if any). 2400 */ 2401CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); 2402 2403/** 2404 * \determine Determine whether two CXTypes represent the same type. 2405 * 2406 * \returns non-zero if the CXTypes represent the same type and 2407 zero otherwise. 2408 */ 2409CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); 2410 2411/** 2412 * \brief Return the canonical type for a CXType. 2413 * 2414 * Clang's type system explicitly models typedefs and all the ways 2415 * a specific type can be represented. The canonical type is the underlying 2416 * type with all the "sugar" removed. For example, if 'T' is a typedef 2417 * for 'int', the canonical type for 'T' would be 'int'. 2418 */ 2419CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); 2420 2421/** 2422 * \determine Determine whether a CXType has the "const" qualifier set, 2423 * without looking through typedefs that may have added "const" at a different level. 2424 */ 2425CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T); 2426 2427/** 2428 * \determine Determine whether a CXType has the "volatile" qualifier set, 2429 * without looking through typedefs that may have added "volatile" at a different level. 2430 */ 2431CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T); 2432 2433/** 2434 * \determine Determine whether a CXType has the "restrict" qualifier set, 2435 * without looking through typedefs that may have added "restrict" at a different level. 2436 */ 2437CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T); 2438 2439/** 2440 * \brief For pointer types, returns the type of the pointee. 2441 * 2442 */ 2443CINDEX_LINKAGE CXType clang_getPointeeType(CXType T); 2444 2445/** 2446 * \brief Return the cursor for the declaration of the given type. 2447 */ 2448CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); 2449 2450/** 2451 * Returns the Objective-C type encoding for the specified declaration. 2452 */ 2453CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C); 2454 2455/** 2456 * \brief Retrieve the spelling of a given CXTypeKind. 2457 */ 2458CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); 2459 2460/** 2461 * \brief Retrieve the result type associated with a function type. 2462 */ 2463CINDEX_LINKAGE CXType clang_getResultType(CXType T); 2464 2465/** 2466 * \brief Retrieve the result type associated with a given cursor. This only 2467 * returns a valid type of the cursor refers to a function or method. 2468 */ 2469CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); 2470 2471/** 2472 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 2473 * otherwise. 2474 */ 2475CINDEX_LINKAGE unsigned clang_isPODType(CXType T); 2476 2477/** 2478 * \brief Return the element type of an array type. 2479 * 2480 * If a non-array type is passed in, an invalid type is returned. 2481 */ 2482CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T); 2483 2484/** 2485 * \brief Return the the array size of a constant array. 2486 * 2487 * If a non-array type is passed in, -1 is returned. 2488 */ 2489CINDEX_LINKAGE long long clang_getArraySize(CXType T); 2490 2491/** 2492 * \brief Returns 1 if the base class specified by the cursor with kind 2493 * CX_CXXBaseSpecifier is virtual. 2494 */ 2495CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor); 2496 2497/** 2498 * \brief Represents the C++ access control level to a base class for a 2499 * cursor with kind CX_CXXBaseSpecifier. 2500 */ 2501enum CX_CXXAccessSpecifier { 2502 CX_CXXInvalidAccessSpecifier, 2503 CX_CXXPublic, 2504 CX_CXXProtected, 2505 CX_CXXPrivate 2506}; 2507 2508/** 2509 * \brief Returns the access control level for the C++ base specifier 2510 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or 2511 * CXCursor_AccessSpecifier. 2512 */ 2513CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor); 2514 2515/** 2516 * \brief Determine the number of overloaded declarations referenced by a 2517 * \c CXCursor_OverloadedDeclRef cursor. 2518 * 2519 * \param cursor The cursor whose overloaded declarations are being queried. 2520 * 2521 * \returns The number of overloaded declarations referenced by \c cursor. If it 2522 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0. 2523 */ 2524CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor); 2525 2526/** 2527 * \brief Retrieve a cursor for one of the overloaded declarations referenced 2528 * by a \c CXCursor_OverloadedDeclRef cursor. 2529 * 2530 * \param cursor The cursor whose overloaded declarations are being queried. 2531 * 2532 * \param index The zero-based index into the set of overloaded declarations in 2533 * the cursor. 2534 * 2535 * \returns A cursor representing the declaration referenced by the given 2536 * \c cursor at the specified \c index. If the cursor does not have an 2537 * associated set of overloaded declarations, or if the index is out of bounds, 2538 * returns \c clang_getNullCursor(); 2539 */ 2540CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor, 2541 unsigned index); 2542 2543/** 2544 * @} 2545 */ 2546 2547/** 2548 * \defgroup CINDEX_ATTRIBUTES Information for attributes 2549 * 2550 * @{ 2551 */ 2552 2553 2554/** 2555 * \brief For cursors representing an iboutletcollection attribute, 2556 * this function returns the collection element type. 2557 * 2558 */ 2559CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor); 2560 2561/** 2562 * @} 2563 */ 2564 2565/** 2566 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 2567 * 2568 * These routines provide the ability to traverse the abstract syntax tree 2569 * using cursors. 2570 * 2571 * @{ 2572 */ 2573 2574/** 2575 * \brief Describes how the traversal of the children of a particular 2576 * cursor should proceed after visiting a particular child cursor. 2577 * 2578 * A value of this enumeration type should be returned by each 2579 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 2580 */ 2581enum CXChildVisitResult { 2582 /** 2583 * \brief Terminates the cursor traversal. 2584 */ 2585 CXChildVisit_Break, 2586 /** 2587 * \brief Continues the cursor traversal with the next sibling of 2588 * the cursor just visited, without visiting its children. 2589 */ 2590 CXChildVisit_Continue, 2591 /** 2592 * \brief Recursively traverse the children of this cursor, using 2593 * the same visitor and client data. 2594 */ 2595 CXChildVisit_Recurse 2596}; 2597 2598/** 2599 * \brief Visitor invoked for each cursor found by a traversal. 2600 * 2601 * This visitor function will be invoked for each cursor found by 2602 * clang_visitCursorChildren(). Its first argument is the cursor being 2603 * visited, its second argument is the parent visitor for that cursor, 2604 * and its third argument is the client data provided to 2605 * clang_visitCursorChildren(). 2606 * 2607 * The visitor should return one of the \c CXChildVisitResult values 2608 * to direct clang_visitCursorChildren(). 2609 */ 2610typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, 2611 CXCursor parent, 2612 CXClientData client_data); 2613 2614/** 2615 * \brief Visit the children of a particular cursor. 2616 * 2617 * This function visits all the direct children of the given cursor, 2618 * invoking the given \p visitor function with the cursors of each 2619 * visited child. The traversal may be recursive, if the visitor returns 2620 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 2621 * the visitor returns \c CXChildVisit_Break. 2622 * 2623 * \param parent the cursor whose child may be visited. All kinds of 2624 * cursors can be visited, including invalid cursors (which, by 2625 * definition, have no children). 2626 * 2627 * \param visitor the visitor function that will be invoked for each 2628 * child of \p parent. 2629 * 2630 * \param client_data pointer data supplied by the client, which will 2631 * be passed to the visitor each time it is invoked. 2632 * 2633 * \returns a non-zero value if the traversal was terminated 2634 * prematurely by the visitor returning \c CXChildVisit_Break. 2635 */ 2636CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, 2637 CXCursorVisitor visitor, 2638 CXClientData client_data); 2639#ifdef __has_feature 2640# if __has_feature(blocks) 2641/** 2642 * \brief Visitor invoked for each cursor found by a traversal. 2643 * 2644 * This visitor block will be invoked for each cursor found by 2645 * clang_visitChildrenWithBlock(). Its first argument is the cursor being 2646 * visited, its second argument is the parent visitor for that cursor. 2647 * 2648 * The visitor should return one of the \c CXChildVisitResult values 2649 * to direct clang_visitChildrenWithBlock(). 2650 */ 2651typedef enum CXChildVisitResult 2652 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent); 2653 2654/** 2655 * Visits the children of a cursor using the specified block. Behaves 2656 * identically to clang_visitChildren() in all other respects. 2657 */ 2658unsigned clang_visitChildrenWithBlock(CXCursor parent, 2659 CXCursorVisitorBlock block); 2660# endif 2661#endif 2662 2663/** 2664 * @} 2665 */ 2666 2667/** 2668 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 2669 * 2670 * These routines provide the ability to determine references within and 2671 * across translation units, by providing the names of the entities referenced 2672 * by cursors, follow reference cursors to the declarations they reference, 2673 * and associate declarations with their definitions. 2674 * 2675 * @{ 2676 */ 2677 2678/** 2679 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 2680 * by the given cursor. 2681 * 2682 * A Unified Symbol Resolution (USR) is a string that identifies a particular 2683 * entity (function, class, variable, etc.) within a program. USRs can be 2684 * compared across translation units to determine, e.g., when references in 2685 * one translation refer to an entity defined in another translation unit. 2686 */ 2687CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); 2688 2689/** 2690 * \brief Construct a USR for a specified Objective-C class. 2691 */ 2692CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); 2693 2694/** 2695 * \brief Construct a USR for a specified Objective-C category. 2696 */ 2697CINDEX_LINKAGE CXString 2698 clang_constructUSR_ObjCCategory(const char *class_name, 2699 const char *category_name); 2700 2701/** 2702 * \brief Construct a USR for a specified Objective-C protocol. 2703 */ 2704CINDEX_LINKAGE CXString 2705 clang_constructUSR_ObjCProtocol(const char *protocol_name); 2706 2707 2708/** 2709 * \brief Construct a USR for a specified Objective-C instance variable and 2710 * the USR for its containing class. 2711 */ 2712CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, 2713 CXString classUSR); 2714 2715/** 2716 * \brief Construct a USR for a specified Objective-C method and 2717 * the USR for its containing class. 2718 */ 2719CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, 2720 unsigned isInstanceMethod, 2721 CXString classUSR); 2722 2723/** 2724 * \brief Construct a USR for a specified Objective-C property and the USR 2725 * for its containing class. 2726 */ 2727CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, 2728 CXString classUSR); 2729 2730/** 2731 * \brief Retrieve a name for the entity referenced by this cursor. 2732 */ 2733CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); 2734 2735/** 2736 * \brief Retrieve the display name for the entity referenced by this cursor. 2737 * 2738 * The display name contains extra information that helps identify the cursor, 2739 * such as the parameters of a function or template or the arguments of a 2740 * class template specialization. 2741 */ 2742CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor); 2743 2744/** \brief For a cursor that is a reference, retrieve a cursor representing the 2745 * entity that it references. 2746 * 2747 * Reference cursors refer to other entities in the AST. For example, an 2748 * Objective-C superclass reference cursor refers to an Objective-C class. 2749 * This function produces the cursor for the Objective-C class from the 2750 * cursor for the superclass reference. If the input cursor is a declaration or 2751 * definition, it returns that declaration or definition unchanged. 2752 * Otherwise, returns the NULL cursor. 2753 */ 2754CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); 2755 2756/** 2757 * \brief For a cursor that is either a reference to or a declaration 2758 * of some entity, retrieve a cursor that describes the definition of 2759 * that entity. 2760 * 2761 * Some entities can be declared multiple times within a translation 2762 * unit, but only one of those declarations can also be a 2763 * definition. For example, given: 2764 * 2765 * \code 2766 * int f(int, int); 2767 * int g(int x, int y) { return f(x, y); } 2768 * int f(int a, int b) { return a + b; } 2769 * int f(int, int); 2770 * \endcode 2771 * 2772 * there are three declarations of the function "f", but only the 2773 * second one is a definition. The clang_getCursorDefinition() 2774 * function will take any cursor pointing to a declaration of "f" 2775 * (the first or fourth lines of the example) or a cursor referenced 2776 * that uses "f" (the call to "f' inside "g") and will return a 2777 * declaration cursor pointing to the definition (the second "f" 2778 * declaration). 2779 * 2780 * If given a cursor for which there is no corresponding definition, 2781 * e.g., because there is no definition of that entity within this 2782 * translation unit, returns a NULL cursor. 2783 */ 2784CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); 2785 2786/** 2787 * \brief Determine whether the declaration pointed to by this cursor 2788 * is also a definition of that entity. 2789 */ 2790CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); 2791 2792/** 2793 * \brief Retrieve the canonical cursor corresponding to the given cursor. 2794 * 2795 * In the C family of languages, many kinds of entities can be declared several 2796 * times within a single translation unit. For example, a structure type can 2797 * be forward-declared (possibly multiple times) and later defined: 2798 * 2799 * \code 2800 * struct X; 2801 * struct X; 2802 * struct X { 2803 * int member; 2804 * }; 2805 * \endcode 2806 * 2807 * The declarations and the definition of \c X are represented by three 2808 * different cursors, all of which are declarations of the same underlying 2809 * entity. One of these cursor is considered the "canonical" cursor, which 2810 * is effectively the representative for the underlying entity. One can 2811 * determine if two cursors are declarations of the same underlying entity by 2812 * comparing their canonical cursors. 2813 * 2814 * \returns The canonical cursor for the entity referred to by the given cursor. 2815 */ 2816CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor); 2817 2818/** 2819 * @} 2820 */ 2821 2822/** 2823 * \defgroup CINDEX_CPP C++ AST introspection 2824 * 2825 * The routines in this group provide access information in the ASTs specific 2826 * to C++ language features. 2827 * 2828 * @{ 2829 */ 2830 2831/** 2832 * \brief Determine if a C++ member function or member function template is 2833 * declared 'static'. 2834 */ 2835CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); 2836 2837/** 2838 * \brief Determine if a C++ member function or member function template is 2839 * explicitly declared 'virtual' or if it overrides a virtual method from 2840 * one of the base classes. 2841 */ 2842CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C); 2843 2844/** 2845 * \brief Given a cursor that represents a template, determine 2846 * the cursor kind of the specializations would be generated by instantiating 2847 * the template. 2848 * 2849 * This routine can be used to determine what flavor of function template, 2850 * class template, or class template partial specialization is stored in the 2851 * cursor. For example, it can describe whether a class template cursor is 2852 * declared with "struct", "class" or "union". 2853 * 2854 * \param C The cursor to query. This cursor should represent a template 2855 * declaration. 2856 * 2857 * \returns The cursor kind of the specializations that would be generated 2858 * by instantiating the template \p C. If \p C is not a template, returns 2859 * \c CXCursor_NoDeclFound. 2860 */ 2861CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C); 2862 2863/** 2864 * \brief Given a cursor that may represent a specialization or instantiation 2865 * of a template, retrieve the cursor that represents the template that it 2866 * specializes or from which it was instantiated. 2867 * 2868 * This routine determines the template involved both for explicit 2869 * specializations of templates and for implicit instantiations of the template, 2870 * both of which are referred to as "specializations". For a class template 2871 * specialization (e.g., \c std::vector<bool>), this routine will return 2872 * either the primary template (\c std::vector) or, if the specialization was 2873 * instantiated from a class template partial specialization, the class template 2874 * partial specialization. For a class template partial specialization and a 2875 * function template specialization (including instantiations), this 2876 * this routine will return the specialized template. 2877 * 2878 * For members of a class template (e.g., member functions, member classes, or 2879 * static data members), returns the specialized or instantiated member. 2880 * Although not strictly "templates" in the C++ language, members of class 2881 * templates have the same notions of specializations and instantiations that 2882 * templates do, so this routine treats them similarly. 2883 * 2884 * \param C A cursor that may be a specialization of a template or a member 2885 * of a template. 2886 * 2887 * \returns If the given cursor is a specialization or instantiation of a 2888 * template or a member thereof, the template or member that it specializes or 2889 * from which it was instantiated. Otherwise, returns a NULL cursor. 2890 */ 2891CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C); 2892 2893/** 2894 * \brief Given a cursor that references something else, return the source range 2895 * covering that reference. 2896 * 2897 * \param C A cursor pointing to a member reference, a declaration reference, or 2898 * an operator call. 2899 * \param NameFlags A bitset with three independent flags: 2900 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and 2901 * CXNameRange_WantSinglePiece. 2902 * \param PieceIndex For contiguous names or when passing the flag 2903 * CXNameRange_WantSinglePiece, only one piece with index 0 is 2904 * available. When the CXNameRange_WantSinglePiece flag is not passed for a 2905 * non-contiguous names, this index can be used to retreive the individual 2906 * pieces of the name. See also CXNameRange_WantSinglePiece. 2907 * 2908 * \returns The piece of the name pointed to by the given cursor. If there is no 2909 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned. 2910 */ 2911CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, 2912 unsigned NameFlags, 2913 unsigned PieceIndex); 2914 2915enum CXNameRefFlags { 2916 /** 2917 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the 2918 * range. 2919 */ 2920 CXNameRange_WantQualifier = 0x1, 2921 2922 /** 2923 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in 2924 * the range. 2925 */ 2926 CXNameRange_WantTemplateArgs = 0x2, 2927 2928 /** 2929 * \brief If the name is non-contiguous, return the full spanning range. 2930 * 2931 * Non-contiguous names occur in Objective-C when a selector with two or more 2932 * parameters is used, or in C++ when using an operator: 2933 * \code 2934 * [object doSomething:here withValue:there]; // ObjC 2935 * return some_vector[1]; // C++ 2936 * \endcode 2937 */ 2938 CXNameRange_WantSinglePiece = 0x4 2939}; 2940 2941/** 2942 * @} 2943 */ 2944 2945/** 2946 * \defgroup CINDEX_LEX Token extraction and manipulation 2947 * 2948 * The routines in this group provide access to the tokens within a 2949 * translation unit, along with a semantic mapping of those tokens to 2950 * their corresponding cursors. 2951 * 2952 * @{ 2953 */ 2954 2955/** 2956 * \brief Describes a kind of token. 2957 */ 2958typedef enum CXTokenKind { 2959 /** 2960 * \brief A token that contains some kind of punctuation. 2961 */ 2962 CXToken_Punctuation, 2963 2964 /** 2965 * \brief A language keyword. 2966 */ 2967 CXToken_Keyword, 2968 2969 /** 2970 * \brief An identifier (that is not a keyword). 2971 */ 2972 CXToken_Identifier, 2973 2974 /** 2975 * \brief A numeric, string, or character literal. 2976 */ 2977 CXToken_Literal, 2978 2979 /** 2980 * \brief A comment. 2981 */ 2982 CXToken_Comment 2983} CXTokenKind; 2984 2985/** 2986 * \brief Describes a single preprocessing token. 2987 */ 2988typedef struct { 2989 unsigned int_data[4]; 2990 void *ptr_data; 2991} CXToken; 2992 2993/** 2994 * \brief Determine the kind of the given token. 2995 */ 2996CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); 2997 2998/** 2999 * \brief Determine the spelling of the given token. 3000 * 3001 * The spelling of a token is the textual representation of that token, e.g., 3002 * the text of an identifier or keyword. 3003 */ 3004CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 3005 3006/** 3007 * \brief Retrieve the source location of the given token. 3008 */ 3009CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, 3010 CXToken); 3011 3012/** 3013 * \brief Retrieve a source range that covers the given token. 3014 */ 3015CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 3016 3017/** 3018 * \brief Tokenize the source code described by the given range into raw 3019 * lexical tokens. 3020 * 3021 * \param TU the translation unit whose text is being tokenized. 3022 * 3023 * \param Range the source range in which text should be tokenized. All of the 3024 * tokens produced by tokenization will fall within this source range, 3025 * 3026 * \param Tokens this pointer will be set to point to the array of tokens 3027 * that occur within the given source range. The returned pointer must be 3028 * freed with clang_disposeTokens() before the translation unit is destroyed. 3029 * 3030 * \param NumTokens will be set to the number of tokens in the \c *Tokens 3031 * array. 3032 * 3033 */ 3034CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, 3035 CXToken **Tokens, unsigned *NumTokens); 3036 3037/** 3038 * \brief Annotate the given set of tokens by providing cursors for each token 3039 * that can be mapped to a specific entity within the abstract syntax tree. 3040 * 3041 * This token-annotation routine is equivalent to invoking 3042 * clang_getCursor() for the source locations of each of the 3043 * tokens. The cursors provided are filtered, so that only those 3044 * cursors that have a direct correspondence to the token are 3045 * accepted. For example, given a function call \c f(x), 3046 * clang_getCursor() would provide the following cursors: 3047 * 3048 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 3049 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 3050 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 3051 * 3052 * Only the first and last of these cursors will occur within the 3053 * annotate, since the tokens "f" and "x' directly refer to a function 3054 * and a variable, respectively, but the parentheses are just a small 3055 * part of the full syntax of the function call expression, which is 3056 * not provided as an annotation. 3057 * 3058 * \param TU the translation unit that owns the given tokens. 3059 * 3060 * \param Tokens the set of tokens to annotate. 3061 * 3062 * \param NumTokens the number of tokens in \p Tokens. 3063 * 3064 * \param Cursors an array of \p NumTokens cursors, whose contents will be 3065 * replaced with the cursors corresponding to each token. 3066 */ 3067CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, 3068 CXToken *Tokens, unsigned NumTokens, 3069 CXCursor *Cursors); 3070 3071/** 3072 * \brief Free the given set of tokens. 3073 */ 3074CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, 3075 CXToken *Tokens, unsigned NumTokens); 3076 3077/** 3078 * @} 3079 */ 3080 3081/** 3082 * \defgroup CINDEX_DEBUG Debugging facilities 3083 * 3084 * These routines are used for testing and debugging, only, and should not 3085 * be relied upon. 3086 * 3087 * @{ 3088 */ 3089 3090/* for debug/testing */ 3091CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); 3092CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, 3093 const char **startBuf, 3094 const char **endBuf, 3095 unsigned *startLine, 3096 unsigned *startColumn, 3097 unsigned *endLine, 3098 unsigned *endColumn); 3099CINDEX_LINKAGE void clang_enableStackTraces(void); 3100CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data, 3101 unsigned stack_size); 3102 3103/** 3104 * @} 3105 */ 3106 3107/** 3108 * \defgroup CINDEX_CODE_COMPLET Code completion 3109 * 3110 * Code completion involves taking an (incomplete) source file, along with 3111 * knowledge of where the user is actively editing that file, and suggesting 3112 * syntactically- and semantically-valid constructs that the user might want to 3113 * use at that particular point in the source code. These data structures and 3114 * routines provide support for code completion. 3115 * 3116 * @{ 3117 */ 3118 3119/** 3120 * \brief A semantic string that describes a code-completion result. 3121 * 3122 * A semantic string that describes the formatting of a code-completion 3123 * result as a single "template" of text that should be inserted into the 3124 * source buffer when a particular code-completion result is selected. 3125 * Each semantic string is made up of some number of "chunks", each of which 3126 * contains some text along with a description of what that text means, e.g., 3127 * the name of the entity being referenced, whether the text chunk is part of 3128 * the template, or whether it is a "placeholder" that the user should replace 3129 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 3130 * description of the different kinds of chunks. 3131 */ 3132typedef void *CXCompletionString; 3133 3134/** 3135 * \brief A single result of code completion. 3136 */ 3137typedef struct { 3138 /** 3139 * \brief The kind of entity that this completion refers to. 3140 * 3141 * The cursor kind will be a macro, keyword, or a declaration (one of the 3142 * *Decl cursor kinds), describing the entity that the completion is 3143 * referring to. 3144 * 3145 * \todo In the future, we would like to provide a full cursor, to allow 3146 * the client to extract additional information from declaration. 3147 */ 3148 enum CXCursorKind CursorKind; 3149 3150 /** 3151 * \brief The code-completion string that describes how to insert this 3152 * code-completion result into the editing buffer. 3153 */ 3154 CXCompletionString CompletionString; 3155} CXCompletionResult; 3156 3157/** 3158 * \brief Describes a single piece of text within a code-completion string. 3159 * 3160 * Each "chunk" within a code-completion string (\c CXCompletionString) is 3161 * either a piece of text with a specific "kind" that describes how that text 3162 * should be interpreted by the client or is another completion string. 3163 */ 3164enum CXCompletionChunkKind { 3165 /** 3166 * \brief A code-completion string that describes "optional" text that 3167 * could be a part of the template (but is not required). 3168 * 3169 * The Optional chunk is the only kind of chunk that has a code-completion 3170 * string for its representation, which is accessible via 3171 * \c clang_getCompletionChunkCompletionString(). The code-completion string 3172 * describes an additional part of the template that is completely optional. 3173 * For example, optional chunks can be used to describe the placeholders for 3174 * arguments that match up with defaulted function parameters, e.g. given: 3175 * 3176 * \code 3177 * void f(int x, float y = 3.14, double z = 2.71828); 3178 * \endcode 3179 * 3180 * The code-completion string for this function would contain: 3181 * - a TypedText chunk for "f". 3182 * - a LeftParen chunk for "(". 3183 * - a Placeholder chunk for "int x" 3184 * - an Optional chunk containing the remaining defaulted arguments, e.g., 3185 * - a Comma chunk for "," 3186 * - a Placeholder chunk for "float y" 3187 * - an Optional chunk containing the last defaulted argument: 3188 * - a Comma chunk for "," 3189 * - a Placeholder chunk for "double z" 3190 * - a RightParen chunk for ")" 3191 * 3192 * There are many ways to handle Optional chunks. Two simple approaches are: 3193 * - Completely ignore optional chunks, in which case the template for the 3194 * function "f" would only include the first parameter ("int x"). 3195 * - Fully expand all optional chunks, in which case the template for the 3196 * function "f" would have all of the parameters. 3197 */ 3198 CXCompletionChunk_Optional, 3199 /** 3200 * \brief Text that a user would be expected to type to get this 3201 * code-completion result. 3202 * 3203 * There will be exactly one "typed text" chunk in a semantic string, which 3204 * will typically provide the spelling of a keyword or the name of a 3205 * declaration that could be used at the current code point. Clients are 3206 * expected to filter the code-completion results based on the text in this 3207 * chunk. 3208 */ 3209 CXCompletionChunk_TypedText, 3210 /** 3211 * \brief Text that should be inserted as part of a code-completion result. 3212 * 3213 * A "text" chunk represents text that is part of the template to be 3214 * inserted into user code should this particular code-completion result 3215 * be selected. 3216 */ 3217 CXCompletionChunk_Text, 3218 /** 3219 * \brief Placeholder text that should be replaced by the user. 3220 * 3221 * A "placeholder" chunk marks a place where the user should insert text 3222 * into the code-completion template. For example, placeholders might mark 3223 * the function parameters for a function declaration, to indicate that the 3224 * user should provide arguments for each of those parameters. The actual 3225 * text in a placeholder is a suggestion for the text to display before 3226 * the user replaces the placeholder with real code. 3227 */ 3228 CXCompletionChunk_Placeholder, 3229 /** 3230 * \brief Informative text that should be displayed but never inserted as 3231 * part of the template. 3232 * 3233 * An "informative" chunk contains annotations that can be displayed to 3234 * help the user decide whether a particular code-completion result is the 3235 * right option, but which is not part of the actual template to be inserted 3236 * by code completion. 3237 */ 3238 CXCompletionChunk_Informative, 3239 /** 3240 * \brief Text that describes the current parameter when code-completion is 3241 * referring to function call, message send, or template specialization. 3242 * 3243 * A "current parameter" chunk occurs when code-completion is providing 3244 * information about a parameter corresponding to the argument at the 3245 * code-completion point. For example, given a function 3246 * 3247 * \code 3248 * int add(int x, int y); 3249 * \endcode 3250 * 3251 * and the source code \c add(, where the code-completion point is after the 3252 * "(", the code-completion string will contain a "current parameter" chunk 3253 * for "int x", indicating that the current argument will initialize that 3254 * parameter. After typing further, to \c add(17, (where the code-completion 3255 * point is after the ","), the code-completion string will contain a 3256 * "current paremeter" chunk to "int y". 3257 */ 3258 CXCompletionChunk_CurrentParameter, 3259 /** 3260 * \brief A left parenthesis ('('), used to initiate a function call or 3261 * signal the beginning of a function parameter list. 3262 */ 3263 CXCompletionChunk_LeftParen, 3264 /** 3265 * \brief A right parenthesis (')'), used to finish a function call or 3266 * signal the end of a function parameter list. 3267 */ 3268 CXCompletionChunk_RightParen, 3269 /** 3270 * \brief A left bracket ('['). 3271 */ 3272 CXCompletionChunk_LeftBracket, 3273 /** 3274 * \brief A right bracket (']'). 3275 */ 3276 CXCompletionChunk_RightBracket, 3277 /** 3278 * \brief A left brace ('{'). 3279 */ 3280 CXCompletionChunk_LeftBrace, 3281 /** 3282 * \brief A right brace ('}'). 3283 */ 3284 CXCompletionChunk_RightBrace, 3285 /** 3286 * \brief A left angle bracket ('<'). 3287 */ 3288 CXCompletionChunk_LeftAngle, 3289 /** 3290 * \brief A right angle bracket ('>'). 3291 */ 3292 CXCompletionChunk_RightAngle, 3293 /** 3294 * \brief A comma separator (','). 3295 */ 3296 CXCompletionChunk_Comma, 3297 /** 3298 * \brief Text that specifies the result type of a given result. 3299 * 3300 * This special kind of informative chunk is not meant to be inserted into 3301 * the text buffer. Rather, it is meant to illustrate the type that an 3302 * expression using the given completion string would have. 3303 */ 3304 CXCompletionChunk_ResultType, 3305 /** 3306 * \brief A colon (':'). 3307 */ 3308 CXCompletionChunk_Colon, 3309 /** 3310 * \brief A semicolon (';'). 3311 */ 3312 CXCompletionChunk_SemiColon, 3313 /** 3314 * \brief An '=' sign. 3315 */ 3316 CXCompletionChunk_Equal, 3317 /** 3318 * Horizontal space (' '). 3319 */ 3320 CXCompletionChunk_HorizontalSpace, 3321 /** 3322 * Vertical space ('\n'), after which it is generally a good idea to 3323 * perform indentation. 3324 */ 3325 CXCompletionChunk_VerticalSpace 3326}; 3327 3328/** 3329 * \brief Determine the kind of a particular chunk within a completion string. 3330 * 3331 * \param completion_string the completion string to query. 3332 * 3333 * \param chunk_number the 0-based index of the chunk in the completion string. 3334 * 3335 * \returns the kind of the chunk at the index \c chunk_number. 3336 */ 3337CINDEX_LINKAGE enum CXCompletionChunkKind 3338clang_getCompletionChunkKind(CXCompletionString completion_string, 3339 unsigned chunk_number); 3340 3341/** 3342 * \brief Retrieve the text associated with a particular chunk within a 3343 * completion string. 3344 * 3345 * \param completion_string the completion string to query. 3346 * 3347 * \param chunk_number the 0-based index of the chunk in the completion string. 3348 * 3349 * \returns the text associated with the chunk at index \c chunk_number. 3350 */ 3351CINDEX_LINKAGE CXString 3352clang_getCompletionChunkText(CXCompletionString completion_string, 3353 unsigned chunk_number); 3354 3355/** 3356 * \brief Retrieve the completion string associated with a particular chunk 3357 * within a completion string. 3358 * 3359 * \param completion_string the completion string to query. 3360 * 3361 * \param chunk_number the 0-based index of the chunk in the completion string. 3362 * 3363 * \returns the completion string associated with the chunk at index 3364 * \c chunk_number. 3365 */ 3366CINDEX_LINKAGE CXCompletionString 3367clang_getCompletionChunkCompletionString(CXCompletionString completion_string, 3368 unsigned chunk_number); 3369 3370/** 3371 * \brief Retrieve the number of chunks in the given code-completion string. 3372 */ 3373CINDEX_LINKAGE unsigned 3374clang_getNumCompletionChunks(CXCompletionString completion_string); 3375 3376/** 3377 * \brief Determine the priority of this code completion. 3378 * 3379 * The priority of a code completion indicates how likely it is that this 3380 * particular completion is the completion that the user will select. The 3381 * priority is selected by various internal heuristics. 3382 * 3383 * \param completion_string The completion string to query. 3384 * 3385 * \returns The priority of this completion string. Smaller values indicate 3386 * higher-priority (more likely) completions. 3387 */ 3388CINDEX_LINKAGE unsigned 3389clang_getCompletionPriority(CXCompletionString completion_string); 3390 3391/** 3392 * \brief Determine the availability of the entity that this code-completion 3393 * string refers to. 3394 * 3395 * \param completion_string The completion string to query. 3396 * 3397 * \returns The availability of the completion string. 3398 */ 3399CINDEX_LINKAGE enum CXAvailabilityKind 3400clang_getCompletionAvailability(CXCompletionString completion_string); 3401 3402/** 3403 * \brief Retrieve the number of annotations associated with the given 3404 * completion string. 3405 * 3406 * \param completion_string the completion string to query. 3407 * 3408 * \returns the number of annotations associated with the given completion 3409 * string. 3410 */ 3411CINDEX_LINKAGE unsigned 3412clang_getCompletionNumAnnotations(CXCompletionString completion_string); 3413 3414/** 3415 * \brief Retrieve the annotation associated with the given completion string. 3416 * 3417 * \param completion_string the completion string to query. 3418 * 3419 * \param annotation_number the 0-based index of the annotation of the 3420 * completion string. 3421 * 3422 * \returns annotation string associated with the completion at index 3423 * \c annotation_number, or a NULL string if that annotation is not available. 3424 */ 3425CINDEX_LINKAGE CXString 3426clang_getCompletionAnnotation(CXCompletionString completion_string, 3427 unsigned annotation_number); 3428 3429/** 3430 * \brief Retrieve a completion string for an arbitrary declaration or macro 3431 * definition cursor. 3432 * 3433 * \param cursor The cursor to query. 3434 * 3435 * \returns A non-context-sensitive completion string for declaration and macro 3436 * definition cursors, or NULL for other kinds of cursors. 3437 */ 3438CINDEX_LINKAGE CXCompletionString 3439clang_getCursorCompletionString(CXCursor cursor); 3440 3441/** 3442 * \brief Contains the results of code-completion. 3443 * 3444 * This data structure contains the results of code completion, as 3445 * produced by \c clang_codeCompleteAt(). Its contents must be freed by 3446 * \c clang_disposeCodeCompleteResults. 3447 */ 3448typedef struct { 3449 /** 3450 * \brief The code-completion results. 3451 */ 3452 CXCompletionResult *Results; 3453 3454 /** 3455 * \brief The number of code-completion results stored in the 3456 * \c Results array. 3457 */ 3458 unsigned NumResults; 3459} CXCodeCompleteResults; 3460 3461/** 3462 * \brief Flags that can be passed to \c clang_codeCompleteAt() to 3463 * modify its behavior. 3464 * 3465 * The enumerators in this enumeration can be bitwise-OR'd together to 3466 * provide multiple options to \c clang_codeCompleteAt(). 3467 */ 3468enum CXCodeComplete_Flags { 3469 /** 3470 * \brief Whether to include macros within the set of code 3471 * completions returned. 3472 */ 3473 CXCodeComplete_IncludeMacros = 0x01, 3474 3475 /** 3476 * \brief Whether to include code patterns for language constructs 3477 * within the set of code completions, e.g., for loops. 3478 */ 3479 CXCodeComplete_IncludeCodePatterns = 0x02 3480}; 3481 3482/** 3483 * \brief Bits that represent the context under which completion is occurring. 3484 * 3485 * The enumerators in this enumeration may be bitwise-OR'd together if multiple 3486 * contexts are occurring simultaneously. 3487 */ 3488enum CXCompletionContext { 3489 /** 3490 * \brief The context for completions is unexposed, as only Clang results 3491 * should be included. (This is equivalent to having no context bits set.) 3492 */ 3493 CXCompletionContext_Unexposed = 0, 3494 3495 /** 3496 * \brief Completions for any possible type should be included in the results. 3497 */ 3498 CXCompletionContext_AnyType = 1 << 0, 3499 3500 /** 3501 * \brief Completions for any possible value (variables, function calls, etc.) 3502 * should be included in the results. 3503 */ 3504 CXCompletionContext_AnyValue = 1 << 1, 3505 /** 3506 * \brief Completions for values that resolve to an Objective-C object should 3507 * be included in the results. 3508 */ 3509 CXCompletionContext_ObjCObjectValue = 1 << 2, 3510 /** 3511 * \brief Completions for values that resolve to an Objective-C selector 3512 * should be included in the results. 3513 */ 3514 CXCompletionContext_ObjCSelectorValue = 1 << 3, 3515 /** 3516 * \brief Completions for values that resolve to a C++ class type should be 3517 * included in the results. 3518 */ 3519 CXCompletionContext_CXXClassTypeValue = 1 << 4, 3520 3521 /** 3522 * \brief Completions for fields of the member being accessed using the dot 3523 * operator should be included in the results. 3524 */ 3525 CXCompletionContext_DotMemberAccess = 1 << 5, 3526 /** 3527 * \brief Completions for fields of the member being accessed using the arrow 3528 * operator should be included in the results. 3529 */ 3530 CXCompletionContext_ArrowMemberAccess = 1 << 6, 3531 /** 3532 * \brief Completions for properties of the Objective-C object being accessed 3533 * using the dot operator should be included in the results. 3534 */ 3535 CXCompletionContext_ObjCPropertyAccess = 1 << 7, 3536 3537 /** 3538 * \brief Completions for enum tags should be included in the results. 3539 */ 3540 CXCompletionContext_EnumTag = 1 << 8, 3541 /** 3542 * \brief Completions for union tags should be included in the results. 3543 */ 3544 CXCompletionContext_UnionTag = 1 << 9, 3545 /** 3546 * \brief Completions for struct tags should be included in the results. 3547 */ 3548 CXCompletionContext_StructTag = 1 << 10, 3549 3550 /** 3551 * \brief Completions for C++ class names should be included in the results. 3552 */ 3553 CXCompletionContext_ClassTag = 1 << 11, 3554 /** 3555 * \brief Completions for C++ namespaces and namespace aliases should be 3556 * included in the results. 3557 */ 3558 CXCompletionContext_Namespace = 1 << 12, 3559 /** 3560 * \brief Completions for C++ nested name specifiers should be included in 3561 * the results. 3562 */ 3563 CXCompletionContext_NestedNameSpecifier = 1 << 13, 3564 3565 /** 3566 * \brief Completions for Objective-C interfaces (classes) should be included 3567 * in the results. 3568 */ 3569 CXCompletionContext_ObjCInterface = 1 << 14, 3570 /** 3571 * \brief Completions for Objective-C protocols should be included in 3572 * the results. 3573 */ 3574 CXCompletionContext_ObjCProtocol = 1 << 15, 3575 /** 3576 * \brief Completions for Objective-C categories should be included in 3577 * the results. 3578 */ 3579 CXCompletionContext_ObjCCategory = 1 << 16, 3580 /** 3581 * \brief Completions for Objective-C instance messages should be included 3582 * in the results. 3583 */ 3584 CXCompletionContext_ObjCInstanceMessage = 1 << 17, 3585 /** 3586 * \brief Completions for Objective-C class messages should be included in 3587 * the results. 3588 */ 3589 CXCompletionContext_ObjCClassMessage = 1 << 18, 3590 /** 3591 * \brief Completions for Objective-C selector names should be included in 3592 * the results. 3593 */ 3594 CXCompletionContext_ObjCSelectorName = 1 << 19, 3595 3596 /** 3597 * \brief Completions for preprocessor macro names should be included in 3598 * the results. 3599 */ 3600 CXCompletionContext_MacroName = 1 << 20, 3601 3602 /** 3603 * \brief Natural language completions should be included in the results. 3604 */ 3605 CXCompletionContext_NaturalLanguage = 1 << 21, 3606 3607 /** 3608 * \brief The current context is unknown, so set all contexts. 3609 */ 3610 CXCompletionContext_Unknown = ((1 << 22) - 1) 3611}; 3612 3613/** 3614 * \brief Returns a default set of code-completion options that can be 3615 * passed to\c clang_codeCompleteAt(). 3616 */ 3617CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void); 3618 3619/** 3620 * \brief Perform code completion at a given location in a translation unit. 3621 * 3622 * This function performs code completion at a particular file, line, and 3623 * column within source code, providing results that suggest potential 3624 * code snippets based on the context of the completion. The basic model 3625 * for code completion is that Clang will parse a complete source file, 3626 * performing syntax checking up to the location where code-completion has 3627 * been requested. At that point, a special code-completion token is passed 3628 * to the parser, which recognizes this token and determines, based on the 3629 * current location in the C/Objective-C/C++ grammar and the state of 3630 * semantic analysis, what completions to provide. These completions are 3631 * returned via a new \c CXCodeCompleteResults structure. 3632 * 3633 * Code completion itself is meant to be triggered by the client when the 3634 * user types punctuation characters or whitespace, at which point the 3635 * code-completion location will coincide with the cursor. For example, if \c p 3636 * is a pointer, code-completion might be triggered after the "-" and then 3637 * after the ">" in \c p->. When the code-completion location is afer the ">", 3638 * the completion results will provide, e.g., the members of the struct that 3639 * "p" points to. The client is responsible for placing the cursor at the 3640 * beginning of the token currently being typed, then filtering the results 3641 * based on the contents of the token. For example, when code-completing for 3642 * the expression \c p->get, the client should provide the location just after 3643 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 3644 * client can filter the results based on the current token text ("get"), only 3645 * showing those results that start with "get". The intent of this interface 3646 * is to separate the relatively high-latency acquisition of code-completion 3647 * results from the filtering of results on a per-character basis, which must 3648 * have a lower latency. 3649 * 3650 * \param TU The translation unit in which code-completion should 3651 * occur. The source files for this translation unit need not be 3652 * completely up-to-date (and the contents of those source files may 3653 * be overridden via \p unsaved_files). Cursors referring into the 3654 * translation unit may be invalidated by this invocation. 3655 * 3656 * \param complete_filename The name of the source file where code 3657 * completion should be performed. This filename may be any file 3658 * included in the translation unit. 3659 * 3660 * \param complete_line The line at which code-completion should occur. 3661 * 3662 * \param complete_column The column at which code-completion should occur. 3663 * Note that the column should point just after the syntactic construct that 3664 * initiated code completion, and not in the middle of a lexical token. 3665 * 3666 * \param unsaved_files the Tiles that have not yet been saved to disk 3667 * but may be required for parsing or code completion, including the 3668 * contents of those files. The contents and name of these files (as 3669 * specified by CXUnsavedFile) are copied when necessary, so the 3670 * client only needs to guarantee their validity until the call to 3671 * this function returns. 3672 * 3673 * \param num_unsaved_files The number of unsaved file entries in \p 3674 * unsaved_files. 3675 * 3676 * \param options Extra options that control the behavior of code 3677 * completion, expressed as a bitwise OR of the enumerators of the 3678 * CXCodeComplete_Flags enumeration. The 3679 * \c clang_defaultCodeCompleteOptions() function returns a default set 3680 * of code-completion options. 3681 * 3682 * \returns If successful, a new \c CXCodeCompleteResults structure 3683 * containing code-completion results, which should eventually be 3684 * freed with \c clang_disposeCodeCompleteResults(). If code 3685 * completion fails, returns NULL. 3686 */ 3687CINDEX_LINKAGE 3688CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, 3689 const char *complete_filename, 3690 unsigned complete_line, 3691 unsigned complete_column, 3692 struct CXUnsavedFile *unsaved_files, 3693 unsigned num_unsaved_files, 3694 unsigned options); 3695 3696/** 3697 * \brief Sort the code-completion results in case-insensitive alphabetical 3698 * order. 3699 * 3700 * \param Results The set of results to sort. 3701 * \param NumResults The number of results in \p Results. 3702 */ 3703CINDEX_LINKAGE 3704void clang_sortCodeCompletionResults(CXCompletionResult *Results, 3705 unsigned NumResults); 3706 3707/** 3708 * \brief Free the given set of code-completion results. 3709 */ 3710CINDEX_LINKAGE 3711void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); 3712 3713/** 3714 * \brief Determine the number of diagnostics produced prior to the 3715 * location where code completion was performed. 3716 */ 3717CINDEX_LINKAGE 3718unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); 3719 3720/** 3721 * \brief Retrieve a diagnostic associated with the given code completion. 3722 * 3723 * \param Result the code completion results to query. 3724 * \param Index the zero-based diagnostic number to retrieve. 3725 * 3726 * \returns the requested diagnostic. This diagnostic must be freed 3727 * via a call to \c clang_disposeDiagnostic(). 3728 */ 3729CINDEX_LINKAGE 3730CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, 3731 unsigned Index); 3732 3733/** 3734 * \brief Determines what compeltions are appropriate for the context 3735 * the given code completion. 3736 * 3737 * \param Results the code completion results to query 3738 * 3739 * \returns the kinds of completions that are appropriate for use 3740 * along with the given code completion results. 3741 */ 3742CINDEX_LINKAGE 3743unsigned long long clang_codeCompleteGetContexts( 3744 CXCodeCompleteResults *Results); 3745 3746/** 3747 * \brief Returns the cursor kind for the container for the current code 3748 * completion context. The container is only guaranteed to be set for 3749 * contexts where a container exists (i.e. member accesses or Objective-C 3750 * message sends); if there is not a container, this function will return 3751 * CXCursor_InvalidCode. 3752 * 3753 * \param Results the code completion results to query 3754 * 3755 * \param IsIncomplete on return, this value will be false if Clang has complete 3756 * information about the container. If Clang does not have complete 3757 * information, this value will be true. 3758 * 3759 * \returns the container kind, or CXCursor_InvalidCode if there is not a 3760 * container 3761 */ 3762CINDEX_LINKAGE 3763enum CXCursorKind clang_codeCompleteGetContainerKind( 3764 CXCodeCompleteResults *Results, 3765 unsigned *IsIncomplete); 3766 3767/** 3768 * \brief Returns the USR for the container for the current code completion 3769 * context. If there is not a container for the current context, this 3770 * function will return the empty string. 3771 * 3772 * \param Results the code completion results to query 3773 * 3774 * \returns the USR for the container 3775 */ 3776CINDEX_LINKAGE 3777CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results); 3778 3779 3780/** 3781 * \brief Returns the currently-entered selector for an Objective-C message 3782 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a 3783 * non-empty string for CXCompletionContext_ObjCInstanceMessage and 3784 * CXCompletionContext_ObjCClassMessage. 3785 * 3786 * \param Results the code completion results to query 3787 * 3788 * \returns the selector (or partial selector) that has been entered thus far 3789 * for an Objective-C message send. 3790 */ 3791CINDEX_LINKAGE 3792CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results); 3793 3794/** 3795 * @} 3796 */ 3797 3798 3799/** 3800 * \defgroup CINDEX_MISC Miscellaneous utility functions 3801 * 3802 * @{ 3803 */ 3804 3805/** 3806 * \brief Return a version string, suitable for showing to a user, but not 3807 * intended to be parsed (the format is not guaranteed to be stable). 3808 */ 3809CINDEX_LINKAGE CXString clang_getClangVersion(); 3810 3811 3812/** 3813 * \brief Enable/disable crash recovery. 3814 * 3815 * \param Flag to indicate if crash recovery is enabled. A non-zero value 3816 * enables crash recovery, while 0 disables it. 3817 */ 3818CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled); 3819 3820 /** 3821 * \brief Visitor invoked for each file in a translation unit 3822 * (used with clang_getInclusions()). 3823 * 3824 * This visitor function will be invoked by clang_getInclusions() for each 3825 * file included (either at the top-level or by #include directives) within 3826 * a translation unit. The first argument is the file being included, and 3827 * the second and third arguments provide the inclusion stack. The 3828 * array is sorted in order of immediate inclusion. For example, 3829 * the first element refers to the location that included 'included_file'. 3830 */ 3831typedef void (*CXInclusionVisitor)(CXFile included_file, 3832 CXSourceLocation* inclusion_stack, 3833 unsigned include_len, 3834 CXClientData client_data); 3835 3836/** 3837 * \brief Visit the set of preprocessor inclusions in a translation unit. 3838 * The visitor function is called with the provided data for every included 3839 * file. This does not include headers included by the PCH file (unless one 3840 * is inspecting the inclusions in the PCH file itself). 3841 */ 3842CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, 3843 CXInclusionVisitor visitor, 3844 CXClientData client_data); 3845 3846/** 3847 * @} 3848 */ 3849 3850/** \defgroup CINDEX_REMAPPING Remapping functions 3851 * 3852 * @{ 3853 */ 3854 3855/** 3856 * \brief A remapping of original source files and their translated files. 3857 */ 3858typedef void *CXRemapping; 3859 3860/** 3861 * \brief Retrieve a remapping. 3862 * 3863 * \param path the path that contains metadata about remappings. 3864 * 3865 * \returns the requested remapping. This remapping must be freed 3866 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. 3867 */ 3868CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path); 3869 3870/** 3871 * \brief Determine the number of remappings. 3872 */ 3873CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping); 3874 3875/** 3876 * \brief Get the original and the associated filename from the remapping. 3877 * 3878 * \param original If non-NULL, will be set to the original filename. 3879 * 3880 * \param transformed If non-NULL, will be set to the filename that the original 3881 * is associated with. 3882 */ 3883CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index, 3884 CXString *original, CXString *transformed); 3885 3886/** 3887 * \brief Dispose the remapping. 3888 */ 3889CINDEX_LINKAGE void clang_remap_dispose(CXRemapping); 3890 3891/** 3892 * @} 3893 */ 3894 3895/** \defgroup CINDEX_HIGH Higher level API functions 3896 * 3897 * @{ 3898 */ 3899 3900enum CXVisitorResult { 3901 CXVisit_Break, 3902 CXVisit_Continue 3903}; 3904 3905typedef struct { 3906 void *context; 3907 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange); 3908} CXCursorAndRangeVisitor; 3909 3910/** 3911 * \brief Find references of a declaration in a specific file. 3912 * 3913 * \param cursor pointing to a declaration or a reference of one. 3914 * 3915 * \param file to search for references. 3916 * 3917 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for 3918 * each reference found. 3919 * The CXSourceRange will point inside the file; if the reference is inside 3920 * a macro (and not a macro argument) the CXSourceRange will be invalid. 3921 */ 3922CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file, 3923 CXCursorAndRangeVisitor visitor); 3924 3925#ifdef __has_feature 3926# if __has_feature(blocks) 3927 3928typedef enum CXVisitorResult 3929 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange); 3930 3931CINDEX_LINKAGE 3932void clang_findReferencesInFileWithBlock(CXCursor, CXFile, 3933 CXCursorAndRangeVisitorBlock); 3934 3935# endif 3936#endif 3937 3938/** 3939 * \brief The client's data object that is associated with a CXFile. 3940 */ 3941typedef void *CXIdxClientFile; 3942 3943/** 3944 * \brief The client's data object that is associated with a semantic container 3945 * of entities. 3946 */ 3947typedef void *CXIdxClientContainer; 3948 3949/** 3950 * \brief The client's data object that is associated with an AST file (PCH 3951 * or module). 3952 */ 3953typedef void *CXIdxClientASTFile; 3954 3955/** 3956 * \brief Source location passed to index callbacks. 3957 */ 3958typedef struct { 3959 void *ptr_data[2]; 3960 unsigned int_data; 3961} CXIdxLoc; 3962 3963/** 3964 * \brief Data for \see ppIncludedFile callback. 3965 */ 3966typedef struct { 3967 /** 3968 * \brief Location of '#' in the #include/#import directive. 3969 */ 3970 CXIdxLoc hashLoc; 3971 /** 3972 * \brief Filename as written in the #include/#import directive. 3973 */ 3974 const char *filename; 3975 /** 3976 * \brief The actual file that the #include/#import directive resolved to. 3977 */ 3978 CXFile file; 3979 int isImport; 3980 int isAngled; 3981} CXIdxIncludedFileInfo; 3982 3983/** 3984 * \brief Data for \see importedASTFile callback. 3985 */ 3986typedef struct { 3987 CXFile file; 3988 /** 3989 * \brief Location where the file is imported. It is useful mostly for 3990 * modules. 3991 */ 3992 CXIdxLoc loc; 3993 /** 3994 * \brief Non-zero if the AST file is a module otherwise it's a PCH. 3995 */ 3996 int isModule; 3997} CXIdxImportedASTFileInfo; 3998 3999typedef enum { 4000 CXIdxEntity_Unexposed = 0, 4001 CXIdxEntity_Typedef = 1, 4002 CXIdxEntity_Function = 2, 4003 CXIdxEntity_Variable = 3, 4004 CXIdxEntity_Field = 4, 4005 CXIdxEntity_EnumConstant = 5, 4006 4007 CXIdxEntity_ObjCClass = 6, 4008 CXIdxEntity_ObjCProtocol = 7, 4009 CXIdxEntity_ObjCCategory = 8, 4010 4011 CXIdxEntity_ObjCInstanceMethod = 9, 4012 CXIdxEntity_ObjCClassMethod = 10, 4013 CXIdxEntity_ObjCProperty = 11, 4014 CXIdxEntity_ObjCIvar = 12, 4015 4016 CXIdxEntity_Enum = 13, 4017 CXIdxEntity_Struct = 14, 4018 CXIdxEntity_Union = 15, 4019 CXIdxEntity_CXXClass = 16 4020 4021} CXIdxEntityKind; 4022 4023typedef struct { 4024 CXIdxEntityKind kind; 4025 const char *name; 4026 const char *USR; 4027} CXIdxEntityInfo; 4028 4029typedef struct { 4030 const CXIdxEntityInfo *entityInfo; 4031 CXCursor cursor; 4032 CXIdxLoc loc; 4033 CXIdxClientContainer container; 4034 int isRedeclaration; 4035 int isDefinition; 4036 int isContainer; 4037 /** 4038 * \brief Whether the declaration exists in code or was created implicitly 4039 * by the compiler, e.g. implicit objc methods for properties. 4040 */ 4041 int isImplicit; 4042} CXIdxDeclInfo; 4043 4044typedef struct { 4045 CXIdxClientContainer *outContainer; 4046} CXIdxDeclOut; 4047 4048typedef enum { 4049 CXIdxObjCContainer_ForwardRef = 0, 4050 CXIdxObjCContainer_Interface = 1, 4051 CXIdxObjCContainer_Implementation = 2 4052} CXIdxObjCContainerKind; 4053 4054typedef struct { 4055 const CXIdxDeclInfo *declInfo; 4056 CXIdxObjCContainerKind kind; 4057} CXIdxObjCContainerDeclInfo; 4058 4059typedef struct { 4060 const CXIdxObjCContainerDeclInfo *containerInfo; 4061 const CXIdxEntityInfo *objcClass; 4062} CXIdxObjCCategoryDeclInfo; 4063 4064typedef struct { 4065 const CXIdxEntityInfo *base; 4066 CXCursor cursor; 4067 CXIdxLoc loc; 4068} CXIdxBaseClassInfo; 4069 4070typedef struct { 4071 const CXIdxEntityInfo *protocol; 4072 CXCursor cursor; 4073 CXIdxLoc loc; 4074} CXIdxObjCProtocolRefInfo; 4075 4076typedef struct { 4077 const CXIdxObjCProtocolRefInfo *const *protocols; 4078 unsigned numProtocols; 4079} CXIdxObjCProtocolRefListInfo; 4080 4081typedef struct { 4082 const CXIdxObjCContainerDeclInfo *containerInfo; 4083 const CXIdxBaseClassInfo *superInfo; 4084 const CXIdxObjCProtocolRefListInfo *protocols; 4085} CXIdxObjCInterfaceDeclInfo; 4086 4087/** 4088 * \brief Data for \see indexEntityReference callback. 4089 */ 4090typedef enum { 4091 /** 4092 * \brief The entity is referenced directly in user's code. 4093 */ 4094 CXIdxEntityRef_Direct = 1, 4095 /** 4096 * \brief A reference of an ObjC method via the dot syntax. 4097 */ 4098 CXIdxEntityRef_ImplicitProperty = 2 4099} CXIdxEntityRefKind; 4100 4101/** 4102 * \brief Data for \see indexEntityReference callback. 4103 */ 4104typedef struct { 4105 /** 4106 * \brief Reference cursor. 4107 */ 4108 CXCursor cursor; 4109 CXIdxLoc loc; 4110 /** 4111 * \brief The entity that gets referenced. 4112 */ 4113 const CXIdxEntityInfo *referencedEntity; 4114 /** 4115 * \brief Immediate "parent" of the reference. For example: 4116 * 4117 * \code 4118 * Foo *var; 4119 * \endcode 4120 * 4121 * The parent of reference of type 'Foo' is the variable 'var'. 4122 * parentEntity will be null for references inside statement bodies. 4123 */ 4124 const CXIdxEntityInfo *parentEntity; 4125 /** 4126 * \brief Container context of the reference. 4127 */ 4128 CXIdxClientContainer container; 4129 CXIdxEntityRefKind kind; 4130} CXIdxEntityRefInfo; 4131 4132typedef struct { 4133 /** 4134 * \brief Called periodically to check whether indexing should be aborted. 4135 * Should return 0 to continue, and non-zero to abort. 4136 */ 4137 int (*abortQuery)(CXClientData client_data, void *reserved); 4138 4139 /** 4140 * \brief Called when a diagnostic is emitted. 4141 */ 4142 void (*diagnostic)(CXClientData client_data, 4143 CXDiagnostic, void *reserved); 4144 4145 CXIdxClientFile (*enteredMainFile)(CXClientData client_data, 4146 CXFile mainFile, void *reserved); 4147 4148 /** 4149 * \brief Called when a file gets #included/#imported. 4150 */ 4151 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data, 4152 const CXIdxIncludedFileInfo *); 4153 4154 /** 4155 * \brief Called when a AST file (PCH or module) gets imported. 4156 * 4157 * AST files will not get indexed (there will not be callbacks to index all 4158 * the entities in an AST file). The recommended action is that, if the AST 4159 * file is not already indexed, to block further indexing and initiate a new 4160 * indexing job specific to the AST file. 4161 */ 4162 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data, 4163 const CXIdxImportedASTFileInfo *); 4164 4165 /** 4166 * \brief Called at the beginning of indexing a translation unit. 4167 */ 4168 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data, 4169 void *reserved); 4170 4171 void (*indexDeclaration)(CXClientData client_data, 4172 const CXIdxDeclInfo *, const CXIdxDeclOut *); 4173 4174 /** 4175 * \brief Called to index a reference of an entity. 4176 */ 4177 void (*indexEntityReference)(CXClientData client_data, 4178 const CXIdxEntityRefInfo *); 4179 4180} IndexerCallbacks; 4181 4182CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind); 4183CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo * 4184clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *); 4185 4186CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo * 4187clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *); 4188 4189CINDEX_LINKAGE 4190const CXIdxObjCCategoryDeclInfo * 4191clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *); 4192 4193CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo * 4194clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *); 4195 4196/** 4197 * \brief Index the given source file and the translation unit corresponding 4198 * to that file via callbacks implemented through \see IndexerCallbacks. 4199 * 4200 * \param client_data pointer data supplied by the client, which will 4201 * be passed to the invoked callbacks. 4202 * 4203 * \param index_callbacks Pointer to indexing callbacks that the client 4204 * implements. 4205 * 4206 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets 4207 * passed in index_callbacks. 4208 * 4209 * \param index_options Options affecting indexing; reserved. 4210 * 4211 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused 4212 * after indexing is finished. Set to NULL if you do not require it. 4213 * 4214 * \returns If there is a failure from which the compiler cannot recover returns 4215 * non-zero, otherwise returns 0. 4216 * 4217 * The rest of the parameters are the same as \see clang_parseTranslationUnit. 4218 */ 4219CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndex CIdx, 4220 CXClientData client_data, 4221 IndexerCallbacks *index_callbacks, 4222 unsigned index_callbacks_size, 4223 unsigned index_options, 4224 const char *source_filename, 4225 const char * const *command_line_args, 4226 int num_command_line_args, 4227 struct CXUnsavedFile *unsaved_files, 4228 unsigned num_unsaved_files, 4229 CXTranslationUnit *out_TU, 4230 unsigned TU_options); 4231 4232/** 4233 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by 4234 * the given CXIdxLoc. 4235 * 4236 * If the location refers into a macro expansion, retrieves the 4237 * location of the macro expansion and if it refers into a macro argument 4238 * retrieves the location of the argument. 4239 */ 4240CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc, 4241 CXIdxClientFile *indexFile, 4242 CXFile *file, 4243 unsigned *line, 4244 unsigned *column, 4245 unsigned *offset); 4246 4247/** 4248 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc. 4249 */ 4250CINDEX_LINKAGE 4251CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc); 4252 4253/** 4254 * @} 4255 */ 4256 4257/** 4258 * @} 4259 */ 4260 4261#ifdef __cplusplus 4262} 4263#endif 4264#endif 4265 4266