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